From 406c98880726b467518e05006edd38c9622a402e Mon Sep 17 00:00:00 2001 From: emlys Date: Mon, 24 May 2021 10:28:06 -0600 Subject: [PATCH 01/10] update to work with gdal 3.3.0 --- src/pygeoprocessing/geoprocessing.py | 34 ++-- src/pygeoprocessing/routing/routing.pyx | 216 +++++++++++----------- src/pygeoprocessing/routing/watershed.pyx | 124 +++++++------ tests/test_watershed_delineation.py | 3 +- 4 files changed, 195 insertions(+), 182 deletions(-) diff --git a/src/pygeoprocessing/geoprocessing.py b/src/pygeoprocessing/geoprocessing.py index 3a05aa76..0c59a8a5 100644 --- a/src/pygeoprocessing/geoprocessing.py +++ b/src/pygeoprocessing/geoprocessing.py @@ -767,7 +767,7 @@ def align_and_resize_raster_stack( vector_mask_options['mask_vector_where_filter']) mask_bounding_box = merge_bounding_box_list( [[feature.GetGeometryRef().GetEnvelope()[i] - for i in [0, 2, 1, 3]] for feature in mask_layer], + for i in [0, 2, 1, 3]] for feature in mask_layer], 'union') mask_layer = None mask_vector = None @@ -779,8 +779,8 @@ def align_and_resize_raster_stack( if mask_vector_projection_wkt is not None and \ target_projection_wkt is not None: mask_vector_bb = transform_bounding_box( - mask_bounding_box, mask_vector_info['projection_wkt'], - target_projection_wkt) + mask_bounding_box, mask_vector_info['projection_wkt'], + target_projection_wkt) else: mask_vector_bb = mask_vector_info['bounding_box'] # Calling `merge_bounding_box_list` will raise an ValueError if the @@ -814,8 +814,8 @@ def align_and_resize_raster_stack( raster_driver_creation_tuple=(raster_driver_creation_tuple), target_projection_wkt=target_projection_wkt, base_projection_wkt=( - None if not base_projection_wkt_list else - base_projection_wkt_list[index]), + None if not base_projection_wkt_list else + base_projection_wkt_list[index]), vector_mask_options=vector_mask_options, gdal_warp_options=gdal_warp_options) LOGGER.info( @@ -1220,7 +1220,7 @@ def zonal_statistics( 'options': [ 'ALL_TOUCHED=FALSE', 'ATTRIBUTE=%s' % local_aggregate_field_name] - } + } # clip base raster to aggregating vector intersection raster_info = get_raster_info(base_raster_path_band[0]) @@ -2233,7 +2233,8 @@ def calculate_disjoint_polygon_set( 'skipping...') continue shapely_polygon_lookup[poly_feat.GetFID()] = ( - shapely.wkb.loads(poly_geom_ref.ExportToWkb())) + # with GDAL>=3.3.0 ExportToWkb returns a bytesarray instead of bytes + shapely.wkb.loads(bytes(poly_geom_ref.ExportToWkb()))) poly_geom_ref = None poly_feat = None @@ -2478,15 +2479,15 @@ def convolve_2d( nodata for the output result where ``signal_path`` has nodata. Note with default values, boundary effects can be seen in the result where - the kernel would hang off the edge of the raster or in regions with + the kernel would hang off the edge of the raster or in regions with nodata pixels. The function would treat these areas as values with "0.0" by default thus pulling the total convolution down in these areas. This is similar to setting ``mode='same'`` in Numpy's ``convolve`` function: https://numpy.org/doc/stable/reference/generated/numpy.convolve.html - This boundary effect can be avoided by setting - ``ignore_nodata_and_edges=True`` which normalizes the target result by - dynamically accounting for the number of valid signal pixels the kernel + This boundary effect can be avoided by setting + ``ignore_nodata_and_edges=True`` which normalizes the target result by + dynamically accounting for the number of valid signal pixels the kernel overlapped during the convolution step. Args: @@ -2606,7 +2607,6 @@ def convolve_2d( signal_path_band[0], target_path, target_datatype, [0], raster_driver_creation_tuple=raster_driver_creation_tuple) - n_cols_signal, n_rows_signal = signal_raster_info['raster_size'] n_cols_kernel, n_rows_kernel = kernel_raster_info['raster_size'] s_path_band = signal_path_band @@ -3828,7 +3828,7 @@ def _mult_op(base_array, base_nodata, scale, datatype): [(base_stitch_raster_path, 1), (base_stitch_nodata, 'raw'), m2_area_per_lat/base_pixel_area_m2, (_GDAL_TYPE_TO_NUMPY_LOOKUP[ - target_raster_info['datatype']], 'raw')], _mult_op, + target_raster_info['datatype']], 'raw')], _mult_op, scaled_raster_path, target_raster_info['datatype'], base_stitch_nodata) @@ -3852,10 +3852,10 @@ def _mult_op(base_array, base_nodata, scale, datatype): overlap = True for (target_to_base_off, off_val, target_off_id, off_clip_id, win_size_id) in [ - (target_to_base_xoff, offset_dict['xoff'], - 'target_xoff', 'xoff_clip', 'win_xsize'), - (target_to_base_yoff, offset_dict['yoff'], - 'target_yoff', 'yoff_clip', 'win_ysize')]: + (target_to_base_xoff, offset_dict['xoff'], + 'target_xoff', 'xoff_clip', 'win_xsize'), + (target_to_base_yoff, offset_dict['yoff'], + 'target_yoff', 'yoff_clip', 'win_ysize')]: _offset_vars[target_off_id] = (target_to_base_off+off_val) if _offset_vars[target_off_id] > target_raster_x_size: overlap = False diff --git a/src/pygeoprocessing/routing/routing.pyx b/src/pygeoprocessing/routing/routing.pyx index e7721cda..02d03547 100644 --- a/src/pygeoprocessing/routing/routing.pyx +++ b/src/pygeoprocessing/routing/routing.pyx @@ -17,6 +17,27 @@ is encoded as:: 4 x 0 5 6 7 """ +import pygeoprocessing +from ..geoprocessing_core import DEFAULT_OSR_AXIS_MAPPING_STRATEGY +import scipy.stats +import shapely.ops +import shapely.wkb +import numpy +from osgeo import osr +from osgeo import ogr +from osgeo import gdal +from libcpp.vector cimport vector +from libcpp.stack cimport stack +from libcpp.set cimport set as cset +from libcpp.queue cimport queue +from libcpp.pair cimport pair +from libcpp.list cimport list as clist +from libcpp.deque cimport deque +from libc.time cimport time_t +from libc.time cimport time as ctime +from cython.operator cimport preincrement as inc +from cython.operator cimport dereference as deref +from cpython.mem cimport PyMem_Malloc, PyMem_Free import collections import logging import os @@ -26,28 +47,7 @@ import time cimport cython cimport numpy -from cpython.mem cimport PyMem_Malloc, PyMem_Free -from cython.operator cimport dereference as deref -from cython.operator cimport preincrement as inc -from libc.time cimport time as ctime -from libc.time cimport time_t -from libcpp.deque cimport deque -from libcpp.list cimport list as clist -from libcpp.pair cimport pair -from libcpp.queue cimport queue -from libcpp.set cimport set as cset -from libcpp.stack cimport stack -from libcpp.vector cimport vector -from osgeo import gdal -from osgeo import ogr -from osgeo import osr -import numpy -import shapely.wkb -import shapely.ops -import scipy.stats -from ..geoprocessing_core import DEFAULT_OSR_AXIS_MAPPING_STRATEGY -import pygeoprocessing LOGGER = logging.getLogger(__name__) @@ -77,12 +77,12 @@ cdef double SQRT2_INV = 1.0 / 1.4142135623730951 # 321 # 4x0 # 567 -cdef int *D8_XOFFSET = [1, 1, 0, -1, -1, -1, 0, 1] -cdef int *D8_YOFFSET = [0, -1, -1, -1, 0, +1, +1, +1] +cdef int * D8_XOFFSET = [1, 1, 0, -1, -1, -1, 0, 1] +cdef int * D8_YOFFSET = [0, -1, -1, -1, 0, +1, +1, +1] # 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] +cdef int * D8_REVERSE_DIRECTION = [4, 5, 6, 7, 0, 1, 2, 3] # default of number of pixels to naturally drain. This number was derived off # of reasonable expectations from a 30m DEM @@ -93,25 +93,25 @@ cdef int _MAX_PIXEL_FILL_COUNT = 500 cdef extern from "" namespace "std" nogil: cdef cppclass priority_queue[T, Container, Compare]: priority_queue() except + - priority_queue(priority_queue&) except + - priority_queue(Container&) + priority_queue(priority_queue & ) except + + priority_queue(Container & ) bint empty() void pop() - void push(T&) + void push(T & ) size_t size() - T& top() + T & top() # this is a least recently used cache written in C++ in an external file, # exposing here so _ManagedRaster can use it cdef extern from "LRUCache.h" nogil: cdef cppclass LRUCache[KEY_T, VAL_T]: LRUCache(int) - void put(KEY_T&, VAL_T&, clist[pair[KEY_T,VAL_T]]&) - clist[pair[KEY_T,VAL_T]].iterator begin() - clist[pair[KEY_T,VAL_T]].iterator end() + void put(KEY_T &, VAL_T&, clist[pair[KEY_T, VAL_T]]&) + clist[pair[KEY_T, VAL_T]].iterator begin() + clist[pair[KEY_T, VAL_T]].iterator end() bint exist(KEY_T &) VAL_T get(KEY_T &) - void clean(clist[pair[KEY_T,VAL_T]]&, int n_items) + void clean(clist[pair[KEY_T, VAL_T]] &, int n_items) size_t size() # this is the class type that'll get stored in the priority queue @@ -119,7 +119,7 @@ cdef struct PixelType: double value # pixel value int xi # pixel x coordinate in the raster int yi # pixel y coordinate in the raster - int priority # for breaking ties if two `value`s are equal. + int priority # for breaking ties if two `value`s are equal. # this struct is used to record an intermediate flow pixel's last calculated # direction and the flow accumulation value so far @@ -166,7 +166,7 @@ ctypedef queue[CoordinateType] CoordinateQueueType # functor for priority queue of pixels cdef cppclass GreaterPixel nogil: - bint get "operator()"(PixelType& lhs, PixelType& rhs): + 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 >. if lhs.value > rhs.value: @@ -182,7 +182,7 @@ cdef int _is_close(double x, double y, double abs_delta, double rel_delta): # 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 LRUCache[int, double*] * lru_cache cdef cset[int] dirty_blocks cdef int block_xsize cdef int block_ysize @@ -256,7 +256,7 @@ cdef class _ManagedRaster: 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 = raster_path + self.raster_path = raster_path self.write_mode = write_mode self.closed = 0 @@ -281,9 +281,9 @@ cdef class _ManagedRaster: return self.closed = 1 cdef int xi_copy, yi_copy - cdef numpy.ndarray[double, ndim=2] block_array = numpy.empty( + cdef numpy.ndarray[double, ndim = 2] block_array = numpy.empty( (self.block_ysize, self.block_xsize)) - cdef double *double_buffer + cdef double * double_buffer cdef int block_xi cdef int block_yi # initially the win size is the same as the block size unless @@ -398,8 +398,8 @@ cdef class _ManagedRaster: cdef int yoff = block_yi << self.block_ybits cdef int xi_copy, yi_copy - cdef numpy.ndarray[double, ndim=2] block_array - cdef double *double_buffer + cdef numpy.ndarray[double, ndim = 2] block_array + cdef double * double_buffer cdef clist[BlockBufferPair] removed_value_list # determine the block aligned xoffset for read as array @@ -429,7 +429,7 @@ cdef class _ManagedRaster: double_buffer[(yi_copy << self.block_xbits)+xi_copy] = ( block_array[yi_copy, xi_copy]) self.lru_cache.put( - block_index, double_buffer, removed_value_list) + < int > block_index, < double*>double_buffer, removed_value_list) if self.write_mode: n_attempts = 5 @@ -494,7 +494,7 @@ cdef class _ManagedRaster: cdef void flush(self) except *: cdef clist[BlockBufferPair] removed_value_list - cdef double *double_buffer + cdef double * double_buffer cdef cset[int].iterator dirty_itr cdef int block_index, block_xi, block_yi cdef int xoff, yoff, win_xsize, win_ysize @@ -763,7 +763,7 @@ def fill_pits( target_filled_dem_raster_path, gdal.OF_RASTER | gdal.GA_Update) filled_dem_band = filled_dem_raster.GetRasterBand(1) for offset_info, block_array in pygeoprocessing.iterblocks( - dem_raster_path_band): + dem_raster_path_band): filled_dem_band.WriteArray( block_array, xoff=offset_info['xoff'], yoff=offset_info['yoff']) filled_dem_band.FlushCache() @@ -1027,7 +1027,7 @@ def flow_dir_d8( # and it's the most complex numerical type and will be compatible without # data loss for any lower type that might be used in # `dem_raster_path_band[0]`. - cdef numpy.ndarray[numpy.float64_t, ndim=2] dem_buffer_array + cdef numpy.ndarray[numpy.float64_t, ndim = 2] dem_buffer_array cdef int win_ysize, win_xsize, xoff, yoff # the _root variables remembers the pixel index where the plateau/pit @@ -1183,7 +1183,7 @@ def flow_dir_d8( (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) + **modified_offset_dict).astype(numpy.float64) # ensure these are set for the complier xi_n = -1 @@ -1397,7 +1397,7 @@ def flow_accumulation_d8( # and it's the most complex numerical type and will be compatible without # data loss for any lower type that might be used in # `dem_raster_path_band[0]`. - cdef numpy.ndarray[numpy.uint8_t, ndim=2] flow_dir_buffer_array + cdef numpy.ndarray[numpy.uint8_t, ndim = 2] flow_dir_buffer_array cdef int win_ysize, win_xsize, xoff, yoff # the _root variables remembers the pixel index where the plateau/pit @@ -1488,7 +1488,7 @@ def flow_accumulation_d8( if ctime(NULL) - last_log_time > _LOGGING_PERIOD: last_log_time = ctime(NULL) current_pixel = xoff + yoff * raster_x_size - LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( raster_x_size * raster_y_size)) # make a buffer big enough to capture block and boundaries around it @@ -1501,7 +1501,7 @@ def flow_accumulation_d8( (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) + **modified_offset_dict).astype(numpy.uint8) # ensure these are set for the complier xi_n = -1 @@ -1522,7 +1522,7 @@ def flow_accumulation_d8( yi_root = yi-1+yoff if weight_raster is not None: - weight_val = weight_raster.get( + weight_val = weight_raster.get( xi_root, yi_root) if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): weight_val = 0.0 @@ -1543,21 +1543,21 @@ def flow_accumulation_d8( yi_n < 0 or yi_n >= raster_y_size): # no upstream here continue - upstream_flow_dir = flow_dir_managed_raster.get( + upstream_flow_dir = 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]): # no upstream here continue - upstream_flow_accum = ( + upstream_flow_accum = ( flow_accum_managed_raster.get(xi_n, yi_n)) if _is_close(upstream_flow_accum, flow_accum_nodata, 1e-8, 1e-5): # 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 = weight_raster.get( + weight_val = weight_raster.get( xi_n, yi_n) if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): weight_val = 0.0 @@ -1619,7 +1619,7 @@ def flow_dir_mfd( # and it's the most complex numerical type and will be compatible without # data loss for any lower type that might be used in # `dem_raster_path_band[0]`. - cdef numpy.ndarray[numpy.float64_t, ndim=2] dem_buffer_array + cdef numpy.ndarray[numpy.float64_t, ndim = 2] dem_buffer_array cdef int win_ysize, win_xsize, xoff, yoff # the _root variables remembers the pixel index where the plateau/pit @@ -1647,7 +1647,7 @@ def flow_dir_mfd( cdef double nodata_downhill_slope_array[8] # a pointer reference to whatever kind of slope we're considering - cdef double *working_downhill_slope_array + cdef double * working_downhill_slope_array # as the neighbor slopes are calculated, this variable gathers them # together to calculate the final contribution of neighbor slopes to @@ -1790,7 +1790,7 @@ def flow_dir_mfd( if ctime(NULL) - last_log_time > _LOGGING_PERIOD: last_log_time = ctime(NULL) current_pixel = xoff + yoff * raster_x_size - LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( raster_x_size * raster_y_size)) # make a buffer big enough to capture block and boundaries around it @@ -1804,7 +1804,7 @@ def flow_dir_mfd( (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) + **modified_offset_dict).astype(numpy.float64) # ensure these are set for the complier xi_n = -1 @@ -1852,7 +1852,7 @@ def flow_dir_mfd( if sum_of_downhill_slopes > 0.0: compressed_integer_slopes = 0 for i_n in range(8): - compressed_integer_slopes |= (( + compressed_integer_slopes |= ( < int > ( 0.5 + downhill_slope_array[i_n] / sum_of_downhill_slopes * 0xF)) << (i_n * 4) @@ -1928,7 +1928,7 @@ def flow_dir_mfd( if working_downhill_slope_sum > 0.0: compressed_integer_slopes = 0 for i_n in range(8): - compressed_integer_slopes |= (( + compressed_integer_slopes |= ( < int > ( 0.5 + working_downhill_slope_array[i_n] / working_downhill_slope_sum * 0xF)) << ( i_n * 4) @@ -2000,7 +2000,7 @@ def flow_dir_mfd( n_drain_distance = drain_distance + ( SQRT2 if i_n & 1 else 1.0) - if ((dem_managed_raster.get( + if ( < double > (dem_managed_raster.get( xi_n, yi_n)) == root_height) and ( plateau_distance_managed_raster.get( xi_n, yi_n) > n_drain_distance): @@ -2053,7 +2053,7 @@ def flow_dir_mfd( continue compressed_integer_slopes = 0 for i_n in range(8): - compressed_integer_slopes |= (( + compressed_integer_slopes |= ( < int > ( 0.5 + downhill_slope_array[i_n] / sum_of_slope_weights * 0xF)) << (i_n * 4) flow_dir_managed_raster.set( @@ -2112,7 +2112,7 @@ def flow_accumulation_mfd( # and it's the most complex numerical type and will be compatible without # data loss for any lower type that might be used in # `dem_raster_path_band[0]`. - cdef numpy.ndarray[numpy.int32_t, ndim=2] flow_dir_mfd_buffer_array + cdef numpy.ndarray[numpy.int32_t, ndim = 2] flow_dir_mfd_buffer_array cdef int win_ysize, win_xsize, xoff, yoff # These are used to estimate % complete @@ -2225,7 +2225,7 @@ def flow_accumulation_mfd( if ctime(NULL) - last_log_time > _LOGGING_PERIOD: last_log_time = ctime(NULL) current_pixel = xoff + yoff * raster_x_size - LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( raster_x_size * raster_y_size)) # make a buffer big enough to capture block and boundaries around it @@ -2239,7 +2239,7 @@ def flow_accumulation_mfd( (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) + **modified_offset_dict).astype(numpy.int32) # ensure these are set for the complier xi_n = -1 @@ -2267,7 +2267,7 @@ def flow_accumulation_mfd( xi_root = xi-1+xoff yi_root = yi-1+yoff if weight_raster is not None: - weight_val = weight_raster.get( + weight_val = weight_raster.get( xi_root, yi_root) if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): weight_val = 0.0 @@ -2298,7 +2298,7 @@ def flow_accumulation_mfd( # no upstream here continue compressed_upstream_flow_dir = ( - flow_dir_managed_raster.get(xi_n, yi_n)) + < int > flow_dir_managed_raster.get(xi_n, yi_n)) upstream_flow_weight = ( compressed_upstream_flow_dir >> ( D8_REVERSE_DIRECTION[i_n] * 4)) & 0xF @@ -2314,7 +2314,7 @@ def flow_accumulation_mfd( flow_pixel.last_flow_dir = i_n search_stack.push(flow_pixel) if weight_raster is not None: - weight_val = weight_raster.get( + weight_val = weight_raster.get( xi_n, yi_n) if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): weight_val = 0.0 @@ -2334,7 +2334,7 @@ def flow_accumulation_mfd( flow_pixel.value += ( upstream_flow_accum * upstream_flow_weight / - upstream_flow_dir_sum) + upstream_flow_dir_sum) if not preempted: flow_accum_managed_raster.set( flow_pixel.xi, flow_pixel.yi, @@ -2391,7 +2391,7 @@ def distance_to_channel_d8( """ # These variables are used to iterate over the DEM using `iterblock` # indexes - cdef numpy.ndarray[numpy.uint8_t, ndim=2] channel_buffer_array + cdef numpy.ndarray[numpy.uint8_t, ndim = 2] channel_buffer_array cdef int win_ysize, win_xsize, xoff, yoff # these variables are used as pixel or neighbor indexes. @@ -2464,7 +2464,7 @@ def distance_to_channel_d8( if ctime(NULL) - last_log_time > _LOGGING_PERIOD: last_log_time = ctime(NULL) current_pixel = xoff + yoff * raster_x_size - LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( raster_x_size * raster_y_size)) # make a buffer big enough to capture block and boundaries around it @@ -2575,8 +2575,8 @@ def distance_to_channel_mfd( """ # These variables are used to iterate over the DEM using `iterblock` # indexes - cdef numpy.ndarray[numpy.uint8_t, ndim=2] channel_buffer_array - cdef numpy.ndarray[numpy.int32_t, ndim=2] flow_dir_buffer_array + cdef numpy.ndarray[numpy.uint8_t, ndim = 2] channel_buffer_array + cdef numpy.ndarray[numpy.int32_t, ndim = 2] flow_dir_buffer_array cdef int win_ysize, win_xsize, xoff, yoff # these variables are used as pixel or neighbor indexes. @@ -2670,7 +2670,7 @@ def distance_to_channel_mfd( if ctime(NULL) - last_log_time > _LOGGING_PERIOD: last_log_time = ctime(NULL) current_pixel = xoff + yoff * raster_x_size - LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( raster_x_size * raster_y_size)) # make a buffer big enough to capture block and boundaries around it @@ -2732,7 +2732,7 @@ def distance_to_channel_mfd( continue compressed_flow_dir = ( - flow_dir_mfd_managed_raster.get( + < int > flow_dir_mfd_managed_raster.get( pixel.xi, pixel.yi)) preempted = 0 @@ -2749,7 +2749,6 @@ def distance_to_channel_mfd( yi_n < 0 or yi_n >= raster_y_size): continue - if visited_managed_raster.get(xi_n, yi_n) == 0: visited_managed_raster.set(xi_n, yi_n, 1) preempted = 1 @@ -2849,7 +2848,7 @@ def extract_streams_mfd( Returns: None. """ - if trace_threshold_proportion < 0.or trace_threshold_proportion > 1.0: + 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) @@ -2890,7 +2889,7 @@ def extract_streams_mfd( # this queue is used to march the front from the stream pixel or the # backwards front for tracing downstream cdef CoordinateQueueType open_set, backtrace_set - cdef int xi_bn, yi_bn # used for backtrace neighbor coordinates + cdef int xi_bn, yi_bn # used for backtrace neighbor coordinates cdef time_t last_log_time = ctime(NULL) @@ -2905,7 +2904,7 @@ def extract_streams_mfd( if ctime(NULL) - last_log_time > _LOGGING_PERIOD: last_log_time = ctime(NULL) current_pixel = xoff + yoff * raster_x_size - LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( raster_x_size * raster_y_size)) for xi in range(win_xsize): xi_root = xi+xoff @@ -2918,7 +2917,7 @@ def extract_streams_mfd( if flow_accum < flow_threshold: continue - flow_dir_mfd = flow_dir_mfd_mr.get(xi_root, yi_root) + flow_dir_mfd = 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: @@ -2950,13 +2949,13 @@ def extract_streams_mfd( if (xi_sn < 0 or xi_sn >= raster_x_size or yi_sn < 0 or yi_sn >= raster_y_size): continue - flow_dir_mfd = flow_dir_mfd_mr.get(xi_sn, yi_sn) + flow_dir_mfd = 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: # upstream pixel flows into this one - stream_val = stream_mr.get(xi_sn, yi_sn) + stream_val = 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) @@ -2972,7 +2971,7 @@ def extract_streams_mfd( xi_bn = backtrace_set.front().xi yi_bn = backtrace_set.front().yi backtrace_set.pop() - flow_dir_mfd = ( + flow_dir_mfd = ( flow_dir_mfd_mr.get(xi_bn, yi_bn)) for i_sn in range(8): if (flow_dir_mfd >> (i_sn*4)) & 0xF > 0: @@ -2982,7 +2981,8 @@ def extract_streams_mfd( 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) + stream_mr.set( + xi_sn, yi_sn, 1) backtrace_set.push( CoordinateType(xi_sn, yi_sn)) elif flow_accum >= trace_flow_threshold: @@ -3156,17 +3156,17 @@ def extract_strahler_streams_d8( cdef stack[StreamConnectivityPoint] source_point_stack cdef StreamConnectivityPoint source_stream_point - cdef int x_l=-1, y_l=-1 # the _l is for "local" aka "current" pixel + cdef int x_l = -1, y_l = -1 # the _l is for "local" aka "current" pixel # D8 backflow directions encoded as # 765 # 0x4 # 123 cdef int x_n, y_n # the _n is for "neighbor" - cdef int upstream_count=0, upstream_index + cdef int upstream_count = 0, upstream_index # this array is filled out as upstream directions are calculated and # indexed by `upstream_count` - cdef int *upstream_dirs = [0, 0, 0, 0, 0, 0, 0, 0] + cdef int * upstream_dirs = [0, 0, 0, 0, 0, 0, 0, 0] cdef long local_flow_accum # used to determine if source is a drain and should be tracked cdef int is_drain @@ -3201,17 +3201,17 @@ def extract_strahler_streams_d8( is_drain = 0 x_l = xoff + i y_l = yoff + j - local_flow_accum = flow_accum_managed_raster.get( + local_flow_accum = flow_accum_managed_raster.get( x_l, y_l) if local_flow_accum < min_flow_accum_threshold: continue # check to see if it's a drain - d_n = flow_dir_managed_raster.get(x_l, y_l) + d_n = flow_dir_managed_raster.get(x_l, y_l) x_n = x_l + D8_XOFFSET[d_n] y_n = y_l + D8_YOFFSET[d_n] if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_cols or - flow_dir_managed_raster.get( + flow_dir_managed_raster.get( x_n, y_n) == flow_nodata): is_drain = 1 @@ -3228,11 +3228,11 @@ def extract_strahler_streams_d8( # check if on border if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: continue - d_n = flow_dir_managed_raster.get(x_n, y_n) + d_n = flow_dir_managed_raster.get(x_n, y_n) if d_n == flow_nodata: continue if (D8_REVERSE_DIRECTION[d] == d_n and - flow_accum_managed_raster.get( + flow_accum_managed_raster.get( x_n, y_n) >= min_flow_accum_threshold): upstream_dirs[upstream_count] = d upstream_count += 1 @@ -3643,7 +3643,7 @@ def extract_strahler_streams_d8( multi_line = working_geom.Union(downstream_geom) joined_line = ogr.CreateGeometryFromWkb( shapely.ops.linemerge(shapely.wkb.loads( - multi_line.ExportToWkb())).wkb) + bytes(multi_line.ExportToWkb()))).wkb) downstream_feature.SetGeometry(joined_line) downstream_feature.SetField( @@ -3765,7 +3765,7 @@ def _build_discovery_finish_rasters( x_l = xoff + i y_l = yoff + j # check to see if this pixel is a drain - d_n = flow_dir_managed_raster.get(x_l, y_l) + d_n = flow_dir_managed_raster.get(x_l, y_l) if d_n == flow_dir_nodata: continue @@ -3774,7 +3774,7 @@ def _build_discovery_finish_rasters( y_n = y_l + D8_YOFFSET[d_n] if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows or - flow_dir_managed_raster.get( + flow_dir_managed_raster.get( x_n, y_n) == flow_dir_nodata): discovery_stack.push(CoordinateType(x_l, y_l)) finish_stack.push(FinishType(x_l, y_l, 1)) @@ -3797,7 +3797,7 @@ def _build_discovery_finish_rasters( if x_n < 0 or y_n < 0 or \ x_n >= n_cols or y_n >= n_rows: continue - n_dir = flow_dir_managed_raster.get(x_n, y_n) + n_dir = flow_dir_managed_raster.get(x_n, y_n) if n_dir == flow_dir_nodata: continue if D8_REVERSE_DIRECTION[test_dir] == n_dir: @@ -4003,7 +4003,7 @@ def calculate_subwatershed_boundary( visit_order_stack.pop() visit_order_stack.append((working_fid, ds_x, ds_y)) - cdef int edge_side, edge_dir, cell_to_test, out_dir_increase=-1 + cdef int edge_side, edge_dir, cell_to_test, out_dir_increase = -1 cdef int left, right, n_steps, terminated_early cdef int delta_x, delta_y cdef int _int_max_steps_per_watershed = max_steps_per_watershed @@ -4014,16 +4014,16 @@ def calculate_subwatershed_boundary( f'(calculate_subwatershed_boundary): watershed building ' f'{(index/len(visit_order_stack))*100:.1f}% complete') last_log_time = ctime(NULL) - discovery = discovery_managed_raster.get(x_l, y_l) + discovery = discovery_managed_raster.get(x_l, y_l) if discovery == -1: continue boundary_list = [(x_l, y_l)] - finish = finish_managed_raster.get(x_l, y_l) + finish = finish_managed_raster.get(x_l, y_l) outlet_x = x_l outlet_y = y_l watershed_boundary = ogr.Geometry(ogr.wkbLinearRing) - outflow_dir = d8_flow_dir_managed_raster.get(x_l, y_l) + outflow_dir = d8_flow_dir_managed_raster.get(x_l, y_l) # this is the center point of the pixel that will be offset to # make the edge @@ -4196,10 +4196,10 @@ def detect_outlets( cdef int xoff, yoff, win_xsize, win_ysize, xi, yi cdef int xi_root, yi_root, raster_x_size, raster_y_size cdef int flow_dir, flow_dir_n - cdef int next_id=0, n_dir, is_outlet + cdef int next_id = 0, n_dir, is_outlet cdef char x_off_border, y_off_border, win_xsize_border, win_ysize_border - cdef numpy.ndarray[numpy.npy_int32, ndim=2] flow_dir_block + cdef numpy.ndarray[numpy.npy_int32, ndim = 2] flow_dir_block raster_info = pygeoprocessing.get_raster_info( flow_dir_raster_path_band[0]) @@ -4335,7 +4335,7 @@ def detect_outlets( # entire MFD direction to the bit shifted 1111 mask, # if it equals 0 it means there was no proportional # flow in the `n_dir` direction. - if flow_dir&(0xF<<(n_dir*4)) == 0: + if flow_dir & (0xF << (n_dir*4)) == 0: continue flow_dir_n = flow_dir_block[ yi+D8_YOFFSET[n_dir], @@ -4426,7 +4426,7 @@ cdef void _diagonal_fill_step( (x_l - xdelta, y_l), (x_l, y_l - ydelta)] for x_t, y_t in test_list: - point_discovery = discovery_managed_raster.get( + point_discovery = discovery_managed_raster.get( x_t, y_t) if (point_discovery != discovery_nodata and point_discovery >= discovery and @@ -4467,7 +4467,7 @@ cdef int _in_watershed( cdef int y_n = y_l + D8_YOFFSET[direction_to_test] if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: return 0 - cdef long point_discovery = discovery_managed_raster.get(x_n, y_n) + cdef long point_discovery = discovery_managed_raster.get(x_n, y_n) return (point_discovery != discovery_nodata and point_discovery >= discovery and point_discovery <= finish) @@ -4515,7 +4515,7 @@ cdef _calculate_stream_geometry( Or ``None` if the point at (x_l, y_l) is below flow accum threshold. """ - cdef int x_1, y_1, x_n, y_n, d, d_n, stream_end=0, pixel_length + cdef int x_1, y_1, x_n, y_n, d, d_n, stream_end = 0, pixel_length if flow_accum_managed_raster.get(x_l, y_l) < flow_accum_threshold: return None @@ -4551,7 +4551,7 @@ cdef _calculate_stream_geometry( if (x_l, y_l) in coord_to_stream_ids: upstream_id_list = coord_to_stream_ids[(x_l, y_l)] del coord_to_stream_ids[(x_l, y_l)] - elif flow_accum_managed_raster.get(x_l, y_l) >= \ + elif < int > flow_accum_managed_raster.get(x_l, y_l) >= \ flow_accum_threshold: # check to see if we can take a step upstream for d in range(8): @@ -4563,15 +4563,15 @@ cdef _calculate_stream_geometry( continue # check for nodata - d_n = flow_dir_managed_raster.get(x_n, y_n) + d_n = flow_dir_managed_raster.get(x_n, y_n) if d_n == flow_dir_nodata: continue # check if there's an upstream inflow pixel with flow accum # greater than the threshold if D8_REVERSE_DIRECTION[d] == d_n and ( - flow_accum_managed_raster.get( - x_n, y_n) > flow_accum_threshold): + < int > flow_accum_managed_raster.get( + x_n, y_n) > flow_accum_threshold): stream_end = 0 next_dir = d break diff --git a/src/pygeoprocessing/routing/watershed.pyx b/src/pygeoprocessing/routing/watershed.pyx index 18f34c70..88d27d8a 100644 --- a/src/pygeoprocessing/routing/watershed.pyx +++ b/src/pygeoprocessing/routing/watershed.pyx @@ -1,5 +1,23 @@ # coding=UTF-8 # cython: language_level=3 +import pygeoprocessing +import shapely.wkb +import shapely.prepared +import shapely.geometry +import numpy +from osgeo import osr +from osgeo import ogr +from osgeo import gdal +from libcpp.set cimport set as cset +from libcpp.queue cimport queue +from libcpp.pair cimport pair +from libcpp.map cimport map as cmap +from libcpp.list cimport list as clist +from libc.time cimport time_t +from libc.time cimport time as ctime +from cython.operator cimport preincrement as inc +from cython.operator cimport dereference as deref +from cpython.mem cimport PyMem_Malloc, PyMem_Free import logging import os import shutil @@ -8,25 +26,7 @@ import time cimport cython cimport numpy -from cpython.mem cimport PyMem_Malloc, PyMem_Free -from cython.operator cimport dereference as deref -from cython.operator cimport preincrement as inc -from libc.time cimport time as ctime -from libc.time cimport time_t -from libcpp.list cimport list as clist -from libcpp.map cimport map as cmap -from libcpp.pair cimport pair -from libcpp.queue cimport queue -from libcpp.set cimport set as cset -from osgeo import gdal -from osgeo import ogr -from osgeo import osr -import numpy -import shapely.geometry -import shapely.prepared -import shapely.wkb -import pygeoprocessing LOGGER = logging.getLogger(__name__) @@ -45,18 +45,18 @@ GTIFF_CREATION_OPTIONS = ( # 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] -cdef int* NEIGHBOR_COL = [1, 1, 0, -1, -1, -1, 0, 1] -cdef int* NEIGHBOR_ROW = [0, -1, -1, -1, 0, 1, 1, 1] +cdef int * D8_REVERSE_DIRECTION = [4, 5, 6, 7, 0, 1, 2, 3] +cdef int * NEIGHBOR_COL = [1, 1, 0, -1, -1, -1, 0, 1] +cdef int * NEIGHBOR_ROW = [0, -1, -1, -1, 0, 1, 1, 1] # this is a least recently used cache written in C++ in an external file, # exposing here so _ManagedRaster can use it cdef extern from "LRUCache.h" nogil: cdef cppclass LRUCache[KEY_T, VAL_T]: LRUCache(int) - void put(KEY_T&, VAL_T&, clist[pair[KEY_T,VAL_T]]&) - clist[pair[KEY_T,VAL_T]].iterator begin() - clist[pair[KEY_T,VAL_T]].iterator end() + void put(KEY_T &, VAL_T&, clist[pair[KEY_T, VAL_T]]&) + clist[pair[KEY_T, VAL_T]].iterator begin() + clist[pair[KEY_T, VAL_T]].iterator end() bint exist(KEY_T &) VAL_T get(KEY_T &) @@ -67,7 +67,7 @@ ctypedef pair[int, int*] BlockBufferPair # a class to allow fast random per-pixel access to a raster for both setting # and reading pixels. cdef class _ManagedRaster: - cdef LRUCache[int, int*]* lru_cache + cdef LRUCache[int, int*] * lru_cache cdef cset[int] dirty_blocks cdef int block_xsize cdef int block_ysize @@ -160,7 +160,7 @@ cdef class _ManagedRaster: self.raster_y_size + (self.block_ysize) - 1) // self.block_ysize self.lru_cache = new LRUCache[int, int*](MANAGED_RASTER_N_BLOCKS) - self.raster_path = raster_path + self.raster_path = raster_path self.write_mode = write_mode self.closed = 0 @@ -185,9 +185,9 @@ cdef class _ManagedRaster: return self.closed = 1 cdef int xi_copy, yi_copy - cdef numpy.ndarray[int, ndim=2] block_array = numpy.empty( + cdef numpy.ndarray[int, ndim = 2] block_array = numpy.empty( (self.block_ysize, self.block_xsize), dtype=numpy.int32) - cdef int *int_buffer + cdef int * int_buffer cdef int block_xi cdef int block_yi # initially the win size is the same as the block size unless @@ -265,7 +265,7 @@ cdef class _ManagedRaster: self._load_block(block_index) self.lru_cache.get( block_index)[ - ((yi & (self.block_ymod))<block_index, int_buffer, removed_value_list) + < int > block_index, < int*>int_buffer, removed_value_list) if self.write_mode: raster = gdal.OpenEx( @@ -443,10 +443,10 @@ cdef cset[CoordinatePair] _c_split_geometry_into_seeds( geometry = shapely.wkb.loads(source_geom_wkb) minx, miny, maxx, maxy = geometry.bounds - cdef int minx_pixelcoord = ((minx - x_origin) // x_pixelwidth) - cdef int miny_pixelcoord = ((miny - y_origin) // y_pixelwidth) - cdef int maxx_pixelcoord = ((maxx - x_origin) // x_pixelwidth) - cdef int maxy_pixelcoord = ((maxy - y_origin) // y_pixelwidth) + cdef int minx_pixelcoord = ((minx - x_origin) // x_pixelwidth) + cdef int miny_pixelcoord = ((miny - y_origin) // y_pixelwidth) + cdef int maxx_pixelcoord = ((maxx - x_origin) // x_pixelwidth) + cdef int maxy_pixelcoord = ((maxy - y_origin) // y_pixelwidth) # If the geometry only intersects a single pixel, we can treat it # as a single point, which means that we can track it directly in our @@ -475,14 +475,17 @@ cdef cset[CoordinatePair] _c_split_geometry_into_seeds( # It's possible for a perfectly vertical or horizontal line to cover 0 rows # or columns, so defaulting to row/col count of 1 in these cases. - local_n_cols = max(abs(maxx_aligned - minx_aligned) // abs(x_pixelwidth), 1) - local_n_rows = max(abs(maxy_aligned - miny_aligned) // abs(y_pixelwidth), 1) + local_n_cols = max(abs(maxx_aligned - minx_aligned) // + abs(x_pixelwidth), 1) + local_n_rows = max(abs(maxy_aligned - miny_aligned) // + abs(y_pixelwidth), 1) # The geometry does not fit into a single pixel, so let's create a new # raster onto which to rasterize it. memory_driver = gdal.GetDriverByName('Memory') new_vector = memory_driver.Create('mem', 0, 0, 0, gdal.GDT_Unknown) - new_layer = new_vector.CreateLayer('user_geometry', flow_dir_srs, ogr.wkbUnknown) + new_layer = new_vector.CreateLayer( + 'user_geometry', flow_dir_srs, ogr.wkbUnknown) new_layer.StartTransaction() new_feature = ogr.Feature(new_layer.GetLayerDefn()) new_feature.SetGeometry(ogr.CreateGeometryFromWkb(source_geom_wkb)) @@ -528,12 +531,12 @@ cdef cset[CoordinatePair] _c_split_geometry_into_seeds( cdef int row, col cdef int global_row, global_col - cdef int seed_raster_origin_col = ((local_origin_x - x_origin) // x_pixelwidth) - cdef int seed_raster_origin_row = ((local_origin_y - y_origin) // y_pixelwidth) + cdef int seed_raster_origin_col = ((local_origin_x - x_origin) // x_pixelwidth) + cdef int seed_raster_origin_row = ((local_origin_y - y_origin) // y_pixelwidth) cdef dict block_info cdef int block_xoff cdef int block_yoff - cdef numpy.ndarray[numpy.npy_uint8, ndim=2] seed_array + cdef numpy.ndarray[numpy.npy_uint8, ndim = 2] seed_array for block_info, seed_array in pygeoprocessing.iterblocks( (target_raster_path, 1)): block_xoff = block_info['xoff'] @@ -705,7 +708,8 @@ def delineate_watersheds_d8( outflow_vector = gdal.OpenEx(outflow_vector_path, gdal.OF_VECTOR) if outflow_vector is None: - raise ValueError(u'Could not open outflow vector %s' % outflow_vector_path) + raise ValueError(u'Could not open outflow vector %s' % + outflow_vector_path) driver = ogr.GetDriverByName('GPKG') watersheds_srs = osr.SpatialReference() @@ -725,9 +729,9 @@ def delineate_watersheds_d8( index_field.SetWidth(24) polygonized_watersheds_layer.CreateField(index_field) - cdef int* reverse_flow = [4, 5, 6, 7, 0, 1, 2, 3] - cdef int* neighbor_col = [1, 1, 0, -1, -1, -1, 0, 1] - cdef int* neighbor_row = [0, -1, -1, -1, 0, 1, 1, 1] + cdef int * reverse_flow = [4, 5, 6, 7, 0, 1, 2, 3] + cdef int * neighbor_col = [1, 1, 0, -1, -1, -1, 0, 1] + cdef int * neighbor_row = [0, -1, -1, -1, 0, 1, 1, 1] cdef queue[CoordinatePair] process_queue cdef cset[CoordinatePair] process_queue_set cdef CoordinatePair neighbor_pixel @@ -760,7 +764,8 @@ def delineate_watersheds_d8( 'Outflow feature %s has empty geometry. Skipping.', current_fid) continue - geom_wkb = geom.ExportToWkb() + # with GDAL>=3.3.0 ExportToWkb returns a bytearray instead of bytes + geom_wkb = bytes(geom.ExportToWkb()) shapely_geom = shapely.wkb.loads(geom_wkb) LOGGER.debug('Testing geometry bbox') @@ -770,9 +775,11 @@ def delineate_watersheds_d8( 'direction raster. Skipping.', current_fid) continue - seeds_raster_path = os.path.join(working_dir_path, '%s_rasterized.tif' % ws_id) + seeds_raster_path = os.path.join( + working_dir_path, '%s_rasterized.tif' % ws_id) if write_diagnostic_vector: - diagnostic_vector_path = os.path.join(working_dir_path, '%s_seeds.gpkg' % ws_id) + diagnostic_vector_path = os.path.join( + working_dir_path, '%s_seeds.gpkg' % ws_id) else: diagnostic_vector_path = None seeds_in_watershed = _c_split_geometry_into_seeds( @@ -897,8 +904,10 @@ def delineate_watersheds_d8( # the whole scratch raster in order to polygonize. x1 = (flow_dir_origin_x + (max(ix_min-1, 0)*flow_dir_pixelsize_x)) # minx y1 = (flow_dir_origin_y + (max(iy_min-1, 0)*flow_dir_pixelsize_y)) # miny - x2 = (flow_dir_origin_x + (min(ix_max+1, flow_dir_n_cols)*flow_dir_pixelsize_x)) # maxx - y2 = (flow_dir_origin_y + (min(iy_max+1, flow_dir_n_rows)*flow_dir_pixelsize_y)) # maxy + x2 = (flow_dir_origin_x + (min(ix_max+1, flow_dir_n_cols) + * flow_dir_pixelsize_x)) # maxx + y2 = (flow_dir_origin_y + (min(iy_max+1, flow_dir_n_rows) + * flow_dir_pixelsize_y)) # maxy vrt_options = gdal.BuildVRTOptions( outputBounds=( @@ -911,7 +920,8 @@ def delineate_watersheds_d8( gdal.BuildVRT(vrt_path, [scratch_raster_path], options=vrt_options) # Polygonize this new watershed from the VRT. - vrt_raster = gdal.OpenEx(vrt_path, gdal.OF_RASTER, allowed_drivers=['VRT']) + vrt_raster = gdal.OpenEx( + vrt_path, gdal.OF_RASTER, allowed_drivers=['VRT']) vrt_band = vrt_raster.GetRasterBand(1) _ = gdal.Polygonize( vrt_band, # The source band @@ -973,7 +983,8 @@ def delineate_watersheds_d8( if duplicate_ids_set.size() == 1: duplicate_fid = deref(duplicate_ids_set_iterator) - source_feature = polygonized_watersheds_layer.GetFeature(duplicate_fid) + source_feature = polygonized_watersheds_layer.GetFeature( + duplicate_fid) new_geometry = source_feature.GetGeometryRef() else: new_geometry = ogr.Geometry(ogr.wkbMultiPolygon) @@ -981,7 +992,8 @@ def delineate_watersheds_d8( duplicate_fid = deref(duplicate_ids_set_iterator) inc(duplicate_ids_set_iterator) - duplicate_feature = polygonized_watersheds_layer.GetFeature(duplicate_fid) + duplicate_feature = polygonized_watersheds_layer.GetFeature( + duplicate_fid) duplicate_geometry = duplicate_feature.GetGeometryRef() new_geometry.AddGeometry(duplicate_geometry) diff --git a/tests/test_watershed_delineation.py b/tests/test_watershed_delineation.py index 2b9399dc..a074f021 100644 --- a/tests/test_watershed_delineation.py +++ b/tests/test_watershed_delineation.py @@ -18,6 +18,7 @@ class WatershedDelineationTests(unittest.TestCase): """Main Watershed test module.""" + def setUp(self): """Create empty workspace dir.""" self.workspace_dir = tempfile.mkdtemp() @@ -181,7 +182,7 @@ def test_watersheds_trivial(self): id_to_fields = {} for feature in watersheds_layer: geometry = feature.GetGeometryRef() - shapely_geom = shapely.wkb.loads(geometry.ExportToWkb()) + shapely_geom = shapely.wkb.loads(bytes(geometry.ExportToWkb())) self.assertEqual( shapely_geom.area, expected_watershed_geometry.area) self.assertEqual( From 9d45cb1e79e21b53695e35f235e75b281c95d498 Mon Sep 17 00:00:00 2001 From: emlys Date: Mon, 24 May 2021 11:40:39 -0600 Subject: [PATCH 02/10] add gdal 3.0.4 and 3.3.0 to gha matrix --- .github/workflows/pythonpackage.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 40cef62b..b0025ac7 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -13,6 +13,7 @@ jobs: matrix: python-version: [3.7, 3.8, 3.9] os: [ubuntu-latest, windows-latest, macos-latest] + gdal: [3.0.4, 3.3.0] steps: - uses: actions/checkout@v2 @@ -36,6 +37,7 @@ jobs: run: | conda install --file requirements.txt conda install $PACKAGES + conda install ${{ matrix.gdal }} python setup.py install - name: Lint with flake8 From 74198802aec1ccc57712daba91f47e90ce262d36 Mon Sep 17 00:00:00 2001 From: emlys Date: Mon, 24 May 2021 11:44:57 -0600 Subject: [PATCH 03/10] fix gha yml syntax --- .github/workflows/pythonpackage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index b0025ac7..80a31fb2 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -37,7 +37,7 @@ jobs: run: | conda install --file requirements.txt conda install $PACKAGES - conda install ${{ matrix.gdal }} + conda install gdal==${{ matrix.gdal }} python setup.py install - name: Lint with flake8 From e17018aaada6e1eb761cec82ab4a37d203a6e46d Mon Sep 17 00:00:00 2001 From: emlys Date: Mon, 24 May 2021 11:47:12 -0600 Subject: [PATCH 04/10] use include matrix so not so many test runs --- .github/workflows/pythonpackage.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 80a31fb2..5a9bcbf3 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -13,7 +13,13 @@ jobs: matrix: python-version: [3.7, 3.8, 3.9] os: [ubuntu-latest, windows-latest, macos-latest] - gdal: [3.0.4, 3.3.0] + include: + - python-version: 3.7 + gdal: 3.0.4 + - python-version: 3.8 + gdal: 3.2.0 + - python-version: 3.9 + gdal: 3.3.0 steps: - uses: actions/checkout@v2 From 1727f69063f76f283022721720a3d2eeae12dee3 Mon Sep 17 00:00:00 2001 From: emlys Date: Mon, 24 May 2021 13:06:11 -0600 Subject: [PATCH 05/10] Revert "fixes #149 just testing for the issue and raising a helpful exception and error message if there's an issue" This reverts commit d1941307a93324fe655bec4add3ac369da4a56a0. --- src/pygeoprocessing/geoprocessing.py | 29 +++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/pygeoprocessing/geoprocessing.py b/src/pygeoprocessing/geoprocessing.py index 0c59a8a5..997a8eee 100644 --- a/src/pygeoprocessing/geoprocessing.py +++ b/src/pygeoprocessing/geoprocessing.py @@ -1005,17 +1005,24 @@ def create_raster_from_vector_extents( shp_extent = None for layer_index in range(vector.GetLayerCount()): layer = vector.GetLayer(layer_index) - if layer.GetFeatureCount() == 0: - continue - layer_extent = layer.GetExtent() - if shp_extent is None: - shp_extent = list(layer_extent) - else: - # expand bounds of current bounding box to include that - # of the newest feature - shp_extent = [ - f(shp_extent[index], layer_extent[index]) - for index, f in enumerate([min, max, min, max])] + for feature in layer: + try: + # envelope is [xmin, xmax, ymin, ymax] + feature_extent = feature.GetGeometryRef().GetEnvelope() + if shp_extent is None: + shp_extent = list(feature_extent) + else: + # expand bounds of current bounding box to include that + # of the newest feature + shp_extent = [ + f(shp_extent[index], feature_extent[index]) + for index, f in enumerate([min, max, min, max])] + except AttributeError as error: + # For some valid OGR objects the geometry can be undefined + # since it's valid to have a NULL entry in the attribute table + # this is expressed as a None value in the geometry reference + # this feature won't contribute + LOGGER.warning(error) layer = None if shp_extent is None: From 4200805ec8670cdbe9a45d465c5cc3066508bbb5 Mon Sep 17 00:00:00 2001 From: emlys Date: Wed, 2 Jun 2021 14:43:27 -0400 Subject: [PATCH 06/10] remove gdal 3.0.4 from matrix --- .github/workflows/pythonpackage.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 5a9bcbf3..20be683b 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -12,14 +12,8 @@ jobs: max-parallel: 4 matrix: python-version: [3.7, 3.8, 3.9] + gdal: [3.2.2, 3.3.0] os: [ubuntu-latest, windows-latest, macos-latest] - include: - - python-version: 3.7 - gdal: 3.0.4 - - python-version: 3.8 - gdal: 3.2.0 - - python-version: 3.9 - gdal: 3.3.0 steps: - uses: actions/checkout@v2 From 0df5e54b12582844876c6261eb4f324487f095d8 Mon Sep 17 00:00:00 2001 From: emlys Date: Tue, 8 Jun 2021 10:21:16 -0400 Subject: [PATCH 07/10] undo autopep8 stuff --- src/pygeoprocessing/geoprocessing.py | 25 +- src/pygeoprocessing/geoprocessing_core.cpp | 38436 +++++++++++ src/pygeoprocessing/routing/routing.cpp | 65695 +++++++++++++++++++ src/pygeoprocessing/routing/routing.pyx | 452 +- src/pygeoprocessing/routing/watershed.cpp | 21754 ++++++ src/pygeoprocessing/routing/watershed.pyx | 122 +- 6 files changed, 126268 insertions(+), 216 deletions(-) create mode 100644 src/pygeoprocessing/geoprocessing_core.cpp create mode 100644 src/pygeoprocessing/routing/routing.cpp create mode 100644 src/pygeoprocessing/routing/watershed.cpp diff --git a/src/pygeoprocessing/geoprocessing.py b/src/pygeoprocessing/geoprocessing.py index 997a8eee..cdb3f3e3 100644 --- a/src/pygeoprocessing/geoprocessing.py +++ b/src/pygeoprocessing/geoprocessing.py @@ -767,7 +767,7 @@ def align_and_resize_raster_stack( vector_mask_options['mask_vector_where_filter']) mask_bounding_box = merge_bounding_box_list( [[feature.GetGeometryRef().GetEnvelope()[i] - for i in [0, 2, 1, 3]] for feature in mask_layer], + for i in [0, 2, 1, 3]] for feature in mask_layer], 'union') mask_layer = None mask_vector = None @@ -779,8 +779,8 @@ def align_and_resize_raster_stack( if mask_vector_projection_wkt is not None and \ target_projection_wkt is not None: mask_vector_bb = transform_bounding_box( - mask_bounding_box, mask_vector_info['projection_wkt'], - target_projection_wkt) + mask_bounding_box, mask_vector_info['projection_wkt'], + target_projection_wkt) else: mask_vector_bb = mask_vector_info['bounding_box'] # Calling `merge_bounding_box_list` will raise an ValueError if the @@ -814,8 +814,8 @@ def align_and_resize_raster_stack( raster_driver_creation_tuple=(raster_driver_creation_tuple), target_projection_wkt=target_projection_wkt, base_projection_wkt=( - None if not base_projection_wkt_list else - base_projection_wkt_list[index]), + None if not base_projection_wkt_list else + base_projection_wkt_list[index]), vector_mask_options=vector_mask_options, gdal_warp_options=gdal_warp_options) LOGGER.info( @@ -1227,7 +1227,7 @@ def zonal_statistics( 'options': [ 'ALL_TOUCHED=FALSE', 'ATTRIBUTE=%s' % local_aggregate_field_name] - } + } # clip base raster to aggregating vector intersection raster_info = get_raster_info(base_raster_path_band[0]) @@ -2239,8 +2239,8 @@ def calculate_disjoint_polygon_set( f'no geometry in {vector_path} FID: {poly_feat.GetFID()}, ' 'skipping...') continue + # with GDAL>=3.3.0 ExportToWkb returns a bytearray instead of bytes shapely_polygon_lookup[poly_feat.GetFID()] = ( - # with GDAL>=3.3.0 ExportToWkb returns a bytesarray instead of bytes shapely.wkb.loads(bytes(poly_geom_ref.ExportToWkb()))) poly_geom_ref = None poly_feat = None @@ -2614,6 +2614,7 @@ def convolve_2d( signal_path_band[0], target_path, target_datatype, [0], raster_driver_creation_tuple=raster_driver_creation_tuple) + n_cols_signal, n_rows_signal = signal_raster_info['raster_size'] n_cols_kernel, n_rows_kernel = kernel_raster_info['raster_size'] s_path_band = signal_path_band @@ -3835,7 +3836,7 @@ def _mult_op(base_array, base_nodata, scale, datatype): [(base_stitch_raster_path, 1), (base_stitch_nodata, 'raw'), m2_area_per_lat/base_pixel_area_m2, (_GDAL_TYPE_TO_NUMPY_LOOKUP[ - target_raster_info['datatype']], 'raw')], _mult_op, + target_raster_info['datatype']], 'raw')], _mult_op, scaled_raster_path, target_raster_info['datatype'], base_stitch_nodata) @@ -3859,10 +3860,10 @@ def _mult_op(base_array, base_nodata, scale, datatype): overlap = True for (target_to_base_off, off_val, target_off_id, off_clip_id, win_size_id) in [ - (target_to_base_xoff, offset_dict['xoff'], - 'target_xoff', 'xoff_clip', 'win_xsize'), - (target_to_base_yoff, offset_dict['yoff'], - 'target_yoff', 'yoff_clip', 'win_ysize')]: + (target_to_base_xoff, offset_dict['xoff'], + 'target_xoff', 'xoff_clip', 'win_xsize'), + (target_to_base_yoff, offset_dict['yoff'], + 'target_yoff', 'yoff_clip', 'win_ysize')]: _offset_vars[target_off_id] = (target_to_base_off+off_val) if _offset_vars[target_off_id] > target_raster_x_size: overlap = False diff --git a/src/pygeoprocessing/geoprocessing_core.cpp b/src/pygeoprocessing/geoprocessing_core.cpp new file mode 100644 index 00000000..5e5fc643 --- /dev/null +++ b/src/pygeoprocessing/geoprocessing_core.cpp @@ -0,0 +1,38436 @@ +/* Generated by Cython 0.29.23 */ + +#ifndef PY_SSIZE_T_CLEAN +#define PY_SSIZE_T_CLEAN +#endif /* 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_29_23" +#define CYTHON_HEX_VERSION 0x001D17F0 +#define CYTHON_FUTURE_DIVISION 1 +#include +#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 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 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 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 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 (PY_VERSION_HEX >= 0x03050000) + #endif + #ifndef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1) + #endif + #ifndef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1) + #endif + #ifndef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3) + #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 + #ifdef SIZEOF_VOID_P + enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) }; + #endif +#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 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 +#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 +void __Pyx_call_destructor(T& x) { + x.~T(); +} +template +class __Pyx_FakeReference { + public: + __Pyx_FakeReference() : ptr(NULL) { } + __Pyx_FakeReference(const T& ref) : ptr(const_cast(&ref)) { } + T *operator->() { return ptr; } + T *operator&() { return ptr; } + operator T&() { return *ptr; } + template bool operator ==(U other) { return *ptr == other; } + template 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" +#if PY_VERSION_HEX >= 0x030800A4 && PY_VERSION_HEX < 0x030800B2 + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#else + #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) +#endif + #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 +#ifndef METH_STACKLESS + #define METH_STACKLESS 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 | METH_STACKLESS))))) +#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_CPYTHON && PY_VERSION_HEX < 0x030400A1 + #define PyMem_RawMalloc(n) PyMem_Malloc(n) + #define PyMem_RawRealloc(p, n) PyMem_Realloc(p, n) + #define PyMem_RawFree(p) PyMem_Free(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; +} +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 +#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) + #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) + #else + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) + #endif +#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 || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) +#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? 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 +#ifndef PyObject_Unicode + #define PyObject_Unicode PyObject_Str +#endif +#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 PY_VERSION_HEX >= 0x030900A4 + #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt) + #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size) +#else + #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt) + #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size) +#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) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(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 +#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_MARK_ERR_POS(f_index, lineno) \ + { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; } +#define __PYX_ERR(f_index, lineno, Ln_error) \ + { __PYX_MARK_ERR_POS(f_index, lineno) 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__geoprocessing_core +#define __PYX_HAVE_API__pygeoprocessing__geoprocessing_core +/* Early includes */ +#include +#include +#include +#include "numpy/arrayobject.h" +#include "numpy/ndarrayobject.h" +#include "numpy/ndarraytypes.h" +#include "numpy/arrayscalars.h" +#include "numpy/ufuncobject.h" + + /* NumPy API declarations from "numpy/__init__.pxd" */ + +#include "ios" +#include "new" +#include "stdexcept" +#include "typeinfo" +#include +#include "FastFileIterator.h" +#include "pythread.h" +#include +#include "pystate.h" +#ifdef _OPENMP +#include +#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_UTF8 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8) +#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))) ) +static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) { + return (size_t) i < (size_t) limit; +} +#if defined (__cplusplus) && __cplusplus >= 201103L + #include + #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 int __Pyx_PyObject_IsTrueAndDecref(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) + 1); + 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 + #else + #include + #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/geoprocessing_core.pyx", + "__init__.pxd", + "stringsource", + "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; + +/* NoFastGil.proto */ +#define __Pyx_PyGILState_Ensure PyGILState_Ensure +#define __Pyx_PyGILState_Release PyGILState_Release +#define __Pyx_FastGIL_Remember() +#define __Pyx_FastGIL_Forget() +#define __Pyx_FastGilFuncInit() + +/* ForceInitThreads.proto */ +#ifndef __PYX_FORCE_INIT_THREADS + #define __PYX_FORCE_INIT_THREADS 0 +#endif + +/* MemviewSliceStruct.proto */ +struct __pyx_memoryview_obj; +typedef struct { + struct __pyx_memoryview_obj *memview; + char *data; + Py_ssize_t shape[8]; + Py_ssize_t strides[8]; + Py_ssize_t suboffsets[8]; +} __Pyx_memviewslice; +#define __Pyx_MemoryView_Len(m) (m.shape[0]) + +/* Atomics.proto */ +#include +#ifndef CYTHON_ATOMICS + #define CYTHON_ATOMICS 1 +#endif +#define __pyx_atomic_int_type int +#if CYTHON_ATOMICS && __GNUC__ >= 4 && (__GNUC_MINOR__ > 1 ||\ + (__GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL >= 2)) &&\ + !defined(__i386__) + #define __pyx_atomic_incr_aligned(value, lock) __sync_fetch_and_add(value, 1) + #define __pyx_atomic_decr_aligned(value, lock) __sync_fetch_and_sub(value, 1) + #ifdef __PYX_DEBUG_ATOMICS + #warning "Using GNU atomics" + #endif +#elif CYTHON_ATOMICS && defined(_MSC_VER) && 0 + #include + #undef __pyx_atomic_int_type + #define __pyx_atomic_int_type LONG + #define __pyx_atomic_incr_aligned(value, lock) InterlockedIncrement(value) + #define __pyx_atomic_decr_aligned(value, lock) InterlockedDecrement(value) + #ifdef __PYX_DEBUG_ATOMICS + #pragma message ("Using MSVC atomics") + #endif +#elif CYTHON_ATOMICS && (defined(__ICC) || defined(__INTEL_COMPILER)) && 0 + #define __pyx_atomic_incr_aligned(value, lock) _InterlockedIncrement(value) + #define __pyx_atomic_decr_aligned(value, lock) _InterlockedDecrement(value) + #ifdef __PYX_DEBUG_ATOMICS + #warning "Using Intel atomics" + #endif +#else + #undef CYTHON_ATOMICS + #define CYTHON_ATOMICS 0 + #ifdef __PYX_DEBUG_ATOMICS + #warning "Not using atomics" + #endif +#endif +typedef volatile __pyx_atomic_int_type __pyx_atomic_int; +#if CYTHON_ATOMICS + #define __pyx_add_acquisition_count(memview)\ + __pyx_atomic_incr_aligned(__pyx_get_slice_count_pointer(memview), memview->lock) + #define __pyx_sub_acquisition_count(memview)\ + __pyx_atomic_decr_aligned(__pyx_get_slice_count_pointer(memview), memview->lock) +#else + #define __pyx_add_acquisition_count(memview)\ + __pyx_add_acquisition_count_locked(__pyx_get_slice_count_pointer(memview), memview->lock) + #define __pyx_sub_acquisition_count(memview)\ + __pyx_sub_acquisition_count_locked(__pyx_get_slice_count_pointer(memview), memview->lock) +#endif + + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":690 + * # 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":691 + * + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":692 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":693 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":697 + * #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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":698 + * + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":699 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":700 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":704 + * #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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":705 + * + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":714 + * # 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":715 + * # 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":716 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":718 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":719 + * + * ctypedef npy_ulong uint_t + * ctypedef npy_ulonglong ulong_t # <<<<<<<<<<<<<< + * ctypedef npy_ulonglong ulonglong_t + * + */ +typedef npy_ulonglong __pyx_t_5numpy_ulong_t; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":720 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":722 + * ctypedef npy_ulonglong ulonglong_t + * + * ctypedef npy_intp intp_t # <<<<<<<<<<<<<< + * ctypedef npy_uintp uintp_t + * + */ +typedef npy_intp __pyx_t_5numpy_intp_t; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":723 + * + * ctypedef npy_intp intp_t + * ctypedef npy_uintp uintp_t # <<<<<<<<<<<<<< + * + * ctypedef npy_double float_t + */ +typedef npy_uintp __pyx_t_5numpy_uintp_t; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":725 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":726 + * + * ctypedef npy_double float_t + * ctypedef npy_double double_t # <<<<<<<<<<<<<< + * ctypedef npy_longdouble longdouble_t + * + */ +typedef npy_double __pyx_t_5numpy_double_t; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":727 + * 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; + +/* "pygeoprocessing/geoprocessing_core.pyx":621 + * + * + * ctypedef long long int64t # <<<<<<<<<<<<<< + * ctypedef FastFileIterator[long long]* FastFileIteratorLongLongIntPtr + * ctypedef FastFileIterator[double]* FastFileIteratorDoublePtr + */ +typedef PY_LONG_LONG __pyx_t_15pygeoprocessing_18geoprocessing_core_int64t; +/* 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_array_obj; +struct __pyx_MemviewEnum_obj; +struct __pyx_memoryview_obj; +struct __pyx_memoryviewslice_obj; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":729 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":730 + * + * ctypedef npy_cfloat cfloat_t + * ctypedef npy_cdouble cdouble_t # <<<<<<<<<<<<<< + * ctypedef npy_clongdouble clongdouble_t + * + */ +typedef npy_cdouble __pyx_t_5numpy_cdouble_t; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":731 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":733 + * ctypedef npy_clongdouble clongdouble_t + * + * ctypedef npy_cdouble complex_t # <<<<<<<<<<<<<< + * + * cdef inline object PyArray_MultiIterNew1(a): + */ +typedef npy_cdouble __pyx_t_5numpy_complex_t; + +/* "pygeoprocessing/geoprocessing_core.pyx":622 + * + * ctypedef long long int64t + * ctypedef FastFileIterator[long long]* FastFileIteratorLongLongIntPtr # <<<<<<<<<<<<<< + * ctypedef FastFileIterator[double]* FastFileIteratorDoublePtr + * + */ +typedef FastFileIterator *__pyx_t_15pygeoprocessing_18geoprocessing_core_FastFileIteratorLongLongIntPtr; + +/* "pygeoprocessing/geoprocessing_core.pyx":623 + * ctypedef long long int64t + * ctypedef FastFileIterator[long long]* FastFileIteratorLongLongIntPtr + * ctypedef FastFileIterator[double]* FastFileIteratorDoublePtr # <<<<<<<<<<<<<< + * + * + */ +typedef FastFileIterator *__pyx_t_15pygeoprocessing_18geoprocessing_core_FastFileIteratorDoublePtr; + +/* "View.MemoryView":105 + * + * @cname("__pyx_array") + * cdef class array: # <<<<<<<<<<<<<< + * + * cdef: + */ +struct __pyx_array_obj { + PyObject_HEAD + struct __pyx_vtabstruct_array *__pyx_vtab; + char *data; + Py_ssize_t len; + char *format; + int ndim; + Py_ssize_t *_shape; + Py_ssize_t *_strides; + Py_ssize_t itemsize; + PyObject *mode; + PyObject *_format; + void (*callback_free_data)(void *); + int free_data; + int dtype_is_object; +}; + + +/* "View.MemoryView":279 + * + * @cname('__pyx_MemviewEnum') + * cdef class Enum(object): # <<<<<<<<<<<<<< + * cdef object name + * def __init__(self, name): + */ +struct __pyx_MemviewEnum_obj { + PyObject_HEAD + PyObject *name; +}; + + +/* "View.MemoryView":330 + * + * @cname('__pyx_memoryview') + * cdef class memoryview(object): # <<<<<<<<<<<<<< + * + * cdef object obj + */ +struct __pyx_memoryview_obj { + PyObject_HEAD + struct __pyx_vtabstruct_memoryview *__pyx_vtab; + PyObject *obj; + PyObject *_size; + PyObject *_array_interface; + PyThread_type_lock lock; + __pyx_atomic_int acquisition_count[2]; + __pyx_atomic_int *acquisition_count_aligned_p; + Py_buffer view; + int flags; + int dtype_is_object; + __Pyx_TypeInfo *typeinfo; +}; + + +/* "View.MemoryView":965 + * + * @cname('__pyx_memoryviewslice') + * cdef class _memoryviewslice(memoryview): # <<<<<<<<<<<<<< + * "Internal class for passing memoryview slices to Python" + * + */ +struct __pyx_memoryviewslice_obj { + struct __pyx_memoryview_obj __pyx_base; + __Pyx_memviewslice from_slice; + PyObject *from_object; + PyObject *(*to_object_func)(char *); + int (*to_dtype_func)(char *, PyObject *); +}; + + + +/* "View.MemoryView":105 + * + * @cname("__pyx_array") + * cdef class array: # <<<<<<<<<<<<<< + * + * cdef: + */ + +struct __pyx_vtabstruct_array { + PyObject *(*get_memview)(struct __pyx_array_obj *); +}; +static struct __pyx_vtabstruct_array *__pyx_vtabptr_array; + + +/* "View.MemoryView":330 + * + * @cname('__pyx_memoryview') + * cdef class memoryview(object): # <<<<<<<<<<<<<< + * + * cdef object obj + */ + +struct __pyx_vtabstruct_memoryview { + char *(*get_item_pointer)(struct __pyx_memoryview_obj *, PyObject *); + PyObject *(*is_slice)(struct __pyx_memoryview_obj *, PyObject *); + PyObject *(*setitem_slice_assignment)(struct __pyx_memoryview_obj *, PyObject *, PyObject *); + PyObject *(*setitem_slice_assign_scalar)(struct __pyx_memoryview_obj *, struct __pyx_memoryview_obj *, PyObject *); + PyObject *(*setitem_indexed)(struct __pyx_memoryview_obj *, PyObject *, PyObject *); + PyObject *(*convert_item_to_object)(struct __pyx_memoryview_obj *, char *); + PyObject *(*assign_item_from_object)(struct __pyx_memoryview_obj *, char *, PyObject *); +}; +static struct __pyx_vtabstruct_memoryview *__pyx_vtabptr_memoryview; + + +/* "View.MemoryView":965 + * + * @cname('__pyx_memoryviewslice') + * cdef class _memoryviewslice(memoryview): # <<<<<<<<<<<<<< + * "Internal class for passing memoryview slices to Python" + * + */ + +struct __pyx_vtabstruct__memoryviewslice { + struct __pyx_vtabstruct_memoryview __pyx_base; +}; +static struct __pyx_vtabstruct__memoryviewslice *__pyx_vtabptr__memoryviewslice; + +/* --- 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); + +/* PyDictVersioning.proto */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +#define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1) +#define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\ + (version_var) = __PYX_GET_DICT_VERSION(dict);\ + (cache_var) = (value); +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\ + (VAR) = __pyx_dict_cached_value;\ + } else {\ + (VAR) = __pyx_dict_cached_value = (LOOKUP);\ + __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\ + }\ +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj); +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj); +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version); +#else +#define __PYX_GET_DICT_VERSION(dict) (0) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP); +#endif + +/* GetModuleGlobalName.proto */ +#if CYTHON_USE_DICT_VERSIONS +#define __Pyx_GetModuleGlobalName(var, name) {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\ + (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\ + __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ +} +#define __Pyx_GetModuleGlobalNameUncached(var, name) {\ + PY_UINT64_T __pyx_dict_version;\ + PyObject *__pyx_dict_cached_value;\ + (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ +} +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); +#else +#define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name) +#define __Pyx_GetModuleGlobalNameUncached(var, name) (var) = __Pyx__GetModuleGlobalName(name) +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name); +#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, Py_ssize_t nargs, PyObject *kwargs); +#else +#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs) +#endif +#define __Pyx_BUILD_ASSERT_EXPR(cond)\ + (sizeof(char [1 - 2*!(cond)]) - 1) +#ifndef Py_MEMBER_SIZE +#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member) +#endif + static size_t __pyx_pyframe_localsplus_offset = 0; + #include "frameobject.h" + #define __Pxy_PyFrame_Initialize_Offsets()\ + ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\ + (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus))) + #define __Pyx_PyFrame_GetLocalsplus(frame)\ + (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset)) +#endif + +/* 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 + +/* 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 + +/* PyObjectCall2Args.proto */ +static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2); + +/* 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); + +/* 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 + +/* 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 + +/* 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); + +/* 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 }; + +/* BufferFallbackError.proto */ +static void __Pyx_RaiseBufferFallbackError(void); + +/* PyIntCompare.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, long intval, long inplace); + +/* 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 + +#define __Pyx_BufPtrStrided2d(type, buf, i0, s0, i1, s1) (type)((char*)buf + i0 * s0 + i1 * s1) +#define __Pyx_BufPtrStrided1d(type, buf, i0, s0) (type)((char*)buf + i0 * s0) +/* 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 + +/* 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); + +/* PyIntBinop.proto */ +#if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check); +#else +#define __Pyx_PyInt_SubtractObjC(op1, op2, intval, inplace, zerodivision_check)\ + (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, int zerodivision_check); +#else +#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace, zerodivision_check)\ + (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2)) +#endif + +/* PyObjectGetMethod.proto */ +static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method); + +/* PyObjectCallMethod0.proto */ +static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name); + +/* RaiseNoneIterError.proto */ +static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void); + +/* UnpackTupleError.proto */ +static void __Pyx_UnpackTupleError(PyObject *, Py_ssize_t index); + +/* UnpackTuple2.proto */ +#define __Pyx_unpack_tuple2(tuple, value1, value2, is_tuple, has_known_size, decref_tuple)\ + (likely(is_tuple || PyTuple_Check(tuple)) ?\ + (likely(has_known_size || PyTuple_GET_SIZE(tuple) == 2) ?\ + __Pyx_unpack_tuple2_exact(tuple, value1, value2, decref_tuple) :\ + (__Pyx_UnpackTupleError(tuple, 2), -1)) :\ + __Pyx_unpack_tuple2_generic(tuple, value1, value2, has_known_size, decref_tuple)) +static CYTHON_INLINE int __Pyx_unpack_tuple2_exact( + PyObject* tuple, PyObject** value1, PyObject** value2, int decref_tuple); +static int __Pyx_unpack_tuple2_generic( + PyObject* tuple, PyObject** value1, PyObject** value2, int has_known_size, int decref_tuple); + +/* dict_iter.proto */ +static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* dict, int is_dict, PyObject* method_name, + Py_ssize_t* p_orig_length, int* p_is_dict); +static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* dict_or_iter, Py_ssize_t orig_length, Py_ssize_t* ppos, + PyObject** pkey, PyObject** pvalue, PyObject** pitem, int is_dict); + +/* MergeKeywords.proto */ +static int __Pyx_MergeKeywords(PyObject *kwdict, PyObject *source_mapping); + +/* PyObjectFormatSimple.proto */ +#if CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyObject_FormatSimple(s, f) (\ + likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ + PyObject_Format(s, f)) +#elif PY_MAJOR_VERSION < 3 + #define __Pyx_PyObject_FormatSimple(s, f) (\ + likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ + likely(PyString_CheckExact(s)) ? PyUnicode_FromEncodedObject(s, NULL, "strict") :\ + PyObject_Format(s, f)) +#elif CYTHON_USE_TYPE_SLOTS + #define __Pyx_PyObject_FormatSimple(s, f) (\ + likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ + likely(PyLong_CheckExact(s)) ? PyLong_Type.tp_str(s) :\ + likely(PyFloat_CheckExact(s)) ? PyFloat_Type.tp_str(s) :\ + PyObject_Format(s, f)) +#else + #define __Pyx_PyObject_FormatSimple(s, f) (\ + likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ + PyObject_Format(s, f)) +#endif + +/* GetTopmostException.proto */ +#if CYTHON_USE_EXC_INFO_STACK +static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate); +#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 + +/* 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 + +/* SwapException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_ExceptionSwap(type, value, tb) __Pyx__ExceptionSwap(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#else +static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb); +#endif + +/* RaiseException.proto */ +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); + +/* PyObjectFormat.proto */ +#if CYTHON_USE_UNICODE_WRITER +static PyObject* __Pyx_PyObject_Format(PyObject* s, PyObject* f); +#else +#define __Pyx_PyObject_Format(s, f) PyObject_Format(s, f) +#endif + +/* GCCDiagnostics.proto */ +#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) +#define __Pyx_HAS_GCC_DIAGNOSTIC +#endif + +/* BuildPyUnicode.proto */ +static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, char* chars, int clength, + int prepend_sign, char padding_char); + +/* CIntToPyUnicode.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_PY_LONG_LONG(PY_LONG_LONG value, Py_ssize_t width, char padding_char, char format_char); + +/* IncludeStringH.proto */ +#include + +/* JoinPyUnicode.proto */ +static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength, + Py_UCS4 max_char); + +/* MemviewSliceInit.proto */ +#define __Pyx_BUF_MAX_NDIMS %(BUF_MAX_NDIMS)d +#define __Pyx_MEMVIEW_DIRECT 1 +#define __Pyx_MEMVIEW_PTR 2 +#define __Pyx_MEMVIEW_FULL 4 +#define __Pyx_MEMVIEW_CONTIG 8 +#define __Pyx_MEMVIEW_STRIDED 16 +#define __Pyx_MEMVIEW_FOLLOW 32 +#define __Pyx_IS_C_CONTIG 1 +#define __Pyx_IS_F_CONTIG 2 +static int __Pyx_init_memviewslice( + struct __pyx_memoryview_obj *memview, + int ndim, + __Pyx_memviewslice *memviewslice, + int memview_is_new_reference); +static CYTHON_INLINE int __pyx_add_acquisition_count_locked( + __pyx_atomic_int *acquisition_count, PyThread_type_lock lock); +static CYTHON_INLINE int __pyx_sub_acquisition_count_locked( + __pyx_atomic_int *acquisition_count, PyThread_type_lock lock); +#define __pyx_get_slice_count_pointer(memview) (memview->acquisition_count_aligned_p) +#define __pyx_get_slice_count(memview) (*__pyx_get_slice_count_pointer(memview)) +#define __PYX_INC_MEMVIEW(slice, have_gil) __Pyx_INC_MEMVIEW(slice, have_gil, __LINE__) +#define __PYX_XDEC_MEMVIEW(slice, have_gil) __Pyx_XDEC_MEMVIEW(slice, have_gil, __LINE__) +static CYTHON_INLINE void __Pyx_INC_MEMVIEW(__Pyx_memviewslice *, int, int); +static CYTHON_INLINE void __Pyx_XDEC_MEMVIEW(__Pyx_memviewslice *, int, int); + +/* ListAppend.proto */ +#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS +static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) { + PyListObject* L = (PyListObject*) list; + Py_ssize_t len = Py_SIZE(list); + if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) { + Py_INCREF(x); + PyList_SET_ITEM(list, len, x); + __Pyx_SET_SIZE(list, len + 1); + return 0; + } + return PyList_Append(list, x); +} +#else +#define __Pyx_PyList_Append(L,x) PyList_Append(L,x) +#endif + +/* BufferIndexError.proto */ +static void __Pyx_RaiseBufferIndexError(int axis); + +/* ArgTypeTest.proto */ +#define __Pyx_ArgTypeTest(obj, type, none_allowed, name, exact)\ + ((likely((Py_TYPE(obj) == type) | (none_allowed && (obj == Py_None)))) ? 1 :\ + __Pyx__ArgTypeTest(obj, type, name, exact)) +static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact); + +/* BytesEquals.proto */ +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); + +/* UnicodeEquals.proto */ +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); + +/* StrEquals.proto */ +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals +#else +#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals +#endif + +/* None.proto */ +static CYTHON_INLINE Py_ssize_t __Pyx_div_Py_ssize_t(Py_ssize_t, Py_ssize_t); + +/* UnaryNegOverflows.proto */ +#define UNARY_NEG_WOULD_OVERFLOW(x)\ + (((x) < 0) & ((unsigned long)(x) == 0-(unsigned long)(x))) + +static CYTHON_UNUSED int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ +static PyObject *__pyx_array_get_memview(struct __pyx_array_obj *); /*proto*/ +/* GetAttr.proto */ +static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *); + +/* decode_c_string_utf16.proto */ +static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16(const char *s, Py_ssize_t size, const char *errors) { + int byteorder = 0; + return PyUnicode_DecodeUTF16(s, size, errors, &byteorder); +} +static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16LE(const char *s, Py_ssize_t size, const char *errors) { + int byteorder = -1; + return PyUnicode_DecodeUTF16(s, size, errors, &byteorder); +} +static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16BE(const char *s, Py_ssize_t size, const char *errors) { + int byteorder = 1; + return PyUnicode_DecodeUTF16(s, size, errors, &byteorder); +} + +/* decode_c_string.proto */ +static CYTHON_INLINE PyObject* __Pyx_decode_c_string( + const char* cstring, Py_ssize_t start, Py_ssize_t stop, + const char* encoding, const char* errors, + PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)); + +/* GetAttr3.proto */ +static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *); + +/* Import.proto */ +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); + +/* 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) + +static CYTHON_UNUSED int __pyx_memoryview_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ +/* ListCompAppend.proto */ +#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS +static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) { + PyListObject* L = (PyListObject*) list; + Py_ssize_t len = Py_SIZE(list); + if (likely(L->allocated > len)) { + Py_INCREF(x); + PyList_SET_ITEM(list, len, x); + __Pyx_SET_SIZE(list, len + 1); + return 0; + } + return PyList_Append(list, x); +} +#else +#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x) +#endif + +/* ListExtend.proto */ +static CYTHON_INLINE int __Pyx_PyList_Extend(PyObject* L, PyObject* v) { +#if CYTHON_COMPILING_IN_CPYTHON + PyObject* none = _PyList_Extend((PyListObject*)L, v); + if (unlikely(!none)) + return -1; + Py_DECREF(none); + return 0; +#else + return PyList_SetSlice(L, PY_SSIZE_T_MAX, PY_SSIZE_T_MAX, v); +#endif +} + +/* None.proto */ +static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname); + +/* None.proto */ +static CYTHON_INLINE long __Pyx_div_long(long, long); + +/* ImportFrom.proto */ +static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name); + +/* HasAttr.proto */ +static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *); + +/* 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); + +/* PyObjectGetAttrStrNoError.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name); + +/* SetupReduce.proto */ +static int __Pyx_setup_reduce(PyObject* type_obj); + +/* TypeImport.proto */ +#ifndef __PYX_HAVE_RT_ImportType_proto +#define __PYX_HAVE_RT_ImportType_proto +enum __Pyx_ImportType_CheckSize { + __Pyx_ImportType_CheckSize_Error = 0, + __Pyx_ImportType_CheckSize_Warn = 1, + __Pyx_ImportType_CheckSize_Ignore = 2 +}; +static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size); +#endif + +/* 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); + +#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 + + +/* 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; + +/* MemviewSliceIsContig.proto */ +static int __pyx_memviewslice_is_contig(const __Pyx_memviewslice mvs, char order, int ndim); + +/* OverlappingSlices.proto */ +static int __pyx_slices_overlap(__Pyx_memviewslice *slice1, + __Pyx_memviewslice *slice2, + int ndim, size_t itemsize); + +/* Capsule.proto */ +static CYTHON_INLINE PyObject *__pyx_capsule_create(void *p, const char *sig); + +/* MemviewDtypeToObject.proto */ +static CYTHON_INLINE PyObject *__pyx_memview_get_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t(const char *itemp); +static CYTHON_INLINE int __pyx_memview_set_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t(const char *itemp, PyObject *obj); + +/* CppExceptionConversion.proto */ +#ifndef __Pyx_CppExn2PyErr +#include +#include +#include +#include +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 + +/* MemviewDtypeToObject.proto */ +static CYTHON_INLINE PyObject *__pyx_memview_get_double(const char *itemp); +static CYTHON_INLINE int __pyx_memview_set_double(const char *itemp, PyObject *obj); + +/* 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 + +/* MemviewSliceCopyTemplate.proto */ +static __Pyx_memviewslice +__pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, + const char *mode, int ndim, + size_t sizeof_dtype, int contig_flag, + int dtype_is_object); + +/* CIntFromPy.proto */ +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_PY_LONG_LONG(PY_LONG_LONG value); + +/* CIntFromPy.proto */ +static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_As_PY_LONG_LONG(PyObject *); + +/* CIntFromPy.proto */ +static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *); + +/* CIntFromPy.proto */ +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); + +/* CIntFromPy.proto */ +static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *); + +/* TypeInfoCompare.proto */ +static int __pyx_typeinfo_cmp(__Pyx_TypeInfo *a, __Pyx_TypeInfo *b); + +/* MemviewSliceValidateAndInit.proto */ +static int __Pyx_ValidateAndInit_memviewslice( + int *axes_specs, + int c_or_f_flag, + int buf_flags, + int ndim, + __Pyx_TypeInfo *dtype, + __Pyx_BufFmt_StackElem stack[], + __Pyx_memviewslice *memviewslice, + PyObject *original_obj); + +/* ObjectToMemviewSlice.proto */ +static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t(PyObject *, int writable_flag); + +/* ObjectToMemviewSlice.proto */ +static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_double(PyObject *, int writable_flag); + +/* CheckBinaryVersion.proto */ +static int __Pyx_check_binary_version(void); + +/* InitStrings.proto */ +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); + +static PyObject *__pyx_array_get_memview(struct __pyx_array_obj *__pyx_v_self); /* proto*/ +static char *__pyx_memoryview_get_item_pointer(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index); /* proto*/ +static PyObject *__pyx_memoryview_is_slice(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj); /* proto*/ +static PyObject *__pyx_memoryview_setitem_slice_assignment(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_dst, PyObject *__pyx_v_src); /* proto*/ +static PyObject *__pyx_memoryview_setitem_slice_assign_scalar(struct __pyx_memoryview_obj *__pyx_v_self, struct __pyx_memoryview_obj *__pyx_v_dst, PyObject *__pyx_v_value); /* proto*/ +static PyObject *__pyx_memoryview_setitem_indexed(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value); /* proto*/ +static PyObject *__pyx_memoryview_convert_item_to_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp); /* proto*/ +static PyObject *__pyx_memoryview_assign_item_from_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp, PyObject *__pyx_v_value); /* proto*/ +static PyObject *__pyx_memoryviewslice_convert_item_to_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp); /* proto*/ +static PyObject *__pyx_memoryviewslice_assign_item_from_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp, PyObject *__pyx_v_value); /* proto*/ + +/* Module declarations from 'cython.view' */ + +/* Module declarations from 'cython' */ + +/* Module declarations from 'libcpp' */ + +/* Module declarations from 'libcpp.algorithm' */ + +/* 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_generic = 0; +static PyTypeObject *__pyx_ptype_5numpy_number = 0; +static PyTypeObject *__pyx_ptype_5numpy_integer = 0; +static PyTypeObject *__pyx_ptype_5numpy_signedinteger = 0; +static PyTypeObject *__pyx_ptype_5numpy_unsignedinteger = 0; +static PyTypeObject *__pyx_ptype_5numpy_inexact = 0; +static PyTypeObject *__pyx_ptype_5numpy_floating = 0; +static PyTypeObject *__pyx_ptype_5numpy_complexfloating = 0; +static PyTypeObject *__pyx_ptype_5numpy_flexible = 0; +static PyTypeObject *__pyx_ptype_5numpy_character = 0; +static PyTypeObject *__pyx_ptype_5numpy_ufunc = 0; + +/* Module declarations from 'libcpp.vector' */ + +/* Module declarations from 'pygeoprocessing.geoprocessing_core' */ +static PyTypeObject *__pyx_array_type = 0; +static PyTypeObject *__pyx_MemviewEnum_type = 0; +static PyTypeObject *__pyx_memoryview_type = 0; +static PyTypeObject *__pyx_memoryviewslice_type = 0; +static float __pyx_v_15pygeoprocessing_18geoprocessing_core__NODATA; +static PyObject *generic = 0; +static PyObject *strided = 0; +static PyObject *indirect = 0; +static PyObject *contiguous = 0; +static PyObject *indirect_contiguous = 0; +static int __pyx_memoryview_thread_locks_used; +static PyThread_type_lock __pyx_memoryview_thread_locks[8]; +static struct __pyx_array_obj *__pyx_array_new(PyObject *, Py_ssize_t, char *, char *, char *); /*proto*/ +static void *__pyx_align_pointer(void *, size_t); /*proto*/ +static PyObject *__pyx_memoryview_new(PyObject *, int, int, __Pyx_TypeInfo *); /*proto*/ +static CYTHON_INLINE int __pyx_memoryview_check(PyObject *); /*proto*/ +static PyObject *_unellipsify(PyObject *, int); /*proto*/ +static PyObject *assert_direct_dimensions(Py_ssize_t *, int); /*proto*/ +static struct __pyx_memoryview_obj *__pyx_memview_slice(struct __pyx_memoryview_obj *, PyObject *); /*proto*/ +static int __pyx_memoryview_slice_memviewslice(__Pyx_memviewslice *, Py_ssize_t, Py_ssize_t, Py_ssize_t, int, int, int *, Py_ssize_t, Py_ssize_t, Py_ssize_t, int, int, int, int); /*proto*/ +static char *__pyx_pybuffer_index(Py_buffer *, char *, Py_ssize_t, Py_ssize_t); /*proto*/ +static int __pyx_memslice_transpose(__Pyx_memviewslice *); /*proto*/ +static PyObject *__pyx_memoryview_fromslice(__Pyx_memviewslice, int, PyObject *(*)(char *), int (*)(char *, PyObject *), int); /*proto*/ +static __Pyx_memviewslice *__pyx_memoryview_get_slice_from_memoryview(struct __pyx_memoryview_obj *, __Pyx_memviewslice *); /*proto*/ +static void __pyx_memoryview_slice_copy(struct __pyx_memoryview_obj *, __Pyx_memviewslice *); /*proto*/ +static PyObject *__pyx_memoryview_copy_object(struct __pyx_memoryview_obj *); /*proto*/ +static PyObject *__pyx_memoryview_copy_object_from_slice(struct __pyx_memoryview_obj *, __Pyx_memviewslice *); /*proto*/ +static Py_ssize_t abs_py_ssize_t(Py_ssize_t); /*proto*/ +static char __pyx_get_best_slice_order(__Pyx_memviewslice *, int); /*proto*/ +static void _copy_strided_to_strided(char *, Py_ssize_t *, char *, Py_ssize_t *, Py_ssize_t *, Py_ssize_t *, int, size_t); /*proto*/ +static void copy_strided_to_strided(__Pyx_memviewslice *, __Pyx_memviewslice *, int, size_t); /*proto*/ +static Py_ssize_t __pyx_memoryview_slice_get_size(__Pyx_memviewslice *, int); /*proto*/ +static Py_ssize_t __pyx_fill_contig_strides_array(Py_ssize_t *, Py_ssize_t *, Py_ssize_t, int, char); /*proto*/ +static void *__pyx_memoryview_copy_data_to_temp(__Pyx_memviewslice *, __Pyx_memviewslice *, char, int); /*proto*/ +static int __pyx_memoryview_err_extents(int, Py_ssize_t, Py_ssize_t); /*proto*/ +static int __pyx_memoryview_err_dim(PyObject *, char *, int); /*proto*/ +static int __pyx_memoryview_err(PyObject *, char *); /*proto*/ +static int __pyx_memoryview_copy_contents(__Pyx_memviewslice, __Pyx_memviewslice, int, int, int); /*proto*/ +static void __pyx_memoryview_broadcast_leading(__Pyx_memviewslice *, int, int); /*proto*/ +static void __pyx_memoryview_refcount_copying(__Pyx_memviewslice *, int, int, int); /*proto*/ +static void __pyx_memoryview_refcount_objects_in_slice_with_gil(char *, Py_ssize_t *, Py_ssize_t *, int, int); /*proto*/ +static void __pyx_memoryview_refcount_objects_in_slice(char *, Py_ssize_t *, Py_ssize_t *, int, int); /*proto*/ +static void __pyx_memoryview_slice_assign_scalar(__Pyx_memviewslice *, int, size_t, void *, int); /*proto*/ +static void __pyx_memoryview__slice_assign_scalar(char *, Py_ssize_t *, Py_ssize_t *, int, size_t, void *); /*proto*/ +static PyObject *__pyx_unpickle_Enum__set_state(struct __pyx_MemviewEnum_obj *, PyObject *); /*proto*/ +static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_int8_t = { "int8_t", NULL, sizeof(__pyx_t_5numpy_int8_t), { 0 }, 0, IS_UNSIGNED(__pyx_t_5numpy_int8_t) ? 'U' : 'I', IS_UNSIGNED(__pyx_t_5numpy_int8_t), 0 }; +static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t = { "float32_t", NULL, sizeof(__pyx_t_5numpy_float32_t), { 0 }, 0, 'R', 0, 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 }; +static __Pyx_TypeInfo __Pyx_TypeInfo_nn_npy_float64 = { "npy_float64", NULL, sizeof(npy_float64), { 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_15pygeoprocessing_18geoprocessing_core_int64t = { "int64t", NULL, sizeof(__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t), { 0 }, 0, IS_UNSIGNED(__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t) ? 'U' : 'I', IS_UNSIGNED(__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t), 0 }; +static __Pyx_TypeInfo __Pyx_TypeInfo_double = { "double", NULL, sizeof(double), { 0 }, 0, 'R', 0, 0 }; +#define __Pyx_MODULE_NAME "pygeoprocessing.geoprocessing_core" +extern int __pyx_module_is_main_pygeoprocessing__geoprocessing_core; +int __pyx_module_is_main_pygeoprocessing__geoprocessing_core = 0; + +/* Implementation of 'pygeoprocessing.geoprocessing_core' */ +static PyObject *__pyx_builtin_range; +static PyObject *__pyx_builtin_ValueError; +static PyObject *__pyx_builtin_OSError; +static PyObject *__pyx_builtin_ImportError; +static PyObject *__pyx_builtin_MemoryError; +static PyObject *__pyx_builtin_enumerate; +static PyObject *__pyx_builtin_TypeError; +static PyObject *__pyx_builtin_Ellipsis; +static PyObject *__pyx_builtin_id; +static PyObject *__pyx_builtin_IndexError; +static const char __pyx_k_O[] = "O"; +static const char __pyx_k_a[] = "a"; +static const char __pyx_k_b[] = "b"; +static const char __pyx_k_c[] = "c"; +static const char __pyx_k_d[] = "d"; +static const char __pyx_k_e[] = "e"; +static const char __pyx_k_f[] = "f"; +static const char __pyx_k_g[] = "g"; +static const char __pyx_k_h[] = "h"; +static const char __pyx_k_i[] = "i"; +static const char __pyx_k_n[] = "n"; +static const char __pyx_k_w[] = "w"; +static const char __pyx_k_x[] = "x"; +static const char __pyx_k_1f[] = ".1f"; +static const char __pyx_k_dt[] = "dt"; +static const char __pyx_k_gu[] = "gu"; +static const char __pyx_k_id[] = "id"; +static const char __pyx_k_os[] = "os"; +static const char __pyx_k_sq[] = "sq"; +static const char __pyx_k_tq[] = "tq"; +static const char __pyx_k__34[] = "_"; +static const char __pyx_k_buf[] = "buf"; +static const char __pyx_k_get[] = "get"; +static const char __pyx_k_gsq[] = "gsq"; +static const char __pyx_k_min[] = "min"; +static const char __pyx_k_new[] = "__new__"; +static const char __pyx_k_obj[] = "obj"; +static const char __pyx_k_osr[] = "osr"; +static const char __pyx_k_put[] = "put"; +static const char __pyx_k_sys[] = "sys"; +static const char __pyx_k_base[] = "base"; +static const char __pyx_k_copy[] = "copy"; +static const char __pyx_k_dict[] = "__dict__"; +static const char __pyx_k_done[] = "done"; +static const char __pyx_k_fptr[] = "fptr"; +static const char __pyx_k_gdal[] = "gdal"; +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_main[] = "__main__"; +static const char __pyx_k_mode[] = "mode"; +static const char __pyx_k_name[] = "name"; +static const char __pyx_k_ndim[] = "ndim"; +static const char __pyx_k_pack[] = "pack"; +static const char __pyx_k_path[] = "path"; +static const char __pyx_k_size[] = "size"; +static const char __pyx_k_sort[] = "sort"; +static const char __pyx_k_sqrt[] = "sqrt"; +static const char __pyx_k_step[] = "step"; +static const char __pyx_k_stop[] = "stop"; +static const char __pyx_k_test[] = "__test__"; +static const char __pyx_k_time[] = "time"; +static const char __pyx_k_xoff[] = "xoff"; +static const char __pyx_k_yoff[] = "yoff"; +static const char __pyx_k_zlib[] = "zlib"; +static const char __pyx_k_ASCII[] = "ASCII"; +static const char __pyx_k_GTIFF[] = "GTIFF"; +static const char __pyx_k_block[] = "block"; +static const char __pyx_k_class[] = "__class__"; +static const char __pyx_k_d_dat[] = "%d.dat"; +static const char __pyx_k_debug[] = "debug"; +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_finfo[] = "finfo"; +static const char __pyx_k_flags[] = "flags"; +static const char __pyx_k_index[] = "index"; +static const char __pyx_k_int32[] = "int32"; +static const char __pyx_k_int64[] = "int64"; +static const char __pyx_k_items[] = "items"; +static const char __pyx_k_numpy[] = "numpy"; +static const char __pyx_k_osgeo[] = "osgeo"; +static const char __pyx_k_range[] = "range"; +static const char __pyx_k_shape[] = "shape"; +static const char __pyx_k_start[] = "start"; +static const char __pyx_k_utf_8[] = "utf-8"; +static const char __pyx_k_x_end[] = "x_end"; +static const char __pyx_k_y_end[] = "y_end"; +static const char __pyx_k_LOGGER[] = "LOGGER"; +static const char __pyx_k_M_last[] = "M_last"; +static const char __pyx_k_OpenEx[] = "OpenEx"; +static const char __pyx_k_arange[] = "arange"; +static const char __pyx_k_astype[] = "astype"; +static const char __pyx_k_buffer[] = "buffer"; +static const char __pyx_k_double[] = "double"; +static const char __pyx_k_encode[] = "encode"; +static const char __pyx_k_format[] = "format"; +static const char __pyx_k_g_band[] = "g_band"; +static const char __pyx_k_getpid[] = "getpid"; +static const char __pyx_k_import[] = "__import__"; +static const char __pyx_k_n_cols[] = "n_cols"; +static const char __pyx_k_n_rows[] = "n_rows"; +static const char __pyx_k_name_2[] = "__name__"; +static const char __pyx_k_nodata[] = "nodata"; +static const char __pyx_k_out_of[] = " out of "; +static const char __pyx_k_pickle[] = "pickle"; +static const char __pyx_k_reduce[] = "__reduce__"; +static const char __pyx_k_remove[] = "remove"; +static const char __pyx_k_rmtree[] = "rmtree"; +static const char __pyx_k_shutil[] = "shutil"; +static const char __pyx_k_struct[] = "struct"; +static const char __pyx_k_unpack[] = "unpack"; +static const char __pyx_k_update[] = "update"; +static const char __pyx_k_M_local[] = "M_local"; +static const char __pyx_k_OSError[] = "OSError"; +static const char __pyx_k_S_local[] = "S_local"; +static const char __pyx_k_buf_obj[] = "buf_obj"; +static const char __pyx_k_float32[] = "float32"; +static const char __pyx_k_float64[] = "float64"; +static const char __pyx_k_fortran[] = "fortran"; +static const char __pyx_k_g_block[] = "g_block"; +static const char __pyx_k_isclose[] = "isclose"; +static const char __pyx_k_logging[] = "logging"; +static const char __pyx_k_memview[] = "memview"; +static const char __pyx_k_payload[] = "payload"; +static const char __pyx_k_q_index[] = "q_index"; +static const char __pyx_k_s_array[] = "s_array"; +static const char __pyx_k_t_array[] = "t_array"; +static const char __pyx_k_u_index[] = "u_index"; +static const char __pyx_k_warning[] = "warning"; +static const char __pyx_k_x_start[] = "x_start"; +static const char __pyx_k_y_start[] = "y_start"; +static const char __pyx_k_Ellipsis[] = "Ellipsis"; +static const char __pyx_k_GDT_Byte[] = "GDT_Byte"; +static const char __pyx_k_complete[] = "% complete, "; +static const char __pyx_k_datatype[] = "datatype"; +static const char __pyx_k_dem_band[] = "dem_band"; +static const char __pyx_k_dem_info[] = "dem_info"; +static const char __pyx_k_g_raster[] = "g_raster"; +static const char __pyx_k_getstate[] = "__getstate__"; +static const char __pyx_k_itemsize[] = "itemsize"; +static const char __pyx_k_makedirs[] = "makedirs"; +static const char __pyx_k_n_pixels[] = "n_pixels"; +static const char __pyx_k_next_val[] = "next_val"; +static const char __pyx_k_pyx_type[] = "__pyx_type"; +static const char __pyx_k_setstate[] = "__setstate__"; +static const char __pyx_k_tempfile[] = "tempfile"; +static const char __pyx_k_GA_Update[] = "GA_Update"; +static const char __pyx_k_GDT_Int16[] = "GDT_Int16"; +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_col_index[] = "col_index"; +static const char __pyx_k_dem_array[] = "dem_array"; +static const char __pyx_k_enumerate[] = "enumerate"; +static const char __pyx_k_exception[] = "exception"; +static const char __pyx_k_ffiv_iter[] = "ffiv_iter"; +static const char __pyx_k_file_path[] = "file_path"; +static const char __pyx_k_getLogger[] = "getLogger"; +static const char __pyx_k_mask_band[] = "mask_band"; +static const char __pyx_k_max_value[] = "max_value"; +static const char __pyx_k_min_value[] = "min_value"; +static const char __pyx_k_pyx_state[] = "__pyx_state"; +static const char __pyx_k_reduce_ex[] = "__reduce_ex__"; +static const char __pyx_k_row_index[] = "row_index"; +static const char __pyx_k_step_size[] = "step_size"; +static const char __pyx_k_traceback[] = "traceback"; +static const char __pyx_k_win_xsize[] = "win_xsize"; +static const char __pyx_k_win_ysize[] = "win_ysize"; +static const char __pyx_k_FlushCache[] = "FlushCache"; +static const char __pyx_k_GDT_UInt16[] = "GDT_UInt16"; +static const char __pyx_k_GDT_UInt32[] = "GDT_UInt32"; +static const char __pyx_k_IndexError[] = "IndexError"; +static const char __pyx_k_ValueError[] = "ValueError"; +static const char __pyx_k_WriteArray[] = "WriteArray"; +static const char __pyx_k_block_data[] = "block_data"; +static const char __pyx_k_block_size[] = "block_size"; +static const char __pyx_k_dem_nodata[] = "dem_nodata"; +static const char __pyx_k_dem_raster[] = "dem_raster"; +static const char __pyx_k_dzdx_array[] = "dzdx_array"; +static const char __pyx_k_dzdy_array[] = "dzdy_array"; +static const char __pyx_k_file_index[] = "file_index"; +static const char __pyx_k_iterblocks[] = "iterblocks"; +static const char __pyx_k_mask_block[] = "mask_block"; +static const char __pyx_k_max_sample[] = "max_sample"; +static const char __pyx_k_n_elements[] = "n_elements"; +static const char __pyx_k_pixel_size[] = "pixel_size"; +static const char __pyx_k_pyx_result[] = "__pyx_result"; +static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__"; +static const char __pyx_k_raw_nodata[] = "raw_nodata"; +static const char __pyx_k_sample_d_x[] = "sample_d_x"; +static const char __pyx_k_sample_d_y[] = "sample_d_y"; +static const char __pyx_k_valid_mask[] = "valid_mask"; +static const char __pyx_k_BIGTIFF_YES[] = "BIGTIFF=YES"; +static const char __pyx_k_GDT_Float32[] = "GDT_Float32"; +static const char __pyx_k_GDT_Float64[] = "GDT_Float64"; +static const char __pyx_k_ImportError[] = "ImportError"; +static const char __pyx_k_MemoryError[] = "MemoryError"; +static const char __pyx_k_PickleError[] = "PickleError"; +static const char __pyx_k_RasterXSize[] = "RasterXSize"; +static const char __pyx_k_RasterYSize[] = "RasterYSize"; +static const char __pyx_k_ReadAsArray[] = "ReadAsArray"; +static const char __pyx_k_block_xsize[] = "block_xsize"; +static const char __pyx_k_block_ysize[] = "block_ysize"; +static const char __pyx_k_buffer_data[] = "buffer_data"; +static const char __pyx_k_last_update[] = "last_update"; +static const char __pyx_k_mask_raster[] = "mask_raster"; +static const char __pyx_k_offset_only[] = "offset_only"; +static const char __pyx_k_raster_info[] = "raster_info"; +static const char __pyx_k_raster_size[] = "raster_size"; +static const char __pyx_k_raster_type[] = "raster_type"; +static const char __pyx_k_result_list[] = "result_list"; +static const char __pyx_k_slope_array[] = "slope_array"; +static const char __pyx_k_x_cell_size[] = "x_cell_size"; +static const char __pyx_k_y_cell_size[] = "y_cell_size"; +static const char __pyx_k_COMPRESS_LZW[] = "COMPRESS=LZW"; +static const char __pyx_k_GetBlockSize[] = "GetBlockSize"; +static const char __pyx_k_block_offset[] = "block_offset"; +static const char __pyx_k_current_step[] = "current_step"; +static const char __pyx_k_existing_shm[] = "existing_shm"; +static const char __pyx_k_pyx_checksum[] = "__pyx_checksum"; +static const char __pyx_k_slope_nodata[] = "slope_nodata"; +static const char __pyx_k_stats_worker[] = "stats_worker"; +static const char __pyx_k_stringsource[] = "stringsource"; +static const char __pyx_k_GetRasterBand[] = "GetRasterBand"; +static const char __pyx_k_g_raster_path[] = "g_raster_path"; +static const char __pyx_k_heapfile_list[] = "heapfile_list"; +static const char __pyx_k_largest_block[] = "largest_block"; +static const char __pyx_k_local_x_index[] = "local_x_index"; +static const char __pyx_k_local_y_index[] = "local_y_index"; +static const char __pyx_k_numerical_inf[] = "numerical_inf"; +static const char __pyx_k_pyx_getbuffer[] = "__pyx_getbuffer"; +static const char __pyx_k_reduce_cython[] = "__reduce_cython__"; +static const char __pyx_k_BLOCKXSIZE_256[] = "BLOCKXSIZE=256"; +static const char __pyx_k_BLOCKYSIZE_256[] = "BLOCKYSIZE=256"; +static const char __pyx_k_x_denom_factor[] = "x_denom_factor"; +static const char __pyx_k_y_denom_factor[] = "y_denom_factor"; +static const char __pyx_k_View_MemoryView[] = "View.MemoryView"; +static const char __pyx_k_allocate_buffer[] = "allocate_buffer"; +static const char __pyx_k_calculate_slope[] = "calculate_slope"; +static const char __pyx_k_distance_nodata[] = "distance_nodata"; +static const char __pyx_k_dtype_is_object[] = "dtype_is_object"; +static const char __pyx_k_expected_blocks[] = "expected_blocks"; +static const char __pyx_k_ffi_buffer_size[] = "ffi_buffer_size"; +static const char __pyx_k_get_raster_info[] = "get_raster_info"; +static const char __pyx_k_multiprocessing[] = "multiprocessing"; +static const char __pyx_k_percentile_list[] = "percentile_list"; +static const char __pyx_k_pygeoprocessing[] = "pygeoprocessing"; +static const char __pyx_k_pyx_PickleError[] = "__pyx_PickleError"; +static const char __pyx_k_setstate_cython[] = "__setstate_cython__"; +static const char __pyx_k_dzdx_accumulator[] = "dzdx_accumulator"; +static const char __pyx_k_dzdy_accumulator[] = "dzdy_accumulator"; +static const char __pyx_k_g_band_blocksize[] = "g_band_blocksize"; +static const char __pyx_k_heap_buffer_size[] = "heap_buffer_size"; +static const char __pyx_k_percentile_index[] = "percentile_index"; +static const char __pyx_k_pixels_processed[] = "pixels_processed"; +static const char __pyx_k_rm_dir_when_done[] = "rm_dir_when_done"; +static const char __pyx_k_stats_work_queue[] = "stats_work_queue"; +static const char __pyx_k_stats_worker_PID[] = "stats worker PID: "; +static const char __pyx_k_ComputeStatistics[] = "ComputeStatistics"; +static const char __pyx_k_block_offset_copy[] = "block_offset_copy"; +static const char __pyx_k_data_sort_to_heap[] = "data sort to heap "; +static const char __pyx_k_pyx_unpickle_Enum[] = "__pyx_unpickle_Enum"; +static const char __pyx_k_target_slope_band[] = "target_slope_band"; +static const char __pyx_k_target_slope_path[] = "target_slope_path"; +static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; +static const char __pyx_k_current_percentile[] = "current_percentile"; +static const char __pyx_k_fast_file_iterator[] = "fast_file_iterator"; +static const char __pyx_k_region_raster_path[] = "region_raster_path"; +static const char __pyx_k_strided_and_direct[] = ""; +static const char __pyx_k_unable_to_remove_s[] = "unable to remove %s"; +static const char __pyx_k_exception_s_s_s_s_s[] = "exception %s %s %s %s %s"; +static const char __pyx_k_target_slope_raster[] = "target_slope_raster"; +static const char __pyx_k_new_raster_from_base[] = "new_raster_from_base"; +static const char __pyx_k_sorting_data_to_heap[] = "sorting data to heap"; +static const char __pyx_k_strided_and_indirect[] = ""; +static const char __pyx_k_target_distance_band[] = "target_distance_band"; +static const char __pyx_k_base_raster_path_band[] = "base_raster_path_band"; +static const char __pyx_k_contiguous_and_direct[] = ""; +static const char __pyx_k_invalid_value_for_n_s[] = "invalid value for n %s"; +static const char __pyx_k_MemoryView_of_r_object[] = ""; +static const char __pyx_k_distance_transform_edt[] = "_distance_transform_edt"; +static const char __pyx_k_raster_band_percentile[] = "raster_band_percentile"; +static const char __pyx_k_target_distance_raster[] = "target_distance_raster"; +static const char __pyx_k_working_sort_directory[] = "working_sort_directory"; +static const char __pyx_k_MemoryView_of_r_at_0x_x[] = ""; +static const char __pyx_k_calculating_percentiles[] = "calculating percentiles"; +static const char __pyx_k_contiguous_and_indirect[] = ""; +static const char __pyx_k_Cannot_index_with_type_s[] = "Cannot index with type '%s'"; +static const char __pyx_k_Invalid_shape_in_axis_d_d[] = "Invalid shape in axis %d: %d."; +static const char __pyx_k_fast_file_iterator_vector[] = "fast_file_iterator_vector"; +static const char __pyx_k_here_is_percentile_list_s[] = "here is percentile_list: %s"; +static const char __pyx_k_Distance_Transform_Phase_2[] = "Distance Transform Phase 2"; +static const char __pyx_k_OAMS_TRADITIONAL_GIS_ORDER[] = "OAMS_TRADITIONAL_GIS_ORDER"; +static const char __pyx_k_raster_band_percentile_int[] = "_raster_band_percentile_int"; +static const char __pyx_k_total_number_of_pixels_s_s[] = "total number of pixels %s (%s)"; +static const char __pyx_k_itemsize_0_for_cython_array[] = "itemsize <= 0 for cython.array"; +static const char __pyx_k_target_distance_raster_path[] = "target_distance_raster_path"; +static const char __pyx_k_raster_driver_creation_tuple[] = "raster_driver_creation_tuple"; +static const char __pyx_k_raster_band_percentile_double[] = "_raster_band_percentile_double"; +static const char __pyx_k_unable_to_allocate_array_data[] = "unable to allocate array data."; +static const char __pyx_k_strided_and_direct_or_indirect[] = ""; +static const char __pyx_k_base_elevation_raster_path_band[] = "base_elevation_raster_path_band"; +static const char __pyx_k_numpy_core_multiarray_failed_to[] = "numpy.core.multiarray failed to import"; +static const char __pyx_k_Buffer_view_does_not_expose_stri[] = "Buffer view does not expose strides"; +static const char __pyx_k_Can_only_create_a_buffer_that_is[] = "Can only create a buffer that is contiguous in memory."; +static const char __pyx_k_Cannot_assign_to_read_only_memor[] = "Cannot assign to read-only memoryview"; +static const char __pyx_k_Cannot_create_writable_memory_vi[] = "Cannot create writable memory view from read-only memoryview"; +static const char __pyx_k_Cannot_process_raster_type_s_not[] = "Cannot process raster type %s (not a known integer nor float type)"; +static const char __pyx_k_DEFAULT_GTIFF_CREATION_TUPLE_OPT[] = "DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS"; +static const char __pyx_k_DEFAULT_OSR_AXIS_MAPPING_STRATEG[] = "DEFAULT_OSR_AXIS_MAPPING_STRATEGY"; +static const char __pyx_k_Empty_shape_tuple_for_cython_arr[] = "Empty shape tuple for cython.array"; +static const char __pyx_k_Incompatible_checksums_s_vs_0xb0[] = "Incompatible checksums (%s vs 0xb068931 = (name))"; +static const char __pyx_k_Indirect_dimensions_not_supporte[] = "Indirect dimensions not supported"; +static const char __pyx_k_Invalid_mode_expected_c_or_fortr[] = "Invalid mode, expected 'c' or 'fortran', got %s"; +static const char __pyx_k_No_valid_pixels_were_received_se[] = "No valid pixels were received, sending None."; +static const char __pyx_k_Out_of_bounds_on_buffer_access_a[] = "Out of bounds on buffer access (axis %d)"; +static const char __pyx_k_Unable_to_convert_item_to_object[] = "Unable to convert item to object"; +static const char __pyx_k_calculating_percentiles_2f_compl[] = "calculating percentiles %.2f%% complete"; +static const char __pyx_k_couldn_t_make_working_sort_direc[] = "couldn't make working_sort_directory: %s"; +static const char __pyx_k_got_differing_extents_in_dimensi[] = "got differing extents in dimension %d (got %d and %d)"; +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_pygeoprocessing_geoprocessing_co[] = "pygeoprocessing.geoprocessing_core"; +static const char __pyx_k_src_pygeoprocessing_geoprocessin[] = "src/pygeoprocessing/geoprocessing_core.pyx"; +static const char __pyx_k_unable_to_allocate_shape_and_str[] = "unable to allocate shape and strides."; +static PyObject *__pyx_kp_u_1f; +static PyObject *__pyx_n_s_ASCII; +static PyObject *__pyx_kp_u_BIGTIFF_YES; +static PyObject *__pyx_kp_u_BLOCKXSIZE_256; +static PyObject *__pyx_kp_u_BLOCKYSIZE_256; +static PyObject *__pyx_kp_s_Buffer_view_does_not_expose_stri; +static PyObject *__pyx_kp_u_COMPRESS_LZW; +static PyObject *__pyx_kp_s_Can_only_create_a_buffer_that_is; +static PyObject *__pyx_kp_s_Cannot_assign_to_read_only_memor; +static PyObject *__pyx_kp_s_Cannot_create_writable_memory_vi; +static PyObject *__pyx_kp_s_Cannot_index_with_type_s; +static PyObject *__pyx_kp_u_Cannot_process_raster_type_s_not; +static PyObject *__pyx_n_s_ComputeStatistics; +static PyObject *__pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT; +static PyObject *__pyx_n_s_DEFAULT_OSR_AXIS_MAPPING_STRATEG; +static PyObject *__pyx_kp_u_Distance_Transform_Phase_2; +static PyObject *__pyx_n_s_Ellipsis; +static PyObject *__pyx_kp_s_Empty_shape_tuple_for_cython_arr; +static PyObject *__pyx_n_s_FlushCache; +static PyObject *__pyx_n_s_GA_Update; +static PyObject *__pyx_n_s_GDT_Byte; +static PyObject *__pyx_n_s_GDT_Float32; +static PyObject *__pyx_n_s_GDT_Float64; +static PyObject *__pyx_n_s_GDT_Int16; +static PyObject *__pyx_n_s_GDT_Int32; +static PyObject *__pyx_n_s_GDT_UInt16; +static PyObject *__pyx_n_s_GDT_UInt32; +static PyObject *__pyx_n_u_GTIFF; +static PyObject *__pyx_n_s_GetBlockSize; +static PyObject *__pyx_n_s_GetRasterBand; +static PyObject *__pyx_n_s_ImportError; +static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0xb0; +static PyObject *__pyx_n_s_IndexError; +static PyObject *__pyx_kp_s_Indirect_dimensions_not_supporte; +static PyObject *__pyx_kp_s_Invalid_mode_expected_c_or_fortr; +static PyObject *__pyx_kp_s_Invalid_shape_in_axis_d_d; +static PyObject *__pyx_n_s_LOGGER; +static PyObject *__pyx_n_s_M_last; +static PyObject *__pyx_n_s_M_local; +static PyObject *__pyx_n_s_MemoryError; +static PyObject *__pyx_kp_s_MemoryView_of_r_at_0x_x; +static PyObject *__pyx_kp_s_MemoryView_of_r_object; +static PyObject *__pyx_kp_u_No_valid_pixels_were_received_se; +static PyObject *__pyx_n_b_O; +static PyObject *__pyx_n_s_OAMS_TRADITIONAL_GIS_ORDER; +static PyObject *__pyx_n_s_OF_RASTER; +static PyObject *__pyx_n_s_OSError; +static PyObject *__pyx_n_s_OpenEx; +static PyObject *__pyx_kp_s_Out_of_bounds_on_buffer_access_a; +static PyObject *__pyx_n_s_PickleError; +static PyObject *__pyx_n_s_RasterXSize; +static PyObject *__pyx_n_s_RasterYSize; +static PyObject *__pyx_n_s_ReadAsArray; +static PyObject *__pyx_n_s_S_local; +static PyObject *__pyx_kp_u_TILED_YES; +static PyObject *__pyx_n_s_TypeError; +static PyObject *__pyx_kp_s_Unable_to_convert_item_to_object; +static PyObject *__pyx_n_s_ValueError; +static PyObject *__pyx_n_s_View_MemoryView; +static PyObject *__pyx_n_s_WriteArray; +static PyObject *__pyx_n_s__34; +static PyObject *__pyx_n_s_a; +static PyObject *__pyx_n_s_allocate_buffer; +static PyObject *__pyx_n_s_arange; +static PyObject *__pyx_n_s_astype; +static PyObject *__pyx_n_s_b; +static PyObject *__pyx_n_s_base; +static PyObject *__pyx_n_s_base_elevation_raster_path_band; +static PyObject *__pyx_n_s_base_raster_path_band; +static PyObject *__pyx_n_s_block; +static PyObject *__pyx_n_s_block_data; +static PyObject *__pyx_n_s_block_offset; +static PyObject *__pyx_n_s_block_offset_copy; +static PyObject *__pyx_n_u_block_size; +static PyObject *__pyx_n_s_block_xsize; +static PyObject *__pyx_n_s_block_ysize; +static PyObject *__pyx_n_s_buf; +static PyObject *__pyx_n_s_buf_obj; +static PyObject *__pyx_n_s_buffer; +static PyObject *__pyx_n_s_buffer_data; +static PyObject *__pyx_n_s_c; +static PyObject *__pyx_n_u_c; +static PyObject *__pyx_n_s_calculate_slope; +static PyObject *__pyx_kp_u_calculating_percentiles; +static PyObject *__pyx_kp_u_calculating_percentiles_2f_compl; +static PyObject *__pyx_n_s_class; +static PyObject *__pyx_n_s_cline_in_traceback; +static PyObject *__pyx_n_s_col_index; +static PyObject *__pyx_kp_u_complete; +static PyObject *__pyx_kp_s_contiguous_and_direct; +static PyObject *__pyx_kp_s_contiguous_and_indirect; +static PyObject *__pyx_n_s_copy; +static PyObject *__pyx_kp_u_couldn_t_make_working_sort_direc; +static PyObject *__pyx_n_s_current_percentile; +static PyObject *__pyx_n_s_current_step; +static PyObject *__pyx_n_s_d; +static PyObject *__pyx_kp_u_d_dat; +static PyObject *__pyx_kp_u_data_sort_to_heap; +static PyObject *__pyx_n_u_datatype; +static PyObject *__pyx_n_s_debug; +static PyObject *__pyx_n_s_dem_array; +static PyObject *__pyx_n_s_dem_band; +static PyObject *__pyx_n_s_dem_info; +static PyObject *__pyx_n_s_dem_nodata; +static PyObject *__pyx_n_s_dem_raster; +static PyObject *__pyx_n_s_dict; +static PyObject *__pyx_n_s_distance_nodata; +static PyObject *__pyx_n_s_distance_transform_edt; +static PyObject *__pyx_n_s_done; +static PyObject *__pyx_n_s_double; +static PyObject *__pyx_n_s_dt; +static PyObject *__pyx_n_s_dtype; +static PyObject *__pyx_n_s_dtype_is_object; +static PyObject *__pyx_n_s_dzdx_accumulator; +static PyObject *__pyx_n_s_dzdx_array; +static PyObject *__pyx_n_s_dzdy_accumulator; +static PyObject *__pyx_n_s_dzdy_array; +static PyObject *__pyx_n_s_e; +static PyObject *__pyx_n_s_empty; +static PyObject *__pyx_n_s_encode; +static PyObject *__pyx_n_s_enumerate; +static PyObject *__pyx_n_s_error; +static PyObject *__pyx_n_s_exception; +static PyObject *__pyx_kp_u_exception_s_s_s_s_s; +static PyObject *__pyx_n_s_existing_shm; +static PyObject *__pyx_n_s_expected_blocks; +static PyObject *__pyx_n_s_f; +static PyObject *__pyx_n_s_fast_file_iterator; +static PyObject *__pyx_n_s_fast_file_iterator_vector; +static PyObject *__pyx_n_s_ffi_buffer_size; +static PyObject *__pyx_n_s_ffiv_iter; +static PyObject *__pyx_n_s_file_index; +static PyObject *__pyx_n_s_file_path; +static PyObject *__pyx_n_s_finfo; +static PyObject *__pyx_n_s_flags; +static PyObject *__pyx_n_s_float32; +static PyObject *__pyx_n_s_float64; +static PyObject *__pyx_n_s_format; +static PyObject *__pyx_n_s_fortran; +static PyObject *__pyx_n_u_fortran; +static PyObject *__pyx_n_s_fptr; +static PyObject *__pyx_n_s_g; +static PyObject *__pyx_n_s_g_band; +static PyObject *__pyx_n_s_g_band_blocksize; +static PyObject *__pyx_n_s_g_block; +static PyObject *__pyx_n_s_g_raster; +static PyObject *__pyx_n_s_g_raster_path; +static PyObject *__pyx_n_s_gdal; +static PyObject *__pyx_n_s_get; +static PyObject *__pyx_n_s_getLogger; +static PyObject *__pyx_n_s_get_raster_info; +static PyObject *__pyx_n_s_getpid; +static PyObject *__pyx_n_s_getstate; +static PyObject *__pyx_kp_s_got_differing_extents_in_dimensi; +static PyObject *__pyx_n_s_gsq; +static PyObject *__pyx_n_s_gu; +static PyObject *__pyx_n_s_h; +static PyObject *__pyx_n_s_heap_buffer_size; +static PyObject *__pyx_n_s_heapfile_list; +static PyObject *__pyx_kp_u_here_is_percentile_list_s; +static PyObject *__pyx_n_s_i; +static PyObject *__pyx_n_s_id; +static PyObject *__pyx_n_s_import; +static PyObject *__pyx_n_s_index; +static PyObject *__pyx_n_s_info; +static PyObject *__pyx_n_s_int32; +static PyObject *__pyx_n_s_int64; +static PyObject *__pyx_n_s_int8; +static PyObject *__pyx_kp_u_invalid_value_for_n_s; +static PyObject *__pyx_n_s_isclose; +static PyObject *__pyx_n_s_items; +static PyObject *__pyx_n_s_itemsize; +static PyObject *__pyx_kp_s_itemsize_0_for_cython_array; +static PyObject *__pyx_n_s_iterblocks; +static PyObject *__pyx_n_s_join; +static PyObject *__pyx_n_s_largest_block; +static PyObject *__pyx_n_s_last_update; +static PyObject *__pyx_n_s_local_x_index; +static PyObject *__pyx_n_s_local_y_index; +static PyObject *__pyx_n_s_logging; +static PyObject *__pyx_n_s_main; +static PyObject *__pyx_n_s_makedirs; +static PyObject *__pyx_n_s_mask_band; +static PyObject *__pyx_n_s_mask_block; +static PyObject *__pyx_n_s_mask_raster; +static PyObject *__pyx_n_s_max_sample; +static PyObject *__pyx_n_s_max_value; +static PyObject *__pyx_n_s_memview; +static PyObject *__pyx_n_s_min; +static PyObject *__pyx_n_s_min_value; +static PyObject *__pyx_n_s_mode; +static PyObject *__pyx_n_s_multiprocessing; +static PyObject *__pyx_n_s_n; +static PyObject *__pyx_n_s_n_cols; +static PyObject *__pyx_n_s_n_elements; +static PyObject *__pyx_n_s_n_pixels; +static PyObject *__pyx_n_s_n_rows; +static PyObject *__pyx_n_s_name; +static PyObject *__pyx_n_s_name_2; +static PyObject *__pyx_n_s_ndim; +static PyObject *__pyx_n_s_new; +static PyObject *__pyx_n_s_new_raster_from_base; +static PyObject *__pyx_n_s_next_val; +static PyObject *__pyx_kp_s_no_default___reduce___due_to_non; +static PyObject *__pyx_n_s_nodata; +static PyObject *__pyx_n_u_nodata; +static PyObject *__pyx_n_s_numerical_inf; +static PyObject *__pyx_n_s_numpy; +static PyObject *__pyx_kp_u_numpy_core_multiarray_failed_to; +static PyObject *__pyx_kp_u_numpy_core_umath_failed_to_impor; +static PyObject *__pyx_n_s_obj; +static PyObject *__pyx_n_s_offset_only; +static PyObject *__pyx_n_s_os; +static PyObject *__pyx_n_s_osgeo; +static PyObject *__pyx_n_s_osr; +static PyObject *__pyx_kp_u_out_of; +static PyObject *__pyx_n_s_pack; +static PyObject *__pyx_n_s_path; +static PyObject *__pyx_n_s_payload; +static PyObject *__pyx_n_s_percentile_index; +static PyObject *__pyx_n_s_percentile_list; +static PyObject *__pyx_n_s_pickle; +static PyObject *__pyx_n_u_pixel_size; +static PyObject *__pyx_n_s_pixels_processed; +static PyObject *__pyx_n_s_put; +static PyObject *__pyx_n_s_pygeoprocessing; +static PyObject *__pyx_n_s_pygeoprocessing_geoprocessing_co; +static PyObject *__pyx_kp_u_pygeoprocessing_geoprocessing_co; +static PyObject *__pyx_n_s_pyx_PickleError; +static PyObject *__pyx_n_s_pyx_checksum; +static PyObject *__pyx_n_s_pyx_getbuffer; +static PyObject *__pyx_n_s_pyx_result; +static PyObject *__pyx_n_s_pyx_state; +static PyObject *__pyx_n_s_pyx_type; +static PyObject *__pyx_n_s_pyx_unpickle_Enum; +static PyObject *__pyx_n_s_pyx_vtable; +static PyObject *__pyx_n_s_q_index; +static PyObject *__pyx_n_s_range; +static PyObject *__pyx_n_s_raster_band_percentile; +static PyObject *__pyx_n_s_raster_band_percentile_double; +static PyObject *__pyx_n_s_raster_band_percentile_int; +static PyObject *__pyx_n_s_raster_driver_creation_tuple; +static PyObject *__pyx_n_s_raster_info; +static PyObject *__pyx_n_u_raster_size; +static PyObject *__pyx_n_s_raster_type; +static PyObject *__pyx_n_s_raw_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_region_raster_path; +static PyObject *__pyx_n_s_remove; +static PyObject *__pyx_n_s_result_list; +static PyObject *__pyx_n_s_rm_dir_when_done; +static PyObject *__pyx_n_s_rmtree; +static PyObject *__pyx_n_s_row_index; +static PyObject *__pyx_n_s_s_array; +static PyObject *__pyx_n_s_sample_d_x; +static PyObject *__pyx_n_s_sample_d_y; +static PyObject *__pyx_n_s_setstate; +static PyObject *__pyx_n_s_setstate_cython; +static PyObject *__pyx_n_s_shape; +static PyObject *__pyx_n_s_shutil; +static PyObject *__pyx_n_s_size; +static PyObject *__pyx_n_s_slope_array; +static PyObject *__pyx_n_s_slope_nodata; +static PyObject *__pyx_n_s_sort; +static PyObject *__pyx_kp_u_sorting_data_to_heap; +static PyObject *__pyx_n_s_sq; +static PyObject *__pyx_n_s_sqrt; +static PyObject *__pyx_kp_s_src_pygeoprocessing_geoprocessin; +static PyObject *__pyx_n_s_start; +static PyObject *__pyx_n_s_stats_work_queue; +static PyObject *__pyx_n_s_stats_worker; +static PyObject *__pyx_kp_u_stats_worker_PID; +static PyObject *__pyx_n_s_step; +static PyObject *__pyx_n_s_step_size; +static PyObject *__pyx_n_s_stop; +static PyObject *__pyx_kp_s_strided_and_direct; +static PyObject *__pyx_kp_s_strided_and_direct_or_indirect; +static PyObject *__pyx_kp_s_strided_and_indirect; +static PyObject *__pyx_kp_s_stringsource; +static PyObject *__pyx_n_s_struct; +static PyObject *__pyx_n_s_sys; +static PyObject *__pyx_n_s_t_array; +static PyObject *__pyx_n_s_target_distance_band; +static PyObject *__pyx_n_s_target_distance_raster; +static PyObject *__pyx_n_s_target_distance_raster_path; +static PyObject *__pyx_n_s_target_slope_band; +static PyObject *__pyx_n_s_target_slope_path; +static PyObject *__pyx_n_s_target_slope_raster; +static PyObject *__pyx_n_s_tempfile; +static PyObject *__pyx_n_s_test; +static PyObject *__pyx_n_s_time; +static PyObject *__pyx_kp_u_total_number_of_pixels_s_s; +static PyObject *__pyx_n_s_tq; +static PyObject *__pyx_n_s_traceback; +static PyObject *__pyx_n_s_u_index; +static PyObject *__pyx_kp_s_unable_to_allocate_array_data; +static PyObject *__pyx_kp_s_unable_to_allocate_shape_and_str; +static PyObject *__pyx_kp_u_unable_to_remove_s; +static PyObject *__pyx_n_s_unpack; +static PyObject *__pyx_n_s_update; +static PyObject *__pyx_kp_u_utf_8; +static PyObject *__pyx_n_s_valid_mask; +static PyObject *__pyx_n_s_w; +static PyObject *__pyx_n_s_warning; +static PyObject *__pyx_n_s_win_xsize; +static PyObject *__pyx_n_u_win_xsize; +static PyObject *__pyx_n_s_win_ysize; +static PyObject *__pyx_n_u_win_ysize; +static PyObject *__pyx_n_s_working_sort_directory; +static PyObject *__pyx_n_s_x; +static PyObject *__pyx_n_s_x_cell_size; +static PyObject *__pyx_n_s_x_denom_factor; +static PyObject *__pyx_n_s_x_end; +static PyObject *__pyx_n_s_x_start; +static PyObject *__pyx_n_s_xoff; +static PyObject *__pyx_n_u_xoff; +static PyObject *__pyx_n_s_y_cell_size; +static PyObject *__pyx_n_s_y_denom_factor; +static PyObject *__pyx_n_s_y_end; +static PyObject *__pyx_n_s_y_start; +static PyObject *__pyx_n_s_yoff; +static PyObject *__pyx_n_u_yoff; +static PyObject *__pyx_n_s_zlib; +static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core__distance_transform_edt(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_region_raster_path, PyObject *__pyx_v_g_raster_path, float __pyx_v_sample_d_x, float __pyx_v_sample_d_y, PyObject *__pyx_v_target_distance_raster_path, PyObject *__pyx_v_raster_driver_creation_tuple); /* proto */ +static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core_2calculate_slope(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_base_elevation_raster_path_band, PyObject *__pyx_v_target_slope_path, PyObject *__pyx_v_raster_driver_creation_tuple); /* proto */ +static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core_4stats_worker(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_stats_work_queue, PyObject *__pyx_v_expected_blocks); /* proto */ +static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core_6raster_band_percentile(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_base_raster_path_band, PyObject *__pyx_v_working_sort_directory, PyObject *__pyx_v_percentile_list, PyObject *__pyx_v_heap_buffer_size, PyObject *__pyx_v_ffi_buffer_size); /* proto */ +static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core_8_raster_band_percentile_int(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_base_raster_path_band, PyObject *__pyx_v_working_sort_directory, PyObject *__pyx_v_percentile_list, PyObject *__pyx_v_heap_buffer_size, PyObject *__pyx_v_ffi_buffer_size); /* proto */ +static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core_10_raster_band_percentile_double(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_base_raster_path_band, PyObject *__pyx_v_working_sort_directory, PyObject *__pyx_v_percentile_list, PyObject *__pyx_v_heap_buffer_size, PyObject *__pyx_v_ffi_buffer_size); /* proto */ +static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, PyObject *__pyx_v_format, PyObject *__pyx_v_mode, int __pyx_v_allocate_buffer); /* proto */ +static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_2__getbuffer__(struct __pyx_array_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */ +static void __pyx_array___pyx_pf_15View_dot_MemoryView_5array_4__dealloc__(struct __pyx_array_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_15View_dot_MemoryView_5array_7memview___get__(struct __pyx_array_obj *__pyx_v_self); /* proto */ +static Py_ssize_t __pyx_array___pyx_pf_15View_dot_MemoryView_5array_6__len__(struct __pyx_array_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_8__getattr__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_attr); /* proto */ +static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_10__getitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item); /* proto */ +static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_12__setitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf___pyx_array___reduce_cython__(CYTHON_UNUSED struct __pyx_array_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf___pyx_array_2__setstate_cython__(CYTHON_UNUSED struct __pyx_array_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ +static int __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum___init__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v_name); /* proto */ +static PyObject *__pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum_2__repr__(struct __pyx_MemviewEnum_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf___pyx_MemviewEnum___reduce_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf___pyx_MemviewEnum_2__setstate_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ +static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview___cinit__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj, int __pyx_v_flags, int __pyx_v_dtype_is_object); /* proto */ +static void __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_2__dealloc__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_4__getitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index); /* proto */ +static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_6__setitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value); /* proto */ +static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_8__getbuffer__(struct __pyx_memoryview_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */ +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_1T___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4base___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_5shape___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_7strides___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_10suboffsets___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4ndim___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_8itemsize___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_6nbytes___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4size___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ +static Py_ssize_t __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_10__len__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_12__repr__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_14__str__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_16is_c_contig(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_18is_f_contig(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_20copy(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_22copy_fortran(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf___pyx_memoryview___reduce_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf___pyx_memoryview_2__setstate_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ +static void __pyx_memoryviewslice___pyx_pf_15View_dot_MemoryView_16_memoryviewslice___dealloc__(struct __pyx_memoryviewslice_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_15View_dot_MemoryView_16_memoryviewslice_4base___get__(struct __pyx_memoryviewslice_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf___pyx_memoryviewslice___reduce_cython__(CYTHON_UNUSED struct __pyx_memoryviewslice_obj *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf___pyx_memoryviewslice_2__setstate_cython__(CYTHON_UNUSED struct __pyx_memoryviewslice_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_15View_dot_MemoryView___pyx_unpickle_Enum(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_tp_new_array(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new_Enum(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new_memoryview(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new__memoryviewslice(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_float_5_0; +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_1024; +static PyObject *__pyx_int_184977713; +static PyObject *__pyx_int_268435456; +static PyObject *__pyx_int_neg_1; +static PyObject *__pyx_k__3; +static PyObject *__pyx_slice_; +static PyObject *__pyx_tuple__2; +static PyObject *__pyx_tuple__4; +static PyObject *__pyx_tuple__5; +static PyObject *__pyx_tuple__6; +static PyObject *__pyx_tuple__7; +static PyObject *__pyx_tuple__8; +static PyObject *__pyx_tuple__9; +static PyObject *__pyx_tuple__10; +static PyObject *__pyx_tuple__11; +static PyObject *__pyx_tuple__12; +static PyObject *__pyx_tuple__13; +static PyObject *__pyx_tuple__14; +static PyObject *__pyx_tuple__15; +static PyObject *__pyx_tuple__16; +static PyObject *__pyx_tuple__17; +static PyObject *__pyx_tuple__18; +static PyObject *__pyx_tuple__19; +static PyObject *__pyx_tuple__20; +static PyObject *__pyx_tuple__21; +static PyObject *__pyx_tuple__22; +static PyObject *__pyx_tuple__23; +static PyObject *__pyx_tuple__24; +static PyObject *__pyx_tuple__25; +static PyObject *__pyx_tuple__26; +static PyObject *__pyx_tuple__28; +static PyObject *__pyx_tuple__30; +static PyObject *__pyx_tuple__32; +static PyObject *__pyx_tuple__35; +static PyObject *__pyx_tuple__37; +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_codeobj__27; +static PyObject *__pyx_codeobj__29; +static PyObject *__pyx_codeobj__31; +static PyObject *__pyx_codeobj__33; +static PyObject *__pyx_codeobj__36; +static PyObject *__pyx_codeobj__38; +static PyObject *__pyx_codeobj__45; +/* Late includes */ + +/* "pygeoprocessing/geoprocessing_core.pyx":71 + * @cython.wraparound(False) + * @cython.cdivision(True) + * def _distance_transform_edt( # <<<<<<<<<<<<<< + * region_raster_path, g_raster_path, float sample_d_x, + * float sample_d_y, target_distance_raster_path, + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_1_distance_transform_edt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_15pygeoprocessing_18geoprocessing_core__distance_transform_edt[] = "Calculate the euclidean distance transform on base raster.\n\n Calculates the euclidean distance transform on the base raster in units of\n pixels multiplied by an optional scalar constant. The implementation is\n based off the algorithm described in: Meijster, Arnold, Jos BTM Roerdink,\n and Wim H. Hesselink. \"A general algorithm for computing distance\n transforms in linear time.\" Mathematical Morphology and its applications\n to image and signal processing. Springer, Boston, MA, 2002. 331-340.\n\n The base mask raster represents the area to distance transform from as\n any pixel that is not 0 or nodata. It is computationally convenient to\n calculate the distance transform on the entire raster irrespective of\n nodata placement and thus produces a raster that will have distance\n transform values even in pixels that are nodata in the base.\n\n Parameters:\n region_raster_path (string): path to a byte raster where region pixels\n are indicated by a 1 and 0 otherwise.\n g_raster_path (string): path to a raster created by this call that\n is used as the intermediate \"g\" variable described in Meijster\n et. al.\n sample_d_x (float):\n sample_d_y (float):\n These parameters scale the pixel distances when calculating the\n distance transform. ``d_x`` is the x direction when changing a\n column index, and ``d_y`` when changing a row index. Both values\n must be > 0.\n target_distance_raster_path (string): path to the target raster\n created by this call that is the exact euclidean distance\n transform from any pixel in the base raster that is not nodata and\n not 0. The units are in (pixel distance * sampling_distance).\n raster_driver_creation_tuple (tuple): a tuple containing a GDAL driver\n name string as the first element and a GDAL creation options\n tup""le/list as the second. Defaults to a GTiff driver tuple\n defined at geoprocessing.DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS.\n\n Returns:\n None\n\n "; +static PyMethodDef __pyx_mdef_15pygeoprocessing_18geoprocessing_core_1_distance_transform_edt = {"_distance_transform_edt", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_18geoprocessing_core_1_distance_transform_edt, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_18geoprocessing_core__distance_transform_edt}; +static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_1_distance_transform_edt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_region_raster_path = 0; + PyObject *__pyx_v_g_raster_path = 0; + float __pyx_v_sample_d_x; + float __pyx_v_sample_d_y; + PyObject *__pyx_v_target_distance_raster_path = 0; + PyObject *__pyx_v_raster_driver_creation_tuple = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_distance_transform_edt (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_region_raster_path,&__pyx_n_s_g_raster_path,&__pyx_n_s_sample_d_x,&__pyx_n_s_sample_d_y,&__pyx_n_s_target_distance_raster_path,&__pyx_n_s_raster_driver_creation_tuple,0}; + PyObject* values[6] = {0,0,0,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 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_region_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_g_raster_path)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_distance_transform_edt", 1, 6, 6, 1); __PYX_ERR(0, 71, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_sample_d_x)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_distance_transform_edt", 1, 6, 6, 2); __PYX_ERR(0, 71, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 3: + if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_sample_d_y)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_distance_transform_edt", 1, 6, 6, 3); __PYX_ERR(0, 71, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 4: + if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_distance_raster_path)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_distance_transform_edt", 1, 6, 6, 4); __PYX_ERR(0, 71, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 5: + if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_raster_driver_creation_tuple)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_distance_transform_edt", 1, 6, 6, 5); __PYX_ERR(0, 71, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_distance_transform_edt") < 0)) __PYX_ERR(0, 71, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 6) { + 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); + values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + } + __pyx_v_region_raster_path = values[0]; + __pyx_v_g_raster_path = values[1]; + __pyx_v_sample_d_x = __pyx_PyFloat_AsFloat(values[2]); if (unlikely((__pyx_v_sample_d_x == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 72, __pyx_L3_error) + __pyx_v_sample_d_y = __pyx_PyFloat_AsFloat(values[3]); if (unlikely((__pyx_v_sample_d_y == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 73, __pyx_L3_error) + __pyx_v_target_distance_raster_path = values[4]; + __pyx_v_raster_driver_creation_tuple = values[5]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("_distance_transform_edt", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 71, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core._distance_transform_edt", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_15pygeoprocessing_18geoprocessing_core__distance_transform_edt(__pyx_self, __pyx_v_region_raster_path, __pyx_v_g_raster_path, __pyx_v_sample_d_x, __pyx_v_sample_d_y, __pyx_v_target_distance_raster_path, __pyx_v_raster_driver_creation_tuple); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core__distance_transform_edt(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_region_raster_path, PyObject *__pyx_v_g_raster_path, float __pyx_v_sample_d_x, float __pyx_v_sample_d_y, PyObject *__pyx_v_target_distance_raster_path, PyObject *__pyx_v_raster_driver_creation_tuple) { + int __pyx_v_yoff; + int __pyx_v_row_index; + int __pyx_v_block_ysize; + int __pyx_v_win_ysize; + int __pyx_v_n_rows; + int __pyx_v_xoff; + int __pyx_v_block_xsize; + int __pyx_v_win_xsize; + int __pyx_v_n_cols; + int __pyx_v_q_index; + int __pyx_v_local_x_index; + int __pyx_v_local_y_index; + int __pyx_v_u_index; + int __pyx_v_tq; + int __pyx_v_sq; + float __pyx_v_gu; + float __pyx_v_gsq; + float __pyx_v_w; + PyArrayObject *__pyx_v_g_block = 0; + PyArrayObject *__pyx_v_s_array = 0; + PyArrayObject *__pyx_v_t_array = 0; + PyArrayObject *__pyx_v_dt = 0; + PyArrayObject *__pyx_v_mask_block = 0; + PyObject *__pyx_v_mask_raster = NULL; + PyObject *__pyx_v_mask_band = NULL; + PyObject *__pyx_v_raster_info = NULL; + PyObject *__pyx_v_g_raster = NULL; + PyObject *__pyx_v_g_band = NULL; + PyObject *__pyx_v_g_band_blocksize = NULL; + PyObject *__pyx_v_max_sample = NULL; + float __pyx_v_numerical_inf; + int __pyx_v_done; + float __pyx_v_distance_nodata; + PyObject *__pyx_v_target_distance_raster = NULL; + PyObject *__pyx_v_target_distance_band = NULL; + PyObject *__pyx_v_valid_mask = NULL; + __Pyx_LocalBuf_ND __pyx_pybuffernd_dt; + __Pyx_Buffer __pyx_pybuffer_dt; + __Pyx_LocalBuf_ND __pyx_pybuffernd_g_block; + __Pyx_Buffer __pyx_pybuffer_g_block; + __Pyx_LocalBuf_ND __pyx_pybuffernd_mask_block; + __Pyx_Buffer __pyx_pybuffer_mask_block; + __Pyx_LocalBuf_ND __pyx_pybuffernd_s_array; + __Pyx_Buffer __pyx_pybuffer_s_array; + __Pyx_LocalBuf_ND __pyx_pybuffernd_t_array; + __Pyx_Buffer __pyx_pybuffer_t_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; + PyObject *__pyx_t_6 = NULL; + float __pyx_t_7; + float __pyx_t_8; + float __pyx_t_9; + double __pyx_t_10; + double __pyx_t_11; + double __pyx_t_12; + PyArrayObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + PyObject *__pyx_t_15 = NULL; + PyObject *__pyx_t_16 = NULL; + PyArrayObject *__pyx_t_17 = NULL; + PyObject *__pyx_t_18 = NULL; + Py_ssize_t __pyx_t_19; + PyObject *(*__pyx_t_20)(PyObject *); + int __pyx_t_21; + int __pyx_t_22; + int __pyx_t_23; + int __pyx_t_24; + int __pyx_t_25; + int __pyx_t_26; + Py_ssize_t __pyx_t_27; + Py_ssize_t __pyx_t_28; + Py_ssize_t __pyx_t_29; + Py_ssize_t __pyx_t_30; + PyArrayObject *__pyx_t_31 = NULL; + PyArrayObject *__pyx_t_32 = NULL; + PyArrayObject *__pyx_t_33 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_distance_transform_edt", 0); + __pyx_pybuffer_g_block.pybuffer.buf = NULL; + __pyx_pybuffer_g_block.refcount = 0; + __pyx_pybuffernd_g_block.data = NULL; + __pyx_pybuffernd_g_block.rcbuffer = &__pyx_pybuffer_g_block; + __pyx_pybuffer_s_array.pybuffer.buf = NULL; + __pyx_pybuffer_s_array.refcount = 0; + __pyx_pybuffernd_s_array.data = NULL; + __pyx_pybuffernd_s_array.rcbuffer = &__pyx_pybuffer_s_array; + __pyx_pybuffer_t_array.pybuffer.buf = NULL; + __pyx_pybuffer_t_array.refcount = 0; + __pyx_pybuffernd_t_array.data = NULL; + __pyx_pybuffernd_t_array.rcbuffer = &__pyx_pybuffer_t_array; + __pyx_pybuffer_dt.pybuffer.buf = NULL; + __pyx_pybuffer_dt.refcount = 0; + __pyx_pybuffernd_dt.data = NULL; + __pyx_pybuffernd_dt.rcbuffer = &__pyx_pybuffer_dt; + __pyx_pybuffer_mask_block.pybuffer.buf = NULL; + __pyx_pybuffer_mask_block.refcount = 0; + __pyx_pybuffernd_mask_block.data = NULL; + __pyx_pybuffernd_mask_block.rcbuffer = &__pyx_pybuffer_mask_block; + + /* "pygeoprocessing/geoprocessing_core.pyx":126 + * cdef numpy.ndarray[numpy.int8_t, ndim=2] mask_block + * + * mask_raster = gdal.OpenEx(region_raster_path, gdal.OF_RASTER) # <<<<<<<<<<<<<< + * mask_band = mask_raster.GetRasterBand(1) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 126, __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, 126, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 126, __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, 126, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + __pyx_t_5 = 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_5 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_region_raster_path, __pyx_t_4}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 126, __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; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_region_raster_path, __pyx_t_4}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 126, __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; + } else + #endif + { + __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 126, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (__pyx_t_2) { + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2); __pyx_t_2 = NULL; + } + __Pyx_INCREF(__pyx_v_region_raster_path); + __Pyx_GIVEREF(__pyx_v_region_raster_path); + PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_region_raster_path); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 126, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_mask_raster = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":127 + * + * mask_raster = gdal.OpenEx(region_raster_path, gdal.OF_RASTER) + * mask_band = mask_raster.GetRasterBand(1) # <<<<<<<<<<<<<< + * + * n_cols = mask_raster.RasterXSize + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_mask_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 127, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_6, __pyx_int_1) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_int_1); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 127, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_mask_band = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":129 + * mask_band = mask_raster.GetRasterBand(1) + * + * n_cols = mask_raster.RasterXSize # <<<<<<<<<<<<<< + * n_rows = mask_raster.RasterYSize + * + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_mask_raster, __pyx_n_s_RasterXSize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 129, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 129, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_n_cols = __pyx_t_5; + + /* "pygeoprocessing/geoprocessing_core.pyx":130 + * + * n_cols = mask_raster.RasterXSize + * n_rows = mask_raster.RasterYSize # <<<<<<<<<<<<<< + * + * raster_info = pygeoprocessing.get_raster_info(region_raster_path) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_mask_raster, __pyx_n_s_RasterYSize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 130, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 130, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_n_rows = __pyx_t_5; + + /* "pygeoprocessing/geoprocessing_core.pyx":132 + * n_rows = mask_raster.RasterYSize + * + * raster_info = pygeoprocessing.get_raster_info(region_raster_path) # <<<<<<<<<<<<<< + * pygeoprocessing.new_raster_from_base( + * region_raster_path, g_raster_path, gdal.GDT_Float32, [_NODATA], + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 132, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 132, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(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); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_3, __pyx_v_region_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_region_raster_path); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 132, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_raster_info = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":133 + * + * raster_info = pygeoprocessing.get_raster_info(region_raster_path) + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * region_raster_path, g_raster_path, gdal.GDT_Float32, [_NODATA], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 133, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 133, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":134 + * raster_info = pygeoprocessing.get_raster_info(region_raster_path) + * pygeoprocessing.new_raster_from_base( + * region_raster_path, g_raster_path, gdal.GDT_Float32, [_NODATA], # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * g_raster = gdal.OpenEx(g_raster_path, gdal.OF_RASTER | gdal.GA_Update) + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 134, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Float32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 134, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_15pygeoprocessing_18geoprocessing_core__NODATA); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 134, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 134, __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; + + /* "pygeoprocessing/geoprocessing_core.pyx":133 + * + * raster_info = pygeoprocessing.get_raster_info(region_raster_path) + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * region_raster_path, g_raster_path, gdal.GDT_Float32, [_NODATA], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + */ + __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 133, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_region_raster_path); + __Pyx_GIVEREF(__pyx_v_region_raster_path); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_region_raster_path); + __Pyx_INCREF(__pyx_v_g_raster_path); + __Pyx_GIVEREF(__pyx_v_g_raster_path); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_g_raster_path); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_4); + __pyx_t_3 = 0; + __pyx_t_4 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":135 + * pygeoprocessing.new_raster_from_base( + * region_raster_path, g_raster_path, gdal.GDT_Float32, [_NODATA], + * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< + * g_raster = gdal.OpenEx(g_raster_path, gdal.OF_RASTER | gdal.GA_Update) + * g_band = g_raster.GetRasterBand(1) + */ + __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 135, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 135, __pyx_L1_error) + + /* "pygeoprocessing/geoprocessing_core.pyx":133 + * + * raster_info = pygeoprocessing.get_raster_info(region_raster_path) + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * region_raster_path, g_raster_path, gdal.GDT_Float32, [_NODATA], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 133, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":136 + * region_raster_path, g_raster_path, gdal.GDT_Float32, [_NODATA], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * g_raster = gdal.OpenEx(g_raster_path, gdal.OF_RASTER | gdal.GA_Update) # <<<<<<<<<<<<<< + * g_band = g_raster.GetRasterBand(1) + * g_band_blocksize = g_band.GetBlockSize() + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 136, __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, 136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_GA_Update); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyNumber_Or(__pyx_t_6, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + __pyx_t_5 = 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_5 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_g_raster_path, __pyx_t_4}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 136, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 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_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_g_raster_path, __pyx_t_4}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 136, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (__pyx_t_2) { + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2); __pyx_t_2 = NULL; + } + __Pyx_INCREF(__pyx_v_g_raster_path); + __Pyx_GIVEREF(__pyx_v_g_raster_path); + PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_g_raster_path); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_g_raster = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":137 + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * g_raster = gdal.OpenEx(g_raster_path, gdal.OF_RASTER | gdal.GA_Update) + * g_band = g_raster.GetRasterBand(1) # <<<<<<<<<<<<<< + * g_band_blocksize = g_band.GetBlockSize() + * + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_g_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 137, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_6, __pyx_int_1) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_int_1); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 137, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_g_band = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":138 + * g_raster = gdal.OpenEx(g_raster_path, gdal.OF_RASTER | gdal.GA_Update) + * g_band = g_raster.GetRasterBand(1) + * g_band_blocksize = g_band.GetBlockSize() # <<<<<<<<<<<<<< + * + * # normalize the sample distances so we don't get a strange numerical + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_g_band, __pyx_n_s_GetBlockSize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 138, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 138, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_g_band_blocksize = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":142 + * # normalize the sample distances so we don't get a strange numerical + * # overflow + * max_sample = max(sample_d_x, sample_d_y) # <<<<<<<<<<<<<< + * sample_d_x /= max_sample + * sample_d_y /= max_sample + */ + __pyx_t_7 = __pyx_v_sample_d_y; + __pyx_t_8 = __pyx_v_sample_d_x; + if (((__pyx_t_7 > __pyx_t_8) != 0)) { + __pyx_t_9 = __pyx_t_7; + } else { + __pyx_t_9 = __pyx_t_8; + } + __pyx_t_3 = PyFloat_FromDouble(__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 142, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_max_sample = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":143 + * # overflow + * max_sample = max(sample_d_x, sample_d_y) + * sample_d_x /= max_sample # <<<<<<<<<<<<<< + * sample_d_y /= max_sample + * + */ + __pyx_t_3 = PyFloat_FromDouble(__pyx_v_sample_d_x); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 143, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_PyNumber_InPlaceDivide(__pyx_t_3, __pyx_v_max_sample); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 143, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_9 = __pyx_PyFloat_AsFloat(__pyx_t_1); if (unlikely((__pyx_t_9 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 143, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_sample_d_x = __pyx_t_9; + + /* "pygeoprocessing/geoprocessing_core.pyx":144 + * max_sample = max(sample_d_x, sample_d_y) + * sample_d_x /= max_sample + * sample_d_y /= max_sample # <<<<<<<<<<<<<< + * + * # distances can't be larger than half the perimeter of the raster. + */ + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_sample_d_y); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 144, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyNumber_InPlaceDivide(__pyx_t_1, __pyx_v_max_sample); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 144, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_9 = __pyx_PyFloat_AsFloat(__pyx_t_3); if (unlikely((__pyx_t_9 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 144, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_sample_d_y = __pyx_t_9; + + /* "pygeoprocessing/geoprocessing_core.pyx":147 + * + * # distances can't be larger than half the perimeter of the raster. + * cdef float numerical_inf = max(sample_d_x, 1.0) * max(sample_d_y, 1.0) * ( # <<<<<<<<<<<<<< + * raster_info['raster_size'][0] + raster_info['raster_size'][1]) + * # scan 1 + */ + __pyx_t_10 = 1.0; + __pyx_t_9 = __pyx_v_sample_d_x; + if (((__pyx_t_10 > __pyx_t_9) != 0)) { + __pyx_t_11 = __pyx_t_10; + } else { + __pyx_t_11 = __pyx_t_9; + } + __pyx_t_10 = 1.0; + __pyx_t_9 = __pyx_v_sample_d_y; + if (((__pyx_t_10 > __pyx_t_9) != 0)) { + __pyx_t_12 = __pyx_t_10; + } else { + __pyx_t_12 = __pyx_t_9; + } + __pyx_t_3 = PyFloat_FromDouble((__pyx_t_11 * __pyx_t_12)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 147, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + + /* "pygeoprocessing/geoprocessing_core.pyx":148 + * # distances can't be larger than half the perimeter of the raster. + * cdef float numerical_inf = max(sample_d_x, 1.0) * max(sample_d_y, 1.0) * ( + * raster_info['raster_size'][0] + raster_info['raster_size'][1]) # <<<<<<<<<<<<<< + * # scan 1 + * done = False + */ + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 148, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 148, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 148, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_1, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 148, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Add(__pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 148, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":147 + * + * # distances can't be larger than half the perimeter of the raster. + * cdef float numerical_inf = max(sample_d_x, 1.0) * max(sample_d_y, 1.0) * ( # <<<<<<<<<<<<<< + * raster_info['raster_size'][0] + raster_info['raster_size'][1]) + * # scan 1 + */ + __pyx_t_4 = PyNumber_Multiply(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 147, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_9 = __pyx_PyFloat_AsFloat(__pyx_t_4); if (unlikely((__pyx_t_9 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 147, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_numerical_inf = __pyx_t_9; + + /* "pygeoprocessing/geoprocessing_core.pyx":150 + * raster_info['raster_size'][0] + raster_info['raster_size'][1]) + * # scan 1 + * done = False # <<<<<<<<<<<<<< + * block_xsize = raster_info['block_size'][0] + * mask_block = numpy.empty((n_rows, block_xsize), dtype=numpy.int8) + */ + __pyx_v_done = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":151 + * # scan 1 + * done = False + * block_xsize = raster_info['block_size'][0] # <<<<<<<<<<<<<< + * mask_block = numpy.empty((n_rows, block_xsize), dtype=numpy.int8) + * g_block = numpy.empty((n_rows, block_xsize), dtype=numpy.float32) + */ + __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_block_size); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 151, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_4, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 151, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 151, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_block_xsize = __pyx_t_5; + + /* "pygeoprocessing/geoprocessing_core.pyx":152 + * done = False + * block_xsize = raster_info['block_size'][0] + * mask_block = numpy.empty((n_rows, block_xsize), dtype=numpy.int8) # <<<<<<<<<<<<<< + * g_block = numpy.empty((n_rows, block_xsize), dtype=numpy.float32) + * for xoff in numpy.arange(0, n_cols, block_xsize): + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 152, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 152, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_n_rows); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 152, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_block_xsize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 152, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 152, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_3); + __pyx_t_1 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 152, __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; + __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 152, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 152, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_int8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 152, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 152, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 152, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 152, __pyx_L1_error) + __pyx_t_13 = ((PyArrayObject *)__pyx_t_2); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer); + __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); + if (unlikely(__pyx_t_5 < 0)) { + PyErr_Fetch(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer, (PyObject*)__pyx_v_mask_block, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_16); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_14, __pyx_t_15, __pyx_t_16); + } + __pyx_t_14 = __pyx_t_15 = __pyx_t_16 = 0; + } + __pyx_pybuffernd_mask_block.diminfo[0].strides = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_mask_block.diminfo[0].shape = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_mask_block.diminfo[1].strides = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_mask_block.diminfo[1].shape = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.shape[1]; + if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 152, __pyx_L1_error) + } + __pyx_t_13 = 0; + __pyx_v_mask_block = ((PyArrayObject *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":153 + * block_xsize = raster_info['block_size'][0] + * mask_block = numpy.empty((n_rows, block_xsize), dtype=numpy.int8) + * g_block = numpy.empty((n_rows, block_xsize), dtype=numpy.float32) # <<<<<<<<<<<<<< + * for xoff in numpy.arange(0, n_cols, block_xsize): + * win_xsize = block_xsize + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 153, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 153, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_n_rows); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 153, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_block_xsize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 153, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 153, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 153, __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 = 0; + __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 153, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 153, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 153, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 153, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 153, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 153, __pyx_L1_error) + __pyx_t_17 = ((PyArrayObject *)__pyx_t_1); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer); + __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer, (PyObject*)__pyx_t_17, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack); + if (unlikely(__pyx_t_5 < 0)) { + PyErr_Fetch(&__pyx_t_16, &__pyx_t_15, &__pyx_t_14); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer, (PyObject*)__pyx_v_g_block, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_16); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_14); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_16, __pyx_t_15, __pyx_t_14); + } + __pyx_t_16 = __pyx_t_15 = __pyx_t_14 = 0; + } + __pyx_pybuffernd_g_block.diminfo[0].strides = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_g_block.diminfo[0].shape = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_g_block.diminfo[1].strides = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_g_block.diminfo[1].shape = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.shape[1]; + if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 153, __pyx_L1_error) + } + __pyx_t_17 = 0; + __pyx_v_g_block = ((PyArrayObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":154 + * mask_block = numpy.empty((n_rows, block_xsize), dtype=numpy.int8) + * g_block = numpy.empty((n_rows, block_xsize), dtype=numpy.float32) + * for xoff in numpy.arange(0, n_cols, block_xsize): # <<<<<<<<<<<<<< + * win_xsize = block_xsize + * if xoff + win_xsize > n_cols: + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_numpy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 154, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_arange); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 154, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 154, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_block_xsize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 154, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_2 = NULL; + __pyx_t_5 = 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_5 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_int_0, __pyx_t_4, __pyx_t_6}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 154, __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_6); __pyx_t_6 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_int_0, __pyx_t_4, __pyx_t_6}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 154, __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_6); __pyx_t_6 = 0; + } else + #endif + { + __pyx_t_18 = PyTuple_New(3+__pyx_t_5); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 154, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + if (__pyx_t_2) { + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_2); __pyx_t_2 = NULL; + } + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_18, 0+__pyx_t_5, __pyx_int_0); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_18, 1+__pyx_t_5, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_18, 2+__pyx_t_5, __pyx_t_6); + __pyx_t_4 = 0; + __pyx_t_6 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_18, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 154, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_19 = 0; + __pyx_t_20 = NULL; + } else { + __pyx_t_19 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 154, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_20 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 154, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (likely(!__pyx_t_20)) { + if (likely(PyList_CheckExact(__pyx_t_3))) { + if (__pyx_t_19 >= PyList_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_19); __Pyx_INCREF(__pyx_t_1); __pyx_t_19++; if (unlikely(0 < 0)) __PYX_ERR(0, 154, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 154, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } else { + if (__pyx_t_19 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_19); __Pyx_INCREF(__pyx_t_1); __pyx_t_19++; if (unlikely(0 < 0)) __PYX_ERR(0, 154, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 154, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } + } else { + __pyx_t_1 = __pyx_t_20(__pyx_t_3); + 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, 154, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 154, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_xoff = __pyx_t_5; + + /* "pygeoprocessing/geoprocessing_core.pyx":155 + * g_block = numpy.empty((n_rows, block_xsize), dtype=numpy.float32) + * for xoff in numpy.arange(0, n_cols, block_xsize): + * win_xsize = block_xsize # <<<<<<<<<<<<<< + * if xoff + win_xsize > n_cols: + * win_xsize = n_cols - xoff + */ + __pyx_v_win_xsize = __pyx_v_block_xsize; + + /* "pygeoprocessing/geoprocessing_core.pyx":156 + * for xoff in numpy.arange(0, n_cols, block_xsize): + * win_xsize = block_xsize + * if xoff + win_xsize > n_cols: # <<<<<<<<<<<<<< + * win_xsize = n_cols - xoff + * mask_block = numpy.empty((n_rows, win_xsize), dtype=numpy.int8) + */ + __pyx_t_21 = (((__pyx_v_xoff + __pyx_v_win_xsize) > __pyx_v_n_cols) != 0); + if (__pyx_t_21) { + + /* "pygeoprocessing/geoprocessing_core.pyx":157 + * win_xsize = block_xsize + * if xoff + win_xsize > n_cols: + * win_xsize = n_cols - xoff # <<<<<<<<<<<<<< + * mask_block = numpy.empty((n_rows, win_xsize), dtype=numpy.int8) + * g_block = numpy.empty((n_rows, win_xsize), dtype=numpy.float32) + */ + __pyx_v_win_xsize = (__pyx_v_n_cols - __pyx_v_xoff); + + /* "pygeoprocessing/geoprocessing_core.pyx":158 + * if xoff + win_xsize > n_cols: + * win_xsize = n_cols - xoff + * mask_block = numpy.empty((n_rows, win_xsize), dtype=numpy.int8) # <<<<<<<<<<<<<< + * g_block = numpy.empty((n_rows, win_xsize), dtype=numpy.float32) + * done = True + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 158, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_18 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 158, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_n_rows); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 158, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 158, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 158, __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_6); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_6); + __pyx_t_1 = 0; + __pyx_t_6 = 0; + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 158, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 158, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 158, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_int8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 158, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 158, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_18, __pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 158, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 158, __pyx_L1_error) + __pyx_t_13 = ((PyArrayObject *)__pyx_t_2); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer); + __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); + if (unlikely(__pyx_t_5 < 0)) { + PyErr_Fetch(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer, (PyObject*)__pyx_v_mask_block, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_16); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_14, __pyx_t_15, __pyx_t_16); + } + __pyx_t_14 = __pyx_t_15 = __pyx_t_16 = 0; + } + __pyx_pybuffernd_mask_block.diminfo[0].strides = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_mask_block.diminfo[0].shape = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_mask_block.diminfo[1].strides = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_mask_block.diminfo[1].shape = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.shape[1]; + if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 158, __pyx_L1_error) + } + __pyx_t_13 = 0; + __Pyx_DECREF_SET(__pyx_v_mask_block, ((PyArrayObject *)__pyx_t_2)); + __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":159 + * win_xsize = n_cols - xoff + * mask_block = numpy.empty((n_rows, win_xsize), dtype=numpy.int8) + * g_block = numpy.empty((n_rows, win_xsize), dtype=numpy.float32) # <<<<<<<<<<<<<< + * done = True + * mask_band.ReadAsArray( + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 159, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 159, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_n_rows); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 159, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 159, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_18 = PyTuple_New(2); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 159, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_18, 1, __pyx_t_6); + __pyx_t_2 = 0; + __pyx_t_6 = 0; + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 159, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_18); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_18); + __pyx_t_18 = 0; + __pyx_t_18 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 159, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 159, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 159, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_t_18, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 159, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, __pyx_t_18); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 159, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 159, __pyx_L1_error) + __pyx_t_17 = ((PyArrayObject *)__pyx_t_1); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer); + __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer, (PyObject*)__pyx_t_17, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack); + if (unlikely(__pyx_t_5 < 0)) { + PyErr_Fetch(&__pyx_t_16, &__pyx_t_15, &__pyx_t_14); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer, (PyObject*)__pyx_v_g_block, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_16); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_14); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_16, __pyx_t_15, __pyx_t_14); + } + __pyx_t_16 = __pyx_t_15 = __pyx_t_14 = 0; + } + __pyx_pybuffernd_g_block.diminfo[0].strides = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_g_block.diminfo[0].shape = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_g_block.diminfo[1].strides = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_g_block.diminfo[1].shape = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.shape[1]; + if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 159, __pyx_L1_error) + } + __pyx_t_17 = 0; + __Pyx_DECREF_SET(__pyx_v_g_block, ((PyArrayObject *)__pyx_t_1)); + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":160 + * mask_block = numpy.empty((n_rows, win_xsize), dtype=numpy.int8) + * g_block = numpy.empty((n_rows, win_xsize), dtype=numpy.float32) + * done = True # <<<<<<<<<<<<<< + * mask_band.ReadAsArray( + * xoff=xoff, yoff=0, win_xsize=win_xsize, win_ysize=n_rows, + */ + __pyx_v_done = 1; + + /* "pygeoprocessing/geoprocessing_core.pyx":156 + * for xoff in numpy.arange(0, n_cols, block_xsize): + * win_xsize = block_xsize + * if xoff + win_xsize > n_cols: # <<<<<<<<<<<<<< + * win_xsize = n_cols - xoff + * mask_block = numpy.empty((n_rows, win_xsize), dtype=numpy.int8) + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":161 + * g_block = numpy.empty((n_rows, win_xsize), dtype=numpy.float32) + * done = True + * mask_band.ReadAsArray( # <<<<<<<<<<<<<< + * xoff=xoff, yoff=0, win_xsize=win_xsize, win_ysize=n_rows, + * buf_obj=mask_block) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_mask_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 161, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/geoprocessing_core.pyx":162 + * done = True + * mask_band.ReadAsArray( + * xoff=xoff, yoff=0, win_xsize=win_xsize, win_ysize=n_rows, # <<<<<<<<<<<<<< + * buf_obj=mask_block) + * # base case + */ + __pyx_t_18 = __Pyx_PyDict_NewPresized(5); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 162, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_xoff); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 162, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_t_18, __pyx_n_s_xoff, __pyx_t_6) < 0) __PYX_ERR(0, 162, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (PyDict_SetItem(__pyx_t_18, __pyx_n_s_yoff, __pyx_int_0) < 0) __PYX_ERR(0, 162, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 162, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_t_18, __pyx_n_s_win_xsize, __pyx_t_6) < 0) __PYX_ERR(0, 162, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_n_rows); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 162, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_t_18, __pyx_n_s_win_ysize, __pyx_t_6) < 0) __PYX_ERR(0, 162, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":163 + * mask_band.ReadAsArray( + * xoff=xoff, yoff=0, win_xsize=win_xsize, win_ysize=n_rows, + * buf_obj=mask_block) # <<<<<<<<<<<<<< + * # base case + * g_block[0, :] = (mask_block[0, :] == 0) * numerical_inf + */ + if (PyDict_SetItem(__pyx_t_18, __pyx_n_s_buf_obj, ((PyObject *)__pyx_v_mask_block)) < 0) __PYX_ERR(0, 162, __pyx_L1_error) + + /* "pygeoprocessing/geoprocessing_core.pyx":161 + * g_block = numpy.empty((n_rows, win_xsize), dtype=numpy.float32) + * done = True + * mask_band.ReadAsArray( # <<<<<<<<<<<<<< + * xoff=xoff, yoff=0, win_xsize=win_xsize, win_ysize=n_rows, + * buf_obj=mask_block) + */ + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_18); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 161, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":165 + * buf_obj=mask_block) + * # base case + * g_block[0, :] = (mask_block[0, :] == 0) * numerical_inf # <<<<<<<<<<<<<< + * for row_index in range(1, n_rows): + * for local_x_index in range(win_xsize): + */ + __pyx_t_6 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_mask_block), __pyx_tuple__2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 165, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_18 = __Pyx_PyInt_EqObjC(__pyx_t_6, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 165, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = PyFloat_FromDouble(__pyx_v_numerical_inf); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 165, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_1 = PyNumber_Multiply(__pyx_t_18, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 165, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_g_block), __pyx_tuple__2, __pyx_t_1) < 0)) __PYX_ERR(0, 165, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":166 + * # base case + * g_block[0, :] = (mask_block[0, :] == 0) * numerical_inf + * for row_index in range(1, n_rows): # <<<<<<<<<<<<<< + * for local_x_index in range(win_xsize): + * if mask_block[row_index, local_x_index] == 1: + */ + __pyx_t_5 = __pyx_v_n_rows; + __pyx_t_22 = __pyx_t_5; + for (__pyx_t_23 = 1; __pyx_t_23 < __pyx_t_22; __pyx_t_23+=1) { + __pyx_v_row_index = __pyx_t_23; + + /* "pygeoprocessing/geoprocessing_core.pyx":167 + * g_block[0, :] = (mask_block[0, :] == 0) * numerical_inf + * for row_index in range(1, n_rows): + * for local_x_index in range(win_xsize): # <<<<<<<<<<<<<< + * if mask_block[row_index, local_x_index] == 1: + * g_block[row_index, local_x_index] = 0 + */ + __pyx_t_24 = __pyx_v_win_xsize; + __pyx_t_25 = __pyx_t_24; + for (__pyx_t_26 = 0; __pyx_t_26 < __pyx_t_25; __pyx_t_26+=1) { + __pyx_v_local_x_index = __pyx_t_26; + + /* "pygeoprocessing/geoprocessing_core.pyx":168 + * for row_index in range(1, n_rows): + * for local_x_index in range(win_xsize): + * if mask_block[row_index, local_x_index] == 1: # <<<<<<<<<<<<<< + * g_block[row_index, local_x_index] = 0 + * else: + */ + __pyx_t_27 = __pyx_v_row_index; + __pyx_t_28 = __pyx_v_local_x_index; + __pyx_t_21 = (((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int8_t *, __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_mask_block.diminfo[0].strides, __pyx_t_28, __pyx_pybuffernd_mask_block.diminfo[1].strides)) == 1) != 0); + if (__pyx_t_21) { + + /* "pygeoprocessing/geoprocessing_core.pyx":169 + * for local_x_index in range(win_xsize): + * if mask_block[row_index, local_x_index] == 1: + * g_block[row_index, local_x_index] = 0 # <<<<<<<<<<<<<< + * else: + * g_block[row_index, local_x_index] = ( + */ + __pyx_t_28 = __pyx_v_row_index; + __pyx_t_27 = __pyx_v_local_x_index; + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_28, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_27, __pyx_pybuffernd_g_block.diminfo[1].strides) = 0.0; + + /* "pygeoprocessing/geoprocessing_core.pyx":168 + * for row_index in range(1, n_rows): + * for local_x_index in range(win_xsize): + * if mask_block[row_index, local_x_index] == 1: # <<<<<<<<<<<<<< + * g_block[row_index, local_x_index] = 0 + * else: + */ + goto __pyx_L10; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":172 + * else: + * g_block[row_index, local_x_index] = ( + * g_block[row_index-1, local_x_index] + sample_d_y) # <<<<<<<<<<<<<< + * for row_index in range(n_rows-2, -1, -1): + * for local_x_index in range(win_xsize): + */ + /*else*/ { + __pyx_t_27 = (__pyx_v_row_index - 1); + __pyx_t_28 = __pyx_v_local_x_index; + + /* "pygeoprocessing/geoprocessing_core.pyx":171 + * g_block[row_index, local_x_index] = 0 + * else: + * g_block[row_index, local_x_index] = ( # <<<<<<<<<<<<<< + * g_block[row_index-1, local_x_index] + sample_d_y) + * for row_index in range(n_rows-2, -1, -1): + */ + __pyx_t_29 = __pyx_v_row_index; + __pyx_t_30 = __pyx_v_local_x_index; + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_g_block.diminfo[1].strides) = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_28, __pyx_pybuffernd_g_block.diminfo[1].strides)) + __pyx_v_sample_d_y); + } + __pyx_L10:; + } + } + + /* "pygeoprocessing/geoprocessing_core.pyx":173 + * g_block[row_index, local_x_index] = ( + * g_block[row_index-1, local_x_index] + sample_d_y) + * for row_index in range(n_rows-2, -1, -1): # <<<<<<<<<<<<<< + * for local_x_index in range(win_xsize): + * if (g_block[row_index+1, local_x_index] < + */ + for (__pyx_t_5 = (__pyx_v_n_rows - 2); __pyx_t_5 > -1; __pyx_t_5-=1) { + __pyx_v_row_index = __pyx_t_5; + + /* "pygeoprocessing/geoprocessing_core.pyx":174 + * g_block[row_index-1, local_x_index] + sample_d_y) + * for row_index in range(n_rows-2, -1, -1): + * for local_x_index in range(win_xsize): # <<<<<<<<<<<<<< + * if (g_block[row_index+1, local_x_index] < + * g_block[row_index, local_x_index]): + */ + __pyx_t_22 = __pyx_v_win_xsize; + __pyx_t_23 = __pyx_t_22; + for (__pyx_t_24 = 0; __pyx_t_24 < __pyx_t_23; __pyx_t_24+=1) { + __pyx_v_local_x_index = __pyx_t_24; + + /* "pygeoprocessing/geoprocessing_core.pyx":175 + * for row_index in range(n_rows-2, -1, -1): + * for local_x_index in range(win_xsize): + * if (g_block[row_index+1, local_x_index] < # <<<<<<<<<<<<<< + * g_block[row_index, local_x_index]): + * g_block[row_index, local_x_index] = ( + */ + __pyx_t_28 = (__pyx_v_row_index + 1); + __pyx_t_27 = __pyx_v_local_x_index; + + /* "pygeoprocessing/geoprocessing_core.pyx":176 + * for local_x_index in range(win_xsize): + * if (g_block[row_index+1, local_x_index] < + * g_block[row_index, local_x_index]): # <<<<<<<<<<<<<< + * g_block[row_index, local_x_index] = ( + * sample_d_y + g_block[row_index+1, local_x_index]) + */ + __pyx_t_30 = __pyx_v_row_index; + __pyx_t_29 = __pyx_v_local_x_index; + + /* "pygeoprocessing/geoprocessing_core.pyx":175 + * for row_index in range(n_rows-2, -1, -1): + * for local_x_index in range(win_xsize): + * if (g_block[row_index+1, local_x_index] < # <<<<<<<<<<<<<< + * g_block[row_index, local_x_index]): + * g_block[row_index, local_x_index] = ( + */ + __pyx_t_21 = (((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_28, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_27, __pyx_pybuffernd_g_block.diminfo[1].strides)) < (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_g_block.diminfo[1].strides))) != 0); + if (__pyx_t_21) { + + /* "pygeoprocessing/geoprocessing_core.pyx":178 + * g_block[row_index, local_x_index]): + * g_block[row_index, local_x_index] = ( + * sample_d_y + g_block[row_index+1, local_x_index]) # <<<<<<<<<<<<<< + * g_band.WriteArray(g_block, xoff=xoff, yoff=0) + * if done: + */ + __pyx_t_29 = (__pyx_v_row_index + 1); + __pyx_t_30 = __pyx_v_local_x_index; + + /* "pygeoprocessing/geoprocessing_core.pyx":177 + * if (g_block[row_index+1, local_x_index] < + * g_block[row_index, local_x_index]): + * g_block[row_index, local_x_index] = ( # <<<<<<<<<<<<<< + * sample_d_y + g_block[row_index+1, local_x_index]) + * g_band.WriteArray(g_block, xoff=xoff, yoff=0) + */ + __pyx_t_27 = __pyx_v_row_index; + __pyx_t_28 = __pyx_v_local_x_index; + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_28, __pyx_pybuffernd_g_block.diminfo[1].strides) = (__pyx_v_sample_d_y + (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_g_block.diminfo[1].strides))); + + /* "pygeoprocessing/geoprocessing_core.pyx":175 + * for row_index in range(n_rows-2, -1, -1): + * for local_x_index in range(win_xsize): + * if (g_block[row_index+1, local_x_index] < # <<<<<<<<<<<<<< + * g_block[row_index, local_x_index]): + * g_block[row_index, local_x_index] = ( + */ + } + } + } + + /* "pygeoprocessing/geoprocessing_core.pyx":179 + * g_block[row_index, local_x_index] = ( + * sample_d_y + g_block[row_index+1, local_x_index]) + * g_band.WriteArray(g_block, xoff=xoff, yoff=0) # <<<<<<<<<<<<<< + * if done: + * break + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_g_band, __pyx_n_s_WriteArray); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 179, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 179, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(((PyObject *)__pyx_v_g_block)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_g_block)); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_g_block)); + __pyx_t_18 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 179, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_xoff); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 179, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_18, __pyx_n_s_xoff, __pyx_t_4) < 0) __PYX_ERR(0, 179, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (PyDict_SetItem(__pyx_t_18, __pyx_n_s_yoff, __pyx_int_0) < 0) __PYX_ERR(0, 179, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, __pyx_t_18); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 179, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":180 + * sample_d_y + g_block[row_index+1, local_x_index]) + * g_band.WriteArray(g_block, xoff=xoff, yoff=0) + * if done: # <<<<<<<<<<<<<< + * break + * g_band.FlushCache() + */ + __pyx_t_21 = (__pyx_v_done != 0); + if (__pyx_t_21) { + + /* "pygeoprocessing/geoprocessing_core.pyx":181 + * g_band.WriteArray(g_block, xoff=xoff, yoff=0) + * if done: + * break # <<<<<<<<<<<<<< + * g_band.FlushCache() + * + */ + goto __pyx_L4_break; + + /* "pygeoprocessing/geoprocessing_core.pyx":180 + * sample_d_y + g_block[row_index+1, local_x_index]) + * g_band.WriteArray(g_block, xoff=xoff, yoff=0) + * if done: # <<<<<<<<<<<<<< + * break + * g_band.FlushCache() + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":154 + * mask_block = numpy.empty((n_rows, block_xsize), dtype=numpy.int8) + * g_block = numpy.empty((n_rows, block_xsize), dtype=numpy.float32) + * for xoff in numpy.arange(0, n_cols, block_xsize): # <<<<<<<<<<<<<< + * win_xsize = block_xsize + * if xoff + win_xsize > n_cols: + */ + } + __pyx_L4_break:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":182 + * if done: + * break + * g_band.FlushCache() # <<<<<<<<<<<<<< + * + * cdef float distance_nodata = -1.0 + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_g_band, __pyx_n_s_FlushCache); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 182, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_18 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_18 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_18)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_18); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_3 = (__pyx_t_18) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_18) : __Pyx_PyObject_CallNoArg(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 182, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":184 + * g_band.FlushCache() + * + * cdef float distance_nodata = -1.0 # <<<<<<<<<<<<<< + * + * pygeoprocessing.new_raster_from_base( + */ + __pyx_v_distance_nodata = -1.0; + + /* "pygeoprocessing/geoprocessing_core.pyx":186 + * cdef float distance_nodata = -1.0 + * + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * region_raster_path, target_distance_raster_path.encode('utf-8'), + * gdal.GDT_Float32, [distance_nodata], + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 186, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 186, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":187 + * + * pygeoprocessing.new_raster_from_base( + * region_raster_path, target_distance_raster_path.encode('utf-8'), # <<<<<<<<<<<<<< + * gdal.GDT_Float32, [distance_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + */ + __pyx_t_18 = __Pyx_PyObject_GetAttrStr(__pyx_v_target_distance_raster_path, __pyx_n_s_encode); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 187, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_18))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_18); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_18); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_18, function); + } + } + __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_18, __pyx_t_6, __pyx_kp_u_utf_8) : __Pyx_PyObject_CallOneArg(__pyx_t_18, __pyx_kp_u_utf_8); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 187, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":188 + * pygeoprocessing.new_raster_from_base( + * region_raster_path, target_distance_raster_path.encode('utf-8'), + * gdal.GDT_Float32, [distance_nodata], # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * target_distance_raster = gdal.OpenEx( + */ + __Pyx_GetModuleGlobalName(__pyx_t_18, __pyx_n_s_gdal); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 188, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_18, __pyx_n_s_GDT_Float32); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 188, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __pyx_t_18 = PyFloat_FromDouble(__pyx_v_distance_nodata); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 188, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 188, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_18); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_18); + __pyx_t_18 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":186 + * cdef float distance_nodata = -1.0 + * + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * region_raster_path, target_distance_raster_path.encode('utf-8'), + * gdal.GDT_Float32, [distance_nodata], + */ + __pyx_t_18 = PyTuple_New(4); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 186, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_INCREF(__pyx_v_region_raster_path); + __Pyx_GIVEREF(__pyx_v_region_raster_path); + PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_v_region_raster_path); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_18, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_18, 2, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_18, 3, __pyx_t_1); + __pyx_t_3 = 0; + __pyx_t_6 = 0; + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":189 + * region_raster_path, target_distance_raster_path.encode('utf-8'), + * gdal.GDT_Float32, [distance_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< + * target_distance_raster = gdal.OpenEx( + * target_distance_raster_path, gdal.OF_RASTER | gdal.GA_Update) + */ + __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 189, __pyx_L1_error) + + /* "pygeoprocessing/geoprocessing_core.pyx":186 + * cdef float distance_nodata = -1.0 + * + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * region_raster_path, target_distance_raster_path.encode('utf-8'), + * gdal.GDT_Float32, [distance_nodata], + */ + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_18, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 186, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":190 + * gdal.GDT_Float32, [distance_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * target_distance_raster = gdal.OpenEx( # <<<<<<<<<<<<<< + * target_distance_raster_path, gdal.OF_RASTER | gdal.GA_Update) + * target_distance_band = target_distance_raster.GetRasterBand(1) + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 190, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_18 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 190, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":191 + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * target_distance_raster = gdal.OpenEx( + * target_distance_raster_path, gdal.OF_RASTER | gdal.GA_Update) # <<<<<<<<<<<<<< + * target_distance_band = target_distance_raster.GetRasterBand(1) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 191, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 191, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 191, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GA_Update); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 191, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Or(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 191, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + __pyx_t_5 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_18))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_18); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_18); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_18, function); + __pyx_t_5 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_18)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_target_distance_raster_path, __pyx_t_1}; + __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_18, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 190, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_18)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_target_distance_raster_path, __pyx_t_1}; + __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_18, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 190, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + { + __pyx_t_4 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 190, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_INCREF(__pyx_v_target_distance_raster_path); + __Pyx_GIVEREF(__pyx_v_target_distance_raster_path); + PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_5, __pyx_v_target_distance_raster_path); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_5, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_18, __pyx_t_4, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 190, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __pyx_v_target_distance_raster = __pyx_t_6; + __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":192 + * target_distance_raster = gdal.OpenEx( + * target_distance_raster_path, gdal.OF_RASTER | gdal.GA_Update) + * target_distance_band = target_distance_raster.GetRasterBand(1) # <<<<<<<<<<<<<< + * + * LOGGER.info('Distance Transform Phase 2') + */ + __pyx_t_18 = __Pyx_PyObject_GetAttrStr(__pyx_v_target_distance_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 192, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_18))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_18); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_18); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_18, function); + } + } + __pyx_t_6 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_18, __pyx_t_4, __pyx_int_1) : __Pyx_PyObject_CallOneArg(__pyx_t_18, __pyx_int_1); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 192, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __pyx_v_target_distance_band = __pyx_t_6; + __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":194 + * target_distance_band = target_distance_raster.GetRasterBand(1) + * + * LOGGER.info('Distance Transform Phase 2') # <<<<<<<<<<<<<< + * s_array = numpy.empty(n_cols, dtype=numpy.int32) + * t_array = numpy.empty(n_cols, dtype=numpy.int32) + */ + __Pyx_GetModuleGlobalName(__pyx_t_18, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 194, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_18, __pyx_n_s_info); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 194, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __pyx_t_18 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_18 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_18)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_18); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_6 = (__pyx_t_18) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_18, __pyx_kp_u_Distance_Transform_Phase_2) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_Distance_Transform_Phase_2); + __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 194, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":195 + * + * LOGGER.info('Distance Transform Phase 2') + * s_array = numpy.empty(n_cols, dtype=numpy.int32) # <<<<<<<<<<<<<< + * t_array = numpy.empty(n_cols, dtype=numpy.int32) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_numpy); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 195, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 195, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 195, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_18 = PyTuple_New(1); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 195, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_6); + __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 195, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 195, __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, 195, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 195, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_18, __pyx_t_6); 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_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 195, __pyx_L1_error) + __pyx_t_31 = ((PyArrayObject *)__pyx_t_3); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_s_array.rcbuffer->pybuffer); + __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_s_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_31, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack); + if (unlikely(__pyx_t_5 < 0)) { + PyErr_Fetch(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_s_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_s_array, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_16); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_14, __pyx_t_15, __pyx_t_16); + } + __pyx_t_14 = __pyx_t_15 = __pyx_t_16 = 0; + } + __pyx_pybuffernd_s_array.diminfo[0].strides = __pyx_pybuffernd_s_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_s_array.diminfo[0].shape = __pyx_pybuffernd_s_array.rcbuffer->pybuffer.shape[0]; + if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 195, __pyx_L1_error) + } + __pyx_t_31 = 0; + __pyx_v_s_array = ((PyArrayObject *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":196 + * LOGGER.info('Distance Transform Phase 2') + * s_array = numpy.empty(n_cols, dtype=numpy.int32) + * t_array = numpy.empty(n_cols, dtype=numpy.int32) # <<<<<<<<<<<<<< + * + * done = False + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 196, __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, 196, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 196, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_18 = PyTuple_New(1); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 196, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 196, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_numpy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 196, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 196, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 196, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_18, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 196, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 196, __pyx_L1_error) + __pyx_t_32 = ((PyArrayObject *)__pyx_t_1); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t_array.rcbuffer->pybuffer); + __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_t_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_32, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack); + if (unlikely(__pyx_t_5 < 0)) { + PyErr_Fetch(&__pyx_t_16, &__pyx_t_15, &__pyx_t_14); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_t_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_t_array, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_16); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_14); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_16, __pyx_t_15, __pyx_t_14); + } + __pyx_t_16 = __pyx_t_15 = __pyx_t_14 = 0; + } + __pyx_pybuffernd_t_array.diminfo[0].strides = __pyx_pybuffernd_t_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_t_array.diminfo[0].shape = __pyx_pybuffernd_t_array.rcbuffer->pybuffer.shape[0]; + if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 196, __pyx_L1_error) + } + __pyx_t_32 = 0; + __pyx_v_t_array = ((PyArrayObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":198 + * t_array = numpy.empty(n_cols, dtype=numpy.int32) + * + * done = False # <<<<<<<<<<<<<< + * block_ysize = g_band_blocksize[1] + * g_block = numpy.empty((block_ysize, n_cols), dtype=numpy.float32) + */ + __pyx_v_done = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":199 + * + * done = False + * block_ysize = g_band_blocksize[1] # <<<<<<<<<<<<<< + * g_block = numpy.empty((block_ysize, n_cols), dtype=numpy.float32) + * dt = numpy.empty((block_ysize, n_cols), dtype=numpy.float32) + */ + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_g_band_blocksize, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 199, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 199, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_block_ysize = __pyx_t_5; + + /* "pygeoprocessing/geoprocessing_core.pyx":200 + * done = False + * block_ysize = g_band_blocksize[1] + * g_block = numpy.empty((block_ysize, n_cols), dtype=numpy.float32) # <<<<<<<<<<<<<< + * dt = numpy.empty((block_ysize, n_cols), dtype=numpy.float32) + * mask_block = numpy.empty((block_ysize, n_cols), dtype=numpy.int8) + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 200, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 200, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_block_ysize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 200, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_18 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 200, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 200, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_18); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_18); + __pyx_t_1 = 0; + __pyx_t_18 = 0; + __pyx_t_18 = PyTuple_New(1); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 200, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_6); + __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 200, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 200, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 200, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 200, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_18, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 200, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 200, __pyx_L1_error) + __pyx_t_17 = ((PyArrayObject *)__pyx_t_4); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer); + __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer, (PyObject*)__pyx_t_17, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack); + if (unlikely(__pyx_t_5 < 0)) { + PyErr_Fetch(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer, (PyObject*)__pyx_v_g_block, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_16); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_14, __pyx_t_15, __pyx_t_16); + } + __pyx_t_14 = __pyx_t_15 = __pyx_t_16 = 0; + } + __pyx_pybuffernd_g_block.diminfo[0].strides = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_g_block.diminfo[0].shape = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_g_block.diminfo[1].strides = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_g_block.diminfo[1].shape = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.shape[1]; + if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 200, __pyx_L1_error) + } + __pyx_t_17 = 0; + __Pyx_DECREF_SET(__pyx_v_g_block, ((PyArrayObject *)__pyx_t_4)); + __pyx_t_4 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":201 + * block_ysize = g_band_blocksize[1] + * g_block = numpy.empty((block_ysize, n_cols), dtype=numpy.float32) + * dt = numpy.empty((block_ysize, n_cols), dtype=numpy.float32) # <<<<<<<<<<<<<< + * mask_block = numpy.empty((block_ysize, n_cols), dtype=numpy.int8) + * sq = 0 # initialize so compiler doesn't complain + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_numpy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 201, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 201, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_block_ysize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 201, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_18 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 201, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 201, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_18); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_18); + __pyx_t_4 = 0; + __pyx_t_18 = 0; + __pyx_t_18 = PyTuple_New(1); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 201, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 201, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_numpy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 201, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 201, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 201, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_18, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 201, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 201, __pyx_L1_error) + __pyx_t_33 = ((PyArrayObject *)__pyx_t_1); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dt.rcbuffer->pybuffer); + __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dt.rcbuffer->pybuffer, (PyObject*)__pyx_t_33, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack); + if (unlikely(__pyx_t_5 < 0)) { + PyErr_Fetch(&__pyx_t_16, &__pyx_t_15, &__pyx_t_14); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dt.rcbuffer->pybuffer, (PyObject*)__pyx_v_dt, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_16); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_14); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_16, __pyx_t_15, __pyx_t_14); + } + __pyx_t_16 = __pyx_t_15 = __pyx_t_14 = 0; + } + __pyx_pybuffernd_dt.diminfo[0].strides = __pyx_pybuffernd_dt.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_dt.diminfo[0].shape = __pyx_pybuffernd_dt.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_dt.diminfo[1].strides = __pyx_pybuffernd_dt.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_dt.diminfo[1].shape = __pyx_pybuffernd_dt.rcbuffer->pybuffer.shape[1]; + if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 201, __pyx_L1_error) + } + __pyx_t_33 = 0; + __pyx_v_dt = ((PyArrayObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":202 + * g_block = numpy.empty((block_ysize, n_cols), dtype=numpy.float32) + * dt = numpy.empty((block_ysize, n_cols), dtype=numpy.float32) + * mask_block = numpy.empty((block_ysize, n_cols), dtype=numpy.int8) # <<<<<<<<<<<<<< + * sq = 0 # initialize so compiler doesn't complain + * gsq = 0 + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 202, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 202, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_block_ysize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 202, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_18 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 202, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 202, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_18); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_18); + __pyx_t_1 = 0; + __pyx_t_18 = 0; + __pyx_t_18 = PyTuple_New(1); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 202, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_6); + __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 202, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 202, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_int8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 202, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 202, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_18, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 202, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 202, __pyx_L1_error) + __pyx_t_13 = ((PyArrayObject *)__pyx_t_4); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer); + __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); + if (unlikely(__pyx_t_5 < 0)) { + PyErr_Fetch(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer, (PyObject*)__pyx_v_mask_block, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_16); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_14, __pyx_t_15, __pyx_t_16); + } + __pyx_t_14 = __pyx_t_15 = __pyx_t_16 = 0; + } + __pyx_pybuffernd_mask_block.diminfo[0].strides = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_mask_block.diminfo[0].shape = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_mask_block.diminfo[1].strides = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_mask_block.diminfo[1].shape = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.shape[1]; + if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 202, __pyx_L1_error) + } + __pyx_t_13 = 0; + __Pyx_DECREF_SET(__pyx_v_mask_block, ((PyArrayObject *)__pyx_t_4)); + __pyx_t_4 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":203 + * dt = numpy.empty((block_ysize, n_cols), dtype=numpy.float32) + * mask_block = numpy.empty((block_ysize, n_cols), dtype=numpy.int8) + * sq = 0 # initialize so compiler doesn't complain # <<<<<<<<<<<<<< + * gsq = 0 + * for yoff in numpy.arange(0, n_rows, block_ysize): + */ + __pyx_v_sq = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":204 + * mask_block = numpy.empty((block_ysize, n_cols), dtype=numpy.int8) + * sq = 0 # initialize so compiler doesn't complain + * gsq = 0 # <<<<<<<<<<<<<< + * for yoff in numpy.arange(0, n_rows, block_ysize): + * win_ysize = block_ysize + */ + __pyx_v_gsq = 0.0; + + /* "pygeoprocessing/geoprocessing_core.pyx":205 + * sq = 0 # initialize so compiler doesn't complain + * gsq = 0 + * for yoff in numpy.arange(0, n_rows, block_ysize): # <<<<<<<<<<<<<< + * win_ysize = block_ysize + * if yoff + win_ysize >= n_rows: + */ + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_numpy); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 205, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_18 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_arange); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 205, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_n_rows); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 205, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_block_ysize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 205, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = NULL; + __pyx_t_5 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_18))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_18); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_18); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_18, function); + __pyx_t_5 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_18)) { + PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_int_0, __pyx_t_6, __pyx_t_3}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_18, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 205, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_18)) { + PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_int_0, __pyx_t_6, __pyx_t_3}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_18, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 205, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + { + __pyx_t_2 = PyTuple_New(3+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 205, __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_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_5, __pyx_int_0); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_5, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 2+__pyx_t_5, __pyx_t_3); + __pyx_t_6 = 0; + __pyx_t_3 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_18, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 205, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) { + __pyx_t_18 = __pyx_t_4; __Pyx_INCREF(__pyx_t_18); __pyx_t_19 = 0; + __pyx_t_20 = NULL; + } else { + __pyx_t_19 = -1; __pyx_t_18 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 205, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __pyx_t_20 = Py_TYPE(__pyx_t_18)->tp_iternext; if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 205, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + for (;;) { + if (likely(!__pyx_t_20)) { + if (likely(PyList_CheckExact(__pyx_t_18))) { + if (__pyx_t_19 >= PyList_GET_SIZE(__pyx_t_18)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_18, __pyx_t_19); __Pyx_INCREF(__pyx_t_4); __pyx_t_19++; if (unlikely(0 < 0)) __PYX_ERR(0, 205, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_18, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 205, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } else { + if (__pyx_t_19 >= PyTuple_GET_SIZE(__pyx_t_18)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_18, __pyx_t_19); __Pyx_INCREF(__pyx_t_4); __pyx_t_19++; if (unlikely(0 < 0)) __PYX_ERR(0, 205, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_18, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 205, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } + } else { + __pyx_t_4 = __pyx_t_20(__pyx_t_18); + 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, 205, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 205, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_yoff = __pyx_t_5; + + /* "pygeoprocessing/geoprocessing_core.pyx":206 + * gsq = 0 + * for yoff in numpy.arange(0, n_rows, block_ysize): + * win_ysize = block_ysize # <<<<<<<<<<<<<< + * if yoff + win_ysize >= n_rows: + * win_ysize = n_rows - yoff + */ + __pyx_v_win_ysize = __pyx_v_block_ysize; + + /* "pygeoprocessing/geoprocessing_core.pyx":207 + * for yoff in numpy.arange(0, n_rows, block_ysize): + * win_ysize = block_ysize + * if yoff + win_ysize >= n_rows: # <<<<<<<<<<<<<< + * win_ysize = n_rows - yoff + * g_block = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) + */ + __pyx_t_21 = (((__pyx_v_yoff + __pyx_v_win_ysize) >= __pyx_v_n_rows) != 0); + if (__pyx_t_21) { + + /* "pygeoprocessing/geoprocessing_core.pyx":208 + * win_ysize = block_ysize + * if yoff + win_ysize >= n_rows: + * win_ysize = n_rows - yoff # <<<<<<<<<<<<<< + * g_block = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) + * mask_block = numpy.empty((win_ysize, n_cols), dtype=numpy.int8) + */ + __pyx_v_win_ysize = (__pyx_v_n_rows - __pyx_v_yoff); + + /* "pygeoprocessing/geoprocessing_core.pyx":209 + * if yoff + win_ysize >= n_rows: + * win_ysize = n_rows - yoff + * g_block = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) # <<<<<<<<<<<<<< + * mask_block = numpy.empty((win_ysize, n_cols), dtype=numpy.int8) + * dt = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_numpy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 209, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 209, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 209, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 209, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 209, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_3); + __pyx_t_4 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 209, __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; + __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 209, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_numpy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 209, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 209, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 209, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 209, __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_6); __pyx_t_6 = 0; + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 209, __pyx_L1_error) + __pyx_t_17 = ((PyArrayObject *)__pyx_t_1); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer); + __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer, (PyObject*)__pyx_t_17, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack); + if (unlikely(__pyx_t_5 < 0)) { + PyErr_Fetch(&__pyx_t_16, &__pyx_t_15, &__pyx_t_14); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer, (PyObject*)__pyx_v_g_block, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_16); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_14); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_16, __pyx_t_15, __pyx_t_14); + } + __pyx_t_16 = __pyx_t_15 = __pyx_t_14 = 0; + } + __pyx_pybuffernd_g_block.diminfo[0].strides = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_g_block.diminfo[0].shape = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_g_block.diminfo[1].strides = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_g_block.diminfo[1].shape = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.shape[1]; + if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 209, __pyx_L1_error) + } + __pyx_t_17 = 0; + __Pyx_DECREF_SET(__pyx_v_g_block, ((PyArrayObject *)__pyx_t_1)); + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":210 + * win_ysize = n_rows - yoff + * g_block = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) + * mask_block = numpy.empty((win_ysize, n_cols), dtype=numpy.int8) # <<<<<<<<<<<<<< + * dt = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) + * done = True + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 210, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 210, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 210, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 210, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 210, __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_t_1 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 210, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 210, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 210, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_int8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 210, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 210, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 210, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 210, __pyx_L1_error) + __pyx_t_13 = ((PyArrayObject *)__pyx_t_4); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer); + __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); + if (unlikely(__pyx_t_5 < 0)) { + PyErr_Fetch(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer, (PyObject*)__pyx_v_mask_block, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_16); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_14, __pyx_t_15, __pyx_t_16); + } + __pyx_t_14 = __pyx_t_15 = __pyx_t_16 = 0; + } + __pyx_pybuffernd_mask_block.diminfo[0].strides = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_mask_block.diminfo[0].shape = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_mask_block.diminfo[1].strides = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_mask_block.diminfo[1].shape = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.shape[1]; + if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 210, __pyx_L1_error) + } + __pyx_t_13 = 0; + __Pyx_DECREF_SET(__pyx_v_mask_block, ((PyArrayObject *)__pyx_t_4)); + __pyx_t_4 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":211 + * g_block = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) + * mask_block = numpy.empty((win_ysize, n_cols), dtype=numpy.int8) + * dt = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) # <<<<<<<<<<<<<< + * done = True + * g_band.ReadAsArray( + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_numpy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 211, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 211, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 211, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 211, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 211, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_3); + __pyx_t_4 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 211, __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; + __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 211, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_numpy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 211, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 211, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 211, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 211, __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_6); __pyx_t_6 = 0; + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 211, __pyx_L1_error) + __pyx_t_33 = ((PyArrayObject *)__pyx_t_1); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dt.rcbuffer->pybuffer); + __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dt.rcbuffer->pybuffer, (PyObject*)__pyx_t_33, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack); + if (unlikely(__pyx_t_5 < 0)) { + PyErr_Fetch(&__pyx_t_16, &__pyx_t_15, &__pyx_t_14); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dt.rcbuffer->pybuffer, (PyObject*)__pyx_v_dt, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_16); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_14); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_16, __pyx_t_15, __pyx_t_14); + } + __pyx_t_16 = __pyx_t_15 = __pyx_t_14 = 0; + } + __pyx_pybuffernd_dt.diminfo[0].strides = __pyx_pybuffernd_dt.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_dt.diminfo[0].shape = __pyx_pybuffernd_dt.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_dt.diminfo[1].strides = __pyx_pybuffernd_dt.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_dt.diminfo[1].shape = __pyx_pybuffernd_dt.rcbuffer->pybuffer.shape[1]; + if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 211, __pyx_L1_error) + } + __pyx_t_33 = 0; + __Pyx_DECREF_SET(__pyx_v_dt, ((PyArrayObject *)__pyx_t_1)); + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":212 + * mask_block = numpy.empty((win_ysize, n_cols), dtype=numpy.int8) + * dt = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) + * done = True # <<<<<<<<<<<<<< + * g_band.ReadAsArray( + * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, + */ + __pyx_v_done = 1; + + /* "pygeoprocessing/geoprocessing_core.pyx":207 + * for yoff in numpy.arange(0, n_rows, block_ysize): + * win_ysize = block_ysize + * if yoff + win_ysize >= n_rows: # <<<<<<<<<<<<<< + * win_ysize = n_rows - yoff + * g_block = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":213 + * dt = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) + * done = True + * g_band.ReadAsArray( # <<<<<<<<<<<<<< + * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, + * buf_obj=g_block) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_g_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 213, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/geoprocessing_core.pyx":214 + * done = True + * g_band.ReadAsArray( + * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, # <<<<<<<<<<<<<< + * buf_obj=g_block) + * mask_band.ReadAsArray( + */ + __pyx_t_6 = __Pyx_PyDict_NewPresized(5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 214, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_xoff, __pyx_int_0) < 0) __PYX_ERR(0, 214, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_yoff); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 214, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_yoff, __pyx_t_3) < 0) __PYX_ERR(0, 214, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 214, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_win_xsize, __pyx_t_3) < 0) __PYX_ERR(0, 214, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 214, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_win_ysize, __pyx_t_3) < 0) __PYX_ERR(0, 214, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":215 + * g_band.ReadAsArray( + * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, + * buf_obj=g_block) # <<<<<<<<<<<<<< + * mask_band.ReadAsArray( + * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, + */ + if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_buf_obj, ((PyObject *)__pyx_v_g_block)) < 0) __PYX_ERR(0, 214, __pyx_L1_error) + + /* "pygeoprocessing/geoprocessing_core.pyx":213 + * dt = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) + * done = True + * g_band.ReadAsArray( # <<<<<<<<<<<<<< + * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, + * buf_obj=g_block) + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 213, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":216 + * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, + * buf_obj=g_block) + * mask_band.ReadAsArray( # <<<<<<<<<<<<<< + * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, + * buf_obj=mask_block) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_mask_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 216, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + + /* "pygeoprocessing/geoprocessing_core.pyx":217 + * buf_obj=g_block) + * mask_band.ReadAsArray( + * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, # <<<<<<<<<<<<<< + * buf_obj=mask_block) + * for local_y_index in range(win_ysize): + */ + __pyx_t_6 = __Pyx_PyDict_NewPresized(5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 217, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_xoff, __pyx_int_0) < 0) __PYX_ERR(0, 217, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_yoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 217, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_yoff, __pyx_t_1) < 0) __PYX_ERR(0, 217, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 217, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_win_xsize, __pyx_t_1) < 0) __PYX_ERR(0, 217, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 217, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_win_ysize, __pyx_t_1) < 0) __PYX_ERR(0, 217, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":218 + * mask_band.ReadAsArray( + * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, + * buf_obj=mask_block) # <<<<<<<<<<<<<< + * for local_y_index in range(win_ysize): + * q_index = 0 + */ + if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_buf_obj, ((PyObject *)__pyx_v_mask_block)) < 0) __PYX_ERR(0, 217, __pyx_L1_error) + + /* "pygeoprocessing/geoprocessing_core.pyx":216 + * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, + * buf_obj=g_block) + * mask_band.ReadAsArray( # <<<<<<<<<<<<<< + * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, + * buf_obj=mask_block) + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_empty_tuple, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 216, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":219 + * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, + * buf_obj=mask_block) + * for local_y_index in range(win_ysize): # <<<<<<<<<<<<<< + * q_index = 0 + * s_array[0] = 0 + */ + __pyx_t_5 = __pyx_v_win_ysize; + __pyx_t_22 = __pyx_t_5; + for (__pyx_t_23 = 0; __pyx_t_23 < __pyx_t_22; __pyx_t_23+=1) { + __pyx_v_local_y_index = __pyx_t_23; + + /* "pygeoprocessing/geoprocessing_core.pyx":220 + * buf_obj=mask_block) + * for local_y_index in range(win_ysize): + * q_index = 0 # <<<<<<<<<<<<<< + * s_array[0] = 0 + * t_array[0] = 0 + */ + __pyx_v_q_index = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":221 + * for local_y_index in range(win_ysize): + * q_index = 0 + * s_array[0] = 0 # <<<<<<<<<<<<<< + * t_array[0] = 0 + * for u_index in range(1, n_cols): + */ + __pyx_t_30 = 0; + *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_s_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_s_array.diminfo[0].strides) = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":222 + * q_index = 0 + * s_array[0] = 0 + * t_array[0] = 0 # <<<<<<<<<<<<<< + * for u_index in range(1, n_cols): + * gu = g_block[local_y_index, u_index]**2 + */ + __pyx_t_30 = 0; + *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_t_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_t_array.diminfo[0].strides) = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":223 + * s_array[0] = 0 + * t_array[0] = 0 + * for u_index in range(1, n_cols): # <<<<<<<<<<<<<< + * gu = g_block[local_y_index, u_index]**2 + * while (q_index >= 0): + */ + __pyx_t_24 = __pyx_v_n_cols; + __pyx_t_25 = __pyx_t_24; + for (__pyx_t_26 = 1; __pyx_t_26 < __pyx_t_25; __pyx_t_26+=1) { + __pyx_v_u_index = __pyx_t_26; + + /* "pygeoprocessing/geoprocessing_core.pyx":224 + * t_array[0] = 0 + * for u_index in range(1, n_cols): + * gu = g_block[local_y_index, u_index]**2 # <<<<<<<<<<<<<< + * while (q_index >= 0): + * tq = t_array[q_index] + */ + __pyx_t_30 = __pyx_v_local_y_index; + __pyx_t_29 = __pyx_v_u_index; + __pyx_v_gu = powf((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_g_block.diminfo[1].strides)), 2.0); + + /* "pygeoprocessing/geoprocessing_core.pyx":225 + * for u_index in range(1, n_cols): + * gu = g_block[local_y_index, u_index]**2 + * while (q_index >= 0): # <<<<<<<<<<<<<< + * tq = t_array[q_index] + * sq = s_array[q_index] + */ + while (1) { + __pyx_t_21 = ((__pyx_v_q_index >= 0) != 0); + if (!__pyx_t_21) break; + + /* "pygeoprocessing/geoprocessing_core.pyx":226 + * gu = g_block[local_y_index, u_index]**2 + * while (q_index >= 0): + * tq = t_array[q_index] # <<<<<<<<<<<<<< + * sq = s_array[q_index] + * gsq = g_block[local_y_index, sq]**2 + */ + __pyx_t_29 = __pyx_v_q_index; + __pyx_v_tq = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_t_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_t_array.diminfo[0].strides)); + + /* "pygeoprocessing/geoprocessing_core.pyx":227 + * while (q_index >= 0): + * tq = t_array[q_index] + * sq = s_array[q_index] # <<<<<<<<<<<<<< + * gsq = g_block[local_y_index, sq]**2 + * if ((sample_d_x*(tq-sq))**2 + gsq <= ( + */ + __pyx_t_29 = __pyx_v_q_index; + __pyx_v_sq = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_s_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_s_array.diminfo[0].strides)); + + /* "pygeoprocessing/geoprocessing_core.pyx":228 + * tq = t_array[q_index] + * sq = s_array[q_index] + * gsq = g_block[local_y_index, sq]**2 # <<<<<<<<<<<<<< + * if ((sample_d_x*(tq-sq))**2 + gsq <= ( + * sample_d_x*(tq-u_index))**2 + gu): + */ + __pyx_t_29 = __pyx_v_local_y_index; + __pyx_t_30 = __pyx_v_sq; + __pyx_v_gsq = powf((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_g_block.diminfo[1].strides)), 2.0); + + /* "pygeoprocessing/geoprocessing_core.pyx":229 + * sq = s_array[q_index] + * gsq = g_block[local_y_index, sq]**2 + * if ((sample_d_x*(tq-sq))**2 + gsq <= ( # <<<<<<<<<<<<<< + * sample_d_x*(tq-u_index))**2 + gu): + * break + */ + __pyx_t_21 = (((powf((__pyx_v_sample_d_x * (__pyx_v_tq - __pyx_v_sq)), 2.0) + __pyx_v_gsq) <= (powf((__pyx_v_sample_d_x * (__pyx_v_tq - __pyx_v_u_index)), 2.0) + __pyx_v_gu)) != 0); + if (__pyx_t_21) { + + /* "pygeoprocessing/geoprocessing_core.pyx":231 + * if ((sample_d_x*(tq-sq))**2 + gsq <= ( + * sample_d_x*(tq-u_index))**2 + gu): + * break # <<<<<<<<<<<<<< + * q_index -= 1 + * if q_index < 0: + */ + goto __pyx_L25_break; + + /* "pygeoprocessing/geoprocessing_core.pyx":229 + * sq = s_array[q_index] + * gsq = g_block[local_y_index, sq]**2 + * if ((sample_d_x*(tq-sq))**2 + gsq <= ( # <<<<<<<<<<<<<< + * sample_d_x*(tq-u_index))**2 + gu): + * break + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":232 + * sample_d_x*(tq-u_index))**2 + gu): + * break + * q_index -= 1 # <<<<<<<<<<<<<< + * if q_index < 0: + * q_index = 0 + */ + __pyx_v_q_index = (__pyx_v_q_index - 1); + } + __pyx_L25_break:; + + /* "pygeoprocessing/geoprocessing_core.pyx":233 + * break + * q_index -= 1 + * if q_index < 0: # <<<<<<<<<<<<<< + * q_index = 0 + * s_array[0] = u_index + */ + __pyx_t_21 = ((__pyx_v_q_index < 0) != 0); + if (__pyx_t_21) { + + /* "pygeoprocessing/geoprocessing_core.pyx":234 + * q_index -= 1 + * if q_index < 0: + * q_index = 0 # <<<<<<<<<<<<<< + * s_array[0] = u_index + * sq = u_index + */ + __pyx_v_q_index = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":235 + * if q_index < 0: + * q_index = 0 + * s_array[0] = u_index # <<<<<<<<<<<<<< + * sq = u_index + * gsq = g_block[local_y_index, sq]**2 + */ + __pyx_t_30 = 0; + *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_s_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_s_array.diminfo[0].strides) = __pyx_v_u_index; + + /* "pygeoprocessing/geoprocessing_core.pyx":236 + * q_index = 0 + * s_array[0] = u_index + * sq = u_index # <<<<<<<<<<<<<< + * gsq = g_block[local_y_index, sq]**2 + * else: + */ + __pyx_v_sq = __pyx_v_u_index; + + /* "pygeoprocessing/geoprocessing_core.pyx":237 + * s_array[0] = u_index + * sq = u_index + * gsq = g_block[local_y_index, sq]**2 # <<<<<<<<<<<<<< + * else: + * w = (float)(sample_d_x + (( + */ + __pyx_t_30 = __pyx_v_local_y_index; + __pyx_t_29 = __pyx_v_sq; + __pyx_v_gsq = powf((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_g_block.diminfo[1].strides)), 2.0); + + /* "pygeoprocessing/geoprocessing_core.pyx":233 + * break + * q_index -= 1 + * if q_index < 0: # <<<<<<<<<<<<<< + * q_index = 0 + * s_array[0] = u_index + */ + goto __pyx_L27; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":239 + * gsq = g_block[local_y_index, sq]**2 + * else: + * w = (float)(sample_d_x + (( # <<<<<<<<<<<<<< + * (sample_d_x*u_index)**2 - (sample_d_x*sq)**2 + + * gu - gsq) / (2*sample_d_x*(u_index-sq)))) + */ + /*else*/ { + + /* "pygeoprocessing/geoprocessing_core.pyx":241 + * w = (float)(sample_d_x + (( + * (sample_d_x*u_index)**2 - (sample_d_x*sq)**2 + + * gu - gsq) / (2*sample_d_x*(u_index-sq)))) # <<<<<<<<<<<<<< + * if w < n_cols*sample_d_x: + * q_index += 1 + */ + __pyx_v_w = ((double)(__pyx_v_sample_d_x + ((((powf((__pyx_v_sample_d_x * __pyx_v_u_index), 2.0) - powf((__pyx_v_sample_d_x * __pyx_v_sq), 2.0)) + __pyx_v_gu) - __pyx_v_gsq) / ((2.0 * __pyx_v_sample_d_x) * (__pyx_v_u_index - __pyx_v_sq))))); + + /* "pygeoprocessing/geoprocessing_core.pyx":242 + * (sample_d_x*u_index)**2 - (sample_d_x*sq)**2 + + * gu - gsq) / (2*sample_d_x*(u_index-sq)))) + * if w < n_cols*sample_d_x: # <<<<<<<<<<<<<< + * q_index += 1 + * s_array[q_index] = u_index + */ + __pyx_t_21 = ((__pyx_v_w < (__pyx_v_n_cols * __pyx_v_sample_d_x)) != 0); + if (__pyx_t_21) { + + /* "pygeoprocessing/geoprocessing_core.pyx":243 + * gu - gsq) / (2*sample_d_x*(u_index-sq)))) + * if w < n_cols*sample_d_x: + * q_index += 1 # <<<<<<<<<<<<<< + * s_array[q_index] = u_index + * t_array[q_index] = (w / sample_d_x) + */ + __pyx_v_q_index = (__pyx_v_q_index + 1); + + /* "pygeoprocessing/geoprocessing_core.pyx":244 + * if w < n_cols*sample_d_x: + * q_index += 1 + * s_array[q_index] = u_index # <<<<<<<<<<<<<< + * t_array[q_index] = (w / sample_d_x) + * + */ + __pyx_t_29 = __pyx_v_q_index; + *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_s_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_s_array.diminfo[0].strides) = __pyx_v_u_index; + + /* "pygeoprocessing/geoprocessing_core.pyx":245 + * q_index += 1 + * s_array[q_index] = u_index + * t_array[q_index] = (w / sample_d_x) # <<<<<<<<<<<<<< + * + * sq = s_array[q_index] + */ + __pyx_t_29 = __pyx_v_q_index; + *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_t_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_t_array.diminfo[0].strides) = ((int)(__pyx_v_w / __pyx_v_sample_d_x)); + + /* "pygeoprocessing/geoprocessing_core.pyx":242 + * (sample_d_x*u_index)**2 - (sample_d_x*sq)**2 + + * gu - gsq) / (2*sample_d_x*(u_index-sq)))) + * if w < n_cols*sample_d_x: # <<<<<<<<<<<<<< + * q_index += 1 + * s_array[q_index] = u_index + */ + } + } + __pyx_L27:; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":247 + * t_array[q_index] = (w / sample_d_x) + * + * sq = s_array[q_index] # <<<<<<<<<<<<<< + * gsq = g_block[local_y_index, sq]**2 + * tq = t_array[q_index] + */ + __pyx_t_29 = __pyx_v_q_index; + __pyx_v_sq = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_s_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_s_array.diminfo[0].strides)); + + /* "pygeoprocessing/geoprocessing_core.pyx":248 + * + * sq = s_array[q_index] + * gsq = g_block[local_y_index, sq]**2 # <<<<<<<<<<<<<< + * tq = t_array[q_index] + * for u_index in range(n_cols-1, -1, -1): + */ + __pyx_t_29 = __pyx_v_local_y_index; + __pyx_t_30 = __pyx_v_sq; + __pyx_v_gsq = powf((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_g_block.diminfo[1].strides)), 2.0); + + /* "pygeoprocessing/geoprocessing_core.pyx":249 + * sq = s_array[q_index] + * gsq = g_block[local_y_index, sq]**2 + * tq = t_array[q_index] # <<<<<<<<<<<<<< + * for u_index in range(n_cols-1, -1, -1): + * if mask_block[local_y_index, u_index] != 1: + */ + __pyx_t_30 = __pyx_v_q_index; + __pyx_v_tq = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_t_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_t_array.diminfo[0].strides)); + + /* "pygeoprocessing/geoprocessing_core.pyx":250 + * gsq = g_block[local_y_index, sq]**2 + * tq = t_array[q_index] + * for u_index in range(n_cols-1, -1, -1): # <<<<<<<<<<<<<< + * if mask_block[local_y_index, u_index] != 1: + * dt[local_y_index, u_index] = ( + */ + for (__pyx_t_24 = (__pyx_v_n_cols - 1); __pyx_t_24 > -1; __pyx_t_24-=1) { + __pyx_v_u_index = __pyx_t_24; + + /* "pygeoprocessing/geoprocessing_core.pyx":251 + * tq = t_array[q_index] + * for u_index in range(n_cols-1, -1, -1): + * if mask_block[local_y_index, u_index] != 1: # <<<<<<<<<<<<<< + * dt[local_y_index, u_index] = ( + * sample_d_x*(u_index-sq))**2+gsq + */ + __pyx_t_30 = __pyx_v_local_y_index; + __pyx_t_29 = __pyx_v_u_index; + __pyx_t_21 = (((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int8_t *, __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_mask_block.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_mask_block.diminfo[1].strides)) != 1) != 0); + if (__pyx_t_21) { + + /* "pygeoprocessing/geoprocessing_core.pyx":252 + * for u_index in range(n_cols-1, -1, -1): + * if mask_block[local_y_index, u_index] != 1: + * dt[local_y_index, u_index] = ( # <<<<<<<<<<<<<< + * sample_d_x*(u_index-sq))**2+gsq + * else: + */ + __pyx_t_29 = __pyx_v_local_y_index; + __pyx_t_30 = __pyx_v_u_index; + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_dt.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_dt.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_dt.diminfo[1].strides) = (powf((__pyx_v_sample_d_x * (__pyx_v_u_index - __pyx_v_sq)), 2.0) + __pyx_v_gsq); + + /* "pygeoprocessing/geoprocessing_core.pyx":251 + * tq = t_array[q_index] + * for u_index in range(n_cols-1, -1, -1): + * if mask_block[local_y_index, u_index] != 1: # <<<<<<<<<<<<<< + * dt[local_y_index, u_index] = ( + * sample_d_x*(u_index-sq))**2+gsq + */ + goto __pyx_L31; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":255 + * sample_d_x*(u_index-sq))**2+gsq + * else: + * dt[local_y_index, u_index] = 0 # <<<<<<<<<<<<<< + * if u_index <= tq: + * q_index -= 1 + */ + /*else*/ { + __pyx_t_30 = __pyx_v_local_y_index; + __pyx_t_29 = __pyx_v_u_index; + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_dt.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_dt.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_dt.diminfo[1].strides) = 0.0; + } + __pyx_L31:; + + /* "pygeoprocessing/geoprocessing_core.pyx":256 + * else: + * dt[local_y_index, u_index] = 0 + * if u_index <= tq: # <<<<<<<<<<<<<< + * q_index -= 1 + * if q_index >= 0: + */ + __pyx_t_21 = ((__pyx_v_u_index <= __pyx_v_tq) != 0); + if (__pyx_t_21) { + + /* "pygeoprocessing/geoprocessing_core.pyx":257 + * dt[local_y_index, u_index] = 0 + * if u_index <= tq: + * q_index -= 1 # <<<<<<<<<<<<<< + * if q_index >= 0: + * sq = s_array[q_index] + */ + __pyx_v_q_index = (__pyx_v_q_index - 1); + + /* "pygeoprocessing/geoprocessing_core.pyx":258 + * if u_index <= tq: + * q_index -= 1 + * if q_index >= 0: # <<<<<<<<<<<<<< + * sq = s_array[q_index] + * gsq = g_block[local_y_index, sq]**2 + */ + __pyx_t_21 = ((__pyx_v_q_index >= 0) != 0); + if (__pyx_t_21) { + + /* "pygeoprocessing/geoprocessing_core.pyx":259 + * q_index -= 1 + * if q_index >= 0: + * sq = s_array[q_index] # <<<<<<<<<<<<<< + * gsq = g_block[local_y_index, sq]**2 + * tq = t_array[q_index] + */ + __pyx_t_29 = __pyx_v_q_index; + __pyx_v_sq = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_s_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_s_array.diminfo[0].strides)); + + /* "pygeoprocessing/geoprocessing_core.pyx":260 + * if q_index >= 0: + * sq = s_array[q_index] + * gsq = g_block[local_y_index, sq]**2 # <<<<<<<<<<<<<< + * tq = t_array[q_index] + * + */ + __pyx_t_29 = __pyx_v_local_y_index; + __pyx_t_30 = __pyx_v_sq; + __pyx_v_gsq = powf((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_g_block.diminfo[1].strides)), 2.0); + + /* "pygeoprocessing/geoprocessing_core.pyx":261 + * sq = s_array[q_index] + * gsq = g_block[local_y_index, sq]**2 + * tq = t_array[q_index] # <<<<<<<<<<<<<< + * + * valid_mask = g_block != _NODATA + */ + __pyx_t_30 = __pyx_v_q_index; + __pyx_v_tq = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_t_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_t_array.diminfo[0].strides)); + + /* "pygeoprocessing/geoprocessing_core.pyx":258 + * if u_index <= tq: + * q_index -= 1 + * if q_index >= 0: # <<<<<<<<<<<<<< + * sq = s_array[q_index] + * gsq = g_block[local_y_index, sq]**2 + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":256 + * else: + * dt[local_y_index, u_index] = 0 + * if u_index <= tq: # <<<<<<<<<<<<<< + * q_index -= 1 + * if q_index >= 0: + */ + } + } + } + + /* "pygeoprocessing/geoprocessing_core.pyx":263 + * tq = t_array[q_index] + * + * valid_mask = g_block != _NODATA # <<<<<<<<<<<<<< + * # "unnormalize" distances along with square root + * dt[valid_mask] = numpy.sqrt(dt[valid_mask]) * max_sample + */ + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_15pygeoprocessing_18geoprocessing_core__NODATA); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 263, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = PyObject_RichCompare(((PyObject *)__pyx_v_g_block), __pyx_t_1, Py_NE); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 263, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_valid_mask, __pyx_t_6); + __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":265 + * valid_mask = g_block != _NODATA + * # "unnormalize" distances along with square root + * dt[valid_mask] = numpy.sqrt(dt[valid_mask]) * max_sample # <<<<<<<<<<<<<< + * dt[~valid_mask] = _NODATA + * target_distance_band.WriteArray(dt, xoff=0, yoff=yoff) + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 265, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_sqrt); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 265, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_dt), __pyx_v_valid_mask); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 265, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = NULL; + 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_6 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 265, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyNumber_Multiply(__pyx_t_6, __pyx_v_max_sample); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 265, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_dt), __pyx_v_valid_mask, __pyx_t_3) < 0)) __PYX_ERR(0, 265, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":266 + * # "unnormalize" distances along with square root + * dt[valid_mask] = numpy.sqrt(dt[valid_mask]) * max_sample + * dt[~valid_mask] = _NODATA # <<<<<<<<<<<<<< + * target_distance_band.WriteArray(dt, xoff=0, yoff=yoff) + * + */ + __pyx_t_3 = PyFloat_FromDouble(__pyx_v_15pygeoprocessing_18geoprocessing_core__NODATA); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 266, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = PyNumber_Invert(__pyx_v_valid_mask); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 266, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_dt), __pyx_t_6, __pyx_t_3) < 0)) __PYX_ERR(0, 266, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":267 + * dt[valid_mask] = numpy.sqrt(dt[valid_mask]) * max_sample + * dt[~valid_mask] = _NODATA + * target_distance_band.WriteArray(dt, xoff=0, yoff=yoff) # <<<<<<<<<<<<<< + * + * # we do this in the case where the blocksize is many times larger than + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_target_distance_band, __pyx_n_s_WriteArray); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 267, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 267, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(((PyObject *)__pyx_v_dt)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_dt)); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_dt)); + __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 267, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_xoff, __pyx_int_0) < 0) __PYX_ERR(0, 267, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_yoff); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 267, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_yoff, __pyx_t_2) < 0) __PYX_ERR(0, 267, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 267, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":271 + * # we do this in the case where the blocksize is many times larger than + * # the raster size so we don't re-loop through the only block + * if done: # <<<<<<<<<<<<<< + * break + * + */ + __pyx_t_21 = (__pyx_v_done != 0); + if (__pyx_t_21) { + + /* "pygeoprocessing/geoprocessing_core.pyx":272 + * # the raster size so we don't re-loop through the only block + * if done: + * break # <<<<<<<<<<<<<< + * + * target_distance_band.ComputeStatistics(0) + */ + goto __pyx_L18_break; + + /* "pygeoprocessing/geoprocessing_core.pyx":271 + * # we do this in the case where the blocksize is many times larger than + * # the raster size so we don't re-loop through the only block + * if done: # <<<<<<<<<<<<<< + * break + * + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":205 + * sq = 0 # initialize so compiler doesn't complain + * gsq = 0 + * for yoff in numpy.arange(0, n_rows, block_ysize): # <<<<<<<<<<<<<< + * win_ysize = block_ysize + * if yoff + win_ysize >= n_rows: + */ + } + __pyx_L18_break:; + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":274 + * break + * + * target_distance_band.ComputeStatistics(0) # <<<<<<<<<<<<<< + * target_distance_band.FlushCache() + * target_distance_band = None + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_target_distance_band, __pyx_n_s_ComputeStatistics); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 274, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_18 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_1, __pyx_int_0) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_int_0); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 274, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":275 + * + * target_distance_band.ComputeStatistics(0) + * target_distance_band.FlushCache() # <<<<<<<<<<<<<< + * target_distance_band = None + * mask_band = None + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_target_distance_band, __pyx_n_s_FlushCache); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 275, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_18 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 275, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":276 + * target_distance_band.ComputeStatistics(0) + * target_distance_band.FlushCache() + * target_distance_band = None # <<<<<<<<<<<<<< + * mask_band = None + * g_band = None + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_target_distance_band, Py_None); + + /* "pygeoprocessing/geoprocessing_core.pyx":277 + * target_distance_band.FlushCache() + * target_distance_band = None + * mask_band = None # <<<<<<<<<<<<<< + * g_band = None + * target_distance_raster = None + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_mask_band, Py_None); + + /* "pygeoprocessing/geoprocessing_core.pyx":278 + * target_distance_band = None + * mask_band = None + * g_band = None # <<<<<<<<<<<<<< + * target_distance_raster = None + * mask_raster = None + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_g_band, Py_None); + + /* "pygeoprocessing/geoprocessing_core.pyx":279 + * mask_band = None + * g_band = None + * target_distance_raster = None # <<<<<<<<<<<<<< + * mask_raster = None + * g_raster = None + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_target_distance_raster, Py_None); + + /* "pygeoprocessing/geoprocessing_core.pyx":280 + * g_band = None + * target_distance_raster = None + * mask_raster = None # <<<<<<<<<<<<<< + * g_raster = None + * + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_mask_raster, Py_None); + + /* "pygeoprocessing/geoprocessing_core.pyx":281 + * target_distance_raster = None + * mask_raster = None + * g_raster = None # <<<<<<<<<<<<<< + * + * @cython.boundscheck(False) + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_g_raster, Py_None); + + /* "pygeoprocessing/geoprocessing_core.pyx":71 + * @cython.wraparound(False) + * @cython.cdivision(True) + * def _distance_transform_edt( # <<<<<<<<<<<<<< + * region_raster_path, g_raster_path, float sample_d_x, + * float sample_d_y, target_distance_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_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_18); + { 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_dt.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_s_array.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t_array.rcbuffer->pybuffer); + __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} + __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core._distance_transform_edt", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + goto __pyx_L2; + __pyx_L0:; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dt.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_s_array.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t_array.rcbuffer->pybuffer); + __pyx_L2:; + __Pyx_XDECREF((PyObject *)__pyx_v_g_block); + __Pyx_XDECREF((PyObject *)__pyx_v_s_array); + __Pyx_XDECREF((PyObject *)__pyx_v_t_array); + __Pyx_XDECREF((PyObject *)__pyx_v_dt); + __Pyx_XDECREF((PyObject *)__pyx_v_mask_block); + __Pyx_XDECREF(__pyx_v_mask_raster); + __Pyx_XDECREF(__pyx_v_mask_band); + __Pyx_XDECREF(__pyx_v_raster_info); + __Pyx_XDECREF(__pyx_v_g_raster); + __Pyx_XDECREF(__pyx_v_g_band); + __Pyx_XDECREF(__pyx_v_g_band_blocksize); + __Pyx_XDECREF(__pyx_v_max_sample); + __Pyx_XDECREF(__pyx_v_target_distance_raster); + __Pyx_XDECREF(__pyx_v_target_distance_band); + __Pyx_XDECREF(__pyx_v_valid_mask); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pygeoprocessing/geoprocessing_core.pyx":287 + * @cython.nonecheck(False) + * @cython.cdivision(True) + * def calculate_slope( # <<<<<<<<<<<<<< + * base_elevation_raster_path_band, target_slope_path, + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_3calculate_slope(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_15pygeoprocessing_18geoprocessing_core_2calculate_slope[] = "Create a percent slope raster from DEM raster.\n\n Base algorithm is from Zevenbergen & Thorne \"Quantitative Analysis of Land\n Surface Topography\" 1987 although it has been modified to include the\n diagonal pixels by classic finite difference analysis.\n\n For the following notation, we define each pixel's DEM value by a letter\n with this spatial scheme::\n\n a b c\n d e f\n g h i\n\n Then the slope at ``e`` is defined at ``([dz/dx]^2 + [dz/dy]^2)^0.5``\n\n Where::\n\n [dz/dx] = ((c+2f+i)-(a+2d+g)/(8*x_cell_size)\n [dz/dy] = ((g+2h+i)-(a+2b+c))/(8*y_cell_size)\n\n In cases where a cell is nodata, we attempt to use the middle cell inline\n with the direction of differentiation (either in x or y direction). If\n no inline pixel is defined, we use ``e`` and multiply the difference by\n ``2^0.5`` to account for the diagonal projection.\n\n Parameters:\n base_elevation_raster_path_band (string): a path/band tuple to a\n raster of height values. (path_to_raster, band_index)\n target_slope_path (string): path to target slope raster; will be a\n 32 bit float GeoTIFF of same size/projection as calculate slope\n with units of percent slope.\n raster_driver_creation_tuple (tuple): a tuple containing a GDAL driver\n name string as the first element and a GDAL creation options\n tuple/list as the second. Defaults to\n geoprocessing.DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS.\n\n Returns:\n ``None``\n "; +static PyMethodDef __pyx_mdef_15pygeoprocessing_18geoprocessing_core_3calculate_slope = {"calculate_slope", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_18geoprocessing_core_3calculate_slope, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_18geoprocessing_core_2calculate_slope}; +static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_3calculate_slope(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_base_elevation_raster_path_band = 0; + PyObject *__pyx_v_target_slope_path = 0; + PyObject *__pyx_v_raster_driver_creation_tuple = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("calculate_slope (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_base_elevation_raster_path_band,&__pyx_n_s_target_slope_path,&__pyx_n_s_raster_driver_creation_tuple,0}; + PyObject* values[3] = {0,0,0}; + values[2] = __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 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_base_elevation_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_slope_path)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("calculate_slope", 0, 2, 3, 1); __PYX_ERR(0, 287, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_raster_driver_creation_tuple); + if (value) { values[2] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "calculate_slope") < 0)) __PYX_ERR(0, 287, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + 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_base_elevation_raster_path_band = values[0]; + __pyx_v_target_slope_path = values[1]; + __pyx_v_raster_driver_creation_tuple = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("calculate_slope", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 287, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core.calculate_slope", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_15pygeoprocessing_18geoprocessing_core_2calculate_slope(__pyx_self, __pyx_v_base_elevation_raster_path_band, __pyx_v_target_slope_path, __pyx_v_raster_driver_creation_tuple); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core_2calculate_slope(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_base_elevation_raster_path_band, PyObject *__pyx_v_target_slope_path, PyObject *__pyx_v_raster_driver_creation_tuple) { + npy_float64 __pyx_v_a; + npy_float64 __pyx_v_b; + npy_float64 __pyx_v_c; + npy_float64 __pyx_v_d; + npy_float64 __pyx_v_e; + npy_float64 __pyx_v_f; + npy_float64 __pyx_v_g; + npy_float64 __pyx_v_h; + npy_float64 __pyx_v_i; + npy_float64 __pyx_v_dem_nodata; + npy_float64 __pyx_v_x_cell_size; + npy_float64 __pyx_v_y_cell_size; + npy_float64 __pyx_v_dzdx_accumulator; + npy_float64 __pyx_v_dzdy_accumulator; + int __pyx_v_row_index; + int __pyx_v_col_index; + int __pyx_v_n_rows; + int __pyx_v_n_cols; + int __pyx_v_x_denom_factor; + int __pyx_v_y_denom_factor; + int __pyx_v_win_xsize; + int __pyx_v_win_ysize; + PyArrayObject *__pyx_v_dem_array = 0; + PyArrayObject *__pyx_v_slope_array = 0; + PyArrayObject *__pyx_v_dzdx_array = 0; + PyArrayObject *__pyx_v_dzdy_array = 0; + PyObject *__pyx_v_dem_raster = NULL; + PyObject *__pyx_v_dem_band = NULL; + PyObject *__pyx_v_dem_info = NULL; + PyObject *__pyx_v_raw_nodata = NULL; + npy_float64 __pyx_v_slope_nodata; + PyObject *__pyx_v_target_slope_raster = NULL; + PyObject *__pyx_v_target_slope_band = NULL; + PyObject *__pyx_v_block_offset = NULL; + PyObject *__pyx_v_block_offset_copy = NULL; + PyObject *__pyx_v_x_start = NULL; + PyObject *__pyx_v_x_end = NULL; + PyObject *__pyx_v_y_start = NULL; + PyObject *__pyx_v_y_end = NULL; + PyObject *__pyx_v_valid_mask = NULL; + __Pyx_LocalBuf_ND __pyx_pybuffernd_dem_array; + __Pyx_Buffer __pyx_pybuffer_dem_array; + __Pyx_LocalBuf_ND __pyx_pybuffernd_dzdx_array; + __Pyx_Buffer __pyx_pybuffer_dzdx_array; + __Pyx_LocalBuf_ND __pyx_pybuffernd_dzdy_array; + __Pyx_Buffer __pyx_pybuffer_dzdy_array; + __Pyx_LocalBuf_ND __pyx_pybuffernd_slope_array; + __Pyx_Buffer __pyx_pybuffer_slope_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; + npy_float64 __pyx_t_7; + PyObject *(*__pyx_t_8)(PyObject *); + npy_float64 __pyx_t_9; + int __pyx_t_10; + int __pyx_t_11; + PyObject *__pyx_t_12 = NULL; + Py_ssize_t __pyx_t_13; + PyObject *(*__pyx_t_14)(PyObject *); + PyObject *__pyx_t_15 = NULL; + PyObject *__pyx_t_16 = NULL; + PyArrayObject *__pyx_t_17 = NULL; + PyObject *__pyx_t_18 = NULL; + PyObject *__pyx_t_19 = NULL; + PyObject *__pyx_t_20 = NULL; + PyArrayObject *__pyx_t_21 = NULL; + PyArrayObject *__pyx_t_22 = NULL; + PyArrayObject *__pyx_t_23 = NULL; + PyObject *__pyx_t_24 = NULL; + long __pyx_t_25; + long __pyx_t_26; + long __pyx_t_27; + long __pyx_t_28; + Py_ssize_t __pyx_t_29; + Py_ssize_t __pyx_t_30; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("calculate_slope", 0); + __pyx_pybuffer_dem_array.pybuffer.buf = NULL; + __pyx_pybuffer_dem_array.refcount = 0; + __pyx_pybuffernd_dem_array.data = NULL; + __pyx_pybuffernd_dem_array.rcbuffer = &__pyx_pybuffer_dem_array; + __pyx_pybuffer_slope_array.pybuffer.buf = NULL; + __pyx_pybuffer_slope_array.refcount = 0; + __pyx_pybuffernd_slope_array.data = NULL; + __pyx_pybuffernd_slope_array.rcbuffer = &__pyx_pybuffer_slope_array; + __pyx_pybuffer_dzdx_array.pybuffer.buf = NULL; + __pyx_pybuffer_dzdx_array.refcount = 0; + __pyx_pybuffernd_dzdx_array.data = NULL; + __pyx_pybuffernd_dzdx_array.rcbuffer = &__pyx_pybuffer_dzdx_array; + __pyx_pybuffer_dzdy_array.pybuffer.buf = NULL; + __pyx_pybuffer_dzdy_array.refcount = 0; + __pyx_pybuffernd_dzdy_array.data = NULL; + __pyx_pybuffernd_dzdy_array.rcbuffer = &__pyx_pybuffer_dzdy_array; + + /* "pygeoprocessing/geoprocessing_core.pyx":339 + * cdef numpy.ndarray[numpy.npy_float64, ndim=2] dzdy_array + * + * dem_raster = gdal.OpenEx(base_elevation_raster_path_band[0]) # <<<<<<<<<<<<<< + * dem_band = dem_raster.GetRasterBand(base_elevation_raster_path_band[1]) + * dem_info = pygeoprocessing.get_raster_info( + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 339, __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, 339, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_base_elevation_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 339, __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); + } + } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 339, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_dem_raster = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":340 + * + * dem_raster = gdal.OpenEx(base_elevation_raster_path_band[0]) + * dem_band = dem_raster.GetRasterBand(base_elevation_raster_path_band[1]) # <<<<<<<<<<<<<< + * dem_info = pygeoprocessing.get_raster_info( + * base_elevation_raster_path_band[0]) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_dem_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 340, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_base_elevation_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 340, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __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); + } + } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 340, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_dem_band = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":341 + * dem_raster = gdal.OpenEx(base_elevation_raster_path_band[0]) + * dem_band = dem_raster.GetRasterBand(base_elevation_raster_path_band[1]) + * dem_info = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< + * base_elevation_raster_path_band[0]) + * raw_nodata = dem_info['nodata'][0] + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 341, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 341, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":342 + * dem_band = dem_raster.GetRasterBand(base_elevation_raster_path_band[1]) + * dem_info = pygeoprocessing.get_raster_info( + * base_elevation_raster_path_band[0]) # <<<<<<<<<<<<<< + * raw_nodata = dem_info['nodata'][0] + * if raw_nodata is None: + */ + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_base_elevation_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 342, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 341, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_dem_info = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":343 + * dem_info = pygeoprocessing.get_raster_info( + * base_elevation_raster_path_band[0]) + * raw_nodata = dem_info['nodata'][0] # <<<<<<<<<<<<<< + * if raw_nodata is None: + * # if nodata is undefined, choose most negative 32 bit float + */ + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_dem_info, __pyx_n_u_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 343, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 343, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_raw_nodata = __pyx_t_2; + __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":344 + * base_elevation_raster_path_band[0]) + * raw_nodata = dem_info['nodata'][0] + * if raw_nodata is None: # <<<<<<<<<<<<<< + * # if nodata is undefined, choose most negative 32 bit float + * raw_nodata = numpy.finfo(numpy.float32).min + */ + __pyx_t_5 = (__pyx_v_raw_nodata == Py_None); + __pyx_t_6 = (__pyx_t_5 != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":346 + * if raw_nodata is None: + * # if nodata is undefined, choose most negative 32 bit float + * raw_nodata = numpy.finfo(numpy.float32).min # <<<<<<<<<<<<<< + * dem_nodata = raw_nodata + * x_cell_size, y_cell_size = dem_info['pixel_size'] + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 346, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_finfo); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 346, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 346, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 346, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + 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_2 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_1, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 346, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_min); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 346, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF_SET(__pyx_v_raw_nodata, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":344 + * base_elevation_raster_path_band[0]) + * raw_nodata = dem_info['nodata'][0] + * if raw_nodata is None: # <<<<<<<<<<<<<< + * # if nodata is undefined, choose most negative 32 bit float + * raw_nodata = numpy.finfo(numpy.float32).min + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":347 + * # if nodata is undefined, choose most negative 32 bit float + * raw_nodata = numpy.finfo(numpy.float32).min + * dem_nodata = raw_nodata # <<<<<<<<<<<<<< + * x_cell_size, y_cell_size = dem_info['pixel_size'] + * n_cols, n_rows = dem_info['raster_size'] + */ + __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_v_raw_nodata); if (unlikely((__pyx_t_7 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 347, __pyx_L1_error) + __pyx_v_dem_nodata = __pyx_t_7; + + /* "pygeoprocessing/geoprocessing_core.pyx":348 + * raw_nodata = numpy.finfo(numpy.float32).min + * dem_nodata = raw_nodata + * x_cell_size, y_cell_size = dem_info['pixel_size'] # <<<<<<<<<<<<<< + * n_cols, n_rows = dem_info['raster_size'] + * cdef numpy.npy_float64 slope_nodata = numpy.finfo(numpy.float32).min + */ + __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_dem_info, __pyx_n_u_pixel_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 348, __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, 348, __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_4 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_2 = PyList_GET_ITEM(sequence, 0); + __pyx_t_4 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + #else + __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 348, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 348, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #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, 348, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_1)->tp_iternext; + index = 0; __pyx_t_2 = __pyx_t_8(__pyx_t_1); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + index = 1; __pyx_t_4 = __pyx_t_8(__pyx_t_1); if (unlikely(!__pyx_t_4)) goto __pyx_L4_unpacking_failed; + __Pyx_GOTREF(__pyx_t_4); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_1), 2) < 0) __PYX_ERR(0, 348, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L5_unpacking_done; + __pyx_L4_unpacking_failed:; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 348, __pyx_L1_error) + __pyx_L5_unpacking_done:; + } + __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_t_2); if (unlikely((__pyx_t_7 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 348, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_9 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_9 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 348, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_x_cell_size = __pyx_t_7; + __pyx_v_y_cell_size = __pyx_t_9; + + /* "pygeoprocessing/geoprocessing_core.pyx":349 + * dem_nodata = raw_nodata + * x_cell_size, y_cell_size = dem_info['pixel_size'] + * n_cols, n_rows = dem_info['raster_size'] # <<<<<<<<<<<<<< + * cdef numpy.npy_float64 slope_nodata = numpy.finfo(numpy.float32).min + * pygeoprocessing.new_raster_from_base( + */ + __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_dem_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 349, __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, 349, __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_2 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_4 = PyList_GET_ITEM(sequence, 0); + __pyx_t_2 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_2); + #else + __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 349, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 349, __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_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 349, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_1)->tp_iternext; + index = 0; __pyx_t_4 = __pyx_t_8(__pyx_t_1); if (unlikely(!__pyx_t_4)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_4); + index = 1; __pyx_t_2 = __pyx_t_8(__pyx_t_1); if (unlikely(!__pyx_t_2)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_1), 2) < 0) __PYX_ERR(0, 349, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L7_unpacking_done; + __pyx_L6_unpacking_failed:; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 349, __pyx_L1_error) + __pyx_L7_unpacking_done:; + } + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 349, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 349, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_n_cols = __pyx_t_10; + __pyx_v_n_rows = __pyx_t_11; + + /* "pygeoprocessing/geoprocessing_core.pyx":350 + * x_cell_size, y_cell_size = dem_info['pixel_size'] + * n_cols, n_rows = dem_info['raster_size'] + * cdef numpy.npy_float64 slope_nodata = numpy.finfo(numpy.float32).min # <<<<<<<<<<<<<< + * pygeoprocessing.new_raster_from_base( + * base_elevation_raster_path_band[0], target_slope_path, + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 350, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_finfo); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 350, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 350, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 350, __pyx_L1_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_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_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_2, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 350, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_min); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 350, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_9 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_9 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 350, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_slope_nodata = __pyx_t_9; + + /* "pygeoprocessing/geoprocessing_core.pyx":351 + * n_cols, n_rows = dem_info['raster_size'] + * cdef numpy.npy_float64 slope_nodata = numpy.finfo(numpy.float32).min + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * base_elevation_raster_path_band[0], target_slope_path, + * gdal.GDT_Float32, [slope_nodata], + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 351, __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, 351, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":352 + * cdef numpy.npy_float64 slope_nodata = numpy.finfo(numpy.float32).min + * pygeoprocessing.new_raster_from_base( + * base_elevation_raster_path_band[0], target_slope_path, # <<<<<<<<<<<<<< + * gdal.GDT_Float32, [slope_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + */ + __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_base_elevation_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 352, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "pygeoprocessing/geoprocessing_core.pyx":353 + * pygeoprocessing.new_raster_from_base( + * base_elevation_raster_path_band[0], target_slope_path, + * gdal.GDT_Float32, [slope_nodata], # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * target_slope_raster = gdal.OpenEx(target_slope_path, gdal.GA_Update) + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 353, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Float32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 353, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_slope_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 353, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_12 = PyList_New(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 353, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_GIVEREF(__pyx_t_1); + PyList_SET_ITEM(__pyx_t_12, 0, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":351 + * n_cols, n_rows = dem_info['raster_size'] + * cdef numpy.npy_float64 slope_nodata = numpy.finfo(numpy.float32).min + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * base_elevation_raster_path_band[0], target_slope_path, + * gdal.GDT_Float32, [slope_nodata], + */ + __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 351, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4); + __Pyx_INCREF(__pyx_v_target_slope_path); + __Pyx_GIVEREF(__pyx_v_target_slope_path); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_target_slope_path); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_12); + __pyx_t_4 = 0; + __pyx_t_2 = 0; + __pyx_t_12 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":354 + * base_elevation_raster_path_band[0], target_slope_path, + * gdal.GDT_Float32, [slope_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< + * target_slope_raster = gdal.OpenEx(target_slope_path, gdal.GA_Update) + * target_slope_band = target_slope_raster.GetRasterBand(1) + */ + __pyx_t_12 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 354, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 354, __pyx_L1_error) + + /* "pygeoprocessing/geoprocessing_core.pyx":351 + * n_cols, n_rows = dem_info['raster_size'] + * cdef numpy.npy_float64 slope_nodata = numpy.finfo(numpy.float32).min + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * base_elevation_raster_path_band[0], target_slope_path, + * gdal.GDT_Float32, [slope_nodata], + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, __pyx_t_12); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 351, __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; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":355 + * gdal.GDT_Float32, [slope_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * target_slope_raster = gdal.OpenEx(target_slope_path, gdal.GA_Update) # <<<<<<<<<<<<<< + * target_slope_band = target_slope_raster.GetRasterBand(1) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_gdal); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 355, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 355, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_gdal); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 355, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_GA_Update); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 355, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_12)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_12); + __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_12, __pyx_v_target_slope_path, __pyx_t_3}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 355, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_2); + __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[3] = {__pyx_t_12, __pyx_v_target_slope_path, __pyx_t_3}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 355, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + { + __pyx_t_4 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 355, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (__pyx_t_12) { + __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_12); __pyx_t_12 = NULL; + } + __Pyx_INCREF(__pyx_v_target_slope_path); + __Pyx_GIVEREF(__pyx_v_target_slope_path); + PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_11, __pyx_v_target_slope_path); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_11, __pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 355, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_target_slope_raster = __pyx_t_2; + __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":356 + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * target_slope_raster = gdal.OpenEx(target_slope_path, gdal.GA_Update) + * target_slope_band = target_slope_raster.GetRasterBand(1) # <<<<<<<<<<<<<< + * + * for block_offset in pygeoprocessing.iterblocks( + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_target_slope_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 356, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = NULL; + 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_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_4, __pyx_int_1) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_int_1); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 356, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_target_slope_band = __pyx_t_2; + __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":358 + * target_slope_band = target_slope_raster.GetRasterBand(1) + * + * for block_offset in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * base_elevation_raster_path_band, offset_only=True): + * block_offset_copy = block_offset.copy() + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 358, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 358, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":359 + * + * for block_offset in pygeoprocessing.iterblocks( + * base_elevation_raster_path_band, offset_only=True): # <<<<<<<<<<<<<< + * block_offset_copy = block_offset.copy() + * # try to expand the block around the edges if it fits + */ + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 358, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_base_elevation_raster_path_band); + __Pyx_GIVEREF(__pyx_v_base_elevation_raster_path_band); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_base_elevation_raster_path_band); + __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 359, __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, 359, __pyx_L1_error) + + /* "pygeoprocessing/geoprocessing_core.pyx":358 + * target_slope_band = target_slope_raster.GetRasterBand(1) + * + * for block_offset in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * base_elevation_raster_path_band, offset_only=True): + * block_offset_copy = block_offset.copy() + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 358, __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(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) { + __pyx_t_4 = __pyx_t_3; __Pyx_INCREF(__pyx_t_4); __pyx_t_13 = 0; + __pyx_t_14 = NULL; + } else { + __pyx_t_13 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 358, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_14 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 358, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + for (;;) { + if (likely(!__pyx_t_14)) { + if (likely(PyList_CheckExact(__pyx_t_4))) { + if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_13); __Pyx_INCREF(__pyx_t_3); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 358, __pyx_L1_error) + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 358, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + } else { + if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_13); __Pyx_INCREF(__pyx_t_3); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 358, __pyx_L1_error) + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 358, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + } + } else { + __pyx_t_3 = __pyx_t_14(__pyx_t_4); + 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, 358, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF_SET(__pyx_v_block_offset, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":360 + * for block_offset in pygeoprocessing.iterblocks( + * base_elevation_raster_path_band, offset_only=True): + * block_offset_copy = block_offset.copy() # <<<<<<<<<<<<<< + * # try to expand the block around the edges if it fits + * x_start = 1 + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_block_offset, __pyx_n_s_copy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 360, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_3 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 360, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF_SET(__pyx_v_block_offset_copy, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":362 + * block_offset_copy = block_offset.copy() + * # try to expand the block around the edges if it fits + * x_start = 1 # <<<<<<<<<<<<<< + * win_xsize = block_offset['win_xsize'] + * x_end = win_xsize+1 + */ + __Pyx_INCREF(__pyx_int_1); + __Pyx_XDECREF_SET(__pyx_v_x_start, __pyx_int_1); + + /* "pygeoprocessing/geoprocessing_core.pyx":363 + * # try to expand the block around the edges if it fits + * x_start = 1 + * win_xsize = block_offset['win_xsize'] # <<<<<<<<<<<<<< + * x_end = win_xsize+1 + * y_start = 1 + */ + __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 363, __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, 363, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_win_xsize = __pyx_t_11; + + /* "pygeoprocessing/geoprocessing_core.pyx":364 + * x_start = 1 + * win_xsize = block_offset['win_xsize'] + * x_end = win_xsize+1 # <<<<<<<<<<<<<< + * y_start = 1 + * win_ysize = block_offset['win_ysize'] + */ + __pyx_t_3 = __Pyx_PyInt_From_long((__pyx_v_win_xsize + 1)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 364, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XDECREF_SET(__pyx_v_x_end, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":365 + * win_xsize = block_offset['win_xsize'] + * x_end = win_xsize+1 + * y_start = 1 # <<<<<<<<<<<<<< + * win_ysize = block_offset['win_ysize'] + * y_end = win_ysize+1 + */ + __Pyx_INCREF(__pyx_int_1); + __Pyx_XDECREF_SET(__pyx_v_y_start, __pyx_int_1); + + /* "pygeoprocessing/geoprocessing_core.pyx":366 + * x_end = win_xsize+1 + * y_start = 1 + * win_ysize = block_offset['win_ysize'] # <<<<<<<<<<<<<< + * y_end = win_ysize+1 + * + */ + __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 366, __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, 366, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_win_ysize = __pyx_t_11; + + /* "pygeoprocessing/geoprocessing_core.pyx":367 + * y_start = 1 + * win_ysize = block_offset['win_ysize'] + * y_end = win_ysize+1 # <<<<<<<<<<<<<< + * + * if block_offset['xoff'] > 0: + */ + __pyx_t_3 = __Pyx_PyInt_From_long((__pyx_v_win_ysize + 1)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 367, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XDECREF_SET(__pyx_v_y_end, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":369 + * y_end = win_ysize+1 + * + * if block_offset['xoff'] > 0: # <<<<<<<<<<<<<< + * block_offset_copy['xoff'] -= 1 + * block_offset_copy['win_xsize'] += 1 + */ + __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset, __pyx_n_u_xoff); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 369, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 369, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 369, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":370 + * + * if block_offset['xoff'] > 0: + * block_offset_copy['xoff'] -= 1 # <<<<<<<<<<<<<< + * block_offset_copy['win_xsize'] += 1 + * x_start -= 1 + */ + __Pyx_INCREF(__pyx_n_u_xoff); + __pyx_t_15 = __pyx_n_u_xoff; + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset_copy, __pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 370, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyInt_SubtractObjC(__pyx_t_2, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 370, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(PyObject_SetItem(__pyx_v_block_offset_copy, __pyx_t_15, __pyx_t_3) < 0)) __PYX_ERR(0, 370, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":371 + * if block_offset['xoff'] > 0: + * block_offset_copy['xoff'] -= 1 + * block_offset_copy['win_xsize'] += 1 # <<<<<<<<<<<<<< + * x_start -= 1 + * if block_offset['xoff']+win_xsize < n_cols: + */ + __Pyx_INCREF(__pyx_n_u_win_xsize); + __pyx_t_15 = __pyx_n_u_win_xsize; + __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset_copy, __pyx_t_15); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 371, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 371, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(PyObject_SetItem(__pyx_v_block_offset_copy, __pyx_t_15, __pyx_t_2) < 0)) __PYX_ERR(0, 371, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":372 + * block_offset_copy['xoff'] -= 1 + * block_offset_copy['win_xsize'] += 1 + * x_start -= 1 # <<<<<<<<<<<<<< + * if block_offset['xoff']+win_xsize < n_cols: + * block_offset_copy['win_xsize'] += 1 + */ + __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_v_x_start, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 372, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF_SET(__pyx_v_x_start, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":369 + * y_end = win_ysize+1 + * + * if block_offset['xoff'] > 0: # <<<<<<<<<<<<<< + * block_offset_copy['xoff'] -= 1 + * block_offset_copy['win_xsize'] += 1 + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":373 + * block_offset_copy['win_xsize'] += 1 + * x_start -= 1 + * if block_offset['xoff']+win_xsize < n_cols: # <<<<<<<<<<<<<< + * block_offset_copy['win_xsize'] += 1 + * x_end += 1 + */ + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset, __pyx_n_u_xoff); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 373, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 373, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyNumber_Add(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 373, __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_t_3 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 373, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 373, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 373, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":374 + * x_start -= 1 + * if block_offset['xoff']+win_xsize < n_cols: + * block_offset_copy['win_xsize'] += 1 # <<<<<<<<<<<<<< + * x_end += 1 + * if block_offset['yoff'] > 0: + */ + __Pyx_INCREF(__pyx_n_u_win_xsize); + __pyx_t_15 = __pyx_n_u_win_xsize; + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset_copy, __pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 374, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 374, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(PyObject_SetItem(__pyx_v_block_offset_copy, __pyx_t_15, __pyx_t_3) < 0)) __PYX_ERR(0, 374, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":375 + * if block_offset['xoff']+win_xsize < n_cols: + * block_offset_copy['win_xsize'] += 1 + * x_end += 1 # <<<<<<<<<<<<<< + * if block_offset['yoff'] > 0: + * block_offset_copy['yoff'] -= 1 + */ + __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_v_x_end, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 375, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF_SET(__pyx_v_x_end, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":373 + * block_offset_copy['win_xsize'] += 1 + * x_start -= 1 + * if block_offset['xoff']+win_xsize < n_cols: # <<<<<<<<<<<<<< + * block_offset_copy['win_xsize'] += 1 + * x_end += 1 + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":376 + * block_offset_copy['win_xsize'] += 1 + * x_end += 1 + * if block_offset['yoff'] > 0: # <<<<<<<<<<<<<< + * block_offset_copy['yoff'] -= 1 + * block_offset_copy['win_ysize'] += 1 + */ + __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset, __pyx_n_u_yoff); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 376, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 376, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 376, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":377 + * x_end += 1 + * if block_offset['yoff'] > 0: + * block_offset_copy['yoff'] -= 1 # <<<<<<<<<<<<<< + * block_offset_copy['win_ysize'] += 1 + * y_start -= 1 + */ + __Pyx_INCREF(__pyx_n_u_yoff); + __pyx_t_15 = __pyx_n_u_yoff; + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset_copy, __pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 377, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyInt_SubtractObjC(__pyx_t_2, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 377, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(PyObject_SetItem(__pyx_v_block_offset_copy, __pyx_t_15, __pyx_t_3) < 0)) __PYX_ERR(0, 377, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":378 + * if block_offset['yoff'] > 0: + * block_offset_copy['yoff'] -= 1 + * block_offset_copy['win_ysize'] += 1 # <<<<<<<<<<<<<< + * y_start -= 1 + * if block_offset['yoff']+win_ysize < n_rows: + */ + __Pyx_INCREF(__pyx_n_u_win_ysize); + __pyx_t_15 = __pyx_n_u_win_ysize; + __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset_copy, __pyx_t_15); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 378, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 378, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(PyObject_SetItem(__pyx_v_block_offset_copy, __pyx_t_15, __pyx_t_2) < 0)) __PYX_ERR(0, 378, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":379 + * block_offset_copy['yoff'] -= 1 + * block_offset_copy['win_ysize'] += 1 + * y_start -= 1 # <<<<<<<<<<<<<< + * if block_offset['yoff']+win_ysize < n_rows: + * block_offset_copy['win_ysize'] += 1 + */ + __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_v_y_start, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 379, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF_SET(__pyx_v_y_start, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":376 + * block_offset_copy['win_xsize'] += 1 + * x_end += 1 + * if block_offset['yoff'] > 0: # <<<<<<<<<<<<<< + * block_offset_copy['yoff'] -= 1 + * block_offset_copy['win_ysize'] += 1 + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":380 + * block_offset_copy['win_ysize'] += 1 + * y_start -= 1 + * if block_offset['yoff']+win_ysize < n_rows: # <<<<<<<<<<<<<< + * block_offset_copy['win_ysize'] += 1 + * y_end += 1 + */ + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset, __pyx_n_u_yoff); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 380, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 380, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyNumber_Add(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 380, __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_t_3 = __Pyx_PyInt_From_int(__pyx_v_n_rows); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 380, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 380, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 380, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":381 + * y_start -= 1 + * if block_offset['yoff']+win_ysize < n_rows: + * block_offset_copy['win_ysize'] += 1 # <<<<<<<<<<<<<< + * y_end += 1 + * + */ + __Pyx_INCREF(__pyx_n_u_win_ysize); + __pyx_t_15 = __pyx_n_u_win_ysize; + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset_copy, __pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 381, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 381, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(PyObject_SetItem(__pyx_v_block_offset_copy, __pyx_t_15, __pyx_t_3) < 0)) __PYX_ERR(0, 381, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":382 + * if block_offset['yoff']+win_ysize < n_rows: + * block_offset_copy['win_ysize'] += 1 + * y_end += 1 # <<<<<<<<<<<<<< + * + * dem_array = numpy.empty( + */ + __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_v_y_end, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 382, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF_SET(__pyx_v_y_end, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":380 + * block_offset_copy['win_ysize'] += 1 + * y_start -= 1 + * if block_offset['yoff']+win_ysize < n_rows: # <<<<<<<<<<<<<< + * block_offset_copy['win_ysize'] += 1 + * y_end += 1 + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":384 + * y_end += 1 + * + * dem_array = numpy.empty( # <<<<<<<<<<<<<< + * (win_ysize+2, win_xsize+2), + * dtype=numpy.float64) + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 384, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 384, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":385 + * + * dem_array = numpy.empty( + * (win_ysize+2, win_xsize+2), # <<<<<<<<<<<<<< + * dtype=numpy.float64) + * dem_array[:] = dem_nodata + */ + __pyx_t_3 = __Pyx_PyInt_From_long((__pyx_v_win_ysize + 2)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 385, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_PyInt_From_long((__pyx_v_win_xsize + 2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 385, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 385, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_1); + __pyx_t_3 = 0; + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":384 + * y_end += 1 + * + * dem_array = numpy.empty( # <<<<<<<<<<<<<< + * (win_ysize+2, win_xsize+2), + * dtype=numpy.float64) + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 384, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_12); + __pyx_t_12 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":386 + * dem_array = numpy.empty( + * (win_ysize+2, win_xsize+2), + * dtype=numpy.float64) # <<<<<<<<<<<<<< + * dem_array[:] = dem_nodata + * slope_array = numpy.empty( + */ + __pyx_t_12 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 386, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 386, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 386, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_dtype, __pyx_t_16) < 0) __PYX_ERR(0, 386, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":384 + * y_end += 1 + * + * dem_array = numpy.empty( # <<<<<<<<<<<<<< + * (win_ysize+2, win_xsize+2), + * dtype=numpy.float64) + */ + __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_12); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 384, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (!(likely(((__pyx_t_16) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_16, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 384, __pyx_L1_error) + __pyx_t_17 = ((PyArrayObject *)__pyx_t_16); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dem_array.rcbuffer->pybuffer); + __pyx_t_11 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dem_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_17, &__Pyx_TypeInfo_nn_npy_float64, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); + if (unlikely(__pyx_t_11 < 0)) { + PyErr_Fetch(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dem_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_dem_array, &__Pyx_TypeInfo_nn_npy_float64, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_18); Py_XDECREF(__pyx_t_19); Py_XDECREF(__pyx_t_20); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_18, __pyx_t_19, __pyx_t_20); + } + __pyx_t_18 = __pyx_t_19 = __pyx_t_20 = 0; + } + __pyx_pybuffernd_dem_array.diminfo[0].strides = __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_dem_array.diminfo[0].shape = __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_dem_array.diminfo[1].strides = __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_dem_array.diminfo[1].shape = __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.shape[1]; + if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 384, __pyx_L1_error) + } + __pyx_t_17 = 0; + __Pyx_XDECREF_SET(__pyx_v_dem_array, ((PyArrayObject *)__pyx_t_16)); + __pyx_t_16 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":387 + * (win_ysize+2, win_xsize+2), + * dtype=numpy.float64) + * dem_array[:] = dem_nodata # <<<<<<<<<<<<<< + * slope_array = numpy.empty( + * (win_ysize, win_xsize), + */ + __pyx_t_16 = PyFloat_FromDouble(__pyx_v_dem_nodata); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 387, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_dem_array), __pyx_slice_, __pyx_t_16) < 0)) __PYX_ERR(0, 387, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":388 + * dtype=numpy.float64) + * dem_array[:] = dem_nodata + * slope_array = numpy.empty( # <<<<<<<<<<<<<< + * (win_ysize, win_xsize), + * dtype=numpy.float64) + */ + __Pyx_GetModuleGlobalName(__pyx_t_16, __pyx_n_s_numpy); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 388, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_16, __pyx_n_s_empty); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 388, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":389 + * dem_array[:] = dem_nodata + * slope_array = numpy.empty( + * (win_ysize, win_xsize), # <<<<<<<<<<<<<< + * dtype=numpy.float64) + * dzdx_array = numpy.empty( + */ + __pyx_t_16 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 389, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 389, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 389, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_16); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_16); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1); + __pyx_t_16 = 0; + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":388 + * dtype=numpy.float64) + * dem_array[:] = dem_nodata + * slope_array = numpy.empty( # <<<<<<<<<<<<<< + * (win_ysize, win_xsize), + * dtype=numpy.float64) + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 388, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":390 + * slope_array = numpy.empty( + * (win_ysize, win_xsize), + * dtype=numpy.float64) # <<<<<<<<<<<<<< + * dzdx_array = numpy.empty( + * (win_ysize, win_xsize), + */ + __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 390, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GetModuleGlobalName(__pyx_t_16, __pyx_n_s_numpy); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 390, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_16, __pyx_n_s_float64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 390, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 390, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":388 + * dtype=numpy.float64) + * dem_array[:] = dem_nodata + * slope_array = numpy.empty( # <<<<<<<<<<<<<< + * (win_ysize, win_xsize), + * dtype=numpy.float64) + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 388, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 388, __pyx_L1_error) + __pyx_t_21 = ((PyArrayObject *)__pyx_t_3); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_slope_array.rcbuffer->pybuffer); + __pyx_t_11 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_slope_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_21, &__Pyx_TypeInfo_nn_npy_float64, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); + if (unlikely(__pyx_t_11 < 0)) { + PyErr_Fetch(&__pyx_t_20, &__pyx_t_19, &__pyx_t_18); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_slope_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_slope_array, &__Pyx_TypeInfo_nn_npy_float64, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_20); Py_XDECREF(__pyx_t_19); Py_XDECREF(__pyx_t_18); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_20, __pyx_t_19, __pyx_t_18); + } + __pyx_t_20 = __pyx_t_19 = __pyx_t_18 = 0; + } + __pyx_pybuffernd_slope_array.diminfo[0].strides = __pyx_pybuffernd_slope_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_slope_array.diminfo[0].shape = __pyx_pybuffernd_slope_array.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_slope_array.diminfo[1].strides = __pyx_pybuffernd_slope_array.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_slope_array.diminfo[1].shape = __pyx_pybuffernd_slope_array.rcbuffer->pybuffer.shape[1]; + if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 388, __pyx_L1_error) + } + __pyx_t_21 = 0; + __Pyx_XDECREF_SET(__pyx_v_slope_array, ((PyArrayObject *)__pyx_t_3)); + __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":391 + * (win_ysize, win_xsize), + * dtype=numpy.float64) + * dzdx_array = numpy.empty( # <<<<<<<<<<<<<< + * (win_ysize, win_xsize), + * dtype=numpy.float64) + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 391, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 391, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":392 + * dtype=numpy.float64) + * dzdx_array = numpy.empty( + * (win_ysize, win_xsize), # <<<<<<<<<<<<<< + * dtype=numpy.float64) + * dzdy_array = numpy.empty( + */ + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 392, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 392, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 392, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_1); + __pyx_t_3 = 0; + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":391 + * (win_ysize, win_xsize), + * dtype=numpy.float64) + * dzdx_array = numpy.empty( # <<<<<<<<<<<<<< + * (win_ysize, win_xsize), + * dtype=numpy.float64) + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 391, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_12); + __pyx_t_12 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":393 + * dzdx_array = numpy.empty( + * (win_ysize, win_xsize), + * dtype=numpy.float64) # <<<<<<<<<<<<<< + * dzdy_array = numpy.empty( + * (win_ysize, win_xsize), + */ + __pyx_t_12 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 393, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 393, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 393, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_dtype, __pyx_t_16) < 0) __PYX_ERR(0, 393, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":391 + * (win_ysize, win_xsize), + * dtype=numpy.float64) + * dzdx_array = numpy.empty( # <<<<<<<<<<<<<< + * (win_ysize, win_xsize), + * dtype=numpy.float64) + */ + __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_12); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 391, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (!(likely(((__pyx_t_16) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_16, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 391, __pyx_L1_error) + __pyx_t_22 = ((PyArrayObject *)__pyx_t_16); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer); + __pyx_t_11 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_22, &__Pyx_TypeInfo_nn_npy_float64, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack); + if (unlikely(__pyx_t_11 < 0)) { + PyErr_Fetch(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_dzdx_array, &__Pyx_TypeInfo_nn_npy_float64, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_18); Py_XDECREF(__pyx_t_19); Py_XDECREF(__pyx_t_20); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_18, __pyx_t_19, __pyx_t_20); + } + __pyx_t_18 = __pyx_t_19 = __pyx_t_20 = 0; + } + __pyx_pybuffernd_dzdx_array.diminfo[0].strides = __pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_dzdx_array.diminfo[0].shape = __pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_dzdx_array.diminfo[1].strides = __pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_dzdx_array.diminfo[1].shape = __pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer.shape[1]; + if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 391, __pyx_L1_error) + } + __pyx_t_22 = 0; + __Pyx_XDECREF_SET(__pyx_v_dzdx_array, ((PyArrayObject *)__pyx_t_16)); + __pyx_t_16 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":394 + * (win_ysize, win_xsize), + * dtype=numpy.float64) + * dzdy_array = numpy.empty( # <<<<<<<<<<<<<< + * (win_ysize, win_xsize), + * dtype=numpy.float64) + */ + __Pyx_GetModuleGlobalName(__pyx_t_16, __pyx_n_s_numpy); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 394, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_16, __pyx_n_s_empty); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 394, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":395 + * dtype=numpy.float64) + * dzdy_array = numpy.empty( + * (win_ysize, win_xsize), # <<<<<<<<<<<<<< + * dtype=numpy.float64) + * + */ + __pyx_t_16 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 395, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 395, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 395, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_16); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_16); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1); + __pyx_t_16 = 0; + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":394 + * (win_ysize, win_xsize), + * dtype=numpy.float64) + * dzdy_array = numpy.empty( # <<<<<<<<<<<<<< + * (win_ysize, win_xsize), + * dtype=numpy.float64) + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 394, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":396 + * dzdy_array = numpy.empty( + * (win_ysize, win_xsize), + * dtype=numpy.float64) # <<<<<<<<<<<<<< + * + * dem_band.ReadAsArray( + */ + __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 396, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GetModuleGlobalName(__pyx_t_16, __pyx_n_s_numpy); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 396, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_16, __pyx_n_s_float64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 396, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 396, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":394 + * (win_ysize, win_xsize), + * dtype=numpy.float64) + * dzdy_array = numpy.empty( # <<<<<<<<<<<<<< + * (win_ysize, win_xsize), + * dtype=numpy.float64) + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 394, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 394, __pyx_L1_error) + __pyx_t_23 = ((PyArrayObject *)__pyx_t_3); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dzdy_array.rcbuffer->pybuffer); + __pyx_t_11 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dzdy_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_23, &__Pyx_TypeInfo_nn_npy_float64, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack); + if (unlikely(__pyx_t_11 < 0)) { + PyErr_Fetch(&__pyx_t_20, &__pyx_t_19, &__pyx_t_18); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dzdy_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_dzdy_array, &__Pyx_TypeInfo_nn_npy_float64, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_20); Py_XDECREF(__pyx_t_19); Py_XDECREF(__pyx_t_18); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_20, __pyx_t_19, __pyx_t_18); + } + __pyx_t_20 = __pyx_t_19 = __pyx_t_18 = 0; + } + __pyx_pybuffernd_dzdy_array.diminfo[0].strides = __pyx_pybuffernd_dzdy_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_dzdy_array.diminfo[0].shape = __pyx_pybuffernd_dzdy_array.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_dzdy_array.diminfo[1].strides = __pyx_pybuffernd_dzdy_array.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_dzdy_array.diminfo[1].shape = __pyx_pybuffernd_dzdy_array.rcbuffer->pybuffer.shape[1]; + if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 394, __pyx_L1_error) + } + __pyx_t_23 = 0; + __Pyx_XDECREF_SET(__pyx_v_dzdy_array, ((PyArrayObject *)__pyx_t_3)); + __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":398 + * dtype=numpy.float64) + * + * dem_band.ReadAsArray( # <<<<<<<<<<<<<< + * buf_obj=dem_array[y_start:y_end, x_start:x_end], + * **block_offset_copy) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_dem_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 398, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + + /* "pygeoprocessing/geoprocessing_core.pyx":399 + * + * dem_band.ReadAsArray( + * buf_obj=dem_array[y_start:y_end, x_start:x_end], # <<<<<<<<<<<<<< + * **block_offset_copy) + * + */ + __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 399, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_12 = PySlice_New(__pyx_v_y_start, __pyx_v_y_end, Py_None); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 399, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_16 = PySlice_New(__pyx_v_x_start, __pyx_v_x_end, Py_None); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 399, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_24 = PyTuple_New(2); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 399, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_24); + __Pyx_GIVEREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_24, 0, __pyx_t_12); + __Pyx_GIVEREF(__pyx_t_16); + PyTuple_SET_ITEM(__pyx_t_24, 1, __pyx_t_16); + __pyx_t_12 = 0; + __pyx_t_16 = 0; + __pyx_t_16 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_dem_array), __pyx_t_24); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 399, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_buf_obj, __pyx_t_16) < 0) __PYX_ERR(0, 399, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __pyx_t_2 = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":400 + * dem_band.ReadAsArray( + * buf_obj=dem_array[y_start:y_end, x_start:x_end], + * **block_offset_copy) # <<<<<<<<<<<<<< + * + * for row_index in range(1, win_ysize+1): + */ + if (unlikely(__pyx_v_block_offset_copy == Py_None)) { + PyErr_SetString(PyExc_TypeError, "argument after ** must be a mapping, not NoneType"); + __PYX_ERR(0, 400, __pyx_L1_error) + } + if (__Pyx_MergeKeywords(__pyx_t_2, __pyx_v_block_offset_copy) < 0) __PYX_ERR(0, 400, __pyx_L1_error) + + /* "pygeoprocessing/geoprocessing_core.pyx":398 + * dtype=numpy.float64) + * + * dem_band.ReadAsArray( # <<<<<<<<<<<<<< + * buf_obj=dem_array[y_start:y_end, x_start:x_end], + * **block_offset_copy) + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_empty_tuple, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 398, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":402 + * **block_offset_copy) + * + * for row_index in range(1, win_ysize+1): # <<<<<<<<<<<<<< + * for col_index in range(1, win_xsize+1): + * # Notation of the cell below comes from the algorithm + */ + __pyx_t_25 = (__pyx_v_win_ysize + 1); + __pyx_t_26 = __pyx_t_25; + for (__pyx_t_11 = 1; __pyx_t_11 < __pyx_t_26; __pyx_t_11+=1) { + __pyx_v_row_index = __pyx_t_11; + + /* "pygeoprocessing/geoprocessing_core.pyx":403 + * + * for row_index in range(1, win_ysize+1): + * for col_index in range(1, win_xsize+1): # <<<<<<<<<<<<<< + * # Notation of the cell below comes from the algorithm + * # description, cells are arraged as follows: + */ + __pyx_t_27 = (__pyx_v_win_xsize + 1); + __pyx_t_28 = __pyx_t_27; + for (__pyx_t_10 = 1; __pyx_t_10 < __pyx_t_28; __pyx_t_10+=1) { + __pyx_v_col_index = __pyx_t_10; + + /* "pygeoprocessing/geoprocessing_core.pyx":409 + * # def + * # ghi + * e = dem_array[row_index, col_index] # <<<<<<<<<<<<<< + * if e == dem_nodata: + * # we use dzdx as a guard below, no need to set dzdy + */ + __pyx_t_29 = __pyx_v_row_index; + __pyx_t_30 = __pyx_v_col_index; + __pyx_v_e = (*__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_dem_array.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_dem_array.diminfo[1].strides)); + + /* "pygeoprocessing/geoprocessing_core.pyx":410 + * # ghi + * e = dem_array[row_index, col_index] + * if e == dem_nodata: # <<<<<<<<<<<<<< + * # we use dzdx as a guard below, no need to set dzdy + * dzdx_array[row_index-1, col_index-1] = slope_nodata + */ + __pyx_t_6 = ((__pyx_v_e == __pyx_v_dem_nodata) != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":412 + * if e == dem_nodata: + * # we use dzdx as a guard below, no need to set dzdy + * dzdx_array[row_index-1, col_index-1] = slope_nodata # <<<<<<<<<<<<<< + * continue + * dzdx_accumulator = 0.0 + */ + __pyx_t_30 = (__pyx_v_row_index - 1); + __pyx_t_29 = (__pyx_v_col_index - 1); + *__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_dzdx_array.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_dzdx_array.diminfo[1].strides) = __pyx_v_slope_nodata; + + /* "pygeoprocessing/geoprocessing_core.pyx":413 + * # we use dzdx as a guard below, no need to set dzdy + * dzdx_array[row_index-1, col_index-1] = slope_nodata + * continue # <<<<<<<<<<<<<< + * dzdx_accumulator = 0.0 + * dzdy_accumulator = 0.0 + */ + goto __pyx_L16_continue; + + /* "pygeoprocessing/geoprocessing_core.pyx":410 + * # ghi + * e = dem_array[row_index, col_index] + * if e == dem_nodata: # <<<<<<<<<<<<<< + * # we use dzdx as a guard below, no need to set dzdy + * dzdx_array[row_index-1, col_index-1] = slope_nodata + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":414 + * dzdx_array[row_index-1, col_index-1] = slope_nodata + * continue + * dzdx_accumulator = 0.0 # <<<<<<<<<<<<<< + * dzdy_accumulator = 0.0 + * x_denom_factor = 0 + */ + __pyx_v_dzdx_accumulator = 0.0; + + /* "pygeoprocessing/geoprocessing_core.pyx":415 + * continue + * dzdx_accumulator = 0.0 + * dzdy_accumulator = 0.0 # <<<<<<<<<<<<<< + * x_denom_factor = 0 + * y_denom_factor = 0 + */ + __pyx_v_dzdy_accumulator = 0.0; + + /* "pygeoprocessing/geoprocessing_core.pyx":416 + * dzdx_accumulator = 0.0 + * dzdy_accumulator = 0.0 + * x_denom_factor = 0 # <<<<<<<<<<<<<< + * y_denom_factor = 0 + * a = dem_array[row_index-1, col_index-1] + */ + __pyx_v_x_denom_factor = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":417 + * dzdy_accumulator = 0.0 + * x_denom_factor = 0 + * y_denom_factor = 0 # <<<<<<<<<<<<<< + * a = dem_array[row_index-1, col_index-1] + * b = dem_array[row_index-1, col_index] + */ + __pyx_v_y_denom_factor = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":418 + * x_denom_factor = 0 + * y_denom_factor = 0 + * a = dem_array[row_index-1, col_index-1] # <<<<<<<<<<<<<< + * b = dem_array[row_index-1, col_index] + * c = dem_array[row_index-1, col_index+1] + */ + __pyx_t_29 = (__pyx_v_row_index - 1); + __pyx_t_30 = (__pyx_v_col_index - 1); + __pyx_v_a = (*__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_dem_array.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_dem_array.diminfo[1].strides)); + + /* "pygeoprocessing/geoprocessing_core.pyx":419 + * y_denom_factor = 0 + * a = dem_array[row_index-1, col_index-1] + * b = dem_array[row_index-1, col_index] # <<<<<<<<<<<<<< + * c = dem_array[row_index-1, col_index+1] + * d = dem_array[row_index, col_index-1] + */ + __pyx_t_30 = (__pyx_v_row_index - 1); + __pyx_t_29 = __pyx_v_col_index; + __pyx_v_b = (*__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_dem_array.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_dem_array.diminfo[1].strides)); + + /* "pygeoprocessing/geoprocessing_core.pyx":420 + * a = dem_array[row_index-1, col_index-1] + * b = dem_array[row_index-1, col_index] + * c = dem_array[row_index-1, col_index+1] # <<<<<<<<<<<<<< + * d = dem_array[row_index, col_index-1] + * f = dem_array[row_index, col_index+1] + */ + __pyx_t_29 = (__pyx_v_row_index - 1); + __pyx_t_30 = (__pyx_v_col_index + 1); + __pyx_v_c = (*__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_dem_array.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_dem_array.diminfo[1].strides)); + + /* "pygeoprocessing/geoprocessing_core.pyx":421 + * b = dem_array[row_index-1, col_index] + * c = dem_array[row_index-1, col_index+1] + * d = dem_array[row_index, col_index-1] # <<<<<<<<<<<<<< + * f = dem_array[row_index, col_index+1] + * g = dem_array[row_index+1, col_index-1] + */ + __pyx_t_30 = __pyx_v_row_index; + __pyx_t_29 = (__pyx_v_col_index - 1); + __pyx_v_d = (*__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_dem_array.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_dem_array.diminfo[1].strides)); + + /* "pygeoprocessing/geoprocessing_core.pyx":422 + * c = dem_array[row_index-1, col_index+1] + * d = dem_array[row_index, col_index-1] + * f = dem_array[row_index, col_index+1] # <<<<<<<<<<<<<< + * g = dem_array[row_index+1, col_index-1] + * h = dem_array[row_index+1, col_index] + */ + __pyx_t_29 = __pyx_v_row_index; + __pyx_t_30 = (__pyx_v_col_index + 1); + __pyx_v_f = (*__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_dem_array.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_dem_array.diminfo[1].strides)); + + /* "pygeoprocessing/geoprocessing_core.pyx":423 + * d = dem_array[row_index, col_index-1] + * f = dem_array[row_index, col_index+1] + * g = dem_array[row_index+1, col_index-1] # <<<<<<<<<<<<<< + * h = dem_array[row_index+1, col_index] + * i = dem_array[row_index+1, col_index+1] + */ + __pyx_t_30 = (__pyx_v_row_index + 1); + __pyx_t_29 = (__pyx_v_col_index - 1); + __pyx_v_g = (*__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_dem_array.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_dem_array.diminfo[1].strides)); + + /* "pygeoprocessing/geoprocessing_core.pyx":424 + * f = dem_array[row_index, col_index+1] + * g = dem_array[row_index+1, col_index-1] + * h = dem_array[row_index+1, col_index] # <<<<<<<<<<<<<< + * i = dem_array[row_index+1, col_index+1] + * + */ + __pyx_t_29 = (__pyx_v_row_index + 1); + __pyx_t_30 = __pyx_v_col_index; + __pyx_v_h = (*__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_dem_array.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_dem_array.diminfo[1].strides)); + + /* "pygeoprocessing/geoprocessing_core.pyx":425 + * g = dem_array[row_index+1, col_index-1] + * h = dem_array[row_index+1, col_index] + * i = dem_array[row_index+1, col_index+1] # <<<<<<<<<<<<<< + * + * # a - c direction + */ + __pyx_t_30 = (__pyx_v_row_index + 1); + __pyx_t_29 = (__pyx_v_col_index + 1); + __pyx_v_i = (*__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_dem_array.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_dem_array.diminfo[1].strides)); + + /* "pygeoprocessing/geoprocessing_core.pyx":428 + * + * # a - c direction + * if a != dem_nodata and c != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += a - c + * x_denom_factor += 2 + */ + __pyx_t_5 = ((__pyx_v_a != __pyx_v_dem_nodata) != 0); + if (__pyx_t_5) { + } else { + __pyx_t_6 = __pyx_t_5; + goto __pyx_L20_bool_binop_done; + } + __pyx_t_5 = ((__pyx_v_c != __pyx_v_dem_nodata) != 0); + __pyx_t_6 = __pyx_t_5; + __pyx_L20_bool_binop_done:; + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":429 + * # a - c direction + * if a != dem_nodata and c != dem_nodata: + * dzdx_accumulator += a - c # <<<<<<<<<<<<<< + * x_denom_factor += 2 + * elif a != dem_nodata and b != dem_nodata: + */ + __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + (__pyx_v_a - __pyx_v_c)); + + /* "pygeoprocessing/geoprocessing_core.pyx":430 + * if a != dem_nodata and c != dem_nodata: + * dzdx_accumulator += a - c + * x_denom_factor += 2 # <<<<<<<<<<<<<< + * elif a != dem_nodata and b != dem_nodata: + * dzdx_accumulator += a - b + */ + __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 2); + + /* "pygeoprocessing/geoprocessing_core.pyx":428 + * + * # a - c direction + * if a != dem_nodata and c != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += a - c + * x_denom_factor += 2 + */ + goto __pyx_L19; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":431 + * dzdx_accumulator += a - c + * x_denom_factor += 2 + * elif a != dem_nodata and b != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += a - b + * x_denom_factor += 1 + */ + __pyx_t_5 = ((__pyx_v_a != __pyx_v_dem_nodata) != 0); + if (__pyx_t_5) { + } else { + __pyx_t_6 = __pyx_t_5; + goto __pyx_L22_bool_binop_done; + } + __pyx_t_5 = ((__pyx_v_b != __pyx_v_dem_nodata) != 0); + __pyx_t_6 = __pyx_t_5; + __pyx_L22_bool_binop_done:; + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":432 + * x_denom_factor += 2 + * elif a != dem_nodata and b != dem_nodata: + * dzdx_accumulator += a - b # <<<<<<<<<<<<<< + * x_denom_factor += 1 + * elif b != dem_nodata and c != dem_nodata: + */ + __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + (__pyx_v_a - __pyx_v_b)); + + /* "pygeoprocessing/geoprocessing_core.pyx":433 + * elif a != dem_nodata and b != dem_nodata: + * dzdx_accumulator += a - b + * x_denom_factor += 1 # <<<<<<<<<<<<<< + * elif b != dem_nodata and c != dem_nodata: + * dzdx_accumulator += b - c + */ + __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 1); + + /* "pygeoprocessing/geoprocessing_core.pyx":431 + * dzdx_accumulator += a - c + * x_denom_factor += 2 + * elif a != dem_nodata and b != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += a - b + * x_denom_factor += 1 + */ + goto __pyx_L19; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":434 + * dzdx_accumulator += a - b + * x_denom_factor += 1 + * elif b != dem_nodata and c != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += b - c + * x_denom_factor += 1 + */ + __pyx_t_5 = ((__pyx_v_b != __pyx_v_dem_nodata) != 0); + if (__pyx_t_5) { + } else { + __pyx_t_6 = __pyx_t_5; + goto __pyx_L24_bool_binop_done; + } + __pyx_t_5 = ((__pyx_v_c != __pyx_v_dem_nodata) != 0); + __pyx_t_6 = __pyx_t_5; + __pyx_L24_bool_binop_done:; + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":435 + * x_denom_factor += 1 + * elif b != dem_nodata and c != dem_nodata: + * dzdx_accumulator += b - c # <<<<<<<<<<<<<< + * x_denom_factor += 1 + * elif a != dem_nodata: + */ + __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + (__pyx_v_b - __pyx_v_c)); + + /* "pygeoprocessing/geoprocessing_core.pyx":436 + * elif b != dem_nodata and c != dem_nodata: + * dzdx_accumulator += b - c + * x_denom_factor += 1 # <<<<<<<<<<<<<< + * elif a != dem_nodata: + * dzdx_accumulator += (a - e) * 2**0.5 + */ + __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 1); + + /* "pygeoprocessing/geoprocessing_core.pyx":434 + * dzdx_accumulator += a - b + * x_denom_factor += 1 + * elif b != dem_nodata and c != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += b - c + * x_denom_factor += 1 + */ + goto __pyx_L19; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":437 + * dzdx_accumulator += b - c + * x_denom_factor += 1 + * elif a != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += (a - e) * 2**0.5 + * x_denom_factor += 1 + */ + __pyx_t_6 = ((__pyx_v_a != __pyx_v_dem_nodata) != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":438 + * x_denom_factor += 1 + * elif a != dem_nodata: + * dzdx_accumulator += (a - e) * 2**0.5 # <<<<<<<<<<<<<< + * x_denom_factor += 1 + * elif c != dem_nodata: + */ + __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + ((__pyx_v_a - __pyx_v_e) * pow(2.0, 0.5))); + + /* "pygeoprocessing/geoprocessing_core.pyx":439 + * elif a != dem_nodata: + * dzdx_accumulator += (a - e) * 2**0.5 + * x_denom_factor += 1 # <<<<<<<<<<<<<< + * elif c != dem_nodata: + * dzdx_accumulator += (e - c) * 2**0.5 + */ + __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 1); + + /* "pygeoprocessing/geoprocessing_core.pyx":437 + * dzdx_accumulator += b - c + * x_denom_factor += 1 + * elif a != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += (a - e) * 2**0.5 + * x_denom_factor += 1 + */ + goto __pyx_L19; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":440 + * dzdx_accumulator += (a - e) * 2**0.5 + * x_denom_factor += 1 + * elif c != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += (e - c) * 2**0.5 + * x_denom_factor += 1 + */ + __pyx_t_6 = ((__pyx_v_c != __pyx_v_dem_nodata) != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":441 + * x_denom_factor += 1 + * elif c != dem_nodata: + * dzdx_accumulator += (e - c) * 2**0.5 # <<<<<<<<<<<<<< + * x_denom_factor += 1 + * + */ + __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + ((__pyx_v_e - __pyx_v_c) * pow(2.0, 0.5))); + + /* "pygeoprocessing/geoprocessing_core.pyx":442 + * elif c != dem_nodata: + * dzdx_accumulator += (e - c) * 2**0.5 + * x_denom_factor += 1 # <<<<<<<<<<<<<< + * + * # d - f direction + */ + __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 1); + + /* "pygeoprocessing/geoprocessing_core.pyx":440 + * dzdx_accumulator += (a - e) * 2**0.5 + * x_denom_factor += 1 + * elif c != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += (e - c) * 2**0.5 + * x_denom_factor += 1 + */ + } + __pyx_L19:; + + /* "pygeoprocessing/geoprocessing_core.pyx":445 + * + * # d - f direction + * if d != dem_nodata and f != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += 2 * (d - f) + * x_denom_factor += 4 + */ + __pyx_t_5 = ((__pyx_v_d != __pyx_v_dem_nodata) != 0); + if (__pyx_t_5) { + } else { + __pyx_t_6 = __pyx_t_5; + goto __pyx_L27_bool_binop_done; + } + __pyx_t_5 = ((__pyx_v_f != __pyx_v_dem_nodata) != 0); + __pyx_t_6 = __pyx_t_5; + __pyx_L27_bool_binop_done:; + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":446 + * # d - f direction + * if d != dem_nodata and f != dem_nodata: + * dzdx_accumulator += 2 * (d - f) # <<<<<<<<<<<<<< + * x_denom_factor += 4 + * elif d != dem_nodata: + */ + __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + (2.0 * (__pyx_v_d - __pyx_v_f))); + + /* "pygeoprocessing/geoprocessing_core.pyx":447 + * if d != dem_nodata and f != dem_nodata: + * dzdx_accumulator += 2 * (d - f) + * x_denom_factor += 4 # <<<<<<<<<<<<<< + * elif d != dem_nodata: + * dzdx_accumulator += 2 * (d - e) + */ + __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 4); + + /* "pygeoprocessing/geoprocessing_core.pyx":445 + * + * # d - f direction + * if d != dem_nodata and f != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += 2 * (d - f) + * x_denom_factor += 4 + */ + goto __pyx_L26; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":448 + * dzdx_accumulator += 2 * (d - f) + * x_denom_factor += 4 + * elif d != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += 2 * (d - e) + * x_denom_factor += 2 + */ + __pyx_t_6 = ((__pyx_v_d != __pyx_v_dem_nodata) != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":449 + * x_denom_factor += 4 + * elif d != dem_nodata: + * dzdx_accumulator += 2 * (d - e) # <<<<<<<<<<<<<< + * x_denom_factor += 2 + * elif f != dem_nodata: + */ + __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + (2.0 * (__pyx_v_d - __pyx_v_e))); + + /* "pygeoprocessing/geoprocessing_core.pyx":450 + * elif d != dem_nodata: + * dzdx_accumulator += 2 * (d - e) + * x_denom_factor += 2 # <<<<<<<<<<<<<< + * elif f != dem_nodata: + * dzdx_accumulator += 2 * (e - f) + */ + __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 2); + + /* "pygeoprocessing/geoprocessing_core.pyx":448 + * dzdx_accumulator += 2 * (d - f) + * x_denom_factor += 4 + * elif d != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += 2 * (d - e) + * x_denom_factor += 2 + */ + goto __pyx_L26; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":451 + * dzdx_accumulator += 2 * (d - e) + * x_denom_factor += 2 + * elif f != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += 2 * (e - f) + * x_denom_factor += 2 + */ + __pyx_t_6 = ((__pyx_v_f != __pyx_v_dem_nodata) != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":452 + * x_denom_factor += 2 + * elif f != dem_nodata: + * dzdx_accumulator += 2 * (e - f) # <<<<<<<<<<<<<< + * x_denom_factor += 2 + * + */ + __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + (2.0 * (__pyx_v_e - __pyx_v_f))); + + /* "pygeoprocessing/geoprocessing_core.pyx":453 + * elif f != dem_nodata: + * dzdx_accumulator += 2 * (e - f) + * x_denom_factor += 2 # <<<<<<<<<<<<<< + * + * # g - i direction + */ + __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 2); + + /* "pygeoprocessing/geoprocessing_core.pyx":451 + * dzdx_accumulator += 2 * (d - e) + * x_denom_factor += 2 + * elif f != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += 2 * (e - f) + * x_denom_factor += 2 + */ + } + __pyx_L26:; + + /* "pygeoprocessing/geoprocessing_core.pyx":456 + * + * # g - i direction + * if g != dem_nodata and i != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += g - i + * x_denom_factor += 2 + */ + __pyx_t_5 = ((__pyx_v_g != __pyx_v_dem_nodata) != 0); + if (__pyx_t_5) { + } else { + __pyx_t_6 = __pyx_t_5; + goto __pyx_L30_bool_binop_done; + } + __pyx_t_5 = ((__pyx_v_i != __pyx_v_dem_nodata) != 0); + __pyx_t_6 = __pyx_t_5; + __pyx_L30_bool_binop_done:; + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":457 + * # g - i direction + * if g != dem_nodata and i != dem_nodata: + * dzdx_accumulator += g - i # <<<<<<<<<<<<<< + * x_denom_factor += 2 + * elif g != dem_nodata and h != dem_nodata: + */ + __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + (__pyx_v_g - __pyx_v_i)); + + /* "pygeoprocessing/geoprocessing_core.pyx":458 + * if g != dem_nodata and i != dem_nodata: + * dzdx_accumulator += g - i + * x_denom_factor += 2 # <<<<<<<<<<<<<< + * elif g != dem_nodata and h != dem_nodata: + * dzdx_accumulator += g - h + */ + __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 2); + + /* "pygeoprocessing/geoprocessing_core.pyx":456 + * + * # g - i direction + * if g != dem_nodata and i != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += g - i + * x_denom_factor += 2 + */ + goto __pyx_L29; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":459 + * dzdx_accumulator += g - i + * x_denom_factor += 2 + * elif g != dem_nodata and h != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += g - h + * x_denom_factor += 1 + */ + __pyx_t_5 = ((__pyx_v_g != __pyx_v_dem_nodata) != 0); + if (__pyx_t_5) { + } else { + __pyx_t_6 = __pyx_t_5; + goto __pyx_L32_bool_binop_done; + } + __pyx_t_5 = ((__pyx_v_h != __pyx_v_dem_nodata) != 0); + __pyx_t_6 = __pyx_t_5; + __pyx_L32_bool_binop_done:; + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":460 + * x_denom_factor += 2 + * elif g != dem_nodata and h != dem_nodata: + * dzdx_accumulator += g - h # <<<<<<<<<<<<<< + * x_denom_factor += 1 + * elif h != dem_nodata and i != dem_nodata: + */ + __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + (__pyx_v_g - __pyx_v_h)); + + /* "pygeoprocessing/geoprocessing_core.pyx":461 + * elif g != dem_nodata and h != dem_nodata: + * dzdx_accumulator += g - h + * x_denom_factor += 1 # <<<<<<<<<<<<<< + * elif h != dem_nodata and i != dem_nodata: + * dzdx_accumulator += h - i + */ + __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 1); + + /* "pygeoprocessing/geoprocessing_core.pyx":459 + * dzdx_accumulator += g - i + * x_denom_factor += 2 + * elif g != dem_nodata and h != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += g - h + * x_denom_factor += 1 + */ + goto __pyx_L29; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":462 + * dzdx_accumulator += g - h + * x_denom_factor += 1 + * elif h != dem_nodata and i != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += h - i + * x_denom_factor += 1 + */ + __pyx_t_5 = ((__pyx_v_h != __pyx_v_dem_nodata) != 0); + if (__pyx_t_5) { + } else { + __pyx_t_6 = __pyx_t_5; + goto __pyx_L34_bool_binop_done; + } + __pyx_t_5 = ((__pyx_v_i != __pyx_v_dem_nodata) != 0); + __pyx_t_6 = __pyx_t_5; + __pyx_L34_bool_binop_done:; + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":463 + * x_denom_factor += 1 + * elif h != dem_nodata and i != dem_nodata: + * dzdx_accumulator += h - i # <<<<<<<<<<<<<< + * x_denom_factor += 1 + * elif g != dem_nodata: + */ + __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + (__pyx_v_h - __pyx_v_i)); + + /* "pygeoprocessing/geoprocessing_core.pyx":464 + * elif h != dem_nodata and i != dem_nodata: + * dzdx_accumulator += h - i + * x_denom_factor += 1 # <<<<<<<<<<<<<< + * elif g != dem_nodata: + * dzdx_accumulator += (g - e) * 2**0.5 + */ + __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 1); + + /* "pygeoprocessing/geoprocessing_core.pyx":462 + * dzdx_accumulator += g - h + * x_denom_factor += 1 + * elif h != dem_nodata and i != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += h - i + * x_denom_factor += 1 + */ + goto __pyx_L29; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":465 + * dzdx_accumulator += h - i + * x_denom_factor += 1 + * elif g != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += (g - e) * 2**0.5 + * x_denom_factor += 1 + */ + __pyx_t_6 = ((__pyx_v_g != __pyx_v_dem_nodata) != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":466 + * x_denom_factor += 1 + * elif g != dem_nodata: + * dzdx_accumulator += (g - e) * 2**0.5 # <<<<<<<<<<<<<< + * x_denom_factor += 1 + * elif i != dem_nodata: + */ + __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + ((__pyx_v_g - __pyx_v_e) * pow(2.0, 0.5))); + + /* "pygeoprocessing/geoprocessing_core.pyx":467 + * elif g != dem_nodata: + * dzdx_accumulator += (g - e) * 2**0.5 + * x_denom_factor += 1 # <<<<<<<<<<<<<< + * elif i != dem_nodata: + * dzdx_accumulator += (e - i) * 2**0.5 + */ + __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 1); + + /* "pygeoprocessing/geoprocessing_core.pyx":465 + * dzdx_accumulator += h - i + * x_denom_factor += 1 + * elif g != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += (g - e) * 2**0.5 + * x_denom_factor += 1 + */ + goto __pyx_L29; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":468 + * dzdx_accumulator += (g - e) * 2**0.5 + * x_denom_factor += 1 + * elif i != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += (e - i) * 2**0.5 + * x_denom_factor += 1 + */ + __pyx_t_6 = ((__pyx_v_i != __pyx_v_dem_nodata) != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":469 + * x_denom_factor += 1 + * elif i != dem_nodata: + * dzdx_accumulator += (e - i) * 2**0.5 # <<<<<<<<<<<<<< + * x_denom_factor += 1 + * + */ + __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + ((__pyx_v_e - __pyx_v_i) * pow(2.0, 0.5))); + + /* "pygeoprocessing/geoprocessing_core.pyx":470 + * elif i != dem_nodata: + * dzdx_accumulator += (e - i) * 2**0.5 + * x_denom_factor += 1 # <<<<<<<<<<<<<< + * + * # a - g direction + */ + __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 1); + + /* "pygeoprocessing/geoprocessing_core.pyx":468 + * dzdx_accumulator += (g - e) * 2**0.5 + * x_denom_factor += 1 + * elif i != dem_nodata: # <<<<<<<<<<<<<< + * dzdx_accumulator += (e - i) * 2**0.5 + * x_denom_factor += 1 + */ + } + __pyx_L29:; + + /* "pygeoprocessing/geoprocessing_core.pyx":473 + * + * # a - g direction + * if a != dem_nodata and g != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += a - g + * y_denom_factor += 2 + */ + __pyx_t_5 = ((__pyx_v_a != __pyx_v_dem_nodata) != 0); + if (__pyx_t_5) { + } else { + __pyx_t_6 = __pyx_t_5; + goto __pyx_L37_bool_binop_done; + } + __pyx_t_5 = ((__pyx_v_g != __pyx_v_dem_nodata) != 0); + __pyx_t_6 = __pyx_t_5; + __pyx_L37_bool_binop_done:; + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":474 + * # a - g direction + * if a != dem_nodata and g != dem_nodata: + * dzdy_accumulator += a - g # <<<<<<<<<<<<<< + * y_denom_factor += 2 + * elif a != dem_nodata and d != dem_nodata: + */ + __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + (__pyx_v_a - __pyx_v_g)); + + /* "pygeoprocessing/geoprocessing_core.pyx":475 + * if a != dem_nodata and g != dem_nodata: + * dzdy_accumulator += a - g + * y_denom_factor += 2 # <<<<<<<<<<<<<< + * elif a != dem_nodata and d != dem_nodata: + * dzdy_accumulator += a - d + */ + __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 2); + + /* "pygeoprocessing/geoprocessing_core.pyx":473 + * + * # a - g direction + * if a != dem_nodata and g != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += a - g + * y_denom_factor += 2 + */ + goto __pyx_L36; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":476 + * dzdy_accumulator += a - g + * y_denom_factor += 2 + * elif a != dem_nodata and d != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += a - d + * y_denom_factor += 1 + */ + __pyx_t_5 = ((__pyx_v_a != __pyx_v_dem_nodata) != 0); + if (__pyx_t_5) { + } else { + __pyx_t_6 = __pyx_t_5; + goto __pyx_L39_bool_binop_done; + } + __pyx_t_5 = ((__pyx_v_d != __pyx_v_dem_nodata) != 0); + __pyx_t_6 = __pyx_t_5; + __pyx_L39_bool_binop_done:; + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":477 + * y_denom_factor += 2 + * elif a != dem_nodata and d != dem_nodata: + * dzdy_accumulator += a - d # <<<<<<<<<<<<<< + * y_denom_factor += 1 + * elif d != dem_nodata and g != dem_nodata: + */ + __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + (__pyx_v_a - __pyx_v_d)); + + /* "pygeoprocessing/geoprocessing_core.pyx":478 + * elif a != dem_nodata and d != dem_nodata: + * dzdy_accumulator += a - d + * y_denom_factor += 1 # <<<<<<<<<<<<<< + * elif d != dem_nodata and g != dem_nodata: + * dzdy_accumulator += d - g + */ + __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 1); + + /* "pygeoprocessing/geoprocessing_core.pyx":476 + * dzdy_accumulator += a - g + * y_denom_factor += 2 + * elif a != dem_nodata and d != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += a - d + * y_denom_factor += 1 + */ + goto __pyx_L36; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":479 + * dzdy_accumulator += a - d + * y_denom_factor += 1 + * elif d != dem_nodata and g != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += d - g + * y_denom_factor += 1 + */ + __pyx_t_5 = ((__pyx_v_d != __pyx_v_dem_nodata) != 0); + if (__pyx_t_5) { + } else { + __pyx_t_6 = __pyx_t_5; + goto __pyx_L41_bool_binop_done; + } + __pyx_t_5 = ((__pyx_v_g != __pyx_v_dem_nodata) != 0); + __pyx_t_6 = __pyx_t_5; + __pyx_L41_bool_binop_done:; + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":480 + * y_denom_factor += 1 + * elif d != dem_nodata and g != dem_nodata: + * dzdy_accumulator += d - g # <<<<<<<<<<<<<< + * y_denom_factor += 1 + * elif a != dem_nodata: + */ + __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + (__pyx_v_d - __pyx_v_g)); + + /* "pygeoprocessing/geoprocessing_core.pyx":481 + * elif d != dem_nodata and g != dem_nodata: + * dzdy_accumulator += d - g + * y_denom_factor += 1 # <<<<<<<<<<<<<< + * elif a != dem_nodata: + * dzdy_accumulator += (a - e) * 2**0.5 + */ + __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 1); + + /* "pygeoprocessing/geoprocessing_core.pyx":479 + * dzdy_accumulator += a - d + * y_denom_factor += 1 + * elif d != dem_nodata and g != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += d - g + * y_denom_factor += 1 + */ + goto __pyx_L36; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":482 + * dzdy_accumulator += d - g + * y_denom_factor += 1 + * elif a != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += (a - e) * 2**0.5 + * y_denom_factor += 1 + */ + __pyx_t_6 = ((__pyx_v_a != __pyx_v_dem_nodata) != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":483 + * y_denom_factor += 1 + * elif a != dem_nodata: + * dzdy_accumulator += (a - e) * 2**0.5 # <<<<<<<<<<<<<< + * y_denom_factor += 1 + * elif g != dem_nodata: + */ + __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + ((__pyx_v_a - __pyx_v_e) * pow(2.0, 0.5))); + + /* "pygeoprocessing/geoprocessing_core.pyx":484 + * elif a != dem_nodata: + * dzdy_accumulator += (a - e) * 2**0.5 + * y_denom_factor += 1 # <<<<<<<<<<<<<< + * elif g != dem_nodata: + * dzdy_accumulator += (e - g) * 2**0.5 + */ + __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 1); + + /* "pygeoprocessing/geoprocessing_core.pyx":482 + * dzdy_accumulator += d - g + * y_denom_factor += 1 + * elif a != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += (a - e) * 2**0.5 + * y_denom_factor += 1 + */ + goto __pyx_L36; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":485 + * dzdy_accumulator += (a - e) * 2**0.5 + * y_denom_factor += 1 + * elif g != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += (e - g) * 2**0.5 + * y_denom_factor += 1 + */ + __pyx_t_6 = ((__pyx_v_g != __pyx_v_dem_nodata) != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":486 + * y_denom_factor += 1 + * elif g != dem_nodata: + * dzdy_accumulator += (e - g) * 2**0.5 # <<<<<<<<<<<<<< + * y_denom_factor += 1 + * + */ + __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + ((__pyx_v_e - __pyx_v_g) * pow(2.0, 0.5))); + + /* "pygeoprocessing/geoprocessing_core.pyx":487 + * elif g != dem_nodata: + * dzdy_accumulator += (e - g) * 2**0.5 + * y_denom_factor += 1 # <<<<<<<<<<<<<< + * + * # b - h direction + */ + __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 1); + + /* "pygeoprocessing/geoprocessing_core.pyx":485 + * dzdy_accumulator += (a - e) * 2**0.5 + * y_denom_factor += 1 + * elif g != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += (e - g) * 2**0.5 + * y_denom_factor += 1 + */ + } + __pyx_L36:; + + /* "pygeoprocessing/geoprocessing_core.pyx":490 + * + * # b - h direction + * if b != dem_nodata and h != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += 2 * (b - h) + * y_denom_factor += 4 + */ + __pyx_t_5 = ((__pyx_v_b != __pyx_v_dem_nodata) != 0); + if (__pyx_t_5) { + } else { + __pyx_t_6 = __pyx_t_5; + goto __pyx_L44_bool_binop_done; + } + __pyx_t_5 = ((__pyx_v_h != __pyx_v_dem_nodata) != 0); + __pyx_t_6 = __pyx_t_5; + __pyx_L44_bool_binop_done:; + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":491 + * # b - h direction + * if b != dem_nodata and h != dem_nodata: + * dzdy_accumulator += 2 * (b - h) # <<<<<<<<<<<<<< + * y_denom_factor += 4 + * elif b != dem_nodata: + */ + __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + (2.0 * (__pyx_v_b - __pyx_v_h))); + + /* "pygeoprocessing/geoprocessing_core.pyx":492 + * if b != dem_nodata and h != dem_nodata: + * dzdy_accumulator += 2 * (b - h) + * y_denom_factor += 4 # <<<<<<<<<<<<<< + * elif b != dem_nodata: + * dzdy_accumulator += 2 * (b - e) + */ + __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 4); + + /* "pygeoprocessing/geoprocessing_core.pyx":490 + * + * # b - h direction + * if b != dem_nodata and h != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += 2 * (b - h) + * y_denom_factor += 4 + */ + goto __pyx_L43; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":493 + * dzdy_accumulator += 2 * (b - h) + * y_denom_factor += 4 + * elif b != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += 2 * (b - e) + * y_denom_factor += 2 + */ + __pyx_t_6 = ((__pyx_v_b != __pyx_v_dem_nodata) != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":494 + * y_denom_factor += 4 + * elif b != dem_nodata: + * dzdy_accumulator += 2 * (b - e) # <<<<<<<<<<<<<< + * y_denom_factor += 2 + * elif h != dem_nodata: + */ + __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + (2.0 * (__pyx_v_b - __pyx_v_e))); + + /* "pygeoprocessing/geoprocessing_core.pyx":495 + * elif b != dem_nodata: + * dzdy_accumulator += 2 * (b - e) + * y_denom_factor += 2 # <<<<<<<<<<<<<< + * elif h != dem_nodata: + * dzdy_accumulator += 2 * (e - h) + */ + __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 2); + + /* "pygeoprocessing/geoprocessing_core.pyx":493 + * dzdy_accumulator += 2 * (b - h) + * y_denom_factor += 4 + * elif b != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += 2 * (b - e) + * y_denom_factor += 2 + */ + goto __pyx_L43; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":496 + * dzdy_accumulator += 2 * (b - e) + * y_denom_factor += 2 + * elif h != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += 2 * (e - h) + * y_denom_factor += 2 + */ + __pyx_t_6 = ((__pyx_v_h != __pyx_v_dem_nodata) != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":497 + * y_denom_factor += 2 + * elif h != dem_nodata: + * dzdy_accumulator += 2 * (e - h) # <<<<<<<<<<<<<< + * y_denom_factor += 2 + * + */ + __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + (2.0 * (__pyx_v_e - __pyx_v_h))); + + /* "pygeoprocessing/geoprocessing_core.pyx":498 + * elif h != dem_nodata: + * dzdy_accumulator += 2 * (e - h) + * y_denom_factor += 2 # <<<<<<<<<<<<<< + * + * # c - i direction + */ + __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 2); + + /* "pygeoprocessing/geoprocessing_core.pyx":496 + * dzdy_accumulator += 2 * (b - e) + * y_denom_factor += 2 + * elif h != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += 2 * (e - h) + * y_denom_factor += 2 + */ + } + __pyx_L43:; + + /* "pygeoprocessing/geoprocessing_core.pyx":501 + * + * # c - i direction + * if c != dem_nodata and i != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += c - i + * y_denom_factor += 2 + */ + __pyx_t_5 = ((__pyx_v_c != __pyx_v_dem_nodata) != 0); + if (__pyx_t_5) { + } else { + __pyx_t_6 = __pyx_t_5; + goto __pyx_L47_bool_binop_done; + } + __pyx_t_5 = ((__pyx_v_i != __pyx_v_dem_nodata) != 0); + __pyx_t_6 = __pyx_t_5; + __pyx_L47_bool_binop_done:; + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":502 + * # c - i direction + * if c != dem_nodata and i != dem_nodata: + * dzdy_accumulator += c - i # <<<<<<<<<<<<<< + * y_denom_factor += 2 + * elif c != dem_nodata and f != dem_nodata: + */ + __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + (__pyx_v_c - __pyx_v_i)); + + /* "pygeoprocessing/geoprocessing_core.pyx":503 + * if c != dem_nodata and i != dem_nodata: + * dzdy_accumulator += c - i + * y_denom_factor += 2 # <<<<<<<<<<<<<< + * elif c != dem_nodata and f != dem_nodata: + * dzdy_accumulator += c - f + */ + __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 2); + + /* "pygeoprocessing/geoprocessing_core.pyx":501 + * + * # c - i direction + * if c != dem_nodata and i != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += c - i + * y_denom_factor += 2 + */ + goto __pyx_L46; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":504 + * dzdy_accumulator += c - i + * y_denom_factor += 2 + * elif c != dem_nodata and f != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += c - f + * y_denom_factor += 1 + */ + __pyx_t_5 = ((__pyx_v_c != __pyx_v_dem_nodata) != 0); + if (__pyx_t_5) { + } else { + __pyx_t_6 = __pyx_t_5; + goto __pyx_L49_bool_binop_done; + } + __pyx_t_5 = ((__pyx_v_f != __pyx_v_dem_nodata) != 0); + __pyx_t_6 = __pyx_t_5; + __pyx_L49_bool_binop_done:; + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":505 + * y_denom_factor += 2 + * elif c != dem_nodata and f != dem_nodata: + * dzdy_accumulator += c - f # <<<<<<<<<<<<<< + * y_denom_factor += 1 + * elif f != dem_nodata and i != dem_nodata: + */ + __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + (__pyx_v_c - __pyx_v_f)); + + /* "pygeoprocessing/geoprocessing_core.pyx":506 + * elif c != dem_nodata and f != dem_nodata: + * dzdy_accumulator += c - f + * y_denom_factor += 1 # <<<<<<<<<<<<<< + * elif f != dem_nodata and i != dem_nodata: + * dzdy_accumulator += f - i + */ + __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 1); + + /* "pygeoprocessing/geoprocessing_core.pyx":504 + * dzdy_accumulator += c - i + * y_denom_factor += 2 + * elif c != dem_nodata and f != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += c - f + * y_denom_factor += 1 + */ + goto __pyx_L46; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":507 + * dzdy_accumulator += c - f + * y_denom_factor += 1 + * elif f != dem_nodata and i != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += f - i + * y_denom_factor += 1 + */ + __pyx_t_5 = ((__pyx_v_f != __pyx_v_dem_nodata) != 0); + if (__pyx_t_5) { + } else { + __pyx_t_6 = __pyx_t_5; + goto __pyx_L51_bool_binop_done; + } + __pyx_t_5 = ((__pyx_v_i != __pyx_v_dem_nodata) != 0); + __pyx_t_6 = __pyx_t_5; + __pyx_L51_bool_binop_done:; + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":508 + * y_denom_factor += 1 + * elif f != dem_nodata and i != dem_nodata: + * dzdy_accumulator += f - i # <<<<<<<<<<<<<< + * y_denom_factor += 1 + * elif c != dem_nodata: + */ + __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + (__pyx_v_f - __pyx_v_i)); + + /* "pygeoprocessing/geoprocessing_core.pyx":509 + * elif f != dem_nodata and i != dem_nodata: + * dzdy_accumulator += f - i + * y_denom_factor += 1 # <<<<<<<<<<<<<< + * elif c != dem_nodata: + * dzdy_accumulator += (c - e) * 2**0.5 + */ + __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 1); + + /* "pygeoprocessing/geoprocessing_core.pyx":507 + * dzdy_accumulator += c - f + * y_denom_factor += 1 + * elif f != dem_nodata and i != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += f - i + * y_denom_factor += 1 + */ + goto __pyx_L46; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":510 + * dzdy_accumulator += f - i + * y_denom_factor += 1 + * elif c != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += (c - e) * 2**0.5 + * y_denom_factor += 1 + */ + __pyx_t_6 = ((__pyx_v_c != __pyx_v_dem_nodata) != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":511 + * y_denom_factor += 1 + * elif c != dem_nodata: + * dzdy_accumulator += (c - e) * 2**0.5 # <<<<<<<<<<<<<< + * y_denom_factor += 1 + * elif i != dem_nodata: + */ + __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + ((__pyx_v_c - __pyx_v_e) * pow(2.0, 0.5))); + + /* "pygeoprocessing/geoprocessing_core.pyx":512 + * elif c != dem_nodata: + * dzdy_accumulator += (c - e) * 2**0.5 + * y_denom_factor += 1 # <<<<<<<<<<<<<< + * elif i != dem_nodata: + * dzdy_accumulator += (e - i) * 2**0.5 + */ + __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 1); + + /* "pygeoprocessing/geoprocessing_core.pyx":510 + * dzdy_accumulator += f - i + * y_denom_factor += 1 + * elif c != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += (c - e) * 2**0.5 + * y_denom_factor += 1 + */ + goto __pyx_L46; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":513 + * dzdy_accumulator += (c - e) * 2**0.5 + * y_denom_factor += 1 + * elif i != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += (e - i) * 2**0.5 + * y_denom_factor += 1 + */ + __pyx_t_6 = ((__pyx_v_i != __pyx_v_dem_nodata) != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":514 + * y_denom_factor += 1 + * elif i != dem_nodata: + * dzdy_accumulator += (e - i) * 2**0.5 # <<<<<<<<<<<<<< + * y_denom_factor += 1 + * + */ + __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + ((__pyx_v_e - __pyx_v_i) * pow(2.0, 0.5))); + + /* "pygeoprocessing/geoprocessing_core.pyx":515 + * elif i != dem_nodata: + * dzdy_accumulator += (e - i) * 2**0.5 + * y_denom_factor += 1 # <<<<<<<<<<<<<< + * + * if x_denom_factor != 0: + */ + __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 1); + + /* "pygeoprocessing/geoprocessing_core.pyx":513 + * dzdy_accumulator += (c - e) * 2**0.5 + * y_denom_factor += 1 + * elif i != dem_nodata: # <<<<<<<<<<<<<< + * dzdy_accumulator += (e - i) * 2**0.5 + * y_denom_factor += 1 + */ + } + __pyx_L46:; + + /* "pygeoprocessing/geoprocessing_core.pyx":517 + * y_denom_factor += 1 + * + * if x_denom_factor != 0: # <<<<<<<<<<<<<< + * dzdx_array[row_index-1, col_index-1] = ( + * dzdx_accumulator / (x_denom_factor * x_cell_size)) + */ + __pyx_t_6 = ((__pyx_v_x_denom_factor != 0) != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":518 + * + * if x_denom_factor != 0: + * dzdx_array[row_index-1, col_index-1] = ( # <<<<<<<<<<<<<< + * dzdx_accumulator / (x_denom_factor * x_cell_size)) + * else: + */ + __pyx_t_29 = (__pyx_v_row_index - 1); + __pyx_t_30 = (__pyx_v_col_index - 1); + *__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_dzdx_array.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_dzdx_array.diminfo[1].strides) = (__pyx_v_dzdx_accumulator / (__pyx_v_x_denom_factor * __pyx_v_x_cell_size)); + + /* "pygeoprocessing/geoprocessing_core.pyx":517 + * y_denom_factor += 1 + * + * if x_denom_factor != 0: # <<<<<<<<<<<<<< + * dzdx_array[row_index-1, col_index-1] = ( + * dzdx_accumulator / (x_denom_factor * x_cell_size)) + */ + goto __pyx_L53; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":521 + * dzdx_accumulator / (x_denom_factor * x_cell_size)) + * else: + * dzdx_array[row_index-1, col_index-1] = 0.0 # <<<<<<<<<<<<<< + * if y_denom_factor != 0: + * dzdy_array[row_index-1, col_index-1] = ( + */ + /*else*/ { + __pyx_t_30 = (__pyx_v_row_index - 1); + __pyx_t_29 = (__pyx_v_col_index - 1); + *__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_dzdx_array.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_dzdx_array.diminfo[1].strides) = 0.0; + } + __pyx_L53:; + + /* "pygeoprocessing/geoprocessing_core.pyx":522 + * else: + * dzdx_array[row_index-1, col_index-1] = 0.0 + * if y_denom_factor != 0: # <<<<<<<<<<<<<< + * dzdy_array[row_index-1, col_index-1] = ( + * dzdy_accumulator / (y_denom_factor * y_cell_size)) + */ + __pyx_t_6 = ((__pyx_v_y_denom_factor != 0) != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":523 + * dzdx_array[row_index-1, col_index-1] = 0.0 + * if y_denom_factor != 0: + * dzdy_array[row_index-1, col_index-1] = ( # <<<<<<<<<<<<<< + * dzdy_accumulator / (y_denom_factor * y_cell_size)) + * else: + */ + __pyx_t_29 = (__pyx_v_row_index - 1); + __pyx_t_30 = (__pyx_v_col_index - 1); + *__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dzdy_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_dzdy_array.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_dzdy_array.diminfo[1].strides) = (__pyx_v_dzdy_accumulator / (__pyx_v_y_denom_factor * __pyx_v_y_cell_size)); + + /* "pygeoprocessing/geoprocessing_core.pyx":522 + * else: + * dzdx_array[row_index-1, col_index-1] = 0.0 + * if y_denom_factor != 0: # <<<<<<<<<<<<<< + * dzdy_array[row_index-1, col_index-1] = ( + * dzdy_accumulator / (y_denom_factor * y_cell_size)) + */ + goto __pyx_L54; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":526 + * dzdy_accumulator / (y_denom_factor * y_cell_size)) + * else: + * dzdy_array[row_index-1, col_index-1] = 0.0 # <<<<<<<<<<<<<< + * valid_mask = dzdx_array != slope_nodata + * slope_array[:] = slope_nodata + */ + /*else*/ { + __pyx_t_30 = (__pyx_v_row_index - 1); + __pyx_t_29 = (__pyx_v_col_index - 1); + *__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dzdy_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_dzdy_array.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_dzdy_array.diminfo[1].strides) = 0.0; + } + __pyx_L54:; + __pyx_L16_continue:; + } + } + + /* "pygeoprocessing/geoprocessing_core.pyx":527 + * else: + * dzdy_array[row_index-1, col_index-1] = 0.0 + * valid_mask = dzdx_array != slope_nodata # <<<<<<<<<<<<<< + * slope_array[:] = slope_nodata + * # multiply by 100 for percent output + */ + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_slope_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 527, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_RichCompare(((PyObject *)__pyx_v_dzdx_array), __pyx_t_1, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 527, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_valid_mask, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":528 + * dzdy_array[row_index-1, col_index-1] = 0.0 + * valid_mask = dzdx_array != slope_nodata + * slope_array[:] = slope_nodata # <<<<<<<<<<<<<< + * # multiply by 100 for percent output + * slope_array[valid_mask] = 100.0 * numpy.sqrt( + */ + __pyx_t_2 = PyFloat_FromDouble(__pyx_v_slope_nodata); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 528, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_slope_array), __pyx_slice_, __pyx_t_2) < 0)) __PYX_ERR(0, 528, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":530 + * slope_array[:] = slope_nodata + * # multiply by 100 for percent output + * slope_array[valid_mask] = 100.0 * numpy.sqrt( # <<<<<<<<<<<<<< + * dzdx_array[valid_mask]**2 + dzdy_array[valid_mask]**2) + * target_slope_band.WriteArray( + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 530, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_sqrt); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 530, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":531 + * # multiply by 100 for percent output + * slope_array[valid_mask] = 100.0 * numpy.sqrt( + * dzdx_array[valid_mask]**2 + dzdy_array[valid_mask]**2) # <<<<<<<<<<<<<< + * target_slope_band.WriteArray( + * slope_array, xoff=block_offset['xoff'], + */ + __pyx_t_1 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_dzdx_array), __pyx_v_valid_mask); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 531, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_16 = PyNumber_Power(__pyx_t_1, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 531, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_dzdy_array), __pyx_v_valid_mask); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 531, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_24 = PyNumber_Power(__pyx_t_1, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 531, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_24); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Add(__pyx_t_16, __pyx_t_24); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 531, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; + __pyx_t_24 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_24 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_24)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_24); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_2 = (__pyx_t_24) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_24, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1); + __Pyx_XDECREF(__pyx_t_24); __pyx_t_24 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 530, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":530 + * slope_array[:] = slope_nodata + * # multiply by 100 for percent output + * slope_array[valid_mask] = 100.0 * numpy.sqrt( # <<<<<<<<<<<<<< + * dzdx_array[valid_mask]**2 + dzdy_array[valid_mask]**2) + * target_slope_band.WriteArray( + */ + __pyx_t_3 = PyNumber_Multiply(__pyx_float_100_0, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 530, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_slope_array), __pyx_v_valid_mask, __pyx_t_3) < 0)) __PYX_ERR(0, 530, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":532 + * slope_array[valid_mask] = 100.0 * numpy.sqrt( + * dzdx_array[valid_mask]**2 + dzdy_array[valid_mask]**2) + * target_slope_band.WriteArray( # <<<<<<<<<<<<<< + * slope_array, xoff=block_offset['xoff'], + * yoff=block_offset['yoff']) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_target_slope_band, __pyx_n_s_WriteArray); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 532, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + + /* "pygeoprocessing/geoprocessing_core.pyx":533 + * dzdx_array[valid_mask]**2 + dzdy_array[valid_mask]**2) + * target_slope_band.WriteArray( + * slope_array, xoff=block_offset['xoff'], # <<<<<<<<<<<<<< + * yoff=block_offset['yoff']) + * + */ + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 532, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_v_slope_array)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_slope_array)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_slope_array)); + __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 533, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_24 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset, __pyx_n_u_xoff); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 533, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_24); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_xoff, __pyx_t_24) < 0) __PYX_ERR(0, 533, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":534 + * target_slope_band.WriteArray( + * slope_array, xoff=block_offset['xoff'], + * yoff=block_offset['yoff']) # <<<<<<<<<<<<<< + * + * dem_band = None + */ + __pyx_t_24 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset, __pyx_n_u_yoff); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 534, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_24); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_yoff, __pyx_t_24) < 0) __PYX_ERR(0, 533, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":532 + * slope_array[valid_mask] = 100.0 * numpy.sqrt( + * dzdx_array[valid_mask]**2 + dzdy_array[valid_mask]**2) + * target_slope_band.WriteArray( # <<<<<<<<<<<<<< + * slope_array, xoff=block_offset['xoff'], + * yoff=block_offset['yoff']) + */ + __pyx_t_24 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 532, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_24); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":358 + * target_slope_band = target_slope_raster.GetRasterBand(1) + * + * for block_offset in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * base_elevation_raster_path_band, offset_only=True): + * block_offset_copy = block_offset.copy() + */ + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":536 + * yoff=block_offset['yoff']) + * + * dem_band = None # <<<<<<<<<<<<<< + * target_slope_band = None + * dem_raster = None + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_dem_band, Py_None); + + /* "pygeoprocessing/geoprocessing_core.pyx":537 + * + * dem_band = None + * target_slope_band = None # <<<<<<<<<<<<<< + * dem_raster = None + * target_slope_raster = None + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_target_slope_band, Py_None); + + /* "pygeoprocessing/geoprocessing_core.pyx":538 + * dem_band = None + * target_slope_band = None + * dem_raster = None # <<<<<<<<<<<<<< + * target_slope_raster = None + * + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_dem_raster, Py_None); + + /* "pygeoprocessing/geoprocessing_core.pyx":539 + * target_slope_band = None + * dem_raster = None + * target_slope_raster = None # <<<<<<<<<<<<<< + * + * + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_target_slope_raster, Py_None); + + /* "pygeoprocessing/geoprocessing_core.pyx":287 + * @cython.nonecheck(False) + * @cython.cdivision(True) + * def calculate_slope( # <<<<<<<<<<<<<< + * base_elevation_raster_path_band, target_slope_path, + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_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_12); + __Pyx_XDECREF(__pyx_t_15); + __Pyx_XDECREF(__pyx_t_16); + __Pyx_XDECREF(__pyx_t_24); + { 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_array.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dzdy_array.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_slope_array.rcbuffer->pybuffer); + __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} + __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core.calculate_slope", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + goto __pyx_L2; + __pyx_L0:; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dem_array.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dzdy_array.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_slope_array.rcbuffer->pybuffer); + __pyx_L2:; + __Pyx_XDECREF((PyObject *)__pyx_v_dem_array); + __Pyx_XDECREF((PyObject *)__pyx_v_slope_array); + __Pyx_XDECREF((PyObject *)__pyx_v_dzdx_array); + __Pyx_XDECREF((PyObject *)__pyx_v_dzdy_array); + __Pyx_XDECREF(__pyx_v_dem_raster); + __Pyx_XDECREF(__pyx_v_dem_band); + __Pyx_XDECREF(__pyx_v_dem_info); + __Pyx_XDECREF(__pyx_v_raw_nodata); + __Pyx_XDECREF(__pyx_v_target_slope_raster); + __Pyx_XDECREF(__pyx_v_target_slope_band); + __Pyx_XDECREF(__pyx_v_block_offset); + __Pyx_XDECREF(__pyx_v_block_offset_copy); + __Pyx_XDECREF(__pyx_v_x_start); + __Pyx_XDECREF(__pyx_v_x_end); + __Pyx_XDECREF(__pyx_v_y_start); + __Pyx_XDECREF(__pyx_v_y_end); + __Pyx_XDECREF(__pyx_v_valid_mask); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pygeoprocessing/geoprocessing_core.pyx":544 + * @cython.boundscheck(False) + * @cython.cdivision(True) + * def stats_worker(stats_work_queue, expected_blocks): # <<<<<<<<<<<<<< + * """Worker to calculate continuous min, max, mean and standard deviation. + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_5stats_worker(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_15pygeoprocessing_18geoprocessing_core_4stats_worker[] = "Worker to calculate continuous min, max, mean and standard deviation.\n\n Parameters:\n stats_work_queue (Queue): a queue of 1D numpy arrays or None. If\n None, function puts a (min, max, mean, stddev) tuple to the\n queue and quits.\n expected_blocks (int): number of expected payloads through\n ``stats_work_queue``. Will terminate after this many.\n\n Returns:\n None\n\n "; +static PyMethodDef __pyx_mdef_15pygeoprocessing_18geoprocessing_core_5stats_worker = {"stats_worker", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_18geoprocessing_core_5stats_worker, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_18geoprocessing_core_4stats_worker}; +static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_5stats_worker(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_stats_work_queue = 0; + PyObject *__pyx_v_expected_blocks = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("stats_worker (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_stats_work_queue,&__pyx_n_s_expected_blocks,0}; + PyObject* values[2] = {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 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_stats_work_queue)) != 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_expected_blocks)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("stats_worker", 1, 2, 2, 1); __PYX_ERR(0, 544, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "stats_worker") < 0)) __PYX_ERR(0, 544, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_stats_work_queue = values[0]; + __pyx_v_expected_blocks = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("stats_worker", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 544, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core.stats_worker", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_15pygeoprocessing_18geoprocessing_core_4stats_worker(__pyx_self, __pyx_v_stats_work_queue, __pyx_v_expected_blocks); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core_4stats_worker(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_stats_work_queue, PyObject *__pyx_v_expected_blocks) { + PyArrayObject *__pyx_v_block = 0; + double __pyx_v_M_local; + double __pyx_v_S_local; + double __pyx_v_min_value; + double __pyx_v_max_value; + double __pyx_v_x; + int __pyx_v_i; + int __pyx_v_n_elements; + PY_LONG_LONG __pyx_v_n; + PyObject *__pyx_v_payload = NULL; + CYTHON_UNUSED PyObject *__pyx_v_index = NULL; + PyObject *__pyx_v_existing_shm = NULL; + PyObject *__pyx_v_shape = NULL; + PyObject *__pyx_v_dtype = NULL; + double __pyx_v_M_last; + CYTHON_UNUSED PyObject *__pyx_v_e = NULL; + __Pyx_LocalBuf_ND __pyx_pybuffernd_block; + __Pyx_Buffer __pyx_pybuffer_block; + 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; + Py_ssize_t __pyx_t_6; + PyObject *(*__pyx_t_7)(PyObject *); + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + int __pyx_t_11; + int __pyx_t_12; + int __pyx_t_13; + PyObject *__pyx_t_14 = NULL; + PyObject *__pyx_t_15 = NULL; + PyObject *__pyx_t_16 = NULL; + PyObject *(*__pyx_t_17)(PyObject *); + int __pyx_t_18; + int __pyx_t_19; + Py_ssize_t __pyx_t_20; + PyObject *__pyx_t_21 = NULL; + PyObject *__pyx_t_22 = NULL; + PyObject *__pyx_t_23 = NULL; + PyObject *__pyx_t_24 = NULL; + PyObject *__pyx_t_25 = NULL; + PyObject *__pyx_t_26 = NULL; + PyObject *__pyx_t_27 = NULL; + char const *__pyx_t_28; + PyObject *__pyx_t_29 = NULL; + PyObject *__pyx_t_30 = NULL; + PyObject *__pyx_t_31 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("stats_worker", 0); + __pyx_pybuffer_block.pybuffer.buf = NULL; + __pyx_pybuffer_block.refcount = 0; + __pyx_pybuffernd_block.data = NULL; + __pyx_pybuffernd_block.rcbuffer = &__pyx_pybuffer_block; + + /* "pygeoprocessing/geoprocessing_core.pyx":558 + * + * """ + * LOGGER.debug(f'stats worker PID: {os.getpid()}') # <<<<<<<<<<<<<< + * cdef numpy.ndarray[numpy.float64_t, ndim=1] block + * cdef double M_local = 0.0 + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 558, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_debug); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 558, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_os); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 558, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_getpid); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 558, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __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); + } + } + __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 558, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_FormatSimple(__pyx_t_2, __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 558, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyUnicode_Concat(__pyx_kp_u_stats_worker_PID, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 558, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + 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_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 558, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":560 + * LOGGER.debug(f'stats worker PID: {os.getpid()}') + * cdef numpy.ndarray[numpy.float64_t, ndim=1] block + * cdef double M_local = 0.0 # <<<<<<<<<<<<<< + * cdef double S_local = 0.0 + * cdef double min_value = 0.0 + */ + __pyx_v_M_local = 0.0; + + /* "pygeoprocessing/geoprocessing_core.pyx":561 + * cdef numpy.ndarray[numpy.float64_t, ndim=1] block + * cdef double M_local = 0.0 + * cdef double S_local = 0.0 # <<<<<<<<<<<<<< + * cdef double min_value = 0.0 + * cdef double max_value = 0.0 + */ + __pyx_v_S_local = 0.0; + + /* "pygeoprocessing/geoprocessing_core.pyx":562 + * cdef double M_local = 0.0 + * cdef double S_local = 0.0 + * cdef double min_value = 0.0 # <<<<<<<<<<<<<< + * cdef double max_value = 0.0 + * cdef double x = 0.0 + */ + __pyx_v_min_value = 0.0; + + /* "pygeoprocessing/geoprocessing_core.pyx":563 + * cdef double S_local = 0.0 + * cdef double min_value = 0.0 + * cdef double max_value = 0.0 # <<<<<<<<<<<<<< + * cdef double x = 0.0 + * cdef int i, n_elements + */ + __pyx_v_max_value = 0.0; + + /* "pygeoprocessing/geoprocessing_core.pyx":564 + * cdef double min_value = 0.0 + * cdef double max_value = 0.0 + * cdef double x = 0.0 # <<<<<<<<<<<<<< + * cdef int i, n_elements + * cdef long long n = 0L + */ + __pyx_v_x = 0.0; + + /* "pygeoprocessing/geoprocessing_core.pyx":566 + * cdef double x = 0.0 + * cdef int i, n_elements + * cdef long long n = 0L # <<<<<<<<<<<<<< + * payload = None + * + */ + __pyx_v_n = 0L; + + /* "pygeoprocessing/geoprocessing_core.pyx":567 + * cdef int i, n_elements + * cdef long long n = 0L + * payload = None # <<<<<<<<<<<<<< + * + * for index in range(expected_blocks): + */ + __Pyx_INCREF(Py_None); + __pyx_v_payload = Py_None; + + /* "pygeoprocessing/geoprocessing_core.pyx":569 + * payload = None + * + * for index in range(expected_blocks): # <<<<<<<<<<<<<< + * try: + * existing_shm = None + */ + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_v_expected_blocks); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 569, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_6 = 0; + __pyx_t_7 = NULL; + } else { + __pyx_t_6 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 569, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 569, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (likely(!__pyx_t_7)) { + if (likely(PyList_CheckExact(__pyx_t_3))) { + if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 569, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 569, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } else { + if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 569, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 569, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } + } else { + __pyx_t_1 = __pyx_t_7(__pyx_t_3); + 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, 569, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XDECREF_SET(__pyx_v_index, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":570 + * + * for index in range(expected_blocks): + * try: # <<<<<<<<<<<<<< + * existing_shm = None + * payload = stats_work_queue.get() + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_8); + __Pyx_XGOTREF(__pyx_t_9); + __Pyx_XGOTREF(__pyx_t_10); + /*try:*/ { + + /* "pygeoprocessing/geoprocessing_core.pyx":571 + * for index in range(expected_blocks): + * try: + * existing_shm = None # <<<<<<<<<<<<<< + * payload = stats_work_queue.get() + * if payload is None: + */ + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_existing_shm, Py_None); + + /* "pygeoprocessing/geoprocessing_core.pyx":572 + * try: + * existing_shm = None + * payload = stats_work_queue.get() # <<<<<<<<<<<<<< + * if payload is None: + * break + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_stats_work_queue, __pyx_n_s_get); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 572, __pyx_L5_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 572, __pyx_L5_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF_SET(__pyx_v_payload, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":573 + * existing_shm = None + * payload = stats_work_queue.get() + * if payload is None: # <<<<<<<<<<<<<< + * break + * if isinstance(payload, numpy.ndarray): + */ + __pyx_t_11 = (__pyx_v_payload == Py_None); + __pyx_t_12 = (__pyx_t_11 != 0); + if (__pyx_t_12) { + + /* "pygeoprocessing/geoprocessing_core.pyx":574 + * payload = stats_work_queue.get() + * if payload is None: + * break # <<<<<<<<<<<<<< + * if isinstance(payload, numpy.ndarray): + * # if the payload is a normal array take it as the array block + */ + goto __pyx_L10_try_break; + + /* "pygeoprocessing/geoprocessing_core.pyx":573 + * existing_shm = None + * payload = stats_work_queue.get() + * if payload is None: # <<<<<<<<<<<<<< + * break + * if isinstance(payload, numpy.ndarray): + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":575 + * if payload is None: + * break + * if isinstance(payload, numpy.ndarray): # <<<<<<<<<<<<<< + * # if the payload is a normal array take it as the array block + * block = payload + */ + __pyx_t_12 = __Pyx_TypeCheck(__pyx_v_payload, __pyx_ptype_5numpy_ndarray); + __pyx_t_11 = (__pyx_t_12 != 0); + if (__pyx_t_11) { + + /* "pygeoprocessing/geoprocessing_core.pyx":577 + * if isinstance(payload, numpy.ndarray): + * # if the payload is a normal array take it as the array block + * block = payload # <<<<<<<<<<<<<< + * else: + * # if not an ndarray, it is a shared memory pointer tuple + */ + if (!(likely(((__pyx_v_payload) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_payload, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 577, __pyx_L5_error) + __pyx_t_1 = __pyx_v_payload; + __Pyx_INCREF(__pyx_t_1); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_block.rcbuffer->pybuffer); + __pyx_t_13 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_block.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack); + if (unlikely(__pyx_t_13 < 0)) { + PyErr_Fetch(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_block.rcbuffer->pybuffer, (PyObject*)__pyx_v_block, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_16); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_14, __pyx_t_15, __pyx_t_16); + } + __pyx_t_14 = __pyx_t_15 = __pyx_t_16 = 0; + } + __pyx_pybuffernd_block.diminfo[0].strides = __pyx_pybuffernd_block.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_block.diminfo[0].shape = __pyx_pybuffernd_block.rcbuffer->pybuffer.shape[0]; + if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 577, __pyx_L5_error) + } + __Pyx_XDECREF_SET(__pyx_v_block, ((PyArrayObject *)__pyx_t_1)); + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":575 + * if payload is None: + * break + * if isinstance(payload, numpy.ndarray): # <<<<<<<<<<<<<< + * # if the payload is a normal array take it as the array block + * block = payload + */ + goto __pyx_L14; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":580 + * else: + * # if not an ndarray, it is a shared memory pointer tuple + * shape, dtype, existing_shm = payload # <<<<<<<<<<<<<< + * block = numpy.ndarray( + * shape, dtype=dtype, buffer=existing_shm.buf) + */ + /*else*/ { + if ((likely(PyTuple_CheckExact(__pyx_v_payload))) || (PyList_CheckExact(__pyx_v_payload))) { + PyObject* sequence = __pyx_v_payload; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 3)) { + if (size > 3) __Pyx_RaiseTooManyValuesError(3); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 580, __pyx_L5_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_5 = PyTuple_GET_ITEM(sequence, 2); + } else { + __pyx_t_1 = PyList_GET_ITEM(sequence, 0); + __pyx_t_2 = PyList_GET_ITEM(sequence, 1); + __pyx_t_5 = PyList_GET_ITEM(sequence, 2); + } + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_5); + #else + __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 580, __pyx_L5_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 580, __pyx_L5_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 580, __pyx_L5_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + } else { + Py_ssize_t index = -1; + __pyx_t_4 = PyObject_GetIter(__pyx_v_payload); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 580, __pyx_L5_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_17 = Py_TYPE(__pyx_t_4)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_17(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L15_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 1; __pyx_t_2 = __pyx_t_17(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L15_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + index = 2; __pyx_t_5 = __pyx_t_17(__pyx_t_4); if (unlikely(!__pyx_t_5)) goto __pyx_L15_unpacking_failed; + __Pyx_GOTREF(__pyx_t_5); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_4), 3) < 0) __PYX_ERR(0, 580, __pyx_L5_error) + __pyx_t_17 = NULL; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L16_unpacking_done; + __pyx_L15_unpacking_failed:; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_17 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 580, __pyx_L5_error) + __pyx_L16_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_shape, __pyx_t_1); + __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_dtype, __pyx_t_2); + __pyx_t_2 = 0; + __Pyx_DECREF_SET(__pyx_v_existing_shm, __pyx_t_5); + __pyx_t_5 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":581 + * # if not an ndarray, it is a shared memory pointer tuple + * shape, dtype, existing_shm = payload + * block = numpy.ndarray( # <<<<<<<<<<<<<< + * shape, dtype=dtype, buffer=existing_shm.buf) + * if block.size == 0: + */ + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 581, __pyx_L5_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_v_shape); + __Pyx_GIVEREF(__pyx_v_shape); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_shape); + + /* "pygeoprocessing/geoprocessing_core.pyx":582 + * shape, dtype, existing_shm = payload + * block = numpy.ndarray( + * shape, dtype=dtype, buffer=existing_shm.buf) # <<<<<<<<<<<<<< + * if block.size == 0: + * continue + */ + __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 582, __pyx_L5_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_v_dtype) < 0) __PYX_ERR(0, 582, __pyx_L5_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_existing_shm, __pyx_n_s_buf); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 582, __pyx_L5_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_buffer, __pyx_t_1) < 0) __PYX_ERR(0, 582, __pyx_L5_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":581 + * # if not an ndarray, it is a shared memory pointer tuple + * shape, dtype, existing_shm = payload + * block = numpy.ndarray( # <<<<<<<<<<<<<< + * shape, dtype=dtype, buffer=existing_shm.buf) + * if block.size == 0: + */ + __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5numpy_ndarray), __pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 581, __pyx_L5_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_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_block.rcbuffer->pybuffer); + __pyx_t_13 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_block.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack); + if (unlikely(__pyx_t_13 < 0)) { + PyErr_Fetch(&__pyx_t_16, &__pyx_t_15, &__pyx_t_14); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_block.rcbuffer->pybuffer, (PyObject*)__pyx_v_block, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_16); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_14); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_16, __pyx_t_15, __pyx_t_14); + } + __pyx_t_16 = __pyx_t_15 = __pyx_t_14 = 0; + } + __pyx_pybuffernd_block.diminfo[0].strides = __pyx_pybuffernd_block.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_block.diminfo[0].shape = __pyx_pybuffernd_block.rcbuffer->pybuffer.shape[0]; + if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 581, __pyx_L5_error) + } + __Pyx_XDECREF_SET(__pyx_v_block, ((PyArrayObject *)__pyx_t_1)); + __pyx_t_1 = 0; + } + __pyx_L14:; + + /* "pygeoprocessing/geoprocessing_core.pyx":583 + * block = numpy.ndarray( + * shape, dtype=dtype, buffer=existing_shm.buf) + * if block.size == 0: # <<<<<<<<<<<<<< + * continue + * n_elements = block.size + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_block), __pyx_n_s_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 583, __pyx_L5_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 583, __pyx_L5_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 583, __pyx_L5_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_11) { + + /* "pygeoprocessing/geoprocessing_core.pyx":584 + * shape, dtype=dtype, buffer=existing_shm.buf) + * if block.size == 0: + * continue # <<<<<<<<<<<<<< + * n_elements = block.size + * with nogil: + */ + goto __pyx_L11_try_continue; + + /* "pygeoprocessing/geoprocessing_core.pyx":583 + * block = numpy.ndarray( + * shape, dtype=dtype, buffer=existing_shm.buf) + * if block.size == 0: # <<<<<<<<<<<<<< + * continue + * n_elements = block.size + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":585 + * if block.size == 0: + * continue + * n_elements = block.size # <<<<<<<<<<<<<< + * with nogil: + * for i in range(n_elements): + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_block), __pyx_n_s_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 585, __pyx_L5_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 585, __pyx_L5_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_n_elements = __pyx_t_13; + + /* "pygeoprocessing/geoprocessing_core.pyx":586 + * continue + * n_elements = block.size + * with nogil: # <<<<<<<<<<<<<< + * for i in range(n_elements): + * n = n + 1 + */ + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { + + /* "pygeoprocessing/geoprocessing_core.pyx":587 + * n_elements = block.size + * with nogil: + * for i in range(n_elements): # <<<<<<<<<<<<<< + * n = n + 1 + * x = block[i] + */ + __pyx_t_13 = __pyx_v_n_elements; + __pyx_t_18 = __pyx_t_13; + for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_18; __pyx_t_19+=1) { + __pyx_v_i = __pyx_t_19; + + /* "pygeoprocessing/geoprocessing_core.pyx":588 + * with nogil: + * for i in range(n_elements): + * n = n + 1 # <<<<<<<<<<<<<< + * x = block[i] + * if n <= 0: + */ + __pyx_v_n = (__pyx_v_n + 1); + + /* "pygeoprocessing/geoprocessing_core.pyx":589 + * for i in range(n_elements): + * n = n + 1 + * x = block[i] # <<<<<<<<<<<<<< + * if n <= 0: + * with gil: + */ + __pyx_t_20 = __pyx_v_i; + if (__pyx_t_20 < 0) __pyx_t_20 += __pyx_pybuffernd_block.diminfo[0].shape; + __pyx_v_x = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_block.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_block.diminfo[0].strides)); + + /* "pygeoprocessing/geoprocessing_core.pyx":590 + * n = n + 1 + * x = block[i] + * if n <= 0: # <<<<<<<<<<<<<< + * with gil: + * LOGGER.error('invalid value for n %s' % n) + */ + __pyx_t_11 = ((__pyx_v_n <= 0) != 0); + if (__pyx_t_11) { + + /* "pygeoprocessing/geoprocessing_core.pyx":591 + * x = block[i] + * if n <= 0: + * with gil: # <<<<<<<<<<<<<< + * LOGGER.error('invalid value for n %s' % n) + * if n == 1: + */ + { + #ifdef WITH_THREAD + PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); + #endif + /*try:*/ { + + /* "pygeoprocessing/geoprocessing_core.pyx":592 + * if n <= 0: + * with gil: + * LOGGER.error('invalid value for n %s' % n) # <<<<<<<<<<<<<< + * if n == 1: + * M_local = x + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 592, __pyx_L29_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_error); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 592, __pyx_L29_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_n); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 592, __pyx_L29_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyUnicode_Format(__pyx_kp_u_invalid_value_for_n_s, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 592, __pyx_L29_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + __pyx_t_2 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_1, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 592, __pyx_L29_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":591 + * x = block[i] + * if n <= 0: + * with gil: # <<<<<<<<<<<<<< + * LOGGER.error('invalid value for n %s' % n) + * if n == 1: + */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_PyGILState_Release(__pyx_gilstate_save); + #endif + goto __pyx_L30; + } + __pyx_L29_error: { + #ifdef WITH_THREAD + __Pyx_PyGILState_Release(__pyx_gilstate_save); + #endif + goto __pyx_L21_error; + } + __pyx_L30:; + } + } + + /* "pygeoprocessing/geoprocessing_core.pyx":590 + * n = n + 1 + * x = block[i] + * if n <= 0: # <<<<<<<<<<<<<< + * with gil: + * LOGGER.error('invalid value for n %s' % n) + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":593 + * with gil: + * LOGGER.error('invalid value for n %s' % n) + * if n == 1: # <<<<<<<<<<<<<< + * M_local = x + * S_local = 0.0 + */ + __pyx_t_11 = ((__pyx_v_n == 1) != 0); + if (__pyx_t_11) { + + /* "pygeoprocessing/geoprocessing_core.pyx":594 + * LOGGER.error('invalid value for n %s' % n) + * if n == 1: + * M_local = x # <<<<<<<<<<<<<< + * S_local = 0.0 + * min_value = x + */ + __pyx_v_M_local = __pyx_v_x; + + /* "pygeoprocessing/geoprocessing_core.pyx":595 + * if n == 1: + * M_local = x + * S_local = 0.0 # <<<<<<<<<<<<<< + * min_value = x + * max_value = x + */ + __pyx_v_S_local = 0.0; + + /* "pygeoprocessing/geoprocessing_core.pyx":596 + * M_local = x + * S_local = 0.0 + * min_value = x # <<<<<<<<<<<<<< + * max_value = x + * else: + */ + __pyx_v_min_value = __pyx_v_x; + + /* "pygeoprocessing/geoprocessing_core.pyx":597 + * S_local = 0.0 + * min_value = x + * max_value = x # <<<<<<<<<<<<<< + * else: + * M_last = M_local + */ + __pyx_v_max_value = __pyx_v_x; + + /* "pygeoprocessing/geoprocessing_core.pyx":593 + * with gil: + * LOGGER.error('invalid value for n %s' % n) + * if n == 1: # <<<<<<<<<<<<<< + * M_local = x + * S_local = 0.0 + */ + goto __pyx_L31; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":599 + * max_value = x + * else: + * M_last = M_local # <<<<<<<<<<<<<< + * M_local = M_local+(x - M_local)/(n) + * S_local = S_local+(x-M_last)*(x-M_local) + */ + /*else*/ { + __pyx_v_M_last = __pyx_v_M_local; + + /* "pygeoprocessing/geoprocessing_core.pyx":600 + * else: + * M_last = M_local + * M_local = M_local+(x - M_local)/(n) # <<<<<<<<<<<<<< + * S_local = S_local+(x-M_last)*(x-M_local) + * if x < min_value: + */ + __pyx_v_M_local = (__pyx_v_M_local + ((__pyx_v_x - __pyx_v_M_local) / ((double)__pyx_v_n))); + + /* "pygeoprocessing/geoprocessing_core.pyx":601 + * M_last = M_local + * M_local = M_local+(x - M_local)/(n) + * S_local = S_local+(x-M_last)*(x-M_local) # <<<<<<<<<<<<<< + * if x < min_value: + * min_value = x + */ + __pyx_v_S_local = (__pyx_v_S_local + ((__pyx_v_x - __pyx_v_M_last) * (__pyx_v_x - __pyx_v_M_local))); + + /* "pygeoprocessing/geoprocessing_core.pyx":602 + * M_local = M_local+(x - M_local)/(n) + * S_local = S_local+(x-M_last)*(x-M_local) + * if x < min_value: # <<<<<<<<<<<<<< + * min_value = x + * elif x > max_value: + */ + __pyx_t_11 = ((__pyx_v_x < __pyx_v_min_value) != 0); + if (__pyx_t_11) { + + /* "pygeoprocessing/geoprocessing_core.pyx":603 + * S_local = S_local+(x-M_last)*(x-M_local) + * if x < min_value: + * min_value = x # <<<<<<<<<<<<<< + * elif x > max_value: + * max_value = x + */ + __pyx_v_min_value = __pyx_v_x; + + /* "pygeoprocessing/geoprocessing_core.pyx":602 + * M_local = M_local+(x - M_local)/(n) + * S_local = S_local+(x-M_last)*(x-M_local) + * if x < min_value: # <<<<<<<<<<<<<< + * min_value = x + * elif x > max_value: + */ + goto __pyx_L32; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":604 + * if x < min_value: + * min_value = x + * elif x > max_value: # <<<<<<<<<<<<<< + * max_value = x + * except Exception as e: + */ + __pyx_t_11 = ((__pyx_v_x > __pyx_v_max_value) != 0); + if (__pyx_t_11) { + + /* "pygeoprocessing/geoprocessing_core.pyx":605 + * min_value = x + * elif x > max_value: + * max_value = x # <<<<<<<<<<<<<< + * except Exception as e: + * LOGGER.exception( + */ + __pyx_v_max_value = __pyx_v_x; + + /* "pygeoprocessing/geoprocessing_core.pyx":604 + * if x < min_value: + * min_value = x + * elif x > max_value: # <<<<<<<<<<<<<< + * max_value = x + * except Exception as e: + */ + } + __pyx_L32:; + } + __pyx_L31:; + } + } + + /* "pygeoprocessing/geoprocessing_core.pyx":586 + * continue + * n_elements = block.size + * with nogil: # <<<<<<<<<<<<<< + * for i in range(n_elements): + * n = n + 1 + */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L22; + } + __pyx_L21_error: { + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L5_error; + } + __pyx_L22:; + } + } + + /* "pygeoprocessing/geoprocessing_core.pyx":570 + * + * for index in range(expected_blocks): + * try: # <<<<<<<<<<<<<< + * existing_shm = None + * payload = stats_work_queue.get() + */ + } + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + goto __pyx_L12_try_end; + __pyx_L5_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":606 + * elif x > max_value: + * max_value = x + * except Exception as e: # <<<<<<<<<<<<<< + * LOGGER.exception( + * "exception %s %s %s %s %s", x, M_local, S_local, n, payload) + */ + __pyx_t_13 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0]))); + if (__pyx_t_13) { + __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core.stats_worker", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_5, &__pyx_t_4) < 0) __PYX_ERR(0, 606, __pyx_L7_except_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __pyx_v_e = __pyx_t_5; + /*try:*/ { + + /* "pygeoprocessing/geoprocessing_core.pyx":607 + * max_value = x + * except Exception as e: + * LOGGER.exception( # <<<<<<<<<<<<<< + * "exception %s %s %s %s %s", x, M_local, S_local, n, payload) + * raise + */ + __Pyx_GetModuleGlobalName(__pyx_t_21, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 607, __pyx_L38_error) + __Pyx_GOTREF(__pyx_t_21); + __pyx_t_22 = __Pyx_PyObject_GetAttrStr(__pyx_t_21, __pyx_n_s_exception); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 607, __pyx_L38_error) + __Pyx_GOTREF(__pyx_t_22); + __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":608 + * except Exception as e: + * LOGGER.exception( + * "exception %s %s %s %s %s", x, M_local, S_local, n, payload) # <<<<<<<<<<<<<< + * raise + * + */ + __pyx_t_21 = PyFloat_FromDouble(__pyx_v_x); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 608, __pyx_L38_error) + __Pyx_GOTREF(__pyx_t_21); + __pyx_t_23 = PyFloat_FromDouble(__pyx_v_M_local); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 608, __pyx_L38_error) + __Pyx_GOTREF(__pyx_t_23); + __pyx_t_24 = PyFloat_FromDouble(__pyx_v_S_local); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 608, __pyx_L38_error) + __Pyx_GOTREF(__pyx_t_24); + __pyx_t_25 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_n); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 608, __pyx_L38_error) + __Pyx_GOTREF(__pyx_t_25); + __pyx_t_26 = NULL; + __pyx_t_13 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_22))) { + __pyx_t_26 = PyMethod_GET_SELF(__pyx_t_22); + if (likely(__pyx_t_26)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_22); + __Pyx_INCREF(__pyx_t_26); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_22, function); + __pyx_t_13 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_22)) { + PyObject *__pyx_temp[7] = {__pyx_t_26, __pyx_kp_u_exception_s_s_s_s_s, __pyx_t_21, __pyx_t_23, __pyx_t_24, __pyx_t_25, __pyx_v_payload}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_22, __pyx_temp+1-__pyx_t_13, 6+__pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 607, __pyx_L38_error) + __Pyx_XDECREF(__pyx_t_26); __pyx_t_26 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; + __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; + __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; + __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_22)) { + PyObject *__pyx_temp[7] = {__pyx_t_26, __pyx_kp_u_exception_s_s_s_s_s, __pyx_t_21, __pyx_t_23, __pyx_t_24, __pyx_t_25, __pyx_v_payload}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_22, __pyx_temp+1-__pyx_t_13, 6+__pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 607, __pyx_L38_error) + __Pyx_XDECREF(__pyx_t_26); __pyx_t_26 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; + __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; + __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; + __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0; + } else + #endif + { + __pyx_t_27 = PyTuple_New(6+__pyx_t_13); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 607, __pyx_L38_error) + __Pyx_GOTREF(__pyx_t_27); + if (__pyx_t_26) { + __Pyx_GIVEREF(__pyx_t_26); PyTuple_SET_ITEM(__pyx_t_27, 0, __pyx_t_26); __pyx_t_26 = NULL; + } + __Pyx_INCREF(__pyx_kp_u_exception_s_s_s_s_s); + __Pyx_GIVEREF(__pyx_kp_u_exception_s_s_s_s_s); + PyTuple_SET_ITEM(__pyx_t_27, 0+__pyx_t_13, __pyx_kp_u_exception_s_s_s_s_s); + __Pyx_GIVEREF(__pyx_t_21); + PyTuple_SET_ITEM(__pyx_t_27, 1+__pyx_t_13, __pyx_t_21); + __Pyx_GIVEREF(__pyx_t_23); + PyTuple_SET_ITEM(__pyx_t_27, 2+__pyx_t_13, __pyx_t_23); + __Pyx_GIVEREF(__pyx_t_24); + PyTuple_SET_ITEM(__pyx_t_27, 3+__pyx_t_13, __pyx_t_24); + __Pyx_GIVEREF(__pyx_t_25); + PyTuple_SET_ITEM(__pyx_t_27, 4+__pyx_t_13, __pyx_t_25); + __Pyx_INCREF(__pyx_v_payload); + __Pyx_GIVEREF(__pyx_v_payload); + PyTuple_SET_ITEM(__pyx_t_27, 5+__pyx_t_13, __pyx_v_payload); + __pyx_t_21 = 0; + __pyx_t_23 = 0; + __pyx_t_24 = 0; + __pyx_t_25 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_22, __pyx_t_27, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 607, __pyx_L38_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0; + } + __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":609 + * LOGGER.exception( + * "exception %s %s %s %s %s", x, M_local, S_local, n, payload) + * raise # <<<<<<<<<<<<<< + * + * if n > 0: + */ + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_ErrRestoreWithState(__pyx_t_2, __pyx_t_5, __pyx_t_4); + __pyx_t_2 = 0; __pyx_t_5 = 0; __pyx_t_4 = 0; + __PYX_ERR(0, 609, __pyx_L38_error) + } + + /* "pygeoprocessing/geoprocessing_core.pyx":606 + * elif x > max_value: + * max_value = x + * except Exception as e: # <<<<<<<<<<<<<< + * LOGGER.exception( + * "exception %s %s %s %s %s", x, M_local, S_local, n, payload) + */ + /*finally:*/ { + __pyx_L38_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_29 = 0; __pyx_t_30 = 0; __pyx_t_31 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; + __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; + __Pyx_XDECREF(__pyx_t_23); __pyx_t_23 = 0; + __Pyx_XDECREF(__pyx_t_24); __pyx_t_24 = 0; + __Pyx_XDECREF(__pyx_t_25); __pyx_t_25 = 0; + __Pyx_XDECREF(__pyx_t_26); __pyx_t_26 = 0; + __Pyx_XDECREF(__pyx_t_27); __pyx_t_27 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_29, &__pyx_t_30, &__pyx_t_31); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16) < 0)) __Pyx_ErrFetch(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_14); + __Pyx_XGOTREF(__pyx_t_15); + __Pyx_XGOTREF(__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_29); + __Pyx_XGOTREF(__pyx_t_30); + __Pyx_XGOTREF(__pyx_t_31); + __pyx_t_13 = __pyx_lineno; __pyx_t_18 = __pyx_clineno; __pyx_t_28 = __pyx_filename; + { + __Pyx_DECREF(__pyx_v_e); + __pyx_v_e = NULL; + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_29); + __Pyx_XGIVEREF(__pyx_t_30); + __Pyx_XGIVEREF(__pyx_t_31); + __Pyx_ExceptionReset(__pyx_t_29, __pyx_t_30, __pyx_t_31); + } + __Pyx_XGIVEREF(__pyx_t_14); + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_ErrRestore(__pyx_t_14, __pyx_t_15, __pyx_t_16); + __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_29 = 0; __pyx_t_30 = 0; __pyx_t_31 = 0; + __pyx_lineno = __pyx_t_13; __pyx_clineno = __pyx_t_18; __pyx_filename = __pyx_t_28; + goto __pyx_L7_except_error; + } + } + } + goto __pyx_L7_except_error; + __pyx_L7_except_error:; + + /* "pygeoprocessing/geoprocessing_core.pyx":570 + * + * for index in range(expected_blocks): + * try: # <<<<<<<<<<<<<< + * existing_shm = None + * payload = stats_work_queue.get() + */ + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10); + goto __pyx_L1_error; + __pyx_L10_try_break:; + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10); + goto __pyx_L4_break; + __pyx_L11_try_continue:; + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10); + goto __pyx_L3_continue; + __pyx_L12_try_end:; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":569 + * payload = None + * + * for index in range(expected_blocks): # <<<<<<<<<<<<<< + * try: + * existing_shm = None + */ + __pyx_L3_continue:; + } + __pyx_L4_break:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":611 + * raise + * + * if n > 0: # <<<<<<<<<<<<<< + * stats_work_queue.put( + * (min_value, max_value, M_local, + */ + __pyx_t_11 = ((__pyx_v_n > 0) != 0); + if (__pyx_t_11) { + + /* "pygeoprocessing/geoprocessing_core.pyx":612 + * + * if n > 0: + * stats_work_queue.put( # <<<<<<<<<<<<<< + * (min_value, max_value, M_local, + * (S_local / n) ** 0.5)) + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_stats_work_queue, __pyx_n_s_put); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 612, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "pygeoprocessing/geoprocessing_core.pyx":613 + * if n > 0: + * stats_work_queue.put( + * (min_value, max_value, M_local, # <<<<<<<<<<<<<< + * (S_local / n) ** 0.5)) + * else: + */ + __pyx_t_5 = PyFloat_FromDouble(__pyx_v_min_value); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 613, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = PyFloat_FromDouble(__pyx_v_max_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 613, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_M_local); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 613, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/geoprocessing_core.pyx":614 + * stats_work_queue.put( + * (min_value, max_value, M_local, + * (S_local / n) ** 0.5)) # <<<<<<<<<<<<<< + * else: + * LOGGER.warning( + */ + __pyx_t_22 = PyFloat_FromDouble(pow((__pyx_v_S_local / ((double)__pyx_v_n)), 0.5)); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 614, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_22); + + /* "pygeoprocessing/geoprocessing_core.pyx":613 + * if n > 0: + * stats_work_queue.put( + * (min_value, max_value, M_local, # <<<<<<<<<<<<<< + * (S_local / n) ** 0.5)) + * else: + */ + __pyx_t_27 = PyTuple_New(4); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 613, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_27); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_27, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_27, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_27, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_22); + PyTuple_SET_ITEM(__pyx_t_27, 3, __pyx_t_22); + __pyx_t_5 = 0; + __pyx_t_2 = 0; + __pyx_t_1 = 0; + __pyx_t_22 = 0; + __pyx_t_22 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_22 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_22)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_22); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_3 = (__pyx_t_22) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_22, __pyx_t_27) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_27); + __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; + __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 612, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":611 + * raise + * + * if n > 0: # <<<<<<<<<<<<<< + * stats_work_queue.put( + * (min_value, max_value, M_local, + */ + goto __pyx_L44; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":616 + * (S_local / n) ** 0.5)) + * else: + * LOGGER.warning( # <<<<<<<<<<<<<< + * "No valid pixels were received, sending None.") + * stats_work_queue.put(None) + */ + /*else*/ { + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 616, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_27 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_warning); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 616, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_27); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_27))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_27); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_27); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_27, function); + } + } + __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_27, __pyx_t_4, __pyx_kp_u_No_valid_pixels_were_received_se) : __Pyx_PyObject_CallOneArg(__pyx_t_27, __pyx_kp_u_No_valid_pixels_were_received_se); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 616, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":618 + * LOGGER.warning( + * "No valid pixels were received, sending None.") + * stats_work_queue.put(None) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_27 = __Pyx_PyObject_GetAttrStr(__pyx_v_stats_work_queue, __pyx_n_s_put); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 618, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_27); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_27))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_27); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_27); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_27, function); + } + } + __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_27, __pyx_t_4, Py_None) : __Pyx_PyObject_CallOneArg(__pyx_t_27, Py_None); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 618, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __pyx_L44:; + + /* "pygeoprocessing/geoprocessing_core.pyx":544 + * @cython.boundscheck(False) + * @cython.cdivision(True) + * def stats_worker(stats_work_queue, expected_blocks): # <<<<<<<<<<<<<< + * """Worker to calculate continuous min, max, mean and standard deviation. + * + */ + + /* 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_21); + __Pyx_XDECREF(__pyx_t_22); + __Pyx_XDECREF(__pyx_t_23); + __Pyx_XDECREF(__pyx_t_24); + __Pyx_XDECREF(__pyx_t_25); + __Pyx_XDECREF(__pyx_t_26); + __Pyx_XDECREF(__pyx_t_27); + { 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.rcbuffer->pybuffer); + __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} + __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core.stats_worker", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + goto __pyx_L2; + __pyx_L0:; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_block.rcbuffer->pybuffer); + __pyx_L2:; + __Pyx_XDECREF((PyObject *)__pyx_v_block); + __Pyx_XDECREF(__pyx_v_payload); + __Pyx_XDECREF(__pyx_v_index); + __Pyx_XDECREF(__pyx_v_existing_shm); + __Pyx_XDECREF(__pyx_v_shape); + __Pyx_XDECREF(__pyx_v_dtype); + __Pyx_XDECREF(__pyx_v_e); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pygeoprocessing/geoprocessing_core.pyx":626 + * + * + * def raster_band_percentile( # <<<<<<<<<<<<<< + * base_raster_path_band, working_sort_directory, percentile_list, + * heap_buffer_size=2**28, ffi_buffer_size=2**10): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_7raster_band_percentile(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_15pygeoprocessing_18geoprocessing_core_6raster_band_percentile[] = "Calculate percentiles of a raster band.\n\n Parameters:\n base_raster_path_band (tuple): raster path band tuple to a raster\n that is of any integer or real type.\n working_sort_directory (str): path to a directory that does not\n exist or is empty. This directory will be used to create heapfiles\n with sizes no larger than ``heap_buffer_size`` which are written in the\n of the pattern N.dat where N is in the numbering 0, 1, 2, ... up\n to the number of files necessary to handle the raster.\n percentile_list (list): sorted list of percentiles to report must\n contain values in the range [0, 100].\n heap_buffer_size (int): defines approximately how many elements to hold in\n a single heap file. This is proportional to the amount of maximum\n memory to use when storing elements before a sort and write to\n disk.\n ffi_buffer_size (int): defines how many elements will be stored per\n heap file buffer for iteration.\n\n Returns:\n A list of len(percentile_list) elements long containing the\n percentile values (ranging from [0, 100]) in ``base_raster_path_band``\n where the interpolation scheme is \"higher\" (i.e. any percentile splits\n will select the next element higher than the percentile cutoff).\n\n "; +static PyMethodDef __pyx_mdef_15pygeoprocessing_18geoprocessing_core_7raster_band_percentile = {"raster_band_percentile", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_18geoprocessing_core_7raster_band_percentile, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_18geoprocessing_core_6raster_band_percentile}; +static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_7raster_band_percentile(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_base_raster_path_band = 0; + PyObject *__pyx_v_working_sort_directory = 0; + PyObject *__pyx_v_percentile_list = 0; + PyObject *__pyx_v_heap_buffer_size = 0; + PyObject *__pyx_v_ffi_buffer_size = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("raster_band_percentile (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_base_raster_path_band,&__pyx_n_s_working_sort_directory,&__pyx_n_s_percentile_list,&__pyx_n_s_heap_buffer_size,&__pyx_n_s_ffi_buffer_size,0}; + PyObject* values[5] = {0,0,0,0,0}; + values[3] = ((PyObject *)__pyx_int_268435456); + values[4] = ((PyObject *)__pyx_int_1024); + 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_base_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_working_sort_directory)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("raster_band_percentile", 0, 3, 5, 1); __PYX_ERR(0, 626, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_percentile_list)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("raster_band_percentile", 0, 3, 5, 2); __PYX_ERR(0, 626, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 3: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_heap_buffer_size); + 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_ffi_buffer_size); + if (value) { values[4] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "raster_band_percentile") < 0)) __PYX_ERR(0, 626, __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_base_raster_path_band = values[0]; + __pyx_v_working_sort_directory = values[1]; + __pyx_v_percentile_list = values[2]; + __pyx_v_heap_buffer_size = values[3]; + __pyx_v_ffi_buffer_size = values[4]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("raster_band_percentile", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 626, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core.raster_band_percentile", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_15pygeoprocessing_18geoprocessing_core_6raster_band_percentile(__pyx_self, __pyx_v_base_raster_path_band, __pyx_v_working_sort_directory, __pyx_v_percentile_list, __pyx_v_heap_buffer_size, __pyx_v_ffi_buffer_size); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core_6raster_band_percentile(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_base_raster_path_band, PyObject *__pyx_v_working_sort_directory, PyObject *__pyx_v_percentile_list, PyObject *__pyx_v_heap_buffer_size, PyObject *__pyx_v_ffi_buffer_size) { + PyObject *__pyx_v_raster_type = NULL; + 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("raster_band_percentile", 0); + + /* "pygeoprocessing/geoprocessing_core.pyx":655 + * + * """ + * raster_type = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< + * base_raster_path_band[0])['datatype'] + * if raster_type in ( + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 655, __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, 655, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":656 + * """ + * raster_type = pygeoprocessing.get_raster_info( + * base_raster_path_band[0])['datatype'] # <<<<<<<<<<<<<< + * if raster_type in ( + * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, + */ + __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_base_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 656, __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); + } + } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 655, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_t_1, __pyx_n_u_datatype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 656, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_raster_type = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":657 + * raster_type = pygeoprocessing.get_raster_info( + * base_raster_path_band[0])['datatype'] + * if raster_type in ( # <<<<<<<<<<<<<< + * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, + * gdal.GDT_UInt32): + */ + __Pyx_INCREF(__pyx_v_raster_type); + __pyx_t_3 = __pyx_v_raster_type; + + /* "pygeoprocessing/geoprocessing_core.pyx":658 + * base_raster_path_band[0])['datatype'] + * if raster_type in ( + * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, # <<<<<<<<<<<<<< + * gdal.GDT_UInt32): + * return _raster_band_percentile_int( + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 658, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 658, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 657, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":657 + * raster_type = pygeoprocessing.get_raster_info( + * base_raster_path_band[0])['datatype'] + * if raster_type in ( # <<<<<<<<<<<<<< + * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, + * gdal.GDT_UInt32): + */ + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 657, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L4_bool_binop_done; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":658 + * base_raster_path_band[0])['datatype'] + * if raster_type in ( + * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, # <<<<<<<<<<<<<< + * gdal.GDT_UInt32): + * return _raster_band_percentile_int( + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 658, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Int16); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 658, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 657, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":657 + * raster_type = pygeoprocessing.get_raster_info( + * base_raster_path_band[0])['datatype'] + * if raster_type in ( # <<<<<<<<<<<<<< + * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, + * gdal.GDT_UInt32): + */ + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 657, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L4_bool_binop_done; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":658 + * base_raster_path_band[0])['datatype'] + * if raster_type in ( + * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, # <<<<<<<<<<<<<< + * gdal.GDT_UInt32): + * return _raster_band_percentile_int( + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 658, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_UInt16); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 658, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 657, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":657 + * raster_type = pygeoprocessing.get_raster_info( + * base_raster_path_band[0])['datatype'] + * if raster_type in ( # <<<<<<<<<<<<<< + * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, + * gdal.GDT_UInt32): + */ + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 657, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L4_bool_binop_done; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":658 + * base_raster_path_band[0])['datatype'] + * if raster_type in ( + * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, # <<<<<<<<<<<<<< + * gdal.GDT_UInt32): + * return _raster_band_percentile_int( + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 658, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Int32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 658, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 657, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":657 + * raster_type = pygeoprocessing.get_raster_info( + * base_raster_path_band[0])['datatype'] + * if raster_type in ( # <<<<<<<<<<<<<< + * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, + * gdal.GDT_UInt32): + */ + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 657, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L4_bool_binop_done; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":659 + * if raster_type in ( + * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, + * gdal.GDT_UInt32): # <<<<<<<<<<<<<< + * return _raster_band_percentile_int( + * base_raster_path_band, working_sort_directory, percentile_list, + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 659, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_UInt32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 659, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 657, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":657 + * raster_type = pygeoprocessing.get_raster_info( + * base_raster_path_band[0])['datatype'] + * if raster_type in ( # <<<<<<<<<<<<<< + * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, + * gdal.GDT_UInt32): + */ + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 657, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_5 = __pyx_t_6; + __pyx_L4_bool_binop_done:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = (__pyx_t_5 != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/geoprocessing_core.pyx":660 + * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, + * gdal.GDT_UInt32): + * return _raster_band_percentile_int( # <<<<<<<<<<<<<< + * base_raster_path_band, working_sort_directory, percentile_list, + * heap_buffer_size, ffi_buffer_size) + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_raster_band_percentile_int); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 660, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/geoprocessing_core.pyx":662 + * return _raster_band_percentile_int( + * base_raster_path_band, working_sort_directory, percentile_list, + * heap_buffer_size, ffi_buffer_size) # <<<<<<<<<<<<<< + * elif raster_type in (gdal.GDT_Float32, gdal.GDT_Float64): + * return _raster_band_percentile_double( + */ + __pyx_t_2 = NULL; + __pyx_t_7 = 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_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[6] = {__pyx_t_2, __pyx_v_base_raster_path_band, __pyx_v_working_sort_directory, __pyx_v_percentile_list, __pyx_v_heap_buffer_size, __pyx_v_ffi_buffer_size}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_7, 5+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 660, __pyx_L1_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[6] = {__pyx_t_2, __pyx_v_base_raster_path_band, __pyx_v_working_sort_directory, __pyx_v_percentile_list, __pyx_v_heap_buffer_size, __pyx_v_ffi_buffer_size}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_7, 5+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 660, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_4 = PyTuple_New(5+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 660, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (__pyx_t_2) { + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __pyx_t_2 = NULL; + } + __Pyx_INCREF(__pyx_v_base_raster_path_band); + __Pyx_GIVEREF(__pyx_v_base_raster_path_band); + PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_7, __pyx_v_base_raster_path_band); + __Pyx_INCREF(__pyx_v_working_sort_directory); + __Pyx_GIVEREF(__pyx_v_working_sort_directory); + PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_7, __pyx_v_working_sort_directory); + __Pyx_INCREF(__pyx_v_percentile_list); + __Pyx_GIVEREF(__pyx_v_percentile_list); + PyTuple_SET_ITEM(__pyx_t_4, 2+__pyx_t_7, __pyx_v_percentile_list); + __Pyx_INCREF(__pyx_v_heap_buffer_size); + __Pyx_GIVEREF(__pyx_v_heap_buffer_size); + PyTuple_SET_ITEM(__pyx_t_4, 3+__pyx_t_7, __pyx_v_heap_buffer_size); + __Pyx_INCREF(__pyx_v_ffi_buffer_size); + __Pyx_GIVEREF(__pyx_v_ffi_buffer_size); + PyTuple_SET_ITEM(__pyx_t_4, 4+__pyx_t_7, __pyx_v_ffi_buffer_size); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 660, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + /* "pygeoprocessing/geoprocessing_core.pyx":657 + * raster_type = pygeoprocessing.get_raster_info( + * base_raster_path_band[0])['datatype'] + * if raster_type in ( # <<<<<<<<<<<<<< + * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, + * gdal.GDT_UInt32): + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":663 + * base_raster_path_band, working_sort_directory, percentile_list, + * heap_buffer_size, ffi_buffer_size) + * elif raster_type in (gdal.GDT_Float32, gdal.GDT_Float64): # <<<<<<<<<<<<<< + * return _raster_band_percentile_double( + * base_raster_path_band, working_sort_directory, percentile_list, + */ + __Pyx_INCREF(__pyx_v_raster_type); + __pyx_t_3 = __pyx_v_raster_type; + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 663, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Float32); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 663, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 663, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 663, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (!__pyx_t_5) { + } else { + __pyx_t_6 = __pyx_t_5; + goto __pyx_L9_bool_binop_done; + } + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 663, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 663, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 663, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 663, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_6 = __pyx_t_5; + __pyx_L9_bool_binop_done:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_5 = (__pyx_t_6 != 0); + if (likely(__pyx_t_5)) { + + /* "pygeoprocessing/geoprocessing_core.pyx":664 + * heap_buffer_size, ffi_buffer_size) + * elif raster_type in (gdal.GDT_Float32, gdal.GDT_Float64): + * return _raster_band_percentile_double( # <<<<<<<<<<<<<< + * base_raster_path_band, working_sort_directory, percentile_list, + * heap_buffer_size, ffi_buffer_size) + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_raster_band_percentile_double); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 664, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/geoprocessing_core.pyx":666 + * return _raster_band_percentile_double( + * base_raster_path_band, working_sort_directory, percentile_list, + * heap_buffer_size, ffi_buffer_size) # <<<<<<<<<<<<<< + * else: + * raise ValueError( + */ + __pyx_t_4 = NULL; + __pyx_t_7 = 0; + 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); + __pyx_t_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[6] = {__pyx_t_4, __pyx_v_base_raster_path_band, __pyx_v_working_sort_directory, __pyx_v_percentile_list, __pyx_v_heap_buffer_size, __pyx_v_ffi_buffer_size}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_7, 5+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 664, __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[6] = {__pyx_t_4, __pyx_v_base_raster_path_band, __pyx_v_working_sort_directory, __pyx_v_percentile_list, __pyx_v_heap_buffer_size, __pyx_v_ffi_buffer_size}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_7, 5+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 664, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_2 = PyTuple_New(5+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 664, __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_INCREF(__pyx_v_base_raster_path_band); + __Pyx_GIVEREF(__pyx_v_base_raster_path_band); + PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_7, __pyx_v_base_raster_path_band); + __Pyx_INCREF(__pyx_v_working_sort_directory); + __Pyx_GIVEREF(__pyx_v_working_sort_directory); + PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_7, __pyx_v_working_sort_directory); + __Pyx_INCREF(__pyx_v_percentile_list); + __Pyx_GIVEREF(__pyx_v_percentile_list); + PyTuple_SET_ITEM(__pyx_t_2, 2+__pyx_t_7, __pyx_v_percentile_list); + __Pyx_INCREF(__pyx_v_heap_buffer_size); + __Pyx_GIVEREF(__pyx_v_heap_buffer_size); + PyTuple_SET_ITEM(__pyx_t_2, 3+__pyx_t_7, __pyx_v_heap_buffer_size); + __Pyx_INCREF(__pyx_v_ffi_buffer_size); + __Pyx_GIVEREF(__pyx_v_ffi_buffer_size); + PyTuple_SET_ITEM(__pyx_t_2, 4+__pyx_t_7, __pyx_v_ffi_buffer_size); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 664, __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_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + /* "pygeoprocessing/geoprocessing_core.pyx":663 + * base_raster_path_band, working_sort_directory, percentile_list, + * heap_buffer_size, ffi_buffer_size) + * elif raster_type in (gdal.GDT_Float32, gdal.GDT_Float64): # <<<<<<<<<<<<<< + * return _raster_band_percentile_double( + * base_raster_path_band, working_sort_directory, percentile_list, + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":668 + * heap_buffer_size, ffi_buffer_size) + * else: + * raise ValueError( # <<<<<<<<<<<<<< + * 'Cannot process raster type %s (not a known integer nor float ' + * 'type)', raster_type) + */ + /*else*/ { + + /* "pygeoprocessing/geoprocessing_core.pyx":670 + * raise ValueError( + * 'Cannot process raster type %s (not a known integer nor float ' + * 'type)', raster_type) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 668, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_kp_u_Cannot_process_raster_type_s_not); + __Pyx_GIVEREF(__pyx_kp_u_Cannot_process_raster_type_s_not); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_u_Cannot_process_raster_type_s_not); + __Pyx_INCREF(__pyx_v_raster_type); + __Pyx_GIVEREF(__pyx_v_raster_type); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_raster_type); + + /* "pygeoprocessing/geoprocessing_core.pyx":668 + * heap_buffer_size, ffi_buffer_size) + * else: + * raise ValueError( # <<<<<<<<<<<<<< + * 'Cannot process raster type %s (not a known integer nor float ' + * 'type)', raster_type) + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 668, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 668, __pyx_L1_error) + } + + /* "pygeoprocessing/geoprocessing_core.pyx":626 + * + * + * def raster_band_percentile( # <<<<<<<<<<<<<< + * base_raster_path_band, working_sort_directory, percentile_list, + * heap_buffer_size=2**28, ffi_buffer_size=2**10): + */ + + /* 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_4); + __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core.raster_band_percentile", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_raster_type); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pygeoprocessing/geoprocessing_core.pyx":673 + * + * + * def _raster_band_percentile_int( # <<<<<<<<<<<<<< + * base_raster_path_band, working_sort_directory, percentile_list, + * heap_buffer_size, ffi_buffer_size): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_9_raster_band_percentile_int(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_15pygeoprocessing_18geoprocessing_core_8_raster_band_percentile_int[] = "Calculate percentiles of a raster band of an integer type.\n\n Parameters:\n base_raster_path_band (tuple): raster path band tuple to a raster that\n is of an integer type.\n working_sort_directory (str): path to a directory that does not\n exist or is empty. This directory will be used to create heapfiles\n with sizes no larger than ``heap_buffer_size`` which are written in the\n of the pattern N.dat where N is in the numbering 0, 1, 2, ... up\n to the number of files necessary to handle the raster.\n percentile_list (list): sorted list of percentiles to report must\n contain values in the range [0, 100].\n heap_buffer_size (int): defines approximately how many elements to hold in\n a single heap file. This is proportional to the amount of maximum\n memory to use when storing elements before a sort and write to\n disk.\n ffi_buffer_size (int): defines how many elements to store in a file\n buffer at any time.\n\n Returns:\n A list of len(percentile_list) elements long containing the\n percentile values (ranging from [0, 100]) in ``base_raster_path_band``\n where the interpolation scheme is \"higher\" (i.e. any percentile splits\n will select the next element higher than the percentile cutoff).\n\n "; +static PyMethodDef __pyx_mdef_15pygeoprocessing_18geoprocessing_core_9_raster_band_percentile_int = {"_raster_band_percentile_int", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_18geoprocessing_core_9_raster_band_percentile_int, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_18geoprocessing_core_8_raster_band_percentile_int}; +static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_9_raster_band_percentile_int(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_base_raster_path_band = 0; + PyObject *__pyx_v_working_sort_directory = 0; + PyObject *__pyx_v_percentile_list = 0; + PyObject *__pyx_v_heap_buffer_size = 0; + PyObject *__pyx_v_ffi_buffer_size = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_raster_band_percentile_int (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_base_raster_path_band,&__pyx_n_s_working_sort_directory,&__pyx_n_s_percentile_list,&__pyx_n_s_heap_buffer_size,&__pyx_n_s_ffi_buffer_size,0}; + PyObject* values[5] = {0,0,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 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_base_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_working_sort_directory)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_raster_band_percentile_int", 1, 5, 5, 1); __PYX_ERR(0, 673, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_percentile_list)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_raster_band_percentile_int", 1, 5, 5, 2); __PYX_ERR(0, 673, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 3: + if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_heap_buffer_size)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_raster_band_percentile_int", 1, 5, 5, 3); __PYX_ERR(0, 673, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 4: + if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_ffi_buffer_size)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_raster_band_percentile_int", 1, 5, 5, 4); __PYX_ERR(0, 673, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_raster_band_percentile_int") < 0)) __PYX_ERR(0, 673, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 5) { + 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); + values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + } + __pyx_v_base_raster_path_band = values[0]; + __pyx_v_working_sort_directory = values[1]; + __pyx_v_percentile_list = values[2]; + __pyx_v_heap_buffer_size = values[3]; + __pyx_v_ffi_buffer_size = values[4]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("_raster_band_percentile_int", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 673, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core._raster_band_percentile_int", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_15pygeoprocessing_18geoprocessing_core_8_raster_band_percentile_int(__pyx_self, __pyx_v_base_raster_path_band, __pyx_v_working_sort_directory, __pyx_v_percentile_list, __pyx_v_heap_buffer_size, __pyx_v_ffi_buffer_size); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core_8_raster_band_percentile_int(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_base_raster_path_band, PyObject *__pyx_v_working_sort_directory, PyObject *__pyx_v_percentile_list, PyObject *__pyx_v_heap_buffer_size, PyObject *__pyx_v_ffi_buffer_size) { + FILE *__pyx_v_fptr; + __pyx_t_15pygeoprocessing_18geoprocessing_core_FastFileIteratorLongLongIntPtr __pyx_v_fast_file_iterator; + std::vector<__pyx_t_15pygeoprocessing_18geoprocessing_core_FastFileIteratorLongLongIntPtr> __pyx_v_fast_file_iterator_vector; + std::vector<__pyx_t_15pygeoprocessing_18geoprocessing_core_FastFileIteratorLongLongIntPtr> ::iterator __pyx_v_ffiv_iter; + int __pyx_v_percentile_index; + PY_LONG_LONG __pyx_v_i; + PY_LONG_LONG __pyx_v_n_elements; + __pyx_t_15pygeoprocessing_18geoprocessing_core_int64t __pyx_v_next_val; + double __pyx_v_step_size; + double __pyx_v_current_percentile; + double __pyx_v_current_step; + PyObject *__pyx_v_result_list = NULL; + int __pyx_v_rm_dir_when_done; + __Pyx_memviewslice __pyx_v_buffer_data = { 0, 0, { 0 }, { 0 }, { 0 } }; + PyObject *__pyx_v_heapfile_list = NULL; + PyObject *__pyx_v_file_index = NULL; + PyObject *__pyx_v_raster_info = NULL; + PyObject *__pyx_v_nodata = NULL; + PY_LONG_LONG __pyx_v_n_pixels; + PY_LONG_LONG __pyx_v_pixels_processed; + PyObject *__pyx_v_last_update = NULL; + CYTHON_UNUSED PyObject *__pyx_v__ = NULL; + PyObject *__pyx_v_block_data = NULL; + PyObject *__pyx_v_file_path = NULL; + 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; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + PyObject *__pyx_t_8 = NULL; + PY_LONG_LONG __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + Py_ssize_t __pyx_t_12; + PyObject *(*__pyx_t_13)(PyObject *); + PyObject *(*__pyx_t_14)(PyObject *); + int __pyx_t_15; + Py_ssize_t __pyx_t_16; + Py_UCS4 __pyx_t_17; + double __pyx_t_18; + PyObject *__pyx_t_19 = NULL; + PyObject *__pyx_t_20 = NULL; + __Pyx_memviewslice __pyx_t_21 = { 0, 0, { 0 }, { 0 }, { 0 } }; + int __pyx_t_22; + char const *__pyx_t_23; + Py_ssize_t __pyx_t_24; + size_t __pyx_t_25; + char const *__pyx_t_26; + PY_LONG_LONG __pyx_t_27; + PY_LONG_LONG __pyx_t_28; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_raster_band_percentile_int", 0); + + /* "pygeoprocessing/geoprocessing_core.pyx":706 + * cdef vector[FastFileIteratorLongLongIntPtr] fast_file_iterator_vector + * cdef vector[FastFileIteratorLongLongIntPtr].iterator ffiv_iter + * cdef int percentile_index = 0 # <<<<<<<<<<<<<< + * cdef long long i, n_elements = 0 + * cdef int64t next_val = 0L + */ + __pyx_v_percentile_index = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":707 + * cdef vector[FastFileIteratorLongLongIntPtr].iterator ffiv_iter + * cdef int percentile_index = 0 + * cdef long long i, n_elements = 0 # <<<<<<<<<<<<<< + * cdef int64t next_val = 0L + * cdef double step_size, current_percentile + */ + __pyx_v_n_elements = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":708 + * cdef int percentile_index = 0 + * cdef long long i, n_elements = 0 + * cdef int64t next_val = 0L # <<<<<<<<<<<<<< + * cdef double step_size, current_percentile + * cdef double current_step = 0.0 + */ + __pyx_v_next_val = 0L; + + /* "pygeoprocessing/geoprocessing_core.pyx":710 + * cdef int64t next_val = 0L + * cdef double step_size, current_percentile + * cdef double current_step = 0.0 # <<<<<<<<<<<<<< + * result_list = [] + * rm_dir_when_done = False + */ + __pyx_v_current_step = 0.0; + + /* "pygeoprocessing/geoprocessing_core.pyx":711 + * cdef double step_size, current_percentile + * cdef double current_step = 0.0 + * result_list = [] # <<<<<<<<<<<<<< + * rm_dir_when_done = False + * try: + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 711, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_result_list = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":712 + * cdef double current_step = 0.0 + * result_list = [] + * rm_dir_when_done = False # <<<<<<<<<<<<<< + * try: + * os.makedirs(working_sort_directory) + */ + __pyx_v_rm_dir_when_done = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":713 + * result_list = [] + * rm_dir_when_done = False + * try: # <<<<<<<<<<<<<< + * os.makedirs(working_sort_directory) + * rm_dir_when_done = True + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_2, &__pyx_t_3, &__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_4); + /*try:*/ { + + /* "pygeoprocessing/geoprocessing_core.pyx":714 + * rm_dir_when_done = False + * try: + * os.makedirs(working_sort_directory) # <<<<<<<<<<<<<< + * rm_dir_when_done = True + * except OSError: + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_os); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 714, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_makedirs); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 714, __pyx_L3_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_6))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_v_working_sort_directory) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_working_sort_directory); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 714, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":715 + * try: + * os.makedirs(working_sort_directory) + * rm_dir_when_done = True # <<<<<<<<<<<<<< + * except OSError: + * pass + */ + __pyx_v_rm_dir_when_done = 1; + + /* "pygeoprocessing/geoprocessing_core.pyx":713 + * result_list = [] + * rm_dir_when_done = False + * try: # <<<<<<<<<<<<<< + * os.makedirs(working_sort_directory) + * rm_dir_when_done = True + */ + } + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L8_try_end; + __pyx_L3_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":716 + * os.makedirs(working_sort_directory) + * rm_dir_when_done = True + * except OSError: # <<<<<<<<<<<<<< + * pass + * + */ + __pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OSError); + if (__pyx_t_7) { + __Pyx_ErrRestore(0,0,0); + goto __pyx_L4_exception_handled; + } + goto __pyx_L5_except_error; + __pyx_L5_except_error:; + + /* "pygeoprocessing/geoprocessing_core.pyx":713 + * result_list = [] + * rm_dir_when_done = False + * try: # <<<<<<<<<<<<<< + * os.makedirs(working_sort_directory) + * rm_dir_when_done = True + */ + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4); + goto __pyx_L1_error; + __pyx_L4_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4); + __pyx_L8_try_end:; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":721 + * cdef int64t[:] buffer_data + * + * heapfile_list = [] # <<<<<<<<<<<<<< + * file_index = 0 + * raster_info = pygeoprocessing.get_raster_info( + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 721, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_heapfile_list = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":722 + * + * heapfile_list = [] + * file_index = 0 # <<<<<<<<<<<<<< + * raster_info = pygeoprocessing.get_raster_info( + * base_raster_path_band[0]) + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_v_file_index = __pyx_int_0; + + /* "pygeoprocessing/geoprocessing_core.pyx":723 + * heapfile_list = [] + * file_index = 0 + * raster_info = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< + * base_raster_path_band[0]) + * nodata = raster_info['nodata'][base_raster_path_band[1]-1] + */ + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 723, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 723, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":724 + * file_index = 0 + * raster_info = pygeoprocessing.get_raster_info( + * base_raster_path_band[0]) # <<<<<<<<<<<<<< + * nodata = raster_info['nodata'][base_raster_path_band[1]-1] + * cdef long long n_pixels = raster_info['raster_size'][0] * raster_info['raster_size'][1] + */ + __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_base_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 724, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 723, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_raster_info = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":725 + * raster_info = pygeoprocessing.get_raster_info( + * base_raster_path_band[0]) + * nodata = raster_info['nodata'][base_raster_path_band[1]-1] # <<<<<<<<<<<<<< + * cdef long long n_pixels = raster_info['raster_size'][0] * raster_info['raster_size'][1] + * + */ + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 725, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_base_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 725, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyInt_SubtractObjC(__pyx_t_5, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 725, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 725, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_nodata = __pyx_t_5; + __pyx_t_5 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":726 + * base_raster_path_band[0]) + * nodata = raster_info['nodata'][base_raster_path_band[1]-1] + * cdef long long n_pixels = raster_info['raster_size'][0] * raster_info['raster_size'][1] # <<<<<<<<<<<<<< + * + * LOGGER.debug('total number of pixels %s (%s)', n_pixels, raster_info['raster_size']) + */ + __pyx_t_5 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 726, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_5, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 726, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 726, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_5, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 726, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyNumber_Multiply(__pyx_t_6, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 726, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_9 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_t_5); if (unlikely((__pyx_t_9 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 726, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_n_pixels = __pyx_t_9; + + /* "pygeoprocessing/geoprocessing_core.pyx":728 + * cdef long long n_pixels = raster_info['raster_size'][0] * raster_info['raster_size'][1] + * + * LOGGER.debug('total number of pixels %s (%s)', n_pixels, raster_info['raster_size']) # <<<<<<<<<<<<<< + * cdef long long pixels_processed = 0 + * LOGGER.debug('sorting data to heap') + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 728, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_debug); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 728, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_n_pixels); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 728, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 728, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_10 = NULL; + __pyx_t_7 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[4] = {__pyx_t_10, __pyx_kp_u_total_number_of_pixels_s_s, __pyx_t_1, __pyx_t_8}; + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 3+__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 728, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[4] = {__pyx_t_10, __pyx_kp_u_total_number_of_pixels_s_s, __pyx_t_1, __pyx_t_8}; + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 3+__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 728, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + { + __pyx_t_11 = PyTuple_New(3+__pyx_t_7); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 728, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + if (__pyx_t_10) { + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10); __pyx_t_10 = NULL; + } + __Pyx_INCREF(__pyx_kp_u_total_number_of_pixels_s_s); + __Pyx_GIVEREF(__pyx_kp_u_total_number_of_pixels_s_s); + PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_7, __pyx_kp_u_total_number_of_pixels_s_s); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_7, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_11, 2+__pyx_t_7, __pyx_t_8); + __pyx_t_1 = 0; + __pyx_t_8 = 0; + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_11, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 728, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":729 + * + * LOGGER.debug('total number of pixels %s (%s)', n_pixels, raster_info['raster_size']) + * cdef long long pixels_processed = 0 # <<<<<<<<<<<<<< + * LOGGER.debug('sorting data to heap') + * last_update = time.time() + */ + __pyx_v_pixels_processed = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":730 + * LOGGER.debug('total number of pixels %s (%s)', n_pixels, raster_info['raster_size']) + * cdef long long pixels_processed = 0 + * LOGGER.debug('sorting data to heap') # <<<<<<<<<<<<<< + * last_update = time.time() + * for _, block_data in pygeoprocessing.iterblocks( + */ + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 730, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_debug); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 730, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + } + } + __pyx_t_5 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_6, __pyx_kp_u_sorting_data_to_heap) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_kp_u_sorting_data_to_heap); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 730, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":731 + * cdef long long pixels_processed = 0 + * LOGGER.debug('sorting data to heap') + * last_update = time.time() # <<<<<<<<<<<<<< + * for _, block_data in pygeoprocessing.iterblocks( + * base_raster_path_band, largest_block=heap_buffer_size): + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_time); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 731, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_time); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 731, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + __pyx_t_5 = (__pyx_t_11) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_11) : __Pyx_PyObject_CallNoArg(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 731, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_last_update = __pyx_t_5; + __pyx_t_5 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":732 + * LOGGER.debug('sorting data to heap') + * last_update = time.time() + * for _, block_data in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * base_raster_path_band, largest_block=heap_buffer_size): + * pixels_processed += block_data.size + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 732, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 732, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":733 + * last_update = time.time() + * for _, block_data in pygeoprocessing.iterblocks( + * base_raster_path_band, largest_block=heap_buffer_size): # <<<<<<<<<<<<<< + * pixels_processed += block_data.size + * if time.time() - last_update > 5.0: + */ + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 732, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_v_base_raster_path_band); + __Pyx_GIVEREF(__pyx_v_base_raster_path_band); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_base_raster_path_band); + __pyx_t_11 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 733, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_largest_block, __pyx_v_heap_buffer_size) < 0) __PYX_ERR(0, 733, __pyx_L1_error) + + /* "pygeoprocessing/geoprocessing_core.pyx":732 + * LOGGER.debug('sorting data to heap') + * last_update = time.time() + * for _, block_data in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * base_raster_path_band, largest_block=heap_buffer_size): + * pixels_processed += block_data.size + */ + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 732, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (likely(PyList_CheckExact(__pyx_t_8)) || PyTuple_CheckExact(__pyx_t_8)) { + __pyx_t_11 = __pyx_t_8; __Pyx_INCREF(__pyx_t_11); __pyx_t_12 = 0; + __pyx_t_13 = NULL; + } else { + __pyx_t_12 = -1; __pyx_t_11 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 732, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_13 = Py_TYPE(__pyx_t_11)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 732, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + for (;;) { + if (likely(!__pyx_t_13)) { + if (likely(PyList_CheckExact(__pyx_t_11))) { + if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_11)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_8 = PyList_GET_ITEM(__pyx_t_11, __pyx_t_12); __Pyx_INCREF(__pyx_t_8); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 732, __pyx_L1_error) + #else + __pyx_t_8 = PySequence_ITEM(__pyx_t_11, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 732, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + #endif + } else { + if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_11)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_11, __pyx_t_12); __Pyx_INCREF(__pyx_t_8); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 732, __pyx_L1_error) + #else + __pyx_t_8 = PySequence_ITEM(__pyx_t_11, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 732, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + #endif + } + } else { + __pyx_t_8 = __pyx_t_13(__pyx_t_11); + if (unlikely(!__pyx_t_8)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 732, __pyx_L1_error) + } + break; + } + __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, 732, __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_6 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_5 = PyList_GET_ITEM(sequence, 0); + __pyx_t_6 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(__pyx_t_6); + #else + __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 732, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 732, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + #endif + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_1 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 732, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_14 = Py_TYPE(__pyx_t_1)->tp_iternext; + index = 0; __pyx_t_5 = __pyx_t_14(__pyx_t_1); if (unlikely(!__pyx_t_5)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_5); + index = 1; __pyx_t_6 = __pyx_t_14(__pyx_t_1); if (unlikely(!__pyx_t_6)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_14(__pyx_t_1), 2) < 0) __PYX_ERR(0, 732, __pyx_L1_error) + __pyx_t_14 = NULL; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L12_unpacking_done; + __pyx_L11_unpacking_failed:; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_14 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 732, __pyx_L1_error) + __pyx_L12_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_5); + __pyx_t_5 = 0; + __Pyx_XDECREF_SET(__pyx_v_block_data, __pyx_t_6); + __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":734 + * for _, block_data in pygeoprocessing.iterblocks( + * base_raster_path_band, largest_block=heap_buffer_size): + * pixels_processed += block_data.size # <<<<<<<<<<<<<< + * if time.time() - last_update > 5.0: + * LOGGER.debug( + */ + __pyx_t_8 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_pixels_processed); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 734, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_block_data, __pyx_n_s_size); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 734, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_t_8, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 734, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_9 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_t_5); if (unlikely((__pyx_t_9 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 734, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_pixels_processed = __pyx_t_9; + + /* "pygeoprocessing/geoprocessing_core.pyx":735 + * base_raster_path_band, largest_block=heap_buffer_size): + * pixels_processed += block_data.size + * if time.time() - last_update > 5.0: # <<<<<<<<<<<<<< + * LOGGER.debug( + * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' + */ + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_time); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 735, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_time); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 735, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_5 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 735, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = PyNumber_Subtract(__pyx_t_5, __pyx_v_last_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 735, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyObject_RichCompare(__pyx_t_8, __pyx_float_5_0, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 735, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_15 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_15 < 0)) __PYX_ERR(0, 735, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_15) { + + /* "pygeoprocessing/geoprocessing_core.pyx":736 + * pixels_processed += block_data.size + * if time.time() - last_update > 5.0: + * LOGGER.debug( # <<<<<<<<<<<<<< + * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' + * f'complete, {pixels_processed} out of {n_pixels}'), + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 736, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_debug); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 736, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":737 + * if time.time() - last_update > 5.0: + * LOGGER.debug( + * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' # <<<<<<<<<<<<<< + * f'complete, {pixels_processed} out of {n_pixels}'), + * + */ + __pyx_t_8 = PyTuple_New(6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 737, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_16 = 0; + __pyx_t_17 = 127; + __Pyx_INCREF(__pyx_kp_u_data_sort_to_heap); + __pyx_t_16 += 18; + __Pyx_GIVEREF(__pyx_kp_u_data_sort_to_heap); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_kp_u_data_sort_to_heap); + __pyx_t_18 = (100. * __pyx_v_pixels_processed); + if (unlikely(__pyx_v_n_pixels == 0)) { + PyErr_SetString(PyExc_ZeroDivisionError, "float division"); + __PYX_ERR(0, 737, __pyx_L1_error) + } + __pyx_t_1 = PyFloat_FromDouble((__pyx_t_18 / ((double)__pyx_v_n_pixels))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 737, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = __Pyx_PyObject_Format(__pyx_t_1, __pyx_kp_u_1f); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 737, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_17 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_10) > __pyx_t_17) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_10) : __pyx_t_17; + __pyx_t_16 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_10); + __pyx_t_10 = 0; + __Pyx_INCREF(__pyx_kp_u_complete); + __pyx_t_16 += 12; + __Pyx_GIVEREF(__pyx_kp_u_complete); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_kp_u_complete); + + /* "pygeoprocessing/geoprocessing_core.pyx":738 + * LOGGER.debug( + * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' + * f'complete, {pixels_processed} out of {n_pixels}'), # <<<<<<<<<<<<<< + * + * last_update = time.time() + */ + __pyx_t_10 = __Pyx_PyUnicode_From_PY_LONG_LONG(__pyx_v_pixels_processed, 0, ' ', 'd'); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 738, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_16 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_10); + __pyx_t_10 = 0; + __Pyx_INCREF(__pyx_kp_u_out_of); + __pyx_t_16 += 8; + __Pyx_GIVEREF(__pyx_kp_u_out_of); + PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_kp_u_out_of); + __pyx_t_10 = __Pyx_PyUnicode_From_PY_LONG_LONG(__pyx_v_n_pixels, 0, ' ', 'd'); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 738, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_16 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_8, 5, __pyx_t_10); + __pyx_t_10 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":737 + * if time.time() - last_update > 5.0: + * LOGGER.debug( + * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' # <<<<<<<<<<<<<< + * f'complete, {pixels_processed} out of {n_pixels}'), + * + */ + __pyx_t_10 = __Pyx_PyUnicode_Join(__pyx_t_8, 6, __pyx_t_16, __pyx_t_17); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 737, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + __pyx_t_5 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_8, __pyx_t_10) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_10); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 736, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":736 + * pixels_processed += block_data.size + * if time.time() - last_update > 5.0: + * LOGGER.debug( # <<<<<<<<<<<<<< + * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' + * f'complete, {pixels_processed} out of {n_pixels}'), + */ + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 736, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); + __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":740 + * f'complete, {pixels_processed} out of {n_pixels}'), + * + * last_update = time.time() # <<<<<<<<<<<<<< + * buffer_data = numpy.sort( + * block_data[~numpy.isclose(block_data, nodata)]).astype( + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 740, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 740, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_10); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_10, function); + } + } + __pyx_t_6 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 740, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF_SET(__pyx_v_last_update, __pyx_t_6); + __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":735 + * base_raster_path_band, largest_block=heap_buffer_size): + * pixels_processed += block_data.size + * if time.time() - last_update > 5.0: # <<<<<<<<<<<<<< + * LOGGER.debug( + * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":741 + * + * last_update = time.time() + * buffer_data = numpy.sort( # <<<<<<<<<<<<<< + * block_data[~numpy.isclose(block_data, nodata)]).astype( + * numpy.int64) + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_numpy); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 741, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_sort); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 741, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":742 + * last_update = time.time() + * buffer_data = numpy.sort( + * block_data[~numpy.isclose(block_data, nodata)]).astype( # <<<<<<<<<<<<<< + * numpy.int64) + * if buffer_data.size == 0: + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 742, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_isclose); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 742, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + __pyx_t_7 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_19))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_19); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_19, function); + __pyx_t_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_19)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_block_data, __pyx_v_nodata}; + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_19, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 742, __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_19)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_block_data, __pyx_v_nodata}; + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_19, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 742, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_5); + } else + #endif + { + __pyx_t_20 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 742, __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_block_data); + __Pyx_GIVEREF(__pyx_v_block_data); + PyTuple_SET_ITEM(__pyx_t_20, 0+__pyx_t_7, __pyx_v_block_data); + __Pyx_INCREF(__pyx_v_nodata); + __Pyx_GIVEREF(__pyx_v_nodata); + PyTuple_SET_ITEM(__pyx_t_20, 1+__pyx_t_7, __pyx_v_nodata); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_19, __pyx_t_20, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 742, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + } + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __pyx_t_19 = PyNumber_Invert(__pyx_t_5); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 742, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_block_data, __pyx_t_19); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 742, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __pyx_t_19 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_19)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_19); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_10 = (__pyx_t_19) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_19, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_5); + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 741, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_astype); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 742, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":743 + * buffer_data = numpy.sort( + * block_data[~numpy.isclose(block_data, nodata)]).astype( + * numpy.int64) # <<<<<<<<<<<<<< + * if buffer_data.size == 0: + * continue + */ + __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_numpy); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 743, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 743, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_6 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_10, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_5); + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 742, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":742 + * last_update = time.time() + * buffer_data = numpy.sort( + * block_data[~numpy.isclose(block_data, nodata)]).astype( # <<<<<<<<<<<<<< + * numpy.int64) + * if buffer_data.size == 0: + */ + __pyx_t_21 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_21.memview)) __PYX_ERR(0, 742, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __PYX_XDEC_MEMVIEW(&__pyx_v_buffer_data, 1); + __pyx_v_buffer_data = __pyx_t_21; + __pyx_t_21.memview = NULL; + __pyx_t_21.data = NULL; + + /* "pygeoprocessing/geoprocessing_core.pyx":744 + * block_data[~numpy.isclose(block_data, nodata)]).astype( + * numpy.int64) + * if buffer_data.size == 0: # <<<<<<<<<<<<<< + * continue + * n_elements += buffer_data.size + */ + __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_buffer_data, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 744, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_size); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 744, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyInt_EqObjC(__pyx_t_8, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 744, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_15 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_15 < 0)) __PYX_ERR(0, 744, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (__pyx_t_15) { + + /* "pygeoprocessing/geoprocessing_core.pyx":745 + * numpy.int64) + * if buffer_data.size == 0: + * continue # <<<<<<<<<<<<<< + * n_elements += buffer_data.size + * file_path = os.path.join( + */ + goto __pyx_L9_continue; + + /* "pygeoprocessing/geoprocessing_core.pyx":744 + * block_data[~numpy.isclose(block_data, nodata)]).astype( + * numpy.int64) + * if buffer_data.size == 0: # <<<<<<<<<<<<<< + * continue + * n_elements += buffer_data.size + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":746 + * if buffer_data.size == 0: + * continue + * n_elements += buffer_data.size # <<<<<<<<<<<<<< + * file_path = os.path.join( + * working_sort_directory, '%d.dat' % file_index) + */ + __pyx_t_6 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_n_elements); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 746, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = __pyx_memoryview_fromslice(__pyx_v_buffer_data, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t, 0);; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 746, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_size); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 746, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = PyNumber_InPlaceAdd(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 746, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_9 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_t_8); if (unlikely((__pyx_t_9 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 746, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_n_elements = __pyx_t_9; + + /* "pygeoprocessing/geoprocessing_core.pyx":747 + * continue + * n_elements += buffer_data.size + * file_path = os.path.join( # <<<<<<<<<<<<<< + * working_sort_directory, '%d.dat' % file_index) + * heapfile_list.append(file_path) + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_os); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 747, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_path); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 747, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_join); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 747, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":748 + * n_elements += buffer_data.size + * file_path = os.path.join( + * working_sort_directory, '%d.dat' % file_index) # <<<<<<<<<<<<<< + * heapfile_list.append(file_path) + * fptr = fopen(bytes(file_path.encode()), "wb") + */ + __pyx_t_6 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_d_dat, __pyx_v_file_index); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 748, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_10 = NULL; + __pyx_t_7 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_working_sort_directory, __pyx_t_6}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 747, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_8); + __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_10, __pyx_v_working_sort_directory, __pyx_t_6}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 747, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + { + __pyx_t_19 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 747, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + if (__pyx_t_10) { + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_10); __pyx_t_10 = NULL; + } + __Pyx_INCREF(__pyx_v_working_sort_directory); + __Pyx_GIVEREF(__pyx_v_working_sort_directory); + PyTuple_SET_ITEM(__pyx_t_19, 0+__pyx_t_7, __pyx_v_working_sort_directory); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_19, 1+__pyx_t_7, __pyx_t_6); + __pyx_t_6 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_19, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 747, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF_SET(__pyx_v_file_path, __pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":749 + * file_path = os.path.join( + * working_sort_directory, '%d.dat' % file_index) + * heapfile_list.append(file_path) # <<<<<<<<<<<<<< + * fptr = fopen(bytes(file_path.encode()), "wb") + * fwrite( + */ + __pyx_t_22 = __Pyx_PyList_Append(__pyx_v_heapfile_list, __pyx_v_file_path); if (unlikely(__pyx_t_22 == ((int)-1))) __PYX_ERR(0, 749, __pyx_L1_error) + + /* "pygeoprocessing/geoprocessing_core.pyx":750 + * working_sort_directory, '%d.dat' % file_index) + * heapfile_list.append(file_path) + * fptr = fopen(bytes(file_path.encode()), "wb") # <<<<<<<<<<<<<< + * fwrite( + * &buffer_data[0], sizeof(int64t), buffer_data.size, + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_file_path, __pyx_n_s_encode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 750, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_19 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_19)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_19); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + __pyx_t_8 = (__pyx_t_19) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_19) : __Pyx_PyObject_CallNoArg(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 750, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 750, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_23 = __Pyx_PyBytes_AsString(__pyx_t_5); if (unlikely((!__pyx_t_23) && PyErr_Occurred())) __PYX_ERR(0, 750, __pyx_L1_error) + __pyx_v_fptr = fopen(__pyx_t_23, ((char const *)"wb")); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":752 + * fptr = fopen(bytes(file_path.encode()), "wb") + * fwrite( + * &buffer_data[0], sizeof(int64t), buffer_data.size, # <<<<<<<<<<<<<< + * fptr) + * fclose(fptr) + */ + __pyx_t_24 = 0; + __pyx_t_7 = -1; + if (__pyx_t_24 < 0) { + __pyx_t_24 += __pyx_v_buffer_data.shape[0]; + if (unlikely(__pyx_t_24 < 0)) __pyx_t_7 = 0; + } else if (unlikely(__pyx_t_24 >= __pyx_v_buffer_data.shape[0])) __pyx_t_7 = 0; + if (unlikely(__pyx_t_7 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_7); + __PYX_ERR(0, 752, __pyx_L1_error) + } + __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_buffer_data, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 752, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_size); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 752, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_25 = __Pyx_PyInt_As_size_t(__pyx_t_8); if (unlikely((__pyx_t_25 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 752, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":751 + * heapfile_list.append(file_path) + * fptr = fopen(bytes(file_path.encode()), "wb") + * fwrite( # <<<<<<<<<<<<<< + * &buffer_data[0], sizeof(int64t), buffer_data.size, + * fptr) + */ + (void)(fwrite(((__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t *)(&(*((__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t *) ( /* dim=0 */ (__pyx_v_buffer_data.data + __pyx_t_24 * __pyx_v_buffer_data.strides[0]) ))))), (sizeof(__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t)), __pyx_t_25, __pyx_v_fptr)); + + /* "pygeoprocessing/geoprocessing_core.pyx":754 + * &buffer_data[0], sizeof(int64t), buffer_data.size, + * fptr) + * fclose(fptr) # <<<<<<<<<<<<<< + * file_index += 1 + * + */ + (void)(fclose(__pyx_v_fptr)); + + /* "pygeoprocessing/geoprocessing_core.pyx":755 + * fptr) + * fclose(fptr) + * file_index += 1 # <<<<<<<<<<<<<< + * + * fast_file_iterator = new FastFileIterator[int64t]( + */ + __pyx_t_8 = __Pyx_PyInt_AddObjC(__pyx_v_file_index, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 755, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF_SET(__pyx_v_file_index, __pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":758 + * + * fast_file_iterator = new FastFileIterator[int64t]( + * (bytes(file_path.encode())), ffi_buffer_size) # <<<<<<<<<<<<<< + * fast_file_iterator_vector.push_back(fast_file_iterator) + * push_heap( + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_file_path, __pyx_n_s_encode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 758, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_19 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_19)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_19); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + __pyx_t_8 = (__pyx_t_19) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_19) : __Pyx_PyObject_CallNoArg(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 758, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 758, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_26 = __Pyx_PyBytes_AsString(__pyx_t_5); if (unlikely((!__pyx_t_26) && PyErr_Occurred())) __PYX_ERR(0, 758, __pyx_L1_error) + __pyx_t_25 = __Pyx_PyInt_As_size_t(__pyx_v_ffi_buffer_size); if (unlikely((__pyx_t_25 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 758, __pyx_L1_error) + + /* "pygeoprocessing/geoprocessing_core.pyx":757 + * file_index += 1 + * + * fast_file_iterator = new FastFileIterator[int64t]( # <<<<<<<<<<<<<< + * (bytes(file_path.encode())), ffi_buffer_size) + * fast_file_iterator_vector.push_back(fast_file_iterator) + */ + __pyx_v_fast_file_iterator = new FastFileIterator<__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t> (__pyx_t_26, __pyx_t_25); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":759 + * fast_file_iterator = new FastFileIterator[int64t]( + * (bytes(file_path.encode())), ffi_buffer_size) + * fast_file_iterator_vector.push_back(fast_file_iterator) # <<<<<<<<<<<<<< + * push_heap( + * fast_file_iterator_vector.begin(), + */ + try { + __pyx_v_fast_file_iterator_vector.push_back(__pyx_v_fast_file_iterator); + } catch(...) { + __Pyx_CppExn2PyErr(); + __PYX_ERR(0, 759, __pyx_L1_error) + } + + /* "pygeoprocessing/geoprocessing_core.pyx":760 + * (bytes(file_path.encode())), ffi_buffer_size) + * fast_file_iterator_vector.push_back(fast_file_iterator) + * push_heap( # <<<<<<<<<<<<<< + * fast_file_iterator_vector.begin(), + * fast_file_iterator_vector.end(), + */ + std::push_heap(__pyx_v_fast_file_iterator_vector.begin(), __pyx_v_fast_file_iterator_vector.end(), FastFileIteratorCompare<__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t>); + + /* "pygeoprocessing/geoprocessing_core.pyx":732 + * LOGGER.debug('sorting data to heap') + * last_update = time.time() + * for _, block_data in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * base_raster_path_band, largest_block=heap_buffer_size): + * pixels_processed += block_data.size + */ + __pyx_L9_continue:; + } + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":764 + * fast_file_iterator_vector.end(), + * FastFileIteratorCompare[int64t]) + * LOGGER.debug('calculating percentiles') # <<<<<<<<<<<<<< + * current_percentile = percentile_list[percentile_index] + * step_size = 0 + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 764, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_debug); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 764, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_11 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_5, __pyx_kp_u_calculating_percentiles) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_kp_u_calculating_percentiles); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 764, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":765 + * FastFileIteratorCompare[int64t]) + * LOGGER.debug('calculating percentiles') + * current_percentile = percentile_list[percentile_index] # <<<<<<<<<<<<<< + * step_size = 0 + * if n_elements > 0: + */ + __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_percentile_list, __pyx_v_percentile_index, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 765, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_18 = __pyx_PyFloat_AsDouble(__pyx_t_11); if (unlikely((__pyx_t_18 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 765, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_v_current_percentile = __pyx_t_18; + + /* "pygeoprocessing/geoprocessing_core.pyx":766 + * LOGGER.debug('calculating percentiles') + * current_percentile = percentile_list[percentile_index] + * step_size = 0 # <<<<<<<<<<<<<< + * if n_elements > 0: + * step_size = 100.0 / n_elements + */ + __pyx_v_step_size = 0.0; + + /* "pygeoprocessing/geoprocessing_core.pyx":767 + * current_percentile = percentile_list[percentile_index] + * step_size = 0 + * if n_elements > 0: # <<<<<<<<<<<<<< + * step_size = 100.0 / n_elements + * + */ + __pyx_t_15 = ((__pyx_v_n_elements > 0) != 0); + if (__pyx_t_15) { + + /* "pygeoprocessing/geoprocessing_core.pyx":768 + * step_size = 0 + * if n_elements > 0: + * step_size = 100.0 / n_elements # <<<<<<<<<<<<<< + * + * for i in range(n_elements): + */ + if (unlikely(__pyx_v_n_elements == 0)) { + PyErr_SetString(PyExc_ZeroDivisionError, "float division"); + __PYX_ERR(0, 768, __pyx_L1_error) + } + __pyx_v_step_size = (100.0 / ((double)__pyx_v_n_elements)); + + /* "pygeoprocessing/geoprocessing_core.pyx":767 + * current_percentile = percentile_list[percentile_index] + * step_size = 0 + * if n_elements > 0: # <<<<<<<<<<<<<< + * step_size = 100.0 / n_elements + * + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":770 + * step_size = 100.0 / n_elements + * + * for i in range(n_elements): # <<<<<<<<<<<<<< + * if time.time() - last_update > 5.0: + * LOGGER.debug( + */ + __pyx_t_9 = __pyx_v_n_elements; + __pyx_t_27 = __pyx_t_9; + for (__pyx_t_28 = 0; __pyx_t_28 < __pyx_t_27; __pyx_t_28+=1) { + __pyx_v_i = __pyx_t_28; + + /* "pygeoprocessing/geoprocessing_core.pyx":771 + * + * for i in range(n_elements): + * if time.time() - last_update > 5.0: # <<<<<<<<<<<<<< + * LOGGER.debug( + * 'calculating percentiles %.2f%% complete', + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_time); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 771, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 771, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + __pyx_t_11 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 771, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyNumber_Subtract(__pyx_t_11, __pyx_v_last_update); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 771, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = PyObject_RichCompare(__pyx_t_5, __pyx_float_5_0, Py_GT); __Pyx_XGOTREF(__pyx_t_11); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 771, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_15 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_15 < 0)) __PYX_ERR(0, 771, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (__pyx_t_15) { + + /* "pygeoprocessing/geoprocessing_core.pyx":772 + * for i in range(n_elements): + * if time.time() - last_update > 5.0: + * LOGGER.debug( # <<<<<<<<<<<<<< + * 'calculating percentiles %.2f%% complete', + * 100.0 * i / float(n_elements)) + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 772, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_debug); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 772, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":774 + * LOGGER.debug( + * 'calculating percentiles %.2f%% complete', + * 100.0 * i / float(n_elements)) # <<<<<<<<<<<<<< + * last_update = time.time() + * current_step = step_size * i + */ + __pyx_t_18 = (100.0 * __pyx_v_i); + if (unlikely(((double)__pyx_v_n_elements) == 0)) { + PyErr_SetString(PyExc_ZeroDivisionError, "float division"); + __PYX_ERR(0, 774, __pyx_L1_error) + } + __pyx_t_5 = PyFloat_FromDouble((__pyx_t_18 / ((double)__pyx_v_n_elements))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 774, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_19 = NULL; + __pyx_t_7 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_19)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_19); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + __pyx_t_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[3] = {__pyx_t_19, __pyx_kp_u_calculating_percentiles_2f_compl, __pyx_t_5}; + __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 772, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[3] = {__pyx_t_19, __pyx_kp_u_calculating_percentiles_2f_compl, __pyx_t_5}; + __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 772, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_6 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 772, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (__pyx_t_19) { + __Pyx_GIVEREF(__pyx_t_19); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_19); __pyx_t_19 = NULL; + } + __Pyx_INCREF(__pyx_kp_u_calculating_percentiles_2f_compl); + __Pyx_GIVEREF(__pyx_kp_u_calculating_percentiles_2f_compl); + PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_7, __pyx_kp_u_calculating_percentiles_2f_compl); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_7, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_6, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 772, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":775 + * 'calculating percentiles %.2f%% complete', + * 100.0 * i / float(n_elements)) + * last_update = time.time() # <<<<<<<<<<<<<< + * current_step = step_size * i + * next_val = fast_file_iterator_vector.front().next() + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_time); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 775, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_time); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 775, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + __pyx_t_11 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 775, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF_SET(__pyx_v_last_update, __pyx_t_11); + __pyx_t_11 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":771 + * + * for i in range(n_elements): + * if time.time() - last_update > 5.0: # <<<<<<<<<<<<<< + * LOGGER.debug( + * 'calculating percentiles %.2f%% complete', + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":776 + * 100.0 * i / float(n_elements)) + * last_update = time.time() + * current_step = step_size * i # <<<<<<<<<<<<<< + * next_val = fast_file_iterator_vector.front().next() + * if current_step >= current_percentile: + */ + __pyx_v_current_step = (__pyx_v_step_size * __pyx_v_i); + + /* "pygeoprocessing/geoprocessing_core.pyx":777 + * last_update = time.time() + * current_step = step_size * i + * next_val = fast_file_iterator_vector.front().next() # <<<<<<<<<<<<<< + * if current_step >= current_percentile: + * result_list.append(next_val) + */ + __pyx_v_next_val = __pyx_v_fast_file_iterator_vector.front()->next(); + + /* "pygeoprocessing/geoprocessing_core.pyx":778 + * current_step = step_size * i + * next_val = fast_file_iterator_vector.front().next() + * if current_step >= current_percentile: # <<<<<<<<<<<<<< + * result_list.append(next_val) + * percentile_index += 1 + */ + __pyx_t_15 = ((__pyx_v_current_step >= __pyx_v_current_percentile) != 0); + if (__pyx_t_15) { + + /* "pygeoprocessing/geoprocessing_core.pyx":779 + * next_val = fast_file_iterator_vector.front().next() + * if current_step >= current_percentile: + * result_list.append(next_val) # <<<<<<<<<<<<<< + * percentile_index += 1 + * if percentile_index >= len(percentile_list): + */ + __pyx_t_11 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_next_val); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 779, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_22 = __Pyx_PyList_Append(__pyx_v_result_list, __pyx_t_11); if (unlikely(__pyx_t_22 == ((int)-1))) __PYX_ERR(0, 779, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":780 + * if current_step >= current_percentile: + * result_list.append(next_val) + * percentile_index += 1 # <<<<<<<<<<<<<< + * if percentile_index >= len(percentile_list): + * break + */ + __pyx_v_percentile_index = (__pyx_v_percentile_index + 1); + + /* "pygeoprocessing/geoprocessing_core.pyx":781 + * result_list.append(next_val) + * percentile_index += 1 + * if percentile_index >= len(percentile_list): # <<<<<<<<<<<<<< + * break + * current_percentile = percentile_list[percentile_index] + */ + __pyx_t_12 = PyObject_Length(__pyx_v_percentile_list); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 781, __pyx_L1_error) + __pyx_t_15 = ((__pyx_v_percentile_index >= __pyx_t_12) != 0); + if (__pyx_t_15) { + + /* "pygeoprocessing/geoprocessing_core.pyx":782 + * percentile_index += 1 + * if percentile_index >= len(percentile_list): + * break # <<<<<<<<<<<<<< + * current_percentile = percentile_list[percentile_index] + * pop_heap( + */ + goto __pyx_L17_break; + + /* "pygeoprocessing/geoprocessing_core.pyx":781 + * result_list.append(next_val) + * percentile_index += 1 + * if percentile_index >= len(percentile_list): # <<<<<<<<<<<<<< + * break + * current_percentile = percentile_list[percentile_index] + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":783 + * if percentile_index >= len(percentile_list): + * break + * current_percentile = percentile_list[percentile_index] # <<<<<<<<<<<<<< + * pop_heap( + * fast_file_iterator_vector.begin(), + */ + __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_percentile_list, __pyx_v_percentile_index, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 783, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_18 = __pyx_PyFloat_AsDouble(__pyx_t_11); if (unlikely((__pyx_t_18 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 783, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_v_current_percentile = __pyx_t_18; + + /* "pygeoprocessing/geoprocessing_core.pyx":778 + * current_step = step_size * i + * next_val = fast_file_iterator_vector.front().next() + * if current_step >= current_percentile: # <<<<<<<<<<<<<< + * result_list.append(next_val) + * percentile_index += 1 + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":784 + * break + * current_percentile = percentile_list[percentile_index] + * pop_heap( # <<<<<<<<<<<<<< + * fast_file_iterator_vector.begin(), + * fast_file_iterator_vector.end(), + */ + std::pop_heap(__pyx_v_fast_file_iterator_vector.begin(), __pyx_v_fast_file_iterator_vector.end(), FastFileIteratorCompare<__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t>); + + /* "pygeoprocessing/geoprocessing_core.pyx":788 + * fast_file_iterator_vector.end(), + * FastFileIteratorCompare[int64t]) + * if fast_file_iterator_vector.back().size() > 0: # <<<<<<<<<<<<<< + * push_heap( + * fast_file_iterator_vector.begin(), + */ + __pyx_t_15 = ((__pyx_v_fast_file_iterator_vector.back()->size() > 0) != 0); + if (__pyx_t_15) { + + /* "pygeoprocessing/geoprocessing_core.pyx":789 + * FastFileIteratorCompare[int64t]) + * if fast_file_iterator_vector.back().size() > 0: + * push_heap( # <<<<<<<<<<<<<< + * fast_file_iterator_vector.begin(), + * fast_file_iterator_vector.end(), + */ + std::push_heap(__pyx_v_fast_file_iterator_vector.begin(), __pyx_v_fast_file_iterator_vector.end(), FastFileIteratorCompare<__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t>); + + /* "pygeoprocessing/geoprocessing_core.pyx":788 + * fast_file_iterator_vector.end(), + * FastFileIteratorCompare[int64t]) + * if fast_file_iterator_vector.back().size() > 0: # <<<<<<<<<<<<<< + * push_heap( + * fast_file_iterator_vector.begin(), + */ + goto __pyx_L21; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":794 + * FastFileIteratorCompare[int64t]) + * else: + * fast_file_iterator = fast_file_iterator_vector.back() # <<<<<<<<<<<<<< + * del fast_file_iterator + * fast_file_iterator_vector.pop_back() + */ + /*else*/ { + __pyx_v_fast_file_iterator = __pyx_v_fast_file_iterator_vector.back(); + + /* "pygeoprocessing/geoprocessing_core.pyx":795 + * else: + * fast_file_iterator = fast_file_iterator_vector.back() + * del fast_file_iterator # <<<<<<<<<<<<<< + * fast_file_iterator_vector.pop_back() + * if percentile_index < len(percentile_list): + */ + delete __pyx_v_fast_file_iterator; + + /* "pygeoprocessing/geoprocessing_core.pyx":796 + * fast_file_iterator = fast_file_iterator_vector.back() + * del fast_file_iterator + * fast_file_iterator_vector.pop_back() # <<<<<<<<<<<<<< + * if percentile_index < len(percentile_list): + * result_list.append(next_val) + */ + __pyx_v_fast_file_iterator_vector.pop_back(); + } + __pyx_L21:; + } + __pyx_L17_break:; + + /* "pygeoprocessing/geoprocessing_core.pyx":797 + * del fast_file_iterator + * fast_file_iterator_vector.pop_back() + * if percentile_index < len(percentile_list): # <<<<<<<<<<<<<< + * result_list.append(next_val) + * + */ + __pyx_t_12 = PyObject_Length(__pyx_v_percentile_list); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 797, __pyx_L1_error) + __pyx_t_15 = ((__pyx_v_percentile_index < __pyx_t_12) != 0); + if (__pyx_t_15) { + + /* "pygeoprocessing/geoprocessing_core.pyx":798 + * fast_file_iterator_vector.pop_back() + * if percentile_index < len(percentile_list): + * result_list.append(next_val) # <<<<<<<<<<<<<< + * + * # free all the iterator memory + */ + __pyx_t_11 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_next_val); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 798, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_22 = __Pyx_PyList_Append(__pyx_v_result_list, __pyx_t_11); if (unlikely(__pyx_t_22 == ((int)-1))) __PYX_ERR(0, 798, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":797 + * del fast_file_iterator + * fast_file_iterator_vector.pop_back() + * if percentile_index < len(percentile_list): # <<<<<<<<<<<<<< + * result_list.append(next_val) + * + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":801 + * + * # free all the iterator memory + * ffiv_iter = fast_file_iterator_vector.begin() # <<<<<<<<<<<<<< + * while ffiv_iter != fast_file_iterator_vector.end(): + * fast_file_iterator = deref(ffiv_iter) + */ + __pyx_v_ffiv_iter = __pyx_v_fast_file_iterator_vector.begin(); + + /* "pygeoprocessing/geoprocessing_core.pyx":802 + * # free all the iterator memory + * ffiv_iter = fast_file_iterator_vector.begin() + * while ffiv_iter != fast_file_iterator_vector.end(): # <<<<<<<<<<<<<< + * fast_file_iterator = deref(ffiv_iter) + * del fast_file_iterator + */ + while (1) { + __pyx_t_15 = ((__pyx_v_ffiv_iter != __pyx_v_fast_file_iterator_vector.end()) != 0); + if (!__pyx_t_15) break; + + /* "pygeoprocessing/geoprocessing_core.pyx":803 + * ffiv_iter = fast_file_iterator_vector.begin() + * while ffiv_iter != fast_file_iterator_vector.end(): + * fast_file_iterator = deref(ffiv_iter) # <<<<<<<<<<<<<< + * del fast_file_iterator + * inc(ffiv_iter) + */ + __pyx_v_fast_file_iterator = (*__pyx_v_ffiv_iter); + + /* "pygeoprocessing/geoprocessing_core.pyx":804 + * while ffiv_iter != fast_file_iterator_vector.end(): + * fast_file_iterator = deref(ffiv_iter) + * del fast_file_iterator # <<<<<<<<<<<<<< + * inc(ffiv_iter) + * fast_file_iterator_vector.clear() + */ + delete __pyx_v_fast_file_iterator; + + /* "pygeoprocessing/geoprocessing_core.pyx":805 + * fast_file_iterator = deref(ffiv_iter) + * del fast_file_iterator + * inc(ffiv_iter) # <<<<<<<<<<<<<< + * fast_file_iterator_vector.clear() + * # delete all the heap files + */ + (void)((++__pyx_v_ffiv_iter)); + } + + /* "pygeoprocessing/geoprocessing_core.pyx":806 + * del fast_file_iterator + * inc(ffiv_iter) + * fast_file_iterator_vector.clear() # <<<<<<<<<<<<<< + * # delete all the heap files + * for file_path in heapfile_list: + */ + __pyx_v_fast_file_iterator_vector.clear(); + + /* "pygeoprocessing/geoprocessing_core.pyx":808 + * fast_file_iterator_vector.clear() + * # delete all the heap files + * for file_path in heapfile_list: # <<<<<<<<<<<<<< + * try: + * os.remove(file_path) + */ + __pyx_t_11 = __pyx_v_heapfile_list; __Pyx_INCREF(__pyx_t_11); __pyx_t_12 = 0; + for (;;) { + if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_11)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_6 = PyList_GET_ITEM(__pyx_t_11, __pyx_t_12); __Pyx_INCREF(__pyx_t_6); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 808, __pyx_L1_error) + #else + __pyx_t_6 = PySequence_ITEM(__pyx_t_11, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 808, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + #endif + __Pyx_XDECREF_SET(__pyx_v_file_path, __pyx_t_6); + __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":809 + * # delete all the heap files + * for file_path in heapfile_list: + * try: # <<<<<<<<<<<<<< + * os.remove(file_path) + * except OSError: + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_4, &__pyx_t_3, &__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_2); + /*try:*/ { + + /* "pygeoprocessing/geoprocessing_core.pyx":810 + * for file_path in heapfile_list: + * try: + * os.remove(file_path) # <<<<<<<<<<<<<< + * except OSError: + * # you never know if this might fail! + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_os); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 810, __pyx_L27_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_remove); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 810, __pyx_L27_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + __pyx_t_6 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_8, __pyx_v_file_path) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_file_path); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 810, __pyx_L27_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":809 + * # delete all the heap files + * for file_path in heapfile_list: + * try: # <<<<<<<<<<<<<< + * os.remove(file_path) + * except OSError: + */ + } + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L34_try_end; + __pyx_L27_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; + __PYX_XDEC_MEMVIEW(&__pyx_t_21, 1); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":811 + * try: + * os.remove(file_path) + * except OSError: # <<<<<<<<<<<<<< + * # you never know if this might fail! + * LOGGER.warning('unable to remove %s', file_path) + */ + __pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OSError); + if (__pyx_t_7) { + __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core._raster_band_percentile_int", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_5, &__pyx_t_8) < 0) __PYX_ERR(0, 811, __pyx_L29_except_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_8); + + /* "pygeoprocessing/geoprocessing_core.pyx":813 + * except OSError: + * # you never know if this might fail! + * LOGGER.warning('unable to remove %s', file_path) # <<<<<<<<<<<<<< + * if rm_dir_when_done: + * shutil.rmtree(working_sort_directory) + */ + __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 813, __pyx_L29_except_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_warning); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 813, __pyx_L29_except_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = NULL; + __pyx_t_7 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_20))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_20); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_20); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_20, function); + __pyx_t_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_20)) { + PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_kp_u_unable_to_remove_s, __pyx_v_file_path}; + __pyx_t_19 = __Pyx_PyFunction_FastCall(__pyx_t_20, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 813, __pyx_L29_except_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_19); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_20)) { + PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_kp_u_unable_to_remove_s, __pyx_v_file_path}; + __pyx_t_19 = __Pyx_PyCFunction_FastCall(__pyx_t_20, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 813, __pyx_L29_except_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_19); + } else + #endif + { + __pyx_t_1 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 813, __pyx_L29_except_error) + __Pyx_GOTREF(__pyx_t_1); + if (__pyx_t_10) { + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_10); __pyx_t_10 = NULL; + } + __Pyx_INCREF(__pyx_kp_u_unable_to_remove_s); + __Pyx_GIVEREF(__pyx_kp_u_unable_to_remove_s); + PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_7, __pyx_kp_u_unable_to_remove_s); + __Pyx_INCREF(__pyx_v_file_path); + __Pyx_GIVEREF(__pyx_v_file_path); + PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_7, __pyx_v_file_path); + __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_20, __pyx_t_1, NULL); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 813, __pyx_L29_except_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L28_exception_handled; + } + goto __pyx_L29_except_error; + __pyx_L29_except_error:; + + /* "pygeoprocessing/geoprocessing_core.pyx":809 + * # delete all the heap files + * for file_path in heapfile_list: + * try: # <<<<<<<<<<<<<< + * os.remove(file_path) + * except OSError: + */ + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_3, __pyx_t_2); + goto __pyx_L1_error; + __pyx_L28_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_3, __pyx_t_2); + __pyx_L34_try_end:; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":808 + * fast_file_iterator_vector.clear() + * # delete all the heap files + * for file_path in heapfile_list: # <<<<<<<<<<<<<< + * try: + * os.remove(file_path) + */ + } + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":814 + * # you never know if this might fail! + * LOGGER.warning('unable to remove %s', file_path) + * if rm_dir_when_done: # <<<<<<<<<<<<<< + * shutil.rmtree(working_sort_directory) + * return result_list + */ + __pyx_t_15 = (__pyx_v_rm_dir_when_done != 0); + if (__pyx_t_15) { + + /* "pygeoprocessing/geoprocessing_core.pyx":815 + * LOGGER.warning('unable to remove %s', file_path) + * if rm_dir_when_done: + * shutil.rmtree(working_sort_directory) # <<<<<<<<<<<<<< + * return result_list + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_shutil); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 815, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_rmtree); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 815, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + __pyx_t_11 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_8, __pyx_v_working_sort_directory) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_working_sort_directory); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 815, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":814 + * # you never know if this might fail! + * LOGGER.warning('unable to remove %s', file_path) + * if rm_dir_when_done: # <<<<<<<<<<<<<< + * shutil.rmtree(working_sort_directory) + * return result_list + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":816 + * if rm_dir_when_done: + * shutil.rmtree(working_sort_directory) + * return result_list # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_result_list); + __pyx_r = __pyx_v_result_list; + goto __pyx_L0; + + /* "pygeoprocessing/geoprocessing_core.pyx":673 + * + * + * def _raster_band_percentile_int( # <<<<<<<<<<<<<< + * base_raster_path_band, working_sort_directory, percentile_list, + * heap_buffer_size, ffi_buffer_size): + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_19); + __Pyx_XDECREF(__pyx_t_20); + __PYX_XDEC_MEMVIEW(&__pyx_t_21, 1); + __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core._raster_band_percentile_int", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_result_list); + __PYX_XDEC_MEMVIEW(&__pyx_v_buffer_data, 1); + __Pyx_XDECREF(__pyx_v_heapfile_list); + __Pyx_XDECREF(__pyx_v_file_index); + __Pyx_XDECREF(__pyx_v_raster_info); + __Pyx_XDECREF(__pyx_v_nodata); + __Pyx_XDECREF(__pyx_v_last_update); + __Pyx_XDECREF(__pyx_v__); + __Pyx_XDECREF(__pyx_v_block_data); + __Pyx_XDECREF(__pyx_v_file_path); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pygeoprocessing/geoprocessing_core.pyx":819 + * + * + * def _raster_band_percentile_double( # <<<<<<<<<<<<<< + * base_raster_path_band, working_sort_directory, percentile_list, + * heap_buffer_size, ffi_buffer_size): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_11_raster_band_percentile_double(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_15pygeoprocessing_18geoprocessing_core_10_raster_band_percentile_double[] = "Calculate percentiles of a raster band of a real type.\n\n Parameters:\n base_raster_path_band (tuple): raster path band tuple to raster that\n is a real/float type.\n working_sort_directory (str): path to a directory that does not\n exist or is empty. This directory will be used to create heapfiles\n with sizes no larger than ``heap_buffer_size`` which are written in the\n of the pattern N.dat where N is in the numbering 0, 1, 2, ... up\n to the number of files necessary to handle the raster.\n percentile_list (list): sorted list of percentiles to report must\n contain values in the range [0, 100].\n heap_buffer_size (int): defines approximately how many elements to hold in\n a single heap file. This is proportional to the amount of maximum\n memory to use when storing elements before a sort and write to\n disk.\n ffi_buffer_size (int): defines how many elements to store in a file\n buffer at any time.\n\n Returns:\n A list of len(percentile_list) elements long containing the\n percentile values (ranging from [0, 100]) in ``base_raster_path_band``\n where the interpolation scheme is \"higher\" (i.e. any percentile splits\n will select the next element higher than the percentile cutoff).\n\n "; +static PyMethodDef __pyx_mdef_15pygeoprocessing_18geoprocessing_core_11_raster_band_percentile_double = {"_raster_band_percentile_double", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_18geoprocessing_core_11_raster_band_percentile_double, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_18geoprocessing_core_10_raster_band_percentile_double}; +static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_11_raster_band_percentile_double(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_base_raster_path_band = 0; + PyObject *__pyx_v_working_sort_directory = 0; + PyObject *__pyx_v_percentile_list = 0; + PyObject *__pyx_v_heap_buffer_size = 0; + PyObject *__pyx_v_ffi_buffer_size = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_raster_band_percentile_double (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_base_raster_path_band,&__pyx_n_s_working_sort_directory,&__pyx_n_s_percentile_list,&__pyx_n_s_heap_buffer_size,&__pyx_n_s_ffi_buffer_size,0}; + PyObject* values[5] = {0,0,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 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_base_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_working_sort_directory)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_raster_band_percentile_double", 1, 5, 5, 1); __PYX_ERR(0, 819, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_percentile_list)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_raster_band_percentile_double", 1, 5, 5, 2); __PYX_ERR(0, 819, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 3: + if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_heap_buffer_size)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_raster_band_percentile_double", 1, 5, 5, 3); __PYX_ERR(0, 819, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 4: + if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_ffi_buffer_size)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_raster_band_percentile_double", 1, 5, 5, 4); __PYX_ERR(0, 819, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_raster_band_percentile_double") < 0)) __PYX_ERR(0, 819, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 5) { + 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); + values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + } + __pyx_v_base_raster_path_band = values[0]; + __pyx_v_working_sort_directory = values[1]; + __pyx_v_percentile_list = values[2]; + __pyx_v_heap_buffer_size = values[3]; + __pyx_v_ffi_buffer_size = values[4]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("_raster_band_percentile_double", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 819, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core._raster_band_percentile_double", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_15pygeoprocessing_18geoprocessing_core_10_raster_band_percentile_double(__pyx_self, __pyx_v_base_raster_path_band, __pyx_v_working_sort_directory, __pyx_v_percentile_list, __pyx_v_heap_buffer_size, __pyx_v_ffi_buffer_size); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core_10_raster_band_percentile_double(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_base_raster_path_band, PyObject *__pyx_v_working_sort_directory, PyObject *__pyx_v_percentile_list, PyObject *__pyx_v_heap_buffer_size, PyObject *__pyx_v_ffi_buffer_size) { + FILE *__pyx_v_fptr; + __Pyx_memviewslice __pyx_v_buffer_data = { 0, 0, { 0 }, { 0 }, { 0 } }; + __pyx_t_15pygeoprocessing_18geoprocessing_core_FastFileIteratorDoublePtr __pyx_v_fast_file_iterator; + std::vector<__pyx_t_15pygeoprocessing_18geoprocessing_core_FastFileIteratorDoublePtr> __pyx_v_fast_file_iterator_vector; + int __pyx_v_percentile_index; + PY_LONG_LONG __pyx_v_i; + PY_LONG_LONG __pyx_v_n_elements; + double __pyx_v_next_val; + double __pyx_v_current_step; + double __pyx_v_step_size; + double __pyx_v_current_percentile; + PyObject *__pyx_v_result_list = NULL; + int __pyx_v_rm_dir_when_done; + PyObject *__pyx_v_e = NULL; + PyObject *__pyx_v_file_index = NULL; + PyObject *__pyx_v_nodata = NULL; + PyObject *__pyx_v_heapfile_list = NULL; + PyObject *__pyx_v_raster_info = NULL; + PY_LONG_LONG __pyx_v_n_pixels; + PY_LONG_LONG __pyx_v_pixels_processed; + PyObject *__pyx_v_last_update = NULL; + CYTHON_UNUSED PyObject *__pyx_v__ = NULL; + PyObject *__pyx_v_block_data = NULL; + PyObject *__pyx_v_file_path = NULL; + std::vector<__pyx_t_15pygeoprocessing_18geoprocessing_core_FastFileIteratorDoublePtr> ::iterator __pyx_v_ffiv_iter; + 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; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + int __pyx_t_13; + char const *__pyx_t_14; + PyObject *__pyx_t_15 = NULL; + PyObject *__pyx_t_16 = NULL; + PyObject *__pyx_t_17 = NULL; + PyObject *__pyx_t_18 = NULL; + PyObject *__pyx_t_19 = NULL; + PyObject *__pyx_t_20 = NULL; + PY_LONG_LONG __pyx_t_21; + Py_ssize_t __pyx_t_22; + PyObject *(*__pyx_t_23)(PyObject *); + PyObject *(*__pyx_t_24)(PyObject *); + int __pyx_t_25; + Py_ssize_t __pyx_t_26; + Py_UCS4 __pyx_t_27; + double __pyx_t_28; + __Pyx_memviewslice __pyx_t_29 = { 0, 0, { 0 }, { 0 }, { 0 } }; + int __pyx_t_30; + char const *__pyx_t_31; + Py_ssize_t __pyx_t_32; + size_t __pyx_t_33; + char const *__pyx_t_34; + PY_LONG_LONG __pyx_t_35; + PY_LONG_LONG __pyx_t_36; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_raster_band_percentile_double", 0); + + /* "pygeoprocessing/geoprocessing_core.pyx":852 + * cdef FastFileIteratorDoublePtr fast_file_iterator + * cdef vector[FastFileIteratorDoublePtr] fast_file_iterator_vector + * cdef int percentile_index = 0 # <<<<<<<<<<<<<< + * cdef long long i, n_elements = 0 + * cdef double next_val = 0.0 + */ + __pyx_v_percentile_index = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":853 + * cdef vector[FastFileIteratorDoublePtr] fast_file_iterator_vector + * cdef int percentile_index = 0 + * cdef long long i, n_elements = 0 # <<<<<<<<<<<<<< + * cdef double next_val = 0.0 + * cdef double current_step = 0.0 + */ + __pyx_v_n_elements = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":854 + * cdef int percentile_index = 0 + * cdef long long i, n_elements = 0 + * cdef double next_val = 0.0 # <<<<<<<<<<<<<< + * cdef double current_step = 0.0 + * cdef double step_size, current_percentile + */ + __pyx_v_next_val = 0.0; + + /* "pygeoprocessing/geoprocessing_core.pyx":855 + * cdef long long i, n_elements = 0 + * cdef double next_val = 0.0 + * cdef double current_step = 0.0 # <<<<<<<<<<<<<< + * cdef double step_size, current_percentile + * result_list = [] + */ + __pyx_v_current_step = 0.0; + + /* "pygeoprocessing/geoprocessing_core.pyx":857 + * cdef double current_step = 0.0 + * cdef double step_size, current_percentile + * result_list = [] # <<<<<<<<<<<<<< + * rm_dir_when_done = False + * try: + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 857, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_result_list = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":858 + * cdef double step_size, current_percentile + * result_list = [] + * rm_dir_when_done = False # <<<<<<<<<<<<<< + * try: + * os.makedirs(working_sort_directory) + */ + __pyx_v_rm_dir_when_done = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":859 + * result_list = [] + * rm_dir_when_done = False + * try: # <<<<<<<<<<<<<< + * os.makedirs(working_sort_directory) + * rm_dir_when_done = True + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_2, &__pyx_t_3, &__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_4); + /*try:*/ { + + /* "pygeoprocessing/geoprocessing_core.pyx":860 + * rm_dir_when_done = False + * try: + * os.makedirs(working_sort_directory) # <<<<<<<<<<<<<< + * rm_dir_when_done = True + * except OSError as e: + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_os); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 860, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_makedirs); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 860, __pyx_L3_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_6))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_v_working_sort_directory) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_working_sort_directory); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 860, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":861 + * try: + * os.makedirs(working_sort_directory) + * rm_dir_when_done = True # <<<<<<<<<<<<<< + * except OSError as e: + * LOGGER.warning("couldn't make working_sort_directory: %s", str(e)) + */ + __pyx_v_rm_dir_when_done = 1; + + /* "pygeoprocessing/geoprocessing_core.pyx":859 + * result_list = [] + * rm_dir_when_done = False + * try: # <<<<<<<<<<<<<< + * os.makedirs(working_sort_directory) + * rm_dir_when_done = True + */ + } + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L8_try_end; + __pyx_L3_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":862 + * os.makedirs(working_sort_directory) + * rm_dir_when_done = True + * except OSError as e: # <<<<<<<<<<<<<< + * LOGGER.warning("couldn't make working_sort_directory: %s", str(e)) + * file_index = 0 + */ + __pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OSError); + if (__pyx_t_7) { + __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core._raster_band_percentile_double", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_6, &__pyx_t_5) < 0) __PYX_ERR(0, 862, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_t_6); + __pyx_v_e = __pyx_t_6; + /*try:*/ { + + /* "pygeoprocessing/geoprocessing_core.pyx":863 + * rm_dir_when_done = True + * except OSError as e: + * LOGGER.warning("couldn't make working_sort_directory: %s", str(e)) # <<<<<<<<<<<<<< + * file_index = 0 + * nodata = pygeoprocessing.get_raster_info( + */ + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 863, __pyx_L14_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_warning); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 863, __pyx_L14_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_v_e); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 863, __pyx_L14_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_11 = NULL; + __pyx_t_7 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_10); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_10, function); + __pyx_t_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_10)) { + PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_kp_u_couldn_t_make_working_sort_direc, __pyx_t_9}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 863, __pyx_L14_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 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_10)) { + PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_kp_u_couldn_t_make_working_sort_direc, __pyx_t_9}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 863, __pyx_L14_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + { + __pyx_t_12 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 863, __pyx_L14_error) + __Pyx_GOTREF(__pyx_t_12); + if (__pyx_t_11) { + __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11); __pyx_t_11 = NULL; + } + __Pyx_INCREF(__pyx_kp_u_couldn_t_make_working_sort_direc); + __Pyx_GIVEREF(__pyx_kp_u_couldn_t_make_working_sort_direc); + PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_7, __pyx_kp_u_couldn_t_make_working_sort_direc); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_7, __pyx_t_9); + __pyx_t_9 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_12, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 863, __pyx_L14_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":862 + * os.makedirs(working_sort_directory) + * rm_dir_when_done = True + * except OSError as e: # <<<<<<<<<<<<<< + * LOGGER.warning("couldn't make working_sort_directory: %s", str(e)) + * file_index = 0 + */ + /*finally:*/ { + /*normal exit:*/{ + __Pyx_DECREF(__pyx_v_e); + __pyx_v_e = NULL; + goto __pyx_L15; + } + __pyx_L14_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17) < 0)) __Pyx_ErrFetch(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17); + __Pyx_XGOTREF(__pyx_t_15); + __Pyx_XGOTREF(__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_17); + __Pyx_XGOTREF(__pyx_t_18); + __Pyx_XGOTREF(__pyx_t_19); + __Pyx_XGOTREF(__pyx_t_20); + __pyx_t_7 = __pyx_lineno; __pyx_t_13 = __pyx_clineno; __pyx_t_14 = __pyx_filename; + { + __Pyx_DECREF(__pyx_v_e); + __pyx_v_e = NULL; + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_18); + __Pyx_XGIVEREF(__pyx_t_19); + __Pyx_XGIVEREF(__pyx_t_20); + __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_19, __pyx_t_20); + } + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_ErrRestore(__pyx_t_15, __pyx_t_16, __pyx_t_17); + __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; + __pyx_lineno = __pyx_t_7; __pyx_clineno = __pyx_t_13; __pyx_filename = __pyx_t_14; + goto __pyx_L5_except_error; + } + __pyx_L15:; + } + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L4_exception_handled; + } + goto __pyx_L5_except_error; + __pyx_L5_except_error:; + + /* "pygeoprocessing/geoprocessing_core.pyx":859 + * result_list = [] + * rm_dir_when_done = False + * try: # <<<<<<<<<<<<<< + * os.makedirs(working_sort_directory) + * rm_dir_when_done = True + */ + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4); + goto __pyx_L1_error; + __pyx_L4_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4); + __pyx_L8_try_end:; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":864 + * except OSError as e: + * LOGGER.warning("couldn't make working_sort_directory: %s", str(e)) + * file_index = 0 # <<<<<<<<<<<<<< + * nodata = pygeoprocessing.get_raster_info( + * base_raster_path_band[0])['nodata'][base_raster_path_band[1]-1] + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_v_file_index = __pyx_int_0; + + /* "pygeoprocessing/geoprocessing_core.pyx":865 + * LOGGER.warning("couldn't make working_sort_directory: %s", str(e)) + * file_index = 0 + * nodata = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< + * base_raster_path_band[0])['nodata'][base_raster_path_band[1]-1] + * heapfile_list = [] + */ + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 865, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 865, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":866 + * file_index = 0 + * nodata = pygeoprocessing.get_raster_info( + * base_raster_path_band[0])['nodata'][base_raster_path_band[1]-1] # <<<<<<<<<<<<<< + * heapfile_list = [] + * + */ + __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_base_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 866, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_5 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_6); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 865, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_t_5, __pyx_n_u_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 866, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_base_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 866, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyInt_SubtractObjC(__pyx_t_5, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 866, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 866, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_nodata = __pyx_t_5; + __pyx_t_5 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":867 + * nodata = pygeoprocessing.get_raster_info( + * base_raster_path_band[0])['nodata'][base_raster_path_band[1]-1] + * heapfile_list = [] # <<<<<<<<<<<<<< + * + * raster_info = pygeoprocessing.get_raster_info( + */ + __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 867, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_v_heapfile_list = ((PyObject*)__pyx_t_5); + __pyx_t_5 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":869 + * heapfile_list = [] + * + * raster_info = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< + * base_raster_path_band[0]) + * nodata = raster_info['nodata'][base_raster_path_band[1]-1] + */ + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 869, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 869, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":870 + * + * raster_info = pygeoprocessing.get_raster_info( + * base_raster_path_band[0]) # <<<<<<<<<<<<<< + * nodata = raster_info['nodata'][base_raster_path_band[1]-1] + * cdef long long n_pixels = ( + */ + __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_base_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 870, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_5 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_6); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 869, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_raster_info = __pyx_t_5; + __pyx_t_5 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":871 + * raster_info = pygeoprocessing.get_raster_info( + * base_raster_path_band[0]) + * nodata = raster_info['nodata'][base_raster_path_band[1]-1] # <<<<<<<<<<<<<< + * cdef long long n_pixels = ( + * raster_info['raster_size'][0] * raster_info['raster_size'][1]) + */ + __pyx_t_5 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_nodata); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 871, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_base_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 871, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = __Pyx_PyInt_SubtractObjC(__pyx_t_1, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 871, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 871, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF_SET(__pyx_v_nodata, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":873 + * nodata = raster_info['nodata'][base_raster_path_band[1]-1] + * cdef long long n_pixels = ( + * raster_info['raster_size'][0] * raster_info['raster_size'][1]) # <<<<<<<<<<<<<< + * cdef long long pixels_processed = 0 + * + */ + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 873, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 873, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 873, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_1, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 873, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Multiply(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 873, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_21 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_21 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 873, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_n_pixels = __pyx_t_21; + + /* "pygeoprocessing/geoprocessing_core.pyx":874 + * cdef long long n_pixels = ( + * raster_info['raster_size'][0] * raster_info['raster_size'][1]) + * cdef long long pixels_processed = 0 # <<<<<<<<<<<<<< + * + * last_update = time.time() + */ + __pyx_v_pixels_processed = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":876 + * cdef long long pixels_processed = 0 + * + * last_update = time.time() # <<<<<<<<<<<<<< + * LOGGER.debug('sorting data to heap') + * for _, block_data in pygeoprocessing.iterblocks( + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 876, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 876, __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_6))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 876, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_last_update = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":877 + * + * last_update = time.time() + * LOGGER.debug('sorting data to heap') # <<<<<<<<<<<<<< + * for _, block_data in pygeoprocessing.iterblocks( + * base_raster_path_band, largest_block=heap_buffer_size): + */ + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 877, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_debug); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 877, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __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); + } + } + __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_kp_u_sorting_data_to_heap) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_kp_u_sorting_data_to_heap); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 877, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":878 + * last_update = time.time() + * LOGGER.debug('sorting data to heap') + * for _, block_data in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * base_raster_path_band, largest_block=heap_buffer_size): + * pixels_processed += block_data.size + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 878, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 878, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":879 + * LOGGER.debug('sorting data to heap') + * for _, block_data in pygeoprocessing.iterblocks( + * base_raster_path_band, largest_block=heap_buffer_size): # <<<<<<<<<<<<<< + * pixels_processed += block_data.size + * if time.time() - last_update > 5.0: + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 878, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_base_raster_path_band); + __Pyx_GIVEREF(__pyx_v_base_raster_path_band); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_base_raster_path_band); + __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 879, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_largest_block, __pyx_v_heap_buffer_size) < 0) __PYX_ERR(0, 879, __pyx_L1_error) + + /* "pygeoprocessing/geoprocessing_core.pyx":878 + * last_update = time.time() + * LOGGER.debug('sorting data to heap') + * for _, block_data in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * base_raster_path_band, largest_block=heap_buffer_size): + * pixels_processed += block_data.size + */ + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 878, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (likely(PyList_CheckExact(__pyx_t_8)) || PyTuple_CheckExact(__pyx_t_8)) { + __pyx_t_6 = __pyx_t_8; __Pyx_INCREF(__pyx_t_6); __pyx_t_22 = 0; + __pyx_t_23 = NULL; + } else { + __pyx_t_22 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 878, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_23 = Py_TYPE(__pyx_t_6)->tp_iternext; if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 878, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + for (;;) { + if (likely(!__pyx_t_23)) { + if (likely(PyList_CheckExact(__pyx_t_6))) { + if (__pyx_t_22 >= PyList_GET_SIZE(__pyx_t_6)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_8 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_22); __Pyx_INCREF(__pyx_t_8); __pyx_t_22++; if (unlikely(0 < 0)) __PYX_ERR(0, 878, __pyx_L1_error) + #else + __pyx_t_8 = PySequence_ITEM(__pyx_t_6, __pyx_t_22); __pyx_t_22++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 878, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + #endif + } else { + if (__pyx_t_22 >= PyTuple_GET_SIZE(__pyx_t_6)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_22); __Pyx_INCREF(__pyx_t_8); __pyx_t_22++; if (unlikely(0 < 0)) __PYX_ERR(0, 878, __pyx_L1_error) + #else + __pyx_t_8 = PySequence_ITEM(__pyx_t_6, __pyx_t_22); __pyx_t_22++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 878, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + #endif + } + } else { + __pyx_t_8 = __pyx_t_23(__pyx_t_6); + if (unlikely(!__pyx_t_8)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 878, __pyx_L1_error) + } + break; + } + __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, 878, __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_5 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_1 = PyList_GET_ITEM(sequence, 0); + __pyx_t_5 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_5); + #else + __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 878, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 878, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_10 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 878, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_24 = Py_TYPE(__pyx_t_10)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_24(__pyx_t_10); if (unlikely(!__pyx_t_1)) goto __pyx_L22_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 1; __pyx_t_5 = __pyx_t_24(__pyx_t_10); if (unlikely(!__pyx_t_5)) goto __pyx_L22_unpacking_failed; + __Pyx_GOTREF(__pyx_t_5); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_24(__pyx_t_10), 2) < 0) __PYX_ERR(0, 878, __pyx_L1_error) + __pyx_t_24 = NULL; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + goto __pyx_L23_unpacking_done; + __pyx_L22_unpacking_failed:; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_24 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 878, __pyx_L1_error) + __pyx_L23_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_1); + __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_block_data, __pyx_t_5); + __pyx_t_5 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":880 + * for _, block_data in pygeoprocessing.iterblocks( + * base_raster_path_band, largest_block=heap_buffer_size): + * pixels_processed += block_data.size # <<<<<<<<<<<<<< + * if time.time() - last_update > 5.0: + * LOGGER.debug( + */ + __pyx_t_8 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_pixels_processed); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 880, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_block_data, __pyx_n_s_size); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 880, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_t_8, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 880, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_21 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_21 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 880, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_pixels_processed = __pyx_t_21; + + /* "pygeoprocessing/geoprocessing_core.pyx":881 + * base_raster_path_band, largest_block=heap_buffer_size): + * pixels_processed += block_data.size + * if time.time() - last_update > 5.0: # <<<<<<<<<<<<<< + * LOGGER.debug( + * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 881, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 881, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 881, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = PyNumber_Subtract(__pyx_t_1, __pyx_v_last_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 881, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_RichCompare(__pyx_t_8, __pyx_float_5_0, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 881, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_25 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_25 < 0)) __PYX_ERR(0, 881, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_25) { + + /* "pygeoprocessing/geoprocessing_core.pyx":882 + * pixels_processed += block_data.size + * if time.time() - last_update > 5.0: + * LOGGER.debug( # <<<<<<<<<<<<<< + * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' + * f'complete, {pixels_processed} out of {n_pixels}'), + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 882, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_debug); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 882, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":883 + * if time.time() - last_update > 5.0: + * LOGGER.debug( + * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' # <<<<<<<<<<<<<< + * f'complete, {pixels_processed} out of {n_pixels}'), + * + */ + __pyx_t_8 = PyTuple_New(6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 883, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_26 = 0; + __pyx_t_27 = 127; + __Pyx_INCREF(__pyx_kp_u_data_sort_to_heap); + __pyx_t_26 += 18; + __Pyx_GIVEREF(__pyx_kp_u_data_sort_to_heap); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_kp_u_data_sort_to_heap); + __pyx_t_28 = (100. * __pyx_v_pixels_processed); + if (unlikely(__pyx_v_n_pixels == 0)) { + PyErr_SetString(PyExc_ZeroDivisionError, "float division"); + __PYX_ERR(0, 883, __pyx_L1_error) + } + __pyx_t_10 = PyFloat_FromDouble((__pyx_t_28 / ((double)__pyx_v_n_pixels))); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 883, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_12 = __Pyx_PyObject_Format(__pyx_t_10, __pyx_kp_u_1f); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 883, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_27 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_12) > __pyx_t_27) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_12) : __pyx_t_27; + __pyx_t_26 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_12); + __Pyx_GIVEREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_12); + __pyx_t_12 = 0; + __Pyx_INCREF(__pyx_kp_u_complete); + __pyx_t_26 += 12; + __Pyx_GIVEREF(__pyx_kp_u_complete); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_kp_u_complete); + + /* "pygeoprocessing/geoprocessing_core.pyx":884 + * LOGGER.debug( + * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' + * f'complete, {pixels_processed} out of {n_pixels}'), # <<<<<<<<<<<<<< + * + * last_update = time.time() + */ + __pyx_t_12 = __Pyx_PyUnicode_From_PY_LONG_LONG(__pyx_v_pixels_processed, 0, ' ', 'd'); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 884, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_26 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_12); + __Pyx_GIVEREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_12); + __pyx_t_12 = 0; + __Pyx_INCREF(__pyx_kp_u_out_of); + __pyx_t_26 += 8; + __Pyx_GIVEREF(__pyx_kp_u_out_of); + PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_kp_u_out_of); + __pyx_t_12 = __Pyx_PyUnicode_From_PY_LONG_LONG(__pyx_v_n_pixels, 0, ' ', 'd'); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 884, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_26 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_12); + __Pyx_GIVEREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_8, 5, __pyx_t_12); + __pyx_t_12 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":883 + * if time.time() - last_update > 5.0: + * LOGGER.debug( + * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' # <<<<<<<<<<<<<< + * f'complete, {pixels_processed} out of {n_pixels}'), + * + */ + __pyx_t_12 = __Pyx_PyUnicode_Join(__pyx_t_8, 6, __pyx_t_26, __pyx_t_27); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 883, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_8, __pyx_t_12) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_12); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 882, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":882 + * pixels_processed += block_data.size + * if time.time() - last_update > 5.0: + * LOGGER.debug( # <<<<<<<<<<<<<< + * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' + * f'complete, {pixels_processed} out of {n_pixels}'), + */ + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 882, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); + __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":886 + * f'complete, {pixels_processed} out of {n_pixels}'), + * + * last_update = time.time() # <<<<<<<<<<<<<< + * buffer_data = numpy.sort( + * block_data[~numpy.isclose(block_data, nodata)]).astype( + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_time); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 886, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_time); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 886, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + } + } + __pyx_t_5 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 886, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF_SET(__pyx_v_last_update, __pyx_t_5); + __pyx_t_5 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":881 + * base_raster_path_band, largest_block=heap_buffer_size): + * pixels_processed += block_data.size + * if time.time() - last_update > 5.0: # <<<<<<<<<<<<<< + * LOGGER.debug( + * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":887 + * + * last_update = time.time() + * buffer_data = numpy.sort( # <<<<<<<<<<<<<< + * block_data[~numpy.isclose(block_data, nodata)]).astype( + * numpy.double) + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 887, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_sort); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 887, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":888 + * last_update = time.time() + * buffer_data = numpy.sort( + * block_data[~numpy.isclose(block_data, nodata)]).astype( # <<<<<<<<<<<<<< + * numpy.double) + * if buffer_data.size == 0: + */ + __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_numpy); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 888, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_isclose); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 888, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = NULL; + __pyx_t_13 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + __pyx_t_13 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_block_data, __pyx_v_nodata}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 888, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_block_data, __pyx_v_nodata}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 888, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_11 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 888, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + if (__pyx_t_10) { + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10); __pyx_t_10 = NULL; + } + __Pyx_INCREF(__pyx_v_block_data); + __Pyx_GIVEREF(__pyx_v_block_data); + PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_13, __pyx_v_block_data); + __Pyx_INCREF(__pyx_v_nodata); + __Pyx_GIVEREF(__pyx_v_nodata); + PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_13, __pyx_v_nodata); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_11, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 888, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = PyNumber_Invert(__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 888, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_block_data, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 888, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(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); + } + } + __pyx_t_12 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_9, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_1); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 887, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_astype); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 888, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":889 + * buffer_data = numpy.sort( + * block_data[~numpy.isclose(block_data, nodata)]).astype( + * numpy.double) # <<<<<<<<<<<<<< + * if buffer_data.size == 0: + * continue + */ + __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_numpy); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 889, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_double); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 889, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_12)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_5 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_12, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_1); + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 888, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":888 + * last_update = time.time() + * buffer_data = numpy.sort( + * block_data[~numpy.isclose(block_data, nodata)]).astype( # <<<<<<<<<<<<<< + * numpy.double) + * if buffer_data.size == 0: + */ + __pyx_t_29 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_29.memview)) __PYX_ERR(0, 888, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __PYX_XDEC_MEMVIEW(&__pyx_v_buffer_data, 1); + __pyx_v_buffer_data = __pyx_t_29; + __pyx_t_29.memview = NULL; + __pyx_t_29.data = NULL; + + /* "pygeoprocessing/geoprocessing_core.pyx":890 + * block_data[~numpy.isclose(block_data, nodata)]).astype( + * numpy.double) + * if buffer_data.size == 0: # <<<<<<<<<<<<<< + * continue + * n_elements += buffer_data.size + */ + __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_buffer_data, 1, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 890, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_size); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 890, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyInt_EqObjC(__pyx_t_8, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 890, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_25 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_25 < 0)) __PYX_ERR(0, 890, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_25) { + + /* "pygeoprocessing/geoprocessing_core.pyx":891 + * numpy.double) + * if buffer_data.size == 0: + * continue # <<<<<<<<<<<<<< + * n_elements += buffer_data.size + * file_path = os.path.join( + */ + goto __pyx_L20_continue; + + /* "pygeoprocessing/geoprocessing_core.pyx":890 + * block_data[~numpy.isclose(block_data, nodata)]).astype( + * numpy.double) + * if buffer_data.size == 0: # <<<<<<<<<<<<<< + * continue + * n_elements += buffer_data.size + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":892 + * if buffer_data.size == 0: + * continue + * n_elements += buffer_data.size # <<<<<<<<<<<<<< + * file_path = os.path.join( + * working_sort_directory, '%d.dat' % file_index) + */ + __pyx_t_5 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_n_elements); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 892, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_8 = __pyx_memoryview_fromslice(__pyx_v_buffer_data, 1, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 892, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 892, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = PyNumber_InPlaceAdd(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 892, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_21 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_t_8); if (unlikely((__pyx_t_21 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 892, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_n_elements = __pyx_t_21; + + /* "pygeoprocessing/geoprocessing_core.pyx":893 + * continue + * n_elements += buffer_data.size + * file_path = os.path.join( # <<<<<<<<<<<<<< + * working_sort_directory, '%d.dat' % file_index) + * heapfile_list.append(file_path) + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 893, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_path); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 893, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_join); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 893, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":894 + * n_elements += buffer_data.size + * file_path = os.path.join( + * working_sort_directory, '%d.dat' % file_index) # <<<<<<<<<<<<<< + * heapfile_list.append(file_path) + * fptr = fopen(bytes(file_path.encode()), "wb") + */ + __pyx_t_5 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_d_dat, __pyx_v_file_index); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 894, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_12 = NULL; + __pyx_t_13 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_12)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_12); + __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_12, __pyx_v_working_sort_directory, __pyx_t_5}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 893, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_8); + __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[3] = {__pyx_t_12, __pyx_v_working_sort_directory, __pyx_t_5}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 893, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_9 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 893, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + if (__pyx_t_12) { + __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_12); __pyx_t_12 = NULL; + } + __Pyx_INCREF(__pyx_v_working_sort_directory); + __Pyx_GIVEREF(__pyx_v_working_sort_directory); + PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_13, __pyx_v_working_sort_directory); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_13, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 893, __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_XDECREF_SET(__pyx_v_file_path, __pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":895 + * file_path = os.path.join( + * working_sort_directory, '%d.dat' % file_index) + * heapfile_list.append(file_path) # <<<<<<<<<<<<<< + * fptr = fopen(bytes(file_path.encode()), "wb") + * fwrite( + */ + __pyx_t_30 = __Pyx_PyList_Append(__pyx_v_heapfile_list, __pyx_v_file_path); if (unlikely(__pyx_t_30 == ((int)-1))) __PYX_ERR(0, 895, __pyx_L1_error) + + /* "pygeoprocessing/geoprocessing_core.pyx":896 + * working_sort_directory, '%d.dat' % file_index) + * heapfile_list.append(file_path) + * fptr = fopen(bytes(file_path.encode()), "wb") # <<<<<<<<<<<<<< + * fwrite( + * &buffer_data[0], sizeof(double), buffer_data.size, fptr) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_file_path, __pyx_n_s_encode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 896, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_8 = (__pyx_t_9) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_9) : __Pyx_PyObject_CallNoArg(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 896, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 896, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_31 = __Pyx_PyBytes_AsString(__pyx_t_1); if (unlikely((!__pyx_t_31) && PyErr_Occurred())) __PYX_ERR(0, 896, __pyx_L1_error) + __pyx_v_fptr = fopen(__pyx_t_31, ((char const *)"wb")); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":898 + * fptr = fopen(bytes(file_path.encode()), "wb") + * fwrite( + * &buffer_data[0], sizeof(double), buffer_data.size, fptr) # <<<<<<<<<<<<<< + * fclose(fptr) + * file_index += 1 + */ + __pyx_t_32 = 0; + __pyx_t_13 = -1; + if (__pyx_t_32 < 0) { + __pyx_t_32 += __pyx_v_buffer_data.shape[0]; + if (unlikely(__pyx_t_32 < 0)) __pyx_t_13 = 0; + } else if (unlikely(__pyx_t_32 >= __pyx_v_buffer_data.shape[0])) __pyx_t_13 = 0; + if (unlikely(__pyx_t_13 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_13); + __PYX_ERR(0, 898, __pyx_L1_error) + } + __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_buffer_data, 1, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 898, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_size); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 898, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_33 = __Pyx_PyInt_As_size_t(__pyx_t_8); if (unlikely((__pyx_t_33 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 898, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":897 + * heapfile_list.append(file_path) + * fptr = fopen(bytes(file_path.encode()), "wb") + * fwrite( # <<<<<<<<<<<<<< + * &buffer_data[0], sizeof(double), buffer_data.size, fptr) + * fclose(fptr) + */ + (void)(fwrite(((double *)(&(*((double *) ( /* dim=0 */ (__pyx_v_buffer_data.data + __pyx_t_32 * __pyx_v_buffer_data.strides[0]) ))))), (sizeof(double)), __pyx_t_33, __pyx_v_fptr)); + + /* "pygeoprocessing/geoprocessing_core.pyx":899 + * fwrite( + * &buffer_data[0], sizeof(double), buffer_data.size, fptr) + * fclose(fptr) # <<<<<<<<<<<<<< + * file_index += 1 + * + */ + (void)(fclose(__pyx_v_fptr)); + + /* "pygeoprocessing/geoprocessing_core.pyx":900 + * &buffer_data[0], sizeof(double), buffer_data.size, fptr) + * fclose(fptr) + * file_index += 1 # <<<<<<<<<<<<<< + * + * fast_file_iterator = new FastFileIterator[double]( + */ + __pyx_t_8 = __Pyx_PyInt_AddObjC(__pyx_v_file_index, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 900, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF_SET(__pyx_v_file_index, __pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":903 + * + * fast_file_iterator = new FastFileIterator[double]( + * (bytes(file_path.encode())), ffi_buffer_size) # <<<<<<<<<<<<<< + * fast_file_iterator_vector.push_back(fast_file_iterator) + * push_heap( + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_file_path, __pyx_n_s_encode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 903, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_8 = (__pyx_t_9) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_9) : __Pyx_PyObject_CallNoArg(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 903, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 903, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_34 = __Pyx_PyBytes_AsString(__pyx_t_1); if (unlikely((!__pyx_t_34) && PyErr_Occurred())) __PYX_ERR(0, 903, __pyx_L1_error) + __pyx_t_33 = __Pyx_PyInt_As_size_t(__pyx_v_ffi_buffer_size); if (unlikely((__pyx_t_33 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 903, __pyx_L1_error) + + /* "pygeoprocessing/geoprocessing_core.pyx":902 + * file_index += 1 + * + * fast_file_iterator = new FastFileIterator[double]( # <<<<<<<<<<<<<< + * (bytes(file_path.encode())), ffi_buffer_size) + * fast_file_iterator_vector.push_back(fast_file_iterator) + */ + __pyx_v_fast_file_iterator = new FastFileIterator (__pyx_t_34, __pyx_t_33); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":904 + * fast_file_iterator = new FastFileIterator[double]( + * (bytes(file_path.encode())), ffi_buffer_size) + * fast_file_iterator_vector.push_back(fast_file_iterator) # <<<<<<<<<<<<<< + * push_heap( + * fast_file_iterator_vector.begin(), + */ + try { + __pyx_v_fast_file_iterator_vector.push_back(__pyx_v_fast_file_iterator); + } catch(...) { + __Pyx_CppExn2PyErr(); + __PYX_ERR(0, 904, __pyx_L1_error) + } + + /* "pygeoprocessing/geoprocessing_core.pyx":905 + * (bytes(file_path.encode())), ffi_buffer_size) + * fast_file_iterator_vector.push_back(fast_file_iterator) + * push_heap( # <<<<<<<<<<<<<< + * fast_file_iterator_vector.begin(), + * fast_file_iterator_vector.end(), + */ + std::push_heap(__pyx_v_fast_file_iterator_vector.begin(), __pyx_v_fast_file_iterator_vector.end(), FastFileIteratorCompare); + + /* "pygeoprocessing/geoprocessing_core.pyx":878 + * last_update = time.time() + * LOGGER.debug('sorting data to heap') + * for _, block_data in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * base_raster_path_band, largest_block=heap_buffer_size): + * pixels_processed += block_data.size + */ + __pyx_L20_continue:; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":910 + * FastFileIteratorCompare[double]) + * + * current_percentile = percentile_list[percentile_index] # <<<<<<<<<<<<<< + * step_size = 0 + * if n_elements > 0: + */ + __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_percentile_list, __pyx_v_percentile_index, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 910, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_28 = __pyx_PyFloat_AsDouble(__pyx_t_6); if (unlikely((__pyx_t_28 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 910, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_current_percentile = __pyx_t_28; + + /* "pygeoprocessing/geoprocessing_core.pyx":911 + * + * current_percentile = percentile_list[percentile_index] + * step_size = 0 # <<<<<<<<<<<<<< + * if n_elements > 0: + * step_size = 100.0 / n_elements + */ + __pyx_v_step_size = 0.0; + + /* "pygeoprocessing/geoprocessing_core.pyx":912 + * current_percentile = percentile_list[percentile_index] + * step_size = 0 + * if n_elements > 0: # <<<<<<<<<<<<<< + * step_size = 100.0 / n_elements + * + */ + __pyx_t_25 = ((__pyx_v_n_elements > 0) != 0); + if (__pyx_t_25) { + + /* "pygeoprocessing/geoprocessing_core.pyx":913 + * step_size = 0 + * if n_elements > 0: + * step_size = 100.0 / n_elements # <<<<<<<<<<<<<< + * + * LOGGER.debug('calculating percentiles') + */ + if (unlikely(__pyx_v_n_elements == 0)) { + PyErr_SetString(PyExc_ZeroDivisionError, "float division"); + __PYX_ERR(0, 913, __pyx_L1_error) + } + __pyx_v_step_size = (100.0 / ((double)__pyx_v_n_elements)); + + /* "pygeoprocessing/geoprocessing_core.pyx":912 + * current_percentile = percentile_list[percentile_index] + * step_size = 0 + * if n_elements > 0: # <<<<<<<<<<<<<< + * step_size = 100.0 / n_elements + * + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":915 + * step_size = 100.0 / n_elements + * + * LOGGER.debug('calculating percentiles') # <<<<<<<<<<<<<< + * for i in range(n_elements): + * if time.time() - last_update > 5.0: + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 915, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_debug); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 915, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_6 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_1, __pyx_kp_u_calculating_percentiles) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_kp_u_calculating_percentiles); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 915, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":916 + * + * LOGGER.debug('calculating percentiles') + * for i in range(n_elements): # <<<<<<<<<<<<<< + * if time.time() - last_update > 5.0: + * LOGGER.debug( + */ + __pyx_t_21 = __pyx_v_n_elements; + __pyx_t_35 = __pyx_t_21; + for (__pyx_t_36 = 0; __pyx_t_36 < __pyx_t_35; __pyx_t_36+=1) { + __pyx_v_i = __pyx_t_36; + + /* "pygeoprocessing/geoprocessing_core.pyx":917 + * LOGGER.debug('calculating percentiles') + * for i in range(n_elements): + * if time.time() - last_update > 5.0: # <<<<<<<<<<<<<< + * LOGGER.debug( + * 'calculating percentiles %.2f%% complete', + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_time); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 917, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_time); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 917, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_6 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 917, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Subtract(__pyx_t_6, __pyx_v_last_update); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 917, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = PyObject_RichCompare(__pyx_t_1, __pyx_float_5_0, Py_GT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 917, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_25 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_25 < 0)) __PYX_ERR(0, 917, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (__pyx_t_25) { + + /* "pygeoprocessing/geoprocessing_core.pyx":918 + * for i in range(n_elements): + * if time.time() - last_update > 5.0: + * LOGGER.debug( # <<<<<<<<<<<<<< + * 'calculating percentiles %.2f%% complete', + * 100.0 * i / float(n_elements)) + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 918, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_debug); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 918, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":920 + * LOGGER.debug( + * 'calculating percentiles %.2f%% complete', + * 100.0 * i / float(n_elements)) # <<<<<<<<<<<<<< + * last_update = time.time() + * current_step = step_size * i + */ + __pyx_t_28 = (100.0 * __pyx_v_i); + if (unlikely(((double)__pyx_v_n_elements) == 0)) { + PyErr_SetString(PyExc_ZeroDivisionError, "float division"); + __PYX_ERR(0, 920, __pyx_L1_error) + } + __pyx_t_1 = PyFloat_FromDouble((__pyx_t_28 / ((double)__pyx_v_n_elements))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 920, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = NULL; + __pyx_t_13 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(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); + __pyx_t_13 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_kp_u_calculating_percentiles_2f_compl, __pyx_t_1}; + __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 918, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_6); + __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[3] = {__pyx_t_9, __pyx_kp_u_calculating_percentiles_2f_compl, __pyx_t_1}; + __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 918, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + { + __pyx_t_5 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 918, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_9) { + __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_9); __pyx_t_9 = NULL; + } + __Pyx_INCREF(__pyx_kp_u_calculating_percentiles_2f_compl); + __Pyx_GIVEREF(__pyx_kp_u_calculating_percentiles_2f_compl); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_13, __pyx_kp_u_calculating_percentiles_2f_compl); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_13, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_5, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 918, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":921 + * 'calculating percentiles %.2f%% complete', + * 100.0 * i / float(n_elements)) + * last_update = time.time() # <<<<<<<<<<<<<< + * current_step = step_size * i + * next_val = fast_file_iterator_vector.front().next() + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_time); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 921, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 921, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + __pyx_t_6 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 921, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF_SET(__pyx_v_last_update, __pyx_t_6); + __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":917 + * LOGGER.debug('calculating percentiles') + * for i in range(n_elements): + * if time.time() - last_update > 5.0: # <<<<<<<<<<<<<< + * LOGGER.debug( + * 'calculating percentiles %.2f%% complete', + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":922 + * 100.0 * i / float(n_elements)) + * last_update = time.time() + * current_step = step_size * i # <<<<<<<<<<<<<< + * next_val = fast_file_iterator_vector.front().next() + * if current_step >= current_percentile: + */ + __pyx_v_current_step = (__pyx_v_step_size * __pyx_v_i); + + /* "pygeoprocessing/geoprocessing_core.pyx":923 + * last_update = time.time() + * current_step = step_size * i + * next_val = fast_file_iterator_vector.front().next() # <<<<<<<<<<<<<< + * if current_step >= current_percentile: + * result_list.append(next_val) + */ + __pyx_v_next_val = __pyx_v_fast_file_iterator_vector.front()->next(); + + /* "pygeoprocessing/geoprocessing_core.pyx":924 + * current_step = step_size * i + * next_val = fast_file_iterator_vector.front().next() + * if current_step >= current_percentile: # <<<<<<<<<<<<<< + * result_list.append(next_val) + * percentile_index += 1 + */ + __pyx_t_25 = ((__pyx_v_current_step >= __pyx_v_current_percentile) != 0); + if (__pyx_t_25) { + + /* "pygeoprocessing/geoprocessing_core.pyx":925 + * next_val = fast_file_iterator_vector.front().next() + * if current_step >= current_percentile: + * result_list.append(next_val) # <<<<<<<<<<<<<< + * percentile_index += 1 + * if percentile_index >= len(percentile_list): + */ + __pyx_t_6 = PyFloat_FromDouble(__pyx_v_next_val); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 925, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_30 = __Pyx_PyList_Append(__pyx_v_result_list, __pyx_t_6); if (unlikely(__pyx_t_30 == ((int)-1))) __PYX_ERR(0, 925, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":926 + * if current_step >= current_percentile: + * result_list.append(next_val) + * percentile_index += 1 # <<<<<<<<<<<<<< + * if percentile_index >= len(percentile_list): + * break + */ + __pyx_v_percentile_index = (__pyx_v_percentile_index + 1); + + /* "pygeoprocessing/geoprocessing_core.pyx":927 + * result_list.append(next_val) + * percentile_index += 1 + * if percentile_index >= len(percentile_list): # <<<<<<<<<<<<<< + * break + * current_percentile = percentile_list[percentile_index] + */ + __pyx_t_22 = PyObject_Length(__pyx_v_percentile_list); if (unlikely(__pyx_t_22 == ((Py_ssize_t)-1))) __PYX_ERR(0, 927, __pyx_L1_error) + __pyx_t_25 = ((__pyx_v_percentile_index >= __pyx_t_22) != 0); + if (__pyx_t_25) { + + /* "pygeoprocessing/geoprocessing_core.pyx":928 + * percentile_index += 1 + * if percentile_index >= len(percentile_list): + * break # <<<<<<<<<<<<<< + * current_percentile = percentile_list[percentile_index] + * pop_heap( + */ + goto __pyx_L28_break; + + /* "pygeoprocessing/geoprocessing_core.pyx":927 + * result_list.append(next_val) + * percentile_index += 1 + * if percentile_index >= len(percentile_list): # <<<<<<<<<<<<<< + * break + * current_percentile = percentile_list[percentile_index] + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":929 + * if percentile_index >= len(percentile_list): + * break + * current_percentile = percentile_list[percentile_index] # <<<<<<<<<<<<<< + * pop_heap( + * fast_file_iterator_vector.begin(), + */ + __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_percentile_list, __pyx_v_percentile_index, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 929, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_28 = __pyx_PyFloat_AsDouble(__pyx_t_6); if (unlikely((__pyx_t_28 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 929, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_current_percentile = __pyx_t_28; + + /* "pygeoprocessing/geoprocessing_core.pyx":924 + * current_step = step_size * i + * next_val = fast_file_iterator_vector.front().next() + * if current_step >= current_percentile: # <<<<<<<<<<<<<< + * result_list.append(next_val) + * percentile_index += 1 + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":930 + * break + * current_percentile = percentile_list[percentile_index] + * pop_heap( # <<<<<<<<<<<<<< + * fast_file_iterator_vector.begin(), + * fast_file_iterator_vector.end(), + */ + std::pop_heap(__pyx_v_fast_file_iterator_vector.begin(), __pyx_v_fast_file_iterator_vector.end(), FastFileIteratorCompare); + + /* "pygeoprocessing/geoprocessing_core.pyx":934 + * fast_file_iterator_vector.end(), + * FastFileIteratorCompare[double]) + * if fast_file_iterator_vector.back().size() > 0: # <<<<<<<<<<<<<< + * push_heap( + * fast_file_iterator_vector.begin(), + */ + __pyx_t_25 = ((__pyx_v_fast_file_iterator_vector.back()->size() > 0) != 0); + if (__pyx_t_25) { + + /* "pygeoprocessing/geoprocessing_core.pyx":935 + * FastFileIteratorCompare[double]) + * if fast_file_iterator_vector.back().size() > 0: + * push_heap( # <<<<<<<<<<<<<< + * fast_file_iterator_vector.begin(), + * fast_file_iterator_vector.end(), + */ + std::push_heap(__pyx_v_fast_file_iterator_vector.begin(), __pyx_v_fast_file_iterator_vector.end(), FastFileIteratorCompare); + + /* "pygeoprocessing/geoprocessing_core.pyx":934 + * fast_file_iterator_vector.end(), + * FastFileIteratorCompare[double]) + * if fast_file_iterator_vector.back().size() > 0: # <<<<<<<<<<<<<< + * push_heap( + * fast_file_iterator_vector.begin(), + */ + goto __pyx_L32; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":940 + * FastFileIteratorCompare[double]) + * else: + * fast_file_iterator_vector.pop_back() # <<<<<<<<<<<<<< + * if percentile_index < len(percentile_list): + * result_list.append(next_val) + */ + /*else*/ { + __pyx_v_fast_file_iterator_vector.pop_back(); + } + __pyx_L32:; + } + __pyx_L28_break:; + + /* "pygeoprocessing/geoprocessing_core.pyx":941 + * else: + * fast_file_iterator_vector.pop_back() + * if percentile_index < len(percentile_list): # <<<<<<<<<<<<<< + * result_list.append(next_val) + * # free all the iterator memory + */ + __pyx_t_22 = PyObject_Length(__pyx_v_percentile_list); if (unlikely(__pyx_t_22 == ((Py_ssize_t)-1))) __PYX_ERR(0, 941, __pyx_L1_error) + __pyx_t_25 = ((__pyx_v_percentile_index < __pyx_t_22) != 0); + if (__pyx_t_25) { + + /* "pygeoprocessing/geoprocessing_core.pyx":942 + * fast_file_iterator_vector.pop_back() + * if percentile_index < len(percentile_list): + * result_list.append(next_val) # <<<<<<<<<<<<<< + * # free all the iterator memory + * ffiv_iter = fast_file_iterator_vector.begin() + */ + __pyx_t_6 = PyFloat_FromDouble(__pyx_v_next_val); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 942, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_30 = __Pyx_PyList_Append(__pyx_v_result_list, __pyx_t_6); if (unlikely(__pyx_t_30 == ((int)-1))) __PYX_ERR(0, 942, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":941 + * else: + * fast_file_iterator_vector.pop_back() + * if percentile_index < len(percentile_list): # <<<<<<<<<<<<<< + * result_list.append(next_val) + * # free all the iterator memory + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":944 + * result_list.append(next_val) + * # free all the iterator memory + * ffiv_iter = fast_file_iterator_vector.begin() # <<<<<<<<<<<<<< + * while ffiv_iter != fast_file_iterator_vector.end(): + * fast_file_iterator = deref(ffiv_iter) + */ + __pyx_v_ffiv_iter = __pyx_v_fast_file_iterator_vector.begin(); + + /* "pygeoprocessing/geoprocessing_core.pyx":945 + * # free all the iterator memory + * ffiv_iter = fast_file_iterator_vector.begin() + * while ffiv_iter != fast_file_iterator_vector.end(): # <<<<<<<<<<<<<< + * fast_file_iterator = deref(ffiv_iter) + * del fast_file_iterator + */ + while (1) { + __pyx_t_25 = ((__pyx_v_ffiv_iter != __pyx_v_fast_file_iterator_vector.end()) != 0); + if (!__pyx_t_25) break; + + /* "pygeoprocessing/geoprocessing_core.pyx":946 + * ffiv_iter = fast_file_iterator_vector.begin() + * while ffiv_iter != fast_file_iterator_vector.end(): + * fast_file_iterator = deref(ffiv_iter) # <<<<<<<<<<<<<< + * del fast_file_iterator + * inc(ffiv_iter) + */ + __pyx_v_fast_file_iterator = (*__pyx_v_ffiv_iter); + + /* "pygeoprocessing/geoprocessing_core.pyx":947 + * while ffiv_iter != fast_file_iterator_vector.end(): + * fast_file_iterator = deref(ffiv_iter) + * del fast_file_iterator # <<<<<<<<<<<<<< + * inc(ffiv_iter) + * fast_file_iterator_vector.clear() + */ + delete __pyx_v_fast_file_iterator; + + /* "pygeoprocessing/geoprocessing_core.pyx":948 + * fast_file_iterator = deref(ffiv_iter) + * del fast_file_iterator + * inc(ffiv_iter) # <<<<<<<<<<<<<< + * fast_file_iterator_vector.clear() + * # delete all the heap files + */ + (void)((++__pyx_v_ffiv_iter)); + } + + /* "pygeoprocessing/geoprocessing_core.pyx":949 + * del fast_file_iterator + * inc(ffiv_iter) + * fast_file_iterator_vector.clear() # <<<<<<<<<<<<<< + * # delete all the heap files + * for file_path in heapfile_list: + */ + __pyx_v_fast_file_iterator_vector.clear(); + + /* "pygeoprocessing/geoprocessing_core.pyx":951 + * fast_file_iterator_vector.clear() + * # delete all the heap files + * for file_path in heapfile_list: # <<<<<<<<<<<<<< + * try: + * os.remove(file_path) + */ + __pyx_t_6 = __pyx_v_heapfile_list; __Pyx_INCREF(__pyx_t_6); __pyx_t_22 = 0; + for (;;) { + if (__pyx_t_22 >= 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_22); __Pyx_INCREF(__pyx_t_5); __pyx_t_22++; if (unlikely(0 < 0)) __PYX_ERR(0, 951, __pyx_L1_error) + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_6, __pyx_t_22); __pyx_t_22++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 951, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + __Pyx_XDECREF_SET(__pyx_v_file_path, __pyx_t_5); + __pyx_t_5 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":952 + * # delete all the heap files + * for file_path in heapfile_list: + * try: # <<<<<<<<<<<<<< + * os.remove(file_path) + * except OSError: + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_4, &__pyx_t_3, &__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_2); + /*try:*/ { + + /* "pygeoprocessing/geoprocessing_core.pyx":953 + * for file_path in heapfile_list: + * try: + * os.remove(file_path) # <<<<<<<<<<<<<< + * except OSError: + * # you never know if this might fail! + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_os); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 953, __pyx_L38_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_remove); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 953, __pyx_L38_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_5 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_8, __pyx_v_file_path) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_file_path); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 953, __pyx_L38_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/geoprocessing_core.pyx":952 + * # delete all the heap files + * for file_path in heapfile_list: + * try: # <<<<<<<<<<<<<< + * os.remove(file_path) + * except OSError: + */ + } + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L45_try_end; + __pyx_L38_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __PYX_XDEC_MEMVIEW(&__pyx_t_29, 1); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":954 + * try: + * os.remove(file_path) + * except OSError: # <<<<<<<<<<<<<< + * # you never know if this might fail! + * LOGGER.warning('unable to remove %s', file_path) + */ + __pyx_t_13 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OSError); + if (__pyx_t_13) { + __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core._raster_band_percentile_double", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_1, &__pyx_t_8) < 0) __PYX_ERR(0, 954, __pyx_L40_except_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_8); + + /* "pygeoprocessing/geoprocessing_core.pyx":956 + * except OSError: + * # you never know if this might fail! + * LOGGER.warning('unable to remove %s', file_path) # <<<<<<<<<<<<<< + * if rm_dir_when_done: + * shutil.rmtree(working_sort_directory) + */ + __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 956, __pyx_L40_except_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_warning); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 956, __pyx_L40_except_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = NULL; + __pyx_t_13 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_12)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + __pyx_t_13 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_kp_u_unable_to_remove_s, __pyx_v_file_path}; + __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 956, __pyx_L40_except_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_9); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_kp_u_unable_to_remove_s, __pyx_v_file_path}; + __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 956, __pyx_L40_except_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_9); + } else + #endif + { + __pyx_t_10 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 956, __pyx_L40_except_error) + __Pyx_GOTREF(__pyx_t_10); + if (__pyx_t_12) { + __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_12); __pyx_t_12 = NULL; + } + __Pyx_INCREF(__pyx_kp_u_unable_to_remove_s); + __Pyx_GIVEREF(__pyx_kp_u_unable_to_remove_s); + PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_13, __pyx_kp_u_unable_to_remove_s); + __Pyx_INCREF(__pyx_v_file_path); + __Pyx_GIVEREF(__pyx_v_file_path); + PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_13, __pyx_v_file_path); + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_10, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 956, __pyx_L40_except_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L39_exception_handled; + } + goto __pyx_L40_except_error; + __pyx_L40_except_error:; + + /* "pygeoprocessing/geoprocessing_core.pyx":952 + * # delete all the heap files + * for file_path in heapfile_list: + * try: # <<<<<<<<<<<<<< + * os.remove(file_path) + * except OSError: + */ + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_3, __pyx_t_2); + goto __pyx_L1_error; + __pyx_L39_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_3, __pyx_t_2); + __pyx_L45_try_end:; + } + + /* "pygeoprocessing/geoprocessing_core.pyx":951 + * fast_file_iterator_vector.clear() + * # delete all the heap files + * for file_path in heapfile_list: # <<<<<<<<<<<<<< + * try: + * os.remove(file_path) + */ + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":957 + * # you never know if this might fail! + * LOGGER.warning('unable to remove %s', file_path) + * if rm_dir_when_done: # <<<<<<<<<<<<<< + * shutil.rmtree(working_sort_directory) + * LOGGER.debug('here is percentile_list: %s', str(result_list)) + */ + __pyx_t_25 = (__pyx_v_rm_dir_when_done != 0); + if (__pyx_t_25) { + + /* "pygeoprocessing/geoprocessing_core.pyx":958 + * LOGGER.warning('unable to remove %s', file_path) + * if rm_dir_when_done: + * shutil.rmtree(working_sort_directory) # <<<<<<<<<<<<<< + * LOGGER.debug('here is percentile_list: %s', str(result_list)) + * return result_list + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_shutil); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 958, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_rmtree); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 958, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_6 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_8, __pyx_v_working_sort_directory) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_working_sort_directory); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 958, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":957 + * # you never know if this might fail! + * LOGGER.warning('unable to remove %s', file_path) + * if rm_dir_when_done: # <<<<<<<<<<<<<< + * shutil.rmtree(working_sort_directory) + * LOGGER.debug('here is percentile_list: %s', str(result_list)) + */ + } + + /* "pygeoprocessing/geoprocessing_core.pyx":959 + * if rm_dir_when_done: + * shutil.rmtree(working_sort_directory) + * LOGGER.debug('here is percentile_list: %s', str(result_list)) # <<<<<<<<<<<<<< + * return result_list + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 959, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_debug); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 959, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_v_result_list); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 959, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = NULL; + __pyx_t_13 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + __pyx_t_13 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_kp_u_here_is_percentile_list_s, __pyx_t_1}; + __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 959, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_6); + __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[3] = {__pyx_t_5, __pyx_kp_u_here_is_percentile_list_s, __pyx_t_1}; + __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 959, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + { + __pyx_t_9 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 959, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + if (__pyx_t_5) { + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_5); __pyx_t_5 = NULL; + } + __Pyx_INCREF(__pyx_kp_u_here_is_percentile_list_s); + __Pyx_GIVEREF(__pyx_kp_u_here_is_percentile_list_s); + PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_13, __pyx_kp_u_here_is_percentile_list_s); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_13, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_9, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 959, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":960 + * shutil.rmtree(working_sort_directory) + * LOGGER.debug('here is percentile_list: %s', str(result_list)) + * return result_list # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_result_list); + __pyx_r = __pyx_v_result_list; + goto __pyx_L0; + + /* "pygeoprocessing/geoprocessing_core.pyx":819 + * + * + * def _raster_band_percentile_double( # <<<<<<<<<<<<<< + * base_raster_path_band, working_sort_directory, percentile_list, + * heap_buffer_size, ffi_buffer_size): + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __PYX_XDEC_MEMVIEW(&__pyx_t_29, 1); + __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core._raster_band_percentile_double", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __PYX_XDEC_MEMVIEW(&__pyx_v_buffer_data, 1); + __Pyx_XDECREF(__pyx_v_result_list); + __Pyx_XDECREF(__pyx_v_e); + __Pyx_XDECREF(__pyx_v_file_index); + __Pyx_XDECREF(__pyx_v_nodata); + __Pyx_XDECREF(__pyx_v_heapfile_list); + __Pyx_XDECREF(__pyx_v_raster_info); + __Pyx_XDECREF(__pyx_v_last_update); + __Pyx_XDECREF(__pyx_v__); + __Pyx_XDECREF(__pyx_v_block_data); + __Pyx_XDECREF(__pyx_v_file_path); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":735 + * ctypedef npy_cdouble complex_t + * + * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(1, 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("PyArray_MultiIterNew1", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":736 + * + * cdef inline object PyArray_MultiIterNew1(a): + * return PyArray_MultiIterNew(1, 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(1, 736, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":735 + * ctypedef npy_cdouble complex_t + * + * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(1, 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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":738 + * return PyArray_MultiIterNew(1, a) + * + * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(2, a, 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("PyArray_MultiIterNew2", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":739 + * + * cdef inline object PyArray_MultiIterNew2(a, b): + * return PyArray_MultiIterNew(2, a, 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(1, 739, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":738 + * return PyArray_MultiIterNew(1, a) + * + * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(2, a, 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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":741 + * return PyArray_MultiIterNew(2, a, b) + * + * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(3, a, b, 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("PyArray_MultiIterNew3", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":742 + * + * cdef inline object PyArray_MultiIterNew3(a, b, c): + * return PyArray_MultiIterNew(3, a, b, 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(1, 742, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":741 + * return PyArray_MultiIterNew(2, a, b) + * + * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(3, a, b, 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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":744 + * return PyArray_MultiIterNew(3, a, b, c) + * + * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(4, a, b, c, 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("PyArray_MultiIterNew4", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":745 + * + * cdef inline object PyArray_MultiIterNew4(a, b, c, d): + * return PyArray_MultiIterNew(4, a, b, c, 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(1, 745, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":744 + * return PyArray_MultiIterNew(3, a, b, c) + * + * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(4, a, b, c, 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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":747 + * return PyArray_MultiIterNew(4, a, b, c, d) + * + * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(5, a, b, c, d, 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("PyArray_MultiIterNew5", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":748 + * + * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): + * return PyArray_MultiIterNew(5, a, b, c, d, 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(1, 748, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":747 + * return PyArray_MultiIterNew(4, a, b, c, d) + * + * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(5, a, b, c, d, 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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":750 + * return PyArray_MultiIterNew(5, a, b, c, d, e) + * + * cdef inline tuple PyDataType_SHAPE(dtype d): # <<<<<<<<<<<<<< + * if PyDataType_HASSUBARRAY(d): + * return 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); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":751 + * + * cdef inline tuple PyDataType_SHAPE(dtype d): + * if PyDataType_HASSUBARRAY(d): # <<<<<<<<<<<<<< + * return d.subarray.shape + * else: + */ + __pyx_t_1 = (PyDataType_HASSUBARRAY(__pyx_v_d) != 0); + if (__pyx_t_1) { + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":752 + * cdef inline tuple PyDataType_SHAPE(dtype d): + * if PyDataType_HASSUBARRAY(d): + * return 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; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":751 + * + * cdef inline tuple PyDataType_SHAPE(dtype d): + * if PyDataType_HASSUBARRAY(d): # <<<<<<<<<<<<<< + * return d.subarray.shape + * else: + */ + } + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":754 + * return d.subarray.shape + * else: + * return () # <<<<<<<<<<<<<< + * + * + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_empty_tuple); + __pyx_r = __pyx_empty_tuple; + goto __pyx_L0; + } + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":750 + * return PyArray_MultiIterNew(5, a, b, c, d, e) + * + * cdef inline tuple PyDataType_SHAPE(dtype d): # <<<<<<<<<<<<<< + * if PyDataType_HASSUBARRAY(d): + * return d.subarray.shape + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":931 + * int _import_umath() except -1 + * + * cdef inline void set_array_base(ndarray arr, object base): # <<<<<<<<<<<<<< + * Py_INCREF(base) # important to do this before stealing the reference below! + * PyArray_SetBaseObject(arr, base) + */ + +static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_arr, PyObject *__pyx_v_base) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("set_array_base", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":932 + * + * cdef inline void set_array_base(ndarray arr, object base): + * Py_INCREF(base) # important to do this before stealing the reference below! # <<<<<<<<<<<<<< + * PyArray_SetBaseObject(arr, base) + * + */ + Py_INCREF(__pyx_v_base); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":933 + * cdef inline void set_array_base(ndarray arr, object base): + * Py_INCREF(base) # important to do this before stealing the reference below! + * PyArray_SetBaseObject(arr, base) # <<<<<<<<<<<<<< + * + * cdef inline object get_array_base(ndarray arr): + */ + (void)(PyArray_SetBaseObject(__pyx_v_arr, __pyx_v_base)); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":931 + * int _import_umath() except -1 + * + * cdef inline void set_array_base(ndarray arr, object base): # <<<<<<<<<<<<<< + * Py_INCREF(base) # important to do this before stealing the reference below! + * PyArray_SetBaseObject(arr, base) + */ + + /* function exit code */ + __Pyx_RefNannyFinishContext(); +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":935 + * PyArray_SetBaseObject(arr, base) + * + * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< + * base = PyArray_BASE(arr) + * if base is NULL: + */ + +static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__pyx_v_arr) { + PyObject *__pyx_v_base; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("get_array_base", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":936 + * + * cdef inline object get_array_base(ndarray arr): + * base = PyArray_BASE(arr) # <<<<<<<<<<<<<< + * if base is NULL: + * return None + */ + __pyx_v_base = PyArray_BASE(__pyx_v_arr); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":937 + * cdef inline object get_array_base(ndarray arr): + * base = PyArray_BASE(arr) + * if base is NULL: # <<<<<<<<<<<<<< + * return None + * return base + */ + __pyx_t_1 = ((__pyx_v_base == NULL) != 0); + if (__pyx_t_1) { + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":938 + * base = PyArray_BASE(arr) + * if base is NULL: + * return None # <<<<<<<<<<<<<< + * return base + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":937 + * cdef inline object get_array_base(ndarray arr): + * base = PyArray_BASE(arr) + * if base is NULL: # <<<<<<<<<<<<<< + * return None + * return base + */ + } + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":939 + * if base is NULL: + * return None + * return base # <<<<<<<<<<<<<< + * + * # Versions of the import_* functions which are more suitable for + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_base)); + __pyx_r = ((PyObject *)__pyx_v_base); + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":935 + * PyArray_SetBaseObject(arr, base) + * + * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< + * base = PyArray_BASE(arr) + * if base is NULL: + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":943 + * # Versions of the import_* functions which are more suitable for + * # Cython code. + * cdef inline int import_array() except -1: # <<<<<<<<<<<<<< + * try: + * __pyx_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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("import_array", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":944 + * # Cython code. + * cdef inline int import_array() except -1: + * try: # <<<<<<<<<<<<<< + * __pyx_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:*/ { + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":945 + * cdef inline int import_array() except -1: + * try: + * __pyx_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(1, 945, __pyx_L3_error) + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":944 + * # Cython code. + * cdef inline int import_array() except -1: + * try: # <<<<<<<<<<<<<< + * __pyx_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:; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":946 + * try: + * __pyx_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(1, 946, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_7); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":947 + * __pyx_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__4, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 947, __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(1, 947, __pyx_L5_except_error) + } + goto __pyx_L5_except_error; + __pyx_L5_except_error:; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":944 + * # Cython code. + * cdef inline int import_array() except -1: + * try: # <<<<<<<<<<<<<< + * __pyx_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:; + } + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":943 + * # Versions of the import_* functions which are more suitable for + * # Cython code. + * cdef inline int import_array() except -1: # <<<<<<<<<<<<<< + * try: + * __pyx_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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":949 + * 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("import_umath", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":950 + * + * 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:*/ { + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":951 + * 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(1, 951, __pyx_L3_error) + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":950 + * + * 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:; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":952 + * 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(1, 952, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_7); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":953 + * _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__5, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 953, __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(1, 953, __pyx_L5_except_error) + } + goto __pyx_L5_except_error; + __pyx_L5_except_error:; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":950 + * + * 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:; + } + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":949 + * 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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":955 + * 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("import_ufunc", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":956 + * + * 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:*/ { + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":957 + * 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(1, 957, __pyx_L3_error) + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":956 + * + * 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:; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":958 + * 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(1, 958, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_7); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":959 + * _import_umath() + * except Exception: + * raise ImportError("numpy.core.umath failed to import") # <<<<<<<<<<<<<< + * + * cdef extern from *: + */ + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 959, __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(1, 959, __pyx_L5_except_error) + } + goto __pyx_L5_except_error; + __pyx_L5_except_error:; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":956 + * + * 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:; + } + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":955 + * 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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":969 + * + * + * cdef inline bint is_timedelta64_object(object obj): # <<<<<<<<<<<<<< + * """ + * Cython equivalent of `isinstance(obj, np.timedelta64)` + */ + +static CYTHON_INLINE int __pyx_f_5numpy_is_timedelta64_object(PyObject *__pyx_v_obj) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("is_timedelta64_object", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":981 + * bool + * """ + * return PyObject_TypeCheck(obj, &PyTimedeltaArrType_Type) # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = PyObject_TypeCheck(__pyx_v_obj, (&PyTimedeltaArrType_Type)); + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":969 + * + * + * cdef inline bint is_timedelta64_object(object obj): # <<<<<<<<<<<<<< + * """ + * Cython equivalent of `isinstance(obj, np.timedelta64)` + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":984 + * + * + * cdef inline bint is_datetime64_object(object obj): # <<<<<<<<<<<<<< + * """ + * Cython equivalent of `isinstance(obj, np.datetime64)` + */ + +static CYTHON_INLINE int __pyx_f_5numpy_is_datetime64_object(PyObject *__pyx_v_obj) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("is_datetime64_object", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":996 + * bool + * """ + * return PyObject_TypeCheck(obj, &PyDatetimeArrType_Type) # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = PyObject_TypeCheck(__pyx_v_obj, (&PyDatetimeArrType_Type)); + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":984 + * + * + * cdef inline bint is_datetime64_object(object obj): # <<<<<<<<<<<<<< + * """ + * Cython equivalent of `isinstance(obj, np.datetime64)` + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":999 + * + * + * cdef inline npy_datetime get_datetime64_value(object obj) nogil: # <<<<<<<<<<<<<< + * """ + * returns the int64 value underlying scalar numpy datetime64 object + */ + +static CYTHON_INLINE npy_datetime __pyx_f_5numpy_get_datetime64_value(PyObject *__pyx_v_obj) { + npy_datetime __pyx_r; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1006 + * also needed. That can be found using `get_datetime64_unit`. + * """ + * return (obj).obval # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = ((PyDatetimeScalarObject *)__pyx_v_obj)->obval; + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":999 + * + * + * cdef inline npy_datetime get_datetime64_value(object obj) nogil: # <<<<<<<<<<<<<< + * """ + * returns the int64 value underlying scalar numpy datetime64 object + */ + + /* function exit code */ + __pyx_L0:; + return __pyx_r; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1009 + * + * + * cdef inline npy_timedelta get_timedelta64_value(object obj) nogil: # <<<<<<<<<<<<<< + * """ + * returns the int64 value underlying scalar numpy timedelta64 object + */ + +static CYTHON_INLINE npy_timedelta __pyx_f_5numpy_get_timedelta64_value(PyObject *__pyx_v_obj) { + npy_timedelta __pyx_r; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1013 + * returns the int64 value underlying scalar numpy timedelta64 object + * """ + * return (obj).obval # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = ((PyTimedeltaScalarObject *)__pyx_v_obj)->obval; + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1009 + * + * + * cdef inline npy_timedelta get_timedelta64_value(object obj) nogil: # <<<<<<<<<<<<<< + * """ + * returns the int64 value underlying scalar numpy timedelta64 object + */ + + /* function exit code */ + __pyx_L0:; + return __pyx_r; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1016 + * + * + * cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil: # <<<<<<<<<<<<<< + * """ + * returns the unit part of the dtype for a numpy datetime64 object. + */ + +static CYTHON_INLINE NPY_DATETIMEUNIT __pyx_f_5numpy_get_datetime64_unit(PyObject *__pyx_v_obj) { + NPY_DATETIMEUNIT __pyx_r; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1020 + * returns the unit part of the dtype for a numpy datetime64 object. + * """ + * return (obj).obmeta.base # <<<<<<<<<<<<<< + */ + __pyx_r = ((NPY_DATETIMEUNIT)((PyDatetimeScalarObject *)__pyx_v_obj)->obmeta.base); + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1016 + * + * + * cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil: # <<<<<<<<<<<<<< + * """ + * returns the unit part of the dtype for a numpy datetime64 object. + */ + + /* function exit code */ + __pyx_L0:; + return __pyx_r; +} + +/* "View.MemoryView":122 + * cdef bint dtype_is_object + * + * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, # <<<<<<<<<<<<<< + * mode="c", bint allocate_buffer=True): + * + */ + +/* Python wrapper */ +static int __pyx_array___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_array___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_shape = 0; + Py_ssize_t __pyx_v_itemsize; + PyObject *__pyx_v_format = 0; + PyObject *__pyx_v_mode = 0; + int __pyx_v_allocate_buffer; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_shape,&__pyx_n_s_itemsize,&__pyx_n_s_format,&__pyx_n_s_mode,&__pyx_n_s_allocate_buffer,0}; + PyObject* values[5] = {0,0,0,0,0}; + values[3] = ((PyObject *)__pyx_n_s_c); + 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_shape)) != 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_itemsize)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 1); __PYX_ERR(2, 122, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_format)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 2); __PYX_ERR(2, 122, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 3: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mode); + 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_allocate_buffer); + if (value) { values[4] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(2, 122, __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_shape = ((PyObject*)values[0]); + __pyx_v_itemsize = __Pyx_PyIndex_AsSsize_t(values[1]); if (unlikely((__pyx_v_itemsize == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 122, __pyx_L3_error) + __pyx_v_format = values[2]; + __pyx_v_mode = values[3]; + if (values[4]) { + __pyx_v_allocate_buffer = __Pyx_PyObject_IsTrue(values[4]); if (unlikely((__pyx_v_allocate_buffer == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 123, __pyx_L3_error) + } else { + + /* "View.MemoryView":123 + * + * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, + * mode="c", bint allocate_buffer=True): # <<<<<<<<<<<<<< + * + * cdef int idx + */ + __pyx_v_allocate_buffer = ((int)1); + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 122, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("View.MemoryView.array.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_shape), (&PyTuple_Type), 1, "shape", 1))) __PYX_ERR(2, 122, __pyx_L1_error) + if (unlikely(((PyObject *)__pyx_v_format) == Py_None)) { + PyErr_Format(PyExc_TypeError, "Argument '%.200s' must not be None", "format"); __PYX_ERR(2, 122, __pyx_L1_error) + } + __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(((struct __pyx_array_obj *)__pyx_v_self), __pyx_v_shape, __pyx_v_itemsize, __pyx_v_format, __pyx_v_mode, __pyx_v_allocate_buffer); + + /* "View.MemoryView":122 + * cdef bint dtype_is_object + * + * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, # <<<<<<<<<<<<<< + * mode="c", bint allocate_buffer=True): + * + */ + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, PyObject *__pyx_v_format, PyObject *__pyx_v_mode, int __pyx_v_allocate_buffer) { + int __pyx_v_idx; + Py_ssize_t __pyx_v_i; + Py_ssize_t __pyx_v_dim; + PyObject **__pyx_v_p; + char __pyx_v_order; + int __pyx_r; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + char *__pyx_t_7; + int __pyx_t_8; + Py_ssize_t __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + Py_ssize_t __pyx_t_11; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + __Pyx_INCREF(__pyx_v_format); + + /* "View.MemoryView":129 + * cdef PyObject **p + * + * self.ndim = len(shape) # <<<<<<<<<<<<<< + * self.itemsize = itemsize + * + */ + if (unlikely(__pyx_v_shape == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + __PYX_ERR(2, 129, __pyx_L1_error) + } + __pyx_t_1 = PyTuple_GET_SIZE(__pyx_v_shape); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(2, 129, __pyx_L1_error) + __pyx_v_self->ndim = ((int)__pyx_t_1); + + /* "View.MemoryView":130 + * + * self.ndim = len(shape) + * self.itemsize = itemsize # <<<<<<<<<<<<<< + * + * if not self.ndim: + */ + __pyx_v_self->itemsize = __pyx_v_itemsize; + + /* "View.MemoryView":132 + * self.itemsize = itemsize + * + * if not self.ndim: # <<<<<<<<<<<<<< + * raise ValueError("Empty shape tuple for cython.array") + * + */ + __pyx_t_2 = ((!(__pyx_v_self->ndim != 0)) != 0); + if (unlikely(__pyx_t_2)) { + + /* "View.MemoryView":133 + * + * if not self.ndim: + * raise ValueError("Empty shape tuple for cython.array") # <<<<<<<<<<<<<< + * + * if itemsize <= 0: + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 133, __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, 133, __pyx_L1_error) + + /* "View.MemoryView":132 + * self.itemsize = itemsize + * + * if not self.ndim: # <<<<<<<<<<<<<< + * raise ValueError("Empty shape tuple for cython.array") + * + */ + } + + /* "View.MemoryView":135 + * raise ValueError("Empty shape tuple for cython.array") + * + * if itemsize <= 0: # <<<<<<<<<<<<<< + * raise ValueError("itemsize <= 0 for cython.array") + * + */ + __pyx_t_2 = ((__pyx_v_itemsize <= 0) != 0); + if (unlikely(__pyx_t_2)) { + + /* "View.MemoryView":136 + * + * if itemsize <= 0: + * raise ValueError("itemsize <= 0 for cython.array") # <<<<<<<<<<<<<< + * + * if not isinstance(format, bytes): + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 136, __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, 136, __pyx_L1_error) + + /* "View.MemoryView":135 + * raise ValueError("Empty shape tuple for cython.array") + * + * if itemsize <= 0: # <<<<<<<<<<<<<< + * raise ValueError("itemsize <= 0 for cython.array") + * + */ + } + + /* "View.MemoryView":138 + * raise ValueError("itemsize <= 0 for cython.array") + * + * if not isinstance(format, bytes): # <<<<<<<<<<<<<< + * format = format.encode('ASCII') + * self._format = format # keep a reference to the byte string + */ + __pyx_t_2 = PyBytes_Check(__pyx_v_format); + __pyx_t_4 = ((!(__pyx_t_2 != 0)) != 0); + if (__pyx_t_4) { + + /* "View.MemoryView":139 + * + * if not isinstance(format, bytes): + * format = format.encode('ASCII') # <<<<<<<<<<<<<< + * self._format = format # keep a reference to the byte string + * self.format = self._format + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_format, __pyx_n_s_encode); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 139, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __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); + } + } + __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_n_s_ASCII) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_n_s_ASCII); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 139, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF_SET(__pyx_v_format, __pyx_t_3); + __pyx_t_3 = 0; + + /* "View.MemoryView":138 + * raise ValueError("itemsize <= 0 for cython.array") + * + * if not isinstance(format, bytes): # <<<<<<<<<<<<<< + * format = format.encode('ASCII') + * self._format = format # keep a reference to the byte string + */ + } + + /* "View.MemoryView":140 + * if not isinstance(format, bytes): + * format = format.encode('ASCII') + * self._format = format # keep a reference to the byte string # <<<<<<<<<<<<<< + * self.format = self._format + * + */ + if (!(likely(PyBytes_CheckExact(__pyx_v_format))||((__pyx_v_format) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_v_format)->tp_name), 0))) __PYX_ERR(2, 140, __pyx_L1_error) + __pyx_t_3 = __pyx_v_format; + __Pyx_INCREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_v_self->_format); + __Pyx_DECREF(__pyx_v_self->_format); + __pyx_v_self->_format = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + + /* "View.MemoryView":141 + * format = format.encode('ASCII') + * self._format = format # keep a reference to the byte string + * self.format = self._format # <<<<<<<<<<<<<< + * + * + */ + if (unlikely(__pyx_v_self->_format == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(2, 141, __pyx_L1_error) + } + __pyx_t_7 = __Pyx_PyBytes_AsWritableString(__pyx_v_self->_format); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(2, 141, __pyx_L1_error) + __pyx_v_self->format = __pyx_t_7; + + /* "View.MemoryView":144 + * + * + * self._shape = PyObject_Malloc(sizeof(Py_ssize_t)*self.ndim*2) # <<<<<<<<<<<<<< + * self._strides = self._shape + self.ndim + * + */ + __pyx_v_self->_shape = ((Py_ssize_t *)PyObject_Malloc((((sizeof(Py_ssize_t)) * __pyx_v_self->ndim) * 2))); + + /* "View.MemoryView":145 + * + * self._shape = PyObject_Malloc(sizeof(Py_ssize_t)*self.ndim*2) + * self._strides = self._shape + self.ndim # <<<<<<<<<<<<<< + * + * if not self._shape: + */ + __pyx_v_self->_strides = (__pyx_v_self->_shape + __pyx_v_self->ndim); + + /* "View.MemoryView":147 + * self._strides = self._shape + self.ndim + * + * if not self._shape: # <<<<<<<<<<<<<< + * raise MemoryError("unable to allocate shape and strides.") + * + */ + __pyx_t_4 = ((!(__pyx_v_self->_shape != 0)) != 0); + if (unlikely(__pyx_t_4)) { + + /* "View.MemoryView":148 + * + * if not self._shape: + * raise MemoryError("unable to allocate shape and strides.") # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 148, __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, 148, __pyx_L1_error) + + /* "View.MemoryView":147 + * self._strides = self._shape + self.ndim + * + * if not self._shape: # <<<<<<<<<<<<<< + * raise MemoryError("unable to allocate shape and strides.") + * + */ + } + + /* "View.MemoryView":151 + * + * + * for idx, dim in enumerate(shape): # <<<<<<<<<<<<<< + * if dim <= 0: + * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) + */ + __pyx_t_8 = 0; + __pyx_t_3 = __pyx_v_shape; __Pyx_INCREF(__pyx_t_3); __pyx_t_1 = 0; + for (;;) { + if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_5); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(2, 151, __pyx_L1_error) + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 151, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + __pyx_t_9 = __Pyx_PyIndex_AsSsize_t(__pyx_t_5); if (unlikely((__pyx_t_9 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 151, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_dim = __pyx_t_9; + __pyx_v_idx = __pyx_t_8; + __pyx_t_8 = (__pyx_t_8 + 1); + + /* "View.MemoryView":152 + * + * for idx, dim in enumerate(shape): + * if dim <= 0: # <<<<<<<<<<<<<< + * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) + * self._shape[idx] = dim + */ + __pyx_t_4 = ((__pyx_v_dim <= 0) != 0); + if (unlikely(__pyx_t_4)) { + + /* "View.MemoryView":153 + * for idx, dim in enumerate(shape): + * if dim <= 0: + * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) # <<<<<<<<<<<<<< + * self._shape[idx] = dim + * + */ + __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 153, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 153, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 153, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_6); + __pyx_t_5 = 0; + __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_Invalid_shape_in_axis_d_d, __pyx_t_10); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 153, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_6); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 153, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_Raise(__pyx_t_10, 0, 0, 0); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __PYX_ERR(2, 153, __pyx_L1_error) + + /* "View.MemoryView":152 + * + * for idx, dim in enumerate(shape): + * if dim <= 0: # <<<<<<<<<<<<<< + * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) + * self._shape[idx] = dim + */ + } + + /* "View.MemoryView":154 + * if dim <= 0: + * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) + * self._shape[idx] = dim # <<<<<<<<<<<<<< + * + * cdef char order + */ + (__pyx_v_self->_shape[__pyx_v_idx]) = __pyx_v_dim; + + /* "View.MemoryView":151 + * + * + * for idx, dim in enumerate(shape): # <<<<<<<<<<<<<< + * if dim <= 0: + * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) + */ + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "View.MemoryView":157 + * + * cdef char order + * if mode == 'fortran': # <<<<<<<<<<<<<< + * order = b'F' + * self.mode = u'fortran' + */ + __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_fortran, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(2, 157, __pyx_L1_error) + if (__pyx_t_4) { + + /* "View.MemoryView":158 + * cdef char order + * if mode == 'fortran': + * order = b'F' # <<<<<<<<<<<<<< + * self.mode = u'fortran' + * elif mode == 'c': + */ + __pyx_v_order = 'F'; + + /* "View.MemoryView":159 + * if mode == 'fortran': + * order = b'F' + * self.mode = u'fortran' # <<<<<<<<<<<<<< + * elif mode == 'c': + * order = b'C' + */ + __Pyx_INCREF(__pyx_n_u_fortran); + __Pyx_GIVEREF(__pyx_n_u_fortran); + __Pyx_GOTREF(__pyx_v_self->mode); + __Pyx_DECREF(__pyx_v_self->mode); + __pyx_v_self->mode = __pyx_n_u_fortran; + + /* "View.MemoryView":157 + * + * cdef char order + * if mode == 'fortran': # <<<<<<<<<<<<<< + * order = b'F' + * self.mode = u'fortran' + */ + goto __pyx_L10; + } + + /* "View.MemoryView":160 + * order = b'F' + * self.mode = u'fortran' + * elif mode == 'c': # <<<<<<<<<<<<<< + * order = b'C' + * self.mode = u'c' + */ + __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_c, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(2, 160, __pyx_L1_error) + if (likely(__pyx_t_4)) { + + /* "View.MemoryView":161 + * self.mode = u'fortran' + * elif mode == 'c': + * order = b'C' # <<<<<<<<<<<<<< + * self.mode = u'c' + * else: + */ + __pyx_v_order = 'C'; + + /* "View.MemoryView":162 + * elif mode == 'c': + * order = b'C' + * self.mode = u'c' # <<<<<<<<<<<<<< + * else: + * raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode) + */ + __Pyx_INCREF(__pyx_n_u_c); + __Pyx_GIVEREF(__pyx_n_u_c); + __Pyx_GOTREF(__pyx_v_self->mode); + __Pyx_DECREF(__pyx_v_self->mode); + __pyx_v_self->mode = __pyx_n_u_c; + + /* "View.MemoryView":160 + * order = b'F' + * self.mode = u'fortran' + * elif mode == 'c': # <<<<<<<<<<<<<< + * order = b'C' + * self.mode = u'c' + */ + goto __pyx_L10; + } + + /* "View.MemoryView":164 + * self.mode = u'c' + * else: + * raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode) # <<<<<<<<<<<<<< + * + * self.len = fill_contig_strides_array(self._shape, self._strides, + */ + /*else*/ { + __pyx_t_3 = __Pyx_PyString_FormatSafe(__pyx_kp_s_Invalid_mode_expected_c_or_fortr, __pyx_v_mode); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 164, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 164, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_10, 0, 0, 0); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __PYX_ERR(2, 164, __pyx_L1_error) + } + __pyx_L10:; + + /* "View.MemoryView":166 + * raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode) + * + * self.len = fill_contig_strides_array(self._shape, self._strides, # <<<<<<<<<<<<<< + * itemsize, self.ndim, order) + * + */ + __pyx_v_self->len = __pyx_fill_contig_strides_array(__pyx_v_self->_shape, __pyx_v_self->_strides, __pyx_v_itemsize, __pyx_v_self->ndim, __pyx_v_order); + + /* "View.MemoryView":169 + * itemsize, self.ndim, order) + * + * self.free_data = allocate_buffer # <<<<<<<<<<<<<< + * self.dtype_is_object = format == b'O' + * if allocate_buffer: + */ + __pyx_v_self->free_data = __pyx_v_allocate_buffer; + + /* "View.MemoryView":170 + * + * self.free_data = allocate_buffer + * self.dtype_is_object = format == b'O' # <<<<<<<<<<<<<< + * if allocate_buffer: + * + */ + __pyx_t_10 = PyObject_RichCompare(__pyx_v_format, __pyx_n_b_O, Py_EQ); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 170, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 170, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_v_self->dtype_is_object = __pyx_t_4; + + /* "View.MemoryView":171 + * self.free_data = allocate_buffer + * self.dtype_is_object = format == b'O' + * if allocate_buffer: # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_4 = (__pyx_v_allocate_buffer != 0); + if (__pyx_t_4) { + + /* "View.MemoryView":174 + * + * + * self.data = malloc(self.len) # <<<<<<<<<<<<<< + * if not self.data: + * raise MemoryError("unable to allocate array data.") + */ + __pyx_v_self->data = ((char *)malloc(__pyx_v_self->len)); + + /* "View.MemoryView":175 + * + * self.data = malloc(self.len) + * if not self.data: # <<<<<<<<<<<<<< + * raise MemoryError("unable to allocate array data.") + * + */ + __pyx_t_4 = ((!(__pyx_v_self->data != 0)) != 0); + if (unlikely(__pyx_t_4)) { + + /* "View.MemoryView":176 + * self.data = malloc(self.len) + * if not self.data: + * raise MemoryError("unable to allocate array data.") # <<<<<<<<<<<<<< + * + * if self.dtype_is_object: + */ + __pyx_t_10 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 176, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_Raise(__pyx_t_10, 0, 0, 0); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __PYX_ERR(2, 176, __pyx_L1_error) + + /* "View.MemoryView":175 + * + * self.data = malloc(self.len) + * if not self.data: # <<<<<<<<<<<<<< + * raise MemoryError("unable to allocate array data.") + * + */ + } + + /* "View.MemoryView":178 + * raise MemoryError("unable to allocate array data.") + * + * if self.dtype_is_object: # <<<<<<<<<<<<<< + * p = self.data + * for i in range(self.len / itemsize): + */ + __pyx_t_4 = (__pyx_v_self->dtype_is_object != 0); + if (__pyx_t_4) { + + /* "View.MemoryView":179 + * + * if self.dtype_is_object: + * p = self.data # <<<<<<<<<<<<<< + * for i in range(self.len / itemsize): + * p[i] = Py_None + */ + __pyx_v_p = ((PyObject **)__pyx_v_self->data); + + /* "View.MemoryView":180 + * if self.dtype_is_object: + * p = self.data + * for i in range(self.len / itemsize): # <<<<<<<<<<<<<< + * p[i] = Py_None + * Py_INCREF(Py_None) + */ + if (unlikely(__pyx_v_itemsize == 0)) { + PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero"); + __PYX_ERR(2, 180, __pyx_L1_error) + } + else if (sizeof(Py_ssize_t) == sizeof(long) && (!(((Py_ssize_t)-1) > 0)) && unlikely(__pyx_v_itemsize == (Py_ssize_t)-1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_self->len))) { + PyErr_SetString(PyExc_OverflowError, "value too large to perform division"); + __PYX_ERR(2, 180, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_div_Py_ssize_t(__pyx_v_self->len, __pyx_v_itemsize); + __pyx_t_9 = __pyx_t_1; + for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_9; __pyx_t_11+=1) { + __pyx_v_i = __pyx_t_11; + + /* "View.MemoryView":181 + * p = self.data + * for i in range(self.len / itemsize): + * p[i] = Py_None # <<<<<<<<<<<<<< + * Py_INCREF(Py_None) + * + */ + (__pyx_v_p[__pyx_v_i]) = Py_None; + + /* "View.MemoryView":182 + * for i in range(self.len / itemsize): + * p[i] = Py_None + * Py_INCREF(Py_None) # <<<<<<<<<<<<<< + * + * @cname('getbuffer') + */ + Py_INCREF(Py_None); + } + + /* "View.MemoryView":178 + * raise MemoryError("unable to allocate array data.") + * + * if self.dtype_is_object: # <<<<<<<<<<<<<< + * p = self.data + * for i in range(self.len / itemsize): + */ + } + + /* "View.MemoryView":171 + * self.free_data = allocate_buffer + * self.dtype_is_object = format == b'O' + * if allocate_buffer: # <<<<<<<<<<<<<< + * + * + */ + } + + /* "View.MemoryView":122 + * cdef bint dtype_is_object + * + * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, # <<<<<<<<<<<<<< + * mode="c", bint allocate_buffer=True): + * + */ + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("View.MemoryView.array.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_format); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":185 + * + * @cname('getbuffer') + * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<< + * cdef int bufmode = -1 + * if self.mode == u"c": + */ + +/* Python wrapper */ +static CYTHON_UNUSED int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ +static CYTHON_UNUSED int __pyx_array_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_array___pyx_pf_15View_dot_MemoryView_5array_2__getbuffer__(((struct __pyx_array_obj *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_2__getbuffer__(struct __pyx_array_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { + int __pyx_v_bufmode; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + char *__pyx_t_4; + Py_ssize_t __pyx_t_5; + int __pyx_t_6; + Py_ssize_t *__pyx_t_7; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + 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); + + /* "View.MemoryView":186 + * @cname('getbuffer') + * def __getbuffer__(self, Py_buffer *info, int flags): + * cdef int bufmode = -1 # <<<<<<<<<<<<<< + * if self.mode == u"c": + * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + */ + __pyx_v_bufmode = -1; + + /* "View.MemoryView":187 + * def __getbuffer__(self, Py_buffer *info, int flags): + * cdef int bufmode = -1 + * if self.mode == u"c": # <<<<<<<<<<<<<< + * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + * elif self.mode == u"fortran": + */ + __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_self->mode, __pyx_n_u_c, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(2, 187, __pyx_L1_error) + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":188 + * cdef int bufmode = -1 + * if self.mode == u"c": + * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS # <<<<<<<<<<<<<< + * elif self.mode == u"fortran": + * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + */ + __pyx_v_bufmode = (PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS); + + /* "View.MemoryView":187 + * def __getbuffer__(self, Py_buffer *info, int flags): + * cdef int bufmode = -1 + * if self.mode == u"c": # <<<<<<<<<<<<<< + * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + * elif self.mode == u"fortran": + */ + goto __pyx_L3; + } + + /* "View.MemoryView":189 + * if self.mode == u"c": + * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + * elif self.mode == u"fortran": # <<<<<<<<<<<<<< + * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + * if not (flags & bufmode): + */ + __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_self->mode, __pyx_n_u_fortran, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(2, 189, __pyx_L1_error) + __pyx_t_1 = (__pyx_t_2 != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":190 + * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + * elif self.mode == u"fortran": + * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS # <<<<<<<<<<<<<< + * if not (flags & bufmode): + * raise ValueError("Can only create a buffer that is contiguous in memory.") + */ + __pyx_v_bufmode = (PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS); + + /* "View.MemoryView":189 + * if self.mode == u"c": + * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + * elif self.mode == u"fortran": # <<<<<<<<<<<<<< + * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + * if not (flags & bufmode): + */ + } + __pyx_L3:; + + /* "View.MemoryView":191 + * elif self.mode == u"fortran": + * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + * if not (flags & bufmode): # <<<<<<<<<<<<<< + * raise ValueError("Can only create a buffer that is contiguous in memory.") + * info.buf = self.data + */ + __pyx_t_1 = ((!((__pyx_v_flags & __pyx_v_bufmode) != 0)) != 0); + if (unlikely(__pyx_t_1)) { + + /* "View.MemoryView":192 + * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + * if not (flags & bufmode): + * raise ValueError("Can only create a buffer that is contiguous in memory.") # <<<<<<<<<<<<<< + * info.buf = self.data + * info.len = self.len + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 192, __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, 192, __pyx_L1_error) + + /* "View.MemoryView":191 + * elif self.mode == u"fortran": + * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + * if not (flags & bufmode): # <<<<<<<<<<<<<< + * raise ValueError("Can only create a buffer that is contiguous in memory.") + * info.buf = self.data + */ + } + + /* "View.MemoryView":193 + * if not (flags & bufmode): + * raise ValueError("Can only create a buffer that is contiguous in memory.") + * info.buf = self.data # <<<<<<<<<<<<<< + * info.len = self.len + * info.ndim = self.ndim + */ + __pyx_t_4 = __pyx_v_self->data; + __pyx_v_info->buf = __pyx_t_4; + + /* "View.MemoryView":194 + * raise ValueError("Can only create a buffer that is contiguous in memory.") + * info.buf = self.data + * info.len = self.len # <<<<<<<<<<<<<< + * info.ndim = self.ndim + * info.shape = self._shape + */ + __pyx_t_5 = __pyx_v_self->len; + __pyx_v_info->len = __pyx_t_5; + + /* "View.MemoryView":195 + * info.buf = self.data + * info.len = self.len + * info.ndim = self.ndim # <<<<<<<<<<<<<< + * info.shape = self._shape + * info.strides = self._strides + */ + __pyx_t_6 = __pyx_v_self->ndim; + __pyx_v_info->ndim = __pyx_t_6; + + /* "View.MemoryView":196 + * info.len = self.len + * info.ndim = self.ndim + * info.shape = self._shape # <<<<<<<<<<<<<< + * info.strides = self._strides + * info.suboffsets = NULL + */ + __pyx_t_7 = __pyx_v_self->_shape; + __pyx_v_info->shape = __pyx_t_7; + + /* "View.MemoryView":197 + * info.ndim = self.ndim + * info.shape = self._shape + * info.strides = self._strides # <<<<<<<<<<<<<< + * info.suboffsets = NULL + * info.itemsize = self.itemsize + */ + __pyx_t_7 = __pyx_v_self->_strides; + __pyx_v_info->strides = __pyx_t_7; + + /* "View.MemoryView":198 + * info.shape = self._shape + * info.strides = self._strides + * info.suboffsets = NULL # <<<<<<<<<<<<<< + * info.itemsize = self.itemsize + * info.readonly = 0 + */ + __pyx_v_info->suboffsets = NULL; + + /* "View.MemoryView":199 + * info.strides = self._strides + * info.suboffsets = NULL + * info.itemsize = self.itemsize # <<<<<<<<<<<<<< + * info.readonly = 0 + * + */ + __pyx_t_5 = __pyx_v_self->itemsize; + __pyx_v_info->itemsize = __pyx_t_5; + + /* "View.MemoryView":200 + * info.suboffsets = NULL + * info.itemsize = self.itemsize + * info.readonly = 0 # <<<<<<<<<<<<<< + * + * if flags & PyBUF_FORMAT: + */ + __pyx_v_info->readonly = 0; + + /* "View.MemoryView":202 + * info.readonly = 0 + * + * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< + * info.format = self.format + * else: + */ + __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":203 + * + * if flags & PyBUF_FORMAT: + * info.format = self.format # <<<<<<<<<<<<<< + * else: + * info.format = NULL + */ + __pyx_t_4 = __pyx_v_self->format; + __pyx_v_info->format = __pyx_t_4; + + /* "View.MemoryView":202 + * info.readonly = 0 + * + * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< + * info.format = self.format + * else: + */ + goto __pyx_L5; + } + + /* "View.MemoryView":205 + * info.format = self.format + * else: + * info.format = NULL # <<<<<<<<<<<<<< + * + * info.obj = self + */ + /*else*/ { + __pyx_v_info->format = NULL; + } + __pyx_L5:; + + /* "View.MemoryView":207 + * info.format = NULL + * + * info.obj = self # <<<<<<<<<<<<<< + * + * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)") + */ + __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); + + /* "View.MemoryView":185 + * + * @cname('getbuffer') + * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<< + * cdef int bufmode = -1 + * if self.mode == u"c": + */ + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("View.MemoryView.array.__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_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":211 + * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)") + * + * def __dealloc__(array self): # <<<<<<<<<<<<<< + * if self.callback_free_data != NULL: + * self.callback_free_data(self.data) + */ + +/* Python wrapper */ +static void __pyx_array___dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_array___dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_array___pyx_pf_15View_dot_MemoryView_5array_4__dealloc__(((struct __pyx_array_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); +} + +static void __pyx_array___pyx_pf_15View_dot_MemoryView_5array_4__dealloc__(struct __pyx_array_obj *__pyx_v_self) { + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "View.MemoryView":212 + * + * def __dealloc__(array self): + * if self.callback_free_data != NULL: # <<<<<<<<<<<<<< + * self.callback_free_data(self.data) + * elif self.free_data: + */ + __pyx_t_1 = ((__pyx_v_self->callback_free_data != NULL) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":213 + * def __dealloc__(array self): + * if self.callback_free_data != NULL: + * self.callback_free_data(self.data) # <<<<<<<<<<<<<< + * elif self.free_data: + * if self.dtype_is_object: + */ + __pyx_v_self->callback_free_data(__pyx_v_self->data); + + /* "View.MemoryView":212 + * + * def __dealloc__(array self): + * if self.callback_free_data != NULL: # <<<<<<<<<<<<<< + * self.callback_free_data(self.data) + * elif self.free_data: + */ + goto __pyx_L3; + } + + /* "View.MemoryView":214 + * if self.callback_free_data != NULL: + * self.callback_free_data(self.data) + * elif self.free_data: # <<<<<<<<<<<<<< + * if self.dtype_is_object: + * refcount_objects_in_slice(self.data, self._shape, + */ + __pyx_t_1 = (__pyx_v_self->free_data != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":215 + * self.callback_free_data(self.data) + * elif self.free_data: + * if self.dtype_is_object: # <<<<<<<<<<<<<< + * refcount_objects_in_slice(self.data, self._shape, + * self._strides, self.ndim, False) + */ + __pyx_t_1 = (__pyx_v_self->dtype_is_object != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":216 + * elif self.free_data: + * if self.dtype_is_object: + * refcount_objects_in_slice(self.data, self._shape, # <<<<<<<<<<<<<< + * self._strides, self.ndim, False) + * free(self.data) + */ + __pyx_memoryview_refcount_objects_in_slice(__pyx_v_self->data, __pyx_v_self->_shape, __pyx_v_self->_strides, __pyx_v_self->ndim, 0); + + /* "View.MemoryView":215 + * self.callback_free_data(self.data) + * elif self.free_data: + * if self.dtype_is_object: # <<<<<<<<<<<<<< + * refcount_objects_in_slice(self.data, self._shape, + * self._strides, self.ndim, False) + */ + } + + /* "View.MemoryView":218 + * refcount_objects_in_slice(self.data, self._shape, + * self._strides, self.ndim, False) + * free(self.data) # <<<<<<<<<<<<<< + * PyObject_Free(self._shape) + * + */ + free(__pyx_v_self->data); + + /* "View.MemoryView":214 + * if self.callback_free_data != NULL: + * self.callback_free_data(self.data) + * elif self.free_data: # <<<<<<<<<<<<<< + * if self.dtype_is_object: + * refcount_objects_in_slice(self.data, self._shape, + */ + } + __pyx_L3:; + + /* "View.MemoryView":219 + * self._strides, self.ndim, False) + * free(self.data) + * PyObject_Free(self._shape) # <<<<<<<<<<<<<< + * + * @property + */ + PyObject_Free(__pyx_v_self->_shape); + + /* "View.MemoryView":211 + * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)") + * + * def __dealloc__(array self): # <<<<<<<<<<<<<< + * if self.callback_free_data != NULL: + * self.callback_free_data(self.data) + */ + + /* function exit code */ + __Pyx_RefNannyFinishContext(); +} + +/* "View.MemoryView":222 + * + * @property + * def memview(self): # <<<<<<<<<<<<<< + * return self.get_memview() + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15View_dot_MemoryView_5array_7memview_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_15View_dot_MemoryView_5array_7memview_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_15View_dot_MemoryView_5array_7memview___get__(((struct __pyx_array_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15View_dot_MemoryView_5array_7memview___get__(struct __pyx_array_obj *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + + /* "View.MemoryView":223 + * @property + * def memview(self): + * return self.get_memview() # <<<<<<<<<<<<<< + * + * @cname('get_memview') + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = ((struct __pyx_vtabstruct_array *)__pyx_v_self->__pyx_vtab)->get_memview(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 223, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "View.MemoryView":222 + * + * @property + * def memview(self): # <<<<<<<<<<<<<< + * return self.get_memview() + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("View.MemoryView.array.memview.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":226 + * + * @cname('get_memview') + * cdef get_memview(self): # <<<<<<<<<<<<<< + * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE + * return memoryview(self, flags, self.dtype_is_object) + */ + +static PyObject *__pyx_array_get_memview(struct __pyx_array_obj *__pyx_v_self) { + int __pyx_v_flags; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("get_memview", 0); + + /* "View.MemoryView":227 + * @cname('get_memview') + * cdef get_memview(self): + * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE # <<<<<<<<<<<<<< + * return memoryview(self, flags, self.dtype_is_object) + * + */ + __pyx_v_flags = ((PyBUF_ANY_CONTIGUOUS | PyBUF_FORMAT) | PyBUF_WRITABLE); + + /* "View.MemoryView":228 + * cdef get_memview(self): + * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE + * return memoryview(self, flags, self.dtype_is_object) # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_flags); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 228, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_self->dtype_is_object); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 228, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 228, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 228, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "View.MemoryView":226 + * + * @cname('get_memview') + * cdef get_memview(self): # <<<<<<<<<<<<<< + * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE + * return memoryview(self, flags, self.dtype_is_object) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("View.MemoryView.array.get_memview", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":230 + * return memoryview(self, flags, self.dtype_is_object) + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self._shape[0] + * + */ + +/* Python wrapper */ +static Py_ssize_t __pyx_array___len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_array___len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_6__len__(((struct __pyx_array_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static Py_ssize_t __pyx_array___pyx_pf_15View_dot_MemoryView_5array_6__len__(struct __pyx_array_obj *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + + /* "View.MemoryView":231 + * + * def __len__(self): + * return self._shape[0] # <<<<<<<<<<<<<< + * + * def __getattr__(self, attr): + */ + __pyx_r = (__pyx_v_self->_shape[0]); + goto __pyx_L0; + + /* "View.MemoryView":230 + * return memoryview(self, flags, self.dtype_is_object) + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self._shape[0] + * + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":233 + * return self._shape[0] + * + * def __getattr__(self, attr): # <<<<<<<<<<<<<< + * return getattr(self.memview, attr) + * + */ + +/* Python wrapper */ +static PyObject *__pyx_array___getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_attr); /*proto*/ +static PyObject *__pyx_array___getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_attr) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getattr__ (wrapper)", 0); + __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_8__getattr__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_attr)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_8__getattr__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_attr) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__getattr__", 0); + + /* "View.MemoryView":234 + * + * def __getattr__(self, attr): + * return getattr(self.memview, attr) # <<<<<<<<<<<<<< + * + * def __getitem__(self, item): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 234, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_GetAttr(__pyx_t_1, __pyx_v_attr); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 234, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "View.MemoryView":233 + * return self._shape[0] + * + * def __getattr__(self, attr): # <<<<<<<<<<<<<< + * return getattr(self.memview, attr) + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("View.MemoryView.array.__getattr__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":236 + * return getattr(self.memview, attr) + * + * def __getitem__(self, item): # <<<<<<<<<<<<<< + * return self.memview[item] + * + */ + +/* Python wrapper */ +static PyObject *__pyx_array___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item); /*proto*/ +static PyObject *__pyx_array___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_10__getitem__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_item)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_10__getitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__getitem__", 0); + + /* "View.MemoryView":237 + * + * def __getitem__(self, item): + * return self.memview[item] # <<<<<<<<<<<<<< + * + * def __setitem__(self, item, value): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 237, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_item); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 237, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "View.MemoryView":236 + * return getattr(self.memview, attr) + * + * def __getitem__(self, item): # <<<<<<<<<<<<<< + * return self.memview[item] + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("View.MemoryView.array.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":239 + * return self.memview[item] + * + * def __setitem__(self, item, value): # <<<<<<<<<<<<<< + * self.memview[item] = value + * + */ + +/* Python wrapper */ +static int __pyx_array___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_array___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); + __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_12__setitem__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_item), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_12__setitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__setitem__", 0); + + /* "View.MemoryView":240 + * + * def __setitem__(self, item, value): + * self.memview[item] = value # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 240, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (unlikely(PyObject_SetItem(__pyx_t_1, __pyx_v_item, __pyx_v_value) < 0)) __PYX_ERR(2, 240, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "View.MemoryView":239 + * return self.memview[item] + * + * def __setitem__(self, item, value): # <<<<<<<<<<<<<< + * self.memview[item] = value + * + */ + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("View.MemoryView.array.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(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___pyx_array_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw___pyx_array_1__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___pyx_array___reduce_cython__(((struct __pyx_array_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf___pyx_array___reduce_cython__(CYTHON_UNUSED struct __pyx_array_obj *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __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__11, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 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(2, 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("View.MemoryView.array.__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___pyx_array_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw___pyx_array_3__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___pyx_array_2__setstate_cython__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf___pyx_array_2__setstate_cython__(CYTHON_UNUSED struct __pyx_array_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __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__12, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 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(2, 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("View.MemoryView.array.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":244 + * + * @cname("__pyx_array_new") + * cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format, # <<<<<<<<<<<<<< + * char *mode, char *buf): + * cdef array result + */ + +static struct __pyx_array_obj *__pyx_array_new(PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, char *__pyx_v_format, char *__pyx_v_mode, char *__pyx_v_buf) { + struct __pyx_array_obj *__pyx_v_result = 0; + struct __pyx_array_obj *__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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("array_cwrapper", 0); + + /* "View.MemoryView":248 + * cdef array result + * + * if buf == NULL: # <<<<<<<<<<<<<< + * result = array(shape, itemsize, format, mode.decode('ASCII')) + * else: + */ + __pyx_t_1 = ((__pyx_v_buf == NULL) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":249 + * + * if buf == NULL: + * result = array(shape, itemsize, format, mode.decode('ASCII')) # <<<<<<<<<<<<<< + * else: + * result = array(shape, itemsize, format, mode.decode('ASCII'), + */ + __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_itemsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 249, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 249, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_decode_c_string(__pyx_v_mode, 0, strlen(__pyx_v_mode), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 249, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 249, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_v_shape); + __Pyx_GIVEREF(__pyx_v_shape); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_shape); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_4); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_array_type), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 249, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_result = ((struct __pyx_array_obj *)__pyx_t_4); + __pyx_t_4 = 0; + + /* "View.MemoryView":248 + * cdef array result + * + * if buf == NULL: # <<<<<<<<<<<<<< + * result = array(shape, itemsize, format, mode.decode('ASCII')) + * else: + */ + goto __pyx_L3; + } + + /* "View.MemoryView":251 + * result = array(shape, itemsize, format, mode.decode('ASCII')) + * else: + * result = array(shape, itemsize, format, mode.decode('ASCII'), # <<<<<<<<<<<<<< + * allocate_buffer=False) + * result.data = buf + */ + /*else*/ { + __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_itemsize); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 251, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyBytes_FromString(__pyx_v_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 251, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = __Pyx_decode_c_string(__pyx_v_mode, 0, strlen(__pyx_v_mode), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 251, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 251, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_shape); + __Pyx_GIVEREF(__pyx_v_shape); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_shape); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_3); + __pyx_t_4 = 0; + __pyx_t_5 = 0; + __pyx_t_3 = 0; + + /* "View.MemoryView":252 + * else: + * result = array(shape, itemsize, format, mode.decode('ASCII'), + * allocate_buffer=False) # <<<<<<<<<<<<<< + * result.data = buf + * + */ + __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 252, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_allocate_buffer, Py_False) < 0) __PYX_ERR(2, 252, __pyx_L1_error) + + /* "View.MemoryView":251 + * result = array(shape, itemsize, format, mode.decode('ASCII')) + * else: + * result = array(shape, itemsize, format, mode.decode('ASCII'), # <<<<<<<<<<<<<< + * allocate_buffer=False) + * result.data = buf + */ + __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_array_type), __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 251, __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_result = ((struct __pyx_array_obj *)__pyx_t_5); + __pyx_t_5 = 0; + + /* "View.MemoryView":253 + * result = array(shape, itemsize, format, mode.decode('ASCII'), + * allocate_buffer=False) + * result.data = buf # <<<<<<<<<<<<<< + * + * return result + */ + __pyx_v_result->data = __pyx_v_buf; + } + __pyx_L3:; + + /* "View.MemoryView":255 + * result.data = buf + * + * return result # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + /* "View.MemoryView":244 + * + * @cname("__pyx_array_new") + * cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format, # <<<<<<<<<<<<<< + * char *mode, char *buf): + * cdef array result + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("View.MemoryView.array_cwrapper", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_result); + __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":281 + * cdef class Enum(object): + * cdef object name + * def __init__(self, name): # <<<<<<<<<<<<<< + * self.name = name + * def __repr__(self): + */ + +/* Python wrapper */ +static int __pyx_MemviewEnum___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_MemviewEnum___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_name = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_name,0}; + PyObject* values[1] = {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 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_name)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(2, 281, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + } + __pyx_v_name = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 281, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("View.MemoryView.Enum.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum___init__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self), __pyx_v_name); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum___init__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v_name) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__", 0); + + /* "View.MemoryView":282 + * cdef object name + * def __init__(self, name): + * self.name = name # <<<<<<<<<<<<<< + * def __repr__(self): + * return self.name + */ + __Pyx_INCREF(__pyx_v_name); + __Pyx_GIVEREF(__pyx_v_name); + __Pyx_GOTREF(__pyx_v_self->name); + __Pyx_DECREF(__pyx_v_self->name); + __pyx_v_self->name = __pyx_v_name; + + /* "View.MemoryView":281 + * cdef class Enum(object): + * cdef object name + * def __init__(self, name): # <<<<<<<<<<<<<< + * self.name = name + * def __repr__(self): + */ + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":283 + * def __init__(self, name): + * self.name = name + * def __repr__(self): # <<<<<<<<<<<<<< + * return self.name + * + */ + +/* Python wrapper */ +static PyObject *__pyx_MemviewEnum___repr__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_MemviewEnum___repr__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0); + __pyx_r = __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum_2__repr__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum_2__repr__(struct __pyx_MemviewEnum_obj *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__repr__", 0); + + /* "View.MemoryView":284 + * self.name = name + * def __repr__(self): + * return self.name # <<<<<<<<<<<<<< + * + * cdef generic = Enum("") + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->name); + __pyx_r = __pyx_v_self->name; + goto __pyx_L0; + + /* "View.MemoryView":283 + * def __init__(self, name): + * self.name = name + * def __repr__(self): # <<<<<<<<<<<<<< + * return self.name + * + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + +/* Python wrapper */ +static PyObject *__pyx_pw___pyx_MemviewEnum_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw___pyx_MemviewEnum_1__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___pyx_MemviewEnum___reduce_cython__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf___pyx_MemviewEnum___reduce_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self) { + PyObject *__pyx_v_state = 0; + PyObject *__pyx_v__dict = 0; + int __pyx_v_use_setstate; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + + /* "(tree fragment)":5 + * cdef object _dict + * cdef bint use_setstate + * state = (self.name,) # <<<<<<<<<<<<<< + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_self->name); + __Pyx_GIVEREF(__pyx_v_self->name); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->name); + __pyx_v_state = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "(tree fragment)":6 + * cdef bint use_setstate + * state = (self.name,) + * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< + * if _dict is not None: + * state += (_dict,) + */ + __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v__dict = __pyx_t_1; + __pyx_t_1 = 0; + + /* "(tree fragment)":7 + * state = (self.name,) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + __pyx_t_2 = (__pyx_v__dict != Py_None); + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { + + /* "(tree fragment)":8 + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + * state += (_dict,) # <<<<<<<<<<<<<< + * use_setstate = True + * else: + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v__dict); + __Pyx_GIVEREF(__pyx_v__dict); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict); + __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4)); + __pyx_t_4 = 0; + + /* "(tree fragment)":9 + * if _dict is not None: + * state += (_dict,) + * use_setstate = True # <<<<<<<<<<<<<< + * else: + * use_setstate = self.name is not None + */ + __pyx_v_use_setstate = 1; + + /* "(tree fragment)":7 + * state = (self.name,) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + goto __pyx_L3; + } + + /* "(tree fragment)":11 + * use_setstate = True + * else: + * use_setstate = self.name is not None # <<<<<<<<<<<<<< + * if use_setstate: + * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state + */ + /*else*/ { + __pyx_t_3 = (__pyx_v_self->name != Py_None); + __pyx_v_use_setstate = __pyx_t_3; + } + __pyx_L3:; + + /* "(tree fragment)":12 + * else: + * use_setstate = self.name is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state + * else: + */ + __pyx_t_3 = (__pyx_v_use_setstate != 0); + if (__pyx_t_3) { + + /* "(tree fragment)":13 + * use_setstate = self.name is not None + * if use_setstate: + * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state # <<<<<<<<<<<<<< + * else: + * return __pyx_unpickle_Enum, (type(self), 0xb068931, state) + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pyx_unpickle_Enum); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_184977713); + __Pyx_GIVEREF(__pyx_int_184977713); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_184977713); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None); + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_state); + __pyx_t_4 = 0; + __pyx_t_1 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; + + /* "(tree fragment)":12 + * else: + * use_setstate = self.name is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state + * else: + */ + } + + /* "(tree fragment)":15 + * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state + * else: + * return __pyx_unpickle_Enum, (type(self), 0xb068931, state) # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_Enum__set_state(self, __pyx_state) + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_pyx_unpickle_Enum); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_184977713); + __Pyx_GIVEREF(__pyx_int_184977713); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_184977713); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1); + __pyx_t_5 = 0; + __pyx_t_1 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + } + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("View.MemoryView.Enum.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_state); + __Pyx_XDECREF(__pyx_v__dict); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":16 + * else: + * return __pyx_unpickle_Enum, (type(self), 0xb068931, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_Enum__set_state(self, __pyx_state) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw___pyx_MemviewEnum_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw___pyx_MemviewEnum_3__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___pyx_MemviewEnum_2__setstate_cython__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf___pyx_MemviewEnum_2__setstate_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + + /* "(tree fragment)":17 + * return __pyx_unpickle_Enum, (type(self), 0xb068931, state) + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_Enum__set_state(self, __pyx_state) # <<<<<<<<<<<<<< + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 17, __pyx_L1_error) + __pyx_t_1 = __pyx_unpickle_Enum__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":16 + * else: + * return __pyx_unpickle_Enum, (type(self), 0xb068931, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_Enum__set_state(self, __pyx_state) + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("View.MemoryView.Enum.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":298 + * + * @cname('__pyx_align_pointer') + * cdef void *align_pointer(void *memory, size_t alignment) nogil: # <<<<<<<<<<<<<< + * "Align pointer memory on a given boundary" + * cdef Py_intptr_t aligned_p = memory + */ + +static void *__pyx_align_pointer(void *__pyx_v_memory, size_t __pyx_v_alignment) { + Py_intptr_t __pyx_v_aligned_p; + size_t __pyx_v_offset; + void *__pyx_r; + int __pyx_t_1; + + /* "View.MemoryView":300 + * cdef void *align_pointer(void *memory, size_t alignment) nogil: + * "Align pointer memory on a given boundary" + * cdef Py_intptr_t aligned_p = memory # <<<<<<<<<<<<<< + * cdef size_t offset + * + */ + __pyx_v_aligned_p = ((Py_intptr_t)__pyx_v_memory); + + /* "View.MemoryView":304 + * + * with cython.cdivision(True): + * offset = aligned_p % alignment # <<<<<<<<<<<<<< + * + * if offset > 0: + */ + __pyx_v_offset = (__pyx_v_aligned_p % __pyx_v_alignment); + + /* "View.MemoryView":306 + * offset = aligned_p % alignment + * + * if offset > 0: # <<<<<<<<<<<<<< + * aligned_p += alignment - offset + * + */ + __pyx_t_1 = ((__pyx_v_offset > 0) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":307 + * + * if offset > 0: + * aligned_p += alignment - offset # <<<<<<<<<<<<<< + * + * return aligned_p + */ + __pyx_v_aligned_p = (__pyx_v_aligned_p + (__pyx_v_alignment - __pyx_v_offset)); + + /* "View.MemoryView":306 + * offset = aligned_p % alignment + * + * if offset > 0: # <<<<<<<<<<<<<< + * aligned_p += alignment - offset + * + */ + } + + /* "View.MemoryView":309 + * aligned_p += alignment - offset + * + * return aligned_p # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = ((void *)__pyx_v_aligned_p); + goto __pyx_L0; + + /* "View.MemoryView":298 + * + * @cname('__pyx_align_pointer') + * cdef void *align_pointer(void *memory, size_t alignment) nogil: # <<<<<<<<<<<<<< + * "Align pointer memory on a given boundary" + * cdef Py_intptr_t aligned_p = memory + */ + + /* function exit code */ + __pyx_L0:; + return __pyx_r; +} + +/* "View.MemoryView":345 + * cdef __Pyx_TypeInfo *typeinfo + * + * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False): # <<<<<<<<<<<<<< + * self.obj = obj + * self.flags = flags + */ + +/* Python wrapper */ +static int __pyx_memoryview___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_memoryview___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_obj = 0; + int __pyx_v_flags; + int __pyx_v_dtype_is_object; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_obj,&__pyx_n_s_flags,&__pyx_n_s_dtype_is_object,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_obj)) != 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_flags)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, 1); __PYX_ERR(2, 345, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dtype_is_object); + if (value) { values[2] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(2, 345, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + 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_obj = values[0]; + __pyx_v_flags = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_flags == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 345, __pyx_L3_error) + if (values[2]) { + __pyx_v_dtype_is_object = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_dtype_is_object == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 345, __pyx_L3_error) + } else { + __pyx_v_dtype_is_object = ((int)0); + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 345, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("View.MemoryView.memoryview.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview___cinit__(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_obj, __pyx_v_flags, __pyx_v_dtype_is_object); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview___cinit__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj, int __pyx_v_flags, int __pyx_v_dtype_is_object) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "View.MemoryView":346 + * + * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False): + * self.obj = obj # <<<<<<<<<<<<<< + * self.flags = flags + * if type(self) is memoryview or obj is not None: + */ + __Pyx_INCREF(__pyx_v_obj); + __Pyx_GIVEREF(__pyx_v_obj); + __Pyx_GOTREF(__pyx_v_self->obj); + __Pyx_DECREF(__pyx_v_self->obj); + __pyx_v_self->obj = __pyx_v_obj; + + /* "View.MemoryView":347 + * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False): + * self.obj = obj + * self.flags = flags # <<<<<<<<<<<<<< + * if type(self) is memoryview or obj is not None: + * __Pyx_GetBuffer(obj, &self.view, flags) + */ + __pyx_v_self->flags = __pyx_v_flags; + + /* "View.MemoryView":348 + * self.obj = obj + * self.flags = flags + * if type(self) is memoryview or obj is not None: # <<<<<<<<<<<<<< + * __Pyx_GetBuffer(obj, &self.view, flags) + * if self.view.obj == NULL: + */ + __pyx_t_2 = (((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))) == ((PyObject *)__pyx_memoryview_type)); + __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 = (__pyx_v_obj != Py_None); + __pyx_t_2 = (__pyx_t_3 != 0); + __pyx_t_1 = __pyx_t_2; + __pyx_L4_bool_binop_done:; + if (__pyx_t_1) { + + /* "View.MemoryView":349 + * self.flags = flags + * if type(self) is memoryview or obj is not None: + * __Pyx_GetBuffer(obj, &self.view, flags) # <<<<<<<<<<<<<< + * if self.view.obj == NULL: + * (<__pyx_buffer *> &self.view).obj = Py_None + */ + __pyx_t_4 = __Pyx_GetBuffer(__pyx_v_obj, (&__pyx_v_self->view), __pyx_v_flags); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(2, 349, __pyx_L1_error) + + /* "View.MemoryView":350 + * if type(self) is memoryview or obj is not None: + * __Pyx_GetBuffer(obj, &self.view, flags) + * if self.view.obj == NULL: # <<<<<<<<<<<<<< + * (<__pyx_buffer *> &self.view).obj = Py_None + * Py_INCREF(Py_None) + */ + __pyx_t_1 = ((((PyObject *)__pyx_v_self->view.obj) == NULL) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":351 + * __Pyx_GetBuffer(obj, &self.view, flags) + * if self.view.obj == NULL: + * (<__pyx_buffer *> &self.view).obj = Py_None # <<<<<<<<<<<<<< + * Py_INCREF(Py_None) + * + */ + ((Py_buffer *)(&__pyx_v_self->view))->obj = Py_None; + + /* "View.MemoryView":352 + * if self.view.obj == NULL: + * (<__pyx_buffer *> &self.view).obj = Py_None + * Py_INCREF(Py_None) # <<<<<<<<<<<<<< + * + * global __pyx_memoryview_thread_locks_used + */ + Py_INCREF(Py_None); + + /* "View.MemoryView":350 + * if type(self) is memoryview or obj is not None: + * __Pyx_GetBuffer(obj, &self.view, flags) + * if self.view.obj == NULL: # <<<<<<<<<<<<<< + * (<__pyx_buffer *> &self.view).obj = Py_None + * Py_INCREF(Py_None) + */ + } + + /* "View.MemoryView":348 + * self.obj = obj + * self.flags = flags + * if type(self) is memoryview or obj is not None: # <<<<<<<<<<<<<< + * __Pyx_GetBuffer(obj, &self.view, flags) + * if self.view.obj == NULL: + */ + } + + /* "View.MemoryView":355 + * + * global __pyx_memoryview_thread_locks_used + * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED: # <<<<<<<<<<<<<< + * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] + * __pyx_memoryview_thread_locks_used += 1 + */ + __pyx_t_1 = ((__pyx_memoryview_thread_locks_used < 8) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":356 + * global __pyx_memoryview_thread_locks_used + * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED: + * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] # <<<<<<<<<<<<<< + * __pyx_memoryview_thread_locks_used += 1 + * if self.lock is NULL: + */ + __pyx_v_self->lock = (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]); + + /* "View.MemoryView":357 + * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED: + * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] + * __pyx_memoryview_thread_locks_used += 1 # <<<<<<<<<<<<<< + * if self.lock is NULL: + * self.lock = PyThread_allocate_lock() + */ + __pyx_memoryview_thread_locks_used = (__pyx_memoryview_thread_locks_used + 1); + + /* "View.MemoryView":355 + * + * global __pyx_memoryview_thread_locks_used + * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED: # <<<<<<<<<<<<<< + * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] + * __pyx_memoryview_thread_locks_used += 1 + */ + } + + /* "View.MemoryView":358 + * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] + * __pyx_memoryview_thread_locks_used += 1 + * if self.lock is NULL: # <<<<<<<<<<<<<< + * self.lock = PyThread_allocate_lock() + * if self.lock is NULL: + */ + __pyx_t_1 = ((__pyx_v_self->lock == NULL) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":359 + * __pyx_memoryview_thread_locks_used += 1 + * if self.lock is NULL: + * self.lock = PyThread_allocate_lock() # <<<<<<<<<<<<<< + * if self.lock is NULL: + * raise MemoryError + */ + __pyx_v_self->lock = PyThread_allocate_lock(); + + /* "View.MemoryView":360 + * if self.lock is NULL: + * self.lock = PyThread_allocate_lock() + * if self.lock is NULL: # <<<<<<<<<<<<<< + * raise MemoryError + * + */ + __pyx_t_1 = ((__pyx_v_self->lock == NULL) != 0); + if (unlikely(__pyx_t_1)) { + + /* "View.MemoryView":361 + * self.lock = PyThread_allocate_lock() + * if self.lock is NULL: + * raise MemoryError # <<<<<<<<<<<<<< + * + * if flags & PyBUF_FORMAT: + */ + PyErr_NoMemory(); __PYX_ERR(2, 361, __pyx_L1_error) + + /* "View.MemoryView":360 + * if self.lock is NULL: + * self.lock = PyThread_allocate_lock() + * if self.lock is NULL: # <<<<<<<<<<<<<< + * raise MemoryError + * + */ + } + + /* "View.MemoryView":358 + * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] + * __pyx_memoryview_thread_locks_used += 1 + * if self.lock is NULL: # <<<<<<<<<<<<<< + * self.lock = PyThread_allocate_lock() + * if self.lock is NULL: + */ + } + + /* "View.MemoryView":363 + * raise MemoryError + * + * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< + * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0') + * else: + */ + __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":364 + * + * if flags & PyBUF_FORMAT: + * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0') # <<<<<<<<<<<<<< + * else: + * self.dtype_is_object = dtype_is_object + */ + __pyx_t_2 = (((__pyx_v_self->view.format[0]) == 'O') != 0); + if (__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L11_bool_binop_done; + } + __pyx_t_2 = (((__pyx_v_self->view.format[1]) == '\x00') != 0); + __pyx_t_1 = __pyx_t_2; + __pyx_L11_bool_binop_done:; + __pyx_v_self->dtype_is_object = __pyx_t_1; + + /* "View.MemoryView":363 + * raise MemoryError + * + * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< + * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0') + * else: + */ + goto __pyx_L10; + } + + /* "View.MemoryView":366 + * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0') + * else: + * self.dtype_is_object = dtype_is_object # <<<<<<<<<<<<<< + * + * self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer( + */ + /*else*/ { + __pyx_v_self->dtype_is_object = __pyx_v_dtype_is_object; + } + __pyx_L10:; + + /* "View.MemoryView":368 + * self.dtype_is_object = dtype_is_object + * + * self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer( # <<<<<<<<<<<<<< + * &self.acquisition_count[0], sizeof(__pyx_atomic_int)) + * self.typeinfo = NULL + */ + __pyx_v_self->acquisition_count_aligned_p = ((__pyx_atomic_int *)__pyx_align_pointer(((void *)(&(__pyx_v_self->acquisition_count[0]))), (sizeof(__pyx_atomic_int)))); + + /* "View.MemoryView":370 + * self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer( + * &self.acquisition_count[0], sizeof(__pyx_atomic_int)) + * self.typeinfo = NULL # <<<<<<<<<<<<<< + * + * def __dealloc__(memoryview self): + */ + __pyx_v_self->typeinfo = NULL; + + /* "View.MemoryView":345 + * cdef __Pyx_TypeInfo *typeinfo + * + * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False): # <<<<<<<<<<<<<< + * self.obj = obj + * self.flags = flags + */ + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("View.MemoryView.memoryview.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":372 + * self.typeinfo = NULL + * + * def __dealloc__(memoryview self): # <<<<<<<<<<<<<< + * if self.obj is not None: + * __Pyx_ReleaseBuffer(&self.view) + */ + +/* Python wrapper */ +static void __pyx_memoryview___dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_memoryview___dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_2__dealloc__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); +} + +static void __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_2__dealloc__(struct __pyx_memoryview_obj *__pyx_v_self) { + int __pyx_v_i; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + PyThread_type_lock __pyx_t_6; + PyThread_type_lock __pyx_t_7; + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "View.MemoryView":373 + * + * def __dealloc__(memoryview self): + * if self.obj is not None: # <<<<<<<<<<<<<< + * __Pyx_ReleaseBuffer(&self.view) + * elif (<__pyx_buffer *> &self.view).obj == Py_None: + */ + __pyx_t_1 = (__pyx_v_self->obj != Py_None); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":374 + * def __dealloc__(memoryview self): + * if self.obj is not None: + * __Pyx_ReleaseBuffer(&self.view) # <<<<<<<<<<<<<< + * elif (<__pyx_buffer *> &self.view).obj == Py_None: + * + */ + __Pyx_ReleaseBuffer((&__pyx_v_self->view)); + + /* "View.MemoryView":373 + * + * def __dealloc__(memoryview self): + * if self.obj is not None: # <<<<<<<<<<<<<< + * __Pyx_ReleaseBuffer(&self.view) + * elif (<__pyx_buffer *> &self.view).obj == Py_None: + */ + goto __pyx_L3; + } + + /* "View.MemoryView":375 + * if self.obj is not None: + * __Pyx_ReleaseBuffer(&self.view) + * elif (<__pyx_buffer *> &self.view).obj == Py_None: # <<<<<<<<<<<<<< + * + * (<__pyx_buffer *> &self.view).obj = NULL + */ + __pyx_t_2 = ((((Py_buffer *)(&__pyx_v_self->view))->obj == Py_None) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":377 + * elif (<__pyx_buffer *> &self.view).obj == Py_None: + * + * (<__pyx_buffer *> &self.view).obj = NULL # <<<<<<<<<<<<<< + * Py_DECREF(Py_None) + * + */ + ((Py_buffer *)(&__pyx_v_self->view))->obj = NULL; + + /* "View.MemoryView":378 + * + * (<__pyx_buffer *> &self.view).obj = NULL + * Py_DECREF(Py_None) # <<<<<<<<<<<<<< + * + * cdef int i + */ + Py_DECREF(Py_None); + + /* "View.MemoryView":375 + * if self.obj is not None: + * __Pyx_ReleaseBuffer(&self.view) + * elif (<__pyx_buffer *> &self.view).obj == Py_None: # <<<<<<<<<<<<<< + * + * (<__pyx_buffer *> &self.view).obj = NULL + */ + } + __pyx_L3:; + + /* "View.MemoryView":382 + * cdef int i + * global __pyx_memoryview_thread_locks_used + * if self.lock != NULL: # <<<<<<<<<<<<<< + * for i in range(__pyx_memoryview_thread_locks_used): + * if __pyx_memoryview_thread_locks[i] is self.lock: + */ + __pyx_t_2 = ((__pyx_v_self->lock != NULL) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":383 + * global __pyx_memoryview_thread_locks_used + * if self.lock != NULL: + * for i in range(__pyx_memoryview_thread_locks_used): # <<<<<<<<<<<<<< + * if __pyx_memoryview_thread_locks[i] is self.lock: + * __pyx_memoryview_thread_locks_used -= 1 + */ + __pyx_t_3 = __pyx_memoryview_thread_locks_used; + __pyx_t_4 = __pyx_t_3; + for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { + __pyx_v_i = __pyx_t_5; + + /* "View.MemoryView":384 + * if self.lock != NULL: + * for i in range(__pyx_memoryview_thread_locks_used): + * if __pyx_memoryview_thread_locks[i] is self.lock: # <<<<<<<<<<<<<< + * __pyx_memoryview_thread_locks_used -= 1 + * if i != __pyx_memoryview_thread_locks_used: + */ + __pyx_t_2 = (((__pyx_memoryview_thread_locks[__pyx_v_i]) == __pyx_v_self->lock) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":385 + * for i in range(__pyx_memoryview_thread_locks_used): + * if __pyx_memoryview_thread_locks[i] is self.lock: + * __pyx_memoryview_thread_locks_used -= 1 # <<<<<<<<<<<<<< + * if i != __pyx_memoryview_thread_locks_used: + * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( + */ + __pyx_memoryview_thread_locks_used = (__pyx_memoryview_thread_locks_used - 1); + + /* "View.MemoryView":386 + * if __pyx_memoryview_thread_locks[i] is self.lock: + * __pyx_memoryview_thread_locks_used -= 1 + * if i != __pyx_memoryview_thread_locks_used: # <<<<<<<<<<<<<< + * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( + * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i]) + */ + __pyx_t_2 = ((__pyx_v_i != __pyx_memoryview_thread_locks_used) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":388 + * if i != __pyx_memoryview_thread_locks_used: + * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( + * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i]) # <<<<<<<<<<<<<< + * break + * else: + */ + __pyx_t_6 = (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]); + __pyx_t_7 = (__pyx_memoryview_thread_locks[__pyx_v_i]); + + /* "View.MemoryView":387 + * __pyx_memoryview_thread_locks_used -= 1 + * if i != __pyx_memoryview_thread_locks_used: + * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( # <<<<<<<<<<<<<< + * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i]) + * break + */ + (__pyx_memoryview_thread_locks[__pyx_v_i]) = __pyx_t_6; + (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]) = __pyx_t_7; + + /* "View.MemoryView":386 + * if __pyx_memoryview_thread_locks[i] is self.lock: + * __pyx_memoryview_thread_locks_used -= 1 + * if i != __pyx_memoryview_thread_locks_used: # <<<<<<<<<<<<<< + * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( + * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i]) + */ + } + + /* "View.MemoryView":389 + * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( + * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i]) + * break # <<<<<<<<<<<<<< + * else: + * PyThread_free_lock(self.lock) + */ + goto __pyx_L6_break; + + /* "View.MemoryView":384 + * if self.lock != NULL: + * for i in range(__pyx_memoryview_thread_locks_used): + * if __pyx_memoryview_thread_locks[i] is self.lock: # <<<<<<<<<<<<<< + * __pyx_memoryview_thread_locks_used -= 1 + * if i != __pyx_memoryview_thread_locks_used: + */ + } + } + /*else*/ { + + /* "View.MemoryView":391 + * break + * else: + * PyThread_free_lock(self.lock) # <<<<<<<<<<<<<< + * + * cdef char *get_item_pointer(memoryview self, object index) except NULL: + */ + PyThread_free_lock(__pyx_v_self->lock); + } + __pyx_L6_break:; + + /* "View.MemoryView":382 + * cdef int i + * global __pyx_memoryview_thread_locks_used + * if self.lock != NULL: # <<<<<<<<<<<<<< + * for i in range(__pyx_memoryview_thread_locks_used): + * if __pyx_memoryview_thread_locks[i] is self.lock: + */ + } + + /* "View.MemoryView":372 + * self.typeinfo = NULL + * + * def __dealloc__(memoryview self): # <<<<<<<<<<<<<< + * if self.obj is not None: + * __Pyx_ReleaseBuffer(&self.view) + */ + + /* function exit code */ + __Pyx_RefNannyFinishContext(); +} + +/* "View.MemoryView":393 + * PyThread_free_lock(self.lock) + * + * cdef char *get_item_pointer(memoryview self, object index) except NULL: # <<<<<<<<<<<<<< + * cdef Py_ssize_t dim + * cdef char *itemp = self.view.buf + */ + +static char *__pyx_memoryview_get_item_pointer(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index) { + Py_ssize_t __pyx_v_dim; + char *__pyx_v_itemp; + PyObject *__pyx_v_idx = NULL; + char *__pyx_r; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + PyObject *(*__pyx_t_4)(PyObject *); + PyObject *__pyx_t_5 = NULL; + Py_ssize_t __pyx_t_6; + char *__pyx_t_7; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("get_item_pointer", 0); + + /* "View.MemoryView":395 + * cdef char *get_item_pointer(memoryview self, object index) except NULL: + * cdef Py_ssize_t dim + * cdef char *itemp = self.view.buf # <<<<<<<<<<<<<< + * + * for dim, idx in enumerate(index): + */ + __pyx_v_itemp = ((char *)__pyx_v_self->view.buf); + + /* "View.MemoryView":397 + * cdef char *itemp = self.view.buf + * + * for dim, idx in enumerate(index): # <<<<<<<<<<<<<< + * itemp = pybuffer_index(&self.view, itemp, idx, dim) + * + */ + __pyx_t_1 = 0; + if (likely(PyList_CheckExact(__pyx_v_index)) || PyTuple_CheckExact(__pyx_v_index)) { + __pyx_t_2 = __pyx_v_index; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 397, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 397, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_4)) { + if (likely(PyList_CheckExact(__pyx_t_2))) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(2, 397, __pyx_L1_error) + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 397, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + } else { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(2, 397, __pyx_L1_error) + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 397, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + } + } else { + __pyx_t_5 = __pyx_t_4(__pyx_t_2); + 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(2, 397, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_5); + } + __Pyx_XDECREF_SET(__pyx_v_idx, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_v_dim = __pyx_t_1; + __pyx_t_1 = (__pyx_t_1 + 1); + + /* "View.MemoryView":398 + * + * for dim, idx in enumerate(index): + * itemp = pybuffer_index(&self.view, itemp, idx, dim) # <<<<<<<<<<<<<< + * + * return itemp + */ + __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_v_idx); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 398, __pyx_L1_error) + __pyx_t_7 = __pyx_pybuffer_index((&__pyx_v_self->view), __pyx_v_itemp, __pyx_t_6, __pyx_v_dim); if (unlikely(__pyx_t_7 == ((char *)NULL))) __PYX_ERR(2, 398, __pyx_L1_error) + __pyx_v_itemp = __pyx_t_7; + + /* "View.MemoryView":397 + * cdef char *itemp = self.view.buf + * + * for dim, idx in enumerate(index): # <<<<<<<<<<<<<< + * itemp = pybuffer_index(&self.view, itemp, idx, dim) + * + */ + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "View.MemoryView":400 + * itemp = pybuffer_index(&self.view, itemp, idx, dim) + * + * return itemp # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_itemp; + goto __pyx_L0; + + /* "View.MemoryView":393 + * PyThread_free_lock(self.lock) + * + * cdef char *get_item_pointer(memoryview self, object index) except NULL: # <<<<<<<<<<<<<< + * cdef Py_ssize_t dim + * cdef char *itemp = self.view.buf + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("View.MemoryView.memoryview.get_item_pointer", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_idx); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":403 + * + * + * def __getitem__(memoryview self, object index): # <<<<<<<<<<<<<< + * if index is Ellipsis: + * return self + */ + +/* Python wrapper */ +static PyObject *__pyx_memoryview___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index); /*proto*/ +static PyObject *__pyx_memoryview___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_4__getitem__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v_index)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_4__getitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index) { + PyObject *__pyx_v_have_slices = NULL; + PyObject *__pyx_v_indices = NULL; + char *__pyx_v_itemp; + 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; + char *__pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__getitem__", 0); + + /* "View.MemoryView":404 + * + * def __getitem__(memoryview self, object index): + * if index is Ellipsis: # <<<<<<<<<<<<<< + * return self + * + */ + __pyx_t_1 = (__pyx_v_index == __pyx_builtin_Ellipsis); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":405 + * def __getitem__(memoryview self, object index): + * if index is Ellipsis: + * return self # <<<<<<<<<<<<<< + * + * have_slices, indices = _unellipsify(index, self.view.ndim) + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __pyx_r = ((PyObject *)__pyx_v_self); + goto __pyx_L0; + + /* "View.MemoryView":404 + * + * def __getitem__(memoryview self, object index): + * if index is Ellipsis: # <<<<<<<<<<<<<< + * return self + * + */ + } + + /* "View.MemoryView":407 + * return self + * + * have_slices, indices = _unellipsify(index, self.view.ndim) # <<<<<<<<<<<<<< + * + * cdef char *itemp + */ + __pyx_t_3 = _unellipsify(__pyx_v_index, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 407, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (likely(__pyx_t_3 != Py_None)) { + 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(2, 407, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + #else + __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 407, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 407, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(2, 407, __pyx_L1_error) + } + __pyx_v_have_slices = __pyx_t_4; + __pyx_t_4 = 0; + __pyx_v_indices = __pyx_t_5; + __pyx_t_5 = 0; + + /* "View.MemoryView":410 + * + * cdef char *itemp + * if have_slices: # <<<<<<<<<<<<<< + * return memview_slice(self, indices) + * else: + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(2, 410, __pyx_L1_error) + if (__pyx_t_2) { + + /* "View.MemoryView":411 + * cdef char *itemp + * if have_slices: + * return memview_slice(self, indices) # <<<<<<<<<<<<<< + * else: + * itemp = self.get_item_pointer(indices) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = ((PyObject *)__pyx_memview_slice(__pyx_v_self, __pyx_v_indices)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 411, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + /* "View.MemoryView":410 + * + * cdef char *itemp + * if have_slices: # <<<<<<<<<<<<<< + * return memview_slice(self, indices) + * else: + */ + } + + /* "View.MemoryView":413 + * return memview_slice(self, indices) + * else: + * itemp = self.get_item_pointer(indices) # <<<<<<<<<<<<<< + * return self.convert_item_to_object(itemp) + * + */ + /*else*/ { + __pyx_t_6 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->get_item_pointer(__pyx_v_self, __pyx_v_indices); if (unlikely(__pyx_t_6 == ((char *)NULL))) __PYX_ERR(2, 413, __pyx_L1_error) + __pyx_v_itemp = __pyx_t_6; + + /* "View.MemoryView":414 + * else: + * itemp = self.get_item_pointer(indices) + * return self.convert_item_to_object(itemp) # <<<<<<<<<<<<<< + * + * def __setitem__(memoryview self, object index, object value): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->convert_item_to_object(__pyx_v_self, __pyx_v_itemp); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 414, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + } + + /* "View.MemoryView":403 + * + * + * def __getitem__(memoryview self, object index): # <<<<<<<<<<<<<< + * if index is Ellipsis: + * return self + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("View.MemoryView.memoryview.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_have_slices); + __Pyx_XDECREF(__pyx_v_indices); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":416 + * return self.convert_item_to_object(itemp) + * + * def __setitem__(memoryview self, object index, object value): # <<<<<<<<<<<<<< + * if self.view.readonly: + * raise TypeError("Cannot assign to read-only memoryview") + */ + +/* Python wrapper */ +static int __pyx_memoryview___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_memoryview___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); + __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_6__setitem__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v_index), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_6__setitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) { + PyObject *__pyx_v_have_slices = NULL; + PyObject *__pyx_v_obj = NULL; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__setitem__", 0); + __Pyx_INCREF(__pyx_v_index); + + /* "View.MemoryView":417 + * + * def __setitem__(memoryview self, object index, object value): + * if self.view.readonly: # <<<<<<<<<<<<<< + * raise TypeError("Cannot assign to read-only memoryview") + * + */ + __pyx_t_1 = (__pyx_v_self->view.readonly != 0); + if (unlikely(__pyx_t_1)) { + + /* "View.MemoryView":418 + * def __setitem__(memoryview self, object index, object value): + * if self.view.readonly: + * raise TypeError("Cannot assign to read-only memoryview") # <<<<<<<<<<<<<< + * + * have_slices, index = _unellipsify(index, self.view.ndim) + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 418, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(2, 418, __pyx_L1_error) + + /* "View.MemoryView":417 + * + * def __setitem__(memoryview self, object index, object value): + * if self.view.readonly: # <<<<<<<<<<<<<< + * raise TypeError("Cannot assign to read-only memoryview") + * + */ + } + + /* "View.MemoryView":420 + * raise TypeError("Cannot assign to read-only memoryview") + * + * have_slices, index = _unellipsify(index, self.view.ndim) # <<<<<<<<<<<<<< + * + * if have_slices: + */ + __pyx_t_2 = _unellipsify(__pyx_v_index, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 420, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (likely(__pyx_t_2 != Py_None)) { + PyObject* sequence = __pyx_t_2; + 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, 420, __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, 420, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 420, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(2, 420, __pyx_L1_error) + } + __pyx_v_have_slices = __pyx_t_3; + __pyx_t_3 = 0; + __Pyx_DECREF_SET(__pyx_v_index, __pyx_t_4); + __pyx_t_4 = 0; + + /* "View.MemoryView":422 + * have_slices, index = _unellipsify(index, self.view.ndim) + * + * if have_slices: # <<<<<<<<<<<<<< + * obj = self.is_slice(value) + * if obj: + */ + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(2, 422, __pyx_L1_error) + if (__pyx_t_1) { + + /* "View.MemoryView":423 + * + * if have_slices: + * obj = self.is_slice(value) # <<<<<<<<<<<<<< + * if obj: + * self.setitem_slice_assignment(self[index], obj) + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->is_slice(__pyx_v_self, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 423, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_obj = __pyx_t_2; + __pyx_t_2 = 0; + + /* "View.MemoryView":424 + * if have_slices: + * obj = self.is_slice(value) + * if obj: # <<<<<<<<<<<<<< + * self.setitem_slice_assignment(self[index], obj) + * else: + */ + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_obj); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(2, 424, __pyx_L1_error) + if (__pyx_t_1) { + + /* "View.MemoryView":425 + * obj = self.is_slice(value) + * if obj: + * self.setitem_slice_assignment(self[index], obj) # <<<<<<<<<<<<<< + * else: + * self.setitem_slice_assign_scalar(self[index], value) + */ + __pyx_t_2 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 425, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_slice_assignment(__pyx_v_self, __pyx_t_2, __pyx_v_obj); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 425, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "View.MemoryView":424 + * if have_slices: + * obj = self.is_slice(value) + * if obj: # <<<<<<<<<<<<<< + * self.setitem_slice_assignment(self[index], obj) + * else: + */ + goto __pyx_L5; + } + + /* "View.MemoryView":427 + * self.setitem_slice_assignment(self[index], obj) + * else: + * self.setitem_slice_assign_scalar(self[index], value) # <<<<<<<<<<<<<< + * else: + * self.setitem_indexed(index, value) + */ + /*else*/ { + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_index); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 427, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_memoryview_type))))) __PYX_ERR(2, 427, __pyx_L1_error) + __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_slice_assign_scalar(__pyx_v_self, ((struct __pyx_memoryview_obj *)__pyx_t_4), __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 427, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __pyx_L5:; + + /* "View.MemoryView":422 + * have_slices, index = _unellipsify(index, self.view.ndim) + * + * if have_slices: # <<<<<<<<<<<<<< + * obj = self.is_slice(value) + * if obj: + */ + goto __pyx_L4; + } + + /* "View.MemoryView":429 + * self.setitem_slice_assign_scalar(self[index], value) + * else: + * self.setitem_indexed(index, value) # <<<<<<<<<<<<<< + * + * cdef is_slice(self, obj): + */ + /*else*/ { + __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_indexed(__pyx_v_self, __pyx_v_index, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 429, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __pyx_L4:; + + /* "View.MemoryView":416 + * return self.convert_item_to_object(itemp) + * + * def __setitem__(memoryview self, object index, object value): # <<<<<<<<<<<<<< + * if self.view.readonly: + * raise TypeError("Cannot assign to read-only memoryview") + */ + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("View.MemoryView.memoryview.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_have_slices); + __Pyx_XDECREF(__pyx_v_obj); + __Pyx_XDECREF(__pyx_v_index); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":431 + * self.setitem_indexed(index, value) + * + * cdef is_slice(self, obj): # <<<<<<<<<<<<<< + * if not isinstance(obj, memoryview): + * try: + */ + +static PyObject *__pyx_memoryview_is_slice(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj) { + 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; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("is_slice", 0); + __Pyx_INCREF(__pyx_v_obj); + + /* "View.MemoryView":432 + * + * cdef is_slice(self, obj): + * if not isinstance(obj, memoryview): # <<<<<<<<<<<<<< + * try: + * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS, + */ + __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_obj, __pyx_memoryview_type); + __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":433 + * cdef is_slice(self, obj): + * if not isinstance(obj, memoryview): + * try: # <<<<<<<<<<<<<< + * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS, + * self.dtype_is_object) + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_5); + /*try:*/ { + + /* "View.MemoryView":434 + * if not isinstance(obj, memoryview): + * try: + * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS, # <<<<<<<<<<<<<< + * self.dtype_is_object) + * except TypeError: + */ + __pyx_t_6 = __Pyx_PyInt_From_int(((__pyx_v_self->flags & (~PyBUF_WRITABLE)) | PyBUF_ANY_CONTIGUOUS)); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 434, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_6); + + /* "View.MemoryView":435 + * try: + * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS, + * self.dtype_is_object) # <<<<<<<<<<<<<< + * except TypeError: + * return None + */ + __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_self->dtype_is_object); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 435, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + + /* "View.MemoryView":434 + * if not isinstance(obj, memoryview): + * try: + * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS, # <<<<<<<<<<<<<< + * self.dtype_is_object) + * except TypeError: + */ + __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 434, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(__pyx_v_obj); + __Pyx_GIVEREF(__pyx_v_obj); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_obj); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7); + __pyx_t_6 = 0; + __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 434, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF_SET(__pyx_v_obj, __pyx_t_7); + __pyx_t_7 = 0; + + /* "View.MemoryView":433 + * cdef is_slice(self, obj): + * if not isinstance(obj, memoryview): + * try: # <<<<<<<<<<<<<< + * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS, + * self.dtype_is_object) + */ + } + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L9_try_end; + __pyx_L4_error:; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "View.MemoryView":436 + * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS, + * self.dtype_is_object) + * except TypeError: # <<<<<<<<<<<<<< + * return None + * + */ + __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_TypeError); + if (__pyx_t_9) { + __Pyx_AddTraceback("View.MemoryView.memoryview.is_slice", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_8, &__pyx_t_6) < 0) __PYX_ERR(2, 436, __pyx_L6_except_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GOTREF(__pyx_t_6); + + /* "View.MemoryView":437 + * self.dtype_is_object) + * except TypeError: + * return None # <<<<<<<<<<<<<< + * + * return obj + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L7_except_return; + } + goto __pyx_L6_except_error; + __pyx_L6_except_error:; + + /* "View.MemoryView":433 + * cdef is_slice(self, obj): + * if not isinstance(obj, memoryview): + * try: # <<<<<<<<<<<<<< + * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS, + * self.dtype_is_object) + */ + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5); + goto __pyx_L1_error; + __pyx_L7_except_return:; + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5); + goto __pyx_L0; + __pyx_L9_try_end:; + } + + /* "View.MemoryView":432 + * + * cdef is_slice(self, obj): + * if not isinstance(obj, memoryview): # <<<<<<<<<<<<<< + * try: + * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS, + */ + } + + /* "View.MemoryView":439 + * return None + * + * return obj # <<<<<<<<<<<<<< + * + * cdef setitem_slice_assignment(self, dst, src): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_obj); + __pyx_r = __pyx_v_obj; + goto __pyx_L0; + + /* "View.MemoryView":431 + * self.setitem_indexed(index, value) + * + * cdef is_slice(self, obj): # <<<<<<<<<<<<<< + * if not isinstance(obj, memoryview): + * try: + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("View.MemoryView.memoryview.is_slice", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_obj); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":441 + * return obj + * + * cdef setitem_slice_assignment(self, dst, src): # <<<<<<<<<<<<<< + * cdef __Pyx_memviewslice dst_slice + * cdef __Pyx_memviewslice src_slice + */ + +static PyObject *__pyx_memoryview_setitem_slice_assignment(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_dst, PyObject *__pyx_v_src) { + __Pyx_memviewslice __pyx_v_dst_slice; + __Pyx_memviewslice __pyx_v_src_slice; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_memviewslice *__pyx_t_1; + __Pyx_memviewslice *__pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("setitem_slice_assignment", 0); + + /* "View.MemoryView":445 + * cdef __Pyx_memviewslice src_slice + * + * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0], # <<<<<<<<<<<<<< + * get_slice_from_memview(dst, &dst_slice)[0], + * src.ndim, dst.ndim, self.dtype_is_object) + */ + if (!(likely(((__pyx_v_src) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_src, __pyx_memoryview_type))))) __PYX_ERR(2, 445, __pyx_L1_error) + __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(((struct __pyx_memoryview_obj *)__pyx_v_src), (&__pyx_v_src_slice)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(2, 445, __pyx_L1_error) + + /* "View.MemoryView":446 + * + * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0], + * get_slice_from_memview(dst, &dst_slice)[0], # <<<<<<<<<<<<<< + * src.ndim, dst.ndim, self.dtype_is_object) + * + */ + if (!(likely(((__pyx_v_dst) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_dst, __pyx_memoryview_type))))) __PYX_ERR(2, 446, __pyx_L1_error) + __pyx_t_2 = __pyx_memoryview_get_slice_from_memoryview(((struct __pyx_memoryview_obj *)__pyx_v_dst), (&__pyx_v_dst_slice)); if (unlikely(__pyx_t_2 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(2, 446, __pyx_L1_error) + + /* "View.MemoryView":447 + * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0], + * get_slice_from_memview(dst, &dst_slice)[0], + * src.ndim, dst.ndim, self.dtype_is_object) # <<<<<<<<<<<<<< + * + * cdef setitem_slice_assign_scalar(self, memoryview dst, value): + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_src, __pyx_n_s_ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 447, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 447, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_dst, __pyx_n_s_ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 447, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 447, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "View.MemoryView":445 + * cdef __Pyx_memviewslice src_slice + * + * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0], # <<<<<<<<<<<<<< + * get_slice_from_memview(dst, &dst_slice)[0], + * src.ndim, dst.ndim, self.dtype_is_object) + */ + __pyx_t_6 = __pyx_memoryview_copy_contents((__pyx_t_1[0]), (__pyx_t_2[0]), __pyx_t_4, __pyx_t_5, __pyx_v_self->dtype_is_object); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(2, 445, __pyx_L1_error) + + /* "View.MemoryView":441 + * return obj + * + * cdef setitem_slice_assignment(self, dst, src): # <<<<<<<<<<<<<< + * cdef __Pyx_memviewslice dst_slice + * cdef __Pyx_memviewslice src_slice + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_slice_assignment", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":449 + * src.ndim, dst.ndim, self.dtype_is_object) + * + * cdef setitem_slice_assign_scalar(self, memoryview dst, value): # <<<<<<<<<<<<<< + * cdef int array[128] + * cdef void *tmp = NULL + */ + +static PyObject *__pyx_memoryview_setitem_slice_assign_scalar(struct __pyx_memoryview_obj *__pyx_v_self, struct __pyx_memoryview_obj *__pyx_v_dst, PyObject *__pyx_v_value) { + int __pyx_v_array[0x80]; + void *__pyx_v_tmp; + void *__pyx_v_item; + __Pyx_memviewslice *__pyx_v_dst_slice; + __Pyx_memviewslice __pyx_v_tmp_slice; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_memviewslice *__pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_t_5; + char const *__pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("setitem_slice_assign_scalar", 0); + + /* "View.MemoryView":451 + * cdef setitem_slice_assign_scalar(self, memoryview dst, value): + * cdef int array[128] + * cdef void *tmp = NULL # <<<<<<<<<<<<<< + * cdef void *item + * + */ + __pyx_v_tmp = NULL; + + /* "View.MemoryView":456 + * cdef __Pyx_memviewslice *dst_slice + * cdef __Pyx_memviewslice tmp_slice + * dst_slice = get_slice_from_memview(dst, &tmp_slice) # <<<<<<<<<<<<<< + * + * if self.view.itemsize > sizeof(array): + */ + __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_dst, (&__pyx_v_tmp_slice)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(2, 456, __pyx_L1_error) + __pyx_v_dst_slice = __pyx_t_1; + + /* "View.MemoryView":458 + * dst_slice = get_slice_from_memview(dst, &tmp_slice) + * + * if self.view.itemsize > sizeof(array): # <<<<<<<<<<<<<< + * tmp = PyMem_Malloc(self.view.itemsize) + * if tmp == NULL: + */ + __pyx_t_2 = ((((size_t)__pyx_v_self->view.itemsize) > (sizeof(__pyx_v_array))) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":459 + * + * if self.view.itemsize > sizeof(array): + * tmp = PyMem_Malloc(self.view.itemsize) # <<<<<<<<<<<<<< + * if tmp == NULL: + * raise MemoryError + */ + __pyx_v_tmp = PyMem_Malloc(__pyx_v_self->view.itemsize); + + /* "View.MemoryView":460 + * if self.view.itemsize > sizeof(array): + * tmp = PyMem_Malloc(self.view.itemsize) + * if tmp == NULL: # <<<<<<<<<<<<<< + * raise MemoryError + * item = tmp + */ + __pyx_t_2 = ((__pyx_v_tmp == NULL) != 0); + if (unlikely(__pyx_t_2)) { + + /* "View.MemoryView":461 + * tmp = PyMem_Malloc(self.view.itemsize) + * if tmp == NULL: + * raise MemoryError # <<<<<<<<<<<<<< + * item = tmp + * else: + */ + PyErr_NoMemory(); __PYX_ERR(2, 461, __pyx_L1_error) + + /* "View.MemoryView":460 + * if self.view.itemsize > sizeof(array): + * tmp = PyMem_Malloc(self.view.itemsize) + * if tmp == NULL: # <<<<<<<<<<<<<< + * raise MemoryError + * item = tmp + */ + } + + /* "View.MemoryView":462 + * if tmp == NULL: + * raise MemoryError + * item = tmp # <<<<<<<<<<<<<< + * else: + * item = array + */ + __pyx_v_item = __pyx_v_tmp; + + /* "View.MemoryView":458 + * dst_slice = get_slice_from_memview(dst, &tmp_slice) + * + * if self.view.itemsize > sizeof(array): # <<<<<<<<<<<<<< + * tmp = PyMem_Malloc(self.view.itemsize) + * if tmp == NULL: + */ + goto __pyx_L3; + } + + /* "View.MemoryView":464 + * item = tmp + * else: + * item = array # <<<<<<<<<<<<<< + * + * try: + */ + /*else*/ { + __pyx_v_item = ((void *)__pyx_v_array); + } + __pyx_L3:; + + /* "View.MemoryView":466 + * item = array + * + * try: # <<<<<<<<<<<<<< + * if self.dtype_is_object: + * ( item)[0] = value + */ + /*try:*/ { + + /* "View.MemoryView":467 + * + * try: + * if self.dtype_is_object: # <<<<<<<<<<<<<< + * ( item)[0] = value + * else: + */ + __pyx_t_2 = (__pyx_v_self->dtype_is_object != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":468 + * try: + * if self.dtype_is_object: + * ( item)[0] = value # <<<<<<<<<<<<<< + * else: + * self.assign_item_from_object( item, value) + */ + (((PyObject **)__pyx_v_item)[0]) = ((PyObject *)__pyx_v_value); + + /* "View.MemoryView":467 + * + * try: + * if self.dtype_is_object: # <<<<<<<<<<<<<< + * ( item)[0] = value + * else: + */ + goto __pyx_L8; + } + + /* "View.MemoryView":470 + * ( item)[0] = value + * else: + * self.assign_item_from_object( item, value) # <<<<<<<<<<<<<< + * + * + */ + /*else*/ { + __pyx_t_3 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->assign_item_from_object(__pyx_v_self, ((char *)__pyx_v_item), __pyx_v_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 470, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __pyx_L8:; + + /* "View.MemoryView":474 + * + * + * if self.view.suboffsets != NULL: # <<<<<<<<<<<<<< + * assert_direct_dimensions(self.view.suboffsets, self.view.ndim) + * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize, + */ + __pyx_t_2 = ((__pyx_v_self->view.suboffsets != NULL) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":475 + * + * if self.view.suboffsets != NULL: + * assert_direct_dimensions(self.view.suboffsets, self.view.ndim) # <<<<<<<<<<<<<< + * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize, + * item, self.dtype_is_object) + */ + __pyx_t_3 = assert_direct_dimensions(__pyx_v_self->view.suboffsets, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 475, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "View.MemoryView":474 + * + * + * if self.view.suboffsets != NULL: # <<<<<<<<<<<<<< + * assert_direct_dimensions(self.view.suboffsets, self.view.ndim) + * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize, + */ + } + + /* "View.MemoryView":476 + * if self.view.suboffsets != NULL: + * assert_direct_dimensions(self.view.suboffsets, self.view.ndim) + * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize, # <<<<<<<<<<<<<< + * item, self.dtype_is_object) + * finally: + */ + __pyx_memoryview_slice_assign_scalar(__pyx_v_dst_slice, __pyx_v_dst->view.ndim, __pyx_v_self->view.itemsize, __pyx_v_item, __pyx_v_self->dtype_is_object); + } + + /* "View.MemoryView":479 + * item, self.dtype_is_object) + * finally: + * PyMem_Free(tmp) # <<<<<<<<<<<<<< + * + * cdef setitem_indexed(self, index, value): + */ + /*finally:*/ { + /*normal exit:*/{ + PyMem_Free(__pyx_v_tmp); + goto __pyx_L7; + } + __pyx_L6_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9) < 0)) __Pyx_ErrFetch(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9); + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_8); + __Pyx_XGOTREF(__pyx_t_9); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_12); + __pyx_t_4 = __pyx_lineno; __pyx_t_5 = __pyx_clineno; __pyx_t_6 = __pyx_filename; + { + PyMem_Free(__pyx_v_tmp); + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + } + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_ErrRestore(__pyx_t_7, __pyx_t_8, __pyx_t_9); + __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; + __pyx_lineno = __pyx_t_4; __pyx_clineno = __pyx_t_5; __pyx_filename = __pyx_t_6; + goto __pyx_L1_error; + } + __pyx_L7:; + } + + /* "View.MemoryView":449 + * src.ndim, dst.ndim, self.dtype_is_object) + * + * cdef setitem_slice_assign_scalar(self, memoryview dst, value): # <<<<<<<<<<<<<< + * cdef int array[128] + * cdef void *tmp = NULL + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_slice_assign_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":481 + * PyMem_Free(tmp) + * + * cdef setitem_indexed(self, index, value): # <<<<<<<<<<<<<< + * cdef char *itemp = self.get_item_pointer(index) + * self.assign_item_from_object(itemp, value) + */ + +static PyObject *__pyx_memoryview_setitem_indexed(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) { + char *__pyx_v_itemp; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + char *__pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("setitem_indexed", 0); + + /* "View.MemoryView":482 + * + * cdef setitem_indexed(self, index, value): + * cdef char *itemp = self.get_item_pointer(index) # <<<<<<<<<<<<<< + * self.assign_item_from_object(itemp, value) + * + */ + __pyx_t_1 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->get_item_pointer(__pyx_v_self, __pyx_v_index); if (unlikely(__pyx_t_1 == ((char *)NULL))) __PYX_ERR(2, 482, __pyx_L1_error) + __pyx_v_itemp = __pyx_t_1; + + /* "View.MemoryView":483 + * cdef setitem_indexed(self, index, value): + * cdef char *itemp = self.get_item_pointer(index) + * self.assign_item_from_object(itemp, value) # <<<<<<<<<<<<<< + * + * cdef convert_item_to_object(self, char *itemp): + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->assign_item_from_object(__pyx_v_self, __pyx_v_itemp, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 483, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "View.MemoryView":481 + * PyMem_Free(tmp) + * + * cdef setitem_indexed(self, index, value): # <<<<<<<<<<<<<< + * cdef char *itemp = self.get_item_pointer(index) + * self.assign_item_from_object(itemp, value) + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_indexed", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":485 + * self.assign_item_from_object(itemp, value) + * + * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<< + * """Only used if instantiated manually by the user, or if Cython doesn't + * know how to convert the type""" + */ + +static PyObject *__pyx_memoryview_convert_item_to_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp) { + PyObject *__pyx_v_struct = NULL; + PyObject *__pyx_v_bytesitem = 0; + PyObject *__pyx_v_result = NULL; + 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; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + int __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + size_t __pyx_t_10; + int __pyx_t_11; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("convert_item_to_object", 0); + + /* "View.MemoryView":488 + * """Only used if instantiated manually by the user, or if Cython doesn't + * know how to convert the type""" + * import struct # <<<<<<<<<<<<<< + * cdef bytes bytesitem + * + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_struct, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 488, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_struct = __pyx_t_1; + __pyx_t_1 = 0; + + /* "View.MemoryView":491 + * cdef bytes bytesitem + * + * bytesitem = itemp[:self.view.itemsize] # <<<<<<<<<<<<<< + * try: + * result = struct.unpack(self.view.format, bytesitem) + */ + __pyx_t_1 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_itemp + 0, __pyx_v_self->view.itemsize - 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 491, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_bytesitem = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "View.MemoryView":492 + * + * bytesitem = itemp[:self.view.itemsize] + * try: # <<<<<<<<<<<<<< + * result = struct.unpack(self.view.format, bytesitem) + * except struct.error: + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_2, &__pyx_t_3, &__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_4); + /*try:*/ { + + /* "View.MemoryView":493 + * bytesitem = itemp[:self.view.itemsize] + * try: + * result = struct.unpack(self.view.format, bytesitem) # <<<<<<<<<<<<<< + * except struct.error: + * raise ValueError("Unable to convert item to object") + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_unpack); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 493, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 493, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = NULL; + __pyx_t_8 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_8 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_6, __pyx_v_bytesitem}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 493, __pyx_L3_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + __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_7, __pyx_t_6, __pyx_v_bytesitem}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 493, __pyx_L3_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + { + __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 493, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_9); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_t_6); + __Pyx_INCREF(__pyx_v_bytesitem); + __Pyx_GIVEREF(__pyx_v_bytesitem); + PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_v_bytesitem); + __pyx_t_6 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 493, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_result = __pyx_t_1; + __pyx_t_1 = 0; + + /* "View.MemoryView":492 + * + * bytesitem = itemp[:self.view.itemsize] + * try: # <<<<<<<<<<<<<< + * result = struct.unpack(self.view.format, bytesitem) + * except struct.error: + */ + } + + /* "View.MemoryView":497 + * raise ValueError("Unable to convert item to object") + * else: + * if len(self.view.format) == 1: # <<<<<<<<<<<<<< + * return result[0] + * return result + */ + /*else:*/ { + __pyx_t_10 = strlen(__pyx_v_self->view.format); + __pyx_t_11 = ((__pyx_t_10 == 1) != 0); + if (__pyx_t_11) { + + /* "View.MemoryView":498 + * else: + * if len(self.view.format) == 1: + * return result[0] # <<<<<<<<<<<<<< + * return result + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_result, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 498, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L6_except_return; + + /* "View.MemoryView":497 + * raise ValueError("Unable to convert item to object") + * else: + * if len(self.view.format) == 1: # <<<<<<<<<<<<<< + * return result[0] + * return result + */ + } + + /* "View.MemoryView":499 + * if len(self.view.format) == 1: + * return result[0] + * return result # <<<<<<<<<<<<<< + * + * cdef assign_item_from_object(self, char *itemp, object value): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L6_except_return; + } + __pyx_L3_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "View.MemoryView":494 + * try: + * result = struct.unpack(self.view.format, bytesitem) + * except struct.error: # <<<<<<<<<<<<<< + * raise ValueError("Unable to convert item to object") + * else: + */ + __Pyx_ErrFetch(&__pyx_t_1, &__pyx_t_5, &__pyx_t_9); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_error); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 494, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_1, __pyx_t_6); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_ErrRestore(__pyx_t_1, __pyx_t_5, __pyx_t_9); + __pyx_t_1 = 0; __pyx_t_5 = 0; __pyx_t_9 = 0; + if (__pyx_t_8) { + __Pyx_AddTraceback("View.MemoryView.memoryview.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_5, &__pyx_t_1) < 0) __PYX_ERR(2, 494, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_1); + + /* "View.MemoryView":495 + * result = struct.unpack(self.view.format, bytesitem) + * except struct.error: + * raise ValueError("Unable to convert item to object") # <<<<<<<<<<<<<< + * else: + * if len(self.view.format) == 1: + */ + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 495, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __PYX_ERR(2, 495, __pyx_L5_except_error) + } + goto __pyx_L5_except_error; + __pyx_L5_except_error:; + + /* "View.MemoryView":492 + * + * bytesitem = itemp[:self.view.itemsize] + * try: # <<<<<<<<<<<<<< + * result = struct.unpack(self.view.format, bytesitem) + * except struct.error: + */ + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4); + goto __pyx_L1_error; + __pyx_L6_except_return:; + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4); + goto __pyx_L0; + } + + /* "View.MemoryView":485 + * self.assign_item_from_object(itemp, value) + * + * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<< + * """Only used if instantiated manually by the user, or if Cython doesn't + * know how to convert the type""" + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("View.MemoryView.memoryview.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_struct); + __Pyx_XDECREF(__pyx_v_bytesitem); + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":501 + * return result + * + * cdef assign_item_from_object(self, char *itemp, object value): # <<<<<<<<<<<<<< + * """Only used if instantiated manually by the user, or if Cython doesn't + * know how to convert the type""" + */ + +static PyObject *__pyx_memoryview_assign_item_from_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp, PyObject *__pyx_v_value) { + PyObject *__pyx_v_struct = NULL; + char __pyx_v_c; + PyObject *__pyx_v_bytesvalue = 0; + Py_ssize_t __pyx_v_i; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + PyObject *__pyx_t_8 = NULL; + Py_ssize_t __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + char *__pyx_t_11; + char *__pyx_t_12; + char *__pyx_t_13; + char *__pyx_t_14; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("assign_item_from_object", 0); + + /* "View.MemoryView":504 + * """Only used if instantiated manually by the user, or if Cython doesn't + * know how to convert the type""" + * import struct # <<<<<<<<<<<<<< + * cdef char c + * cdef bytes bytesvalue + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_struct, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 504, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_struct = __pyx_t_1; + __pyx_t_1 = 0; + + /* "View.MemoryView":509 + * cdef Py_ssize_t i + * + * if isinstance(value, tuple): # <<<<<<<<<<<<<< + * bytesvalue = struct.pack(self.view.format, *value) + * else: + */ + __pyx_t_2 = PyTuple_Check(__pyx_v_value); + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { + + /* "View.MemoryView":510 + * + * if isinstance(value, tuple): + * bytesvalue = struct.pack(self.view.format, *value) # <<<<<<<<<<<<<< + * else: + * bytesvalue = struct.pack(self.view.format, value) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_pack); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 510, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 510, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 510, __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 = 0; + __pyx_t_4 = __Pyx_PySequence_Tuple(__pyx_v_value); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 510, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = PyNumber_Add(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 510, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 510, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(2, 510, __pyx_L1_error) + __pyx_v_bytesvalue = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; + + /* "View.MemoryView":509 + * cdef Py_ssize_t i + * + * if isinstance(value, tuple): # <<<<<<<<<<<<<< + * bytesvalue = struct.pack(self.view.format, *value) + * else: + */ + goto __pyx_L3; + } + + /* "View.MemoryView":512 + * bytesvalue = struct.pack(self.view.format, *value) + * else: + * bytesvalue = struct.pack(self.view.format, value) # <<<<<<<<<<<<<< + * + * for i, c in enumerate(bytesvalue): + */ + /*else*/ { + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_pack); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 512, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 512, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = NULL; + __pyx_t_7 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_1, __pyx_v_value}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 512, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 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_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_1, __pyx_v_value}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 512, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + { + __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 512, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + if (__pyx_t_5) { + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5); __pyx_t_5 = NULL; + } + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_t_1); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_v_value); + __pyx_t_1 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 512, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(2, 512, __pyx_L1_error) + __pyx_v_bytesvalue = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; + } + __pyx_L3:; + + /* "View.MemoryView":514 + * bytesvalue = struct.pack(self.view.format, value) + * + * for i, c in enumerate(bytesvalue): # <<<<<<<<<<<<<< + * itemp[i] = c + * + */ + __pyx_t_9 = 0; + if (unlikely(__pyx_v_bytesvalue == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' is not iterable"); + __PYX_ERR(2, 514, __pyx_L1_error) + } + __Pyx_INCREF(__pyx_v_bytesvalue); + __pyx_t_10 = __pyx_v_bytesvalue; + __pyx_t_12 = PyBytes_AS_STRING(__pyx_t_10); + __pyx_t_13 = (__pyx_t_12 + PyBytes_GET_SIZE(__pyx_t_10)); + for (__pyx_t_14 = __pyx_t_12; __pyx_t_14 < __pyx_t_13; __pyx_t_14++) { + __pyx_t_11 = __pyx_t_14; + __pyx_v_c = (__pyx_t_11[0]); + + /* "View.MemoryView":515 + * + * for i, c in enumerate(bytesvalue): + * itemp[i] = c # <<<<<<<<<<<<<< + * + * @cname('getbuffer') + */ + __pyx_v_i = __pyx_t_9; + + /* "View.MemoryView":514 + * bytesvalue = struct.pack(self.view.format, value) + * + * for i, c in enumerate(bytesvalue): # <<<<<<<<<<<<<< + * itemp[i] = c + * + */ + __pyx_t_9 = (__pyx_t_9 + 1); + + /* "View.MemoryView":515 + * + * for i, c in enumerate(bytesvalue): + * itemp[i] = c # <<<<<<<<<<<<<< + * + * @cname('getbuffer') + */ + (__pyx_v_itemp[__pyx_v_i]) = __pyx_v_c; + } + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "View.MemoryView":501 + * return result + * + * cdef assign_item_from_object(self, char *itemp, object value): # <<<<<<<<<<<<<< + * """Only used if instantiated manually by the user, or if Cython doesn't + * know how to convert the type""" + */ + + /* 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_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("View.MemoryView.memoryview.assign_item_from_object", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_struct); + __Pyx_XDECREF(__pyx_v_bytesvalue); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":518 + * + * @cname('getbuffer') + * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<< + * if flags & PyBUF_WRITABLE and self.view.readonly: + * raise ValueError("Cannot create writable memory view from read-only memoryview") + */ + +/* Python wrapper */ +static CYTHON_UNUSED int __pyx_memoryview_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ +static CYTHON_UNUSED int __pyx_memoryview_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_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_8__getbuffer__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_8__getbuffer__(struct __pyx_memoryview_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + Py_ssize_t *__pyx_t_4; + char *__pyx_t_5; + void *__pyx_t_6; + int __pyx_t_7; + Py_ssize_t __pyx_t_8; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + 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); + + /* "View.MemoryView":519 + * @cname('getbuffer') + * def __getbuffer__(self, Py_buffer *info, int flags): + * if flags & PyBUF_WRITABLE and self.view.readonly: # <<<<<<<<<<<<<< + * raise ValueError("Cannot create writable memory view from read-only memoryview") + * + */ + __pyx_t_2 = ((__pyx_v_flags & PyBUF_WRITABLE) != 0); + if (__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_2 = (__pyx_v_self->view.readonly != 0); + __pyx_t_1 = __pyx_t_2; + __pyx_L4_bool_binop_done:; + if (unlikely(__pyx_t_1)) { + + /* "View.MemoryView":520 + * def __getbuffer__(self, Py_buffer *info, int flags): + * if flags & PyBUF_WRITABLE and self.view.readonly: + * raise ValueError("Cannot create writable memory view from read-only memoryview") # <<<<<<<<<<<<<< + * + * if flags & PyBUF_ND: + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 520, __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, 520, __pyx_L1_error) + + /* "View.MemoryView":519 + * @cname('getbuffer') + * def __getbuffer__(self, Py_buffer *info, int flags): + * if flags & PyBUF_WRITABLE and self.view.readonly: # <<<<<<<<<<<<<< + * raise ValueError("Cannot create writable memory view from read-only memoryview") + * + */ + } + + /* "View.MemoryView":522 + * raise ValueError("Cannot create writable memory view from read-only memoryview") + * + * if flags & PyBUF_ND: # <<<<<<<<<<<<<< + * info.shape = self.view.shape + * else: + */ + __pyx_t_1 = ((__pyx_v_flags & PyBUF_ND) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":523 + * + * if flags & PyBUF_ND: + * info.shape = self.view.shape # <<<<<<<<<<<<<< + * else: + * info.shape = NULL + */ + __pyx_t_4 = __pyx_v_self->view.shape; + __pyx_v_info->shape = __pyx_t_4; + + /* "View.MemoryView":522 + * raise ValueError("Cannot create writable memory view from read-only memoryview") + * + * if flags & PyBUF_ND: # <<<<<<<<<<<<<< + * info.shape = self.view.shape + * else: + */ + goto __pyx_L6; + } + + /* "View.MemoryView":525 + * info.shape = self.view.shape + * else: + * info.shape = NULL # <<<<<<<<<<<<<< + * + * if flags & PyBUF_STRIDES: + */ + /*else*/ { + __pyx_v_info->shape = NULL; + } + __pyx_L6:; + + /* "View.MemoryView":527 + * info.shape = NULL + * + * if flags & PyBUF_STRIDES: # <<<<<<<<<<<<<< + * info.strides = self.view.strides + * else: + */ + __pyx_t_1 = ((__pyx_v_flags & PyBUF_STRIDES) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":528 + * + * if flags & PyBUF_STRIDES: + * info.strides = self.view.strides # <<<<<<<<<<<<<< + * else: + * info.strides = NULL + */ + __pyx_t_4 = __pyx_v_self->view.strides; + __pyx_v_info->strides = __pyx_t_4; + + /* "View.MemoryView":527 + * info.shape = NULL + * + * if flags & PyBUF_STRIDES: # <<<<<<<<<<<<<< + * info.strides = self.view.strides + * else: + */ + goto __pyx_L7; + } + + /* "View.MemoryView":530 + * info.strides = self.view.strides + * else: + * info.strides = NULL # <<<<<<<<<<<<<< + * + * if flags & PyBUF_INDIRECT: + */ + /*else*/ { + __pyx_v_info->strides = NULL; + } + __pyx_L7:; + + /* "View.MemoryView":532 + * info.strides = NULL + * + * if flags & PyBUF_INDIRECT: # <<<<<<<<<<<<<< + * info.suboffsets = self.view.suboffsets + * else: + */ + __pyx_t_1 = ((__pyx_v_flags & PyBUF_INDIRECT) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":533 + * + * if flags & PyBUF_INDIRECT: + * info.suboffsets = self.view.suboffsets # <<<<<<<<<<<<<< + * else: + * info.suboffsets = NULL + */ + __pyx_t_4 = __pyx_v_self->view.suboffsets; + __pyx_v_info->suboffsets = __pyx_t_4; + + /* "View.MemoryView":532 + * info.strides = NULL + * + * if flags & PyBUF_INDIRECT: # <<<<<<<<<<<<<< + * info.suboffsets = self.view.suboffsets + * else: + */ + goto __pyx_L8; + } + + /* "View.MemoryView":535 + * info.suboffsets = self.view.suboffsets + * else: + * info.suboffsets = NULL # <<<<<<<<<<<<<< + * + * if flags & PyBUF_FORMAT: + */ + /*else*/ { + __pyx_v_info->suboffsets = NULL; + } + __pyx_L8:; + + /* "View.MemoryView":537 + * info.suboffsets = NULL + * + * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< + * info.format = self.view.format + * else: + */ + __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":538 + * + * if flags & PyBUF_FORMAT: + * info.format = self.view.format # <<<<<<<<<<<<<< + * else: + * info.format = NULL + */ + __pyx_t_5 = __pyx_v_self->view.format; + __pyx_v_info->format = __pyx_t_5; + + /* "View.MemoryView":537 + * info.suboffsets = NULL + * + * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< + * info.format = self.view.format + * else: + */ + goto __pyx_L9; + } + + /* "View.MemoryView":540 + * info.format = self.view.format + * else: + * info.format = NULL # <<<<<<<<<<<<<< + * + * info.buf = self.view.buf + */ + /*else*/ { + __pyx_v_info->format = NULL; + } + __pyx_L9:; + + /* "View.MemoryView":542 + * info.format = NULL + * + * info.buf = self.view.buf # <<<<<<<<<<<<<< + * info.ndim = self.view.ndim + * info.itemsize = self.view.itemsize + */ + __pyx_t_6 = __pyx_v_self->view.buf; + __pyx_v_info->buf = __pyx_t_6; + + /* "View.MemoryView":543 + * + * info.buf = self.view.buf + * info.ndim = self.view.ndim # <<<<<<<<<<<<<< + * info.itemsize = self.view.itemsize + * info.len = self.view.len + */ + __pyx_t_7 = __pyx_v_self->view.ndim; + __pyx_v_info->ndim = __pyx_t_7; + + /* "View.MemoryView":544 + * info.buf = self.view.buf + * info.ndim = self.view.ndim + * info.itemsize = self.view.itemsize # <<<<<<<<<<<<<< + * info.len = self.view.len + * info.readonly = self.view.readonly + */ + __pyx_t_8 = __pyx_v_self->view.itemsize; + __pyx_v_info->itemsize = __pyx_t_8; + + /* "View.MemoryView":545 + * info.ndim = self.view.ndim + * info.itemsize = self.view.itemsize + * info.len = self.view.len # <<<<<<<<<<<<<< + * info.readonly = self.view.readonly + * info.obj = self + */ + __pyx_t_8 = __pyx_v_self->view.len; + __pyx_v_info->len = __pyx_t_8; + + /* "View.MemoryView":546 + * info.itemsize = self.view.itemsize + * info.len = self.view.len + * info.readonly = self.view.readonly # <<<<<<<<<<<<<< + * info.obj = self + * + */ + __pyx_t_1 = __pyx_v_self->view.readonly; + __pyx_v_info->readonly = __pyx_t_1; + + /* "View.MemoryView":547 + * info.len = self.view.len + * info.readonly = self.view.readonly + * info.obj = self # <<<<<<<<<<<<<< + * + * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") + */ + __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); + + /* "View.MemoryView":518 + * + * @cname('getbuffer') + * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<< + * if flags & PyBUF_WRITABLE and self.view.readonly: + * raise ValueError("Cannot create writable memory view from read-only memoryview") + */ + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("View.MemoryView.memoryview.__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_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":553 + * + * @property + * def T(self): # <<<<<<<<<<<<<< + * cdef _memoryviewslice result = memoryview_copy(self) + * transpose_memslice(&result.from_slice) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_1T_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_1T_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_1T___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_1T___get__(struct __pyx_memoryview_obj *__pyx_v_self) { + struct __pyx_memoryviewslice_obj *__pyx_v_result = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + + /* "View.MemoryView":554 + * @property + * def T(self): + * cdef _memoryviewslice result = memoryview_copy(self) # <<<<<<<<<<<<<< + * transpose_memslice(&result.from_slice) + * return result + */ + __pyx_t_1 = __pyx_memoryview_copy_object(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 554, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_memoryviewslice_type))))) __PYX_ERR(2, 554, __pyx_L1_error) + __pyx_v_result = ((struct __pyx_memoryviewslice_obj *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "View.MemoryView":555 + * def T(self): + * cdef _memoryviewslice result = memoryview_copy(self) + * transpose_memslice(&result.from_slice) # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_t_2 = __pyx_memslice_transpose((&__pyx_v_result->from_slice)); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(2, 555, __pyx_L1_error) + + /* "View.MemoryView":556 + * cdef _memoryviewslice result = memoryview_copy(self) + * transpose_memslice(&result.from_slice) + * return result # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = ((PyObject *)__pyx_v_result); + goto __pyx_L0; + + /* "View.MemoryView":553 + * + * @property + * def T(self): # <<<<<<<<<<<<<< + * cdef _memoryviewslice result = memoryview_copy(self) + * transpose_memslice(&result.from_slice) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("View.MemoryView.memoryview.T.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":559 + * + * @property + * def base(self): # <<<<<<<<<<<<<< + * return self.obj + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4base_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4base_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4base___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4base___get__(struct __pyx_memoryview_obj *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + + /* "View.MemoryView":560 + * @property + * def base(self): + * return self.obj # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->obj); + __pyx_r = __pyx_v_self->obj; + goto __pyx_L0; + + /* "View.MemoryView":559 + * + * @property + * def base(self): # <<<<<<<<<<<<<< + * return self.obj + * + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":563 + * + * @property + * def shape(self): # <<<<<<<<<<<<<< + * return tuple([length for length in self.view.shape[:self.view.ndim]]) + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_5shape_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_5shape_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_5shape___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_5shape___get__(struct __pyx_memoryview_obj *__pyx_v_self) { + Py_ssize_t __pyx_v_length; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t *__pyx_t_2; + Py_ssize_t *__pyx_t_3; + Py_ssize_t *__pyx_t_4; + PyObject *__pyx_t_5 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + + /* "View.MemoryView":564 + * @property + * def shape(self): + * return tuple([length for length in self.view.shape[:self.view.ndim]]) # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 564, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = (__pyx_v_self->view.shape + __pyx_v_self->view.ndim); + for (__pyx_t_4 = __pyx_v_self->view.shape; __pyx_t_4 < __pyx_t_3; __pyx_t_4++) { + __pyx_t_2 = __pyx_t_4; + __pyx_v_length = (__pyx_t_2[0]); + __pyx_t_5 = PyInt_FromSsize_t(__pyx_v_length); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 564, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_5))) __PYX_ERR(2, 564, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __pyx_t_5 = PyList_AsTuple(((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 564, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; + + /* "View.MemoryView":563 + * + * @property + * def shape(self): # <<<<<<<<<<<<<< + * return tuple([length for length in self.view.shape[:self.view.ndim]]) + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("View.MemoryView.memoryview.shape.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":567 + * + * @property + * def strides(self): # <<<<<<<<<<<<<< + * if self.view.strides == NULL: + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_7strides_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_7strides_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_7strides___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_7strides___get__(struct __pyx_memoryview_obj *__pyx_v_self) { + Py_ssize_t __pyx_v_stride; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t *__pyx_t_3; + Py_ssize_t *__pyx_t_4; + Py_ssize_t *__pyx_t_5; + PyObject *__pyx_t_6 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + + /* "View.MemoryView":568 + * @property + * def strides(self): + * if self.view.strides == NULL: # <<<<<<<<<<<<<< + * + * raise ValueError("Buffer view does not expose strides") + */ + __pyx_t_1 = ((__pyx_v_self->view.strides == NULL) != 0); + if (unlikely(__pyx_t_1)) { + + /* "View.MemoryView":570 + * if self.view.strides == NULL: + * + * raise ValueError("Buffer view does not expose strides") # <<<<<<<<<<<<<< + * + * return tuple([stride for stride in self.view.strides[:self.view.ndim]]) + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 570, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(2, 570, __pyx_L1_error) + + /* "View.MemoryView":568 + * @property + * def strides(self): + * if self.view.strides == NULL: # <<<<<<<<<<<<<< + * + * raise ValueError("Buffer view does not expose strides") + */ + } + + /* "View.MemoryView":572 + * raise ValueError("Buffer view does not expose strides") + * + * return tuple([stride for stride in self.view.strides[:self.view.ndim]]) # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 572, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = (__pyx_v_self->view.strides + __pyx_v_self->view.ndim); + for (__pyx_t_5 = __pyx_v_self->view.strides; __pyx_t_5 < __pyx_t_4; __pyx_t_5++) { + __pyx_t_3 = __pyx_t_5; + __pyx_v_stride = (__pyx_t_3[0]); + __pyx_t_6 = PyInt_FromSsize_t(__pyx_v_stride); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 572, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_6))) __PYX_ERR(2, 572, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __pyx_t_6 = PyList_AsTuple(((PyObject*)__pyx_t_2)); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 572, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_6; + __pyx_t_6 = 0; + goto __pyx_L0; + + /* "View.MemoryView":567 + * + * @property + * def strides(self): # <<<<<<<<<<<<<< + * if self.view.strides == NULL: + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("View.MemoryView.memoryview.strides.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":575 + * + * @property + * def suboffsets(self): # <<<<<<<<<<<<<< + * if self.view.suboffsets == NULL: + * return (-1,) * self.view.ndim + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_10suboffsets_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_10suboffsets_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_10suboffsets___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_10suboffsets___get__(struct __pyx_memoryview_obj *__pyx_v_self) { + Py_ssize_t __pyx_v_suboffset; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + Py_ssize_t *__pyx_t_4; + Py_ssize_t *__pyx_t_5; + Py_ssize_t *__pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + + /* "View.MemoryView":576 + * @property + * def suboffsets(self): + * if self.view.suboffsets == NULL: # <<<<<<<<<<<<<< + * return (-1,) * self.view.ndim + * + */ + __pyx_t_1 = ((__pyx_v_self->view.suboffsets == NULL) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":577 + * def suboffsets(self): + * if self.view.suboffsets == NULL: + * return (-1,) * self.view.ndim # <<<<<<<<<<<<<< + * + * return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]]) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->view.ndim); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 577, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyNumber_Multiply(__pyx_tuple__17, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 577, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + /* "View.MemoryView":576 + * @property + * def suboffsets(self): + * if self.view.suboffsets == NULL: # <<<<<<<<<<<<<< + * return (-1,) * self.view.ndim + * + */ + } + + /* "View.MemoryView":579 + * return (-1,) * self.view.ndim + * + * return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]]) # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 579, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = (__pyx_v_self->view.suboffsets + __pyx_v_self->view.ndim); + for (__pyx_t_6 = __pyx_v_self->view.suboffsets; __pyx_t_6 < __pyx_t_5; __pyx_t_6++) { + __pyx_t_4 = __pyx_t_6; + __pyx_v_suboffset = (__pyx_t_4[0]); + __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_suboffset); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 579, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_2))) __PYX_ERR(2, 579, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __pyx_t_2 = PyList_AsTuple(((PyObject*)__pyx_t_3)); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 579, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "View.MemoryView":575 + * + * @property + * def suboffsets(self): # <<<<<<<<<<<<<< + * if self.view.suboffsets == NULL: + * return (-1,) * self.view.ndim + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("View.MemoryView.memoryview.suboffsets.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":582 + * + * @property + * def ndim(self): # <<<<<<<<<<<<<< + * return self.view.ndim + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4ndim_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4ndim_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4ndim___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4ndim___get__(struct __pyx_memoryview_obj *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + + /* "View.MemoryView":583 + * @property + * def ndim(self): + * return self.view.ndim # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->view.ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 583, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "View.MemoryView":582 + * + * @property + * def ndim(self): # <<<<<<<<<<<<<< + * return self.view.ndim + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("View.MemoryView.memoryview.ndim.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":586 + * + * @property + * def itemsize(self): # <<<<<<<<<<<<<< + * return self.view.itemsize + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_8itemsize_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_8itemsize_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_8itemsize___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_8itemsize___get__(struct __pyx_memoryview_obj *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + + /* "View.MemoryView":587 + * @property + * def itemsize(self): + * return self.view.itemsize # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_self->view.itemsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 587, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "View.MemoryView":586 + * + * @property + * def itemsize(self): # <<<<<<<<<<<<<< + * return self.view.itemsize + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("View.MemoryView.memoryview.itemsize.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":590 + * + * @property + * def nbytes(self): # <<<<<<<<<<<<<< + * return self.size * self.view.itemsize + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_6nbytes_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_6nbytes_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_6nbytes___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_6nbytes___get__(struct __pyx_memoryview_obj *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + + /* "View.MemoryView":591 + * @property + * def nbytes(self): + * return self.size * self.view.itemsize # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 591, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_self->view.itemsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 591, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyNumber_Multiply(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 591, __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_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + /* "View.MemoryView":590 + * + * @property + * def nbytes(self): # <<<<<<<<<<<<<< + * return self.size * self.view.itemsize + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("View.MemoryView.memoryview.nbytes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":594 + * + * @property + * def size(self): # <<<<<<<<<<<<<< + * if self._size is None: + * result = 1 + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4size_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4size_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4size___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4size___get__(struct __pyx_memoryview_obj *__pyx_v_self) { + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_v_length = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + Py_ssize_t *__pyx_t_3; + Py_ssize_t *__pyx_t_4; + Py_ssize_t *__pyx_t_5; + PyObject *__pyx_t_6 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + + /* "View.MemoryView":595 + * @property + * def size(self): + * if self._size is None: # <<<<<<<<<<<<<< + * result = 1 + * + */ + __pyx_t_1 = (__pyx_v_self->_size == Py_None); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":596 + * def size(self): + * if self._size is None: + * result = 1 # <<<<<<<<<<<<<< + * + * for length in self.view.shape[:self.view.ndim]: + */ + __Pyx_INCREF(__pyx_int_1); + __pyx_v_result = __pyx_int_1; + + /* "View.MemoryView":598 + * result = 1 + * + * for length in self.view.shape[:self.view.ndim]: # <<<<<<<<<<<<<< + * result *= length + * + */ + __pyx_t_4 = (__pyx_v_self->view.shape + __pyx_v_self->view.ndim); + for (__pyx_t_5 = __pyx_v_self->view.shape; __pyx_t_5 < __pyx_t_4; __pyx_t_5++) { + __pyx_t_3 = __pyx_t_5; + __pyx_t_6 = PyInt_FromSsize_t((__pyx_t_3[0])); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 598, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_XDECREF_SET(__pyx_v_length, __pyx_t_6); + __pyx_t_6 = 0; + + /* "View.MemoryView":599 + * + * for length in self.view.shape[:self.view.ndim]: + * result *= length # <<<<<<<<<<<<<< + * + * self._size = result + */ + __pyx_t_6 = PyNumber_InPlaceMultiply(__pyx_v_result, __pyx_v_length); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 599, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF_SET(__pyx_v_result, __pyx_t_6); + __pyx_t_6 = 0; + } + + /* "View.MemoryView":601 + * result *= length + * + * self._size = result # <<<<<<<<<<<<<< + * + * return self._size + */ + __Pyx_INCREF(__pyx_v_result); + __Pyx_GIVEREF(__pyx_v_result); + __Pyx_GOTREF(__pyx_v_self->_size); + __Pyx_DECREF(__pyx_v_self->_size); + __pyx_v_self->_size = __pyx_v_result; + + /* "View.MemoryView":595 + * @property + * def size(self): + * if self._size is None: # <<<<<<<<<<<<<< + * result = 1 + * + */ + } + + /* "View.MemoryView":603 + * self._size = result + * + * return self._size # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->_size); + __pyx_r = __pyx_v_self->_size; + goto __pyx_L0; + + /* "View.MemoryView":594 + * + * @property + * def size(self): # <<<<<<<<<<<<<< + * if self._size is None: + * result = 1 + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("View.MemoryView.memoryview.size.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XDECREF(__pyx_v_length); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":605 + * return self._size + * + * def __len__(self): # <<<<<<<<<<<<<< + * if self.view.ndim >= 1: + * return self.view.shape[0] + */ + +/* Python wrapper */ +static Py_ssize_t __pyx_memoryview___len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_memoryview___len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_10__len__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static Py_ssize_t __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_10__len__(struct __pyx_memoryview_obj *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__len__", 0); + + /* "View.MemoryView":606 + * + * def __len__(self): + * if self.view.ndim >= 1: # <<<<<<<<<<<<<< + * return self.view.shape[0] + * + */ + __pyx_t_1 = ((__pyx_v_self->view.ndim >= 1) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":607 + * def __len__(self): + * if self.view.ndim >= 1: + * return self.view.shape[0] # <<<<<<<<<<<<<< + * + * return 0 + */ + __pyx_r = (__pyx_v_self->view.shape[0]); + goto __pyx_L0; + + /* "View.MemoryView":606 + * + * def __len__(self): + * if self.view.ndim >= 1: # <<<<<<<<<<<<<< + * return self.view.shape[0] + * + */ + } + + /* "View.MemoryView":609 + * return self.view.shape[0] + * + * return 0 # <<<<<<<<<<<<<< + * + * def __repr__(self): + */ + __pyx_r = 0; + goto __pyx_L0; + + /* "View.MemoryView":605 + * return self._size + * + * def __len__(self): # <<<<<<<<<<<<<< + * if self.view.ndim >= 1: + * return self.view.shape[0] + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":611 + * return 0 + * + * def __repr__(self): # <<<<<<<<<<<<<< + * return "" % (self.base.__class__.__name__, + * id(self)) + */ + +/* Python wrapper */ +static PyObject *__pyx_memoryview___repr__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_memoryview___repr__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0); + __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_12__repr__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_12__repr__(struct __pyx_memoryview_obj *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__repr__", 0); + + /* "View.MemoryView":612 + * + * def __repr__(self): + * return "" % (self.base.__class__.__name__, # <<<<<<<<<<<<<< + * id(self)) + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 612, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_class); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 612, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_name_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 612, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "View.MemoryView":613 + * def __repr__(self): + * return "" % (self.base.__class__.__name__, + * id(self)) # <<<<<<<<<<<<<< + * + * def __str__(self): + */ + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_id, ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 613, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + + /* "View.MemoryView":612 + * + * def __repr__(self): + * return "" % (self.base.__class__.__name__, # <<<<<<<<<<<<<< + * id(self)) + * + */ + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 612, __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_2); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_MemoryView_of_r_at_0x_x, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 612, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "View.MemoryView":611 + * return 0 + * + * def __repr__(self): # <<<<<<<<<<<<<< + * return "" % (self.base.__class__.__name__, + * id(self)) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("View.MemoryView.memoryview.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":615 + * id(self)) + * + * def __str__(self): # <<<<<<<<<<<<<< + * return "" % (self.base.__class__.__name__,) + * + */ + +/* Python wrapper */ +static PyObject *__pyx_memoryview___str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_memoryview___str__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_14__str__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_14__str__(struct __pyx_memoryview_obj *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__str__", 0); + + /* "View.MemoryView":616 + * + * def __str__(self): + * return "" % (self.base.__class__.__name__,) # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 616, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_class); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 616, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_name_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 616, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 616, __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 = 0; + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_MemoryView_of_r_object, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 616, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "View.MemoryView":615 + * id(self)) + * + * def __str__(self): # <<<<<<<<<<<<<< + * return "" % (self.base.__class__.__name__,) + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("View.MemoryView.memoryview.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":619 + * + * + * def is_c_contig(self): # <<<<<<<<<<<<<< + * cdef __Pyx_memviewslice *mslice + * cdef __Pyx_memviewslice tmp + */ + +/* Python wrapper */ +static PyObject *__pyx_memoryview_is_c_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_memoryview_is_c_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("is_c_contig (wrapper)", 0); + __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_16is_c_contig(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_16is_c_contig(struct __pyx_memoryview_obj *__pyx_v_self) { + __Pyx_memviewslice *__pyx_v_mslice; + __Pyx_memviewslice __pyx_v_tmp; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_memviewslice *__pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("is_c_contig", 0); + + /* "View.MemoryView":622 + * cdef __Pyx_memviewslice *mslice + * cdef __Pyx_memviewslice tmp + * mslice = get_slice_from_memview(self, &tmp) # <<<<<<<<<<<<<< + * return slice_is_contig(mslice[0], 'C', self.view.ndim) + * + */ + __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_self, (&__pyx_v_tmp)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(2, 622, __pyx_L1_error) + __pyx_v_mslice = __pyx_t_1; + + /* "View.MemoryView":623 + * cdef __Pyx_memviewslice tmp + * mslice = get_slice_from_memview(self, &tmp) + * return slice_is_contig(mslice[0], 'C', self.view.ndim) # <<<<<<<<<<<<<< + * + * def is_f_contig(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_memviewslice_is_contig((__pyx_v_mslice[0]), 'C', __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 623, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "View.MemoryView":619 + * + * + * def is_c_contig(self): # <<<<<<<<<<<<<< + * cdef __Pyx_memviewslice *mslice + * cdef __Pyx_memviewslice tmp + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("View.MemoryView.memoryview.is_c_contig", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":625 + * return slice_is_contig(mslice[0], 'C', self.view.ndim) + * + * def is_f_contig(self): # <<<<<<<<<<<<<< + * cdef __Pyx_memviewslice *mslice + * cdef __Pyx_memviewslice tmp + */ + +/* Python wrapper */ +static PyObject *__pyx_memoryview_is_f_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_memoryview_is_f_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("is_f_contig (wrapper)", 0); + __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_18is_f_contig(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_18is_f_contig(struct __pyx_memoryview_obj *__pyx_v_self) { + __Pyx_memviewslice *__pyx_v_mslice; + __Pyx_memviewslice __pyx_v_tmp; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_memviewslice *__pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("is_f_contig", 0); + + /* "View.MemoryView":628 + * cdef __Pyx_memviewslice *mslice + * cdef __Pyx_memviewslice tmp + * mslice = get_slice_from_memview(self, &tmp) # <<<<<<<<<<<<<< + * return slice_is_contig(mslice[0], 'F', self.view.ndim) + * + */ + __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_self, (&__pyx_v_tmp)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(2, 628, __pyx_L1_error) + __pyx_v_mslice = __pyx_t_1; + + /* "View.MemoryView":629 + * cdef __Pyx_memviewslice tmp + * mslice = get_slice_from_memview(self, &tmp) + * return slice_is_contig(mslice[0], 'F', self.view.ndim) # <<<<<<<<<<<<<< + * + * def copy(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_memviewslice_is_contig((__pyx_v_mslice[0]), 'F', __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 629, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "View.MemoryView":625 + * return slice_is_contig(mslice[0], 'C', self.view.ndim) + * + * def is_f_contig(self): # <<<<<<<<<<<<<< + * cdef __Pyx_memviewslice *mslice + * cdef __Pyx_memviewslice tmp + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("View.MemoryView.memoryview.is_f_contig", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":631 + * return slice_is_contig(mslice[0], 'F', self.view.ndim) + * + * def copy(self): # <<<<<<<<<<<<<< + * cdef __Pyx_memviewslice mslice + * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS + */ + +/* Python wrapper */ +static PyObject *__pyx_memoryview_copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_memoryview_copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("copy (wrapper)", 0); + __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_20copy(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_20copy(struct __pyx_memoryview_obj *__pyx_v_self) { + __Pyx_memviewslice __pyx_v_mslice; + int __pyx_v_flags; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_memviewslice __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("copy", 0); + + /* "View.MemoryView":633 + * def copy(self): + * cdef __Pyx_memviewslice mslice + * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS # <<<<<<<<<<<<<< + * + * slice_copy(self, &mslice) + */ + __pyx_v_flags = (__pyx_v_self->flags & (~PyBUF_F_CONTIGUOUS)); + + /* "View.MemoryView":635 + * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS + * + * slice_copy(self, &mslice) # <<<<<<<<<<<<<< + * mslice = slice_copy_contig(&mslice, "c", self.view.ndim, + * self.view.itemsize, + */ + __pyx_memoryview_slice_copy(__pyx_v_self, (&__pyx_v_mslice)); + + /* "View.MemoryView":636 + * + * slice_copy(self, &mslice) + * mslice = slice_copy_contig(&mslice, "c", self.view.ndim, # <<<<<<<<<<<<<< + * self.view.itemsize, + * flags|PyBUF_C_CONTIGUOUS, + */ + __pyx_t_1 = __pyx_memoryview_copy_new_contig((&__pyx_v_mslice), ((char *)"c"), __pyx_v_self->view.ndim, __pyx_v_self->view.itemsize, (__pyx_v_flags | PyBUF_C_CONTIGUOUS), __pyx_v_self->dtype_is_object); if (unlikely(PyErr_Occurred())) __PYX_ERR(2, 636, __pyx_L1_error) + __pyx_v_mslice = __pyx_t_1; + + /* "View.MemoryView":641 + * self.dtype_is_object) + * + * return memoryview_copy_from_slice(self, &mslice) # <<<<<<<<<<<<<< + * + * def copy_fortran(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __pyx_memoryview_copy_object_from_slice(__pyx_v_self, (&__pyx_v_mslice)); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 641, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "View.MemoryView":631 + * return slice_is_contig(mslice[0], 'F', self.view.ndim) + * + * def copy(self): # <<<<<<<<<<<<<< + * cdef __Pyx_memviewslice mslice + * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("View.MemoryView.memoryview.copy", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":643 + * return memoryview_copy_from_slice(self, &mslice) + * + * def copy_fortran(self): # <<<<<<<<<<<<<< + * cdef __Pyx_memviewslice src, dst + * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS + */ + +/* Python wrapper */ +static PyObject *__pyx_memoryview_copy_fortran(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_memoryview_copy_fortran(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("copy_fortran (wrapper)", 0); + __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_22copy_fortran(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_22copy_fortran(struct __pyx_memoryview_obj *__pyx_v_self) { + __Pyx_memviewslice __pyx_v_src; + __Pyx_memviewslice __pyx_v_dst; + int __pyx_v_flags; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_memviewslice __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("copy_fortran", 0); + + /* "View.MemoryView":645 + * def copy_fortran(self): + * cdef __Pyx_memviewslice src, dst + * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS # <<<<<<<<<<<<<< + * + * slice_copy(self, &src) + */ + __pyx_v_flags = (__pyx_v_self->flags & (~PyBUF_C_CONTIGUOUS)); + + /* "View.MemoryView":647 + * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS + * + * slice_copy(self, &src) # <<<<<<<<<<<<<< + * dst = slice_copy_contig(&src, "fortran", self.view.ndim, + * self.view.itemsize, + */ + __pyx_memoryview_slice_copy(__pyx_v_self, (&__pyx_v_src)); + + /* "View.MemoryView":648 + * + * slice_copy(self, &src) + * dst = slice_copy_contig(&src, "fortran", self.view.ndim, # <<<<<<<<<<<<<< + * self.view.itemsize, + * flags|PyBUF_F_CONTIGUOUS, + */ + __pyx_t_1 = __pyx_memoryview_copy_new_contig((&__pyx_v_src), ((char *)"fortran"), __pyx_v_self->view.ndim, __pyx_v_self->view.itemsize, (__pyx_v_flags | PyBUF_F_CONTIGUOUS), __pyx_v_self->dtype_is_object); if (unlikely(PyErr_Occurred())) __PYX_ERR(2, 648, __pyx_L1_error) + __pyx_v_dst = __pyx_t_1; + + /* "View.MemoryView":653 + * self.dtype_is_object) + * + * return memoryview_copy_from_slice(self, &dst) # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __pyx_memoryview_copy_object_from_slice(__pyx_v_self, (&__pyx_v_dst)); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 653, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "View.MemoryView":643 + * return memoryview_copy_from_slice(self, &mslice) + * + * def copy_fortran(self): # <<<<<<<<<<<<<< + * cdef __Pyx_memviewslice src, dst + * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("View.MemoryView.memoryview.copy_fortran", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(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___pyx_memoryview_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw___pyx_memoryview_1__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___pyx_memoryview___reduce_cython__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf___pyx_memoryview___reduce_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __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__18, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 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(2, 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("View.MemoryView.memoryview.__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___pyx_memoryview_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw___pyx_memoryview_3__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___pyx_memoryview_2__setstate_cython__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf___pyx_memoryview_2__setstate_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __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__19, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 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(2, 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("View.MemoryView.memoryview.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":657 + * + * @cname('__pyx_memoryview_new') + * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo): # <<<<<<<<<<<<<< + * cdef memoryview result = memoryview(o, flags, dtype_is_object) + * result.typeinfo = typeinfo + */ + +static PyObject *__pyx_memoryview_new(PyObject *__pyx_v_o, int __pyx_v_flags, int __pyx_v_dtype_is_object, __Pyx_TypeInfo *__pyx_v_typeinfo) { + struct __pyx_memoryview_obj *__pyx_v_result = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("memoryview_cwrapper", 0); + + /* "View.MemoryView":658 + * @cname('__pyx_memoryview_new') + * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo): + * cdef memoryview result = memoryview(o, flags, dtype_is_object) # <<<<<<<<<<<<<< + * result.typeinfo = typeinfo + * return result + */ + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_flags); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 658, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_dtype_is_object); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 658, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 658, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_o); + __Pyx_GIVEREF(__pyx_v_o); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_o); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 658, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_result = ((struct __pyx_memoryview_obj *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "View.MemoryView":659 + * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo): + * cdef memoryview result = memoryview(o, flags, dtype_is_object) + * result.typeinfo = typeinfo # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_v_result->typeinfo = __pyx_v_typeinfo; + + /* "View.MemoryView":660 + * cdef memoryview result = memoryview(o, flags, dtype_is_object) + * result.typeinfo = typeinfo + * return result # <<<<<<<<<<<<<< + * + * @cname('__pyx_memoryview_check') + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = ((PyObject *)__pyx_v_result); + goto __pyx_L0; + + /* "View.MemoryView":657 + * + * @cname('__pyx_memoryview_new') + * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo): # <<<<<<<<<<<<<< + * cdef memoryview result = memoryview(o, flags, dtype_is_object) + * result.typeinfo = typeinfo + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("View.MemoryView.memoryview_cwrapper", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":663 + * + * @cname('__pyx_memoryview_check') + * cdef inline bint memoryview_check(object o): # <<<<<<<<<<<<<< + * return isinstance(o, memoryview) + * + */ + +static CYTHON_INLINE int __pyx_memoryview_check(PyObject *__pyx_v_o) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("memoryview_check", 0); + + /* "View.MemoryView":664 + * @cname('__pyx_memoryview_check') + * cdef inline bint memoryview_check(object o): + * return isinstance(o, memoryview) # <<<<<<<<<<<<<< + * + * cdef tuple _unellipsify(object index, int ndim): + */ + __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_o, __pyx_memoryview_type); + __pyx_r = __pyx_t_1; + goto __pyx_L0; + + /* "View.MemoryView":663 + * + * @cname('__pyx_memoryview_check') + * cdef inline bint memoryview_check(object o): # <<<<<<<<<<<<<< + * return isinstance(o, memoryview) + * + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":666 + * return isinstance(o, memoryview) + * + * cdef tuple _unellipsify(object index, int ndim): # <<<<<<<<<<<<<< + * """ + * Replace all ellipses with full slices and fill incomplete indices with + */ + +static PyObject *_unellipsify(PyObject *__pyx_v_index, int __pyx_v_ndim) { + PyObject *__pyx_v_tup = NULL; + PyObject *__pyx_v_result = NULL; + int __pyx_v_have_slices; + int __pyx_v_seen_ellipsis; + CYTHON_UNUSED PyObject *__pyx_v_idx = NULL; + PyObject *__pyx_v_item = NULL; + Py_ssize_t __pyx_v_nslices; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + Py_ssize_t __pyx_t_5; + PyObject *(*__pyx_t_6)(PyObject *); + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + int __pyx_t_9; + int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_unellipsify", 0); + + /* "View.MemoryView":671 + * full slices. + * """ + * if not isinstance(index, tuple): # <<<<<<<<<<<<<< + * tup = (index,) + * else: + */ + __pyx_t_1 = PyTuple_Check(__pyx_v_index); + __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":672 + * """ + * if not isinstance(index, tuple): + * tup = (index,) # <<<<<<<<<<<<<< + * else: + * tup = index + */ + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 672, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_index); + __Pyx_GIVEREF(__pyx_v_index); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_index); + __pyx_v_tup = __pyx_t_3; + __pyx_t_3 = 0; + + /* "View.MemoryView":671 + * full slices. + * """ + * if not isinstance(index, tuple): # <<<<<<<<<<<<<< + * tup = (index,) + * else: + */ + goto __pyx_L3; + } + + /* "View.MemoryView":674 + * tup = (index,) + * else: + * tup = index # <<<<<<<<<<<<<< + * + * result = [] + */ + /*else*/ { + __Pyx_INCREF(__pyx_v_index); + __pyx_v_tup = __pyx_v_index; + } + __pyx_L3:; + + /* "View.MemoryView":676 + * tup = index + * + * result = [] # <<<<<<<<<<<<<< + * have_slices = False + * seen_ellipsis = False + */ + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 676, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_result = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + + /* "View.MemoryView":677 + * + * result = [] + * have_slices = False # <<<<<<<<<<<<<< + * seen_ellipsis = False + * for idx, item in enumerate(tup): + */ + __pyx_v_have_slices = 0; + + /* "View.MemoryView":678 + * result = [] + * have_slices = False + * seen_ellipsis = False # <<<<<<<<<<<<<< + * for idx, item in enumerate(tup): + * if item is Ellipsis: + */ + __pyx_v_seen_ellipsis = 0; + + /* "View.MemoryView":679 + * have_slices = False + * seen_ellipsis = False + * for idx, item in enumerate(tup): # <<<<<<<<<<<<<< + * if item is Ellipsis: + * if not seen_ellipsis: + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_t_3 = __pyx_int_0; + if (likely(PyList_CheckExact(__pyx_v_tup)) || PyTuple_CheckExact(__pyx_v_tup)) { + __pyx_t_4 = __pyx_v_tup; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0; + __pyx_t_6 = NULL; + } else { + __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_tup); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 679, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 679, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_6)) { + if (likely(PyList_CheckExact(__pyx_t_4))) { + if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(2, 679, __pyx_L1_error) + #else + __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 679, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + } else { + if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(2, 679, __pyx_L1_error) + #else + __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 679, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + } + } else { + __pyx_t_7 = __pyx_t_6(__pyx_t_4); + if (unlikely(!__pyx_t_7)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(2, 679, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_7); + } + __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_INCREF(__pyx_t_3); + __Pyx_XDECREF_SET(__pyx_v_idx, __pyx_t_3); + __pyx_t_7 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 679, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); + __pyx_t_3 = __pyx_t_7; + __pyx_t_7 = 0; + + /* "View.MemoryView":680 + * seen_ellipsis = False + * for idx, item in enumerate(tup): + * if item is Ellipsis: # <<<<<<<<<<<<<< + * if not seen_ellipsis: + * result.extend([slice(None)] * (ndim - len(tup) + 1)) + */ + __pyx_t_2 = (__pyx_v_item == __pyx_builtin_Ellipsis); + __pyx_t_1 = (__pyx_t_2 != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":681 + * for idx, item in enumerate(tup): + * if item is Ellipsis: + * if not seen_ellipsis: # <<<<<<<<<<<<<< + * result.extend([slice(None)] * (ndim - len(tup) + 1)) + * seen_ellipsis = True + */ + __pyx_t_1 = ((!(__pyx_v_seen_ellipsis != 0)) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":682 + * if item is Ellipsis: + * if not seen_ellipsis: + * result.extend([slice(None)] * (ndim - len(tup) + 1)) # <<<<<<<<<<<<<< + * seen_ellipsis = True + * else: + */ + __pyx_t_8 = PyObject_Length(__pyx_v_tup); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(2, 682, __pyx_L1_error) + __pyx_t_7 = PyList_New(1 * ((((__pyx_v_ndim - __pyx_t_8) + 1)<0) ? 0:((__pyx_v_ndim - __pyx_t_8) + 1))); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 682, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + { Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < ((__pyx_v_ndim - __pyx_t_8) + 1); __pyx_temp++) { + __Pyx_INCREF(__pyx_slice_); + __Pyx_GIVEREF(__pyx_slice_); + PyList_SET_ITEM(__pyx_t_7, __pyx_temp, __pyx_slice_); + } + } + __pyx_t_9 = __Pyx_PyList_Extend(__pyx_v_result, __pyx_t_7); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(2, 682, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "View.MemoryView":683 + * if not seen_ellipsis: + * result.extend([slice(None)] * (ndim - len(tup) + 1)) + * seen_ellipsis = True # <<<<<<<<<<<<<< + * else: + * result.append(slice(None)) + */ + __pyx_v_seen_ellipsis = 1; + + /* "View.MemoryView":681 + * for idx, item in enumerate(tup): + * if item is Ellipsis: + * if not seen_ellipsis: # <<<<<<<<<<<<<< + * result.extend([slice(None)] * (ndim - len(tup) + 1)) + * seen_ellipsis = True + */ + goto __pyx_L7; + } + + /* "View.MemoryView":685 + * seen_ellipsis = True + * else: + * result.append(slice(None)) # <<<<<<<<<<<<<< + * have_slices = True + * else: + */ + /*else*/ { + __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_slice_); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(2, 685, __pyx_L1_error) + } + __pyx_L7:; + + /* "View.MemoryView":686 + * else: + * result.append(slice(None)) + * have_slices = True # <<<<<<<<<<<<<< + * else: + * if not isinstance(item, slice) and not PyIndex_Check(item): + */ + __pyx_v_have_slices = 1; + + /* "View.MemoryView":680 + * seen_ellipsis = False + * for idx, item in enumerate(tup): + * if item is Ellipsis: # <<<<<<<<<<<<<< + * if not seen_ellipsis: + * result.extend([slice(None)] * (ndim - len(tup) + 1)) + */ + goto __pyx_L6; + } + + /* "View.MemoryView":688 + * have_slices = True + * else: + * if not isinstance(item, slice) and not PyIndex_Check(item): # <<<<<<<<<<<<<< + * raise TypeError("Cannot index with type '%s'" % type(item)) + * + */ + /*else*/ { + __pyx_t_2 = PySlice_Check(__pyx_v_item); + __pyx_t_10 = ((!(__pyx_t_2 != 0)) != 0); + if (__pyx_t_10) { + } else { + __pyx_t_1 = __pyx_t_10; + goto __pyx_L9_bool_binop_done; + } + __pyx_t_10 = ((!(PyIndex_Check(__pyx_v_item) != 0)) != 0); + __pyx_t_1 = __pyx_t_10; + __pyx_L9_bool_binop_done:; + if (unlikely(__pyx_t_1)) { + + /* "View.MemoryView":689 + * else: + * if not isinstance(item, slice) and not PyIndex_Check(item): + * raise TypeError("Cannot index with type '%s'" % type(item)) # <<<<<<<<<<<<<< + * + * have_slices = have_slices or isinstance(item, slice) + */ + __pyx_t_7 = __Pyx_PyString_FormatSafe(__pyx_kp_s_Cannot_index_with_type_s, ((PyObject *)Py_TYPE(__pyx_v_item))); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 689, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_7); if (unlikely(!__pyx_t_11)) __PYX_ERR(2, 689, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_Raise(__pyx_t_11, 0, 0, 0); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __PYX_ERR(2, 689, __pyx_L1_error) + + /* "View.MemoryView":688 + * have_slices = True + * else: + * if not isinstance(item, slice) and not PyIndex_Check(item): # <<<<<<<<<<<<<< + * raise TypeError("Cannot index with type '%s'" % type(item)) + * + */ + } + + /* "View.MemoryView":691 + * raise TypeError("Cannot index with type '%s'" % type(item)) + * + * have_slices = have_slices or isinstance(item, slice) # <<<<<<<<<<<<<< + * result.append(item) + * + */ + __pyx_t_10 = (__pyx_v_have_slices != 0); + if (!__pyx_t_10) { + } else { + __pyx_t_1 = __pyx_t_10; + goto __pyx_L11_bool_binop_done; + } + __pyx_t_10 = PySlice_Check(__pyx_v_item); + __pyx_t_2 = (__pyx_t_10 != 0); + __pyx_t_1 = __pyx_t_2; + __pyx_L11_bool_binop_done:; + __pyx_v_have_slices = __pyx_t_1; + + /* "View.MemoryView":692 + * + * have_slices = have_slices or isinstance(item, slice) + * result.append(item) # <<<<<<<<<<<<<< + * + * nslices = ndim - len(result) + */ + __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_v_item); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(2, 692, __pyx_L1_error) + } + __pyx_L6:; + + /* "View.MemoryView":679 + * have_slices = False + * seen_ellipsis = False + * for idx, item in enumerate(tup): # <<<<<<<<<<<<<< + * if item is Ellipsis: + * if not seen_ellipsis: + */ + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "View.MemoryView":694 + * result.append(item) + * + * nslices = ndim - len(result) # <<<<<<<<<<<<<< + * if nslices: + * result.extend([slice(None)] * nslices) + */ + __pyx_t_5 = PyList_GET_SIZE(__pyx_v_result); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(2, 694, __pyx_L1_error) + __pyx_v_nslices = (__pyx_v_ndim - __pyx_t_5); + + /* "View.MemoryView":695 + * + * nslices = ndim - len(result) + * if nslices: # <<<<<<<<<<<<<< + * result.extend([slice(None)] * nslices) + * + */ + __pyx_t_1 = (__pyx_v_nslices != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":696 + * nslices = ndim - len(result) + * if nslices: + * result.extend([slice(None)] * nslices) # <<<<<<<<<<<<<< + * + * return have_slices or nslices, tuple(result) + */ + __pyx_t_3 = PyList_New(1 * ((__pyx_v_nslices<0) ? 0:__pyx_v_nslices)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 696, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + { Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < __pyx_v_nslices; __pyx_temp++) { + __Pyx_INCREF(__pyx_slice_); + __Pyx_GIVEREF(__pyx_slice_); + PyList_SET_ITEM(__pyx_t_3, __pyx_temp, __pyx_slice_); + } + } + __pyx_t_9 = __Pyx_PyList_Extend(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(2, 696, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "View.MemoryView":695 + * + * nslices = ndim - len(result) + * if nslices: # <<<<<<<<<<<<<< + * result.extend([slice(None)] * nslices) + * + */ + } + + /* "View.MemoryView":698 + * result.extend([slice(None)] * nslices) + * + * return have_slices or nslices, tuple(result) # <<<<<<<<<<<<<< + * + * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): + */ + __Pyx_XDECREF(__pyx_r); + if (!__pyx_v_have_slices) { + } else { + __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_v_have_slices); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 698, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L14_bool_binop_done; + } + __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_nslices); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 698, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __pyx_t_4; + __pyx_t_4 = 0; + __pyx_L14_bool_binop_done:; + __pyx_t_4 = PyList_AsTuple(__pyx_v_result); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 698, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(2, 698, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_4); + __pyx_t_3 = 0; + __pyx_t_4 = 0; + __pyx_r = ((PyObject*)__pyx_t_11); + __pyx_t_11 = 0; + goto __pyx_L0; + + /* "View.MemoryView":666 + * return isinstance(o, memoryview) + * + * cdef tuple _unellipsify(object index, int ndim): # <<<<<<<<<<<<<< + * """ + * Replace all ellipses with full slices and fill incomplete indices with + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("View.MemoryView._unellipsify", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_tup); + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XDECREF(__pyx_v_idx); + __Pyx_XDECREF(__pyx_v_item); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":700 + * return have_slices or nslices, tuple(result) + * + * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): # <<<<<<<<<<<<<< + * for suboffset in suboffsets[:ndim]: + * if suboffset >= 0: + */ + +static PyObject *assert_direct_dimensions(Py_ssize_t *__pyx_v_suboffsets, int __pyx_v_ndim) { + Py_ssize_t __pyx_v_suboffset; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + Py_ssize_t *__pyx_t_1; + Py_ssize_t *__pyx_t_2; + Py_ssize_t *__pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("assert_direct_dimensions", 0); + + /* "View.MemoryView":701 + * + * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): + * for suboffset in suboffsets[:ndim]: # <<<<<<<<<<<<<< + * if suboffset >= 0: + * raise ValueError("Indirect dimensions not supported") + */ + __pyx_t_2 = (__pyx_v_suboffsets + __pyx_v_ndim); + for (__pyx_t_3 = __pyx_v_suboffsets; __pyx_t_3 < __pyx_t_2; __pyx_t_3++) { + __pyx_t_1 = __pyx_t_3; + __pyx_v_suboffset = (__pyx_t_1[0]); + + /* "View.MemoryView":702 + * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): + * for suboffset in suboffsets[:ndim]: + * if suboffset >= 0: # <<<<<<<<<<<<<< + * raise ValueError("Indirect dimensions not supported") + * + */ + __pyx_t_4 = ((__pyx_v_suboffset >= 0) != 0); + if (unlikely(__pyx_t_4)) { + + /* "View.MemoryView":703 + * for suboffset in suboffsets[:ndim]: + * if suboffset >= 0: + * raise ValueError("Indirect dimensions not supported") # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__20, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 703, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __PYX_ERR(2, 703, __pyx_L1_error) + + /* "View.MemoryView":702 + * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): + * for suboffset in suboffsets[:ndim]: + * if suboffset >= 0: # <<<<<<<<<<<<<< + * raise ValueError("Indirect dimensions not supported") + * + */ + } + } + + /* "View.MemoryView":700 + * return have_slices or nslices, tuple(result) + * + * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): # <<<<<<<<<<<<<< + * for suboffset in suboffsets[:ndim]: + * if suboffset >= 0: + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("View.MemoryView.assert_direct_dimensions", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":710 + * + * @cname('__pyx_memview_slice') + * cdef memoryview memview_slice(memoryview memview, object indices): # <<<<<<<<<<<<<< + * cdef int new_ndim = 0, suboffset_dim = -1, dim + * cdef bint negative_step + */ + +static struct __pyx_memoryview_obj *__pyx_memview_slice(struct __pyx_memoryview_obj *__pyx_v_memview, PyObject *__pyx_v_indices) { + int __pyx_v_new_ndim; + int __pyx_v_suboffset_dim; + int __pyx_v_dim; + __Pyx_memviewslice __pyx_v_src; + __Pyx_memviewslice __pyx_v_dst; + __Pyx_memviewslice *__pyx_v_p_src; + struct __pyx_memoryviewslice_obj *__pyx_v_memviewsliceobj = 0; + __Pyx_memviewslice *__pyx_v_p_dst; + int *__pyx_v_p_suboffset_dim; + Py_ssize_t __pyx_v_start; + Py_ssize_t __pyx_v_stop; + Py_ssize_t __pyx_v_step; + int __pyx_v_have_start; + int __pyx_v_have_stop; + int __pyx_v_have_step; + PyObject *__pyx_v_index = NULL; + struct __pyx_memoryview_obj *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + struct __pyx_memoryview_obj *__pyx_t_4; + char *__pyx_t_5; + int __pyx_t_6; + Py_ssize_t __pyx_t_7; + PyObject *(*__pyx_t_8)(PyObject *); + PyObject *__pyx_t_9 = NULL; + Py_ssize_t __pyx_t_10; + int __pyx_t_11; + Py_ssize_t __pyx_t_12; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("memview_slice", 0); + + /* "View.MemoryView":711 + * @cname('__pyx_memview_slice') + * cdef memoryview memview_slice(memoryview memview, object indices): + * cdef int new_ndim = 0, suboffset_dim = -1, dim # <<<<<<<<<<<<<< + * cdef bint negative_step + * cdef __Pyx_memviewslice src, dst + */ + __pyx_v_new_ndim = 0; + __pyx_v_suboffset_dim = -1; + + /* "View.MemoryView":718 + * + * + * memset(&dst, 0, sizeof(dst)) # <<<<<<<<<<<<<< + * + * cdef _memoryviewslice memviewsliceobj + */ + (void)(memset((&__pyx_v_dst), 0, (sizeof(__pyx_v_dst)))); + + /* "View.MemoryView":722 + * cdef _memoryviewslice memviewsliceobj + * + * assert memview.view.ndim > 0 # <<<<<<<<<<<<<< + * + * if isinstance(memview, _memoryviewslice): + */ + #ifndef CYTHON_WITHOUT_ASSERTIONS + if (unlikely(!Py_OptimizeFlag)) { + if (unlikely(!((__pyx_v_memview->view.ndim > 0) != 0))) { + PyErr_SetNone(PyExc_AssertionError); + __PYX_ERR(2, 722, __pyx_L1_error) + } + } + #endif + + /* "View.MemoryView":724 + * assert memview.view.ndim > 0 + * + * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< + * memviewsliceobj = memview + * p_src = &memviewsliceobj.from_slice + */ + __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":725 + * + * if isinstance(memview, _memoryviewslice): + * memviewsliceobj = memview # <<<<<<<<<<<<<< + * p_src = &memviewsliceobj.from_slice + * else: + */ + if (!(likely(((((PyObject *)__pyx_v_memview)) == Py_None) || likely(__Pyx_TypeTest(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type))))) __PYX_ERR(2, 725, __pyx_L1_error) + __pyx_t_3 = ((PyObject *)__pyx_v_memview); + __Pyx_INCREF(__pyx_t_3); + __pyx_v_memviewsliceobj = ((struct __pyx_memoryviewslice_obj *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "View.MemoryView":726 + * if isinstance(memview, _memoryviewslice): + * memviewsliceobj = memview + * p_src = &memviewsliceobj.from_slice # <<<<<<<<<<<<<< + * else: + * slice_copy(memview, &src) + */ + __pyx_v_p_src = (&__pyx_v_memviewsliceobj->from_slice); + + /* "View.MemoryView":724 + * assert memview.view.ndim > 0 + * + * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< + * memviewsliceobj = memview + * p_src = &memviewsliceobj.from_slice + */ + goto __pyx_L3; + } + + /* "View.MemoryView":728 + * p_src = &memviewsliceobj.from_slice + * else: + * slice_copy(memview, &src) # <<<<<<<<<<<<<< + * p_src = &src + * + */ + /*else*/ { + __pyx_memoryview_slice_copy(__pyx_v_memview, (&__pyx_v_src)); + + /* "View.MemoryView":729 + * else: + * slice_copy(memview, &src) + * p_src = &src # <<<<<<<<<<<<<< + * + * + */ + __pyx_v_p_src = (&__pyx_v_src); + } + __pyx_L3:; + + /* "View.MemoryView":735 + * + * + * dst.memview = p_src.memview # <<<<<<<<<<<<<< + * dst.data = p_src.data + * + */ + __pyx_t_4 = __pyx_v_p_src->memview; + __pyx_v_dst.memview = __pyx_t_4; + + /* "View.MemoryView":736 + * + * dst.memview = p_src.memview + * dst.data = p_src.data # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_5 = __pyx_v_p_src->data; + __pyx_v_dst.data = __pyx_t_5; + + /* "View.MemoryView":741 + * + * + * cdef __Pyx_memviewslice *p_dst = &dst # <<<<<<<<<<<<<< + * cdef int *p_suboffset_dim = &suboffset_dim + * cdef Py_ssize_t start, stop, step + */ + __pyx_v_p_dst = (&__pyx_v_dst); + + /* "View.MemoryView":742 + * + * cdef __Pyx_memviewslice *p_dst = &dst + * cdef int *p_suboffset_dim = &suboffset_dim # <<<<<<<<<<<<<< + * cdef Py_ssize_t start, stop, step + * cdef bint have_start, have_stop, have_step + */ + __pyx_v_p_suboffset_dim = (&__pyx_v_suboffset_dim); + + /* "View.MemoryView":746 + * cdef bint have_start, have_stop, have_step + * + * for dim, index in enumerate(indices): # <<<<<<<<<<<<<< + * if PyIndex_Check(index): + * slice_memviewslice( + */ + __pyx_t_6 = 0; + if (likely(PyList_CheckExact(__pyx_v_indices)) || PyTuple_CheckExact(__pyx_v_indices)) { + __pyx_t_3 = __pyx_v_indices; __Pyx_INCREF(__pyx_t_3); __pyx_t_7 = 0; + __pyx_t_8 = NULL; + } else { + __pyx_t_7 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_indices); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 746, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 746, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_8)) { + if (likely(PyList_CheckExact(__pyx_t_3))) { + if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_9 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_9); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(2, 746, __pyx_L1_error) + #else + __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 746, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + #endif + } else { + if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_9); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(2, 746, __pyx_L1_error) + #else + __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 746, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + #endif + } + } else { + __pyx_t_9 = __pyx_t_8(__pyx_t_3); + 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(2, 746, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_9); + } + __Pyx_XDECREF_SET(__pyx_v_index, __pyx_t_9); + __pyx_t_9 = 0; + __pyx_v_dim = __pyx_t_6; + __pyx_t_6 = (__pyx_t_6 + 1); + + /* "View.MemoryView":747 + * + * for dim, index in enumerate(indices): + * if PyIndex_Check(index): # <<<<<<<<<<<<<< + * slice_memviewslice( + * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim], + */ + __pyx_t_2 = (PyIndex_Check(__pyx_v_index) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":751 + * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim], + * dim, new_ndim, p_suboffset_dim, + * index, 0, 0, # start, stop, step # <<<<<<<<<<<<<< + * 0, 0, 0, # have_{start,stop,step} + * False) + */ + __pyx_t_10 = __Pyx_PyIndex_AsSsize_t(__pyx_v_index); if (unlikely((__pyx_t_10 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 751, __pyx_L1_error) + + /* "View.MemoryView":748 + * for dim, index in enumerate(indices): + * if PyIndex_Check(index): + * slice_memviewslice( # <<<<<<<<<<<<<< + * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim], + * dim, new_ndim, p_suboffset_dim, + */ + __pyx_t_11 = __pyx_memoryview_slice_memviewslice(__pyx_v_p_dst, (__pyx_v_p_src->shape[__pyx_v_dim]), (__pyx_v_p_src->strides[__pyx_v_dim]), (__pyx_v_p_src->suboffsets[__pyx_v_dim]), __pyx_v_dim, __pyx_v_new_ndim, __pyx_v_p_suboffset_dim, __pyx_t_10, 0, 0, 0, 0, 0, 0); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(2, 748, __pyx_L1_error) + + /* "View.MemoryView":747 + * + * for dim, index in enumerate(indices): + * if PyIndex_Check(index): # <<<<<<<<<<<<<< + * slice_memviewslice( + * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim], + */ + goto __pyx_L6; + } + + /* "View.MemoryView":754 + * 0, 0, 0, # have_{start,stop,step} + * False) + * elif index is None: # <<<<<<<<<<<<<< + * p_dst.shape[new_ndim] = 1 + * p_dst.strides[new_ndim] = 0 + */ + __pyx_t_2 = (__pyx_v_index == Py_None); + __pyx_t_1 = (__pyx_t_2 != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":755 + * False) + * elif index is None: + * p_dst.shape[new_ndim] = 1 # <<<<<<<<<<<<<< + * p_dst.strides[new_ndim] = 0 + * p_dst.suboffsets[new_ndim] = -1 + */ + (__pyx_v_p_dst->shape[__pyx_v_new_ndim]) = 1; + + /* "View.MemoryView":756 + * elif index is None: + * p_dst.shape[new_ndim] = 1 + * p_dst.strides[new_ndim] = 0 # <<<<<<<<<<<<<< + * p_dst.suboffsets[new_ndim] = -1 + * new_ndim += 1 + */ + (__pyx_v_p_dst->strides[__pyx_v_new_ndim]) = 0; + + /* "View.MemoryView":757 + * p_dst.shape[new_ndim] = 1 + * p_dst.strides[new_ndim] = 0 + * p_dst.suboffsets[new_ndim] = -1 # <<<<<<<<<<<<<< + * new_ndim += 1 + * else: + */ + (__pyx_v_p_dst->suboffsets[__pyx_v_new_ndim]) = -1L; + + /* "View.MemoryView":758 + * p_dst.strides[new_ndim] = 0 + * p_dst.suboffsets[new_ndim] = -1 + * new_ndim += 1 # <<<<<<<<<<<<<< + * else: + * start = index.start or 0 + */ + __pyx_v_new_ndim = (__pyx_v_new_ndim + 1); + + /* "View.MemoryView":754 + * 0, 0, 0, # have_{start,stop,step} + * False) + * elif index is None: # <<<<<<<<<<<<<< + * p_dst.shape[new_ndim] = 1 + * p_dst.strides[new_ndim] = 0 + */ + goto __pyx_L6; + } + + /* "View.MemoryView":760 + * new_ndim += 1 + * else: + * start = index.start or 0 # <<<<<<<<<<<<<< + * stop = index.stop or 0 + * step = index.step or 0 + */ + /*else*/ { + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_start); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 760, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(2, 760, __pyx_L1_error) + if (!__pyx_t_1) { + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else { + __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 760, __pyx_L1_error) + __pyx_t_10 = __pyx_t_12; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L7_bool_binop_done; + } + __pyx_t_10 = 0; + __pyx_L7_bool_binop_done:; + __pyx_v_start = __pyx_t_10; + + /* "View.MemoryView":761 + * else: + * start = index.start or 0 + * stop = index.stop or 0 # <<<<<<<<<<<<<< + * step = index.step or 0 + * + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_stop); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 761, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(2, 761, __pyx_L1_error) + if (!__pyx_t_1) { + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else { + __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 761, __pyx_L1_error) + __pyx_t_10 = __pyx_t_12; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L9_bool_binop_done; + } + __pyx_t_10 = 0; + __pyx_L9_bool_binop_done:; + __pyx_v_stop = __pyx_t_10; + + /* "View.MemoryView":762 + * start = index.start or 0 + * stop = index.stop or 0 + * step = index.step or 0 # <<<<<<<<<<<<<< + * + * have_start = index.start is not None + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_step); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 762, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(2, 762, __pyx_L1_error) + if (!__pyx_t_1) { + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else { + __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 762, __pyx_L1_error) + __pyx_t_10 = __pyx_t_12; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L11_bool_binop_done; + } + __pyx_t_10 = 0; + __pyx_L11_bool_binop_done:; + __pyx_v_step = __pyx_t_10; + + /* "View.MemoryView":764 + * step = index.step or 0 + * + * have_start = index.start is not None # <<<<<<<<<<<<<< + * have_stop = index.stop is not None + * have_step = index.step is not None + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_start); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 764, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_1 = (__pyx_t_9 != Py_None); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_v_have_start = __pyx_t_1; + + /* "View.MemoryView":765 + * + * have_start = index.start is not None + * have_stop = index.stop is not None # <<<<<<<<<<<<<< + * have_step = index.step is not None + * + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_stop); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 765, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_1 = (__pyx_t_9 != Py_None); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_v_have_stop = __pyx_t_1; + + /* "View.MemoryView":766 + * have_start = index.start is not None + * have_stop = index.stop is not None + * have_step = index.step is not None # <<<<<<<<<<<<<< + * + * slice_memviewslice( + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_step); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 766, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_1 = (__pyx_t_9 != Py_None); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_v_have_step = __pyx_t_1; + + /* "View.MemoryView":768 + * have_step = index.step is not None + * + * slice_memviewslice( # <<<<<<<<<<<<<< + * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim], + * dim, new_ndim, p_suboffset_dim, + */ + __pyx_t_11 = __pyx_memoryview_slice_memviewslice(__pyx_v_p_dst, (__pyx_v_p_src->shape[__pyx_v_dim]), (__pyx_v_p_src->strides[__pyx_v_dim]), (__pyx_v_p_src->suboffsets[__pyx_v_dim]), __pyx_v_dim, __pyx_v_new_ndim, __pyx_v_p_suboffset_dim, __pyx_v_start, __pyx_v_stop, __pyx_v_step, __pyx_v_have_start, __pyx_v_have_stop, __pyx_v_have_step, 1); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(2, 768, __pyx_L1_error) + + /* "View.MemoryView":774 + * have_start, have_stop, have_step, + * True) + * new_ndim += 1 # <<<<<<<<<<<<<< + * + * if isinstance(memview, _memoryviewslice): + */ + __pyx_v_new_ndim = (__pyx_v_new_ndim + 1); + } + __pyx_L6:; + + /* "View.MemoryView":746 + * cdef bint have_start, have_stop, have_step + * + * for dim, index in enumerate(indices): # <<<<<<<<<<<<<< + * if PyIndex_Check(index): + * slice_memviewslice( + */ + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "View.MemoryView":776 + * new_ndim += 1 + * + * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< + * return memoryview_fromslice(dst, new_ndim, + * memviewsliceobj.to_object_func, + */ + __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":777 + * + * if isinstance(memview, _memoryviewslice): + * return memoryview_fromslice(dst, new_ndim, # <<<<<<<<<<<<<< + * memviewsliceobj.to_object_func, + * memviewsliceobj.to_dtype_func, + */ + __Pyx_XDECREF(((PyObject *)__pyx_r)); + + /* "View.MemoryView":778 + * if isinstance(memview, _memoryviewslice): + * return memoryview_fromslice(dst, new_ndim, + * memviewsliceobj.to_object_func, # <<<<<<<<<<<<<< + * memviewsliceobj.to_dtype_func, + * memview.dtype_is_object) + */ + if (unlikely(!__pyx_v_memviewsliceobj)) { __Pyx_RaiseUnboundLocalError("memviewsliceobj"); __PYX_ERR(2, 778, __pyx_L1_error) } + + /* "View.MemoryView":779 + * return memoryview_fromslice(dst, new_ndim, + * memviewsliceobj.to_object_func, + * memviewsliceobj.to_dtype_func, # <<<<<<<<<<<<<< + * memview.dtype_is_object) + * else: + */ + if (unlikely(!__pyx_v_memviewsliceobj)) { __Pyx_RaiseUnboundLocalError("memviewsliceobj"); __PYX_ERR(2, 779, __pyx_L1_error) } + + /* "View.MemoryView":777 + * + * if isinstance(memview, _memoryviewslice): + * return memoryview_fromslice(dst, new_ndim, # <<<<<<<<<<<<<< + * memviewsliceobj.to_object_func, + * memviewsliceobj.to_dtype_func, + */ + __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_dst, __pyx_v_new_ndim, __pyx_v_memviewsliceobj->to_object_func, __pyx_v_memviewsliceobj->to_dtype_func, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 777, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_memoryview_type))))) __PYX_ERR(2, 777, __pyx_L1_error) + __pyx_r = ((struct __pyx_memoryview_obj *)__pyx_t_3); + __pyx_t_3 = 0; + goto __pyx_L0; + + /* "View.MemoryView":776 + * new_ndim += 1 + * + * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< + * return memoryview_fromslice(dst, new_ndim, + * memviewsliceobj.to_object_func, + */ + } + + /* "View.MemoryView":782 + * memview.dtype_is_object) + * else: + * return memoryview_fromslice(dst, new_ndim, NULL, NULL, # <<<<<<<<<<<<<< + * memview.dtype_is_object) + * + */ + /*else*/ { + __Pyx_XDECREF(((PyObject *)__pyx_r)); + + /* "View.MemoryView":783 + * else: + * return memoryview_fromslice(dst, new_ndim, NULL, NULL, + * memview.dtype_is_object) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_dst, __pyx_v_new_ndim, NULL, NULL, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 782, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + + /* "View.MemoryView":782 + * memview.dtype_is_object) + * else: + * return memoryview_fromslice(dst, new_ndim, NULL, NULL, # <<<<<<<<<<<<<< + * memview.dtype_is_object) + * + */ + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_memoryview_type))))) __PYX_ERR(2, 782, __pyx_L1_error) + __pyx_r = ((struct __pyx_memoryview_obj *)__pyx_t_3); + __pyx_t_3 = 0; + goto __pyx_L0; + } + + /* "View.MemoryView":710 + * + * @cname('__pyx_memview_slice') + * cdef memoryview memview_slice(memoryview memview, object indices): # <<<<<<<<<<<<<< + * cdef int new_ndim = 0, suboffset_dim = -1, dim + * cdef bint negative_step + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("View.MemoryView.memview_slice", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_memviewsliceobj); + __Pyx_XDECREF(__pyx_v_index); + __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":807 + * + * @cname('__pyx_memoryview_slice_memviewslice') + * cdef int slice_memviewslice( # <<<<<<<<<<<<<< + * __Pyx_memviewslice *dst, + * Py_ssize_t shape, Py_ssize_t stride, Py_ssize_t suboffset, + */ + +static int __pyx_memoryview_slice_memviewslice(__Pyx_memviewslice *__pyx_v_dst, Py_ssize_t __pyx_v_shape, Py_ssize_t __pyx_v_stride, Py_ssize_t __pyx_v_suboffset, int __pyx_v_dim, int __pyx_v_new_ndim, int *__pyx_v_suboffset_dim, Py_ssize_t __pyx_v_start, Py_ssize_t __pyx_v_stop, Py_ssize_t __pyx_v_step, int __pyx_v_have_start, int __pyx_v_have_stop, int __pyx_v_have_step, int __pyx_v_is_slice) { + Py_ssize_t __pyx_v_new_shape; + int __pyx_v_negative_step; + int __pyx_r; + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + + /* "View.MemoryView":827 + * cdef bint negative_step + * + * if not is_slice: # <<<<<<<<<<<<<< + * + * if start < 0: + */ + __pyx_t_1 = ((!(__pyx_v_is_slice != 0)) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":829 + * if not is_slice: + * + * if start < 0: # <<<<<<<<<<<<<< + * start += shape + * if not 0 <= start < shape: + */ + __pyx_t_1 = ((__pyx_v_start < 0) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":830 + * + * if start < 0: + * start += shape # <<<<<<<<<<<<<< + * if not 0 <= start < shape: + * _err_dim(IndexError, "Index out of bounds (axis %d)", dim) + */ + __pyx_v_start = (__pyx_v_start + __pyx_v_shape); + + /* "View.MemoryView":829 + * if not is_slice: + * + * if start < 0: # <<<<<<<<<<<<<< + * start += shape + * if not 0 <= start < shape: + */ + } + + /* "View.MemoryView":831 + * if start < 0: + * start += shape + * if not 0 <= start < shape: # <<<<<<<<<<<<<< + * _err_dim(IndexError, "Index out of bounds (axis %d)", dim) + * else: + */ + __pyx_t_1 = (0 <= __pyx_v_start); + if (__pyx_t_1) { + __pyx_t_1 = (__pyx_v_start < __pyx_v_shape); + } + __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":832 + * start += shape + * if not 0 <= start < shape: + * _err_dim(IndexError, "Index out of bounds (axis %d)", dim) # <<<<<<<<<<<<<< + * else: + * + */ + __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_IndexError, ((char *)"Index out of bounds (axis %d)"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(2, 832, __pyx_L1_error) + + /* "View.MemoryView":831 + * if start < 0: + * start += shape + * if not 0 <= start < shape: # <<<<<<<<<<<<<< + * _err_dim(IndexError, "Index out of bounds (axis %d)", dim) + * else: + */ + } + + /* "View.MemoryView":827 + * cdef bint negative_step + * + * if not is_slice: # <<<<<<<<<<<<<< + * + * if start < 0: + */ + goto __pyx_L3; + } + + /* "View.MemoryView":835 + * else: + * + * negative_step = have_step != 0 and step < 0 # <<<<<<<<<<<<<< + * + * if have_step and step == 0: + */ + /*else*/ { + __pyx_t_1 = ((__pyx_v_have_step != 0) != 0); + if (__pyx_t_1) { + } else { + __pyx_t_2 = __pyx_t_1; + goto __pyx_L6_bool_binop_done; + } + __pyx_t_1 = ((__pyx_v_step < 0) != 0); + __pyx_t_2 = __pyx_t_1; + __pyx_L6_bool_binop_done:; + __pyx_v_negative_step = __pyx_t_2; + + /* "View.MemoryView":837 + * negative_step = have_step != 0 and step < 0 + * + * if have_step and step == 0: # <<<<<<<<<<<<<< + * _err_dim(ValueError, "Step may not be zero (axis %d)", dim) + * + */ + __pyx_t_1 = (__pyx_v_have_step != 0); + if (__pyx_t_1) { + } else { + __pyx_t_2 = __pyx_t_1; + goto __pyx_L9_bool_binop_done; + } + __pyx_t_1 = ((__pyx_v_step == 0) != 0); + __pyx_t_2 = __pyx_t_1; + __pyx_L9_bool_binop_done:; + if (__pyx_t_2) { + + /* "View.MemoryView":838 + * + * if have_step and step == 0: + * _err_dim(ValueError, "Step may not be zero (axis %d)", dim) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_ValueError, ((char *)"Step may not be zero (axis %d)"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(2, 838, __pyx_L1_error) + + /* "View.MemoryView":837 + * negative_step = have_step != 0 and step < 0 + * + * if have_step and step == 0: # <<<<<<<<<<<<<< + * _err_dim(ValueError, "Step may not be zero (axis %d)", dim) + * + */ + } + + /* "View.MemoryView":841 + * + * + * if have_start: # <<<<<<<<<<<<<< + * if start < 0: + * start += shape + */ + __pyx_t_2 = (__pyx_v_have_start != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":842 + * + * if have_start: + * if start < 0: # <<<<<<<<<<<<<< + * start += shape + * if start < 0: + */ + __pyx_t_2 = ((__pyx_v_start < 0) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":843 + * if have_start: + * if start < 0: + * start += shape # <<<<<<<<<<<<<< + * if start < 0: + * start = 0 + */ + __pyx_v_start = (__pyx_v_start + __pyx_v_shape); + + /* "View.MemoryView":844 + * if start < 0: + * start += shape + * if start < 0: # <<<<<<<<<<<<<< + * start = 0 + * elif start >= shape: + */ + __pyx_t_2 = ((__pyx_v_start < 0) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":845 + * start += shape + * if start < 0: + * start = 0 # <<<<<<<<<<<<<< + * elif start >= shape: + * if negative_step: + */ + __pyx_v_start = 0; + + /* "View.MemoryView":844 + * if start < 0: + * start += shape + * if start < 0: # <<<<<<<<<<<<<< + * start = 0 + * elif start >= shape: + */ + } + + /* "View.MemoryView":842 + * + * if have_start: + * if start < 0: # <<<<<<<<<<<<<< + * start += shape + * if start < 0: + */ + goto __pyx_L12; + } + + /* "View.MemoryView":846 + * if start < 0: + * start = 0 + * elif start >= shape: # <<<<<<<<<<<<<< + * if negative_step: + * start = shape - 1 + */ + __pyx_t_2 = ((__pyx_v_start >= __pyx_v_shape) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":847 + * start = 0 + * elif start >= shape: + * if negative_step: # <<<<<<<<<<<<<< + * start = shape - 1 + * else: + */ + __pyx_t_2 = (__pyx_v_negative_step != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":848 + * elif start >= shape: + * if negative_step: + * start = shape - 1 # <<<<<<<<<<<<<< + * else: + * start = shape + */ + __pyx_v_start = (__pyx_v_shape - 1); + + /* "View.MemoryView":847 + * start = 0 + * elif start >= shape: + * if negative_step: # <<<<<<<<<<<<<< + * start = shape - 1 + * else: + */ + goto __pyx_L14; + } + + /* "View.MemoryView":850 + * start = shape - 1 + * else: + * start = shape # <<<<<<<<<<<<<< + * else: + * if negative_step: + */ + /*else*/ { + __pyx_v_start = __pyx_v_shape; + } + __pyx_L14:; + + /* "View.MemoryView":846 + * if start < 0: + * start = 0 + * elif start >= shape: # <<<<<<<<<<<<<< + * if negative_step: + * start = shape - 1 + */ + } + __pyx_L12:; + + /* "View.MemoryView":841 + * + * + * if have_start: # <<<<<<<<<<<<<< + * if start < 0: + * start += shape + */ + goto __pyx_L11; + } + + /* "View.MemoryView":852 + * start = shape + * else: + * if negative_step: # <<<<<<<<<<<<<< + * start = shape - 1 + * else: + */ + /*else*/ { + __pyx_t_2 = (__pyx_v_negative_step != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":853 + * else: + * if negative_step: + * start = shape - 1 # <<<<<<<<<<<<<< + * else: + * start = 0 + */ + __pyx_v_start = (__pyx_v_shape - 1); + + /* "View.MemoryView":852 + * start = shape + * else: + * if negative_step: # <<<<<<<<<<<<<< + * start = shape - 1 + * else: + */ + goto __pyx_L15; + } + + /* "View.MemoryView":855 + * start = shape - 1 + * else: + * start = 0 # <<<<<<<<<<<<<< + * + * if have_stop: + */ + /*else*/ { + __pyx_v_start = 0; + } + __pyx_L15:; + } + __pyx_L11:; + + /* "View.MemoryView":857 + * start = 0 + * + * if have_stop: # <<<<<<<<<<<<<< + * if stop < 0: + * stop += shape + */ + __pyx_t_2 = (__pyx_v_have_stop != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":858 + * + * if have_stop: + * if stop < 0: # <<<<<<<<<<<<<< + * stop += shape + * if stop < 0: + */ + __pyx_t_2 = ((__pyx_v_stop < 0) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":859 + * if have_stop: + * if stop < 0: + * stop += shape # <<<<<<<<<<<<<< + * if stop < 0: + * stop = 0 + */ + __pyx_v_stop = (__pyx_v_stop + __pyx_v_shape); + + /* "View.MemoryView":860 + * if stop < 0: + * stop += shape + * if stop < 0: # <<<<<<<<<<<<<< + * stop = 0 + * elif stop > shape: + */ + __pyx_t_2 = ((__pyx_v_stop < 0) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":861 + * stop += shape + * if stop < 0: + * stop = 0 # <<<<<<<<<<<<<< + * elif stop > shape: + * stop = shape + */ + __pyx_v_stop = 0; + + /* "View.MemoryView":860 + * if stop < 0: + * stop += shape + * if stop < 0: # <<<<<<<<<<<<<< + * stop = 0 + * elif stop > shape: + */ + } + + /* "View.MemoryView":858 + * + * if have_stop: + * if stop < 0: # <<<<<<<<<<<<<< + * stop += shape + * if stop < 0: + */ + goto __pyx_L17; + } + + /* "View.MemoryView":862 + * if stop < 0: + * stop = 0 + * elif stop > shape: # <<<<<<<<<<<<<< + * stop = shape + * else: + */ + __pyx_t_2 = ((__pyx_v_stop > __pyx_v_shape) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":863 + * stop = 0 + * elif stop > shape: + * stop = shape # <<<<<<<<<<<<<< + * else: + * if negative_step: + */ + __pyx_v_stop = __pyx_v_shape; + + /* "View.MemoryView":862 + * if stop < 0: + * stop = 0 + * elif stop > shape: # <<<<<<<<<<<<<< + * stop = shape + * else: + */ + } + __pyx_L17:; + + /* "View.MemoryView":857 + * start = 0 + * + * if have_stop: # <<<<<<<<<<<<<< + * if stop < 0: + * stop += shape + */ + goto __pyx_L16; + } + + /* "View.MemoryView":865 + * stop = shape + * else: + * if negative_step: # <<<<<<<<<<<<<< + * stop = -1 + * else: + */ + /*else*/ { + __pyx_t_2 = (__pyx_v_negative_step != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":866 + * else: + * if negative_step: + * stop = -1 # <<<<<<<<<<<<<< + * else: + * stop = shape + */ + __pyx_v_stop = -1L; + + /* "View.MemoryView":865 + * stop = shape + * else: + * if negative_step: # <<<<<<<<<<<<<< + * stop = -1 + * else: + */ + goto __pyx_L19; + } + + /* "View.MemoryView":868 + * stop = -1 + * else: + * stop = shape # <<<<<<<<<<<<<< + * + * if not have_step: + */ + /*else*/ { + __pyx_v_stop = __pyx_v_shape; + } + __pyx_L19:; + } + __pyx_L16:; + + /* "View.MemoryView":870 + * stop = shape + * + * if not have_step: # <<<<<<<<<<<<<< + * step = 1 + * + */ + __pyx_t_2 = ((!(__pyx_v_have_step != 0)) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":871 + * + * if not have_step: + * step = 1 # <<<<<<<<<<<<<< + * + * + */ + __pyx_v_step = 1; + + /* "View.MemoryView":870 + * stop = shape + * + * if not have_step: # <<<<<<<<<<<<<< + * step = 1 + * + */ + } + + /* "View.MemoryView":875 + * + * with cython.cdivision(True): + * new_shape = (stop - start) // step # <<<<<<<<<<<<<< + * + * if (stop - start) - step * new_shape: + */ + __pyx_v_new_shape = ((__pyx_v_stop - __pyx_v_start) / __pyx_v_step); + + /* "View.MemoryView":877 + * new_shape = (stop - start) // step + * + * if (stop - start) - step * new_shape: # <<<<<<<<<<<<<< + * new_shape += 1 + * + */ + __pyx_t_2 = (((__pyx_v_stop - __pyx_v_start) - (__pyx_v_step * __pyx_v_new_shape)) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":878 + * + * if (stop - start) - step * new_shape: + * new_shape += 1 # <<<<<<<<<<<<<< + * + * if new_shape < 0: + */ + __pyx_v_new_shape = (__pyx_v_new_shape + 1); + + /* "View.MemoryView":877 + * new_shape = (stop - start) // step + * + * if (stop - start) - step * new_shape: # <<<<<<<<<<<<<< + * new_shape += 1 + * + */ + } + + /* "View.MemoryView":880 + * new_shape += 1 + * + * if new_shape < 0: # <<<<<<<<<<<<<< + * new_shape = 0 + * + */ + __pyx_t_2 = ((__pyx_v_new_shape < 0) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":881 + * + * if new_shape < 0: + * new_shape = 0 # <<<<<<<<<<<<<< + * + * + */ + __pyx_v_new_shape = 0; + + /* "View.MemoryView":880 + * new_shape += 1 + * + * if new_shape < 0: # <<<<<<<<<<<<<< + * new_shape = 0 + * + */ + } + + /* "View.MemoryView":884 + * + * + * dst.strides[new_ndim] = stride * step # <<<<<<<<<<<<<< + * dst.shape[new_ndim] = new_shape + * dst.suboffsets[new_ndim] = suboffset + */ + (__pyx_v_dst->strides[__pyx_v_new_ndim]) = (__pyx_v_stride * __pyx_v_step); + + /* "View.MemoryView":885 + * + * dst.strides[new_ndim] = stride * step + * dst.shape[new_ndim] = new_shape # <<<<<<<<<<<<<< + * dst.suboffsets[new_ndim] = suboffset + * + */ + (__pyx_v_dst->shape[__pyx_v_new_ndim]) = __pyx_v_new_shape; + + /* "View.MemoryView":886 + * dst.strides[new_ndim] = stride * step + * dst.shape[new_ndim] = new_shape + * dst.suboffsets[new_ndim] = suboffset # <<<<<<<<<<<<<< + * + * + */ + (__pyx_v_dst->suboffsets[__pyx_v_new_ndim]) = __pyx_v_suboffset; + } + __pyx_L3:; + + /* "View.MemoryView":889 + * + * + * if suboffset_dim[0] < 0: # <<<<<<<<<<<<<< + * dst.data += start * stride + * else: + */ + __pyx_t_2 = (((__pyx_v_suboffset_dim[0]) < 0) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":890 + * + * if suboffset_dim[0] < 0: + * dst.data += start * stride # <<<<<<<<<<<<<< + * else: + * dst.suboffsets[suboffset_dim[0]] += start * stride + */ + __pyx_v_dst->data = (__pyx_v_dst->data + (__pyx_v_start * __pyx_v_stride)); + + /* "View.MemoryView":889 + * + * + * if suboffset_dim[0] < 0: # <<<<<<<<<<<<<< + * dst.data += start * stride + * else: + */ + goto __pyx_L23; + } + + /* "View.MemoryView":892 + * dst.data += start * stride + * else: + * dst.suboffsets[suboffset_dim[0]] += start * stride # <<<<<<<<<<<<<< + * + * if suboffset >= 0: + */ + /*else*/ { + __pyx_t_3 = (__pyx_v_suboffset_dim[0]); + (__pyx_v_dst->suboffsets[__pyx_t_3]) = ((__pyx_v_dst->suboffsets[__pyx_t_3]) + (__pyx_v_start * __pyx_v_stride)); + } + __pyx_L23:; + + /* "View.MemoryView":894 + * dst.suboffsets[suboffset_dim[0]] += start * stride + * + * if suboffset >= 0: # <<<<<<<<<<<<<< + * if not is_slice: + * if new_ndim == 0: + */ + __pyx_t_2 = ((__pyx_v_suboffset >= 0) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":895 + * + * if suboffset >= 0: + * if not is_slice: # <<<<<<<<<<<<<< + * if new_ndim == 0: + * dst.data = ( dst.data)[0] + suboffset + */ + __pyx_t_2 = ((!(__pyx_v_is_slice != 0)) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":896 + * if suboffset >= 0: + * if not is_slice: + * if new_ndim == 0: # <<<<<<<<<<<<<< + * dst.data = ( dst.data)[0] + suboffset + * else: + */ + __pyx_t_2 = ((__pyx_v_new_ndim == 0) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":897 + * if not is_slice: + * if new_ndim == 0: + * dst.data = ( dst.data)[0] + suboffset # <<<<<<<<<<<<<< + * else: + * _err_dim(IndexError, "All dimensions preceding dimension %d " + */ + __pyx_v_dst->data = ((((char **)__pyx_v_dst->data)[0]) + __pyx_v_suboffset); + + /* "View.MemoryView":896 + * if suboffset >= 0: + * if not is_slice: + * if new_ndim == 0: # <<<<<<<<<<<<<< + * dst.data = ( dst.data)[0] + suboffset + * else: + */ + goto __pyx_L26; + } + + /* "View.MemoryView":899 + * dst.data = ( dst.data)[0] + suboffset + * else: + * _err_dim(IndexError, "All dimensions preceding dimension %d " # <<<<<<<<<<<<<< + * "must be indexed and not sliced", dim) + * else: + */ + /*else*/ { + + /* "View.MemoryView":900 + * else: + * _err_dim(IndexError, "All dimensions preceding dimension %d " + * "must be indexed and not sliced", dim) # <<<<<<<<<<<<<< + * else: + * suboffset_dim[0] = new_ndim + */ + __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_IndexError, ((char *)"All dimensions preceding dimension %d must be indexed and not sliced"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(2, 899, __pyx_L1_error) + } + __pyx_L26:; + + /* "View.MemoryView":895 + * + * if suboffset >= 0: + * if not is_slice: # <<<<<<<<<<<<<< + * if new_ndim == 0: + * dst.data = ( dst.data)[0] + suboffset + */ + goto __pyx_L25; + } + + /* "View.MemoryView":902 + * "must be indexed and not sliced", dim) + * else: + * suboffset_dim[0] = new_ndim # <<<<<<<<<<<<<< + * + * return 0 + */ + /*else*/ { + (__pyx_v_suboffset_dim[0]) = __pyx_v_new_ndim; + } + __pyx_L25:; + + /* "View.MemoryView":894 + * dst.suboffsets[suboffset_dim[0]] += start * stride + * + * if suboffset >= 0: # <<<<<<<<<<<<<< + * if not is_slice: + * if new_ndim == 0: + */ + } + + /* "View.MemoryView":904 + * suboffset_dim[0] = new_ndim + * + * return 0 # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = 0; + goto __pyx_L0; + + /* "View.MemoryView":807 + * + * @cname('__pyx_memoryview_slice_memviewslice') + * cdef int slice_memviewslice( # <<<<<<<<<<<<<< + * __Pyx_memviewslice *dst, + * Py_ssize_t shape, Py_ssize_t stride, Py_ssize_t suboffset, + */ + + /* function exit code */ + __pyx_L1_error:; + { + #ifdef WITH_THREAD + PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); + #endif + __Pyx_AddTraceback("View.MemoryView.slice_memviewslice", __pyx_clineno, __pyx_lineno, __pyx_filename); + #ifdef WITH_THREAD + __Pyx_PyGILState_Release(__pyx_gilstate_save); + #endif + } + __pyx_r = -1; + __pyx_L0:; + return __pyx_r; +} + +/* "View.MemoryView":910 + * + * @cname('__pyx_pybuffer_index') + * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index, # <<<<<<<<<<<<<< + * Py_ssize_t dim) except NULL: + * cdef Py_ssize_t shape, stride, suboffset = -1 + */ + +static char *__pyx_pybuffer_index(Py_buffer *__pyx_v_view, char *__pyx_v_bufp, Py_ssize_t __pyx_v_index, Py_ssize_t __pyx_v_dim) { + Py_ssize_t __pyx_v_shape; + Py_ssize_t __pyx_v_stride; + Py_ssize_t __pyx_v_suboffset; + Py_ssize_t __pyx_v_itemsize; + char *__pyx_v_resultp; + char *__pyx_r; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("pybuffer_index", 0); + + /* "View.MemoryView":912 + * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index, + * Py_ssize_t dim) except NULL: + * cdef Py_ssize_t shape, stride, suboffset = -1 # <<<<<<<<<<<<<< + * cdef Py_ssize_t itemsize = view.itemsize + * cdef char *resultp + */ + __pyx_v_suboffset = -1L; + + /* "View.MemoryView":913 + * Py_ssize_t dim) except NULL: + * cdef Py_ssize_t shape, stride, suboffset = -1 + * cdef Py_ssize_t itemsize = view.itemsize # <<<<<<<<<<<<<< + * cdef char *resultp + * + */ + __pyx_t_1 = __pyx_v_view->itemsize; + __pyx_v_itemsize = __pyx_t_1; + + /* "View.MemoryView":916 + * cdef char *resultp + * + * if view.ndim == 0: # <<<<<<<<<<<<<< + * shape = view.len / itemsize + * stride = itemsize + */ + __pyx_t_2 = ((__pyx_v_view->ndim == 0) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":917 + * + * if view.ndim == 0: + * shape = view.len / itemsize # <<<<<<<<<<<<<< + * stride = itemsize + * else: + */ + if (unlikely(__pyx_v_itemsize == 0)) { + PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero"); + __PYX_ERR(2, 917, __pyx_L1_error) + } + else if (sizeof(Py_ssize_t) == sizeof(long) && (!(((Py_ssize_t)-1) > 0)) && unlikely(__pyx_v_itemsize == (Py_ssize_t)-1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_view->len))) { + PyErr_SetString(PyExc_OverflowError, "value too large to perform division"); + __PYX_ERR(2, 917, __pyx_L1_error) + } + __pyx_v_shape = __Pyx_div_Py_ssize_t(__pyx_v_view->len, __pyx_v_itemsize); + + /* "View.MemoryView":918 + * if view.ndim == 0: + * shape = view.len / itemsize + * stride = itemsize # <<<<<<<<<<<<<< + * else: + * shape = view.shape[dim] + */ + __pyx_v_stride = __pyx_v_itemsize; + + /* "View.MemoryView":916 + * cdef char *resultp + * + * if view.ndim == 0: # <<<<<<<<<<<<<< + * shape = view.len / itemsize + * stride = itemsize + */ + goto __pyx_L3; + } + + /* "View.MemoryView":920 + * stride = itemsize + * else: + * shape = view.shape[dim] # <<<<<<<<<<<<<< + * stride = view.strides[dim] + * if view.suboffsets != NULL: + */ + /*else*/ { + __pyx_v_shape = (__pyx_v_view->shape[__pyx_v_dim]); + + /* "View.MemoryView":921 + * else: + * shape = view.shape[dim] + * stride = view.strides[dim] # <<<<<<<<<<<<<< + * if view.suboffsets != NULL: + * suboffset = view.suboffsets[dim] + */ + __pyx_v_stride = (__pyx_v_view->strides[__pyx_v_dim]); + + /* "View.MemoryView":922 + * shape = view.shape[dim] + * stride = view.strides[dim] + * if view.suboffsets != NULL: # <<<<<<<<<<<<<< + * suboffset = view.suboffsets[dim] + * + */ + __pyx_t_2 = ((__pyx_v_view->suboffsets != NULL) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":923 + * stride = view.strides[dim] + * if view.suboffsets != NULL: + * suboffset = view.suboffsets[dim] # <<<<<<<<<<<<<< + * + * if index < 0: + */ + __pyx_v_suboffset = (__pyx_v_view->suboffsets[__pyx_v_dim]); + + /* "View.MemoryView":922 + * shape = view.shape[dim] + * stride = view.strides[dim] + * if view.suboffsets != NULL: # <<<<<<<<<<<<<< + * suboffset = view.suboffsets[dim] + * + */ + } + } + __pyx_L3:; + + /* "View.MemoryView":925 + * suboffset = view.suboffsets[dim] + * + * if index < 0: # <<<<<<<<<<<<<< + * index += view.shape[dim] + * if index < 0: + */ + __pyx_t_2 = ((__pyx_v_index < 0) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":926 + * + * if index < 0: + * index += view.shape[dim] # <<<<<<<<<<<<<< + * if index < 0: + * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) + */ + __pyx_v_index = (__pyx_v_index + (__pyx_v_view->shape[__pyx_v_dim])); + + /* "View.MemoryView":927 + * if index < 0: + * index += view.shape[dim] + * if index < 0: # <<<<<<<<<<<<<< + * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) + * + */ + __pyx_t_2 = ((__pyx_v_index < 0) != 0); + if (unlikely(__pyx_t_2)) { + + /* "View.MemoryView":928 + * index += view.shape[dim] + * if index < 0: + * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) # <<<<<<<<<<<<<< + * + * if index >= shape: + */ + __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 928, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Out_of_bounds_on_buffer_access_a, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 928, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 928, __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(2, 928, __pyx_L1_error) + + /* "View.MemoryView":927 + * if index < 0: + * index += view.shape[dim] + * if index < 0: # <<<<<<<<<<<<<< + * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) + * + */ + } + + /* "View.MemoryView":925 + * suboffset = view.suboffsets[dim] + * + * if index < 0: # <<<<<<<<<<<<<< + * index += view.shape[dim] + * if index < 0: + */ + } + + /* "View.MemoryView":930 + * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) + * + * if index >= shape: # <<<<<<<<<<<<<< + * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) + * + */ + __pyx_t_2 = ((__pyx_v_index >= __pyx_v_shape) != 0); + if (unlikely(__pyx_t_2)) { + + /* "View.MemoryView":931 + * + * if index >= shape: + * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) # <<<<<<<<<<<<<< + * + * resultp = bufp + index * stride + */ + __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 931, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Out_of_bounds_on_buffer_access_a, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 931, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 931, __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(2, 931, __pyx_L1_error) + + /* "View.MemoryView":930 + * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) + * + * if index >= shape: # <<<<<<<<<<<<<< + * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) + * + */ + } + + /* "View.MemoryView":933 + * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) + * + * resultp = bufp + index * stride # <<<<<<<<<<<<<< + * if suboffset >= 0: + * resultp = ( resultp)[0] + suboffset + */ + __pyx_v_resultp = (__pyx_v_bufp + (__pyx_v_index * __pyx_v_stride)); + + /* "View.MemoryView":934 + * + * resultp = bufp + index * stride + * if suboffset >= 0: # <<<<<<<<<<<<<< + * resultp = ( resultp)[0] + suboffset + * + */ + __pyx_t_2 = ((__pyx_v_suboffset >= 0) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":935 + * resultp = bufp + index * stride + * if suboffset >= 0: + * resultp = ( resultp)[0] + suboffset # <<<<<<<<<<<<<< + * + * return resultp + */ + __pyx_v_resultp = ((((char **)__pyx_v_resultp)[0]) + __pyx_v_suboffset); + + /* "View.MemoryView":934 + * + * resultp = bufp + index * stride + * if suboffset >= 0: # <<<<<<<<<<<<<< + * resultp = ( resultp)[0] + suboffset + * + */ + } + + /* "View.MemoryView":937 + * resultp = ( resultp)[0] + suboffset + * + * return resultp # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_resultp; + goto __pyx_L0; + + /* "View.MemoryView":910 + * + * @cname('__pyx_pybuffer_index') + * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index, # <<<<<<<<<<<<<< + * Py_ssize_t dim) except NULL: + * cdef Py_ssize_t shape, stride, suboffset = -1 + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("View.MemoryView.pybuffer_index", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":943 + * + * @cname('__pyx_memslice_transpose') + * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0: # <<<<<<<<<<<<<< + * cdef int ndim = memslice.memview.view.ndim + * + */ + +static int __pyx_memslice_transpose(__Pyx_memviewslice *__pyx_v_memslice) { + int __pyx_v_ndim; + Py_ssize_t *__pyx_v_shape; + Py_ssize_t *__pyx_v_strides; + int __pyx_v_i; + int __pyx_v_j; + int __pyx_r; + int __pyx_t_1; + Py_ssize_t *__pyx_t_2; + long __pyx_t_3; + long __pyx_t_4; + Py_ssize_t __pyx_t_5; + Py_ssize_t __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + int __pyx_t_9; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + + /* "View.MemoryView":944 + * @cname('__pyx_memslice_transpose') + * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0: + * cdef int ndim = memslice.memview.view.ndim # <<<<<<<<<<<<<< + * + * cdef Py_ssize_t *shape = memslice.shape + */ + __pyx_t_1 = __pyx_v_memslice->memview->view.ndim; + __pyx_v_ndim = __pyx_t_1; + + /* "View.MemoryView":946 + * cdef int ndim = memslice.memview.view.ndim + * + * cdef Py_ssize_t *shape = memslice.shape # <<<<<<<<<<<<<< + * cdef Py_ssize_t *strides = memslice.strides + * + */ + __pyx_t_2 = __pyx_v_memslice->shape; + __pyx_v_shape = __pyx_t_2; + + /* "View.MemoryView":947 + * + * cdef Py_ssize_t *shape = memslice.shape + * cdef Py_ssize_t *strides = memslice.strides # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_2 = __pyx_v_memslice->strides; + __pyx_v_strides = __pyx_t_2; + + /* "View.MemoryView":951 + * + * cdef int i, j + * for i in range(ndim / 2): # <<<<<<<<<<<<<< + * j = ndim - 1 - i + * strides[i], strides[j] = strides[j], strides[i] + */ + __pyx_t_3 = __Pyx_div_long(__pyx_v_ndim, 2); + __pyx_t_4 = __pyx_t_3; + for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_4; __pyx_t_1+=1) { + __pyx_v_i = __pyx_t_1; + + /* "View.MemoryView":952 + * cdef int i, j + * for i in range(ndim / 2): + * j = ndim - 1 - i # <<<<<<<<<<<<<< + * strides[i], strides[j] = strides[j], strides[i] + * shape[i], shape[j] = shape[j], shape[i] + */ + __pyx_v_j = ((__pyx_v_ndim - 1) - __pyx_v_i); + + /* "View.MemoryView":953 + * for i in range(ndim / 2): + * j = ndim - 1 - i + * strides[i], strides[j] = strides[j], strides[i] # <<<<<<<<<<<<<< + * shape[i], shape[j] = shape[j], shape[i] + * + */ + __pyx_t_5 = (__pyx_v_strides[__pyx_v_j]); + __pyx_t_6 = (__pyx_v_strides[__pyx_v_i]); + (__pyx_v_strides[__pyx_v_i]) = __pyx_t_5; + (__pyx_v_strides[__pyx_v_j]) = __pyx_t_6; + + /* "View.MemoryView":954 + * j = ndim - 1 - i + * strides[i], strides[j] = strides[j], strides[i] + * shape[i], shape[j] = shape[j], shape[i] # <<<<<<<<<<<<<< + * + * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0: + */ + __pyx_t_6 = (__pyx_v_shape[__pyx_v_j]); + __pyx_t_5 = (__pyx_v_shape[__pyx_v_i]); + (__pyx_v_shape[__pyx_v_i]) = __pyx_t_6; + (__pyx_v_shape[__pyx_v_j]) = __pyx_t_5; + + /* "View.MemoryView":956 + * shape[i], shape[j] = shape[j], shape[i] + * + * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0: # <<<<<<<<<<<<<< + * _err(ValueError, "Cannot transpose memoryview with indirect dimensions") + * + */ + __pyx_t_8 = (((__pyx_v_memslice->suboffsets[__pyx_v_i]) >= 0) != 0); + if (!__pyx_t_8) { + } else { + __pyx_t_7 = __pyx_t_8; + goto __pyx_L6_bool_binop_done; + } + __pyx_t_8 = (((__pyx_v_memslice->suboffsets[__pyx_v_j]) >= 0) != 0); + __pyx_t_7 = __pyx_t_8; + __pyx_L6_bool_binop_done:; + if (__pyx_t_7) { + + /* "View.MemoryView":957 + * + * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0: + * _err(ValueError, "Cannot transpose memoryview with indirect dimensions") # <<<<<<<<<<<<<< + * + * return 1 + */ + __pyx_t_9 = __pyx_memoryview_err(__pyx_builtin_ValueError, ((char *)"Cannot transpose memoryview with indirect dimensions")); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(2, 957, __pyx_L1_error) + + /* "View.MemoryView":956 + * shape[i], shape[j] = shape[j], shape[i] + * + * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0: # <<<<<<<<<<<<<< + * _err(ValueError, "Cannot transpose memoryview with indirect dimensions") + * + */ + } + } + + /* "View.MemoryView":959 + * _err(ValueError, "Cannot transpose memoryview with indirect dimensions") + * + * return 1 # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = 1; + goto __pyx_L0; + + /* "View.MemoryView":943 + * + * @cname('__pyx_memslice_transpose') + * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0: # <<<<<<<<<<<<<< + * cdef int ndim = memslice.memview.view.ndim + * + */ + + /* function exit code */ + __pyx_L1_error:; + { + #ifdef WITH_THREAD + PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); + #endif + __Pyx_AddTraceback("View.MemoryView.transpose_memslice", __pyx_clineno, __pyx_lineno, __pyx_filename); + #ifdef WITH_THREAD + __Pyx_PyGILState_Release(__pyx_gilstate_save); + #endif + } + __pyx_r = 0; + __pyx_L0:; + return __pyx_r; +} + +/* "View.MemoryView":976 + * cdef int (*to_dtype_func)(char *, object) except 0 + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) + * + */ + +/* Python wrapper */ +static void __pyx_memoryviewslice___dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_memoryviewslice___dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_memoryviewslice___pyx_pf_15View_dot_MemoryView_16_memoryviewslice___dealloc__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); +} + +static void __pyx_memoryviewslice___pyx_pf_15View_dot_MemoryView_16_memoryviewslice___dealloc__(struct __pyx_memoryviewslice_obj *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "View.MemoryView":977 + * + * def __dealloc__(self): + * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) # <<<<<<<<<<<<<< + * + * cdef convert_item_to_object(self, char *itemp): + */ + __PYX_XDEC_MEMVIEW((&__pyx_v_self->from_slice), 1); + + /* "View.MemoryView":976 + * cdef int (*to_dtype_func)(char *, object) except 0 + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) + * + */ + + /* function exit code */ + __Pyx_RefNannyFinishContext(); +} + +/* "View.MemoryView":979 + * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) + * + * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<< + * if self.to_object_func != NULL: + * return self.to_object_func(itemp) + */ + +static PyObject *__pyx_memoryviewslice_convert_item_to_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("convert_item_to_object", 0); + + /* "View.MemoryView":980 + * + * cdef convert_item_to_object(self, char *itemp): + * if self.to_object_func != NULL: # <<<<<<<<<<<<<< + * return self.to_object_func(itemp) + * else: + */ + __pyx_t_1 = ((__pyx_v_self->to_object_func != NULL) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":981 + * cdef convert_item_to_object(self, char *itemp): + * if self.to_object_func != NULL: + * return self.to_object_func(itemp) # <<<<<<<<<<<<<< + * else: + * return memoryview.convert_item_to_object(self, itemp) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __pyx_v_self->to_object_func(__pyx_v_itemp); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 981, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "View.MemoryView":980 + * + * cdef convert_item_to_object(self, char *itemp): + * if self.to_object_func != NULL: # <<<<<<<<<<<<<< + * return self.to_object_func(itemp) + * else: + */ + } + + /* "View.MemoryView":983 + * return self.to_object_func(itemp) + * else: + * return memoryview.convert_item_to_object(self, itemp) # <<<<<<<<<<<<<< + * + * cdef assign_item_from_object(self, char *itemp, object value): + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __pyx_memoryview_convert_item_to_object(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_itemp); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 983, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + } + + /* "View.MemoryView":979 + * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) + * + * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<< + * if self.to_object_func != NULL: + * return self.to_object_func(itemp) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("View.MemoryView._memoryviewslice.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":985 + * return memoryview.convert_item_to_object(self, itemp) + * + * cdef assign_item_from_object(self, char *itemp, object value): # <<<<<<<<<<<<<< + * if self.to_dtype_func != NULL: + * self.to_dtype_func(itemp, value) + */ + +static PyObject *__pyx_memoryviewslice_assign_item_from_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp, PyObject *__pyx_v_value) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("assign_item_from_object", 0); + + /* "View.MemoryView":986 + * + * cdef assign_item_from_object(self, char *itemp, object value): + * if self.to_dtype_func != NULL: # <<<<<<<<<<<<<< + * self.to_dtype_func(itemp, value) + * else: + */ + __pyx_t_1 = ((__pyx_v_self->to_dtype_func != NULL) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":987 + * cdef assign_item_from_object(self, char *itemp, object value): + * if self.to_dtype_func != NULL: + * self.to_dtype_func(itemp, value) # <<<<<<<<<<<<<< + * else: + * memoryview.assign_item_from_object(self, itemp, value) + */ + __pyx_t_2 = __pyx_v_self->to_dtype_func(__pyx_v_itemp, __pyx_v_value); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(2, 987, __pyx_L1_error) + + /* "View.MemoryView":986 + * + * cdef assign_item_from_object(self, char *itemp, object value): + * if self.to_dtype_func != NULL: # <<<<<<<<<<<<<< + * self.to_dtype_func(itemp, value) + * else: + */ + goto __pyx_L3; + } + + /* "View.MemoryView":989 + * self.to_dtype_func(itemp, value) + * else: + * memoryview.assign_item_from_object(self, itemp, value) # <<<<<<<<<<<<<< + * + * @property + */ + /*else*/ { + __pyx_t_3 = __pyx_memoryview_assign_item_from_object(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_itemp, __pyx_v_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 989, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __pyx_L3:; + + /* "View.MemoryView":985 + * return memoryview.convert_item_to_object(self, itemp) + * + * cdef assign_item_from_object(self, char *itemp, object value): # <<<<<<<<<<<<<< + * if self.to_dtype_func != NULL: + * self.to_dtype_func(itemp, value) + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("View.MemoryView._memoryviewslice.assign_item_from_object", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":992 + * + * @property + * def base(self): # <<<<<<<<<<<<<< + * return self.from_object + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15View_dot_MemoryView_16_memoryviewslice_4base_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_15View_dot_MemoryView_16_memoryviewslice_4base_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_15View_dot_MemoryView_16_memoryviewslice_4base___get__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15View_dot_MemoryView_16_memoryviewslice_4base___get__(struct __pyx_memoryviewslice_obj *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + + /* "View.MemoryView":993 + * @property + * def base(self): + * return self.from_object # <<<<<<<<<<<<<< + * + * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->from_object); + __pyx_r = __pyx_v_self->from_object; + goto __pyx_L0; + + /* "View.MemoryView":992 + * + * @property + * def base(self): # <<<<<<<<<<<<<< + * return self.from_object + * + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(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___pyx_memoryviewslice_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw___pyx_memoryviewslice_1__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___pyx_memoryviewslice___reduce_cython__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf___pyx_memoryviewslice___reduce_cython__(CYTHON_UNUSED struct __pyx_memoryviewslice_obj *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __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__21, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 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(2, 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("View.MemoryView._memoryviewslice.__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___pyx_memoryviewslice_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw___pyx_memoryviewslice_3__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___pyx_memoryviewslice_2__setstate_cython__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf___pyx_memoryviewslice_2__setstate_cython__(CYTHON_UNUSED struct __pyx_memoryviewslice_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __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__22, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 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(2, 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("View.MemoryView._memoryviewslice.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":999 + * + * @cname('__pyx_memoryview_fromslice') + * cdef memoryview_fromslice(__Pyx_memviewslice memviewslice, # <<<<<<<<<<<<<< + * int ndim, + * object (*to_object_func)(char *), + */ + +static PyObject *__pyx_memoryview_fromslice(__Pyx_memviewslice __pyx_v_memviewslice, int __pyx_v_ndim, PyObject *(*__pyx_v_to_object_func)(char *), int (*__pyx_v_to_dtype_func)(char *, PyObject *), int __pyx_v_dtype_is_object) { + struct __pyx_memoryviewslice_obj *__pyx_v_result = 0; + Py_ssize_t __pyx_v_suboffset; + PyObject *__pyx_v_length = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_TypeInfo *__pyx_t_4; + Py_buffer __pyx_t_5; + Py_ssize_t *__pyx_t_6; + Py_ssize_t *__pyx_t_7; + Py_ssize_t *__pyx_t_8; + Py_ssize_t __pyx_t_9; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("memoryview_fromslice", 0); + + /* "View.MemoryView":1007 + * cdef _memoryviewslice result + * + * if memviewslice.memview == Py_None: # <<<<<<<<<<<<<< + * return None + * + */ + __pyx_t_1 = ((((PyObject *)__pyx_v_memviewslice.memview) == Py_None) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":1008 + * + * if memviewslice.memview == Py_None: + * return None # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "View.MemoryView":1007 + * cdef _memoryviewslice result + * + * if memviewslice.memview == Py_None: # <<<<<<<<<<<<<< + * return None + * + */ + } + + /* "View.MemoryView":1013 + * + * + * result = _memoryviewslice(None, 0, dtype_is_object) # <<<<<<<<<<<<<< + * + * result.from_slice = memviewslice + */ + __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_dtype_is_object); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1013, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 1013, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_3, 0, Py_None); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryviewslice_type), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1013, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_result = ((struct __pyx_memoryviewslice_obj *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "View.MemoryView":1015 + * result = _memoryviewslice(None, 0, dtype_is_object) + * + * result.from_slice = memviewslice # <<<<<<<<<<<<<< + * __PYX_INC_MEMVIEW(&memviewslice, 1) + * + */ + __pyx_v_result->from_slice = __pyx_v_memviewslice; + + /* "View.MemoryView":1016 + * + * result.from_slice = memviewslice + * __PYX_INC_MEMVIEW(&memviewslice, 1) # <<<<<<<<<<<<<< + * + * result.from_object = ( memviewslice.memview).base + */ + __PYX_INC_MEMVIEW((&__pyx_v_memviewslice), 1); + + /* "View.MemoryView":1018 + * __PYX_INC_MEMVIEW(&memviewslice, 1) + * + * result.from_object = ( memviewslice.memview).base # <<<<<<<<<<<<<< + * result.typeinfo = memviewslice.memview.typeinfo + * + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_memviewslice.memview), __pyx_n_s_base); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1018, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_v_result->from_object); + __Pyx_DECREF(__pyx_v_result->from_object); + __pyx_v_result->from_object = __pyx_t_2; + __pyx_t_2 = 0; + + /* "View.MemoryView":1019 + * + * result.from_object = ( memviewslice.memview).base + * result.typeinfo = memviewslice.memview.typeinfo # <<<<<<<<<<<<<< + * + * result.view = memviewslice.memview.view + */ + __pyx_t_4 = __pyx_v_memviewslice.memview->typeinfo; + __pyx_v_result->__pyx_base.typeinfo = __pyx_t_4; + + /* "View.MemoryView":1021 + * result.typeinfo = memviewslice.memview.typeinfo + * + * result.view = memviewslice.memview.view # <<<<<<<<<<<<<< + * result.view.buf = memviewslice.data + * result.view.ndim = ndim + */ + __pyx_t_5 = __pyx_v_memviewslice.memview->view; + __pyx_v_result->__pyx_base.view = __pyx_t_5; + + /* "View.MemoryView":1022 + * + * result.view = memviewslice.memview.view + * result.view.buf = memviewslice.data # <<<<<<<<<<<<<< + * result.view.ndim = ndim + * (<__pyx_buffer *> &result.view).obj = Py_None + */ + __pyx_v_result->__pyx_base.view.buf = ((void *)__pyx_v_memviewslice.data); + + /* "View.MemoryView":1023 + * result.view = memviewslice.memview.view + * result.view.buf = memviewslice.data + * result.view.ndim = ndim # <<<<<<<<<<<<<< + * (<__pyx_buffer *> &result.view).obj = Py_None + * Py_INCREF(Py_None) + */ + __pyx_v_result->__pyx_base.view.ndim = __pyx_v_ndim; + + /* "View.MemoryView":1024 + * result.view.buf = memviewslice.data + * result.view.ndim = ndim + * (<__pyx_buffer *> &result.view).obj = Py_None # <<<<<<<<<<<<<< + * Py_INCREF(Py_None) + * + */ + ((Py_buffer *)(&__pyx_v_result->__pyx_base.view))->obj = Py_None; + + /* "View.MemoryView":1025 + * result.view.ndim = ndim + * (<__pyx_buffer *> &result.view).obj = Py_None + * Py_INCREF(Py_None) # <<<<<<<<<<<<<< + * + * if (memviewslice.memview).flags & PyBUF_WRITABLE: + */ + Py_INCREF(Py_None); + + /* "View.MemoryView":1027 + * Py_INCREF(Py_None) + * + * if (memviewslice.memview).flags & PyBUF_WRITABLE: # <<<<<<<<<<<<<< + * result.flags = PyBUF_RECORDS + * else: + */ + __pyx_t_1 = ((((struct __pyx_memoryview_obj *)__pyx_v_memviewslice.memview)->flags & PyBUF_WRITABLE) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":1028 + * + * if (memviewslice.memview).flags & PyBUF_WRITABLE: + * result.flags = PyBUF_RECORDS # <<<<<<<<<<<<<< + * else: + * result.flags = PyBUF_RECORDS_RO + */ + __pyx_v_result->__pyx_base.flags = PyBUF_RECORDS; + + /* "View.MemoryView":1027 + * Py_INCREF(Py_None) + * + * if (memviewslice.memview).flags & PyBUF_WRITABLE: # <<<<<<<<<<<<<< + * result.flags = PyBUF_RECORDS + * else: + */ + goto __pyx_L4; + } + + /* "View.MemoryView":1030 + * result.flags = PyBUF_RECORDS + * else: + * result.flags = PyBUF_RECORDS_RO # <<<<<<<<<<<<<< + * + * result.view.shape = result.from_slice.shape + */ + /*else*/ { + __pyx_v_result->__pyx_base.flags = PyBUF_RECORDS_RO; + } + __pyx_L4:; + + /* "View.MemoryView":1032 + * result.flags = PyBUF_RECORDS_RO + * + * result.view.shape = result.from_slice.shape # <<<<<<<<<<<<<< + * result.view.strides = result.from_slice.strides + * + */ + __pyx_v_result->__pyx_base.view.shape = ((Py_ssize_t *)__pyx_v_result->from_slice.shape); + + /* "View.MemoryView":1033 + * + * result.view.shape = result.from_slice.shape + * result.view.strides = result.from_slice.strides # <<<<<<<<<<<<<< + * + * + */ + __pyx_v_result->__pyx_base.view.strides = ((Py_ssize_t *)__pyx_v_result->from_slice.strides); + + /* "View.MemoryView":1036 + * + * + * result.view.suboffsets = NULL # <<<<<<<<<<<<<< + * for suboffset in result.from_slice.suboffsets[:ndim]: + * if suboffset >= 0: + */ + __pyx_v_result->__pyx_base.view.suboffsets = NULL; + + /* "View.MemoryView":1037 + * + * result.view.suboffsets = NULL + * for suboffset in result.from_slice.suboffsets[:ndim]: # <<<<<<<<<<<<<< + * if suboffset >= 0: + * result.view.suboffsets = result.from_slice.suboffsets + */ + __pyx_t_7 = (__pyx_v_result->from_slice.suboffsets + __pyx_v_ndim); + for (__pyx_t_8 = __pyx_v_result->from_slice.suboffsets; __pyx_t_8 < __pyx_t_7; __pyx_t_8++) { + __pyx_t_6 = __pyx_t_8; + __pyx_v_suboffset = (__pyx_t_6[0]); + + /* "View.MemoryView":1038 + * result.view.suboffsets = NULL + * for suboffset in result.from_slice.suboffsets[:ndim]: + * if suboffset >= 0: # <<<<<<<<<<<<<< + * result.view.suboffsets = result.from_slice.suboffsets + * break + */ + __pyx_t_1 = ((__pyx_v_suboffset >= 0) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":1039 + * for suboffset in result.from_slice.suboffsets[:ndim]: + * if suboffset >= 0: + * result.view.suboffsets = result.from_slice.suboffsets # <<<<<<<<<<<<<< + * break + * + */ + __pyx_v_result->__pyx_base.view.suboffsets = ((Py_ssize_t *)__pyx_v_result->from_slice.suboffsets); + + /* "View.MemoryView":1040 + * if suboffset >= 0: + * result.view.suboffsets = result.from_slice.suboffsets + * break # <<<<<<<<<<<<<< + * + * result.view.len = result.view.itemsize + */ + goto __pyx_L6_break; + + /* "View.MemoryView":1038 + * result.view.suboffsets = NULL + * for suboffset in result.from_slice.suboffsets[:ndim]: + * if suboffset >= 0: # <<<<<<<<<<<<<< + * result.view.suboffsets = result.from_slice.suboffsets + * break + */ + } + } + __pyx_L6_break:; + + /* "View.MemoryView":1042 + * break + * + * result.view.len = result.view.itemsize # <<<<<<<<<<<<<< + * for length in result.view.shape[:ndim]: + * result.view.len *= length + */ + __pyx_t_9 = __pyx_v_result->__pyx_base.view.itemsize; + __pyx_v_result->__pyx_base.view.len = __pyx_t_9; + + /* "View.MemoryView":1043 + * + * result.view.len = result.view.itemsize + * for length in result.view.shape[:ndim]: # <<<<<<<<<<<<<< + * result.view.len *= length + * + */ + __pyx_t_7 = (__pyx_v_result->__pyx_base.view.shape + __pyx_v_ndim); + for (__pyx_t_8 = __pyx_v_result->__pyx_base.view.shape; __pyx_t_8 < __pyx_t_7; __pyx_t_8++) { + __pyx_t_6 = __pyx_t_8; + __pyx_t_2 = PyInt_FromSsize_t((__pyx_t_6[0])); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1043, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XDECREF_SET(__pyx_v_length, __pyx_t_2); + __pyx_t_2 = 0; + + /* "View.MemoryView":1044 + * result.view.len = result.view.itemsize + * for length in result.view.shape[:ndim]: + * result.view.len *= length # <<<<<<<<<<<<<< + * + * result.to_object_func = to_object_func + */ + __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_result->__pyx_base.view.len); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1044, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyNumber_InPlaceMultiply(__pyx_t_2, __pyx_v_length); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 1044, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_9 = __Pyx_PyIndex_AsSsize_t(__pyx_t_3); if (unlikely((__pyx_t_9 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 1044, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_result->__pyx_base.view.len = __pyx_t_9; + } + + /* "View.MemoryView":1046 + * result.view.len *= length + * + * result.to_object_func = to_object_func # <<<<<<<<<<<<<< + * result.to_dtype_func = to_dtype_func + * + */ + __pyx_v_result->to_object_func = __pyx_v_to_object_func; + + /* "View.MemoryView":1047 + * + * result.to_object_func = to_object_func + * result.to_dtype_func = to_dtype_func # <<<<<<<<<<<<<< + * + * return result + */ + __pyx_v_result->to_dtype_func = __pyx_v_to_dtype_func; + + /* "View.MemoryView":1049 + * result.to_dtype_func = to_dtype_func + * + * return result # <<<<<<<<<<<<<< + * + * @cname('__pyx_memoryview_get_slice_from_memoryview') + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = ((PyObject *)__pyx_v_result); + goto __pyx_L0; + + /* "View.MemoryView":999 + * + * @cname('__pyx_memoryview_fromslice') + * cdef memoryview_fromslice(__Pyx_memviewslice memviewslice, # <<<<<<<<<<<<<< + * int ndim, + * object (*to_object_func)(char *), + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("View.MemoryView.memoryview_fromslice", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_result); + __Pyx_XDECREF(__pyx_v_length); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":1052 + * + * @cname('__pyx_memoryview_get_slice_from_memoryview') + * cdef __Pyx_memviewslice *get_slice_from_memview(memoryview memview, # <<<<<<<<<<<<<< + * __Pyx_memviewslice *mslice) except NULL: + * cdef _memoryviewslice obj + */ + +static __Pyx_memviewslice *__pyx_memoryview_get_slice_from_memoryview(struct __pyx_memoryview_obj *__pyx_v_memview, __Pyx_memviewslice *__pyx_v_mslice) { + struct __pyx_memoryviewslice_obj *__pyx_v_obj = 0; + __Pyx_memviewslice *__pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("get_slice_from_memview", 0); + + /* "View.MemoryView":1055 + * __Pyx_memviewslice *mslice) except NULL: + * cdef _memoryviewslice obj + * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< + * obj = memview + * return &obj.from_slice + */ + __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1056 + * cdef _memoryviewslice obj + * if isinstance(memview, _memoryviewslice): + * obj = memview # <<<<<<<<<<<<<< + * return &obj.from_slice + * else: + */ + if (!(likely(((((PyObject *)__pyx_v_memview)) == Py_None) || likely(__Pyx_TypeTest(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type))))) __PYX_ERR(2, 1056, __pyx_L1_error) + __pyx_t_3 = ((PyObject *)__pyx_v_memview); + __Pyx_INCREF(__pyx_t_3); + __pyx_v_obj = ((struct __pyx_memoryviewslice_obj *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "View.MemoryView":1057 + * if isinstance(memview, _memoryviewslice): + * obj = memview + * return &obj.from_slice # <<<<<<<<<<<<<< + * else: + * slice_copy(memview, mslice) + */ + __pyx_r = (&__pyx_v_obj->from_slice); + goto __pyx_L0; + + /* "View.MemoryView":1055 + * __Pyx_memviewslice *mslice) except NULL: + * cdef _memoryviewslice obj + * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< + * obj = memview + * return &obj.from_slice + */ + } + + /* "View.MemoryView":1059 + * return &obj.from_slice + * else: + * slice_copy(memview, mslice) # <<<<<<<<<<<<<< + * return mslice + * + */ + /*else*/ { + __pyx_memoryview_slice_copy(__pyx_v_memview, __pyx_v_mslice); + + /* "View.MemoryView":1060 + * else: + * slice_copy(memview, mslice) + * return mslice # <<<<<<<<<<<<<< + * + * @cname('__pyx_memoryview_slice_copy') + */ + __pyx_r = __pyx_v_mslice; + goto __pyx_L0; + } + + /* "View.MemoryView":1052 + * + * @cname('__pyx_memoryview_get_slice_from_memoryview') + * cdef __Pyx_memviewslice *get_slice_from_memview(memoryview memview, # <<<<<<<<<<<<<< + * __Pyx_memviewslice *mslice) except NULL: + * cdef _memoryviewslice obj + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("View.MemoryView.get_slice_from_memview", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_obj); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":1063 + * + * @cname('__pyx_memoryview_slice_copy') + * cdef void slice_copy(memoryview memview, __Pyx_memviewslice *dst): # <<<<<<<<<<<<<< + * cdef int dim + * cdef (Py_ssize_t*) shape, strides, suboffsets + */ + +static void __pyx_memoryview_slice_copy(struct __pyx_memoryview_obj *__pyx_v_memview, __Pyx_memviewslice *__pyx_v_dst) { + int __pyx_v_dim; + Py_ssize_t *__pyx_v_shape; + Py_ssize_t *__pyx_v_strides; + Py_ssize_t *__pyx_v_suboffsets; + __Pyx_RefNannyDeclarations + Py_ssize_t *__pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + Py_ssize_t __pyx_t_5; + __Pyx_RefNannySetupContext("slice_copy", 0); + + /* "View.MemoryView":1067 + * cdef (Py_ssize_t*) shape, strides, suboffsets + * + * shape = memview.view.shape # <<<<<<<<<<<<<< + * strides = memview.view.strides + * suboffsets = memview.view.suboffsets + */ + __pyx_t_1 = __pyx_v_memview->view.shape; + __pyx_v_shape = __pyx_t_1; + + /* "View.MemoryView":1068 + * + * shape = memview.view.shape + * strides = memview.view.strides # <<<<<<<<<<<<<< + * suboffsets = memview.view.suboffsets + * + */ + __pyx_t_1 = __pyx_v_memview->view.strides; + __pyx_v_strides = __pyx_t_1; + + /* "View.MemoryView":1069 + * shape = memview.view.shape + * strides = memview.view.strides + * suboffsets = memview.view.suboffsets # <<<<<<<<<<<<<< + * + * dst.memview = <__pyx_memoryview *> memview + */ + __pyx_t_1 = __pyx_v_memview->view.suboffsets; + __pyx_v_suboffsets = __pyx_t_1; + + /* "View.MemoryView":1071 + * suboffsets = memview.view.suboffsets + * + * dst.memview = <__pyx_memoryview *> memview # <<<<<<<<<<<<<< + * dst.data = memview.view.buf + * + */ + __pyx_v_dst->memview = ((struct __pyx_memoryview_obj *)__pyx_v_memview); + + /* "View.MemoryView":1072 + * + * dst.memview = <__pyx_memoryview *> memview + * dst.data = memview.view.buf # <<<<<<<<<<<<<< + * + * for dim in range(memview.view.ndim): + */ + __pyx_v_dst->data = ((char *)__pyx_v_memview->view.buf); + + /* "View.MemoryView":1074 + * dst.data = memview.view.buf + * + * for dim in range(memview.view.ndim): # <<<<<<<<<<<<<< + * dst.shape[dim] = shape[dim] + * dst.strides[dim] = strides[dim] + */ + __pyx_t_2 = __pyx_v_memview->view.ndim; + __pyx_t_3 = __pyx_t_2; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_dim = __pyx_t_4; + + /* "View.MemoryView":1075 + * + * for dim in range(memview.view.ndim): + * dst.shape[dim] = shape[dim] # <<<<<<<<<<<<<< + * dst.strides[dim] = strides[dim] + * dst.suboffsets[dim] = suboffsets[dim] if suboffsets else -1 + */ + (__pyx_v_dst->shape[__pyx_v_dim]) = (__pyx_v_shape[__pyx_v_dim]); + + /* "View.MemoryView":1076 + * for dim in range(memview.view.ndim): + * dst.shape[dim] = shape[dim] + * dst.strides[dim] = strides[dim] # <<<<<<<<<<<<<< + * dst.suboffsets[dim] = suboffsets[dim] if suboffsets else -1 + * + */ + (__pyx_v_dst->strides[__pyx_v_dim]) = (__pyx_v_strides[__pyx_v_dim]); + + /* "View.MemoryView":1077 + * dst.shape[dim] = shape[dim] + * dst.strides[dim] = strides[dim] + * dst.suboffsets[dim] = suboffsets[dim] if suboffsets else -1 # <<<<<<<<<<<<<< + * + * @cname('__pyx_memoryview_copy_object') + */ + if ((__pyx_v_suboffsets != 0)) { + __pyx_t_5 = (__pyx_v_suboffsets[__pyx_v_dim]); + } else { + __pyx_t_5 = -1L; + } + (__pyx_v_dst->suboffsets[__pyx_v_dim]) = __pyx_t_5; + } + + /* "View.MemoryView":1063 + * + * @cname('__pyx_memoryview_slice_copy') + * cdef void slice_copy(memoryview memview, __Pyx_memviewslice *dst): # <<<<<<<<<<<<<< + * cdef int dim + * cdef (Py_ssize_t*) shape, strides, suboffsets + */ + + /* function exit code */ + __Pyx_RefNannyFinishContext(); +} + +/* "View.MemoryView":1080 + * + * @cname('__pyx_memoryview_copy_object') + * cdef memoryview_copy(memoryview memview): # <<<<<<<<<<<<<< + * "Create a new memoryview object" + * cdef __Pyx_memviewslice memviewslice + */ + +static PyObject *__pyx_memoryview_copy_object(struct __pyx_memoryview_obj *__pyx_v_memview) { + __Pyx_memviewslice __pyx_v_memviewslice; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("memoryview_copy", 0); + + /* "View.MemoryView":1083 + * "Create a new memoryview object" + * cdef __Pyx_memviewslice memviewslice + * slice_copy(memview, &memviewslice) # <<<<<<<<<<<<<< + * return memoryview_copy_from_slice(memview, &memviewslice) + * + */ + __pyx_memoryview_slice_copy(__pyx_v_memview, (&__pyx_v_memviewslice)); + + /* "View.MemoryView":1084 + * cdef __Pyx_memviewslice memviewslice + * slice_copy(memview, &memviewslice) + * return memoryview_copy_from_slice(memview, &memviewslice) # <<<<<<<<<<<<<< + * + * @cname('__pyx_memoryview_copy_object_from_slice') + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __pyx_memoryview_copy_object_from_slice(__pyx_v_memview, (&__pyx_v_memviewslice)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1084, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "View.MemoryView":1080 + * + * @cname('__pyx_memoryview_copy_object') + * cdef memoryview_copy(memoryview memview): # <<<<<<<<<<<<<< + * "Create a new memoryview object" + * cdef __Pyx_memviewslice memviewslice + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("View.MemoryView.memoryview_copy", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":1087 + * + * @cname('__pyx_memoryview_copy_object_from_slice') + * cdef memoryview_copy_from_slice(memoryview memview, __Pyx_memviewslice *memviewslice): # <<<<<<<<<<<<<< + * """ + * Create a new memoryview object from a given memoryview object and slice. + */ + +static PyObject *__pyx_memoryview_copy_object_from_slice(struct __pyx_memoryview_obj *__pyx_v_memview, __Pyx_memviewslice *__pyx_v_memviewslice) { + PyObject *(*__pyx_v_to_object_func)(char *); + int (*__pyx_v_to_dtype_func)(char *, PyObject *); + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *(*__pyx_t_3)(char *); + int (*__pyx_t_4)(char *, PyObject *); + PyObject *__pyx_t_5 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("memoryview_copy_from_slice", 0); + + /* "View.MemoryView":1094 + * cdef int (*to_dtype_func)(char *, object) except 0 + * + * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< + * to_object_func = (<_memoryviewslice> memview).to_object_func + * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func + */ + __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1095 + * + * if isinstance(memview, _memoryviewslice): + * to_object_func = (<_memoryviewslice> memview).to_object_func # <<<<<<<<<<<<<< + * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func + * else: + */ + __pyx_t_3 = ((struct __pyx_memoryviewslice_obj *)__pyx_v_memview)->to_object_func; + __pyx_v_to_object_func = __pyx_t_3; + + /* "View.MemoryView":1096 + * if isinstance(memview, _memoryviewslice): + * to_object_func = (<_memoryviewslice> memview).to_object_func + * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func # <<<<<<<<<<<<<< + * else: + * to_object_func = NULL + */ + __pyx_t_4 = ((struct __pyx_memoryviewslice_obj *)__pyx_v_memview)->to_dtype_func; + __pyx_v_to_dtype_func = __pyx_t_4; + + /* "View.MemoryView":1094 + * cdef int (*to_dtype_func)(char *, object) except 0 + * + * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< + * to_object_func = (<_memoryviewslice> memview).to_object_func + * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func + */ + goto __pyx_L3; + } + + /* "View.MemoryView":1098 + * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func + * else: + * to_object_func = NULL # <<<<<<<<<<<<<< + * to_dtype_func = NULL + * + */ + /*else*/ { + __pyx_v_to_object_func = NULL; + + /* "View.MemoryView":1099 + * else: + * to_object_func = NULL + * to_dtype_func = NULL # <<<<<<<<<<<<<< + * + * return memoryview_fromslice(memviewslice[0], memview.view.ndim, + */ + __pyx_v_to_dtype_func = NULL; + } + __pyx_L3:; + + /* "View.MemoryView":1101 + * to_dtype_func = NULL + * + * return memoryview_fromslice(memviewslice[0], memview.view.ndim, # <<<<<<<<<<<<<< + * to_object_func, to_dtype_func, + * memview.dtype_is_object) + */ + __Pyx_XDECREF(__pyx_r); + + /* "View.MemoryView":1103 + * return memoryview_fromslice(memviewslice[0], memview.view.ndim, + * to_object_func, to_dtype_func, + * memview.dtype_is_object) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_5 = __pyx_memoryview_fromslice((__pyx_v_memviewslice[0]), __pyx_v_memview->view.ndim, __pyx_v_to_object_func, __pyx_v_to_dtype_func, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 1101, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; + + /* "View.MemoryView":1087 + * + * @cname('__pyx_memoryview_copy_object_from_slice') + * cdef memoryview_copy_from_slice(memoryview memview, __Pyx_memviewslice *memviewslice): # <<<<<<<<<<<<<< + * """ + * Create a new memoryview object from a given memoryview object and slice. + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("View.MemoryView.memoryview_copy_from_slice", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":1109 + * + * + * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil: # <<<<<<<<<<<<<< + * if arg < 0: + * return -arg + */ + +static Py_ssize_t abs_py_ssize_t(Py_ssize_t __pyx_v_arg) { + Py_ssize_t __pyx_r; + int __pyx_t_1; + + /* "View.MemoryView":1110 + * + * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil: + * if arg < 0: # <<<<<<<<<<<<<< + * return -arg + * else: + */ + __pyx_t_1 = ((__pyx_v_arg < 0) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":1111 + * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil: + * if arg < 0: + * return -arg # <<<<<<<<<<<<<< + * else: + * return arg + */ + __pyx_r = (-__pyx_v_arg); + goto __pyx_L0; + + /* "View.MemoryView":1110 + * + * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil: + * if arg < 0: # <<<<<<<<<<<<<< + * return -arg + * else: + */ + } + + /* "View.MemoryView":1113 + * return -arg + * else: + * return arg # <<<<<<<<<<<<<< + * + * @cname('__pyx_get_best_slice_order') + */ + /*else*/ { + __pyx_r = __pyx_v_arg; + goto __pyx_L0; + } + + /* "View.MemoryView":1109 + * + * + * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil: # <<<<<<<<<<<<<< + * if arg < 0: + * return -arg + */ + + /* function exit code */ + __pyx_L0:; + return __pyx_r; +} + +/* "View.MemoryView":1116 + * + * @cname('__pyx_get_best_slice_order') + * cdef char get_best_order(__Pyx_memviewslice *mslice, int ndim) nogil: # <<<<<<<<<<<<<< + * """ + * Figure out the best memory access order for a given slice. + */ + +static char __pyx_get_best_slice_order(__Pyx_memviewslice *__pyx_v_mslice, int __pyx_v_ndim) { + int __pyx_v_i; + Py_ssize_t __pyx_v_c_stride; + Py_ssize_t __pyx_v_f_stride; + char __pyx_r; + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + + /* "View.MemoryView":1121 + * """ + * cdef int i + * cdef Py_ssize_t c_stride = 0 # <<<<<<<<<<<<<< + * cdef Py_ssize_t f_stride = 0 + * + */ + __pyx_v_c_stride = 0; + + /* "View.MemoryView":1122 + * cdef int i + * cdef Py_ssize_t c_stride = 0 + * cdef Py_ssize_t f_stride = 0 # <<<<<<<<<<<<<< + * + * for i in range(ndim - 1, -1, -1): + */ + __pyx_v_f_stride = 0; + + /* "View.MemoryView":1124 + * cdef Py_ssize_t f_stride = 0 + * + * for i in range(ndim - 1, -1, -1): # <<<<<<<<<<<<<< + * if mslice.shape[i] > 1: + * c_stride = mslice.strides[i] + */ + for (__pyx_t_1 = (__pyx_v_ndim - 1); __pyx_t_1 > -1; __pyx_t_1-=1) { + __pyx_v_i = __pyx_t_1; + + /* "View.MemoryView":1125 + * + * for i in range(ndim - 1, -1, -1): + * if mslice.shape[i] > 1: # <<<<<<<<<<<<<< + * c_stride = mslice.strides[i] + * break + */ + __pyx_t_2 = (((__pyx_v_mslice->shape[__pyx_v_i]) > 1) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1126 + * for i in range(ndim - 1, -1, -1): + * if mslice.shape[i] > 1: + * c_stride = mslice.strides[i] # <<<<<<<<<<<<<< + * break + * + */ + __pyx_v_c_stride = (__pyx_v_mslice->strides[__pyx_v_i]); + + /* "View.MemoryView":1127 + * if mslice.shape[i] > 1: + * c_stride = mslice.strides[i] + * break # <<<<<<<<<<<<<< + * + * for i in range(ndim): + */ + goto __pyx_L4_break; + + /* "View.MemoryView":1125 + * + * for i in range(ndim - 1, -1, -1): + * if mslice.shape[i] > 1: # <<<<<<<<<<<<<< + * c_stride = mslice.strides[i] + * break + */ + } + } + __pyx_L4_break:; + + /* "View.MemoryView":1129 + * break + * + * for i in range(ndim): # <<<<<<<<<<<<<< + * if mslice.shape[i] > 1: + * f_stride = mslice.strides[i] + */ + __pyx_t_1 = __pyx_v_ndim; + __pyx_t_3 = __pyx_t_1; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_i = __pyx_t_4; + + /* "View.MemoryView":1130 + * + * for i in range(ndim): + * if mslice.shape[i] > 1: # <<<<<<<<<<<<<< + * f_stride = mslice.strides[i] + * break + */ + __pyx_t_2 = (((__pyx_v_mslice->shape[__pyx_v_i]) > 1) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1131 + * for i in range(ndim): + * if mslice.shape[i] > 1: + * f_stride = mslice.strides[i] # <<<<<<<<<<<<<< + * break + * + */ + __pyx_v_f_stride = (__pyx_v_mslice->strides[__pyx_v_i]); + + /* "View.MemoryView":1132 + * if mslice.shape[i] > 1: + * f_stride = mslice.strides[i] + * break # <<<<<<<<<<<<<< + * + * if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride): + */ + goto __pyx_L7_break; + + /* "View.MemoryView":1130 + * + * for i in range(ndim): + * if mslice.shape[i] > 1: # <<<<<<<<<<<<<< + * f_stride = mslice.strides[i] + * break + */ + } + } + __pyx_L7_break:; + + /* "View.MemoryView":1134 + * break + * + * if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride): # <<<<<<<<<<<<<< + * return 'C' + * else: + */ + __pyx_t_2 = ((abs_py_ssize_t(__pyx_v_c_stride) <= abs_py_ssize_t(__pyx_v_f_stride)) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1135 + * + * if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride): + * return 'C' # <<<<<<<<<<<<<< + * else: + * return 'F' + */ + __pyx_r = 'C'; + goto __pyx_L0; + + /* "View.MemoryView":1134 + * break + * + * if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride): # <<<<<<<<<<<<<< + * return 'C' + * else: + */ + } + + /* "View.MemoryView":1137 + * return 'C' + * else: + * return 'F' # <<<<<<<<<<<<<< + * + * @cython.cdivision(True) + */ + /*else*/ { + __pyx_r = 'F'; + goto __pyx_L0; + } + + /* "View.MemoryView":1116 + * + * @cname('__pyx_get_best_slice_order') + * cdef char get_best_order(__Pyx_memviewslice *mslice, int ndim) nogil: # <<<<<<<<<<<<<< + * """ + * Figure out the best memory access order for a given slice. + */ + + /* function exit code */ + __pyx_L0:; + return __pyx_r; +} + +/* "View.MemoryView":1140 + * + * @cython.cdivision(True) + * cdef void _copy_strided_to_strided(char *src_data, Py_ssize_t *src_strides, # <<<<<<<<<<<<<< + * char *dst_data, Py_ssize_t *dst_strides, + * Py_ssize_t *src_shape, Py_ssize_t *dst_shape, + */ + +static void _copy_strided_to_strided(char *__pyx_v_src_data, Py_ssize_t *__pyx_v_src_strides, char *__pyx_v_dst_data, Py_ssize_t *__pyx_v_dst_strides, Py_ssize_t *__pyx_v_src_shape, Py_ssize_t *__pyx_v_dst_shape, int __pyx_v_ndim, size_t __pyx_v_itemsize) { + CYTHON_UNUSED Py_ssize_t __pyx_v_i; + CYTHON_UNUSED Py_ssize_t __pyx_v_src_extent; + Py_ssize_t __pyx_v_dst_extent; + Py_ssize_t __pyx_v_src_stride; + Py_ssize_t __pyx_v_dst_stride; + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + Py_ssize_t __pyx_t_4; + Py_ssize_t __pyx_t_5; + Py_ssize_t __pyx_t_6; + + /* "View.MemoryView":1147 + * + * cdef Py_ssize_t i + * cdef Py_ssize_t src_extent = src_shape[0] # <<<<<<<<<<<<<< + * cdef Py_ssize_t dst_extent = dst_shape[0] + * cdef Py_ssize_t src_stride = src_strides[0] + */ + __pyx_v_src_extent = (__pyx_v_src_shape[0]); + + /* "View.MemoryView":1148 + * cdef Py_ssize_t i + * cdef Py_ssize_t src_extent = src_shape[0] + * cdef Py_ssize_t dst_extent = dst_shape[0] # <<<<<<<<<<<<<< + * cdef Py_ssize_t src_stride = src_strides[0] + * cdef Py_ssize_t dst_stride = dst_strides[0] + */ + __pyx_v_dst_extent = (__pyx_v_dst_shape[0]); + + /* "View.MemoryView":1149 + * cdef Py_ssize_t src_extent = src_shape[0] + * cdef Py_ssize_t dst_extent = dst_shape[0] + * cdef Py_ssize_t src_stride = src_strides[0] # <<<<<<<<<<<<<< + * cdef Py_ssize_t dst_stride = dst_strides[0] + * + */ + __pyx_v_src_stride = (__pyx_v_src_strides[0]); + + /* "View.MemoryView":1150 + * cdef Py_ssize_t dst_extent = dst_shape[0] + * cdef Py_ssize_t src_stride = src_strides[0] + * cdef Py_ssize_t dst_stride = dst_strides[0] # <<<<<<<<<<<<<< + * + * if ndim == 1: + */ + __pyx_v_dst_stride = (__pyx_v_dst_strides[0]); + + /* "View.MemoryView":1152 + * cdef Py_ssize_t dst_stride = dst_strides[0] + * + * if ndim == 1: # <<<<<<<<<<<<<< + * if (src_stride > 0 and dst_stride > 0 and + * src_stride == itemsize == dst_stride): + */ + __pyx_t_1 = ((__pyx_v_ndim == 1) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":1153 + * + * if ndim == 1: + * if (src_stride > 0 and dst_stride > 0 and # <<<<<<<<<<<<<< + * src_stride == itemsize == dst_stride): + * memcpy(dst_data, src_data, itemsize * dst_extent) + */ + __pyx_t_2 = ((__pyx_v_src_stride > 0) != 0); + if (__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L5_bool_binop_done; + } + __pyx_t_2 = ((__pyx_v_dst_stride > 0) != 0); + if (__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L5_bool_binop_done; + } + + /* "View.MemoryView":1154 + * if ndim == 1: + * if (src_stride > 0 and dst_stride > 0 and + * src_stride == itemsize == dst_stride): # <<<<<<<<<<<<<< + * memcpy(dst_data, src_data, itemsize * dst_extent) + * else: + */ + __pyx_t_2 = (((size_t)__pyx_v_src_stride) == __pyx_v_itemsize); + if (__pyx_t_2) { + __pyx_t_2 = (__pyx_v_itemsize == ((size_t)__pyx_v_dst_stride)); + } + __pyx_t_3 = (__pyx_t_2 != 0); + __pyx_t_1 = __pyx_t_3; + __pyx_L5_bool_binop_done:; + + /* "View.MemoryView":1153 + * + * if ndim == 1: + * if (src_stride > 0 and dst_stride > 0 and # <<<<<<<<<<<<<< + * src_stride == itemsize == dst_stride): + * memcpy(dst_data, src_data, itemsize * dst_extent) + */ + if (__pyx_t_1) { + + /* "View.MemoryView":1155 + * if (src_stride > 0 and dst_stride > 0 and + * src_stride == itemsize == dst_stride): + * memcpy(dst_data, src_data, itemsize * dst_extent) # <<<<<<<<<<<<<< + * else: + * for i in range(dst_extent): + */ + (void)(memcpy(__pyx_v_dst_data, __pyx_v_src_data, (__pyx_v_itemsize * __pyx_v_dst_extent))); + + /* "View.MemoryView":1153 + * + * if ndim == 1: + * if (src_stride > 0 and dst_stride > 0 and # <<<<<<<<<<<<<< + * src_stride == itemsize == dst_stride): + * memcpy(dst_data, src_data, itemsize * dst_extent) + */ + goto __pyx_L4; + } + + /* "View.MemoryView":1157 + * memcpy(dst_data, src_data, itemsize * dst_extent) + * else: + * for i in range(dst_extent): # <<<<<<<<<<<<<< + * memcpy(dst_data, src_data, itemsize) + * src_data += src_stride + */ + /*else*/ { + __pyx_t_4 = __pyx_v_dst_extent; + __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; + + /* "View.MemoryView":1158 + * else: + * for i in range(dst_extent): + * memcpy(dst_data, src_data, itemsize) # <<<<<<<<<<<<<< + * src_data += src_stride + * dst_data += dst_stride + */ + (void)(memcpy(__pyx_v_dst_data, __pyx_v_src_data, __pyx_v_itemsize)); + + /* "View.MemoryView":1159 + * for i in range(dst_extent): + * memcpy(dst_data, src_data, itemsize) + * src_data += src_stride # <<<<<<<<<<<<<< + * dst_data += dst_stride + * else: + */ + __pyx_v_src_data = (__pyx_v_src_data + __pyx_v_src_stride); + + /* "View.MemoryView":1160 + * memcpy(dst_data, src_data, itemsize) + * src_data += src_stride + * dst_data += dst_stride # <<<<<<<<<<<<<< + * else: + * for i in range(dst_extent): + */ + __pyx_v_dst_data = (__pyx_v_dst_data + __pyx_v_dst_stride); + } + } + __pyx_L4:; + + /* "View.MemoryView":1152 + * cdef Py_ssize_t dst_stride = dst_strides[0] + * + * if ndim == 1: # <<<<<<<<<<<<<< + * if (src_stride > 0 and dst_stride > 0 and + * src_stride == itemsize == dst_stride): + */ + goto __pyx_L3; + } + + /* "View.MemoryView":1162 + * dst_data += dst_stride + * else: + * for i in range(dst_extent): # <<<<<<<<<<<<<< + * _copy_strided_to_strided(src_data, src_strides + 1, + * dst_data, dst_strides + 1, + */ + /*else*/ { + __pyx_t_4 = __pyx_v_dst_extent; + __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; + + /* "View.MemoryView":1163 + * else: + * for i in range(dst_extent): + * _copy_strided_to_strided(src_data, src_strides + 1, # <<<<<<<<<<<<<< + * dst_data, dst_strides + 1, + * src_shape + 1, dst_shape + 1, + */ + _copy_strided_to_strided(__pyx_v_src_data, (__pyx_v_src_strides + 1), __pyx_v_dst_data, (__pyx_v_dst_strides + 1), (__pyx_v_src_shape + 1), (__pyx_v_dst_shape + 1), (__pyx_v_ndim - 1), __pyx_v_itemsize); + + /* "View.MemoryView":1167 + * src_shape + 1, dst_shape + 1, + * ndim - 1, itemsize) + * src_data += src_stride # <<<<<<<<<<<<<< + * dst_data += dst_stride + * + */ + __pyx_v_src_data = (__pyx_v_src_data + __pyx_v_src_stride); + + /* "View.MemoryView":1168 + * ndim - 1, itemsize) + * src_data += src_stride + * dst_data += dst_stride # <<<<<<<<<<<<<< + * + * cdef void copy_strided_to_strided(__Pyx_memviewslice *src, + */ + __pyx_v_dst_data = (__pyx_v_dst_data + __pyx_v_dst_stride); + } + } + __pyx_L3:; + + /* "View.MemoryView":1140 + * + * @cython.cdivision(True) + * cdef void _copy_strided_to_strided(char *src_data, Py_ssize_t *src_strides, # <<<<<<<<<<<<<< + * char *dst_data, Py_ssize_t *dst_strides, + * Py_ssize_t *src_shape, Py_ssize_t *dst_shape, + */ + + /* function exit code */ +} + +/* "View.MemoryView":1170 + * dst_data += dst_stride + * + * cdef void copy_strided_to_strided(__Pyx_memviewslice *src, # <<<<<<<<<<<<<< + * __Pyx_memviewslice *dst, + * int ndim, size_t itemsize) nogil: + */ + +static void copy_strided_to_strided(__Pyx_memviewslice *__pyx_v_src, __Pyx_memviewslice *__pyx_v_dst, int __pyx_v_ndim, size_t __pyx_v_itemsize) { + + /* "View.MemoryView":1173 + * __Pyx_memviewslice *dst, + * int ndim, size_t itemsize) nogil: + * _copy_strided_to_strided(src.data, src.strides, dst.data, dst.strides, # <<<<<<<<<<<<<< + * src.shape, dst.shape, ndim, itemsize) + * + */ + _copy_strided_to_strided(__pyx_v_src->data, __pyx_v_src->strides, __pyx_v_dst->data, __pyx_v_dst->strides, __pyx_v_src->shape, __pyx_v_dst->shape, __pyx_v_ndim, __pyx_v_itemsize); + + /* "View.MemoryView":1170 + * dst_data += dst_stride + * + * cdef void copy_strided_to_strided(__Pyx_memviewslice *src, # <<<<<<<<<<<<<< + * __Pyx_memviewslice *dst, + * int ndim, size_t itemsize) nogil: + */ + + /* function exit code */ +} + +/* "View.MemoryView":1177 + * + * @cname('__pyx_memoryview_slice_get_size') + * cdef Py_ssize_t slice_get_size(__Pyx_memviewslice *src, int ndim) nogil: # <<<<<<<<<<<<<< + * "Return the size of the memory occupied by the slice in number of bytes" + * cdef Py_ssize_t shape, size = src.memview.view.itemsize + */ + +static Py_ssize_t __pyx_memoryview_slice_get_size(__Pyx_memviewslice *__pyx_v_src, int __pyx_v_ndim) { + Py_ssize_t __pyx_v_shape; + Py_ssize_t __pyx_v_size; + Py_ssize_t __pyx_r; + Py_ssize_t __pyx_t_1; + Py_ssize_t *__pyx_t_2; + Py_ssize_t *__pyx_t_3; + Py_ssize_t *__pyx_t_4; + + /* "View.MemoryView":1179 + * cdef Py_ssize_t slice_get_size(__Pyx_memviewslice *src, int ndim) nogil: + * "Return the size of the memory occupied by the slice in number of bytes" + * cdef Py_ssize_t shape, size = src.memview.view.itemsize # <<<<<<<<<<<<<< + * + * for shape in src.shape[:ndim]: + */ + __pyx_t_1 = __pyx_v_src->memview->view.itemsize; + __pyx_v_size = __pyx_t_1; + + /* "View.MemoryView":1181 + * cdef Py_ssize_t shape, size = src.memview.view.itemsize + * + * for shape in src.shape[:ndim]: # <<<<<<<<<<<<<< + * size *= shape + * + */ + __pyx_t_3 = (__pyx_v_src->shape + __pyx_v_ndim); + for (__pyx_t_4 = __pyx_v_src->shape; __pyx_t_4 < __pyx_t_3; __pyx_t_4++) { + __pyx_t_2 = __pyx_t_4; + __pyx_v_shape = (__pyx_t_2[0]); + + /* "View.MemoryView":1182 + * + * for shape in src.shape[:ndim]: + * size *= shape # <<<<<<<<<<<<<< + * + * return size + */ + __pyx_v_size = (__pyx_v_size * __pyx_v_shape); + } + + /* "View.MemoryView":1184 + * size *= shape + * + * return size # <<<<<<<<<<<<<< + * + * @cname('__pyx_fill_contig_strides_array') + */ + __pyx_r = __pyx_v_size; + goto __pyx_L0; + + /* "View.MemoryView":1177 + * + * @cname('__pyx_memoryview_slice_get_size') + * cdef Py_ssize_t slice_get_size(__Pyx_memviewslice *src, int ndim) nogil: # <<<<<<<<<<<<<< + * "Return the size of the memory occupied by the slice in number of bytes" + * cdef Py_ssize_t shape, size = src.memview.view.itemsize + */ + + /* function exit code */ + __pyx_L0:; + return __pyx_r; +} + +/* "View.MemoryView":1187 + * + * @cname('__pyx_fill_contig_strides_array') + * cdef Py_ssize_t fill_contig_strides_array( # <<<<<<<<<<<<<< + * Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t stride, + * int ndim, char order) nogil: + */ + +static Py_ssize_t __pyx_fill_contig_strides_array(Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, Py_ssize_t __pyx_v_stride, int __pyx_v_ndim, char __pyx_v_order) { + int __pyx_v_idx; + Py_ssize_t __pyx_r; + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + + /* "View.MemoryView":1196 + * cdef int idx + * + * if order == 'F': # <<<<<<<<<<<<<< + * for idx in range(ndim): + * strides[idx] = stride + */ + __pyx_t_1 = ((__pyx_v_order == 'F') != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":1197 + * + * if order == 'F': + * for idx in range(ndim): # <<<<<<<<<<<<<< + * strides[idx] = stride + * stride *= shape[idx] + */ + __pyx_t_2 = __pyx_v_ndim; + __pyx_t_3 = __pyx_t_2; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_idx = __pyx_t_4; + + /* "View.MemoryView":1198 + * if order == 'F': + * for idx in range(ndim): + * strides[idx] = stride # <<<<<<<<<<<<<< + * stride *= shape[idx] + * else: + */ + (__pyx_v_strides[__pyx_v_idx]) = __pyx_v_stride; + + /* "View.MemoryView":1199 + * for idx in range(ndim): + * strides[idx] = stride + * stride *= shape[idx] # <<<<<<<<<<<<<< + * else: + * for idx in range(ndim - 1, -1, -1): + */ + __pyx_v_stride = (__pyx_v_stride * (__pyx_v_shape[__pyx_v_idx])); + } + + /* "View.MemoryView":1196 + * cdef int idx + * + * if order == 'F': # <<<<<<<<<<<<<< + * for idx in range(ndim): + * strides[idx] = stride + */ + goto __pyx_L3; + } + + /* "View.MemoryView":1201 + * stride *= shape[idx] + * else: + * for idx in range(ndim - 1, -1, -1): # <<<<<<<<<<<<<< + * strides[idx] = stride + * stride *= shape[idx] + */ + /*else*/ { + for (__pyx_t_2 = (__pyx_v_ndim - 1); __pyx_t_2 > -1; __pyx_t_2-=1) { + __pyx_v_idx = __pyx_t_2; + + /* "View.MemoryView":1202 + * else: + * for idx in range(ndim - 1, -1, -1): + * strides[idx] = stride # <<<<<<<<<<<<<< + * stride *= shape[idx] + * + */ + (__pyx_v_strides[__pyx_v_idx]) = __pyx_v_stride; + + /* "View.MemoryView":1203 + * for idx in range(ndim - 1, -1, -1): + * strides[idx] = stride + * stride *= shape[idx] # <<<<<<<<<<<<<< + * + * return stride + */ + __pyx_v_stride = (__pyx_v_stride * (__pyx_v_shape[__pyx_v_idx])); + } + } + __pyx_L3:; + + /* "View.MemoryView":1205 + * stride *= shape[idx] + * + * return stride # <<<<<<<<<<<<<< + * + * @cname('__pyx_memoryview_copy_data_to_temp') + */ + __pyx_r = __pyx_v_stride; + goto __pyx_L0; + + /* "View.MemoryView":1187 + * + * @cname('__pyx_fill_contig_strides_array') + * cdef Py_ssize_t fill_contig_strides_array( # <<<<<<<<<<<<<< + * Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t stride, + * int ndim, char order) nogil: + */ + + /* function exit code */ + __pyx_L0:; + return __pyx_r; +} + +/* "View.MemoryView":1208 + * + * @cname('__pyx_memoryview_copy_data_to_temp') + * cdef void *copy_data_to_temp(__Pyx_memviewslice *src, # <<<<<<<<<<<<<< + * __Pyx_memviewslice *tmpslice, + * char order, + */ + +static void *__pyx_memoryview_copy_data_to_temp(__Pyx_memviewslice *__pyx_v_src, __Pyx_memviewslice *__pyx_v_tmpslice, char __pyx_v_order, int __pyx_v_ndim) { + int __pyx_v_i; + void *__pyx_v_result; + size_t __pyx_v_itemsize; + size_t __pyx_v_size; + void *__pyx_r; + Py_ssize_t __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + struct __pyx_memoryview_obj *__pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + + /* "View.MemoryView":1219 + * cdef void *result + * + * cdef size_t itemsize = src.memview.view.itemsize # <<<<<<<<<<<<<< + * cdef size_t size = slice_get_size(src, ndim) + * + */ + __pyx_t_1 = __pyx_v_src->memview->view.itemsize; + __pyx_v_itemsize = __pyx_t_1; + + /* "View.MemoryView":1220 + * + * cdef size_t itemsize = src.memview.view.itemsize + * cdef size_t size = slice_get_size(src, ndim) # <<<<<<<<<<<<<< + * + * result = malloc(size) + */ + __pyx_v_size = __pyx_memoryview_slice_get_size(__pyx_v_src, __pyx_v_ndim); + + /* "View.MemoryView":1222 + * cdef size_t size = slice_get_size(src, ndim) + * + * result = malloc(size) # <<<<<<<<<<<<<< + * if not result: + * _err(MemoryError, NULL) + */ + __pyx_v_result = malloc(__pyx_v_size); + + /* "View.MemoryView":1223 + * + * result = malloc(size) + * if not result: # <<<<<<<<<<<<<< + * _err(MemoryError, NULL) + * + */ + __pyx_t_2 = ((!(__pyx_v_result != 0)) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1224 + * result = malloc(size) + * if not result: + * _err(MemoryError, NULL) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_3 = __pyx_memoryview_err(__pyx_builtin_MemoryError, NULL); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(2, 1224, __pyx_L1_error) + + /* "View.MemoryView":1223 + * + * result = malloc(size) + * if not result: # <<<<<<<<<<<<<< + * _err(MemoryError, NULL) + * + */ + } + + /* "View.MemoryView":1227 + * + * + * tmpslice.data = result # <<<<<<<<<<<<<< + * tmpslice.memview = src.memview + * for i in range(ndim): + */ + __pyx_v_tmpslice->data = ((char *)__pyx_v_result); + + /* "View.MemoryView":1228 + * + * tmpslice.data = result + * tmpslice.memview = src.memview # <<<<<<<<<<<<<< + * for i in range(ndim): + * tmpslice.shape[i] = src.shape[i] + */ + __pyx_t_4 = __pyx_v_src->memview; + __pyx_v_tmpslice->memview = __pyx_t_4; + + /* "View.MemoryView":1229 + * tmpslice.data = result + * tmpslice.memview = src.memview + * for i in range(ndim): # <<<<<<<<<<<<<< + * tmpslice.shape[i] = src.shape[i] + * tmpslice.suboffsets[i] = -1 + */ + __pyx_t_3 = __pyx_v_ndim; + __pyx_t_5 = __pyx_t_3; + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { + __pyx_v_i = __pyx_t_6; + + /* "View.MemoryView":1230 + * tmpslice.memview = src.memview + * for i in range(ndim): + * tmpslice.shape[i] = src.shape[i] # <<<<<<<<<<<<<< + * tmpslice.suboffsets[i] = -1 + * + */ + (__pyx_v_tmpslice->shape[__pyx_v_i]) = (__pyx_v_src->shape[__pyx_v_i]); + + /* "View.MemoryView":1231 + * for i in range(ndim): + * tmpslice.shape[i] = src.shape[i] + * tmpslice.suboffsets[i] = -1 # <<<<<<<<<<<<<< + * + * fill_contig_strides_array(&tmpslice.shape[0], &tmpslice.strides[0], itemsize, + */ + (__pyx_v_tmpslice->suboffsets[__pyx_v_i]) = -1L; + } + + /* "View.MemoryView":1233 + * tmpslice.suboffsets[i] = -1 + * + * fill_contig_strides_array(&tmpslice.shape[0], &tmpslice.strides[0], itemsize, # <<<<<<<<<<<<<< + * ndim, order) + * + */ + (void)(__pyx_fill_contig_strides_array((&(__pyx_v_tmpslice->shape[0])), (&(__pyx_v_tmpslice->strides[0])), __pyx_v_itemsize, __pyx_v_ndim, __pyx_v_order)); + + /* "View.MemoryView":1237 + * + * + * for i in range(ndim): # <<<<<<<<<<<<<< + * if tmpslice.shape[i] == 1: + * tmpslice.strides[i] = 0 + */ + __pyx_t_3 = __pyx_v_ndim; + __pyx_t_5 = __pyx_t_3; + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { + __pyx_v_i = __pyx_t_6; + + /* "View.MemoryView":1238 + * + * for i in range(ndim): + * if tmpslice.shape[i] == 1: # <<<<<<<<<<<<<< + * tmpslice.strides[i] = 0 + * + */ + __pyx_t_2 = (((__pyx_v_tmpslice->shape[__pyx_v_i]) == 1) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1239 + * for i in range(ndim): + * if tmpslice.shape[i] == 1: + * tmpslice.strides[i] = 0 # <<<<<<<<<<<<<< + * + * if slice_is_contig(src[0], order, ndim): + */ + (__pyx_v_tmpslice->strides[__pyx_v_i]) = 0; + + /* "View.MemoryView":1238 + * + * for i in range(ndim): + * if tmpslice.shape[i] == 1: # <<<<<<<<<<<<<< + * tmpslice.strides[i] = 0 + * + */ + } + } + + /* "View.MemoryView":1241 + * tmpslice.strides[i] = 0 + * + * if slice_is_contig(src[0], order, ndim): # <<<<<<<<<<<<<< + * memcpy(result, src.data, size) + * else: + */ + __pyx_t_2 = (__pyx_memviewslice_is_contig((__pyx_v_src[0]), __pyx_v_order, __pyx_v_ndim) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1242 + * + * if slice_is_contig(src[0], order, ndim): + * memcpy(result, src.data, size) # <<<<<<<<<<<<<< + * else: + * copy_strided_to_strided(src, tmpslice, ndim, itemsize) + */ + (void)(memcpy(__pyx_v_result, __pyx_v_src->data, __pyx_v_size)); + + /* "View.MemoryView":1241 + * tmpslice.strides[i] = 0 + * + * if slice_is_contig(src[0], order, ndim): # <<<<<<<<<<<<<< + * memcpy(result, src.data, size) + * else: + */ + goto __pyx_L9; + } + + /* "View.MemoryView":1244 + * memcpy(result, src.data, size) + * else: + * copy_strided_to_strided(src, tmpslice, ndim, itemsize) # <<<<<<<<<<<<<< + * + * return result + */ + /*else*/ { + copy_strided_to_strided(__pyx_v_src, __pyx_v_tmpslice, __pyx_v_ndim, __pyx_v_itemsize); + } + __pyx_L9:; + + /* "View.MemoryView":1246 + * copy_strided_to_strided(src, tmpslice, ndim, itemsize) + * + * return result # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + /* "View.MemoryView":1208 + * + * @cname('__pyx_memoryview_copy_data_to_temp') + * cdef void *copy_data_to_temp(__Pyx_memviewslice *src, # <<<<<<<<<<<<<< + * __Pyx_memviewslice *tmpslice, + * char order, + */ + + /* function exit code */ + __pyx_L1_error:; + { + #ifdef WITH_THREAD + PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); + #endif + __Pyx_AddTraceback("View.MemoryView.copy_data_to_temp", __pyx_clineno, __pyx_lineno, __pyx_filename); + #ifdef WITH_THREAD + __Pyx_PyGILState_Release(__pyx_gilstate_save); + #endif + } + __pyx_r = NULL; + __pyx_L0:; + return __pyx_r; +} + +/* "View.MemoryView":1251 + * + * @cname('__pyx_memoryview_err_extents') + * cdef int _err_extents(int i, Py_ssize_t extent1, # <<<<<<<<<<<<<< + * Py_ssize_t extent2) except -1 with gil: + * raise ValueError("got differing extents in dimension %d (got %d and %d)" % + */ + +static int __pyx_memoryview_err_extents(int __pyx_v_i, Py_ssize_t __pyx_v_extent1, Py_ssize_t __pyx_v_extent2) { + 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_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + #ifdef WITH_THREAD + PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); + #endif + __Pyx_RefNannySetupContext("_err_extents", 0); + + /* "View.MemoryView":1254 + * Py_ssize_t extent2) except -1 with gil: + * raise ValueError("got differing extents in dimension %d (got %d and %d)" % + * (i, extent1, extent2)) # <<<<<<<<<<<<<< + * + * @cname('__pyx_memoryview_err_dim') + */ + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1254, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_extent1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1254, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_extent2); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 1254, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 1254, __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_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_t_3 = 0; + + /* "View.MemoryView":1253 + * cdef int _err_extents(int i, Py_ssize_t extent1, + * Py_ssize_t extent2) except -1 with gil: + * raise ValueError("got differing extents in dimension %d (got %d and %d)" % # <<<<<<<<<<<<<< + * (i, extent1, extent2)) + * + */ + __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_got_differing_extents_in_dimensi, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 1253, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 1253, __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, 1253, __pyx_L1_error) + + /* "View.MemoryView":1251 + * + * @cname('__pyx_memoryview_err_extents') + * cdef int _err_extents(int i, Py_ssize_t extent1, # <<<<<<<<<<<<<< + * Py_ssize_t extent2) except -1 with gil: + * raise ValueError("got differing extents in dimension %d (got %d and %d)" % + */ + + /* 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_4); + __Pyx_AddTraceback("View.MemoryView._err_extents", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __Pyx_RefNannyFinishContext(); + #ifdef WITH_THREAD + __Pyx_PyGILState_Release(__pyx_gilstate_save); + #endif + return __pyx_r; +} + +/* "View.MemoryView":1257 + * + * @cname('__pyx_memoryview_err_dim') + * cdef int _err_dim(object error, char *msg, int dim) except -1 with gil: # <<<<<<<<<<<<<< + * raise error(msg.decode('ascii') % dim) + * + */ + +static int __pyx_memoryview_err_dim(PyObject *__pyx_v_error, char *__pyx_v_msg, int __pyx_v_dim) { + 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_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + #ifdef WITH_THREAD + PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); + #endif + __Pyx_RefNannySetupContext("_err_dim", 0); + __Pyx_INCREF(__pyx_v_error); + + /* "View.MemoryView":1258 + * @cname('__pyx_memoryview_err_dim') + * cdef int _err_dim(object error, char *msg, int dim) except -1 with gil: + * raise error(msg.decode('ascii') % dim) # <<<<<<<<<<<<<< + * + * @cname('__pyx_memoryview_err') + */ + __pyx_t_2 = __Pyx_decode_c_string(__pyx_v_msg, 0, strlen(__pyx_v_msg), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1258, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 1258, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyUnicode_Format(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 1258, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_INCREF(__pyx_v_error); + __pyx_t_3 = __pyx_v_error; __pyx_t_2 = NULL; + 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_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1258, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(2, 1258, __pyx_L1_error) + + /* "View.MemoryView":1257 + * + * @cname('__pyx_memoryview_err_dim') + * cdef int _err_dim(object error, char *msg, int dim) except -1 with gil: # <<<<<<<<<<<<<< + * raise error(msg.decode('ascii') % dim) + * + */ + + /* 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_4); + __Pyx_AddTraceback("View.MemoryView._err_dim", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __Pyx_XDECREF(__pyx_v_error); + __Pyx_RefNannyFinishContext(); + #ifdef WITH_THREAD + __Pyx_PyGILState_Release(__pyx_gilstate_save); + #endif + return __pyx_r; +} + +/* "View.MemoryView":1261 + * + * @cname('__pyx_memoryview_err') + * cdef int _err(object error, char *msg) except -1 with gil: # <<<<<<<<<<<<<< + * if msg != NULL: + * raise error(msg.decode('ascii')) + */ + +static int __pyx_memoryview_err(PyObject *__pyx_v_error, char *__pyx_v_msg) { + int __pyx_r; + __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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + #ifdef WITH_THREAD + PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); + #endif + __Pyx_RefNannySetupContext("_err", 0); + __Pyx_INCREF(__pyx_v_error); + + /* "View.MemoryView":1262 + * @cname('__pyx_memoryview_err') + * cdef int _err(object error, char *msg) except -1 with gil: + * if msg != NULL: # <<<<<<<<<<<<<< + * raise error(msg.decode('ascii')) + * else: + */ + __pyx_t_1 = ((__pyx_v_msg != NULL) != 0); + if (unlikely(__pyx_t_1)) { + + /* "View.MemoryView":1263 + * cdef int _err(object error, char *msg) except -1 with gil: + * if msg != NULL: + * raise error(msg.decode('ascii')) # <<<<<<<<<<<<<< + * else: + * raise error + */ + __pyx_t_3 = __Pyx_decode_c_string(__pyx_v_msg, 0, strlen(__pyx_v_msg), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 1263, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_error); + __pyx_t_4 = __pyx_v_error; __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); + } + } + __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1263, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(2, 1263, __pyx_L1_error) + + /* "View.MemoryView":1262 + * @cname('__pyx_memoryview_err') + * cdef int _err(object error, char *msg) except -1 with gil: + * if msg != NULL: # <<<<<<<<<<<<<< + * raise error(msg.decode('ascii')) + * else: + */ + } + + /* "View.MemoryView":1265 + * raise error(msg.decode('ascii')) + * else: + * raise error # <<<<<<<<<<<<<< + * + * @cname('__pyx_memoryview_copy_contents') + */ + /*else*/ { + __Pyx_Raise(__pyx_v_error, 0, 0, 0); + __PYX_ERR(2, 1265, __pyx_L1_error) + } + + /* "View.MemoryView":1261 + * + * @cname('__pyx_memoryview_err') + * cdef int _err(object error, char *msg) except -1 with gil: # <<<<<<<<<<<<<< + * if msg != NULL: + * raise error(msg.decode('ascii')) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("View.MemoryView._err", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __Pyx_XDECREF(__pyx_v_error); + __Pyx_RefNannyFinishContext(); + #ifdef WITH_THREAD + __Pyx_PyGILState_Release(__pyx_gilstate_save); + #endif + return __pyx_r; +} + +/* "View.MemoryView":1268 + * + * @cname('__pyx_memoryview_copy_contents') + * cdef int memoryview_copy_contents(__Pyx_memviewslice src, # <<<<<<<<<<<<<< + * __Pyx_memviewslice dst, + * int src_ndim, int dst_ndim, + */ + +static int __pyx_memoryview_copy_contents(__Pyx_memviewslice __pyx_v_src, __Pyx_memviewslice __pyx_v_dst, int __pyx_v_src_ndim, int __pyx_v_dst_ndim, int __pyx_v_dtype_is_object) { + void *__pyx_v_tmpdata; + size_t __pyx_v_itemsize; + int __pyx_v_i; + char __pyx_v_order; + int __pyx_v_broadcasting; + int __pyx_v_direct_copy; + __Pyx_memviewslice __pyx_v_tmp; + int __pyx_v_ndim; + int __pyx_r; + Py_ssize_t __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + void *__pyx_t_7; + int __pyx_t_8; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + + /* "View.MemoryView":1276 + * Check for overlapping memory and verify the shapes. + * """ + * cdef void *tmpdata = NULL # <<<<<<<<<<<<<< + * cdef size_t itemsize = src.memview.view.itemsize + * cdef int i + */ + __pyx_v_tmpdata = NULL; + + /* "View.MemoryView":1277 + * """ + * cdef void *tmpdata = NULL + * cdef size_t itemsize = src.memview.view.itemsize # <<<<<<<<<<<<<< + * cdef int i + * cdef char order = get_best_order(&src, src_ndim) + */ + __pyx_t_1 = __pyx_v_src.memview->view.itemsize; + __pyx_v_itemsize = __pyx_t_1; + + /* "View.MemoryView":1279 + * cdef size_t itemsize = src.memview.view.itemsize + * cdef int i + * cdef char order = get_best_order(&src, src_ndim) # <<<<<<<<<<<<<< + * cdef bint broadcasting = False + * cdef bint direct_copy = False + */ + __pyx_v_order = __pyx_get_best_slice_order((&__pyx_v_src), __pyx_v_src_ndim); + + /* "View.MemoryView":1280 + * cdef int i + * cdef char order = get_best_order(&src, src_ndim) + * cdef bint broadcasting = False # <<<<<<<<<<<<<< + * cdef bint direct_copy = False + * cdef __Pyx_memviewslice tmp + */ + __pyx_v_broadcasting = 0; + + /* "View.MemoryView":1281 + * cdef char order = get_best_order(&src, src_ndim) + * cdef bint broadcasting = False + * cdef bint direct_copy = False # <<<<<<<<<<<<<< + * cdef __Pyx_memviewslice tmp + * + */ + __pyx_v_direct_copy = 0; + + /* "View.MemoryView":1284 + * cdef __Pyx_memviewslice tmp + * + * if src_ndim < dst_ndim: # <<<<<<<<<<<<<< + * broadcast_leading(&src, src_ndim, dst_ndim) + * elif dst_ndim < src_ndim: + */ + __pyx_t_2 = ((__pyx_v_src_ndim < __pyx_v_dst_ndim) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1285 + * + * if src_ndim < dst_ndim: + * broadcast_leading(&src, src_ndim, dst_ndim) # <<<<<<<<<<<<<< + * elif dst_ndim < src_ndim: + * broadcast_leading(&dst, dst_ndim, src_ndim) + */ + __pyx_memoryview_broadcast_leading((&__pyx_v_src), __pyx_v_src_ndim, __pyx_v_dst_ndim); + + /* "View.MemoryView":1284 + * cdef __Pyx_memviewslice tmp + * + * if src_ndim < dst_ndim: # <<<<<<<<<<<<<< + * broadcast_leading(&src, src_ndim, dst_ndim) + * elif dst_ndim < src_ndim: + */ + goto __pyx_L3; + } + + /* "View.MemoryView":1286 + * if src_ndim < dst_ndim: + * broadcast_leading(&src, src_ndim, dst_ndim) + * elif dst_ndim < src_ndim: # <<<<<<<<<<<<<< + * broadcast_leading(&dst, dst_ndim, src_ndim) + * + */ + __pyx_t_2 = ((__pyx_v_dst_ndim < __pyx_v_src_ndim) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1287 + * broadcast_leading(&src, src_ndim, dst_ndim) + * elif dst_ndim < src_ndim: + * broadcast_leading(&dst, dst_ndim, src_ndim) # <<<<<<<<<<<<<< + * + * cdef int ndim = max(src_ndim, dst_ndim) + */ + __pyx_memoryview_broadcast_leading((&__pyx_v_dst), __pyx_v_dst_ndim, __pyx_v_src_ndim); + + /* "View.MemoryView":1286 + * if src_ndim < dst_ndim: + * broadcast_leading(&src, src_ndim, dst_ndim) + * elif dst_ndim < src_ndim: # <<<<<<<<<<<<<< + * broadcast_leading(&dst, dst_ndim, src_ndim) + * + */ + } + __pyx_L3:; + + /* "View.MemoryView":1289 + * broadcast_leading(&dst, dst_ndim, src_ndim) + * + * cdef int ndim = max(src_ndim, dst_ndim) # <<<<<<<<<<<<<< + * + * for i in range(ndim): + */ + __pyx_t_3 = __pyx_v_dst_ndim; + __pyx_t_4 = __pyx_v_src_ndim; + if (((__pyx_t_3 > __pyx_t_4) != 0)) { + __pyx_t_5 = __pyx_t_3; + } else { + __pyx_t_5 = __pyx_t_4; + } + __pyx_v_ndim = __pyx_t_5; + + /* "View.MemoryView":1291 + * cdef int ndim = max(src_ndim, dst_ndim) + * + * for i in range(ndim): # <<<<<<<<<<<<<< + * if src.shape[i] != dst.shape[i]: + * if src.shape[i] == 1: + */ + __pyx_t_5 = __pyx_v_ndim; + __pyx_t_3 = __pyx_t_5; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_i = __pyx_t_4; + + /* "View.MemoryView":1292 + * + * for i in range(ndim): + * if src.shape[i] != dst.shape[i]: # <<<<<<<<<<<<<< + * if src.shape[i] == 1: + * broadcasting = True + */ + __pyx_t_2 = (((__pyx_v_src.shape[__pyx_v_i]) != (__pyx_v_dst.shape[__pyx_v_i])) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1293 + * for i in range(ndim): + * if src.shape[i] != dst.shape[i]: + * if src.shape[i] == 1: # <<<<<<<<<<<<<< + * broadcasting = True + * src.strides[i] = 0 + */ + __pyx_t_2 = (((__pyx_v_src.shape[__pyx_v_i]) == 1) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1294 + * if src.shape[i] != dst.shape[i]: + * if src.shape[i] == 1: + * broadcasting = True # <<<<<<<<<<<<<< + * src.strides[i] = 0 + * else: + */ + __pyx_v_broadcasting = 1; + + /* "View.MemoryView":1295 + * if src.shape[i] == 1: + * broadcasting = True + * src.strides[i] = 0 # <<<<<<<<<<<<<< + * else: + * _err_extents(i, dst.shape[i], src.shape[i]) + */ + (__pyx_v_src.strides[__pyx_v_i]) = 0; + + /* "View.MemoryView":1293 + * for i in range(ndim): + * if src.shape[i] != dst.shape[i]: + * if src.shape[i] == 1: # <<<<<<<<<<<<<< + * broadcasting = True + * src.strides[i] = 0 + */ + goto __pyx_L7; + } + + /* "View.MemoryView":1297 + * src.strides[i] = 0 + * else: + * _err_extents(i, dst.shape[i], src.shape[i]) # <<<<<<<<<<<<<< + * + * if src.suboffsets[i] >= 0: + */ + /*else*/ { + __pyx_t_6 = __pyx_memoryview_err_extents(__pyx_v_i, (__pyx_v_dst.shape[__pyx_v_i]), (__pyx_v_src.shape[__pyx_v_i])); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(2, 1297, __pyx_L1_error) + } + __pyx_L7:; + + /* "View.MemoryView":1292 + * + * for i in range(ndim): + * if src.shape[i] != dst.shape[i]: # <<<<<<<<<<<<<< + * if src.shape[i] == 1: + * broadcasting = True + */ + } + + /* "View.MemoryView":1299 + * _err_extents(i, dst.shape[i], src.shape[i]) + * + * if src.suboffsets[i] >= 0: # <<<<<<<<<<<<<< + * _err_dim(ValueError, "Dimension %d is not direct", i) + * + */ + __pyx_t_2 = (((__pyx_v_src.suboffsets[__pyx_v_i]) >= 0) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1300 + * + * if src.suboffsets[i] >= 0: + * _err_dim(ValueError, "Dimension %d is not direct", i) # <<<<<<<<<<<<<< + * + * if slices_overlap(&src, &dst, ndim, itemsize): + */ + __pyx_t_6 = __pyx_memoryview_err_dim(__pyx_builtin_ValueError, ((char *)"Dimension %d is not direct"), __pyx_v_i); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(2, 1300, __pyx_L1_error) + + /* "View.MemoryView":1299 + * _err_extents(i, dst.shape[i], src.shape[i]) + * + * if src.suboffsets[i] >= 0: # <<<<<<<<<<<<<< + * _err_dim(ValueError, "Dimension %d is not direct", i) + * + */ + } + } + + /* "View.MemoryView":1302 + * _err_dim(ValueError, "Dimension %d is not direct", i) + * + * if slices_overlap(&src, &dst, ndim, itemsize): # <<<<<<<<<<<<<< + * + * if not slice_is_contig(src, order, ndim): + */ + __pyx_t_2 = (__pyx_slices_overlap((&__pyx_v_src), (&__pyx_v_dst), __pyx_v_ndim, __pyx_v_itemsize) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1304 + * if slices_overlap(&src, &dst, ndim, itemsize): + * + * if not slice_is_contig(src, order, ndim): # <<<<<<<<<<<<<< + * order = get_best_order(&dst, ndim) + * + */ + __pyx_t_2 = ((!(__pyx_memviewslice_is_contig(__pyx_v_src, __pyx_v_order, __pyx_v_ndim) != 0)) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1305 + * + * if not slice_is_contig(src, order, ndim): + * order = get_best_order(&dst, ndim) # <<<<<<<<<<<<<< + * + * tmpdata = copy_data_to_temp(&src, &tmp, order, ndim) + */ + __pyx_v_order = __pyx_get_best_slice_order((&__pyx_v_dst), __pyx_v_ndim); + + /* "View.MemoryView":1304 + * if slices_overlap(&src, &dst, ndim, itemsize): + * + * if not slice_is_contig(src, order, ndim): # <<<<<<<<<<<<<< + * order = get_best_order(&dst, ndim) + * + */ + } + + /* "View.MemoryView":1307 + * order = get_best_order(&dst, ndim) + * + * tmpdata = copy_data_to_temp(&src, &tmp, order, ndim) # <<<<<<<<<<<<<< + * src = tmp + * + */ + __pyx_t_7 = __pyx_memoryview_copy_data_to_temp((&__pyx_v_src), (&__pyx_v_tmp), __pyx_v_order, __pyx_v_ndim); if (unlikely(__pyx_t_7 == ((void *)NULL))) __PYX_ERR(2, 1307, __pyx_L1_error) + __pyx_v_tmpdata = __pyx_t_7; + + /* "View.MemoryView":1308 + * + * tmpdata = copy_data_to_temp(&src, &tmp, order, ndim) + * src = tmp # <<<<<<<<<<<<<< + * + * if not broadcasting: + */ + __pyx_v_src = __pyx_v_tmp; + + /* "View.MemoryView":1302 + * _err_dim(ValueError, "Dimension %d is not direct", i) + * + * if slices_overlap(&src, &dst, ndim, itemsize): # <<<<<<<<<<<<<< + * + * if not slice_is_contig(src, order, ndim): + */ + } + + /* "View.MemoryView":1310 + * src = tmp + * + * if not broadcasting: # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_2 = ((!(__pyx_v_broadcasting != 0)) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1313 + * + * + * if slice_is_contig(src, 'C', ndim): # <<<<<<<<<<<<<< + * direct_copy = slice_is_contig(dst, 'C', ndim) + * elif slice_is_contig(src, 'F', ndim): + */ + __pyx_t_2 = (__pyx_memviewslice_is_contig(__pyx_v_src, 'C', __pyx_v_ndim) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1314 + * + * if slice_is_contig(src, 'C', ndim): + * direct_copy = slice_is_contig(dst, 'C', ndim) # <<<<<<<<<<<<<< + * elif slice_is_contig(src, 'F', ndim): + * direct_copy = slice_is_contig(dst, 'F', ndim) + */ + __pyx_v_direct_copy = __pyx_memviewslice_is_contig(__pyx_v_dst, 'C', __pyx_v_ndim); + + /* "View.MemoryView":1313 + * + * + * if slice_is_contig(src, 'C', ndim): # <<<<<<<<<<<<<< + * direct_copy = slice_is_contig(dst, 'C', ndim) + * elif slice_is_contig(src, 'F', ndim): + */ + goto __pyx_L12; + } + + /* "View.MemoryView":1315 + * if slice_is_contig(src, 'C', ndim): + * direct_copy = slice_is_contig(dst, 'C', ndim) + * elif slice_is_contig(src, 'F', ndim): # <<<<<<<<<<<<<< + * direct_copy = slice_is_contig(dst, 'F', ndim) + * + */ + __pyx_t_2 = (__pyx_memviewslice_is_contig(__pyx_v_src, 'F', __pyx_v_ndim) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1316 + * direct_copy = slice_is_contig(dst, 'C', ndim) + * elif slice_is_contig(src, 'F', ndim): + * direct_copy = slice_is_contig(dst, 'F', ndim) # <<<<<<<<<<<<<< + * + * if direct_copy: + */ + __pyx_v_direct_copy = __pyx_memviewslice_is_contig(__pyx_v_dst, 'F', __pyx_v_ndim); + + /* "View.MemoryView":1315 + * if slice_is_contig(src, 'C', ndim): + * direct_copy = slice_is_contig(dst, 'C', ndim) + * elif slice_is_contig(src, 'F', ndim): # <<<<<<<<<<<<<< + * direct_copy = slice_is_contig(dst, 'F', ndim) + * + */ + } + __pyx_L12:; + + /* "View.MemoryView":1318 + * direct_copy = slice_is_contig(dst, 'F', ndim) + * + * if direct_copy: # <<<<<<<<<<<<<< + * + * refcount_copying(&dst, dtype_is_object, ndim, False) + */ + __pyx_t_2 = (__pyx_v_direct_copy != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1320 + * if direct_copy: + * + * refcount_copying(&dst, dtype_is_object, ndim, False) # <<<<<<<<<<<<<< + * memcpy(dst.data, src.data, slice_get_size(&src, ndim)) + * refcount_copying(&dst, dtype_is_object, ndim, True) + */ + __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 0); + + /* "View.MemoryView":1321 + * + * refcount_copying(&dst, dtype_is_object, ndim, False) + * memcpy(dst.data, src.data, slice_get_size(&src, ndim)) # <<<<<<<<<<<<<< + * refcount_copying(&dst, dtype_is_object, ndim, True) + * free(tmpdata) + */ + (void)(memcpy(__pyx_v_dst.data, __pyx_v_src.data, __pyx_memoryview_slice_get_size((&__pyx_v_src), __pyx_v_ndim))); + + /* "View.MemoryView":1322 + * refcount_copying(&dst, dtype_is_object, ndim, False) + * memcpy(dst.data, src.data, slice_get_size(&src, ndim)) + * refcount_copying(&dst, dtype_is_object, ndim, True) # <<<<<<<<<<<<<< + * free(tmpdata) + * return 0 + */ + __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 1); + + /* "View.MemoryView":1323 + * memcpy(dst.data, src.data, slice_get_size(&src, ndim)) + * refcount_copying(&dst, dtype_is_object, ndim, True) + * free(tmpdata) # <<<<<<<<<<<<<< + * return 0 + * + */ + free(__pyx_v_tmpdata); + + /* "View.MemoryView":1324 + * refcount_copying(&dst, dtype_is_object, ndim, True) + * free(tmpdata) + * return 0 # <<<<<<<<<<<<<< + * + * if order == 'F' == get_best_order(&dst, ndim): + */ + __pyx_r = 0; + goto __pyx_L0; + + /* "View.MemoryView":1318 + * direct_copy = slice_is_contig(dst, 'F', ndim) + * + * if direct_copy: # <<<<<<<<<<<<<< + * + * refcount_copying(&dst, dtype_is_object, ndim, False) + */ + } + + /* "View.MemoryView":1310 + * src = tmp + * + * if not broadcasting: # <<<<<<<<<<<<<< + * + * + */ + } + + /* "View.MemoryView":1326 + * return 0 + * + * if order == 'F' == get_best_order(&dst, ndim): # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_2 = (__pyx_v_order == 'F'); + if (__pyx_t_2) { + __pyx_t_2 = ('F' == __pyx_get_best_slice_order((&__pyx_v_dst), __pyx_v_ndim)); + } + __pyx_t_8 = (__pyx_t_2 != 0); + if (__pyx_t_8) { + + /* "View.MemoryView":1329 + * + * + * transpose_memslice(&src) # <<<<<<<<<<<<<< + * transpose_memslice(&dst) + * + */ + __pyx_t_5 = __pyx_memslice_transpose((&__pyx_v_src)); if (unlikely(__pyx_t_5 == ((int)0))) __PYX_ERR(2, 1329, __pyx_L1_error) + + /* "View.MemoryView":1330 + * + * transpose_memslice(&src) + * transpose_memslice(&dst) # <<<<<<<<<<<<<< + * + * refcount_copying(&dst, dtype_is_object, ndim, False) + */ + __pyx_t_5 = __pyx_memslice_transpose((&__pyx_v_dst)); if (unlikely(__pyx_t_5 == ((int)0))) __PYX_ERR(2, 1330, __pyx_L1_error) + + /* "View.MemoryView":1326 + * return 0 + * + * if order == 'F' == get_best_order(&dst, ndim): # <<<<<<<<<<<<<< + * + * + */ + } + + /* "View.MemoryView":1332 + * transpose_memslice(&dst) + * + * refcount_copying(&dst, dtype_is_object, ndim, False) # <<<<<<<<<<<<<< + * copy_strided_to_strided(&src, &dst, ndim, itemsize) + * refcount_copying(&dst, dtype_is_object, ndim, True) + */ + __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 0); + + /* "View.MemoryView":1333 + * + * refcount_copying(&dst, dtype_is_object, ndim, False) + * copy_strided_to_strided(&src, &dst, ndim, itemsize) # <<<<<<<<<<<<<< + * refcount_copying(&dst, dtype_is_object, ndim, True) + * + */ + copy_strided_to_strided((&__pyx_v_src), (&__pyx_v_dst), __pyx_v_ndim, __pyx_v_itemsize); + + /* "View.MemoryView":1334 + * refcount_copying(&dst, dtype_is_object, ndim, False) + * copy_strided_to_strided(&src, &dst, ndim, itemsize) + * refcount_copying(&dst, dtype_is_object, ndim, True) # <<<<<<<<<<<<<< + * + * free(tmpdata) + */ + __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 1); + + /* "View.MemoryView":1336 + * refcount_copying(&dst, dtype_is_object, ndim, True) + * + * free(tmpdata) # <<<<<<<<<<<<<< + * return 0 + * + */ + free(__pyx_v_tmpdata); + + /* "View.MemoryView":1337 + * + * free(tmpdata) + * return 0 # <<<<<<<<<<<<<< + * + * @cname('__pyx_memoryview_broadcast_leading') + */ + __pyx_r = 0; + goto __pyx_L0; + + /* "View.MemoryView":1268 + * + * @cname('__pyx_memoryview_copy_contents') + * cdef int memoryview_copy_contents(__Pyx_memviewslice src, # <<<<<<<<<<<<<< + * __Pyx_memviewslice dst, + * int src_ndim, int dst_ndim, + */ + + /* function exit code */ + __pyx_L1_error:; + { + #ifdef WITH_THREAD + PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); + #endif + __Pyx_AddTraceback("View.MemoryView.memoryview_copy_contents", __pyx_clineno, __pyx_lineno, __pyx_filename); + #ifdef WITH_THREAD + __Pyx_PyGILState_Release(__pyx_gilstate_save); + #endif + } + __pyx_r = -1; + __pyx_L0:; + return __pyx_r; +} + +/* "View.MemoryView":1340 + * + * @cname('__pyx_memoryview_broadcast_leading') + * cdef void broadcast_leading(__Pyx_memviewslice *mslice, # <<<<<<<<<<<<<< + * int ndim, + * int ndim_other) nogil: + */ + +static void __pyx_memoryview_broadcast_leading(__Pyx_memviewslice *__pyx_v_mslice, int __pyx_v_ndim, int __pyx_v_ndim_other) { + int __pyx_v_i; + int __pyx_v_offset; + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + + /* "View.MemoryView":1344 + * int ndim_other) nogil: + * cdef int i + * cdef int offset = ndim_other - ndim # <<<<<<<<<<<<<< + * + * for i in range(ndim - 1, -1, -1): + */ + __pyx_v_offset = (__pyx_v_ndim_other - __pyx_v_ndim); + + /* "View.MemoryView":1346 + * cdef int offset = ndim_other - ndim + * + * for i in range(ndim - 1, -1, -1): # <<<<<<<<<<<<<< + * mslice.shape[i + offset] = mslice.shape[i] + * mslice.strides[i + offset] = mslice.strides[i] + */ + for (__pyx_t_1 = (__pyx_v_ndim - 1); __pyx_t_1 > -1; __pyx_t_1-=1) { + __pyx_v_i = __pyx_t_1; + + /* "View.MemoryView":1347 + * + * for i in range(ndim - 1, -1, -1): + * mslice.shape[i + offset] = mslice.shape[i] # <<<<<<<<<<<<<< + * mslice.strides[i + offset] = mslice.strides[i] + * mslice.suboffsets[i + offset] = mslice.suboffsets[i] + */ + (__pyx_v_mslice->shape[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_mslice->shape[__pyx_v_i]); + + /* "View.MemoryView":1348 + * for i in range(ndim - 1, -1, -1): + * mslice.shape[i + offset] = mslice.shape[i] + * mslice.strides[i + offset] = mslice.strides[i] # <<<<<<<<<<<<<< + * mslice.suboffsets[i + offset] = mslice.suboffsets[i] + * + */ + (__pyx_v_mslice->strides[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_mslice->strides[__pyx_v_i]); + + /* "View.MemoryView":1349 + * mslice.shape[i + offset] = mslice.shape[i] + * mslice.strides[i + offset] = mslice.strides[i] + * mslice.suboffsets[i + offset] = mslice.suboffsets[i] # <<<<<<<<<<<<<< + * + * for i in range(offset): + */ + (__pyx_v_mslice->suboffsets[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_mslice->suboffsets[__pyx_v_i]); + } + + /* "View.MemoryView":1351 + * mslice.suboffsets[i + offset] = mslice.suboffsets[i] + * + * for i in range(offset): # <<<<<<<<<<<<<< + * mslice.shape[i] = 1 + * mslice.strides[i] = mslice.strides[0] + */ + __pyx_t_1 = __pyx_v_offset; + __pyx_t_2 = __pyx_t_1; + for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { + __pyx_v_i = __pyx_t_3; + + /* "View.MemoryView":1352 + * + * for i in range(offset): + * mslice.shape[i] = 1 # <<<<<<<<<<<<<< + * mslice.strides[i] = mslice.strides[0] + * mslice.suboffsets[i] = -1 + */ + (__pyx_v_mslice->shape[__pyx_v_i]) = 1; + + /* "View.MemoryView":1353 + * for i in range(offset): + * mslice.shape[i] = 1 + * mslice.strides[i] = mslice.strides[0] # <<<<<<<<<<<<<< + * mslice.suboffsets[i] = -1 + * + */ + (__pyx_v_mslice->strides[__pyx_v_i]) = (__pyx_v_mslice->strides[0]); + + /* "View.MemoryView":1354 + * mslice.shape[i] = 1 + * mslice.strides[i] = mslice.strides[0] + * mslice.suboffsets[i] = -1 # <<<<<<<<<<<<<< + * + * + */ + (__pyx_v_mslice->suboffsets[__pyx_v_i]) = -1L; + } + + /* "View.MemoryView":1340 + * + * @cname('__pyx_memoryview_broadcast_leading') + * cdef void broadcast_leading(__Pyx_memviewslice *mslice, # <<<<<<<<<<<<<< + * int ndim, + * int ndim_other) nogil: + */ + + /* function exit code */ +} + +/* "View.MemoryView":1362 + * + * @cname('__pyx_memoryview_refcount_copying') + * cdef void refcount_copying(__Pyx_memviewslice *dst, bint dtype_is_object, # <<<<<<<<<<<<<< + * int ndim, bint inc) nogil: + * + */ + +static void __pyx_memoryview_refcount_copying(__Pyx_memviewslice *__pyx_v_dst, int __pyx_v_dtype_is_object, int __pyx_v_ndim, int __pyx_v_inc) { + int __pyx_t_1; + + /* "View.MemoryView":1366 + * + * + * if dtype_is_object: # <<<<<<<<<<<<<< + * refcount_objects_in_slice_with_gil(dst.data, dst.shape, + * dst.strides, ndim, inc) + */ + __pyx_t_1 = (__pyx_v_dtype_is_object != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":1367 + * + * if dtype_is_object: + * refcount_objects_in_slice_with_gil(dst.data, dst.shape, # <<<<<<<<<<<<<< + * dst.strides, ndim, inc) + * + */ + __pyx_memoryview_refcount_objects_in_slice_with_gil(__pyx_v_dst->data, __pyx_v_dst->shape, __pyx_v_dst->strides, __pyx_v_ndim, __pyx_v_inc); + + /* "View.MemoryView":1366 + * + * + * if dtype_is_object: # <<<<<<<<<<<<<< + * refcount_objects_in_slice_with_gil(dst.data, dst.shape, + * dst.strides, ndim, inc) + */ + } + + /* "View.MemoryView":1362 + * + * @cname('__pyx_memoryview_refcount_copying') + * cdef void refcount_copying(__Pyx_memviewslice *dst, bint dtype_is_object, # <<<<<<<<<<<<<< + * int ndim, bint inc) nogil: + * + */ + + /* function exit code */ +} + +/* "View.MemoryView":1371 + * + * @cname('__pyx_memoryview_refcount_objects_in_slice_with_gil') + * cdef void refcount_objects_in_slice_with_gil(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< + * Py_ssize_t *strides, int ndim, + * bint inc) with gil: + */ + +static void __pyx_memoryview_refcount_objects_in_slice_with_gil(char *__pyx_v_data, Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, int __pyx_v_ndim, int __pyx_v_inc) { + __Pyx_RefNannyDeclarations + #ifdef WITH_THREAD + PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); + #endif + __Pyx_RefNannySetupContext("refcount_objects_in_slice_with_gil", 0); + + /* "View.MemoryView":1374 + * Py_ssize_t *strides, int ndim, + * bint inc) with gil: + * refcount_objects_in_slice(data, shape, strides, ndim, inc) # <<<<<<<<<<<<<< + * + * @cname('__pyx_memoryview_refcount_objects_in_slice') + */ + __pyx_memoryview_refcount_objects_in_slice(__pyx_v_data, __pyx_v_shape, __pyx_v_strides, __pyx_v_ndim, __pyx_v_inc); + + /* "View.MemoryView":1371 + * + * @cname('__pyx_memoryview_refcount_objects_in_slice_with_gil') + * cdef void refcount_objects_in_slice_with_gil(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< + * Py_ssize_t *strides, int ndim, + * bint inc) with gil: + */ + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + #ifdef WITH_THREAD + __Pyx_PyGILState_Release(__pyx_gilstate_save); + #endif +} + +/* "View.MemoryView":1377 + * + * @cname('__pyx_memoryview_refcount_objects_in_slice') + * cdef void refcount_objects_in_slice(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< + * Py_ssize_t *strides, int ndim, bint inc): + * cdef Py_ssize_t i + */ + +static void __pyx_memoryview_refcount_objects_in_slice(char *__pyx_v_data, Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, int __pyx_v_ndim, int __pyx_v_inc) { + CYTHON_UNUSED Py_ssize_t __pyx_v_i; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + Py_ssize_t __pyx_t_2; + Py_ssize_t __pyx_t_3; + int __pyx_t_4; + __Pyx_RefNannySetupContext("refcount_objects_in_slice", 0); + + /* "View.MemoryView":1381 + * cdef Py_ssize_t i + * + * for i in range(shape[0]): # <<<<<<<<<<<<<< + * if ndim == 1: + * if inc: + */ + __pyx_t_1 = (__pyx_v_shape[0]); + __pyx_t_2 = __pyx_t_1; + for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { + __pyx_v_i = __pyx_t_3; + + /* "View.MemoryView":1382 + * + * for i in range(shape[0]): + * if ndim == 1: # <<<<<<<<<<<<<< + * if inc: + * Py_INCREF(( data)[0]) + */ + __pyx_t_4 = ((__pyx_v_ndim == 1) != 0); + if (__pyx_t_4) { + + /* "View.MemoryView":1383 + * for i in range(shape[0]): + * if ndim == 1: + * if inc: # <<<<<<<<<<<<<< + * Py_INCREF(( data)[0]) + * else: + */ + __pyx_t_4 = (__pyx_v_inc != 0); + if (__pyx_t_4) { + + /* "View.MemoryView":1384 + * if ndim == 1: + * if inc: + * Py_INCREF(( data)[0]) # <<<<<<<<<<<<<< + * else: + * Py_DECREF(( data)[0]) + */ + Py_INCREF((((PyObject **)__pyx_v_data)[0])); + + /* "View.MemoryView":1383 + * for i in range(shape[0]): + * if ndim == 1: + * if inc: # <<<<<<<<<<<<<< + * Py_INCREF(( data)[0]) + * else: + */ + goto __pyx_L6; + } + + /* "View.MemoryView":1386 + * Py_INCREF(( data)[0]) + * else: + * Py_DECREF(( data)[0]) # <<<<<<<<<<<<<< + * else: + * refcount_objects_in_slice(data, shape + 1, strides + 1, + */ + /*else*/ { + Py_DECREF((((PyObject **)__pyx_v_data)[0])); + } + __pyx_L6:; + + /* "View.MemoryView":1382 + * + * for i in range(shape[0]): + * if ndim == 1: # <<<<<<<<<<<<<< + * if inc: + * Py_INCREF(( data)[0]) + */ + goto __pyx_L5; + } + + /* "View.MemoryView":1388 + * Py_DECREF(( data)[0]) + * else: + * refcount_objects_in_slice(data, shape + 1, strides + 1, # <<<<<<<<<<<<<< + * ndim - 1, inc) + * + */ + /*else*/ { + + /* "View.MemoryView":1389 + * else: + * refcount_objects_in_slice(data, shape + 1, strides + 1, + * ndim - 1, inc) # <<<<<<<<<<<<<< + * + * data += strides[0] + */ + __pyx_memoryview_refcount_objects_in_slice(__pyx_v_data, (__pyx_v_shape + 1), (__pyx_v_strides + 1), (__pyx_v_ndim - 1), __pyx_v_inc); + } + __pyx_L5:; + + /* "View.MemoryView":1391 + * ndim - 1, inc) + * + * data += strides[0] # <<<<<<<<<<<<<< + * + * + */ + __pyx_v_data = (__pyx_v_data + (__pyx_v_strides[0])); + } + + /* "View.MemoryView":1377 + * + * @cname('__pyx_memoryview_refcount_objects_in_slice') + * cdef void refcount_objects_in_slice(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< + * Py_ssize_t *strides, int ndim, bint inc): + * cdef Py_ssize_t i + */ + + /* function exit code */ + __Pyx_RefNannyFinishContext(); +} + +/* "View.MemoryView":1397 + * + * @cname('__pyx_memoryview_slice_assign_scalar') + * cdef void slice_assign_scalar(__Pyx_memviewslice *dst, int ndim, # <<<<<<<<<<<<<< + * size_t itemsize, void *item, + * bint dtype_is_object) nogil: + */ + +static void __pyx_memoryview_slice_assign_scalar(__Pyx_memviewslice *__pyx_v_dst, int __pyx_v_ndim, size_t __pyx_v_itemsize, void *__pyx_v_item, int __pyx_v_dtype_is_object) { + + /* "View.MemoryView":1400 + * size_t itemsize, void *item, + * bint dtype_is_object) nogil: + * refcount_copying(dst, dtype_is_object, ndim, False) # <<<<<<<<<<<<<< + * _slice_assign_scalar(dst.data, dst.shape, dst.strides, ndim, + * itemsize, item) + */ + __pyx_memoryview_refcount_copying(__pyx_v_dst, __pyx_v_dtype_is_object, __pyx_v_ndim, 0); + + /* "View.MemoryView":1401 + * bint dtype_is_object) nogil: + * refcount_copying(dst, dtype_is_object, ndim, False) + * _slice_assign_scalar(dst.data, dst.shape, dst.strides, ndim, # <<<<<<<<<<<<<< + * itemsize, item) + * refcount_copying(dst, dtype_is_object, ndim, True) + */ + __pyx_memoryview__slice_assign_scalar(__pyx_v_dst->data, __pyx_v_dst->shape, __pyx_v_dst->strides, __pyx_v_ndim, __pyx_v_itemsize, __pyx_v_item); + + /* "View.MemoryView":1403 + * _slice_assign_scalar(dst.data, dst.shape, dst.strides, ndim, + * itemsize, item) + * refcount_copying(dst, dtype_is_object, ndim, True) # <<<<<<<<<<<<<< + * + * + */ + __pyx_memoryview_refcount_copying(__pyx_v_dst, __pyx_v_dtype_is_object, __pyx_v_ndim, 1); + + /* "View.MemoryView":1397 + * + * @cname('__pyx_memoryview_slice_assign_scalar') + * cdef void slice_assign_scalar(__Pyx_memviewslice *dst, int ndim, # <<<<<<<<<<<<<< + * size_t itemsize, void *item, + * bint dtype_is_object) nogil: + */ + + /* function exit code */ +} + +/* "View.MemoryView":1407 + * + * @cname('__pyx_memoryview__slice_assign_scalar') + * cdef void _slice_assign_scalar(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< + * Py_ssize_t *strides, int ndim, + * size_t itemsize, void *item) nogil: + */ + +static void __pyx_memoryview__slice_assign_scalar(char *__pyx_v_data, Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, int __pyx_v_ndim, size_t __pyx_v_itemsize, void *__pyx_v_item) { + CYTHON_UNUSED Py_ssize_t __pyx_v_i; + Py_ssize_t __pyx_v_stride; + Py_ssize_t __pyx_v_extent; + int __pyx_t_1; + Py_ssize_t __pyx_t_2; + Py_ssize_t __pyx_t_3; + Py_ssize_t __pyx_t_4; + + /* "View.MemoryView":1411 + * size_t itemsize, void *item) nogil: + * cdef Py_ssize_t i + * cdef Py_ssize_t stride = strides[0] # <<<<<<<<<<<<<< + * cdef Py_ssize_t extent = shape[0] + * + */ + __pyx_v_stride = (__pyx_v_strides[0]); + + /* "View.MemoryView":1412 + * cdef Py_ssize_t i + * cdef Py_ssize_t stride = strides[0] + * cdef Py_ssize_t extent = shape[0] # <<<<<<<<<<<<<< + * + * if ndim == 1: + */ + __pyx_v_extent = (__pyx_v_shape[0]); + + /* "View.MemoryView":1414 + * cdef Py_ssize_t extent = shape[0] + * + * if ndim == 1: # <<<<<<<<<<<<<< + * for i in range(extent): + * memcpy(data, item, itemsize) + */ + __pyx_t_1 = ((__pyx_v_ndim == 1) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":1415 + * + * if ndim == 1: + * for i in range(extent): # <<<<<<<<<<<<<< + * memcpy(data, item, itemsize) + * data += stride + */ + __pyx_t_2 = __pyx_v_extent; + __pyx_t_3 = __pyx_t_2; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_i = __pyx_t_4; + + /* "View.MemoryView":1416 + * if ndim == 1: + * for i in range(extent): + * memcpy(data, item, itemsize) # <<<<<<<<<<<<<< + * data += stride + * else: + */ + (void)(memcpy(__pyx_v_data, __pyx_v_item, __pyx_v_itemsize)); + + /* "View.MemoryView":1417 + * for i in range(extent): + * memcpy(data, item, itemsize) + * data += stride # <<<<<<<<<<<<<< + * else: + * for i in range(extent): + */ + __pyx_v_data = (__pyx_v_data + __pyx_v_stride); + } + + /* "View.MemoryView":1414 + * cdef Py_ssize_t extent = shape[0] + * + * if ndim == 1: # <<<<<<<<<<<<<< + * for i in range(extent): + * memcpy(data, item, itemsize) + */ + goto __pyx_L3; + } + + /* "View.MemoryView":1419 + * data += stride + * else: + * for i in range(extent): # <<<<<<<<<<<<<< + * _slice_assign_scalar(data, shape + 1, strides + 1, + * ndim - 1, itemsize, item) + */ + /*else*/ { + __pyx_t_2 = __pyx_v_extent; + __pyx_t_3 = __pyx_t_2; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_i = __pyx_t_4; + + /* "View.MemoryView":1420 + * else: + * for i in range(extent): + * _slice_assign_scalar(data, shape + 1, strides + 1, # <<<<<<<<<<<<<< + * ndim - 1, itemsize, item) + * data += stride + */ + __pyx_memoryview__slice_assign_scalar(__pyx_v_data, (__pyx_v_shape + 1), (__pyx_v_strides + 1), (__pyx_v_ndim - 1), __pyx_v_itemsize, __pyx_v_item); + + /* "View.MemoryView":1422 + * _slice_assign_scalar(data, shape + 1, strides + 1, + * ndim - 1, itemsize, item) + * data += stride # <<<<<<<<<<<<<< + * + * + */ + __pyx_v_data = (__pyx_v_data + __pyx_v_stride); + } + } + __pyx_L3:; + + /* "View.MemoryView":1407 + * + * @cname('__pyx_memoryview__slice_assign_scalar') + * cdef void _slice_assign_scalar(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< + * Py_ssize_t *strides, int ndim, + * size_t itemsize, void *item) nogil: + */ + + /* function exit code */ +} + +/* "(tree fragment)":1 + * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15View_dot_MemoryView_1__pyx_unpickle_Enum(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_15View_dot_MemoryView_1__pyx_unpickle_Enum = {"__pyx_unpickle_Enum", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15View_dot_MemoryView_1__pyx_unpickle_Enum, METH_VARARGS|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_15View_dot_MemoryView_1__pyx_unpickle_Enum(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v___pyx_type = 0; + long __pyx_v___pyx_checksum; + PyObject *__pyx_v___pyx_state = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__pyx_unpickle_Enum (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,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_pyx_type)) != 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_pyx_checksum)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Enum", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Enum", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_Enum") < 0)) __PYX_ERR(2, 1, __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___pyx_type = values[0]; + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error) + __pyx_v___pyx_state = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Enum", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("View.MemoryView.__pyx_unpickle_Enum", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_15View_dot_MemoryView___pyx_unpickle_Enum(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15View_dot_MemoryView___pyx_unpickle_Enum(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_v___pyx_PickleError = 0; + PyObject *__pyx_v___pyx_result = 0; + 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; + int __pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__pyx_unpickle_Enum", 0); + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum != 0xb068931: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) + */ + __pyx_t_1 = ((__pyx_v___pyx_checksum != 0xb068931) != 0); + if (__pyx_t_1) { + + /* "(tree fragment)":5 + * cdef object __pyx_result + * if __pyx_checksum != 0xb068931: + * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) + * __pyx_result = Enum.__new__(__pyx_type) + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_PickleError); + __Pyx_GIVEREF(__pyx_n_s_PickleError); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_2); + __pyx_v___pyx_PickleError = __pyx_t_2; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":6 + * if __pyx_checksum != 0xb068931: + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) # <<<<<<<<<<<<<< + * __pyx_result = Enum.__new__(__pyx_type) + * if __pyx_state is not None: + */ + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xb0, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_INCREF(__pyx_v___pyx_PickleError); + __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(2, 6, __pyx_L1_error) + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum != 0xb068931: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) + */ + } + + /* "(tree fragment)":7 + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) + * __pyx_result = Enum.__new__(__pyx_type) # <<<<<<<<<<<<<< + * if __pyx_state is not None: + * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_MemviewEnum_type), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v___pyx_result = __pyx_t_3; + __pyx_t_3 = 0; + + /* "(tree fragment)":8 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) + * __pyx_result = Enum.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + __pyx_t_1 = (__pyx_v___pyx_state != Py_None); + __pyx_t_6 = (__pyx_t_1 != 0); + if (__pyx_t_6) { + + /* "(tree fragment)":9 + * __pyx_result = Enum.__new__(__pyx_type) + * if __pyx_state is not None: + * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< + * return __pyx_result + * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 9, __pyx_L1_error) + __pyx_t_3 = __pyx_unpickle_Enum__set_state(((struct __pyx_MemviewEnum_obj *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":8 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) + * __pyx_result = Enum.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + } + + /* "(tree fragment)":10 + * if __pyx_state is not None: + * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) + * return __pyx_result # <<<<<<<<<<<<<< + * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): + * __pyx_result.name = __pyx_state[0] + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v___pyx_result); + __pyx_r = __pyx_v___pyx_result; + goto __pyx_L0; + + /* "(tree fragment)":1 + * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("View.MemoryView.__pyx_unpickle_Enum", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v___pyx_PickleError); + __Pyx_XDECREF(__pyx_v___pyx_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":11 + * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result.name = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + */ + +static PyObject *__pyx_unpickle_Enum__set_state(struct __pyx_MemviewEnum_obj *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + Py_ssize_t __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__pyx_unpickle_Enum__set_state", 0); + + /* "(tree fragment)":12 + * return __pyx_result + * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): + * __pyx_result.name = __pyx_state[0] # <<<<<<<<<<<<<< + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[1]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->name); + __Pyx_DECREF(__pyx_v___pyx_result->name); + __pyx_v___pyx_result->name = __pyx_t_1; + __pyx_t_1 = 0; + + /* "(tree fragment)":13 + * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): + * __pyx_result.name = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[1]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + __PYX_ERR(2, 13, __pyx_L1_error) + } + __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(2, 13, __pyx_L1_error) + __pyx_t_4 = ((__pyx_t_3 > 1) != 0); + if (__pyx_t_4) { + } else { + __pyx_t_2 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(2, 13, __pyx_L1_error) + __pyx_t_5 = (__pyx_t_4 != 0); + __pyx_t_2 = __pyx_t_5; + __pyx_L4_bool_binop_done:; + if (__pyx_t_2) { + + /* "(tree fragment)":14 + * __pyx_result.name = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[1]) # <<<<<<<<<<<<<< + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 14, __pyx_L1_error) + } + __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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); + } + } + __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":13 + * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): + * __pyx_result.name = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[1]) + */ + } + + /* "(tree fragment)":11 + * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result.name = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + */ + + /* 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_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("View.MemoryView.__pyx_unpickle_Enum__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static struct __pyx_vtabstruct_array __pyx_vtable_array; + +static PyObject *__pyx_tp_new_array(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_array_obj *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_array_obj *)o); + p->__pyx_vtab = __pyx_vtabptr_array; + p->mode = ((PyObject*)Py_None); Py_INCREF(Py_None); + p->_format = ((PyObject*)Py_None); Py_INCREF(Py_None); + if (unlikely(__pyx_array___cinit__(o, a, k) < 0)) goto bad; + return o; + bad: + Py_DECREF(o); o = 0; + return NULL; +} + +static void __pyx_tp_dealloc_array(PyObject *o) { + struct __pyx_array_obj *p = (struct __pyx_array_obj *)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); + __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1); + __pyx_array___dealloc__(o); + __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1); + PyErr_Restore(etype, eval, etb); + } + Py_CLEAR(p->mode); + Py_CLEAR(p->_format); + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_array(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_array(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_array___setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %.200s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyObject *__pyx_tp_getattro_array(PyObject *o, PyObject *n) { + PyObject *v = __Pyx_PyObject_GenericGetAttr(o, n); + if (!v && PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Clear(); + v = __pyx_array___getattr__(o, n); + } + return v; +} + +static PyObject *__pyx_getprop___pyx_array_memview(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_15View_dot_MemoryView_5array_7memview_1__get__(o); +} + +static PyMethodDef __pyx_methods_array[] = { + {"__getattr__", (PyCFunction)__pyx_array___getattr__, METH_O|METH_COEXIST, 0}, + {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_array_1__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_array_3__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_array[] = { + {(char *)"memview", __pyx_getprop___pyx_array_memview, 0, (char *)0, 0}, + {0, 0, 0, 0, 0} +}; + +static PySequenceMethods __pyx_tp_as_sequence_array = { + __pyx_array___len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_array, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + 0, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_array = { + __pyx_array___len__, /*mp_length*/ + __pyx_array___getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_array, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_array = { + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getreadbuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getwritebuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getsegcount*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getcharbuffer*/ + #endif + __pyx_array_getbuffer, /*bf_getbuffer*/ + 0, /*bf_releasebuffer*/ +}; + +static PyTypeObject __pyx_type___pyx_array = { + PyVarObject_HEAD_INIT(0, 0) + "pygeoprocessing.geoprocessing_core.array", /*tp_name*/ + sizeof(struct __pyx_array_obj), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_array, /*tp_dealloc*/ + #if PY_VERSION_HEX < 0x030800b4 + 0, /*tp_print*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 + 0, /*tp_vectorcall_offset*/ + #endif + 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*/ + &__pyx_tp_as_sequence_array, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_array, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + __pyx_tp_getattro_array, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_array, /*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_array, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_array, /*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_array, /*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 + #if PY_VERSION_HEX >= 0x030800b1 + 0, /*tp_vectorcall*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000 + 0, /*tp_print*/ + #endif +}; + +static PyObject *__pyx_tp_new_Enum(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_MemviewEnum_obj *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_MemviewEnum_obj *)o); + p->name = Py_None; Py_INCREF(Py_None); + return o; +} + +static void __pyx_tp_dealloc_Enum(PyObject *o) { + struct __pyx_MemviewEnum_obj *p = (struct __pyx_MemviewEnum_obj *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + PyObject_GC_UnTrack(o); + Py_CLEAR(p->name); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_Enum(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_MemviewEnum_obj *p = (struct __pyx_MemviewEnum_obj *)o; + if (p->name) { + e = (*v)(p->name, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_Enum(PyObject *o) { + PyObject* tmp; + struct __pyx_MemviewEnum_obj *p = (struct __pyx_MemviewEnum_obj *)o; + tmp = ((PyObject*)p->name); + p->name = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_Enum[] = { + {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_MemviewEnum_1__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_MemviewEnum_3__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type___pyx_MemviewEnum = { + PyVarObject_HEAD_INIT(0, 0) + "pygeoprocessing.geoprocessing_core.Enum", /*tp_name*/ + sizeof(struct __pyx_MemviewEnum_obj), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_Enum, /*tp_dealloc*/ + #if PY_VERSION_HEX < 0x030800b4 + 0, /*tp_print*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 + 0, /*tp_vectorcall_offset*/ + #endif + 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 + __pyx_MemviewEnum___repr__, /*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|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_Enum, /*tp_traverse*/ + __pyx_tp_clear_Enum, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_Enum, /*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*/ + __pyx_MemviewEnum___init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_Enum, /*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 + #if PY_VERSION_HEX >= 0x030800b1 + 0, /*tp_vectorcall*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000 + 0, /*tp_print*/ + #endif +}; +static struct __pyx_vtabstruct_memoryview __pyx_vtable_memoryview; + +static PyObject *__pyx_tp_new_memoryview(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_memoryview_obj *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_memoryview_obj *)o); + p->__pyx_vtab = __pyx_vtabptr_memoryview; + p->obj = Py_None; Py_INCREF(Py_None); + p->_size = Py_None; Py_INCREF(Py_None); + p->_array_interface = Py_None; Py_INCREF(Py_None); + p->view.obj = NULL; + if (unlikely(__pyx_memoryview___cinit__(o, a, k) < 0)) goto bad; + return o; + bad: + Py_DECREF(o); o = 0; + return NULL; +} + +static void __pyx_tp_dealloc_memoryview(PyObject *o) { + struct __pyx_memoryview_obj *p = (struct __pyx_memoryview_obj *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + PyObject_GC_UnTrack(o); + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1); + __pyx_memoryview___dealloc__(o); + __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1); + PyErr_Restore(etype, eval, etb); + } + Py_CLEAR(p->obj); + Py_CLEAR(p->_size); + Py_CLEAR(p->_array_interface); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_memoryview(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_memoryview_obj *p = (struct __pyx_memoryview_obj *)o; + if (p->obj) { + e = (*v)(p->obj, a); if (e) return e; + } + if (p->_size) { + e = (*v)(p->_size, a); if (e) return e; + } + if (p->_array_interface) { + e = (*v)(p->_array_interface, a); if (e) return e; + } + if (p->view.obj) { + e = (*v)(p->view.obj, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_memoryview(PyObject *o) { + PyObject* tmp; + struct __pyx_memoryview_obj *p = (struct __pyx_memoryview_obj *)o; + tmp = ((PyObject*)p->obj); + p->obj = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->_size); + p->_size = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->_array_interface); + p->_array_interface = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + Py_CLEAR(p->view.obj); + return 0; +} +static PyObject *__pyx_sq_item_memoryview(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_memoryview(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_memoryview___setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %.200s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyObject *__pyx_getprop___pyx_memoryview_T(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_15View_dot_MemoryView_10memoryview_1T_1__get__(o); +} + +static PyObject *__pyx_getprop___pyx_memoryview_base(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_15View_dot_MemoryView_10memoryview_4base_1__get__(o); +} + +static PyObject *__pyx_getprop___pyx_memoryview_shape(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_15View_dot_MemoryView_10memoryview_5shape_1__get__(o); +} + +static PyObject *__pyx_getprop___pyx_memoryview_strides(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_15View_dot_MemoryView_10memoryview_7strides_1__get__(o); +} + +static PyObject *__pyx_getprop___pyx_memoryview_suboffsets(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_15View_dot_MemoryView_10memoryview_10suboffsets_1__get__(o); +} + +static PyObject *__pyx_getprop___pyx_memoryview_ndim(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_15View_dot_MemoryView_10memoryview_4ndim_1__get__(o); +} + +static PyObject *__pyx_getprop___pyx_memoryview_itemsize(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_15View_dot_MemoryView_10memoryview_8itemsize_1__get__(o); +} + +static PyObject *__pyx_getprop___pyx_memoryview_nbytes(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_15View_dot_MemoryView_10memoryview_6nbytes_1__get__(o); +} + +static PyObject *__pyx_getprop___pyx_memoryview_size(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_15View_dot_MemoryView_10memoryview_4size_1__get__(o); +} + +static PyMethodDef __pyx_methods_memoryview[] = { + {"is_c_contig", (PyCFunction)__pyx_memoryview_is_c_contig, METH_NOARGS, 0}, + {"is_f_contig", (PyCFunction)__pyx_memoryview_is_f_contig, METH_NOARGS, 0}, + {"copy", (PyCFunction)__pyx_memoryview_copy, METH_NOARGS, 0}, + {"copy_fortran", (PyCFunction)__pyx_memoryview_copy_fortran, METH_NOARGS, 0}, + {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_memoryview_1__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_memoryview_3__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_memoryview[] = { + {(char *)"T", __pyx_getprop___pyx_memoryview_T, 0, (char *)0, 0}, + {(char *)"base", __pyx_getprop___pyx_memoryview_base, 0, (char *)0, 0}, + {(char *)"shape", __pyx_getprop___pyx_memoryview_shape, 0, (char *)0, 0}, + {(char *)"strides", __pyx_getprop___pyx_memoryview_strides, 0, (char *)0, 0}, + {(char *)"suboffsets", __pyx_getprop___pyx_memoryview_suboffsets, 0, (char *)0, 0}, + {(char *)"ndim", __pyx_getprop___pyx_memoryview_ndim, 0, (char *)0, 0}, + {(char *)"itemsize", __pyx_getprop___pyx_memoryview_itemsize, 0, (char *)0, 0}, + {(char *)"nbytes", __pyx_getprop___pyx_memoryview_nbytes, 0, (char *)0, 0}, + {(char *)"size", __pyx_getprop___pyx_memoryview_size, 0, (char *)0, 0}, + {0, 0, 0, 0, 0} +}; + +static PySequenceMethods __pyx_tp_as_sequence_memoryview = { + __pyx_memoryview___len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_memoryview, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + 0, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_memoryview = { + __pyx_memoryview___len__, /*mp_length*/ + __pyx_memoryview___getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_memoryview, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_memoryview = { + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getreadbuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getwritebuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getsegcount*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getcharbuffer*/ + #endif + __pyx_memoryview_getbuffer, /*bf_getbuffer*/ + 0, /*bf_releasebuffer*/ +}; + +static PyTypeObject __pyx_type___pyx_memoryview = { + PyVarObject_HEAD_INIT(0, 0) + "pygeoprocessing.geoprocessing_core.memoryview", /*tp_name*/ + sizeof(struct __pyx_memoryview_obj), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_memoryview, /*tp_dealloc*/ + #if PY_VERSION_HEX < 0x030800b4 + 0, /*tp_print*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 + 0, /*tp_vectorcall_offset*/ + #endif + 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 + __pyx_memoryview___repr__, /*tp_repr*/ + 0, /*tp_as_number*/ + &__pyx_tp_as_sequence_memoryview, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_memoryview, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + __pyx_memoryview___str__, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_memoryview, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_memoryview, /*tp_traverse*/ + __pyx_tp_clear_memoryview, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_memoryview, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_memoryview, /*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_memoryview, /*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 + #if PY_VERSION_HEX >= 0x030800b1 + 0, /*tp_vectorcall*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000 + 0, /*tp_print*/ + #endif +}; +static struct __pyx_vtabstruct__memoryviewslice __pyx_vtable__memoryviewslice; + +static PyObject *__pyx_tp_new__memoryviewslice(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_memoryviewslice_obj *p; + PyObject *o = __pyx_tp_new_memoryview(t, a, k); + if (unlikely(!o)) return 0; + p = ((struct __pyx_memoryviewslice_obj *)o); + p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_memoryview*)__pyx_vtabptr__memoryviewslice; + p->from_object = Py_None; Py_INCREF(Py_None); + p->from_slice.memview = NULL; + return o; +} + +static void __pyx_tp_dealloc__memoryviewslice(PyObject *o) { + struct __pyx_memoryviewslice_obj *p = (struct __pyx_memoryviewslice_obj *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + PyObject_GC_UnTrack(o); + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1); + __pyx_memoryviewslice___dealloc__(o); + __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1); + PyErr_Restore(etype, eval, etb); + } + Py_CLEAR(p->from_object); + PyObject_GC_Track(o); + __pyx_tp_dealloc_memoryview(o); +} + +static int __pyx_tp_traverse__memoryviewslice(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_memoryviewslice_obj *p = (struct __pyx_memoryviewslice_obj *)o; + e = __pyx_tp_traverse_memoryview(o, v, a); if (e) return e; + if (p->from_object) { + e = (*v)(p->from_object, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear__memoryviewslice(PyObject *o) { + PyObject* tmp; + struct __pyx_memoryviewslice_obj *p = (struct __pyx_memoryviewslice_obj *)o; + __pyx_tp_clear_memoryview(o); + tmp = ((PyObject*)p->from_object); + p->from_object = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + __PYX_XDEC_MEMVIEW(&p->from_slice, 1); + return 0; +} + +static PyObject *__pyx_getprop___pyx_memoryviewslice_base(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_15View_dot_MemoryView_16_memoryviewslice_4base_1__get__(o); +} + +static PyMethodDef __pyx_methods__memoryviewslice[] = { + {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_memoryviewslice_1__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_memoryviewslice_3__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets__memoryviewslice[] = { + {(char *)"base", __pyx_getprop___pyx_memoryviewslice_base, 0, (char *)0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type___pyx_memoryviewslice = { + PyVarObject_HEAD_INIT(0, 0) + "pygeoprocessing.geoprocessing_core._memoryviewslice", /*tp_name*/ + sizeof(struct __pyx_memoryviewslice_obj), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc__memoryviewslice, /*tp_dealloc*/ + #if PY_VERSION_HEX < 0x030800b4 + 0, /*tp_print*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 + 0, /*tp_vectorcall_offset*/ + #endif + 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 + #if CYTHON_COMPILING_IN_PYPY + __pyx_memoryview___repr__, /*tp_repr*/ + #else + 0, /*tp_repr*/ + #endif + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + #if CYTHON_COMPILING_IN_PYPY + __pyx_memoryview___str__, /*tp_str*/ + #else + 0, /*tp_str*/ + #endif + 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|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + "Internal class for passing memoryview slices to Python", /*tp_doc*/ + __pyx_tp_traverse__memoryviewslice, /*tp_traverse*/ + __pyx_tp_clear__memoryviewslice, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods__memoryviewslice, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets__memoryviewslice, /*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__memoryviewslice, /*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 + #if PY_VERSION_HEX >= 0x030800b1 + 0, /*tp_vectorcall*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000 + 0, /*tp_print*/ + #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_geoprocessing_core(PyObject* module); /*proto*/ +static PyModuleDef_Slot __pyx_moduledef_slots[] = { + {Py_mod_create, (void*)__pyx_pymod_create}, + {Py_mod_exec, (void*)__pyx_pymod_exec_geoprocessing_core}, + {0, NULL} +}; +#endif + +static struct PyModuleDef __pyx_moduledef = { + PyModuleDef_HEAD_INIT, + "geoprocessing_core", + 0, /* 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 +#ifndef CYTHON_SMALL_CODE +#if defined(__clang__) + #define CYTHON_SMALL_CODE +#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) + #define CYTHON_SMALL_CODE __attribute__((cold)) +#else + #define CYTHON_SMALL_CODE +#endif +#endif + +static __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_kp_u_1f, __pyx_k_1f, sizeof(__pyx_k_1f), 0, 1, 0, 0}, + {&__pyx_n_s_ASCII, __pyx_k_ASCII, sizeof(__pyx_k_ASCII), 0, 0, 1, 1}, + {&__pyx_kp_u_BIGTIFF_YES, __pyx_k_BIGTIFF_YES, sizeof(__pyx_k_BIGTIFF_YES), 0, 1, 0, 0}, + {&__pyx_kp_u_BLOCKXSIZE_256, __pyx_k_BLOCKXSIZE_256, sizeof(__pyx_k_BLOCKXSIZE_256), 0, 1, 0, 0}, + {&__pyx_kp_u_BLOCKYSIZE_256, __pyx_k_BLOCKYSIZE_256, sizeof(__pyx_k_BLOCKYSIZE_256), 0, 1, 0, 0}, + {&__pyx_kp_s_Buffer_view_does_not_expose_stri, __pyx_k_Buffer_view_does_not_expose_stri, sizeof(__pyx_k_Buffer_view_does_not_expose_stri), 0, 0, 1, 0}, + {&__pyx_kp_u_COMPRESS_LZW, __pyx_k_COMPRESS_LZW, sizeof(__pyx_k_COMPRESS_LZW), 0, 1, 0, 0}, + {&__pyx_kp_s_Can_only_create_a_buffer_that_is, __pyx_k_Can_only_create_a_buffer_that_is, sizeof(__pyx_k_Can_only_create_a_buffer_that_is), 0, 0, 1, 0}, + {&__pyx_kp_s_Cannot_assign_to_read_only_memor, __pyx_k_Cannot_assign_to_read_only_memor, sizeof(__pyx_k_Cannot_assign_to_read_only_memor), 0, 0, 1, 0}, + {&__pyx_kp_s_Cannot_create_writable_memory_vi, __pyx_k_Cannot_create_writable_memory_vi, sizeof(__pyx_k_Cannot_create_writable_memory_vi), 0, 0, 1, 0}, + {&__pyx_kp_s_Cannot_index_with_type_s, __pyx_k_Cannot_index_with_type_s, sizeof(__pyx_k_Cannot_index_with_type_s), 0, 0, 1, 0}, + {&__pyx_kp_u_Cannot_process_raster_type_s_not, __pyx_k_Cannot_process_raster_type_s_not, sizeof(__pyx_k_Cannot_process_raster_type_s_not), 0, 1, 0, 0}, + {&__pyx_n_s_ComputeStatistics, __pyx_k_ComputeStatistics, sizeof(__pyx_k_ComputeStatistics), 0, 0, 1, 1}, + {&__pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT, __pyx_k_DEFAULT_GTIFF_CREATION_TUPLE_OPT, sizeof(__pyx_k_DEFAULT_GTIFF_CREATION_TUPLE_OPT), 0, 0, 1, 1}, + {&__pyx_n_s_DEFAULT_OSR_AXIS_MAPPING_STRATEG, __pyx_k_DEFAULT_OSR_AXIS_MAPPING_STRATEG, sizeof(__pyx_k_DEFAULT_OSR_AXIS_MAPPING_STRATEG), 0, 0, 1, 1}, + {&__pyx_kp_u_Distance_Transform_Phase_2, __pyx_k_Distance_Transform_Phase_2, sizeof(__pyx_k_Distance_Transform_Phase_2), 0, 1, 0, 0}, + {&__pyx_n_s_Ellipsis, __pyx_k_Ellipsis, sizeof(__pyx_k_Ellipsis), 0, 0, 1, 1}, + {&__pyx_kp_s_Empty_shape_tuple_for_cython_arr, __pyx_k_Empty_shape_tuple_for_cython_arr, sizeof(__pyx_k_Empty_shape_tuple_for_cython_arr), 0, 0, 1, 0}, + {&__pyx_n_s_FlushCache, __pyx_k_FlushCache, sizeof(__pyx_k_FlushCache), 0, 0, 1, 1}, + {&__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_Float32, __pyx_k_GDT_Float32, sizeof(__pyx_k_GDT_Float32), 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_Int16, __pyx_k_GDT_Int16, sizeof(__pyx_k_GDT_Int16), 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_GDT_UInt16, __pyx_k_GDT_UInt16, sizeof(__pyx_k_GDT_UInt16), 0, 0, 1, 1}, + {&__pyx_n_s_GDT_UInt32, __pyx_k_GDT_UInt32, sizeof(__pyx_k_GDT_UInt32), 0, 0, 1, 1}, + {&__pyx_n_u_GTIFF, __pyx_k_GTIFF, sizeof(__pyx_k_GTIFF), 0, 1, 0, 1}, + {&__pyx_n_s_GetBlockSize, __pyx_k_GetBlockSize, sizeof(__pyx_k_GetBlockSize), 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_kp_s_Incompatible_checksums_s_vs_0xb0, __pyx_k_Incompatible_checksums_s_vs_0xb0, sizeof(__pyx_k_Incompatible_checksums_s_vs_0xb0), 0, 0, 1, 0}, + {&__pyx_n_s_IndexError, __pyx_k_IndexError, sizeof(__pyx_k_IndexError), 0, 0, 1, 1}, + {&__pyx_kp_s_Indirect_dimensions_not_supporte, __pyx_k_Indirect_dimensions_not_supporte, sizeof(__pyx_k_Indirect_dimensions_not_supporte), 0, 0, 1, 0}, + {&__pyx_kp_s_Invalid_mode_expected_c_or_fortr, __pyx_k_Invalid_mode_expected_c_or_fortr, sizeof(__pyx_k_Invalid_mode_expected_c_or_fortr), 0, 0, 1, 0}, + {&__pyx_kp_s_Invalid_shape_in_axis_d_d, __pyx_k_Invalid_shape_in_axis_d_d, sizeof(__pyx_k_Invalid_shape_in_axis_d_d), 0, 0, 1, 0}, + {&__pyx_n_s_LOGGER, __pyx_k_LOGGER, sizeof(__pyx_k_LOGGER), 0, 0, 1, 1}, + {&__pyx_n_s_M_last, __pyx_k_M_last, sizeof(__pyx_k_M_last), 0, 0, 1, 1}, + {&__pyx_n_s_M_local, __pyx_k_M_local, sizeof(__pyx_k_M_local), 0, 0, 1, 1}, + {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1}, + {&__pyx_kp_s_MemoryView_of_r_at_0x_x, __pyx_k_MemoryView_of_r_at_0x_x, sizeof(__pyx_k_MemoryView_of_r_at_0x_x), 0, 0, 1, 0}, + {&__pyx_kp_s_MemoryView_of_r_object, __pyx_k_MemoryView_of_r_object, sizeof(__pyx_k_MemoryView_of_r_object), 0, 0, 1, 0}, + {&__pyx_kp_u_No_valid_pixels_were_received_se, __pyx_k_No_valid_pixels_were_received_se, sizeof(__pyx_k_No_valid_pixels_were_received_se), 0, 1, 0, 0}, + {&__pyx_n_b_O, __pyx_k_O, sizeof(__pyx_k_O), 0, 0, 0, 1}, + {&__pyx_n_s_OAMS_TRADITIONAL_GIS_ORDER, __pyx_k_OAMS_TRADITIONAL_GIS_ORDER, sizeof(__pyx_k_OAMS_TRADITIONAL_GIS_ORDER), 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_kp_s_Out_of_bounds_on_buffer_access_a, __pyx_k_Out_of_bounds_on_buffer_access_a, sizeof(__pyx_k_Out_of_bounds_on_buffer_access_a), 0, 0, 1, 0}, + {&__pyx_n_s_PickleError, __pyx_k_PickleError, sizeof(__pyx_k_PickleError), 0, 0, 1, 1}, + {&__pyx_n_s_RasterXSize, __pyx_k_RasterXSize, sizeof(__pyx_k_RasterXSize), 0, 0, 1, 1}, + {&__pyx_n_s_RasterYSize, __pyx_k_RasterYSize, sizeof(__pyx_k_RasterYSize), 0, 0, 1, 1}, + {&__pyx_n_s_ReadAsArray, __pyx_k_ReadAsArray, sizeof(__pyx_k_ReadAsArray), 0, 0, 1, 1}, + {&__pyx_n_s_S_local, __pyx_k_S_local, sizeof(__pyx_k_S_local), 0, 0, 1, 1}, + {&__pyx_kp_u_TILED_YES, __pyx_k_TILED_YES, sizeof(__pyx_k_TILED_YES), 0, 1, 0, 0}, + {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1}, + {&__pyx_kp_s_Unable_to_convert_item_to_object, __pyx_k_Unable_to_convert_item_to_object, sizeof(__pyx_k_Unable_to_convert_item_to_object), 0, 0, 1, 0}, + {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1}, + {&__pyx_n_s_View_MemoryView, __pyx_k_View_MemoryView, sizeof(__pyx_k_View_MemoryView), 0, 0, 1, 1}, + {&__pyx_n_s_WriteArray, __pyx_k_WriteArray, sizeof(__pyx_k_WriteArray), 0, 0, 1, 1}, + {&__pyx_n_s__34, __pyx_k__34, sizeof(__pyx_k__34), 0, 0, 1, 1}, + {&__pyx_n_s_a, __pyx_k_a, sizeof(__pyx_k_a), 0, 0, 1, 1}, + {&__pyx_n_s_allocate_buffer, __pyx_k_allocate_buffer, sizeof(__pyx_k_allocate_buffer), 0, 0, 1, 1}, + {&__pyx_n_s_arange, __pyx_k_arange, sizeof(__pyx_k_arange), 0, 0, 1, 1}, + {&__pyx_n_s_astype, __pyx_k_astype, sizeof(__pyx_k_astype), 0, 0, 1, 1}, + {&__pyx_n_s_b, __pyx_k_b, sizeof(__pyx_k_b), 0, 0, 1, 1}, + {&__pyx_n_s_base, __pyx_k_base, sizeof(__pyx_k_base), 0, 0, 1, 1}, + {&__pyx_n_s_base_elevation_raster_path_band, __pyx_k_base_elevation_raster_path_band, sizeof(__pyx_k_base_elevation_raster_path_band), 0, 0, 1, 1}, + {&__pyx_n_s_base_raster_path_band, __pyx_k_base_raster_path_band, sizeof(__pyx_k_base_raster_path_band), 0, 0, 1, 1}, + {&__pyx_n_s_block, __pyx_k_block, sizeof(__pyx_k_block), 0, 0, 1, 1}, + {&__pyx_n_s_block_data, __pyx_k_block_data, sizeof(__pyx_k_block_data), 0, 0, 1, 1}, + {&__pyx_n_s_block_offset, __pyx_k_block_offset, sizeof(__pyx_k_block_offset), 0, 0, 1, 1}, + {&__pyx_n_s_block_offset_copy, __pyx_k_block_offset_copy, sizeof(__pyx_k_block_offset_copy), 0, 0, 1, 1}, + {&__pyx_n_u_block_size, __pyx_k_block_size, sizeof(__pyx_k_block_size), 0, 1, 0, 1}, + {&__pyx_n_s_block_xsize, __pyx_k_block_xsize, sizeof(__pyx_k_block_xsize), 0, 0, 1, 1}, + {&__pyx_n_s_block_ysize, __pyx_k_block_ysize, sizeof(__pyx_k_block_ysize), 0, 0, 1, 1}, + {&__pyx_n_s_buf, __pyx_k_buf, sizeof(__pyx_k_buf), 0, 0, 1, 1}, + {&__pyx_n_s_buf_obj, __pyx_k_buf_obj, sizeof(__pyx_k_buf_obj), 0, 0, 1, 1}, + {&__pyx_n_s_buffer, __pyx_k_buffer, sizeof(__pyx_k_buffer), 0, 0, 1, 1}, + {&__pyx_n_s_buffer_data, __pyx_k_buffer_data, sizeof(__pyx_k_buffer_data), 0, 0, 1, 1}, + {&__pyx_n_s_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 0, 1, 1}, + {&__pyx_n_u_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 1, 0, 1}, + {&__pyx_n_s_calculate_slope, __pyx_k_calculate_slope, sizeof(__pyx_k_calculate_slope), 0, 0, 1, 1}, + {&__pyx_kp_u_calculating_percentiles, __pyx_k_calculating_percentiles, sizeof(__pyx_k_calculating_percentiles), 0, 1, 0, 0}, + {&__pyx_kp_u_calculating_percentiles_2f_compl, __pyx_k_calculating_percentiles_2f_compl, sizeof(__pyx_k_calculating_percentiles_2f_compl), 0, 1, 0, 0}, + {&__pyx_n_s_class, __pyx_k_class, sizeof(__pyx_k_class), 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_col_index, __pyx_k_col_index, sizeof(__pyx_k_col_index), 0, 0, 1, 1}, + {&__pyx_kp_u_complete, __pyx_k_complete, sizeof(__pyx_k_complete), 0, 1, 0, 0}, + {&__pyx_kp_s_contiguous_and_direct, __pyx_k_contiguous_and_direct, sizeof(__pyx_k_contiguous_and_direct), 0, 0, 1, 0}, + {&__pyx_kp_s_contiguous_and_indirect, __pyx_k_contiguous_and_indirect, sizeof(__pyx_k_contiguous_and_indirect), 0, 0, 1, 0}, + {&__pyx_n_s_copy, __pyx_k_copy, sizeof(__pyx_k_copy), 0, 0, 1, 1}, + {&__pyx_kp_u_couldn_t_make_working_sort_direc, __pyx_k_couldn_t_make_working_sort_direc, sizeof(__pyx_k_couldn_t_make_working_sort_direc), 0, 1, 0, 0}, + {&__pyx_n_s_current_percentile, __pyx_k_current_percentile, sizeof(__pyx_k_current_percentile), 0, 0, 1, 1}, + {&__pyx_n_s_current_step, __pyx_k_current_step, sizeof(__pyx_k_current_step), 0, 0, 1, 1}, + {&__pyx_n_s_d, __pyx_k_d, sizeof(__pyx_k_d), 0, 0, 1, 1}, + {&__pyx_kp_u_d_dat, __pyx_k_d_dat, sizeof(__pyx_k_d_dat), 0, 1, 0, 0}, + {&__pyx_kp_u_data_sort_to_heap, __pyx_k_data_sort_to_heap, sizeof(__pyx_k_data_sort_to_heap), 0, 1, 0, 0}, + {&__pyx_n_u_datatype, __pyx_k_datatype, sizeof(__pyx_k_datatype), 0, 1, 0, 1}, + {&__pyx_n_s_debug, __pyx_k_debug, sizeof(__pyx_k_debug), 0, 0, 1, 1}, + {&__pyx_n_s_dem_array, __pyx_k_dem_array, sizeof(__pyx_k_dem_array), 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_info, __pyx_k_dem_info, sizeof(__pyx_k_dem_info), 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_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 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_transform_edt, __pyx_k_distance_transform_edt, sizeof(__pyx_k_distance_transform_edt), 0, 0, 1, 1}, + {&__pyx_n_s_done, __pyx_k_done, sizeof(__pyx_k_done), 0, 0, 1, 1}, + {&__pyx_n_s_double, __pyx_k_double, sizeof(__pyx_k_double), 0, 0, 1, 1}, + {&__pyx_n_s_dt, __pyx_k_dt, sizeof(__pyx_k_dt), 0, 0, 1, 1}, + {&__pyx_n_s_dtype, __pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 0, 1, 1}, + {&__pyx_n_s_dtype_is_object, __pyx_k_dtype_is_object, sizeof(__pyx_k_dtype_is_object), 0, 0, 1, 1}, + {&__pyx_n_s_dzdx_accumulator, __pyx_k_dzdx_accumulator, sizeof(__pyx_k_dzdx_accumulator), 0, 0, 1, 1}, + {&__pyx_n_s_dzdx_array, __pyx_k_dzdx_array, sizeof(__pyx_k_dzdx_array), 0, 0, 1, 1}, + {&__pyx_n_s_dzdy_accumulator, __pyx_k_dzdy_accumulator, sizeof(__pyx_k_dzdy_accumulator), 0, 0, 1, 1}, + {&__pyx_n_s_dzdy_array, __pyx_k_dzdy_array, sizeof(__pyx_k_dzdy_array), 0, 0, 1, 1}, + {&__pyx_n_s_e, __pyx_k_e, sizeof(__pyx_k_e), 0, 0, 1, 1}, + {&__pyx_n_s_empty, __pyx_k_empty, sizeof(__pyx_k_empty), 0, 0, 1, 1}, + {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1}, + {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1}, + {&__pyx_n_s_error, __pyx_k_error, sizeof(__pyx_k_error), 0, 0, 1, 1}, + {&__pyx_n_s_exception, __pyx_k_exception, sizeof(__pyx_k_exception), 0, 0, 1, 1}, + {&__pyx_kp_u_exception_s_s_s_s_s, __pyx_k_exception_s_s_s_s_s, sizeof(__pyx_k_exception_s_s_s_s_s), 0, 1, 0, 0}, + {&__pyx_n_s_existing_shm, __pyx_k_existing_shm, sizeof(__pyx_k_existing_shm), 0, 0, 1, 1}, + {&__pyx_n_s_expected_blocks, __pyx_k_expected_blocks, sizeof(__pyx_k_expected_blocks), 0, 0, 1, 1}, + {&__pyx_n_s_f, __pyx_k_f, sizeof(__pyx_k_f), 0, 0, 1, 1}, + {&__pyx_n_s_fast_file_iterator, __pyx_k_fast_file_iterator, sizeof(__pyx_k_fast_file_iterator), 0, 0, 1, 1}, + {&__pyx_n_s_fast_file_iterator_vector, __pyx_k_fast_file_iterator_vector, sizeof(__pyx_k_fast_file_iterator_vector), 0, 0, 1, 1}, + {&__pyx_n_s_ffi_buffer_size, __pyx_k_ffi_buffer_size, sizeof(__pyx_k_ffi_buffer_size), 0, 0, 1, 1}, + {&__pyx_n_s_ffiv_iter, __pyx_k_ffiv_iter, sizeof(__pyx_k_ffiv_iter), 0, 0, 1, 1}, + {&__pyx_n_s_file_index, __pyx_k_file_index, sizeof(__pyx_k_file_index), 0, 0, 1, 1}, + {&__pyx_n_s_file_path, __pyx_k_file_path, sizeof(__pyx_k_file_path), 0, 0, 1, 1}, + {&__pyx_n_s_finfo, __pyx_k_finfo, sizeof(__pyx_k_finfo), 0, 0, 1, 1}, + {&__pyx_n_s_flags, __pyx_k_flags, sizeof(__pyx_k_flags), 0, 0, 1, 1}, + {&__pyx_n_s_float32, __pyx_k_float32, sizeof(__pyx_k_float32), 0, 0, 1, 1}, + {&__pyx_n_s_float64, __pyx_k_float64, sizeof(__pyx_k_float64), 0, 0, 1, 1}, + {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1}, + {&__pyx_n_s_fortran, __pyx_k_fortran, sizeof(__pyx_k_fortran), 0, 0, 1, 1}, + {&__pyx_n_u_fortran, __pyx_k_fortran, sizeof(__pyx_k_fortran), 0, 1, 0, 1}, + {&__pyx_n_s_fptr, __pyx_k_fptr, sizeof(__pyx_k_fptr), 0, 0, 1, 1}, + {&__pyx_n_s_g, __pyx_k_g, sizeof(__pyx_k_g), 0, 0, 1, 1}, + {&__pyx_n_s_g_band, __pyx_k_g_band, sizeof(__pyx_k_g_band), 0, 0, 1, 1}, + {&__pyx_n_s_g_band_blocksize, __pyx_k_g_band_blocksize, sizeof(__pyx_k_g_band_blocksize), 0, 0, 1, 1}, + {&__pyx_n_s_g_block, __pyx_k_g_block, sizeof(__pyx_k_g_block), 0, 0, 1, 1}, + {&__pyx_n_s_g_raster, __pyx_k_g_raster, sizeof(__pyx_k_g_raster), 0, 0, 1, 1}, + {&__pyx_n_s_g_raster_path, __pyx_k_g_raster_path, sizeof(__pyx_k_g_raster_path), 0, 0, 1, 1}, + {&__pyx_n_s_gdal, __pyx_k_gdal, sizeof(__pyx_k_gdal), 0, 0, 1, 1}, + {&__pyx_n_s_get, __pyx_k_get, sizeof(__pyx_k_get), 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_getpid, __pyx_k_getpid, sizeof(__pyx_k_getpid), 0, 0, 1, 1}, + {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1}, + {&__pyx_kp_s_got_differing_extents_in_dimensi, __pyx_k_got_differing_extents_in_dimensi, sizeof(__pyx_k_got_differing_extents_in_dimensi), 0, 0, 1, 0}, + {&__pyx_n_s_gsq, __pyx_k_gsq, sizeof(__pyx_k_gsq), 0, 0, 1, 1}, + {&__pyx_n_s_gu, __pyx_k_gu, sizeof(__pyx_k_gu), 0, 0, 1, 1}, + {&__pyx_n_s_h, __pyx_k_h, sizeof(__pyx_k_h), 0, 0, 1, 1}, + {&__pyx_n_s_heap_buffer_size, __pyx_k_heap_buffer_size, sizeof(__pyx_k_heap_buffer_size), 0, 0, 1, 1}, + {&__pyx_n_s_heapfile_list, __pyx_k_heapfile_list, sizeof(__pyx_k_heapfile_list), 0, 0, 1, 1}, + {&__pyx_kp_u_here_is_percentile_list_s, __pyx_k_here_is_percentile_list_s, sizeof(__pyx_k_here_is_percentile_list_s), 0, 1, 0, 0}, + {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1}, + {&__pyx_n_s_id, __pyx_k_id, sizeof(__pyx_k_id), 0, 0, 1, 1}, + {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, + {&__pyx_n_s_index, __pyx_k_index, sizeof(__pyx_k_index), 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_int64, __pyx_k_int64, sizeof(__pyx_k_int64), 0, 0, 1, 1}, + {&__pyx_n_s_int8, __pyx_k_int8, sizeof(__pyx_k_int8), 0, 0, 1, 1}, + {&__pyx_kp_u_invalid_value_for_n_s, __pyx_k_invalid_value_for_n_s, sizeof(__pyx_k_invalid_value_for_n_s), 0, 1, 0, 0}, + {&__pyx_n_s_isclose, __pyx_k_isclose, sizeof(__pyx_k_isclose), 0, 0, 1, 1}, + {&__pyx_n_s_items, __pyx_k_items, sizeof(__pyx_k_items), 0, 0, 1, 1}, + {&__pyx_n_s_itemsize, __pyx_k_itemsize, sizeof(__pyx_k_itemsize), 0, 0, 1, 1}, + {&__pyx_kp_s_itemsize_0_for_cython_array, __pyx_k_itemsize_0_for_cython_array, sizeof(__pyx_k_itemsize_0_for_cython_array), 0, 0, 1, 0}, + {&__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_last_update, __pyx_k_last_update, sizeof(__pyx_k_last_update), 0, 0, 1, 1}, + {&__pyx_n_s_local_x_index, __pyx_k_local_x_index, sizeof(__pyx_k_local_x_index), 0, 0, 1, 1}, + {&__pyx_n_s_local_y_index, __pyx_k_local_y_index, sizeof(__pyx_k_local_y_index), 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_band, __pyx_k_mask_band, sizeof(__pyx_k_mask_band), 0, 0, 1, 1}, + {&__pyx_n_s_mask_block, __pyx_k_mask_block, sizeof(__pyx_k_mask_block), 0, 0, 1, 1}, + {&__pyx_n_s_mask_raster, __pyx_k_mask_raster, sizeof(__pyx_k_mask_raster), 0, 0, 1, 1}, + {&__pyx_n_s_max_sample, __pyx_k_max_sample, sizeof(__pyx_k_max_sample), 0, 0, 1, 1}, + {&__pyx_n_s_max_value, __pyx_k_max_value, sizeof(__pyx_k_max_value), 0, 0, 1, 1}, + {&__pyx_n_s_memview, __pyx_k_memview, sizeof(__pyx_k_memview), 0, 0, 1, 1}, + {&__pyx_n_s_min, __pyx_k_min, sizeof(__pyx_k_min), 0, 0, 1, 1}, + {&__pyx_n_s_min_value, __pyx_k_min_value, sizeof(__pyx_k_min_value), 0, 0, 1, 1}, + {&__pyx_n_s_mode, __pyx_k_mode, sizeof(__pyx_k_mode), 0, 0, 1, 1}, + {&__pyx_n_s_multiprocessing, __pyx_k_multiprocessing, sizeof(__pyx_k_multiprocessing), 0, 0, 1, 1}, + {&__pyx_n_s_n, __pyx_k_n, sizeof(__pyx_k_n), 0, 0, 1, 1}, + {&__pyx_n_s_n_cols, __pyx_k_n_cols, sizeof(__pyx_k_n_cols), 0, 0, 1, 1}, + {&__pyx_n_s_n_elements, __pyx_k_n_elements, sizeof(__pyx_k_n_elements), 0, 0, 1, 1}, + {&__pyx_n_s_n_pixels, __pyx_k_n_pixels, sizeof(__pyx_k_n_pixels), 0, 0, 1, 1}, + {&__pyx_n_s_n_rows, __pyx_k_n_rows, sizeof(__pyx_k_n_rows), 0, 0, 1, 1}, + {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, + {&__pyx_n_s_name_2, __pyx_k_name_2, sizeof(__pyx_k_name_2), 0, 0, 1, 1}, + {&__pyx_n_s_ndim, __pyx_k_ndim, sizeof(__pyx_k_ndim), 0, 0, 1, 1}, + {&__pyx_n_s_new, __pyx_k_new, sizeof(__pyx_k_new), 0, 0, 1, 1}, + {&__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_n_s_next_val, __pyx_k_next_val, sizeof(__pyx_k_next_val), 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_u_nodata, __pyx_k_nodata, sizeof(__pyx_k_nodata), 0, 1, 0, 1}, + {&__pyx_n_s_numerical_inf, __pyx_k_numerical_inf, sizeof(__pyx_k_numerical_inf), 0, 0, 1, 1}, + {&__pyx_n_s_numpy, __pyx_k_numpy, sizeof(__pyx_k_numpy), 0, 0, 1, 1}, + {&__pyx_kp_u_numpy_core_multiarray_failed_to, __pyx_k_numpy_core_multiarray_failed_to, sizeof(__pyx_k_numpy_core_multiarray_failed_to), 0, 1, 0, 0}, + {&__pyx_kp_u_numpy_core_umath_failed_to_impor, __pyx_k_numpy_core_umath_failed_to_impor, sizeof(__pyx_k_numpy_core_umath_failed_to_impor), 0, 1, 0, 0}, + {&__pyx_n_s_obj, __pyx_k_obj, sizeof(__pyx_k_obj), 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_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_osr, __pyx_k_osr, sizeof(__pyx_k_osr), 0, 0, 1, 1}, + {&__pyx_kp_u_out_of, __pyx_k_out_of, sizeof(__pyx_k_out_of), 0, 1, 0, 0}, + {&__pyx_n_s_pack, __pyx_k_pack, sizeof(__pyx_k_pack), 0, 0, 1, 1}, + {&__pyx_n_s_path, __pyx_k_path, sizeof(__pyx_k_path), 0, 0, 1, 1}, + {&__pyx_n_s_payload, __pyx_k_payload, sizeof(__pyx_k_payload), 0, 0, 1, 1}, + {&__pyx_n_s_percentile_index, __pyx_k_percentile_index, sizeof(__pyx_k_percentile_index), 0, 0, 1, 1}, + {&__pyx_n_s_percentile_list, __pyx_k_percentile_list, sizeof(__pyx_k_percentile_list), 0, 0, 1, 1}, + {&__pyx_n_s_pickle, __pyx_k_pickle, sizeof(__pyx_k_pickle), 0, 0, 1, 1}, + {&__pyx_n_u_pixel_size, __pyx_k_pixel_size, sizeof(__pyx_k_pixel_size), 0, 1, 0, 1}, + {&__pyx_n_s_pixels_processed, __pyx_k_pixels_processed, sizeof(__pyx_k_pixels_processed), 0, 0, 1, 1}, + {&__pyx_n_s_put, __pyx_k_put, sizeof(__pyx_k_put), 0, 0, 1, 1}, + {&__pyx_n_s_pygeoprocessing, __pyx_k_pygeoprocessing, sizeof(__pyx_k_pygeoprocessing), 0, 0, 1, 1}, + {&__pyx_n_s_pygeoprocessing_geoprocessing_co, __pyx_k_pygeoprocessing_geoprocessing_co, sizeof(__pyx_k_pygeoprocessing_geoprocessing_co), 0, 0, 1, 1}, + {&__pyx_kp_u_pygeoprocessing_geoprocessing_co, __pyx_k_pygeoprocessing_geoprocessing_co, sizeof(__pyx_k_pygeoprocessing_geoprocessing_co), 0, 1, 0, 0}, + {&__pyx_n_s_pyx_PickleError, __pyx_k_pyx_PickleError, sizeof(__pyx_k_pyx_PickleError), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_checksum, __pyx_k_pyx_checksum, sizeof(__pyx_k_pyx_checksum), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_getbuffer, __pyx_k_pyx_getbuffer, sizeof(__pyx_k_pyx_getbuffer), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_result, __pyx_k_pyx_result, sizeof(__pyx_k_pyx_result), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_state, __pyx_k_pyx_state, sizeof(__pyx_k_pyx_state), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_type, __pyx_k_pyx_type, sizeof(__pyx_k_pyx_type), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_unpickle_Enum, __pyx_k_pyx_unpickle_Enum, sizeof(__pyx_k_pyx_unpickle_Enum), 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_q_index, __pyx_k_q_index, sizeof(__pyx_k_q_index), 0, 0, 1, 1}, + {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1}, + {&__pyx_n_s_raster_band_percentile, __pyx_k_raster_band_percentile, sizeof(__pyx_k_raster_band_percentile), 0, 0, 1, 1}, + {&__pyx_n_s_raster_band_percentile_double, __pyx_k_raster_band_percentile_double, sizeof(__pyx_k_raster_band_percentile_double), 0, 0, 1, 1}, + {&__pyx_n_s_raster_band_percentile_int, __pyx_k_raster_band_percentile_int, sizeof(__pyx_k_raster_band_percentile_int), 0, 0, 1, 1}, + {&__pyx_n_s_raster_driver_creation_tuple, __pyx_k_raster_driver_creation_tuple, sizeof(__pyx_k_raster_driver_creation_tuple), 0, 0, 1, 1}, + {&__pyx_n_s_raster_info, __pyx_k_raster_info, sizeof(__pyx_k_raster_info), 0, 0, 1, 1}, + {&__pyx_n_u_raster_size, __pyx_k_raster_size, sizeof(__pyx_k_raster_size), 0, 1, 0, 1}, + {&__pyx_n_s_raster_type, __pyx_k_raster_type, sizeof(__pyx_k_raster_type), 0, 0, 1, 1}, + {&__pyx_n_s_raw_nodata, __pyx_k_raw_nodata, sizeof(__pyx_k_raw_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_region_raster_path, __pyx_k_region_raster_path, sizeof(__pyx_k_region_raster_path), 0, 0, 1, 1}, + {&__pyx_n_s_remove, __pyx_k_remove, sizeof(__pyx_k_remove), 0, 0, 1, 1}, + {&__pyx_n_s_result_list, __pyx_k_result_list, sizeof(__pyx_k_result_list), 0, 0, 1, 1}, + {&__pyx_n_s_rm_dir_when_done, __pyx_k_rm_dir_when_done, sizeof(__pyx_k_rm_dir_when_done), 0, 0, 1, 1}, + {&__pyx_n_s_rmtree, __pyx_k_rmtree, sizeof(__pyx_k_rmtree), 0, 0, 1, 1}, + {&__pyx_n_s_row_index, __pyx_k_row_index, sizeof(__pyx_k_row_index), 0, 0, 1, 1}, + {&__pyx_n_s_s_array, __pyx_k_s_array, sizeof(__pyx_k_s_array), 0, 0, 1, 1}, + {&__pyx_n_s_sample_d_x, __pyx_k_sample_d_x, sizeof(__pyx_k_sample_d_x), 0, 0, 1, 1}, + {&__pyx_n_s_sample_d_y, __pyx_k_sample_d_y, sizeof(__pyx_k_sample_d_y), 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_shape, __pyx_k_shape, sizeof(__pyx_k_shape), 0, 0, 1, 1}, + {&__pyx_n_s_shutil, __pyx_k_shutil, sizeof(__pyx_k_shutil), 0, 0, 1, 1}, + {&__pyx_n_s_size, __pyx_k_size, sizeof(__pyx_k_size), 0, 0, 1, 1}, + {&__pyx_n_s_slope_array, __pyx_k_slope_array, sizeof(__pyx_k_slope_array), 0, 0, 1, 1}, + {&__pyx_n_s_slope_nodata, __pyx_k_slope_nodata, sizeof(__pyx_k_slope_nodata), 0, 0, 1, 1}, + {&__pyx_n_s_sort, __pyx_k_sort, sizeof(__pyx_k_sort), 0, 0, 1, 1}, + {&__pyx_kp_u_sorting_data_to_heap, __pyx_k_sorting_data_to_heap, sizeof(__pyx_k_sorting_data_to_heap), 0, 1, 0, 0}, + {&__pyx_n_s_sq, __pyx_k_sq, sizeof(__pyx_k_sq), 0, 0, 1, 1}, + {&__pyx_n_s_sqrt, __pyx_k_sqrt, sizeof(__pyx_k_sqrt), 0, 0, 1, 1}, + {&__pyx_kp_s_src_pygeoprocessing_geoprocessin, __pyx_k_src_pygeoprocessing_geoprocessin, sizeof(__pyx_k_src_pygeoprocessing_geoprocessin), 0, 0, 1, 0}, + {&__pyx_n_s_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 0, 1, 1}, + {&__pyx_n_s_stats_work_queue, __pyx_k_stats_work_queue, sizeof(__pyx_k_stats_work_queue), 0, 0, 1, 1}, + {&__pyx_n_s_stats_worker, __pyx_k_stats_worker, sizeof(__pyx_k_stats_worker), 0, 0, 1, 1}, + {&__pyx_kp_u_stats_worker_PID, __pyx_k_stats_worker_PID, sizeof(__pyx_k_stats_worker_PID), 0, 1, 0, 0}, + {&__pyx_n_s_step, __pyx_k_step, sizeof(__pyx_k_step), 0, 0, 1, 1}, + {&__pyx_n_s_step_size, __pyx_k_step_size, sizeof(__pyx_k_step_size), 0, 0, 1, 1}, + {&__pyx_n_s_stop, __pyx_k_stop, sizeof(__pyx_k_stop), 0, 0, 1, 1}, + {&__pyx_kp_s_strided_and_direct, __pyx_k_strided_and_direct, sizeof(__pyx_k_strided_and_direct), 0, 0, 1, 0}, + {&__pyx_kp_s_strided_and_direct_or_indirect, __pyx_k_strided_and_direct_or_indirect, sizeof(__pyx_k_strided_and_direct_or_indirect), 0, 0, 1, 0}, + {&__pyx_kp_s_strided_and_indirect, __pyx_k_strided_and_indirect, sizeof(__pyx_k_strided_and_indirect), 0, 0, 1, 0}, + {&__pyx_kp_s_stringsource, __pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 0, 1, 0}, + {&__pyx_n_s_struct, __pyx_k_struct, sizeof(__pyx_k_struct), 0, 0, 1, 1}, + {&__pyx_n_s_sys, __pyx_k_sys, sizeof(__pyx_k_sys), 0, 0, 1, 1}, + {&__pyx_n_s_t_array, __pyx_k_t_array, sizeof(__pyx_k_t_array), 0, 0, 1, 1}, + {&__pyx_n_s_target_distance_band, __pyx_k_target_distance_band, sizeof(__pyx_k_target_distance_band), 0, 0, 1, 1}, + {&__pyx_n_s_target_distance_raster, __pyx_k_target_distance_raster, sizeof(__pyx_k_target_distance_raster), 0, 0, 1, 1}, + {&__pyx_n_s_target_distance_raster_path, __pyx_k_target_distance_raster_path, sizeof(__pyx_k_target_distance_raster_path), 0, 0, 1, 1}, + {&__pyx_n_s_target_slope_band, __pyx_k_target_slope_band, sizeof(__pyx_k_target_slope_band), 0, 0, 1, 1}, + {&__pyx_n_s_target_slope_path, __pyx_k_target_slope_path, sizeof(__pyx_k_target_slope_path), 0, 0, 1, 1}, + {&__pyx_n_s_target_slope_raster, __pyx_k_target_slope_raster, sizeof(__pyx_k_target_slope_raster), 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_kp_u_total_number_of_pixels_s_s, __pyx_k_total_number_of_pixels_s_s, sizeof(__pyx_k_total_number_of_pixels_s_s), 0, 1, 0, 0}, + {&__pyx_n_s_tq, __pyx_k_tq, sizeof(__pyx_k_tq), 0, 0, 1, 1}, + {&__pyx_n_s_traceback, __pyx_k_traceback, sizeof(__pyx_k_traceback), 0, 0, 1, 1}, + {&__pyx_n_s_u_index, __pyx_k_u_index, sizeof(__pyx_k_u_index), 0, 0, 1, 1}, + {&__pyx_kp_s_unable_to_allocate_array_data, __pyx_k_unable_to_allocate_array_data, sizeof(__pyx_k_unable_to_allocate_array_data), 0, 0, 1, 0}, + {&__pyx_kp_s_unable_to_allocate_shape_and_str, __pyx_k_unable_to_allocate_shape_and_str, sizeof(__pyx_k_unable_to_allocate_shape_and_str), 0, 0, 1, 0}, + {&__pyx_kp_u_unable_to_remove_s, __pyx_k_unable_to_remove_s, sizeof(__pyx_k_unable_to_remove_s), 0, 1, 0, 0}, + {&__pyx_n_s_unpack, __pyx_k_unpack, sizeof(__pyx_k_unpack), 0, 0, 1, 1}, + {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1}, + {&__pyx_kp_u_utf_8, __pyx_k_utf_8, sizeof(__pyx_k_utf_8), 0, 1, 0, 0}, + {&__pyx_n_s_valid_mask, __pyx_k_valid_mask, sizeof(__pyx_k_valid_mask), 0, 0, 1, 1}, + {&__pyx_n_s_w, __pyx_k_w, sizeof(__pyx_k_w), 0, 0, 1, 1}, + {&__pyx_n_s_warning, __pyx_k_warning, sizeof(__pyx_k_warning), 0, 0, 1, 1}, + {&__pyx_n_s_win_xsize, __pyx_k_win_xsize, sizeof(__pyx_k_win_xsize), 0, 0, 1, 1}, + {&__pyx_n_u_win_xsize, __pyx_k_win_xsize, sizeof(__pyx_k_win_xsize), 0, 1, 0, 1}, + {&__pyx_n_s_win_ysize, __pyx_k_win_ysize, sizeof(__pyx_k_win_ysize), 0, 0, 1, 1}, + {&__pyx_n_u_win_ysize, __pyx_k_win_ysize, sizeof(__pyx_k_win_ysize), 0, 1, 0, 1}, + {&__pyx_n_s_working_sort_directory, __pyx_k_working_sort_directory, sizeof(__pyx_k_working_sort_directory), 0, 0, 1, 1}, + {&__pyx_n_s_x, __pyx_k_x, sizeof(__pyx_k_x), 0, 0, 1, 1}, + {&__pyx_n_s_x_cell_size, __pyx_k_x_cell_size, sizeof(__pyx_k_x_cell_size), 0, 0, 1, 1}, + {&__pyx_n_s_x_denom_factor, __pyx_k_x_denom_factor, sizeof(__pyx_k_x_denom_factor), 0, 0, 1, 1}, + {&__pyx_n_s_x_end, __pyx_k_x_end, sizeof(__pyx_k_x_end), 0, 0, 1, 1}, + {&__pyx_n_s_x_start, __pyx_k_x_start, sizeof(__pyx_k_x_start), 0, 0, 1, 1}, + {&__pyx_n_s_xoff, __pyx_k_xoff, sizeof(__pyx_k_xoff), 0, 0, 1, 1}, + {&__pyx_n_u_xoff, __pyx_k_xoff, sizeof(__pyx_k_xoff), 0, 1, 0, 1}, + {&__pyx_n_s_y_cell_size, __pyx_k_y_cell_size, sizeof(__pyx_k_y_cell_size), 0, 0, 1, 1}, + {&__pyx_n_s_y_denom_factor, __pyx_k_y_denom_factor, sizeof(__pyx_k_y_denom_factor), 0, 0, 1, 1}, + {&__pyx_n_s_y_end, __pyx_k_y_end, sizeof(__pyx_k_y_end), 0, 0, 1, 1}, + {&__pyx_n_s_y_start, __pyx_k_y_start, sizeof(__pyx_k_y_start), 0, 0, 1, 1}, + {&__pyx_n_s_yoff, __pyx_k_yoff, sizeof(__pyx_k_yoff), 0, 0, 1, 1}, + {&__pyx_n_u_yoff, __pyx_k_yoff, sizeof(__pyx_k_yoff), 0, 1, 0, 1}, + {&__pyx_n_s_zlib, __pyx_k_zlib, sizeof(__pyx_k_zlib), 0, 0, 1, 1}, + {0, 0, 0, 0, 0, 0, 0} +}; +static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { + __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 166, __pyx_L1_error) + __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 668, __pyx_L1_error) + __pyx_builtin_OSError = __Pyx_GetBuiltinName(__pyx_n_s_OSError); if (!__pyx_builtin_OSError) __PYX_ERR(0, 716, __pyx_L1_error) + __pyx_builtin_ImportError = __Pyx_GetBuiltinName(__pyx_n_s_ImportError); if (!__pyx_builtin_ImportError) __PYX_ERR(1, 947, __pyx_L1_error) + __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(2, 148, __pyx_L1_error) + __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(2, 151, __pyx_L1_error) + __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(2, 2, __pyx_L1_error) + __pyx_builtin_Ellipsis = __Pyx_GetBuiltinName(__pyx_n_s_Ellipsis); if (!__pyx_builtin_Ellipsis) __PYX_ERR(2, 404, __pyx_L1_error) + __pyx_builtin_id = __Pyx_GetBuiltinName(__pyx_n_s_id); if (!__pyx_builtin_id) __PYX_ERR(2, 613, __pyx_L1_error) + __pyx_builtin_IndexError = __Pyx_GetBuiltinName(__pyx_n_s_IndexError); if (!__pyx_builtin_IndexError) __PYX_ERR(2, 832, __pyx_L1_error) + return 0; + __pyx_L1_error:; + return -1; +} + +static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); + + /* "pygeoprocessing/geoprocessing_core.pyx":165 + * buf_obj=mask_block) + * # base case + * g_block[0, :] = (mask_block[0, :] == 0) * numerical_inf # <<<<<<<<<<<<<< + * for row_index in range(1, n_rows): + * for local_x_index in range(win_xsize): + */ + __pyx_slice_ = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice_)) __PYX_ERR(0, 165, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice_); + __Pyx_GIVEREF(__pyx_slice_); + __pyx_tuple__2 = PyTuple_Pack(2, __pyx_int_0, __pyx_slice_); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 165, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__2); + __Pyx_GIVEREF(__pyx_tuple__2); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":947 + * __pyx_import_array() + * except Exception: + * raise ImportError("numpy.core.multiarray failed to import") # <<<<<<<<<<<<<< + * + * cdef inline int import_umath() except -1: + */ + __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_u_numpy_core_multiarray_failed_to); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(1, 947, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__4); + __Pyx_GIVEREF(__pyx_tuple__4); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":953 + * _import_umath() + * except Exception: + * raise ImportError("numpy.core.umath failed to import") # <<<<<<<<<<<<<< + * + * cdef inline int import_ufunc() except -1: + */ + __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_u_numpy_core_umath_failed_to_impor); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(1, 953, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__5); + __Pyx_GIVEREF(__pyx_tuple__5); + + /* "View.MemoryView":133 + * + * if not self.ndim: + * raise ValueError("Empty shape tuple for cython.array") # <<<<<<<<<<<<<< + * + * if itemsize <= 0: + */ + __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_s_Empty_shape_tuple_for_cython_arr); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(2, 133, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__6); + __Pyx_GIVEREF(__pyx_tuple__6); + + /* "View.MemoryView":136 + * + * if itemsize <= 0: + * raise ValueError("itemsize <= 0 for cython.array") # <<<<<<<<<<<<<< + * + * if not isinstance(format, bytes): + */ + __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_s_itemsize_0_for_cython_array); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(2, 136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__7); + __Pyx_GIVEREF(__pyx_tuple__7); + + /* "View.MemoryView":148 + * + * if not self._shape: + * raise MemoryError("unable to allocate shape and strides.") # <<<<<<<<<<<<<< + * + * + */ + __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_s_unable_to_allocate_shape_and_str); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(2, 148, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__8); + __Pyx_GIVEREF(__pyx_tuple__8); + + /* "View.MemoryView":176 + * self.data = malloc(self.len) + * if not self.data: + * raise MemoryError("unable to allocate array data.") # <<<<<<<<<<<<<< + * + * if self.dtype_is_object: + */ + __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_s_unable_to_allocate_array_data); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(2, 176, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__9); + __Pyx_GIVEREF(__pyx_tuple__9); + + /* "View.MemoryView":192 + * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + * if not (flags & bufmode): + * raise ValueError("Can only create a buffer that is contiguous in memory.") # <<<<<<<<<<<<<< + * info.buf = self.data + * info.len = self.len + */ + __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_s_Can_only_create_a_buffer_that_is); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(2, 192, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__10); + __Pyx_GIVEREF(__pyx_tuple__10); + + /* "(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__11 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(2, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__11); + __Pyx_GIVEREF(__pyx_tuple__11); + + /* "(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__12 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(2, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__12); + __Pyx_GIVEREF(__pyx_tuple__12); + + /* "View.MemoryView":418 + * def __setitem__(memoryview self, object index, object value): + * if self.view.readonly: + * raise TypeError("Cannot assign to read-only memoryview") # <<<<<<<<<<<<<< + * + * have_slices, index = _unellipsify(index, self.view.ndim) + */ + __pyx_tuple__13 = PyTuple_Pack(1, __pyx_kp_s_Cannot_assign_to_read_only_memor); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(2, 418, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__13); + __Pyx_GIVEREF(__pyx_tuple__13); + + /* "View.MemoryView":495 + * result = struct.unpack(self.view.format, bytesitem) + * except struct.error: + * raise ValueError("Unable to convert item to object") # <<<<<<<<<<<<<< + * else: + * if len(self.view.format) == 1: + */ + __pyx_tuple__14 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_convert_item_to_object); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(2, 495, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__14); + __Pyx_GIVEREF(__pyx_tuple__14); + + /* "View.MemoryView":520 + * def __getbuffer__(self, Py_buffer *info, int flags): + * if flags & PyBUF_WRITABLE and self.view.readonly: + * raise ValueError("Cannot create writable memory view from read-only memoryview") # <<<<<<<<<<<<<< + * + * if flags & PyBUF_ND: + */ + __pyx_tuple__15 = PyTuple_Pack(1, __pyx_kp_s_Cannot_create_writable_memory_vi); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(2, 520, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__15); + __Pyx_GIVEREF(__pyx_tuple__15); + + /* "View.MemoryView":570 + * if self.view.strides == NULL: + * + * raise ValueError("Buffer view does not expose strides") # <<<<<<<<<<<<<< + * + * return tuple([stride for stride in self.view.strides[:self.view.ndim]]) + */ + __pyx_tuple__16 = PyTuple_Pack(1, __pyx_kp_s_Buffer_view_does_not_expose_stri); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(2, 570, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__16); + __Pyx_GIVEREF(__pyx_tuple__16); + + /* "View.MemoryView":577 + * def suboffsets(self): + * if self.view.suboffsets == NULL: + * return (-1,) * self.view.ndim # <<<<<<<<<<<<<< + * + * return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]]) + */ + __pyx_tuple__17 = PyTuple_New(1); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(2, 577, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__17); + __Pyx_INCREF(__pyx_int_neg_1); + __Pyx_GIVEREF(__pyx_int_neg_1); + PyTuple_SET_ITEM(__pyx_tuple__17, 0, __pyx_int_neg_1); + __Pyx_GIVEREF(__pyx_tuple__17); + + /* "(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__18 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(2, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__18); + __Pyx_GIVEREF(__pyx_tuple__18); + + /* "(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__19 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(2, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__19); + __Pyx_GIVEREF(__pyx_tuple__19); + + /* "View.MemoryView":703 + * for suboffset in suboffsets[:ndim]: + * if suboffset >= 0: + * raise ValueError("Indirect dimensions not supported") # <<<<<<<<<<<<<< + * + * + */ + __pyx_tuple__20 = PyTuple_Pack(1, __pyx_kp_s_Indirect_dimensions_not_supporte); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(2, 703, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__20); + __Pyx_GIVEREF(__pyx_tuple__20); + + /* "(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__21 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(2, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__21); + __Pyx_GIVEREF(__pyx_tuple__21); + + /* "(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__22 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(2, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__22); + __Pyx_GIVEREF(__pyx_tuple__22); + + /* "pygeoprocessing/geoprocessing_core.pyx":32 + * + * DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS = ('GTIFF', ( + * 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', # <<<<<<<<<<<<<< + * 'BLOCKXSIZE=256', 'BLOCKYSIZE=256')) + * + */ + __pyx_tuple__23 = PyTuple_Pack(5, __pyx_kp_u_TILED_YES, __pyx_kp_u_BIGTIFF_YES, __pyx_kp_u_COMPRESS_LZW, __pyx_kp_u_BLOCKXSIZE_256, __pyx_kp_u_BLOCKYSIZE_256); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 32, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__23); + __Pyx_GIVEREF(__pyx_tuple__23); + + /* "pygeoprocessing/geoprocessing_core.pyx":31 + * import pygeoprocessing + * + * DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS = ('GTIFF', ( # <<<<<<<<<<<<<< + * 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', + * 'BLOCKXSIZE=256', 'BLOCKYSIZE=256')) + */ + __pyx_tuple__24 = PyTuple_Pack(2, __pyx_n_u_GTIFF, __pyx_tuple__23); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 31, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__24); + __Pyx_GIVEREF(__pyx_tuple__24); + + /* "pygeoprocessing/geoprocessing_core.pyx":44 + * DEFAULT_OSR_AXIS_MAPPING_STRATEGY = osr.OAMS_TRADITIONAL_GIS_ORDER + * + * LOGGER = logging.getLogger('pygeoprocessing.geoprocessing_core') # <<<<<<<<<<<<<< + * + * cdef float _NODATA = -1.0 + */ + __pyx_tuple__25 = PyTuple_Pack(1, __pyx_kp_u_pygeoprocessing_geoprocessing_co); if (unlikely(!__pyx_tuple__25)) __PYX_ERR(0, 44, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__25); + __Pyx_GIVEREF(__pyx_tuple__25); + + /* "pygeoprocessing/geoprocessing_core.pyx":71 + * @cython.wraparound(False) + * @cython.cdivision(True) + * def _distance_transform_edt( # <<<<<<<<<<<<<< + * region_raster_path, g_raster_path, float sample_d_x, + * float sample_d_y, target_distance_raster_path, + */ + __pyx_tuple__26 = PyTuple_Pack(42, __pyx_n_s_region_raster_path, __pyx_n_s_g_raster_path, __pyx_n_s_sample_d_x, __pyx_n_s_sample_d_y, __pyx_n_s_target_distance_raster_path, __pyx_n_s_raster_driver_creation_tuple, __pyx_n_s_yoff, __pyx_n_s_row_index, __pyx_n_s_block_ysize, __pyx_n_s_win_ysize, __pyx_n_s_n_rows, __pyx_n_s_xoff, __pyx_n_s_block_xsize, __pyx_n_s_win_xsize, __pyx_n_s_n_cols, __pyx_n_s_q_index, __pyx_n_s_local_x_index, __pyx_n_s_local_y_index, __pyx_n_s_u_index, __pyx_n_s_tq, __pyx_n_s_sq, __pyx_n_s_gu, __pyx_n_s_gsq, __pyx_n_s_w, __pyx_n_s_g_block, __pyx_n_s_s_array, __pyx_n_s_t_array, __pyx_n_s_dt, __pyx_n_s_mask_block, __pyx_n_s_mask_raster, __pyx_n_s_mask_band, __pyx_n_s_raster_info, __pyx_n_s_g_raster, __pyx_n_s_g_band, __pyx_n_s_g_band_blocksize, __pyx_n_s_max_sample, __pyx_n_s_numerical_inf, __pyx_n_s_done, __pyx_n_s_distance_nodata, __pyx_n_s_target_distance_raster, __pyx_n_s_target_distance_band, __pyx_n_s_valid_mask); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 71, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__26); + __Pyx_GIVEREF(__pyx_tuple__26); + __pyx_codeobj__27 = (PyObject*)__Pyx_PyCode_New(6, 0, 42, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_geoprocessin, __pyx_n_s_distance_transform_edt, 71, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__27)) __PYX_ERR(0, 71, __pyx_L1_error) + + /* "pygeoprocessing/geoprocessing_core.pyx":287 + * @cython.nonecheck(False) + * @cython.cdivision(True) + * def calculate_slope( # <<<<<<<<<<<<<< + * base_elevation_raster_path_band, target_slope_path, + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): + */ + __pyx_tuple__28 = PyTuple_Pack(43, __pyx_n_s_base_elevation_raster_path_band, __pyx_n_s_target_slope_path, __pyx_n_s_raster_driver_creation_tuple, __pyx_n_s_a, __pyx_n_s_b, __pyx_n_s_c, __pyx_n_s_d, __pyx_n_s_e, __pyx_n_s_f, __pyx_n_s_g, __pyx_n_s_h, __pyx_n_s_i, __pyx_n_s_dem_nodata, __pyx_n_s_x_cell_size, __pyx_n_s_y_cell_size, __pyx_n_s_dzdx_accumulator, __pyx_n_s_dzdy_accumulator, __pyx_n_s_row_index, __pyx_n_s_col_index, __pyx_n_s_n_rows, __pyx_n_s_n_cols, __pyx_n_s_x_denom_factor, __pyx_n_s_y_denom_factor, __pyx_n_s_win_xsize, __pyx_n_s_win_ysize, __pyx_n_s_dem_array, __pyx_n_s_slope_array, __pyx_n_s_dzdx_array, __pyx_n_s_dzdy_array, __pyx_n_s_dem_raster, __pyx_n_s_dem_band, __pyx_n_s_dem_info, __pyx_n_s_raw_nodata, __pyx_n_s_slope_nodata, __pyx_n_s_target_slope_raster, __pyx_n_s_target_slope_band, __pyx_n_s_block_offset, __pyx_n_s_block_offset_copy, __pyx_n_s_x_start, __pyx_n_s_x_end, __pyx_n_s_y_start, __pyx_n_s_y_end, __pyx_n_s_valid_mask); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 287, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__28); + __Pyx_GIVEREF(__pyx_tuple__28); + __pyx_codeobj__29 = (PyObject*)__Pyx_PyCode_New(3, 0, 43, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_geoprocessin, __pyx_n_s_calculate_slope, 287, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__29)) __PYX_ERR(0, 287, __pyx_L1_error) + + /* "pygeoprocessing/geoprocessing_core.pyx":544 + * @cython.boundscheck(False) + * @cython.cdivision(True) + * def stats_worker(stats_work_queue, expected_blocks): # <<<<<<<<<<<<<< + * """Worker to calculate continuous min, max, mean and standard deviation. + * + */ + __pyx_tuple__30 = PyTuple_Pack(18, __pyx_n_s_stats_work_queue, __pyx_n_s_expected_blocks, __pyx_n_s_block, __pyx_n_s_M_local, __pyx_n_s_S_local, __pyx_n_s_min_value, __pyx_n_s_max_value, __pyx_n_s_x, __pyx_n_s_i, __pyx_n_s_n_elements, __pyx_n_s_n, __pyx_n_s_payload, __pyx_n_s_index, __pyx_n_s_existing_shm, __pyx_n_s_shape, __pyx_n_s_dtype, __pyx_n_s_M_last, __pyx_n_s_e); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 544, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__30); + __Pyx_GIVEREF(__pyx_tuple__30); + __pyx_codeobj__31 = (PyObject*)__Pyx_PyCode_New(2, 0, 18, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__30, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_geoprocessin, __pyx_n_s_stats_worker, 544, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__31)) __PYX_ERR(0, 544, __pyx_L1_error) + + /* "pygeoprocessing/geoprocessing_core.pyx":626 + * + * + * def raster_band_percentile( # <<<<<<<<<<<<<< + * base_raster_path_band, working_sort_directory, percentile_list, + * heap_buffer_size=2**28, ffi_buffer_size=2**10): + */ + __pyx_tuple__32 = PyTuple_Pack(6, __pyx_n_s_base_raster_path_band, __pyx_n_s_working_sort_directory, __pyx_n_s_percentile_list, __pyx_n_s_heap_buffer_size, __pyx_n_s_ffi_buffer_size, __pyx_n_s_raster_type); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 626, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__32); + __Pyx_GIVEREF(__pyx_tuple__32); + __pyx_codeobj__33 = (PyObject*)__Pyx_PyCode_New(5, 0, 6, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__32, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_geoprocessin, __pyx_n_s_raster_band_percentile, 626, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__33)) __PYX_ERR(0, 626, __pyx_L1_error) + + /* "pygeoprocessing/geoprocessing_core.pyx":673 + * + * + * def _raster_band_percentile_int( # <<<<<<<<<<<<<< + * base_raster_path_band, working_sort_directory, percentile_list, + * heap_buffer_size, ffi_buffer_size): + */ + __pyx_tuple__35 = PyTuple_Pack(29, __pyx_n_s_base_raster_path_band, __pyx_n_s_working_sort_directory, __pyx_n_s_percentile_list, __pyx_n_s_heap_buffer_size, __pyx_n_s_ffi_buffer_size, __pyx_n_s_fptr, __pyx_n_s_fast_file_iterator, __pyx_n_s_fast_file_iterator_vector, __pyx_n_s_ffiv_iter, __pyx_n_s_percentile_index, __pyx_n_s_i, __pyx_n_s_n_elements, __pyx_n_s_next_val, __pyx_n_s_step_size, __pyx_n_s_current_percentile, __pyx_n_s_current_step, __pyx_n_s_result_list, __pyx_n_s_rm_dir_when_done, __pyx_n_s_buffer_data, __pyx_n_s_heapfile_list, __pyx_n_s_file_index, __pyx_n_s_raster_info, __pyx_n_s_nodata, __pyx_n_s_n_pixels, __pyx_n_s_pixels_processed, __pyx_n_s_last_update, __pyx_n_s__34, __pyx_n_s_block_data, __pyx_n_s_file_path); if (unlikely(!__pyx_tuple__35)) __PYX_ERR(0, 673, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__35); + __Pyx_GIVEREF(__pyx_tuple__35); + __pyx_codeobj__36 = (PyObject*)__Pyx_PyCode_New(5, 0, 29, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__35, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_geoprocessin, __pyx_n_s_raster_band_percentile_int, 673, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__36)) __PYX_ERR(0, 673, __pyx_L1_error) + + /* "pygeoprocessing/geoprocessing_core.pyx":819 + * + * + * def _raster_band_percentile_double( # <<<<<<<<<<<<<< + * base_raster_path_band, working_sort_directory, percentile_list, + * heap_buffer_size, ffi_buffer_size): + */ + __pyx_tuple__37 = PyTuple_Pack(30, __pyx_n_s_base_raster_path_band, __pyx_n_s_working_sort_directory, __pyx_n_s_percentile_list, __pyx_n_s_heap_buffer_size, __pyx_n_s_ffi_buffer_size, __pyx_n_s_fptr, __pyx_n_s_buffer_data, __pyx_n_s_fast_file_iterator, __pyx_n_s_fast_file_iterator_vector, __pyx_n_s_percentile_index, __pyx_n_s_i, __pyx_n_s_n_elements, __pyx_n_s_next_val, __pyx_n_s_current_step, __pyx_n_s_step_size, __pyx_n_s_current_percentile, __pyx_n_s_result_list, __pyx_n_s_rm_dir_when_done, __pyx_n_s_e, __pyx_n_s_file_index, __pyx_n_s_nodata, __pyx_n_s_heapfile_list, __pyx_n_s_raster_info, __pyx_n_s_n_pixels, __pyx_n_s_pixels_processed, __pyx_n_s_last_update, __pyx_n_s__34, __pyx_n_s_block_data, __pyx_n_s_file_path, __pyx_n_s_ffiv_iter); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(0, 819, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__37); + __Pyx_GIVEREF(__pyx_tuple__37); + __pyx_codeobj__38 = (PyObject*)__Pyx_PyCode_New(5, 0, 30, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__37, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_geoprocessin, __pyx_n_s_raster_band_percentile_double, 819, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__38)) __PYX_ERR(0, 819, __pyx_L1_error) + + /* "View.MemoryView":286 + * return self.name + * + * cdef generic = Enum("") # <<<<<<<<<<<<<< + * cdef strided = Enum("") # default + * cdef indirect = Enum("") + */ + __pyx_tuple__39 = PyTuple_Pack(1, __pyx_kp_s_strided_and_direct_or_indirect); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(2, 286, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__39); + __Pyx_GIVEREF(__pyx_tuple__39); + + /* "View.MemoryView":287 + * + * cdef generic = Enum("") + * cdef strided = Enum("") # default # <<<<<<<<<<<<<< + * cdef indirect = Enum("") + * + */ + __pyx_tuple__40 = PyTuple_Pack(1, __pyx_kp_s_strided_and_direct); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(2, 287, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__40); + __Pyx_GIVEREF(__pyx_tuple__40); + + /* "View.MemoryView":288 + * cdef generic = Enum("") + * cdef strided = Enum("") # default + * cdef indirect = Enum("") # <<<<<<<<<<<<<< + * + * + */ + __pyx_tuple__41 = PyTuple_Pack(1, __pyx_kp_s_strided_and_indirect); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(2, 288, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__41); + __Pyx_GIVEREF(__pyx_tuple__41); + + /* "View.MemoryView":291 + * + * + * cdef contiguous = Enum("") # <<<<<<<<<<<<<< + * cdef indirect_contiguous = Enum("") + * + */ + __pyx_tuple__42 = PyTuple_Pack(1, __pyx_kp_s_contiguous_and_direct); if (unlikely(!__pyx_tuple__42)) __PYX_ERR(2, 291, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__42); + __Pyx_GIVEREF(__pyx_tuple__42); + + /* "View.MemoryView":292 + * + * cdef contiguous = Enum("") + * cdef indirect_contiguous = Enum("") # <<<<<<<<<<<<<< + * + * + */ + __pyx_tuple__43 = PyTuple_Pack(1, __pyx_kp_s_contiguous_and_indirect); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(2, 292, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__43); + __Pyx_GIVEREF(__pyx_tuple__43); + + /* "(tree fragment)":1 + * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + __pyx_tuple__44 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__44); + __Pyx_GIVEREF(__pyx_tuple__44); + __pyx_codeobj__45 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 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_stringsource, __pyx_n_s_pyx_unpickle_Enum, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__45)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} + +static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { + if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + __pyx_float_5_0 = PyFloat_FromDouble(5.0); if (unlikely(!__pyx_float_5_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_1024 = PyInt_FromLong(1024); if (unlikely(!__pyx_int_1024)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_184977713 = PyInt_FromLong(184977713L); if (unlikely(!__pyx_int_184977713)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_268435456 = PyInt_FromLong(268435456L); if (unlikely(!__pyx_int_268435456)) __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 CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE 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 ---*/ + generic = Py_None; Py_INCREF(Py_None); + strided = Py_None; Py_INCREF(Py_None); + indirect = Py_None; Py_INCREF(Py_None); + contiguous = Py_None; Py_INCREF(Py_None); + indirect_contiguous = Py_None; Py_INCREF(Py_None); + __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 + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); + /*--- Type init code ---*/ + __pyx_vtabptr_array = &__pyx_vtable_array; + __pyx_vtable_array.get_memview = (PyObject *(*)(struct __pyx_array_obj *))__pyx_array_get_memview; + if (PyType_Ready(&__pyx_type___pyx_array) < 0) __PYX_ERR(2, 105, __pyx_L1_error) + #if PY_VERSION_HEX < 0x030800B1 + __pyx_type___pyx_array.tp_print = 0; + #endif + if (__Pyx_SetVtable(__pyx_type___pyx_array.tp_dict, __pyx_vtabptr_array) < 0) __PYX_ERR(2, 105, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_array) < 0) __PYX_ERR(2, 105, __pyx_L1_error) + __pyx_array_type = &__pyx_type___pyx_array; + if (PyType_Ready(&__pyx_type___pyx_MemviewEnum) < 0) __PYX_ERR(2, 279, __pyx_L1_error) + #if PY_VERSION_HEX < 0x030800B1 + __pyx_type___pyx_MemviewEnum.tp_print = 0; + #endif + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type___pyx_MemviewEnum.tp_dictoffset && __pyx_type___pyx_MemviewEnum.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type___pyx_MemviewEnum.tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_MemviewEnum) < 0) __PYX_ERR(2, 279, __pyx_L1_error) + __pyx_MemviewEnum_type = &__pyx_type___pyx_MemviewEnum; + __pyx_vtabptr_memoryview = &__pyx_vtable_memoryview; + __pyx_vtable_memoryview.get_item_pointer = (char *(*)(struct __pyx_memoryview_obj *, PyObject *))__pyx_memoryview_get_item_pointer; + __pyx_vtable_memoryview.is_slice = (PyObject *(*)(struct __pyx_memoryview_obj *, PyObject *))__pyx_memoryview_is_slice; + __pyx_vtable_memoryview.setitem_slice_assignment = (PyObject *(*)(struct __pyx_memoryview_obj *, PyObject *, PyObject *))__pyx_memoryview_setitem_slice_assignment; + __pyx_vtable_memoryview.setitem_slice_assign_scalar = (PyObject *(*)(struct __pyx_memoryview_obj *, struct __pyx_memoryview_obj *, PyObject *))__pyx_memoryview_setitem_slice_assign_scalar; + __pyx_vtable_memoryview.setitem_indexed = (PyObject *(*)(struct __pyx_memoryview_obj *, PyObject *, PyObject *))__pyx_memoryview_setitem_indexed; + __pyx_vtable_memoryview.convert_item_to_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *))__pyx_memoryview_convert_item_to_object; + __pyx_vtable_memoryview.assign_item_from_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *, PyObject *))__pyx_memoryview_assign_item_from_object; + if (PyType_Ready(&__pyx_type___pyx_memoryview) < 0) __PYX_ERR(2, 330, __pyx_L1_error) + #if PY_VERSION_HEX < 0x030800B1 + __pyx_type___pyx_memoryview.tp_print = 0; + #endif + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type___pyx_memoryview.tp_dictoffset && __pyx_type___pyx_memoryview.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type___pyx_memoryview.tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + if (__Pyx_SetVtable(__pyx_type___pyx_memoryview.tp_dict, __pyx_vtabptr_memoryview) < 0) __PYX_ERR(2, 330, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_memoryview) < 0) __PYX_ERR(2, 330, __pyx_L1_error) + __pyx_memoryview_type = &__pyx_type___pyx_memoryview; + __pyx_vtabptr__memoryviewslice = &__pyx_vtable__memoryviewslice; + __pyx_vtable__memoryviewslice.__pyx_base = *__pyx_vtabptr_memoryview; + __pyx_vtable__memoryviewslice.__pyx_base.convert_item_to_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *))__pyx_memoryviewslice_convert_item_to_object; + __pyx_vtable__memoryviewslice.__pyx_base.assign_item_from_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *, PyObject *))__pyx_memoryviewslice_assign_item_from_object; + __pyx_type___pyx_memoryviewslice.tp_base = __pyx_memoryview_type; + if (PyType_Ready(&__pyx_type___pyx_memoryviewslice) < 0) __PYX_ERR(2, 965, __pyx_L1_error) + #if PY_VERSION_HEX < 0x030800B1 + __pyx_type___pyx_memoryviewslice.tp_print = 0; + #endif + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type___pyx_memoryviewslice.tp_dictoffset && __pyx_type___pyx_memoryviewslice.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type___pyx_memoryviewslice.tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + if (__Pyx_SetVtable(__pyx_type___pyx_memoryviewslice.tp_dict, __pyx_vtabptr__memoryviewslice) < 0) __PYX_ERR(2, 965, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_memoryviewslice) < 0) __PYX_ERR(2, 965, __pyx_L1_error) + __pyx_memoryviewslice_type = &__pyx_type___pyx_memoryviewslice; + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} + +static int __Pyx_modinit_type_import_code(void) { + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); + /*--- Type import code ---*/ + __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", + #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 + sizeof(PyTypeObject), + #else + sizeof(PyHeapTypeObject), + #endif + __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(3, 9, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyImport_ImportModule("numpy"); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 200, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_ptype_5numpy_dtype = __Pyx_ImportType(__pyx_t_1, "numpy", "dtype", sizeof(PyArray_Descr), __Pyx_ImportType_CheckSize_Ignore); + if (!__pyx_ptype_5numpy_dtype) __PYX_ERR(1, 200, __pyx_L1_error) + __pyx_ptype_5numpy_flatiter = __Pyx_ImportType(__pyx_t_1, "numpy", "flatiter", sizeof(PyArrayIterObject), __Pyx_ImportType_CheckSize_Ignore); + if (!__pyx_ptype_5numpy_flatiter) __PYX_ERR(1, 223, __pyx_L1_error) + __pyx_ptype_5numpy_broadcast = __Pyx_ImportType(__pyx_t_1, "numpy", "broadcast", sizeof(PyArrayMultiIterObject), __Pyx_ImportType_CheckSize_Ignore); + if (!__pyx_ptype_5numpy_broadcast) __PYX_ERR(1, 227, __pyx_L1_error) + __pyx_ptype_5numpy_ndarray = __Pyx_ImportType(__pyx_t_1, "numpy", "ndarray", sizeof(PyArrayObject), __Pyx_ImportType_CheckSize_Ignore); + if (!__pyx_ptype_5numpy_ndarray) __PYX_ERR(1, 239, __pyx_L1_error) + __pyx_ptype_5numpy_generic = __Pyx_ImportType(__pyx_t_1, "numpy", "generic", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_generic) __PYX_ERR(1, 771, __pyx_L1_error) + __pyx_ptype_5numpy_number = __Pyx_ImportType(__pyx_t_1, "numpy", "number", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_number) __PYX_ERR(1, 773, __pyx_L1_error) + __pyx_ptype_5numpy_integer = __Pyx_ImportType(__pyx_t_1, "numpy", "integer", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_integer) __PYX_ERR(1, 775, __pyx_L1_error) + __pyx_ptype_5numpy_signedinteger = __Pyx_ImportType(__pyx_t_1, "numpy", "signedinteger", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_signedinteger) __PYX_ERR(1, 777, __pyx_L1_error) + __pyx_ptype_5numpy_unsignedinteger = __Pyx_ImportType(__pyx_t_1, "numpy", "unsignedinteger", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_unsignedinteger) __PYX_ERR(1, 779, __pyx_L1_error) + __pyx_ptype_5numpy_inexact = __Pyx_ImportType(__pyx_t_1, "numpy", "inexact", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_inexact) __PYX_ERR(1, 781, __pyx_L1_error) + __pyx_ptype_5numpy_floating = __Pyx_ImportType(__pyx_t_1, "numpy", "floating", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_floating) __PYX_ERR(1, 783, __pyx_L1_error) + __pyx_ptype_5numpy_complexfloating = __Pyx_ImportType(__pyx_t_1, "numpy", "complexfloating", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_complexfloating) __PYX_ERR(1, 785, __pyx_L1_error) + __pyx_ptype_5numpy_flexible = __Pyx_ImportType(__pyx_t_1, "numpy", "flexible", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_flexible) __PYX_ERR(1, 787, __pyx_L1_error) + __pyx_ptype_5numpy_character = __Pyx_ImportType(__pyx_t_1, "numpy", "character", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_character) __PYX_ERR(1, 789, __pyx_L1_error) + __pyx_ptype_5numpy_ufunc = __Pyx_ImportType(__pyx_t_1, "numpy", "ufunc", sizeof(PyUFuncObject), __Pyx_ImportType_CheckSize_Ignore); + if (!__pyx_ptype_5numpy_ufunc) __PYX_ERR(1, 827, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __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; +} + + +#ifndef CYTHON_NO_PYINIT_EXPORT +#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC +#elif PY_MAJOR_VERSION < 3 +#ifdef __cplusplus +#define __Pyx_PyMODINIT_FUNC extern "C" void +#else +#define __Pyx_PyMODINIT_FUNC void +#endif +#else +#ifdef __cplusplus +#define __Pyx_PyMODINIT_FUNC extern "C" PyObject * +#else +#define __Pyx_PyMODINIT_FUNC PyObject * +#endif +#endif + + +#if PY_MAJOR_VERSION < 3 +__Pyx_PyMODINIT_FUNC initgeoprocessing_core(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC initgeoprocessing_core(void) +#else +__Pyx_PyMODINIT_FUNC PyInit_geoprocessing_core(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC PyInit_geoprocessing_core(void) +#if CYTHON_PEP489_MULTI_PHASE_INIT +{ + return PyModuleDef_Init(&__pyx_moduledef); +} +static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) { + #if PY_VERSION_HEX >= 0x030700A1 + static PY_INT64_T main_interpreter_id = -1; + PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp); + if (main_interpreter_id == -1) { + main_interpreter_id = current_id; + return (unlikely(current_id == -1)) ? -1 : 0; + } else if (unlikely(main_interpreter_id != current_id)) + #else + static PyInterpreterState *main_interpreter = NULL; + PyInterpreterState *current_interpreter = PyThreadState_Get()->interp; + if (!main_interpreter) { + main_interpreter = current_interpreter; + } else if (unlikely(main_interpreter != current_interpreter)) + #endif + { + PyErr_SetString( + PyExc_ImportError, + "Interpreter change detected - this module can only be loaded into one interpreter per process."); + return -1; + } + return 0; +} +static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) { + PyObject *value = PyObject_GetAttrString(spec, from_name); + int result = 0; + if (likely(value)) { + if (allow_none || value != Py_None) { + result = PyDict_SetItemString(moddict, to_name, value); + } + Py_DECREF(value); + } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Clear(); + } else { + result = -1; + } + return result; +} +static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) { + PyObject *module = NULL, *moddict, *modname; + if (__Pyx_check_single_interpreter()) + return NULL; + 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__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad; + return module; +bad: + Py_XDECREF(module); + return NULL; +} + + +static CYTHON_SMALL_CODE int __pyx_pymod_exec_geoprocessing_core(PyObject *__pyx_pyinit_module) +#endif +#endif +{ + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + static PyThread_type_lock __pyx_t_3[8]; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannyDeclarations + #if CYTHON_PEP489_MULTI_PHASE_INIT + if (__pyx_m) { + if (__pyx_m == __pyx_pyinit_module) return 0; + PyErr_SetString(PyExc_RuntimeError, "Module 'geoprocessing_core' has already been imported. Re-initialisation is not supported."); + return -1; + } + #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_geoprocessing_core(void)", 0); + if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pxy_PyFrame_Initialize_Offsets + __Pxy_PyFrame_Initialize_Offsets(); + #endif + __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("geoprocessing_core", __pyx_methods, 0, 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) + Py_INCREF(__pyx_b); + __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) + Py_INCREF(__pyx_cython_runtime); + 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__geoprocessing_core) { + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name_2, __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.geoprocessing_core")) { + if (unlikely(PyDict_SetItemString(modules, "pygeoprocessing.geoprocessing_core", __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)) __PYX_ERR(0, 1, __pyx_L1_error) + if (unlikely(__Pyx_modinit_type_import_code() < 0)) __PYX_ERR(0, 1, __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/geoprocessing_core.pyx":4 + * # distutils: language=c++ + * # cython: language_level=3 + * import logging # <<<<<<<<<<<<<< + * import multiprocessing + * import os + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_logging, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_logging, __pyx_t_1) < 0) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":5 + * # cython: language_level=3 + * import logging + * import multiprocessing # <<<<<<<<<<<<<< + * import os + * import pickle + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_multiprocessing, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_multiprocessing, __pyx_t_1) < 0) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":6 + * import logging + * import multiprocessing + * import os # <<<<<<<<<<<<<< + * import pickle + * import shutil + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_os, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_1) < 0) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":7 + * import multiprocessing + * import os + * import pickle # <<<<<<<<<<<<<< + * import shutil + * import sys + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_pickle, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pickle, __pyx_t_1) < 0) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":8 + * import os + * import pickle + * import shutil # <<<<<<<<<<<<<< + * import sys + * import tempfile + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_shutil, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_shutil, __pyx_t_1) < 0) __PYX_ERR(0, 8, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":9 + * import pickle + * import shutil + * import sys # <<<<<<<<<<<<<< + * import tempfile + * import time + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_sys, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) __PYX_ERR(0, 9, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":10 + * import shutil + * import sys + * import tempfile # <<<<<<<<<<<<<< + * import time + * import traceback + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_tempfile, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 10, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_tempfile, __pyx_t_1) < 0) __PYX_ERR(0, 10, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":11 + * import sys + * import tempfile + * import time # <<<<<<<<<<<<<< + * import traceback + * import zlib + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_time, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_time, __pyx_t_1) < 0) __PYX_ERR(0, 11, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":12 + * import tempfile + * import time + * import traceback # <<<<<<<<<<<<<< + * import zlib + * + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_traceback, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_traceback, __pyx_t_1) < 0) __PYX_ERR(0, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":13 + * import time + * import traceback + * import zlib # <<<<<<<<<<<<<< + * + * cimport cython + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_zlib, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_zlib, __pyx_t_1) < 0) __PYX_ERR(0, 13, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":26 + * from libc.stdio cimport fwrite + * from libcpp.vector cimport vector + * from osgeo import gdal # <<<<<<<<<<<<<< + * from osgeo import osr + * import 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, 0); 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/geoprocessing_core.pyx":27 + * from libcpp.vector cimport vector + * from osgeo import gdal + * from osgeo import osr # <<<<<<<<<<<<<< + * import numpy + * import pygeoprocessing + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 27, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_osr); + __Pyx_GIVEREF(__pyx_n_s_osr); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_osr); + __pyx_t_1 = __Pyx_Import(__pyx_n_s_osgeo, __pyx_t_2, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 27, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_osr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 27, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_osr, __pyx_t_2) < 0) __PYX_ERR(0, 27, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":28 + * from osgeo import gdal + * from osgeo import osr + * import numpy # <<<<<<<<<<<<<< + * import pygeoprocessing + * + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 28, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_numpy, __pyx_t_1) < 0) __PYX_ERR(0, 28, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":29 + * from osgeo import osr + * import numpy + * import pygeoprocessing # <<<<<<<<<<<<<< + * + * DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS = ('GTIFF', ( + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_pygeoprocessing, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 29, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pygeoprocessing, __pyx_t_1) < 0) __PYX_ERR(0, 29, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":31 + * import pygeoprocessing + * + * DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS = ('GTIFF', ( # <<<<<<<<<<<<<< + * 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', + * 'BLOCKXSIZE=256', 'BLOCKYSIZE=256')) + */ + if (PyDict_SetItem(__pyx_d, __pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT, __pyx_tuple__24) < 0) __PYX_ERR(0, 31, __pyx_L1_error) + + /* "pygeoprocessing/geoprocessing_core.pyx":42 + * # axis order, which will use Lon,Lat order for Geographic CRS, but otherwise + * # leaves Projected CRS alone + * DEFAULT_OSR_AXIS_MAPPING_STRATEGY = osr.OAMS_TRADITIONAL_GIS_ORDER # <<<<<<<<<<<<<< + * + * LOGGER = logging.getLogger('pygeoprocessing.geoprocessing_core') + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_osr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 42, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OAMS_TRADITIONAL_GIS_ORDER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 42, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_DEFAULT_OSR_AXIS_MAPPING_STRATEG, __pyx_t_2) < 0) __PYX_ERR(0, 42, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":44 + * DEFAULT_OSR_AXIS_MAPPING_STRATEGY = osr.OAMS_TRADITIONAL_GIS_ORDER + * + * LOGGER = logging.getLogger('pygeoprocessing.geoprocessing_core') # <<<<<<<<<<<<<< + * + * cdef float _NODATA = -1.0 + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_logging); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 44, __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, 44, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 44, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_LOGGER, __pyx_t_2) < 0) __PYX_ERR(0, 44, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":46 + * LOGGER = logging.getLogger('pygeoprocessing.geoprocessing_core') + * + * cdef float _NODATA = -1.0 # <<<<<<<<<<<<<< + * + * cdef extern from "FastFileIterator.h" nogil: + */ + __pyx_v_15pygeoprocessing_18geoprocessing_core__NODATA = -1.0; + + /* "pygeoprocessing/geoprocessing_core.pyx":71 + * @cython.wraparound(False) + * @cython.cdivision(True) + * def _distance_transform_edt( # <<<<<<<<<<<<<< + * region_raster_path, g_raster_path, float sample_d_x, + * float sample_d_y, target_distance_raster_path, + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_18geoprocessing_core_1_distance_transform_edt, NULL, __pyx_n_s_pygeoprocessing_geoprocessing_co); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 71, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_distance_transform_edt, __pyx_t_2) < 0) __PYX_ERR(0, 71, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":289 + * def calculate_slope( + * base_elevation_raster_path_band, target_slope_path, + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): # <<<<<<<<<<<<<< + * """Create a percent slope raster from DEM raster. + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 289, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_k__3 = __pyx_t_2; + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":287 + * @cython.nonecheck(False) + * @cython.cdivision(True) + * def calculate_slope( # <<<<<<<<<<<<<< + * base_elevation_raster_path_band, target_slope_path, + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_18geoprocessing_core_3calculate_slope, NULL, __pyx_n_s_pygeoprocessing_geoprocessing_co); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 287, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_calculate_slope, __pyx_t_2) < 0) __PYX_ERR(0, 287, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":544 + * @cython.boundscheck(False) + * @cython.cdivision(True) + * def stats_worker(stats_work_queue, expected_blocks): # <<<<<<<<<<<<<< + * """Worker to calculate continuous min, max, mean and standard deviation. + * + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_18geoprocessing_core_5stats_worker, NULL, __pyx_n_s_pygeoprocessing_geoprocessing_co); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 544, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_stats_worker, __pyx_t_2) < 0) __PYX_ERR(0, 544, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":626 + * + * + * def raster_band_percentile( # <<<<<<<<<<<<<< + * base_raster_path_band, working_sort_directory, percentile_list, + * heap_buffer_size=2**28, ffi_buffer_size=2**10): + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_18geoprocessing_core_7raster_band_percentile, NULL, __pyx_n_s_pygeoprocessing_geoprocessing_co); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 626, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_raster_band_percentile, __pyx_t_2) < 0) __PYX_ERR(0, 626, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":673 + * + * + * def _raster_band_percentile_int( # <<<<<<<<<<<<<< + * base_raster_path_band, working_sort_directory, percentile_list, + * heap_buffer_size, ffi_buffer_size): + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_18geoprocessing_core_9_raster_band_percentile_int, NULL, __pyx_n_s_pygeoprocessing_geoprocessing_co); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 673, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_raster_band_percentile_int, __pyx_t_2) < 0) __PYX_ERR(0, 673, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":819 + * + * + * def _raster_band_percentile_double( # <<<<<<<<<<<<<< + * base_raster_path_band, working_sort_directory, percentile_list, + * heap_buffer_size, ffi_buffer_size): + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_18geoprocessing_core_11_raster_band_percentile_double, NULL, __pyx_n_s_pygeoprocessing_geoprocessing_co); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 819, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_raster_band_percentile_double, __pyx_t_2) < 0) __PYX_ERR(0, 819, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/geoprocessing_core.pyx":1 + * # coding=UTF-8 # <<<<<<<<<<<<<< + * # distutils: language=c++ + * # cython: language_level=3 + */ + __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "View.MemoryView":209 + * info.obj = self + * + * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)") # <<<<<<<<<<<<<< + * + * def __dealloc__(array self): + */ + __pyx_t_2 = __pyx_capsule_create(((void *)(&__pyx_array_getbuffer)), ((char *)"getbuffer(obj, view, flags)")); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 209, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem((PyObject *)__pyx_array_type->tp_dict, __pyx_n_s_pyx_getbuffer, __pyx_t_2) < 0) __PYX_ERR(2, 209, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyType_Modified(__pyx_array_type); + + /* "View.MemoryView":286 + * return self.name + * + * cdef generic = Enum("") # <<<<<<<<<<<<<< + * cdef strided = Enum("") # default + * cdef indirect = Enum("") + */ + __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 286, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XGOTREF(generic); + __Pyx_DECREF_SET(generic, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + + /* "View.MemoryView":287 + * + * cdef generic = Enum("") + * cdef strided = Enum("") # default # <<<<<<<<<<<<<< + * cdef indirect = Enum("") + * + */ + __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 287, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XGOTREF(strided); + __Pyx_DECREF_SET(strided, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + + /* "View.MemoryView":288 + * cdef generic = Enum("") + * cdef strided = Enum("") # default + * cdef indirect = Enum("") # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__41, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 288, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XGOTREF(indirect); + __Pyx_DECREF_SET(indirect, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + + /* "View.MemoryView":291 + * + * + * cdef contiguous = Enum("") # <<<<<<<<<<<<<< + * cdef indirect_contiguous = Enum("") + * + */ + __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__42, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 291, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XGOTREF(contiguous); + __Pyx_DECREF_SET(contiguous, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + + /* "View.MemoryView":292 + * + * cdef contiguous = Enum("") + * cdef indirect_contiguous = Enum("") # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__43, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 292, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XGOTREF(indirect_contiguous); + __Pyx_DECREF_SET(indirect_contiguous, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + + /* "View.MemoryView":316 + * + * DEF THREAD_LOCKS_PREALLOCATED = 8 + * cdef int __pyx_memoryview_thread_locks_used = 0 # <<<<<<<<<<<<<< + * cdef PyThread_type_lock[THREAD_LOCKS_PREALLOCATED] __pyx_memoryview_thread_locks = [ + * PyThread_allocate_lock(), + */ + __pyx_memoryview_thread_locks_used = 0; + + /* "View.MemoryView":317 + * DEF THREAD_LOCKS_PREALLOCATED = 8 + * cdef int __pyx_memoryview_thread_locks_used = 0 + * cdef PyThread_type_lock[THREAD_LOCKS_PREALLOCATED] __pyx_memoryview_thread_locks = [ # <<<<<<<<<<<<<< + * PyThread_allocate_lock(), + * PyThread_allocate_lock(), + */ + __pyx_t_3[0] = PyThread_allocate_lock(); + __pyx_t_3[1] = PyThread_allocate_lock(); + __pyx_t_3[2] = PyThread_allocate_lock(); + __pyx_t_3[3] = PyThread_allocate_lock(); + __pyx_t_3[4] = PyThread_allocate_lock(); + __pyx_t_3[5] = PyThread_allocate_lock(); + __pyx_t_3[6] = PyThread_allocate_lock(); + __pyx_t_3[7] = PyThread_allocate_lock(); + memcpy(&(__pyx_memoryview_thread_locks[0]), __pyx_t_3, sizeof(__pyx_memoryview_thread_locks[0]) * (8)); + + /* "View.MemoryView":549 + * info.obj = self + * + * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_2 = __pyx_capsule_create(((void *)(&__pyx_memoryview_getbuffer)), ((char *)"getbuffer(obj, view, flags)")); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 549, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem((PyObject *)__pyx_memoryview_type->tp_dict, __pyx_n_s_pyx_getbuffer, __pyx_t_2) < 0) __PYX_ERR(2, 549, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyType_Modified(__pyx_memoryview_type); + + /* "View.MemoryView":995 + * return self.from_object + * + * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_2 = __pyx_capsule_create(((void *)(&__pyx_memoryview_getbuffer)), ((char *)"getbuffer(obj, view, flags)")); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 995, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem((PyObject *)__pyx_memoryviewslice_type->tp_dict, __pyx_n_s_pyx_getbuffer, __pyx_t_2) < 0) __PYX_ERR(2, 995, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyType_Modified(__pyx_memoryviewslice_type); + + /* "(tree fragment)":1 + * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15View_dot_MemoryView_1__pyx_unpickle_Enum, NULL, __pyx_n_s_View_MemoryView); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_Enum, __pyx_t_2) < 0) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "(tree fragment)":11 + * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result.name = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + */ + + /*--- Wrapped vars code ---*/ + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + if (__pyx_m) { + if (__pyx_d) { + __Pyx_AddTraceback("init pygeoprocessing.geoprocessing_core", __pyx_clineno, __pyx_lineno, __pyx_filename); + } + Py_CLEAR(__pyx_m); + } else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_ImportError, "init pygeoprocessing.geoprocessing_core"); + } + __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(modname); + if (!m) goto end; + p = PyObject_GetAttrString(m, "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_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 + (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(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 + (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(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; +} + +/* PyDictVersioning */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0; +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { + PyObject **dictptr = NULL; + Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; + if (offset) { +#if CYTHON_COMPILING_IN_CPYTHON + dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); +#else + dictptr = _PyObject_GetDictPtr(obj); +#endif + } + return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; +} +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict))) + return 0; + return obj_dict_version == __Pyx_get_object_dict_version(obj); +} +#endif + +/* GetModuleGlobalName */ +#if CYTHON_USE_DICT_VERSIONS +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value) +#else +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name) +#endif +{ + 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); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } else if (unlikely(PyErr_Occurred())) { + return NULL; + } +#else + result = PyDict_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } +#endif +#else + result = PyObject_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } + PyErr_Clear(); +#endif + return __Pyx_GetBuiltinName(name); +} + +/* PyFunctionFastCall */ +#if CYTHON_FAST_PYCALL +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 = __Pyx_PyFrame_GetLocalsplus(f); + 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, Py_ssize_t 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, (int)nargs, + k, (int)nk, + d, (int)nd, kwdefs, closure); +#else + result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL, + args, (int)nargs, + k, (int)nk, + d, (int)nd, closure); +#endif + Py_XDECREF(kwtuple); +done: + Py_LeaveRecursiveCall(); + return result; +} +#endif +#endif + +/* 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 | METH_STACKLESS))); + 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)(void*)meth)) (self, args, nargs, NULL); + } else { + return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs); + } +} +#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 + +/* PyObjectCall2Args */ +static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) { + PyObject *args, *result = NULL; + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(function)) { + PyObject *args[2] = {arg1, arg2}; + return __Pyx_PyFunction_FastCall(function, args, 2); + } + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(function)) { + PyObject *args[2] = {arg1, arg2}; + return __Pyx_PyCFunction_FastCall(function, args, 2); + } + #endif + args = PyTuple_New(2); + if (unlikely(!args)) goto done; + Py_INCREF(arg1); + PyTuple_SET_ITEM(args, 0, arg1); + Py_INCREF(arg2); + PyTuple_SET_ITEM(args, 1, arg2); + Py_INCREF(function); + result = __Pyx_PyObject_Call(function, args, NULL); + Py_DECREF(args); + Py_DECREF(function); +done: + return result; +} + +/* 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 (__Pyx_PyFastCFunction_Check(func)) { + 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 + +/* 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_CyFunction_Check(func))) +#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 + +/* 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()) { + if (unlikely(PyTuple_Check(key))) { + PyObject* args = PyTuple_Pack(1, key); + if (likely(args)) { + PyErr_SetObject(PyExc_KeyError, args); + Py_DECREF(args); + } + } else { + PyErr_SetObject(PyExc_KeyError, key); + } + } + return NULL; + } + Py_INCREF(value); + return value; +} +#endif + +/* 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(__Pyx_is_valid_index(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(__Pyx_is_valid_index(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(__Pyx_is_valid_index(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(__Pyx_is_valid_index(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)); +} + +/* 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 '?': return "'bool'"; + 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 '?': 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 '?': 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, 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; + ndim = ctx->head->field->type->ndim; + 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 '?': 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->is_valid_array)) { + 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((size_t)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; +} + +/* BufferFallbackError */ + static void __Pyx_RaiseBufferFallbackError(void) { + PyErr_SetString(PyExc_ValueError, + "Buffer acquisition failed on assignment; and then reacquiring the old buffer failed too!"); +} + +/* PyIntCompare */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED long 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))) { + int unequal; + unsigned long uintval; + Py_ssize_t size = Py_SIZE(op1); + const digit* digits = ((PyLongObject*)op1)->ob_digit; + if (intval == 0) { + if (size == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE; + } else if (intval < 0) { + if (size >= 0) + Py_RETURN_FALSE; + intval = -intval; + size = -size; + } else { + if (size <= 0) + Py_RETURN_FALSE; + } + uintval = (unsigned long) intval; +#if PyLong_SHIFT * 4 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 4)) { + unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif +#if PyLong_SHIFT * 3 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 3)) { + unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif +#if PyLong_SHIFT * 2 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 2)) { + unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif +#if PyLong_SHIFT * 1 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 1)) { + unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif + unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK)); + if (unequal == 0) 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)); +} + +/* 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 + +/* 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 + +/* 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; +} + +/* PyIntBinop */ + #if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) { + (void)inplace; + (void)zerodivision_check; + #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, int inplace, int zerodivision_check) { + (void)inplace; + (void)zerodivision_check; + #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 + +/* PyObjectGetMethod */ + static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) { + PyObject *attr; +#if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP + PyTypeObject *tp = Py_TYPE(obj); + PyObject *descr; + descrgetfunc f = NULL; + PyObject **dictptr, *dict; + int meth_found = 0; + assert (*method == NULL); + if (unlikely(tp->tp_getattro != PyObject_GenericGetAttr)) { + attr = __Pyx_PyObject_GetAttrStr(obj, name); + goto try_unpack; + } + if (unlikely(tp->tp_dict == NULL) && unlikely(PyType_Ready(tp) < 0)) { + return 0; + } + descr = _PyType_Lookup(tp, name); + if (likely(descr != NULL)) { + Py_INCREF(descr); +#if PY_MAJOR_VERSION >= 3 + #ifdef __Pyx_CyFunction_USED + if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type) || __Pyx_CyFunction_Check(descr))) + #else + if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type))) + #endif +#else + #ifdef __Pyx_CyFunction_USED + if (likely(PyFunction_Check(descr) || __Pyx_CyFunction_Check(descr))) + #else + if (likely(PyFunction_Check(descr))) + #endif +#endif + { + meth_found = 1; + } else { + f = Py_TYPE(descr)->tp_descr_get; + if (f != NULL && PyDescr_IsData(descr)) { + attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); + Py_DECREF(descr); + goto try_unpack; + } + } + } + dictptr = _PyObject_GetDictPtr(obj); + if (dictptr != NULL && (dict = *dictptr) != NULL) { + Py_INCREF(dict); + attr = __Pyx_PyDict_GetItemStr(dict, name); + if (attr != NULL) { + Py_INCREF(attr); + Py_DECREF(dict); + Py_XDECREF(descr); + goto try_unpack; + } + Py_DECREF(dict); + } + if (meth_found) { + *method = descr; + return 1; + } + if (f != NULL) { + attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); + Py_DECREF(descr); + goto try_unpack; + } + if (descr != NULL) { + *method = descr; + return 0; + } + PyErr_Format(PyExc_AttributeError, +#if PY_MAJOR_VERSION >= 3 + "'%.50s' object has no attribute '%U'", + tp->tp_name, name); +#else + "'%.50s' object has no attribute '%.400s'", + tp->tp_name, PyString_AS_STRING(name)); +#endif + return 0; +#else + attr = __Pyx_PyObject_GetAttrStr(obj, name); + goto try_unpack; +#endif +try_unpack: +#if CYTHON_UNPACK_METHODS + if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) { + PyObject *function = PyMethod_GET_FUNCTION(attr); + Py_INCREF(function); + Py_DECREF(attr); + *method = function; + return 1; + } +#endif + *method = attr; + return 0; +} + +/* PyObjectCallMethod0 */ + static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) { + PyObject *method = NULL, *result = NULL; + int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); + if (likely(is_method)) { + result = __Pyx_PyObject_CallOneArg(method, obj); + Py_DECREF(method); + return result; + } + if (unlikely(!method)) goto bad; + result = __Pyx_PyObject_CallNoArg(method); + Py_DECREF(method); +bad: + return result; +} + +/* RaiseNoneIterError */ + static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); +} + +/* UnpackTupleError */ + static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) { + if (t == Py_None) { + __Pyx_RaiseNoneNotIterableError(); + } else if (PyTuple_GET_SIZE(t) < index) { + __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(t)); + } else { + __Pyx_RaiseTooManyValuesError(index); + } +} + +/* UnpackTuple2 */ + static CYTHON_INLINE int __Pyx_unpack_tuple2_exact( + PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2, int decref_tuple) { + PyObject *value1 = NULL, *value2 = NULL; +#if CYTHON_COMPILING_IN_PYPY + value1 = PySequence_ITEM(tuple, 0); if (unlikely(!value1)) goto bad; + value2 = PySequence_ITEM(tuple, 1); if (unlikely(!value2)) goto bad; +#else + value1 = PyTuple_GET_ITEM(tuple, 0); Py_INCREF(value1); + value2 = PyTuple_GET_ITEM(tuple, 1); Py_INCREF(value2); +#endif + if (decref_tuple) { + Py_DECREF(tuple); + } + *pvalue1 = value1; + *pvalue2 = value2; + return 0; +#if CYTHON_COMPILING_IN_PYPY +bad: + Py_XDECREF(value1); + Py_XDECREF(value2); + if (decref_tuple) { Py_XDECREF(tuple); } + return -1; +#endif +} +static int __Pyx_unpack_tuple2_generic(PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2, + int has_known_size, int decref_tuple) { + Py_ssize_t index; + PyObject *value1 = NULL, *value2 = NULL, *iter = NULL; + iternextfunc iternext; + iter = PyObject_GetIter(tuple); + if (unlikely(!iter)) goto bad; + if (decref_tuple) { Py_DECREF(tuple); tuple = NULL; } + iternext = Py_TYPE(iter)->tp_iternext; + value1 = iternext(iter); if (unlikely(!value1)) { index = 0; goto unpacking_failed; } + value2 = iternext(iter); if (unlikely(!value2)) { index = 1; goto unpacking_failed; } + if (!has_known_size && unlikely(__Pyx_IternextUnpackEndCheck(iternext(iter), 2))) goto bad; + Py_DECREF(iter); + *pvalue1 = value1; + *pvalue2 = value2; + return 0; +unpacking_failed: + if (!has_known_size && __Pyx_IterFinish() == 0) + __Pyx_RaiseNeedMoreValuesError(index); +bad: + Py_XDECREF(iter); + Py_XDECREF(value1); + Py_XDECREF(value2); + if (decref_tuple) { Py_XDECREF(tuple); } + return -1; +} + +/* dict_iter */ + static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_dict, PyObject* method_name, + Py_ssize_t* p_orig_length, int* p_source_is_dict) { + is_dict = is_dict || likely(PyDict_CheckExact(iterable)); + *p_source_is_dict = is_dict; + if (is_dict) { +#if !CYTHON_COMPILING_IN_PYPY + *p_orig_length = PyDict_Size(iterable); + Py_INCREF(iterable); + return iterable; +#elif PY_MAJOR_VERSION >= 3 + static PyObject *py_items = NULL, *py_keys = NULL, *py_values = NULL; + PyObject **pp = NULL; + if (method_name) { + const char *name = PyUnicode_AsUTF8(method_name); + if (strcmp(name, "iteritems") == 0) pp = &py_items; + else if (strcmp(name, "iterkeys") == 0) pp = &py_keys; + else if (strcmp(name, "itervalues") == 0) pp = &py_values; + if (pp) { + if (!*pp) { + *pp = PyUnicode_FromString(name + 4); + if (!*pp) + return NULL; + } + method_name = *pp; + } + } +#endif + } + *p_orig_length = 0; + if (method_name) { + PyObject* iter; + iterable = __Pyx_PyObject_CallMethod0(iterable, method_name); + if (!iterable) + return NULL; +#if !CYTHON_COMPILING_IN_PYPY + if (PyTuple_CheckExact(iterable) || PyList_CheckExact(iterable)) + return iterable; +#endif + iter = PyObject_GetIter(iterable); + Py_DECREF(iterable); + return iter; + } + return PyObject_GetIter(iterable); +} +static CYTHON_INLINE int __Pyx_dict_iter_next( + PyObject* iter_obj, CYTHON_NCP_UNUSED Py_ssize_t orig_length, CYTHON_NCP_UNUSED Py_ssize_t* ppos, + PyObject** pkey, PyObject** pvalue, PyObject** pitem, int source_is_dict) { + PyObject* next_item; +#if !CYTHON_COMPILING_IN_PYPY + if (source_is_dict) { + PyObject *key, *value; + if (unlikely(orig_length != PyDict_Size(iter_obj))) { + PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration"); + return -1; + } + if (unlikely(!PyDict_Next(iter_obj, ppos, &key, &value))) { + return 0; + } + if (pitem) { + PyObject* tuple = PyTuple_New(2); + if (unlikely(!tuple)) { + return -1; + } + Py_INCREF(key); + Py_INCREF(value); + PyTuple_SET_ITEM(tuple, 0, key); + PyTuple_SET_ITEM(tuple, 1, value); + *pitem = tuple; + } else { + if (pkey) { + Py_INCREF(key); + *pkey = key; + } + if (pvalue) { + Py_INCREF(value); + *pvalue = value; + } + } + return 1; + } else if (PyTuple_CheckExact(iter_obj)) { + Py_ssize_t pos = *ppos; + if (unlikely(pos >= PyTuple_GET_SIZE(iter_obj))) return 0; + *ppos = pos + 1; + next_item = PyTuple_GET_ITEM(iter_obj, pos); + Py_INCREF(next_item); + } else if (PyList_CheckExact(iter_obj)) { + Py_ssize_t pos = *ppos; + if (unlikely(pos >= PyList_GET_SIZE(iter_obj))) return 0; + *ppos = pos + 1; + next_item = PyList_GET_ITEM(iter_obj, pos); + Py_INCREF(next_item); + } else +#endif + { + next_item = PyIter_Next(iter_obj); + if (unlikely(!next_item)) { + return __Pyx_IterFinish(); + } + } + if (pitem) { + *pitem = next_item; + } else if (pkey && pvalue) { + if (__Pyx_unpack_tuple2(next_item, pkey, pvalue, source_is_dict, source_is_dict, 1)) + return -1; + } else if (pkey) { + *pkey = next_item; + } else { + *pvalue = next_item; + } + return 1; +} + +/* MergeKeywords */ + static int __Pyx_MergeKeywords(PyObject *kwdict, PyObject *source_mapping) { + PyObject *iter, *key = NULL, *value = NULL; + int source_is_dict, result; + Py_ssize_t orig_length, ppos = 0; + iter = __Pyx_dict_iterator(source_mapping, 0, __pyx_n_s_items, &orig_length, &source_is_dict); + if (unlikely(!iter)) { + PyObject *args; + if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad; + PyErr_Clear(); + args = PyTuple_Pack(1, source_mapping); + if (likely(args)) { + PyObject *fallback = PyObject_Call((PyObject*)&PyDict_Type, args, NULL); + Py_DECREF(args); + if (likely(fallback)) { + iter = __Pyx_dict_iterator(fallback, 1, __pyx_n_s_items, &orig_length, &source_is_dict); + Py_DECREF(fallback); + } + } + if (unlikely(!iter)) goto bad; + } + while (1) { + result = __Pyx_dict_iter_next(iter, orig_length, &ppos, &key, &value, NULL, source_is_dict); + if (unlikely(result < 0)) goto bad; + if (!result) break; + if (unlikely(PyDict_Contains(kwdict, key))) { + __Pyx_RaiseDoubleKeywordsError("function", key); + result = -1; + } else { + result = PyDict_SetItem(kwdict, key, value); + } + Py_DECREF(key); + Py_DECREF(value); + if (unlikely(result < 0)) goto bad; + } + Py_XDECREF(iter); + return 0; +bad: + Py_XDECREF(iter); + return -1; +} + +/* GetTopmostException */ + #if CYTHON_USE_EXC_INFO_STACK +static _PyErr_StackItem * +__Pyx_PyErr_GetTopmostException(PyThreadState *tstate) +{ + _PyErr_StackItem *exc_info = tstate->exc_info; + while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) && + exc_info->previous_item != NULL) + { + exc_info = exc_info->previous_item; + } + return exc_info; +} +#endif + +/* SaveResetException */ + #if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + #if CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate); + *type = exc_info->exc_type; + *value = exc_info->exc_value; + *tb = exc_info->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 CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = type; + exc_info->exc_value = value; + exc_info->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; icurexc_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 + +/* 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 CYTHON_USE_EXC_INFO_STACK + { + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = local_type; + exc_info->exc_value = local_value; + exc_info->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; +} + +/* SwapException */ + #if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + #if CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = *type; + exc_info->exc_value = *value; + exc_info->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 + *type = tmp_type; + *value = tmp_value; + *tb = tmp_tb; +} +#else +static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb); + PyErr_SetExcInfo(*type, *value, *tb); + *type = tmp_type; + *value = tmp_value; + *tb = tmp_tb; +} +#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 + +/* PyObjectFormat */ + #if CYTHON_USE_UNICODE_WRITER +static PyObject* __Pyx_PyObject_Format(PyObject* obj, PyObject* format_spec) { + int ret; + _PyUnicodeWriter writer; + if (likely(PyFloat_CheckExact(obj))) { +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x03040000 + _PyUnicodeWriter_Init(&writer, 0); +#else + _PyUnicodeWriter_Init(&writer); +#endif + ret = _PyFloat_FormatAdvancedWriter( + &writer, + obj, + format_spec, 0, PyUnicode_GET_LENGTH(format_spec)); + } else if (likely(PyLong_CheckExact(obj))) { +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x03040000 + _PyUnicodeWriter_Init(&writer, 0); +#else + _PyUnicodeWriter_Init(&writer); +#endif + ret = _PyLong_FormatAdvancedWriter( + &writer, + obj, + format_spec, 0, PyUnicode_GET_LENGTH(format_spec)); + } else { + return PyObject_Format(obj, format_spec); + } + if (unlikely(ret == -1)) { + _PyUnicodeWriter_Dealloc(&writer); + return NULL; + } + return _PyUnicodeWriter_Finish(&writer); +} +#endif + +/* CIntToDigits */ + static const char DIGIT_PAIRS_10[2*10*10+1] = { + "00010203040506070809" + "10111213141516171819" + "20212223242526272829" + "30313233343536373839" + "40414243444546474849" + "50515253545556575859" + "60616263646566676869" + "70717273747576777879" + "80818283848586878889" + "90919293949596979899" +}; +static const char DIGIT_PAIRS_8[2*8*8+1] = { + "0001020304050607" + "1011121314151617" + "2021222324252627" + "3031323334353637" + "4041424344454647" + "5051525354555657" + "6061626364656667" + "7071727374757677" +}; +static const char DIGITS_HEX[2*16+1] = { + "0123456789abcdef" + "0123456789ABCDEF" +}; + +/* BuildPyUnicode */ + static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, char* chars, int clength, + int prepend_sign, char padding_char) { + PyObject *uval; + Py_ssize_t uoffset = ulength - clength; +#if CYTHON_USE_UNICODE_INTERNALS + Py_ssize_t i; +#if CYTHON_PEP393_ENABLED + void *udata; + uval = PyUnicode_New(ulength, 127); + if (unlikely(!uval)) return NULL; + udata = PyUnicode_DATA(uval); +#else + Py_UNICODE *udata; + uval = PyUnicode_FromUnicode(NULL, ulength); + if (unlikely(!uval)) return NULL; + udata = PyUnicode_AS_UNICODE(uval); +#endif + if (uoffset > 0) { + i = 0; + if (prepend_sign) { + __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, 0, '-'); + i++; + } + for (; i < uoffset; i++) { + __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, i, padding_char); + } + } + for (i=0; i < clength; i++) { + __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, uoffset+i, chars[i]); + } +#else + { + PyObject *sign = NULL, *padding = NULL; + uval = NULL; + if (uoffset > 0) { + prepend_sign = !!prepend_sign; + if (uoffset > prepend_sign) { + padding = PyUnicode_FromOrdinal(padding_char); + if (likely(padding) && uoffset > prepend_sign + 1) { + PyObject *tmp; + PyObject *repeat = PyInt_FromSize_t(uoffset - prepend_sign); + if (unlikely(!repeat)) goto done_or_error; + tmp = PyNumber_Multiply(padding, repeat); + Py_DECREF(repeat); + Py_DECREF(padding); + padding = tmp; + } + if (unlikely(!padding)) goto done_or_error; + } + if (prepend_sign) { + sign = PyUnicode_FromOrdinal('-'); + if (unlikely(!sign)) goto done_or_error; + } + } + uval = PyUnicode_DecodeASCII(chars, clength, NULL); + if (likely(uval) && padding) { + PyObject *tmp = PyNumber_Add(padding, uval); + Py_DECREF(uval); + uval = tmp; + } + if (likely(uval) && sign) { + PyObject *tmp = PyNumber_Add(sign, uval); + Py_DECREF(uval); + uval = tmp; + } +done_or_error: + Py_XDECREF(padding); + Py_XDECREF(sign); + } +#endif + return uval; +} + +/* CIntToPyUnicode */ + #ifdef _MSC_VER + #ifndef _MSC_STDINT_H_ + #if _MSC_VER < 1300 + typedef unsigned short uint16_t; + #else + typedef unsigned __int16 uint16_t; + #endif + #endif +#else + #include +#endif +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_PY_LONG_LONG(PY_LONG_LONG value, Py_ssize_t width, char padding_char, char format_char) { + char digits[sizeof(PY_LONG_LONG)*3+2]; + char *dpos, *end = digits + sizeof(PY_LONG_LONG)*3+2; + const char *hex_digits = DIGITS_HEX; + Py_ssize_t length, ulength; + int prepend_sign, last_one_off; + PY_LONG_LONG remaining; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const PY_LONG_LONG neg_one = (PY_LONG_LONG) -1, const_zero = (PY_LONG_LONG) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; + if (format_char == 'X') { + hex_digits += 16; + format_char = 'x'; + } + remaining = value; + last_one_off = 0; + dpos = end; + do { + int digit_pos; + switch (format_char) { + case 'o': + digit_pos = abs((int)(remaining % (8*8))); + remaining = (PY_LONG_LONG) (remaining / (8*8)); + dpos -= 2; + *(uint16_t*)dpos = ((const uint16_t*)DIGIT_PAIRS_8)[digit_pos]; + last_one_off = (digit_pos < 8); + break; + case 'd': + digit_pos = abs((int)(remaining % (10*10))); + remaining = (PY_LONG_LONG) (remaining / (10*10)); + dpos -= 2; + *(uint16_t*)dpos = ((const uint16_t*)DIGIT_PAIRS_10)[digit_pos]; + last_one_off = (digit_pos < 10); + break; + case 'x': + *(--dpos) = hex_digits[abs((int)(remaining % 16))]; + remaining = (PY_LONG_LONG) (remaining / 16); + break; + default: + assert(0); + break; + } + } while (unlikely(remaining != 0)); + if (last_one_off) { + assert(*dpos == '0'); + dpos++; + } + length = end - dpos; + ulength = length; + prepend_sign = 0; + if (!is_unsigned && value <= neg_one) { + if (padding_char == ' ' || width <= length + 1) { + *(--dpos) = '-'; + ++length; + } else { + prepend_sign = 1; + } + ++ulength; + } + if (width > ulength) { + ulength = width; + } + if (ulength == 1) { + return PyUnicode_FromOrdinal(*dpos); + } + return __Pyx_PyUnicode_BuildFromAscii(ulength, dpos, (int) length, prepend_sign, padding_char); +} + +/* JoinPyUnicode */ + static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength, + CYTHON_UNUSED Py_UCS4 max_char) { +#if CYTHON_USE_UNICODE_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + PyObject *result_uval; + int result_ukind; + Py_ssize_t i, char_pos; + void *result_udata; +#if CYTHON_PEP393_ENABLED + result_uval = PyUnicode_New(result_ulength, max_char); + if (unlikely(!result_uval)) return NULL; + result_ukind = (max_char <= 255) ? PyUnicode_1BYTE_KIND : (max_char <= 65535) ? PyUnicode_2BYTE_KIND : PyUnicode_4BYTE_KIND; + result_udata = PyUnicode_DATA(result_uval); +#else + result_uval = PyUnicode_FromUnicode(NULL, result_ulength); + if (unlikely(!result_uval)) return NULL; + result_ukind = sizeof(Py_UNICODE); + result_udata = PyUnicode_AS_UNICODE(result_uval); +#endif + char_pos = 0; + for (i=0; i < value_count; i++) { + int ukind; + Py_ssize_t ulength; + void *udata; + PyObject *uval = PyTuple_GET_ITEM(value_tuple, i); + if (unlikely(__Pyx_PyUnicode_READY(uval))) + goto bad; + ulength = __Pyx_PyUnicode_GET_LENGTH(uval); + if (unlikely(!ulength)) + continue; + if (unlikely(char_pos + ulength < 0)) + goto overflow; + ukind = __Pyx_PyUnicode_KIND(uval); + udata = __Pyx_PyUnicode_DATA(uval); + if (!CYTHON_PEP393_ENABLED || ukind == result_ukind) { + memcpy((char *)result_udata + char_pos * result_ukind, udata, (size_t) (ulength * result_ukind)); + } else { + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030300F0 || defined(_PyUnicode_FastCopyCharacters) + _PyUnicode_FastCopyCharacters(result_uval, char_pos, uval, 0, ulength); + #else + Py_ssize_t j; + for (j=0; j < ulength; j++) { + Py_UCS4 uchar = __Pyx_PyUnicode_READ(ukind, udata, j); + __Pyx_PyUnicode_WRITE(result_ukind, result_udata, char_pos+j, uchar); + } + #endif + } + char_pos += ulength; + } + return result_uval; +overflow: + PyErr_SetString(PyExc_OverflowError, "join() result is too long for a Python string"); +bad: + Py_DECREF(result_uval); + return NULL; +#else + result_ulength++; + value_count++; + return PyUnicode_Join(__pyx_empty_unicode, value_tuple); +#endif +} + +/* MemviewSliceInit */ + static int +__Pyx_init_memviewslice(struct __pyx_memoryview_obj *memview, + int ndim, + __Pyx_memviewslice *memviewslice, + int memview_is_new_reference) +{ + __Pyx_RefNannyDeclarations + int i, retval=-1; + Py_buffer *buf = &memview->view; + __Pyx_RefNannySetupContext("init_memviewslice", 0); + if (unlikely(memviewslice->memview || memviewslice->data)) { + PyErr_SetString(PyExc_ValueError, + "memviewslice is already initialized!"); + goto fail; + } + if (buf->strides) { + for (i = 0; i < ndim; i++) { + memviewslice->strides[i] = buf->strides[i]; + } + } else { + Py_ssize_t stride = buf->itemsize; + for (i = ndim - 1; i >= 0; i--) { + memviewslice->strides[i] = stride; + stride *= buf->shape[i]; + } + } + for (i = 0; i < ndim; i++) { + memviewslice->shape[i] = buf->shape[i]; + if (buf->suboffsets) { + memviewslice->suboffsets[i] = buf->suboffsets[i]; + } else { + memviewslice->suboffsets[i] = -1; + } + } + memviewslice->memview = memview; + memviewslice->data = (char *)buf->buf; + if (__pyx_add_acquisition_count(memview) == 0 && !memview_is_new_reference) { + Py_INCREF(memview); + } + retval = 0; + goto no_fail; +fail: + memviewslice->memview = 0; + memviewslice->data = 0; + retval = -1; +no_fail: + __Pyx_RefNannyFinishContext(); + return retval; +} +#ifndef Py_NO_RETURN +#define Py_NO_RETURN +#endif +static void __pyx_fatalerror(const char *fmt, ...) Py_NO_RETURN { + va_list vargs; + char msg[200]; +#ifdef HAVE_STDARG_PROTOTYPES + va_start(vargs, fmt); +#else + va_start(vargs); +#endif + vsnprintf(msg, 200, fmt, vargs); + va_end(vargs); + Py_FatalError(msg); +} +static CYTHON_INLINE int +__pyx_add_acquisition_count_locked(__pyx_atomic_int *acquisition_count, + PyThread_type_lock lock) +{ + int result; + PyThread_acquire_lock(lock, 1); + result = (*acquisition_count)++; + PyThread_release_lock(lock); + return result; +} +static CYTHON_INLINE int +__pyx_sub_acquisition_count_locked(__pyx_atomic_int *acquisition_count, + PyThread_type_lock lock) +{ + int result; + PyThread_acquire_lock(lock, 1); + result = (*acquisition_count)--; + PyThread_release_lock(lock); + return result; +} +static CYTHON_INLINE void +__Pyx_INC_MEMVIEW(__Pyx_memviewslice *memslice, int have_gil, int lineno) +{ + int first_time; + struct __pyx_memoryview_obj *memview = memslice->memview; + if (unlikely(!memview || (PyObject *) memview == Py_None)) + return; + if (unlikely(__pyx_get_slice_count(memview) < 0)) + __pyx_fatalerror("Acquisition count is %d (line %d)", + __pyx_get_slice_count(memview), lineno); + first_time = __pyx_add_acquisition_count(memview) == 0; + if (unlikely(first_time)) { + if (have_gil) { + Py_INCREF((PyObject *) memview); + } else { + PyGILState_STATE _gilstate = PyGILState_Ensure(); + Py_INCREF((PyObject *) memview); + PyGILState_Release(_gilstate); + } + } +} +static CYTHON_INLINE void __Pyx_XDEC_MEMVIEW(__Pyx_memviewslice *memslice, + int have_gil, int lineno) { + int last_time; + struct __pyx_memoryview_obj *memview = memslice->memview; + if (unlikely(!memview || (PyObject *) memview == Py_None)) { + memslice->memview = NULL; + return; + } + if (unlikely(__pyx_get_slice_count(memview) <= 0)) + __pyx_fatalerror("Acquisition count is %d (line %d)", + __pyx_get_slice_count(memview), lineno); + last_time = __pyx_sub_acquisition_count(memview) == 1; + memslice->data = NULL; + if (unlikely(last_time)) { + if (have_gil) { + Py_CLEAR(memslice->memview); + } else { + PyGILState_STATE _gilstate = PyGILState_Ensure(); + Py_CLEAR(memslice->memview); + PyGILState_Release(_gilstate); + } + } else { + memslice->memview = NULL; + } +} + +/* BufferIndexError */ + static void __Pyx_RaiseBufferIndexError(int axis) { + PyErr_Format(PyExc_IndexError, + "Out of bounds on buffer access (axis %d)", axis); +} + +/* ArgTypeTest */ + static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact) +{ + if (unlikely(!type)) { + PyErr_SetString(PyExc_SystemError, "Missing type object"); + return 0; + } + else if (exact) { + #if PY_MAJOR_VERSION == 2 + if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1; + #endif + } + else { + if (likely(__Pyx_TypeCheck(obj, type))) return 1; + } + PyErr_Format(PyExc_TypeError, + "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)", + name, type->tp_name, Py_TYPE(obj)->tp_name); + return 0; +} + +/* BytesEquals */ + static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY + return PyObject_RichCompareBool(s1, s2, equals); +#else + if (s1 == s2) { + return (equals == Py_EQ); + } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) { + const char *ps1, *ps2; + Py_ssize_t length = PyBytes_GET_SIZE(s1); + if (length != PyBytes_GET_SIZE(s2)) + return (equals == Py_NE); + ps1 = PyBytes_AS_STRING(s1); + ps2 = PyBytes_AS_STRING(s2); + if (ps1[0] != ps2[0]) { + return (equals == Py_NE); + } else if (length == 1) { + return (equals == Py_EQ); + } else { + int result; +#if CYTHON_USE_UNICODE_INTERNALS + Py_hash_t hash1, hash2; + hash1 = ((PyBytesObject*)s1)->ob_shash; + hash2 = ((PyBytesObject*)s2)->ob_shash; + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + return (equals == Py_NE); + } +#endif + result = memcmp(ps1, ps2, (size_t)length); + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) { + return (equals == Py_NE); + } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) { + return (equals == Py_NE); + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +#endif +} + +/* UnicodeEquals */ + static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY + return PyObject_RichCompareBool(s1, s2, equals); +#else +#if PY_MAJOR_VERSION < 3 + PyObject* owned_ref = NULL; +#endif + int s1_is_unicode, s2_is_unicode; + if (s1 == s2) { + goto return_eq; + } + s1_is_unicode = PyUnicode_CheckExact(s1); + s2_is_unicode = PyUnicode_CheckExact(s2); +#if PY_MAJOR_VERSION < 3 + if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) { + owned_ref = PyUnicode_FromObject(s2); + if (unlikely(!owned_ref)) + return -1; + s2 = owned_ref; + s2_is_unicode = 1; + } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) { + owned_ref = PyUnicode_FromObject(s1); + if (unlikely(!owned_ref)) + return -1; + s1 = owned_ref; + s1_is_unicode = 1; + } else if (((!s2_is_unicode) & (!s1_is_unicode))) { + return __Pyx_PyBytes_Equals(s1, s2, equals); + } +#endif + if (s1_is_unicode & s2_is_unicode) { + Py_ssize_t length; + int kind; + void *data1, *data2; + if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0)) + return -1; + length = __Pyx_PyUnicode_GET_LENGTH(s1); + if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) { + goto return_ne; + } +#if CYTHON_USE_UNICODE_INTERNALS + { + Py_hash_t hash1, hash2; + #if CYTHON_PEP393_ENABLED + hash1 = ((PyASCIIObject*)s1)->hash; + hash2 = ((PyASCIIObject*)s2)->hash; + #else + hash1 = ((PyUnicodeObject*)s1)->hash; + hash2 = ((PyUnicodeObject*)s2)->hash; + #endif + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + goto return_ne; + } + } +#endif + kind = __Pyx_PyUnicode_KIND(s1); + if (kind != __Pyx_PyUnicode_KIND(s2)) { + goto return_ne; + } + data1 = __Pyx_PyUnicode_DATA(s1); + data2 = __Pyx_PyUnicode_DATA(s2); + if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) { + goto return_ne; + } else if (length == 1) { + goto return_eq; + } else { + int result = memcmp(data1, data2, (size_t)(length * kind)); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & s2_is_unicode) { + goto return_ne; + } else if ((s2 == Py_None) & s1_is_unicode) { + goto return_ne; + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +return_eq: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ); +return_ne: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_NE); +#endif +} + +/* None */ + static CYTHON_INLINE Py_ssize_t __Pyx_div_Py_ssize_t(Py_ssize_t a, Py_ssize_t b) { + Py_ssize_t q = a / b; + Py_ssize_t r = a - q*b; + q -= ((r != 0) & ((r ^ b) < 0)); + return q; +} + +/* GetAttr */ + static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) { +#if CYTHON_USE_TYPE_SLOTS +#if PY_MAJOR_VERSION >= 3 + if (likely(PyUnicode_Check(n))) +#else + if (likely(PyString_Check(n))) +#endif + return __Pyx_PyObject_GetAttrStr(o, n); +#endif + return PyObject_GetAttr(o, n); +} + +/* decode_c_string */ + static CYTHON_INLINE PyObject* __Pyx_decode_c_string( + const char* cstring, Py_ssize_t start, Py_ssize_t stop, + const char* encoding, const char* errors, + PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) { + Py_ssize_t length; + if (unlikely((start < 0) | (stop < 0))) { + size_t slen = strlen(cstring); + if (unlikely(slen > (size_t) PY_SSIZE_T_MAX)) { + PyErr_SetString(PyExc_OverflowError, + "c-string too long to convert to Python"); + return NULL; + } + length = (Py_ssize_t) slen; + if (start < 0) { + start += length; + if (start < 0) + start = 0; + } + if (stop < 0) + stop += length; + } + if (unlikely(stop <= start)) + return __Pyx_NewRef(__pyx_empty_unicode); + length = stop - start; + cstring += start; + if (decode_func) { + return decode_func(cstring, length, errors); + } else { + return PyUnicode_Decode(cstring, length, encoding, errors); + } +} + +/* GetAttr3 */ + static PyObject *__Pyx_GetAttr3Default(PyObject *d) { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) + return NULL; + __Pyx_PyErr_Clear(); + Py_INCREF(d); + return d; +} +static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject *d) { + PyObject *r = __Pyx_GetAttr(o, n); + return (likely(r)) ? r : __Pyx_GetAttr3Default(d); +} + +/* 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 ((1) && (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, (PyObject *)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; +} + +/* 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 int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { + Py_ssize_t i, n; + assert(PyExceptionClass_Check(exc_type)); + n = PyTuple_GET_SIZE(tuple); +#if PY_MAJOR_VERSION >= 3 + for (i=0; i= 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; +} + +/* PyObjectGetAttrStrNoError */ + static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) + __Pyx_PyErr_Clear(); +} +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) { + PyObject *result; +#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1 + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) { + return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1); + } +#endif + result = __Pyx_PyObject_GetAttrStr(obj, attr_name); + if (unlikely(!result)) { + __Pyx_PyObject_GetAttrStr_ClearAttributeError(); + } + return result; +} + +/* 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_2); + 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 __PYX_GOOD; +#else + if (PyObject_HasAttr(type_obj, __pyx_n_s_getstate)) goto __PYX_GOOD; +#endif +#if CYTHON_USE_PYTYPE_LOOKUP + object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; +#else + object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; +#endif + reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto __PYX_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 __PYX_BAD; +#else + object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD; +#endif + reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto __PYX_BAD; + if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) { + reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_reduce_cython); + if (likely(reduce_cython)) { + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + } else if (reduce == object_reduce || PyErr_Occurred()) { + goto __PYX_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_GetAttrStrNoError(type_obj, __pyx_n_s_setstate_cython); + if (likely(setstate_cython)) { + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + } else if (!setstate || PyErr_Occurred()) { + goto __PYX_BAD; + } + } + PyType_Modified((PyTypeObject*)type_obj); + } + } + goto __PYX_GOOD; +__PYX_BAD: + if (!PyErr_Occurred()) + PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name); + ret = -1; +__PYX_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; +} + +/* TypeImport */ + #ifndef __PYX_HAVE_RT_ImportType +#define __PYX_HAVE_RT_ImportType +static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name, + size_t size, enum __Pyx_ImportType_CheckSize check_size) +{ + PyObject *result = 0; + char warning[200]; + Py_ssize_t basicsize; +#ifdef Py_LIMITED_API + PyObject *py_basicsize; +#endif + result = PyObject_GetAttrString(module, class_name); + 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 ((size_t)basicsize < size) { + PyErr_Format(PyExc_ValueError, + "%.200s.%.200s size changed, may indicate binary incompatibility. " + "Expected %zd from C header, got %zd from PyObject", + module_name, class_name, size, basicsize); + goto bad; + } + if (check_size == __Pyx_ImportType_CheckSize_Error && (size_t)basicsize != size) { + PyErr_Format(PyExc_ValueError, + "%.200s.%.200s size changed, may indicate binary incompatibility. " + "Expected %zd from C header, got %zd from PyObject", + module_name, class_name, size, basicsize); + goto bad; + } + else if (check_size == __Pyx_ImportType_CheckSize_Warn && (size_t)basicsize > size) { + PyOS_snprintf(warning, sizeof(warning), + "%s.%s size changed, may indicate binary incompatibility. " + "Expected %zd from C header, got %zd from PyObject", + module_name, class_name, size, basicsize); + if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad; + } + return (PyTypeObject *)result; +bad: + Py_XDECREF(result); + return NULL; +} +#endif + +/* CLineInTraceback */ + #ifndef CYTHON_CLINE_IN_TRACEBACK +static int __Pyx_CLineForTraceback(CYTHON_NCP_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)) { + __PYX_PY_DICT_LOOKUP_IF_MODIFIED( + use_cline, *cython_runtime_dict, + __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 (use_cline == Py_False || (use_cline != Py_True && 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_array_type)) return __pyx_array_getbuffer(obj, view, flags); + if (__Pyx_TypeCheck(obj, __pyx_memoryview_type)) return __pyx_memoryview_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)) {} + view->obj = NULL; + Py_DECREF(obj); +} +#endif + + + /* MemviewSliceIsContig */ + static int +__pyx_memviewslice_is_contig(const __Pyx_memviewslice mvs, char order, int ndim) +{ + int i, index, step, start; + Py_ssize_t itemsize = mvs.memview->view.itemsize; + if (order == 'F') { + step = 1; + start = 0; + } else { + step = -1; + start = ndim - 1; + } + for (i = 0; i < ndim; i++) { + index = start + step * i; + if (mvs.suboffsets[index] >= 0 || mvs.strides[index] != itemsize) + return 0; + itemsize *= mvs.shape[index]; + } + return 1; +} + +/* OverlappingSlices */ + static void +__pyx_get_array_memory_extents(__Pyx_memviewslice *slice, + void **out_start, void **out_end, + int ndim, size_t itemsize) +{ + char *start, *end; + int i; + start = end = slice->data; + for (i = 0; i < ndim; i++) { + Py_ssize_t stride = slice->strides[i]; + Py_ssize_t extent = slice->shape[i]; + if (extent == 0) { + *out_start = *out_end = start; + return; + } else { + if (stride > 0) + end += stride * (extent - 1); + else + start += stride * (extent - 1); + } + } + *out_start = start; + *out_end = end + itemsize; +} +static int +__pyx_slices_overlap(__Pyx_memviewslice *slice1, + __Pyx_memviewslice *slice2, + int ndim, size_t itemsize) +{ + void *start1, *end1, *start2, *end2; + __pyx_get_array_memory_extents(slice1, &start1, &end1, ndim, itemsize); + __pyx_get_array_memory_extents(slice2, &start2, &end2, ndim, itemsize); + return (start1 < end2) && (start2 < end1); +} + +/* Capsule */ + static CYTHON_INLINE PyObject * +__pyx_capsule_create(void *p, CYTHON_UNUSED const char *sig) +{ + PyObject *cobj; +#if PY_VERSION_HEX >= 0x02070000 + cobj = PyCapsule_New(p, sig, NULL); +#else + cobj = PyCObject_FromVoidPtr(p, NULL); +#endif + return cobj; +} + +/* 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;\ + } + +/* MemviewDtypeToObject */ + static CYTHON_INLINE PyObject *__pyx_memview_get_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t(const char *itemp) { + return (PyObject *) __Pyx_PyInt_From_PY_LONG_LONG(*(__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t *) itemp); +} +static CYTHON_INLINE int __pyx_memview_set_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t(const char *itemp, PyObject *obj) { + __pyx_t_15pygeoprocessing_18geoprocessing_core_int64t value = __Pyx_PyInt_As_PY_LONG_LONG(obj); + if ((value == (PY_LONG_LONG)-1) && PyErr_Occurred()) + return 0; + *(__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t *) itemp = value; + return 1; +} + +/* MemviewDtypeToObject */ + static CYTHON_INLINE PyObject *__pyx_memview_get_double(const char *itemp) { + return (PyObject *) PyFloat_FromDouble(*(double *) itemp); +} +static CYTHON_INLINE int __pyx_memview_set_double(const char *itemp, PyObject *obj) { + double value = __pyx_PyFloat_AsDouble(obj); + if ((value == (double)-1) && PyErr_Occurred()) + return 0; + *(double *) itemp = value; + return 1; +} + +/* 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 = (float)(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 = (float)(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: + 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.0, -1.0); + } + } 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 = (double)(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 = (double)(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: + 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.0, -1.0); + } + } 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 + +/* MemviewSliceCopyTemplate */ + static __Pyx_memviewslice +__pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, + const char *mode, int ndim, + size_t sizeof_dtype, int contig_flag, + int dtype_is_object) +{ + __Pyx_RefNannyDeclarations + int i; + __Pyx_memviewslice new_mvs = { 0, 0, { 0 }, { 0 }, { 0 } }; + struct __pyx_memoryview_obj *from_memview = from_mvs->memview; + Py_buffer *buf = &from_memview->view; + PyObject *shape_tuple = NULL; + PyObject *temp_int = NULL; + struct __pyx_array_obj *array_obj = NULL; + struct __pyx_memoryview_obj *memview_obj = NULL; + __Pyx_RefNannySetupContext("__pyx_memoryview_copy_new_contig", 0); + for (i = 0; i < ndim; i++) { + if (unlikely(from_mvs->suboffsets[i] >= 0)) { + PyErr_Format(PyExc_ValueError, "Cannot copy memoryview slice with " + "indirect dimensions (axis %d)", i); + goto fail; + } + } + shape_tuple = PyTuple_New(ndim); + if (unlikely(!shape_tuple)) { + goto fail; + } + __Pyx_GOTREF(shape_tuple); + for(i = 0; i < ndim; i++) { + temp_int = PyInt_FromSsize_t(from_mvs->shape[i]); + if(unlikely(!temp_int)) { + goto fail; + } else { + PyTuple_SET_ITEM(shape_tuple, i, temp_int); + temp_int = NULL; + } + } + array_obj = __pyx_array_new(shape_tuple, sizeof_dtype, buf->format, (char *) mode, NULL); + if (unlikely(!array_obj)) { + goto fail; + } + __Pyx_GOTREF(array_obj); + memview_obj = (struct __pyx_memoryview_obj *) __pyx_memoryview_new( + (PyObject *) array_obj, contig_flag, + dtype_is_object, + from_mvs->memview->typeinfo); + if (unlikely(!memview_obj)) + goto fail; + if (unlikely(__Pyx_init_memviewslice(memview_obj, ndim, &new_mvs, 1) < 0)) + goto fail; + if (unlikely(__pyx_memoryview_copy_contents(*from_mvs, new_mvs, ndim, ndim, + dtype_is_object) < 0)) + goto fail; + goto no_fail; +fail: + __Pyx_XDECREF(new_mvs.memview); + new_mvs.memview = NULL; + new_mvs.data = NULL; +no_fail: + __Pyx_XDECREF(shape_tuple); + __Pyx_XDECREF(temp_int); + __Pyx_XDECREF(array_obj); + __Pyx_RefNannyFinishContext(); + return new_mvs; +} + +/* CIntFromPy */ + static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const int neg_one = (int) -1, const_zero = (int) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + 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; +} + +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const long neg_one = (long) -1, const_zero = (long) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + 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); + } +} + +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const int neg_one = (int) -1, const_zero = (int) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + 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); + } +} + +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_PY_LONG_LONG(PY_LONG_LONG value) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const PY_LONG_LONG neg_one = (PY_LONG_LONG) -1, const_zero = (PY_LONG_LONG) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(PY_LONG_LONG) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(PY_LONG_LONG) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(PY_LONG_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(PY_LONG_LONG), + little, !is_unsigned); + } +} + +/* CIntFromPy */ + static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_As_PY_LONG_LONG(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const PY_LONG_LONG neg_one = (PY_LONG_LONG) -1, const_zero = (PY_LONG_LONG) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(PY_LONG_LONG) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (PY_LONG_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 (PY_LONG_LONG) 0; + case 1: __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, digit, digits[0]) + case 2: + if (8 * sizeof(PY_LONG_LONG) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(PY_LONG_LONG) >= 2 * PyLong_SHIFT) { + return (PY_LONG_LONG) (((((PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0])); + } + } + break; + case 3: + if (8 * sizeof(PY_LONG_LONG) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(PY_LONG_LONG) >= 3 * PyLong_SHIFT) { + return (PY_LONG_LONG) (((((((PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0])); + } + } + break; + case 4: + if (8 * sizeof(PY_LONG_LONG) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(PY_LONG_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(PY_LONG_LONG) >= 4 * PyLong_SHIFT) { + return (PY_LONG_LONG) (((((((((PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_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 (PY_LONG_LONG) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if (sizeof(PY_LONG_LONG) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT_EXC(PY_LONG_LONG, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(PY_LONG_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 (PY_LONG_LONG) 0; + case -1: __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, sdigit, (sdigit) (-(sdigit)digits[0])) + case 1: __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, digit, +digits[0]) + case -2: + if (8 * sizeof(PY_LONG_LONG) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { + return (PY_LONG_LONG) (((PY_LONG_LONG)-1)*(((((PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); + } + } + break; + case 2: + if (8 * sizeof(PY_LONG_LONG) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { + return (PY_LONG_LONG) ((((((PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); + } + } + break; + case -3: + if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { + return (PY_LONG_LONG) (((PY_LONG_LONG)-1)*(((((((PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); + } + } + break; + case 3: + if (8 * sizeof(PY_LONG_LONG) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { + return (PY_LONG_LONG) ((((((((PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); + } + } + break; + case -4: + if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(PY_LONG_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(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { + return (PY_LONG_LONG) (((PY_LONG_LONG)-1)*(((((((((PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); + } + } + break; + case 4: + if (8 * sizeof(PY_LONG_LONG) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(PY_LONG_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(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { + return (PY_LONG_LONG) ((((((((((PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); + } + } + break; + } +#endif + if (sizeof(PY_LONG_LONG) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT_EXC(PY_LONG_LONG, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(PY_LONG_LONG) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(PY_LONG_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 + PY_LONG_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 (PY_LONG_LONG) -1; + } + } else { + PY_LONG_LONG val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (PY_LONG_LONG) -1; + val = __Pyx_PyInt_As_PY_LONG_LONG(tmp); + Py_DECREF(tmp); + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to PY_LONG_LONG"); + return (PY_LONG_LONG) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to PY_LONG_LONG"); + return (PY_LONG_LONG) -1; +} + +/* CIntFromPy */ + static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const size_t neg_one = (size_t) -1, const_zero = (size_t) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + 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) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const long neg_one = (long) -1, const_zero = (long) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + 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; +} + +/* CIntFromPy */ + static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const char neg_one = (char) -1, const_zero = (char) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(char) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(char, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (char) 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 (char) 0; + case 1: __PYX_VERIFY_RETURN_INT(char, digit, digits[0]) + case 2: + if (8 * sizeof(char) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(char) >= 2 * PyLong_SHIFT) { + return (char) (((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0])); + } + } + break; + case 3: + if (8 * sizeof(char) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(char) >= 3 * PyLong_SHIFT) { + return (char) (((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])); + } + } + break; + case 4: + if (8 * sizeof(char) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(char, 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(char) >= 4 * PyLong_SHIFT) { + return (char) (((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)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 (char) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if (sizeof(char) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT_EXC(char, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(char) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(char, 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 (char) 0; + case -1: __PYX_VERIFY_RETURN_INT(char, sdigit, (sdigit) (-(sdigit)digits[0])) + case 1: __PYX_VERIFY_RETURN_INT(char, digit, +digits[0]) + case -2: + if (8 * sizeof(char) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) { + return (char) (((char)-1)*(((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); + } + } + break; + case 2: + if (8 * sizeof(char) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) { + return (char) ((((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); + } + } + break; + case -3: + if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) { + return (char) (((char)-1)*(((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); + } + } + break; + case 3: + if (8 * sizeof(char) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) { + return (char) ((((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); + } + } + break; + case -4: + if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(char, 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(char) - 1 > 4 * PyLong_SHIFT) { + return (char) (((char)-1)*(((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); + } + } + break; + case 4: + if (8 * sizeof(char) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(char, 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(char) - 1 > 4 * PyLong_SHIFT) { + return (char) ((((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); + } + } + break; + } +#endif + if (sizeof(char) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT_EXC(char, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(char) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(char, 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 + char 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 (char) -1; + } + } else { + char val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (char) -1; + val = __Pyx_PyInt_As_char(tmp); + Py_DECREF(tmp); + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to char"); + return (char) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to char"); + return (char) -1; +} + +/* TypeInfoCompare */ + static int +__pyx_typeinfo_cmp(__Pyx_TypeInfo *a, __Pyx_TypeInfo *b) +{ + int i; + if (!a || !b) + return 0; + if (a == b) + return 1; + if (a->size != b->size || a->typegroup != b->typegroup || + a->is_unsigned != b->is_unsigned || a->ndim != b->ndim) { + if (a->typegroup == 'H' || b->typegroup == 'H') { + return a->size == b->size; + } else { + return 0; + } + } + if (a->ndim) { + for (i = 0; i < a->ndim; i++) + if (a->arraysize[i] != b->arraysize[i]) + return 0; + } + if (a->typegroup == 'S') { + if (a->flags != b->flags) + return 0; + if (a->fields || b->fields) { + if (!(a->fields && b->fields)) + return 0; + for (i = 0; a->fields[i].type && b->fields[i].type; i++) { + __Pyx_StructField *field_a = a->fields + i; + __Pyx_StructField *field_b = b->fields + i; + if (field_a->offset != field_b->offset || + !__pyx_typeinfo_cmp(field_a->type, field_b->type)) + return 0; + } + return !a->fields[i].type && !b->fields[i].type; + } + } + return 1; +} + +/* MemviewSliceValidateAndInit */ + static int +__pyx_check_strides(Py_buffer *buf, int dim, int ndim, int spec) +{ + if (buf->shape[dim] <= 1) + return 1; + if (buf->strides) { + if (spec & __Pyx_MEMVIEW_CONTIG) { + if (spec & (__Pyx_MEMVIEW_PTR|__Pyx_MEMVIEW_FULL)) { + if (unlikely(buf->strides[dim] != sizeof(void *))) { + PyErr_Format(PyExc_ValueError, + "Buffer is not indirectly contiguous " + "in dimension %d.", dim); + goto fail; + } + } else if (unlikely(buf->strides[dim] != buf->itemsize)) { + PyErr_SetString(PyExc_ValueError, + "Buffer and memoryview are not contiguous " + "in the same dimension."); + goto fail; + } + } + if (spec & __Pyx_MEMVIEW_FOLLOW) { + Py_ssize_t stride = buf->strides[dim]; + if (stride < 0) + stride = -stride; + if (unlikely(stride < buf->itemsize)) { + PyErr_SetString(PyExc_ValueError, + "Buffer and memoryview are not contiguous " + "in the same dimension."); + goto fail; + } + } + } else { + if (unlikely(spec & __Pyx_MEMVIEW_CONTIG && dim != ndim - 1)) { + PyErr_Format(PyExc_ValueError, + "C-contiguous buffer is not contiguous in " + "dimension %d", dim); + goto fail; + } else if (unlikely(spec & (__Pyx_MEMVIEW_PTR))) { + PyErr_Format(PyExc_ValueError, + "C-contiguous buffer is not indirect in " + "dimension %d", dim); + goto fail; + } else if (unlikely(buf->suboffsets)) { + PyErr_SetString(PyExc_ValueError, + "Buffer exposes suboffsets but no strides"); + goto fail; + } + } + return 1; +fail: + return 0; +} +static int +__pyx_check_suboffsets(Py_buffer *buf, int dim, CYTHON_UNUSED int ndim, int spec) +{ + if (spec & __Pyx_MEMVIEW_DIRECT) { + if (unlikely(buf->suboffsets && buf->suboffsets[dim] >= 0)) { + PyErr_Format(PyExc_ValueError, + "Buffer not compatible with direct access " + "in dimension %d.", dim); + goto fail; + } + } + if (spec & __Pyx_MEMVIEW_PTR) { + if (unlikely(!buf->suboffsets || (buf->suboffsets[dim] < 0))) { + PyErr_Format(PyExc_ValueError, + "Buffer is not indirectly accessible " + "in dimension %d.", dim); + goto fail; + } + } + return 1; +fail: + return 0; +} +static int +__pyx_verify_contig(Py_buffer *buf, int ndim, int c_or_f_flag) +{ + int i; + if (c_or_f_flag & __Pyx_IS_F_CONTIG) { + Py_ssize_t stride = 1; + for (i = 0; i < ndim; i++) { + if (unlikely(stride * buf->itemsize != buf->strides[i] && buf->shape[i] > 1)) { + PyErr_SetString(PyExc_ValueError, + "Buffer not fortran contiguous."); + goto fail; + } + stride = stride * buf->shape[i]; + } + } else if (c_or_f_flag & __Pyx_IS_C_CONTIG) { + Py_ssize_t stride = 1; + for (i = ndim - 1; i >- 1; i--) { + if (unlikely(stride * buf->itemsize != buf->strides[i] && buf->shape[i] > 1)) { + PyErr_SetString(PyExc_ValueError, + "Buffer not C contiguous."); + goto fail; + } + stride = stride * buf->shape[i]; + } + } + return 1; +fail: + return 0; +} +static int __Pyx_ValidateAndInit_memviewslice( + int *axes_specs, + int c_or_f_flag, + int buf_flags, + int ndim, + __Pyx_TypeInfo *dtype, + __Pyx_BufFmt_StackElem stack[], + __Pyx_memviewslice *memviewslice, + PyObject *original_obj) +{ + struct __pyx_memoryview_obj *memview, *new_memview; + __Pyx_RefNannyDeclarations + Py_buffer *buf; + int i, spec = 0, retval = -1; + __Pyx_BufFmt_Context ctx; + int from_memoryview = __pyx_memoryview_check(original_obj); + __Pyx_RefNannySetupContext("ValidateAndInit_memviewslice", 0); + if (from_memoryview && __pyx_typeinfo_cmp(dtype, ((struct __pyx_memoryview_obj *) + original_obj)->typeinfo)) { + memview = (struct __pyx_memoryview_obj *) original_obj; + new_memview = NULL; + } else { + memview = (struct __pyx_memoryview_obj *) __pyx_memoryview_new( + original_obj, buf_flags, 0, dtype); + new_memview = memview; + if (unlikely(!memview)) + goto fail; + } + buf = &memview->view; + if (unlikely(buf->ndim != ndim)) { + PyErr_Format(PyExc_ValueError, + "Buffer has wrong number of dimensions (expected %d, got %d)", + ndim, buf->ndim); + goto fail; + } + if (new_memview) { + __Pyx_BufFmt_Init(&ctx, stack, dtype); + if (unlikely(!__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 "u byte%s) " + "does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "u byte%s)", + buf->itemsize, + (buf->itemsize > 1) ? "s" : "", + dtype->name, + dtype->size, + (dtype->size > 1) ? "s" : ""); + goto fail; + } + if (buf->len > 0) { + for (i = 0; i < ndim; i++) { + spec = axes_specs[i]; + if (unlikely(!__pyx_check_strides(buf, i, ndim, spec))) + goto fail; + if (unlikely(!__pyx_check_suboffsets(buf, i, ndim, spec))) + goto fail; + } + if (unlikely(buf->strides && !__pyx_verify_contig(buf, ndim, c_or_f_flag))) + goto fail; + } + if (unlikely(__Pyx_init_memviewslice(memview, ndim, memviewslice, + new_memview != NULL) == -1)) { + goto fail; + } + retval = 0; + goto no_fail; +fail: + Py_XDECREF(new_memview); + retval = -1; +no_fail: + __Pyx_RefNannyFinishContext(); + return retval; +} + +/* ObjectToMemviewSlice */ + static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t(PyObject *obj, int writable_flag) { + __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } }; + __Pyx_BufFmt_StackElem stack[1]; + int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_STRIDED) }; + int retcode; + if (obj == Py_None) { + result.memview = (struct __pyx_memoryview_obj *) Py_None; + return result; + } + retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, 0, + PyBUF_RECORDS_RO | writable_flag, 1, + &__Pyx_TypeInfo_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t, stack, + &result, obj); + if (unlikely(retcode == -1)) + goto __pyx_fail; + return result; +__pyx_fail: + result.memview = NULL; + result.data = NULL; + return result; +} + +/* ObjectToMemviewSlice */ + static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_double(PyObject *obj, int writable_flag) { + __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } }; + __Pyx_BufFmt_StackElem stack[1]; + int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_STRIDED) }; + int retcode; + if (obj == Py_None) { + result.memview = (struct __pyx_memoryview_obj *) Py_None; + return result; + } + retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, 0, + PyBUF_RECORDS_RO | writable_flag, 1, + &__Pyx_TypeInfo_double, stack, + &result, obj); + if (unlikely(retcode == -1)) + goto __pyx_fail; + return result; +__pyx_fail: + result.memview = NULL; + result.data = NULL; + return result; +} + +/* 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; +} + +/* 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 CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) { + int retval; + if (unlikely(!x)) return -1; + retval = __Pyx_PyObject_IsTrue(x); + Py_DECREF(x); + return retval; +} +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(b); + } +#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 */ diff --git a/src/pygeoprocessing/routing/routing.cpp b/src/pygeoprocessing/routing/routing.cpp new file mode 100644 index 00000000..73a29134 --- /dev/null +++ b/src/pygeoprocessing/routing/routing.cpp @@ -0,0 +1,65695 @@ +/* Generated by Cython 0.29.23 */ + +#ifndef PY_SSIZE_T_CLEAN +#define PY_SSIZE_T_CLEAN +#endif /* 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_29_23" +#define CYTHON_HEX_VERSION 0x001D17F0 +#define CYTHON_FUTURE_DIVISION 1 +#include +#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 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 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 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 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 (PY_VERSION_HEX >= 0x03050000) + #endif + #ifndef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1) + #endif + #ifndef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1) + #endif + #ifndef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3) + #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 + #ifdef SIZEOF_VOID_P + enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) }; + #endif +#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 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 +#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 +void __Pyx_call_destructor(T& x) { + x.~T(); +} +template +class __Pyx_FakeReference { + public: + __Pyx_FakeReference() : ptr(NULL) { } + __Pyx_FakeReference(const T& ref) : ptr(const_cast(&ref)) { } + T *operator->() { return ptr; } + T *operator&() { return ptr; } + operator T&() { return *ptr; } + template bool operator ==(U other) { return *ptr == other; } + template 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" +#if PY_VERSION_HEX >= 0x030800A4 && PY_VERSION_HEX < 0x030800B2 + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#else + #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) +#endif + #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 +#ifndef METH_STACKLESS + #define METH_STACKLESS 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 | METH_STACKLESS))))) +#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_CPYTHON && PY_VERSION_HEX < 0x030400A1 + #define PyMem_RawMalloc(n) PyMem_Malloc(n) + #define PyMem_RawRealloc(p, n) PyMem_Realloc(p, n) + #define PyMem_RawFree(p) PyMem_Free(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; +} +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 +#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) + #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) + #else + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) + #endif +#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 || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) +#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? 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 +#ifndef PyObject_Unicode + #define PyObject_Unicode PyObject_Str +#endif +#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 PY_VERSION_HEX >= 0x030900A4 + #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt) + #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size) +#else + #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt) + #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size) +#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) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(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 +#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_MARK_ERR_POS(f_index, lineno) \ + { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; } +#define __PYX_ERR(f_index, lineno, Ln_error) \ + { __PYX_MARK_ERR_POS(f_index, lineno) 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 +#include +#include "numpy/arrayobject.h" +#include "numpy/ndarrayobject.h" +#include "numpy/ndarraytypes.h" +#include "numpy/arrayscalars.h" +#include "numpy/ufuncobject.h" + + /* NumPy API declarations from "numpy/__init__.pxd" */ + +#include +#include +#include "ios" +#include "new" +#include "stdexcept" +#include "typeinfo" +#include +#include +#include + + #if __cplusplus > 199711L + #include + + namespace cython_std { + template typename std::remove_reference::type&& move(T& t) noexcept { return std::move(t); } + template typename std::remove_reference::type&& move(T&& t) noexcept { return std::move(t); } + } + + #endif + +#include +#include +#include +#include +#include "LRUCache.h" +#ifdef _OPENMP +#include +#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_UTF8 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8) +#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))) ) +static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) { + return (size_t) i < (size_t) limit; +} +#if defined (__cplusplus) && __cplusplus >= 201103L + #include + #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 int __Pyx_PyObject_IsTrueAndDecref(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) + 1); + 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 + #else + #include + #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; + + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":690 + * # 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":691 + * + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":692 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":693 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":697 + * #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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":698 + * + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":699 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":700 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":704 + * #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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":705 + * + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":714 + * # 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":715 + * # 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":716 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":718 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":719 + * + * ctypedef npy_ulong uint_t + * ctypedef npy_ulonglong ulong_t # <<<<<<<<<<<<<< + * ctypedef npy_ulonglong ulonglong_t + * + */ +typedef npy_ulonglong __pyx_t_5numpy_ulong_t; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":720 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":722 + * ctypedef npy_ulonglong ulonglong_t + * + * ctypedef npy_intp intp_t # <<<<<<<<<<<<<< + * ctypedef npy_uintp uintp_t + * + */ +typedef npy_intp __pyx_t_5numpy_intp_t; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":723 + * + * ctypedef npy_intp intp_t + * ctypedef npy_uintp uintp_t # <<<<<<<<<<<<<< + * + * ctypedef npy_double float_t + */ +typedef npy_uintp __pyx_t_5numpy_uintp_t; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":725 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":726 + * + * ctypedef npy_double float_t + * ctypedef npy_double double_t # <<<<<<<<<<<<<< + * ctypedef npy_longdouble longdouble_t + * + */ +typedef npy_double __pyx_t_5numpy_double_t; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":727 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":729 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":730 + * + * ctypedef npy_cfloat cfloat_t + * ctypedef npy_cdouble cdouble_t # <<<<<<<<<<<<<< + * ctypedef npy_clongdouble clongdouble_t + * + */ +typedef npy_cdouble __pyx_t_5numpy_cdouble_t; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":731 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":733 + * 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_StreamConnectivityPoint; +struct __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateType; +struct __pyx_t_15pygeoprocessing_7routing_7routing_FinishType; +struct __pyx_t_15pygeoprocessing_7routing_7routing_GreaterPixel; + +/* "pygeoprocessing/routing/routing.pyx":118 + * + * # 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":126 + * # 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":136 + * # d8 flow direction to walk and the source_id indicates the source stream it + * # spawned from + * cdef struct StreamConnectivityPoint: # <<<<<<<<<<<<<< + * int xi + * int yi + */ +struct __pyx_t_15pygeoprocessing_7routing_7routing_StreamConnectivityPoint { + int xi; + int yi; + int upstream_d8_dir; + int source_id; +}; + +/* "pygeoprocessing/routing/routing.pyx":143 + * + * # 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":148 + * + * + * cdef struct FinishType: # <<<<<<<<<<<<<< + * int xi + * int yi + */ +struct __pyx_t_15pygeoprocessing_7routing_7routing_FinishType { + int xi; + int yi; + int n_pushed; +}; + +/* "pygeoprocessing/routing/routing.pyx":155 + * # 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 __pyx_t_15pygeoprocessing_7routing_7routing_BlockBufferPair; + +/* "pygeoprocessing/routing/routing.pyx":158 + * + * # 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 ,__pyx_t_15pygeoprocessing_7routing_7routing_GreaterPixel> __pyx_t_15pygeoprocessing_7routing_7routing_PitPriorityQueueType; + +/* "pygeoprocessing/routing/routing.pyx":162 + * + * # 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 __pyx_t_15pygeoprocessing_7routing_7routing_IntQueueType; + +/* "pygeoprocessing/routing/routing.pyx":165 + * + * # 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 __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":168 + * + * # 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":184 + * # 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 *lru_cache; + std::set 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); + void (*flush)(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *); +}; +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); + +/* PyDictVersioning.proto */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +#define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1) +#define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\ + (version_var) = __PYX_GET_DICT_VERSION(dict);\ + (cache_var) = (value); +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\ + (VAR) = __pyx_dict_cached_value;\ + } else {\ + (VAR) = __pyx_dict_cached_value = (LOOKUP);\ + __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\ + }\ +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj); +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj); +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version); +#else +#define __PYX_GET_DICT_VERSION(dict) (0) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP); +#endif + +/* GetModuleGlobalName.proto */ +#if CYTHON_USE_DICT_VERSIONS +#define __Pyx_GetModuleGlobalName(var, name) {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\ + (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\ + __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ +} +#define __Pyx_GetModuleGlobalNameUncached(var, name) {\ + PY_UINT64_T __pyx_dict_version;\ + PyObject *__pyx_dict_cached_value;\ + (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ +} +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); +#else +#define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name) +#define __Pyx_GetModuleGlobalNameUncached(var, name) (var) = __Pyx__GetModuleGlobalName(name) +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name); +#endif + +/* 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, Py_ssize_t nargs, PyObject *kwargs); +#else +#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs) +#endif +#define __Pyx_BUILD_ASSERT_EXPR(cond)\ + (sizeof(char [1 - 2*!(cond)]) - 1) +#ifndef Py_MEMBER_SIZE +#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member) +#endif + static size_t __pyx_pyframe_localsplus_offset = 0; + #include "frameobject.h" + #define __Pxy_PyFrame_Initialize_Offsets()\ + ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\ + (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus))) + #define __Pyx_PyFrame_GetLocalsplus(frame)\ + (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset)) +#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 + +/* PyObjectCall2Args.proto */ +static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2); + +/* 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); + +/* GCCDiagnostics.proto */ +#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) +#define __Pyx_HAS_GCC_DIAGNOSTIC +#endif + +/* BuildPyUnicode.proto */ +static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, char* chars, int clength, + int prepend_sign, char padding_char); + +/* CIntToPyUnicode.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_int(int value, Py_ssize_t width, char padding_char, char format_char); + +/* PyObjectFormatAndDecref.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f); +static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f); + +/* IncludeStringH.proto */ +#include + +/* JoinPyUnicode.proto */ +static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength, + Py_UCS4 max_char); + +/* 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); + +/* PyIntCompare.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, long intval, long inplace); + +/* PyObjectFormatSimple.proto */ +#if CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyObject_FormatSimple(s, f) (\ + likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ + PyObject_Format(s, f)) +#elif PY_MAJOR_VERSION < 3 + #define __Pyx_PyObject_FormatSimple(s, f) (\ + likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ + likely(PyString_CheckExact(s)) ? PyUnicode_FromEncodedObject(s, NULL, "strict") :\ + PyObject_Format(s, f)) +#elif CYTHON_USE_TYPE_SLOTS + #define __Pyx_PyObject_FormatSimple(s, f) (\ + likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ + likely(PyLong_CheckExact(s)) ? PyLong_Type.tp_str(s) :\ + likely(PyFloat_CheckExact(s)) ? PyFloat_Type.tp_str(s) :\ + PyObject_Format(s, f)) +#else + #define __Pyx_PyObject_FormatSimple(s, f) (\ + likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ + PyObject_Format(s, f)) +#endif + +/* PyIntBinop.proto */ +#if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check); +#else +#define __Pyx_PyInt_SubtractObjC(op1, op2, intval, inplace, zerodivision_check)\ + (inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2)) +#endif + +/* None.proto */ +static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname); + +/* PyIntBinop.proto */ +#if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check); +#else +#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace, zerodivision_check)\ + (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2)) +#endif + +/* GetTopmostException.proto */ +#if CYTHON_USE_EXC_INFO_STACK +static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate); +#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 + +/* PyIntCompare.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_NeObjC(PyObject *op1, PyObject *op2, long intval, long inplace); + +/* 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 + +/* None.proto */ +static CYTHON_INLINE long __Pyx_mod_long(long, long); + +/* CIntToPyUnicode.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_long(long value, Py_ssize_t width, char padding_char, char format_char); + +/* ListAppend.proto */ +#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS +static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) { + PyListObject* L = (PyListObject*) list; + Py_ssize_t len = Py_SIZE(list); + if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) { + Py_INCREF(x); + PyList_SET_ITEM(list, len, x); + __Pyx_SET_SIZE(list, len + 1); + return 0; + } + return PyList_Append(list, x); +} +#else +#define __Pyx_PyList_Append(L,x) PyList_Append(L,x) +#endif + +/* PyObjectGetMethod.proto */ +static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method); + +/* PyObjectCallMethod1.proto */ +static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg); + +/* append.proto */ +static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x); + +/* ListCompAppend.proto */ +#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS +static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) { + PyListObject* L = (PyListObject*) list; + Py_ssize_t len = Py_SIZE(list); + if (likely(L->allocated > len)) { + Py_INCREF(x); + PyList_SET_ITEM(list, len, x); + __Pyx_SET_SIZE(list, len + 1); + return 0; + } + return PyList_Append(list, x); +} +#else +#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x) +#endif + +/* pop_index.proto */ +static PyObject* __Pyx__PyObject_PopNewIndex(PyObject* L, PyObject* py_ix); +static PyObject* __Pyx__PyObject_PopIndex(PyObject* L, PyObject* py_ix); +#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS +static PyObject* __Pyx__PyList_PopIndex(PyObject* L, PyObject* py_ix, Py_ssize_t ix); +#define __Pyx_PyObject_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) (\ + (likely(PyList_CheckExact(L) && __Pyx_fits_Py_ssize_t(ix, type, is_signed))) ?\ + __Pyx__PyList_PopIndex(L, py_ix, ix) : (\ + (unlikely((py_ix) == Py_None)) ? __Pyx__PyObject_PopNewIndex(L, to_py_func(ix)) :\ + __Pyx__PyObject_PopIndex(L, py_ix))) +#define __Pyx_PyList_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) (\ + __Pyx_fits_Py_ssize_t(ix, type, is_signed) ?\ + __Pyx__PyList_PopIndex(L, py_ix, ix) : (\ + (unlikely((py_ix) == Py_None)) ? __Pyx__PyObject_PopNewIndex(L, to_py_func(ix)) :\ + __Pyx__PyObject_PopIndex(L, py_ix))) +#else +#define __Pyx_PyList_PopIndex(L, py_ix, ix, is_signed, type, to_py_func)\ + __Pyx_PyObject_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) +#define __Pyx_PyObject_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) (\ + (unlikely((py_ix) == Py_None)) ? __Pyx__PyObject_PopNewIndex(L, to_py_func(ix)) :\ + __Pyx__PyObject_PopIndex(L, py_ix)) +#endif + +/* PyDictContains.proto */ +static CYTHON_INLINE int __Pyx_PyDict_ContainsTF(PyObject* item, PyObject* dict, int eq) { + int result = PyDict_Contains(dict, item); + return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); +} + +/* CIntToPyUnicode.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_Py_ssize_t(Py_ssize_t value, Py_ssize_t width, char padding_char, char format_char); + +/* PyObjectCallMethod0.proto */ +static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name); + +/* pop.proto */ +static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L); +#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS +static CYTHON_INLINE PyObject* __Pyx_PyList_Pop(PyObject* L); +#define __Pyx_PyObject_Pop(L) (likely(PyList_CheckExact(L)) ?\ + __Pyx_PyList_Pop(L) : __Pyx__PyObject_Pop(L)) +#else +#define __Pyx_PyList_Pop(L) __Pyx__PyObject_Pop(L) +#define __Pyx_PyObject_Pop(L) __Pyx__PyObject_Pop(L) +#endif + +/* UnpackUnboundCMethod.proto */ +typedef struct { + PyObject *type; + PyObject **method_name; + PyCFunction func; + PyObject *method; + int flag; +} __Pyx_CachedCFunction; + +/* CallUnboundCMethod0.proto */ +static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self); +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_CallUnboundCMethod0(cfunc, self)\ + (likely((cfunc)->func) ?\ + (likely((cfunc)->flag == METH_NOARGS) ? (*((cfunc)->func))(self, NULL) :\ + (PY_VERSION_HEX >= 0x030600B1 && likely((cfunc)->flag == METH_FASTCALL) ?\ + (PY_VERSION_HEX >= 0x030700A0 ?\ + (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)(cfunc)->func)(self, &__pyx_empty_tuple, 0) :\ + (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, &__pyx_empty_tuple, 0, NULL)) :\ + (PY_VERSION_HEX >= 0x030700A0 && (cfunc)->flag == (METH_FASTCALL | METH_KEYWORDS) ?\ + (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, &__pyx_empty_tuple, 0, NULL) :\ + (likely((cfunc)->flag == (METH_VARARGS | METH_KEYWORDS)) ? ((*(PyCFunctionWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, __pyx_empty_tuple, NULL)) :\ + ((cfunc)->flag == METH_VARARGS ? (*((cfunc)->func))(self, __pyx_empty_tuple) :\ + __Pyx__CallUnboundCMethod0(cfunc, self)))))) :\ + __Pyx__CallUnboundCMethod0(cfunc, self)) +#else +#define __Pyx_CallUnboundCMethod0(cfunc, self) __Pyx__CallUnboundCMethod0(cfunc, self) +#endif + +/* ListExtend.proto */ +static CYTHON_INLINE int __Pyx_PyList_Extend(PyObject* L, PyObject* v) { +#if CYTHON_COMPILING_IN_CPYTHON + PyObject* none = _PyList_Extend((PyListObject*)L, v); + if (unlikely(!none)) + return -1; + Py_DECREF(none); + return 0; +#else + return PyList_SetSlice(L, PY_SSIZE_T_MAX, PY_SSIZE_T_MAX, v); +#endif +} + +/* PySequenceContains.proto */ +static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* seq, int eq) { + int result = PySequence_Contains(seq, item); + return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); +} + +/* RaiseNoneIterError.proto */ +static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void); + +/* UnpackTupleError.proto */ +static void __Pyx_UnpackTupleError(PyObject *, Py_ssize_t index); + +/* UnpackTuple2.proto */ +#define __Pyx_unpack_tuple2(tuple, value1, value2, is_tuple, has_known_size, decref_tuple)\ + (likely(is_tuple || PyTuple_Check(tuple)) ?\ + (likely(has_known_size || PyTuple_GET_SIZE(tuple) == 2) ?\ + __Pyx_unpack_tuple2_exact(tuple, value1, value2, decref_tuple) :\ + (__Pyx_UnpackTupleError(tuple, 2), -1)) :\ + __Pyx_unpack_tuple2_generic(tuple, value1, value2, has_known_size, decref_tuple)) +static CYTHON_INLINE int __Pyx_unpack_tuple2_exact( + PyObject* tuple, PyObject** value1, PyObject** value2, int decref_tuple); +static int __Pyx_unpack_tuple2_generic( + PyObject* tuple, PyObject** value1, PyObject** value2, int has_known_size, int decref_tuple); + +/* dict_iter.proto */ +static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* dict, int is_dict, PyObject* method_name, + Py_ssize_t* p_orig_length, int* p_is_dict); +static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* dict_or_iter, Py_ssize_t orig_length, Py_ssize_t* ppos, + PyObject** pkey, PyObject** pvalue, PyObject** pitem, int is_dict); + +/* PyObjectFormat.proto */ +#if CYTHON_USE_UNICODE_WRITER +static PyObject* __Pyx_PyObject_Format(PyObject* s, PyObject* f); +#else +#define __Pyx_PyObject_Format(s, f) PyObject_Format(s, f) +#endif + +/* pyfrozenset_new.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyFrozenSet_New(PyObject* it); + +/* PySetContains.proto */ +static CYTHON_INLINE int __Pyx_PySet_ContainsTF(PyObject* key, PyObject* set, int eq); + +/* BytesEquals.proto */ +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); + +/* UnicodeEquals.proto */ +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); + +/* 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); + +/* PyObjectGetAttrStrNoError.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name); + +/* SetupReduce.proto */ +static int __Pyx_setup_reduce(PyObject* type_obj); + +/* TypeImport.proto */ +#ifndef __PYX_HAVE_RT_ImportType_proto +#define __PYX_HAVE_RT_ImportType_proto +enum __Pyx_ImportType_CheckSize { + __Pyx_ImportType_CheckSize_Error = 0, + __Pyx_ImportType_CheckSize_Warn = 1, + __Pyx_ImportType_CheckSize_Ignore = 2 +}; +static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size); +#endif + +/* 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 + +/* 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 + + +/* CppExceptionConversion.proto */ +#ifndef __Pyx_CppExn2PyErr +#include +#include +#include +#include +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_long(long value); + +/* CIntFromPy.proto */ +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); + +/* CIntFromPy.proto */ +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); + +/* CIntFromPy.proto */ +static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_PY_LONG_LONG(PY_LONG_LONG value); + +/* 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); + +/* 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*/ +static void __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_flush(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_self); /* proto*/ + +/* Module declarations from 'cython' */ + +/* 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_generic = 0; +static PyTypeObject *__pyx_ptype_5numpy_number = 0; +static PyTypeObject *__pyx_ptype_5numpy_integer = 0; +static PyTypeObject *__pyx_ptype_5numpy_signedinteger = 0; +static PyTypeObject *__pyx_ptype_5numpy_unsignedinteger = 0; +static PyTypeObject *__pyx_ptype_5numpy_inexact = 0; +static PyTypeObject *__pyx_ptype_5numpy_floating = 0; +static PyTypeObject *__pyx_ptype_5numpy_complexfloating = 0; +static PyTypeObject *__pyx_ptype_5numpy_flexible = 0; +static PyTypeObject *__pyx_ptype_5numpy_character = 0; +static PyTypeObject *__pyx_ptype_5numpy_ufunc = 0; + +/* Module declarations from 'libc.stddef' */ + +/* Module declarations from 'libc.time' */ + +/* Module declarations from 'libcpp.deque' */ + +/* Module declarations from 'libcpp.list' */ + +/* Module declarations from 'libcpp.utility' */ + +/* Module declarations from 'libcpp.pair' */ + +/* Module declarations from 'libcpp.queue' */ + +/* Module declarations from 'libcpp.set' */ + +/* Module declarations from 'libcpp.stack' */ + +/* Module declarations from 'libcpp.vector' */ + +/* Module declarations from 'pygeoprocessing.routing.routing' */ +static PyTypeObject *__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster = 0; +static float __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD; +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_D8_XOFFSET; +static int *__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET; +static int *__pyx_v_15pygeoprocessing_7routing_7routing_D8_REVERSE_DIRECTION; +static int __pyx_v_15pygeoprocessing_7routing_7routing__MAX_PIXEL_FILL_COUNT; +static int __pyx_f_15pygeoprocessing_7routing_7routing__is_close(double, double, double, double); /*proto*/ +static void __pyx_f_15pygeoprocessing_7routing_7routing__diagonal_fill_step(int, int, int, long, long, struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *, long, PyObject *); /*proto*/ +static int __pyx_f_15pygeoprocessing_7routing_7routing__in_watershed(int, int, int, int, int, int, int, struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *, long); /*proto*/ +static PyObject *__pyx_f_15pygeoprocessing_7routing_7routing__calculate_stream_geometry(int, int, int, PyObject *, int, int, struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *, struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *, int, int, PyObject *); /*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 }; +static __Pyx_TypeInfo __Pyx_TypeInfo_nn_npy_int32 = { "npy_int32", NULL, sizeof(npy_int32), { 0 }, 0, IS_UNSIGNED(npy_int32) ? 'U' : 'I', IS_UNSIGNED(npy_int32), 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_print; +static PyObject *__pyx_builtin_ValueError; +static PyObject *__pyx_builtin_range; +static PyObject *__pyx_builtin_RuntimeError; +static PyObject *__pyx_builtin_TypeError; +static PyObject *__pyx_builtin_OSError; +static PyObject *__pyx_builtin_enumerate; +static PyObject *__pyx_builtin_min; +static PyObject *__pyx_builtin_max; +static PyObject *__pyx_builtin_sorted; +static PyObject *__pyx_builtin_ImportError; +static const char __pyx_k_[] = ", "; +static const char __pyx_k_d[] = "d"; +static const char __pyx_k_i[] = "i"; +static const char __pyx_k_j[] = "j"; +static const char __pyx_k_x[] = "x"; +static const char __pyx_k_1f[] = ".1f"; +static const char __pyx_k_ID[] = "ID"; +static const char __pyx_k_d8[] = "d8"; +static const char __pyx_k_g0[] = "g0"; +static const char __pyx_k_g1[] = "g1"; +static const char __pyx_k_g2[] = "g2"; +static const char __pyx_k_g3[] = "g3"; +static const char __pyx_k_g4[] = "g4"; +static const char __pyx_k_g5[] = "g5"; +static const char __pyx_k_of[] = " of "; +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__34[] = "_"; +static const char __pyx_k_d_n[] = "d_n"; +static const char __pyx_k_dir[] = "dir"; +static const char __pyx_k_fid[] = "fid"; +static const char __pyx_k_i_n[] = "i_n"; +static const char __pyx_k_max[] = "max"; +static const char __pyx_k_mfd[] = "mfd"; +static const char __pyx_k_min[] = "min"; +static const char __pyx_k_ogr[] = "ogr"; +static const char __pyx_k_ops[] = "ops"; +static const char __pyx_k_osr[] = "osr"; +static const char __pyx_k_pop[] = "pop"; +static const char __pyx_k_wkb[] = "wkb"; +static const char __pyx_k_x_f[] = "x_f"; +static const char __pyx_k_x_l[] = "x_l"; +static const char __pyx_k_x_n[] = "x_n"; +static const char __pyx_k_x_p[] = "x_p"; +static const char __pyx_k_x_u[] = "x_u"; +static const char __pyx_k_y_f[] = "y_f"; +static const char __pyx_k_y_l[] = "y_l"; +static const char __pyx_k_y_n[] = "y_n"; +static const char __pyx_k_y_p[] = "y_p"; +static const char __pyx_k_y_u[] = "y_u"; +static const char __pyx_k_GPKG[] = "GPKG"; +static const char __pyx_k_copy[] = "copy"; +static const char __pyx_k_ds_x[] = "ds_x"; +static const char __pyx_k_ds_y[] = "ds_y"; +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_left[] = "left"; +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_us_x[] = "us_x"; +static const char __pyx_k_us_y[] = "us_y"; +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_Union[] = "Union"; +static const char __pyx_k_close[] = "close"; +static const char __pyx_k_debug[] = "debug"; +static const char __pyx_k_ds_fa[] = "ds_fa"; +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_index[] = "index"; +static const char __pyx_k_int32[] = "int32"; +static const char __pyx_k_isnan[] = "isnan"; +static const char __pyx_k_loads[] = "loads"; +static const char __pyx_k_lower[] = "lower"; +static const char __pyx_k_n_dir[] = "n_dir"; +static const char __pyx_k_numpy[] = "numpy"; +static const char __pyx_k_order[] = "order"; +static const char __pyx_k_osgeo[] = "osgeo"; +static const char __pyx_k_p_val[] = "p_val"; +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_right[] = "right"; +static const char __pyx_k_scipy[] = "scipy"; +static const char __pyx_k_sleep[] = "sleep"; +static const char __pyx_k_stats[] = "stats"; +static const char __pyx_k_uint8[] = "uint8"; +static const char __pyx_k_us_fa[] = "us_fa"; +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_Create[] = "Create"; +static const char __pyx_k_GetFID[] = "GetFID"; +static const char __pyx_k_LOGGER[] = "LOGGER"; +static const char __pyx_k_OpenEx[] = "OpenEx"; +static const char __pyx_k_append[] = "append"; +static const char __pyx_k_astype[] = "astype"; +static const char __pyx_k_double[] = "double"; +static const char __pyx_k_ds_x_1[] = "ds_x_1"; +static const char __pyx_k_ds_y_1[] = "ds_y_1"; +static const char __pyx_k_exists[] = "exists"; +static const char __pyx_k_finish[] = "finish"; +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_n_cols[] = "n_cols"; +static const char __pyx_k_n_rows[] = "n_rows"; +static const char __pyx_k_nodata[] = "nodata"; +static const char __pyx_k_outlet[] = "outlet"; +static const char __pyx_k_prefix[] = "prefix"; +static const char __pyx_k_proj_x[] = "proj_x"; +static const char __pyx_k_proj_y[] = "proj_y"; +static const char __pyx_k_raster[] = " raster."; +static const char __pyx_k_reduce[] = "__reduce__"; +static const char __pyx_k_remove[] = "remove"; +static const char __pyx_k_rmtree[] = "rmtree"; +static const char __pyx_k_shutil[] = "shutil"; +static const char __pyx_k_sorted[] = "sorted"; +static const char __pyx_k_suffix[] = "suffix"; +static const char __pyx_k_Feature[] = "Feature"; +static const char __pyx_k_OFTReal[] = "OFTReal"; +static const char __pyx_k_OSError[] = "OSError"; +static const char __pyx_k_bak_tif[] = "_bak.tif"; +static const char __pyx_k_band_id[] = "band_id"; +static const char __pyx_k_delta_x[] = "delta_x"; +static const char __pyx_k_delta_y[] = "delta_y"; +static const char __pyx_k_dirname[] = "dirname"; +static const char __pyx_k_float64[] = "float64"; +static const char __pyx_k_left_in[] = "left_in"; +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_n_steps[] = "n_steps"; +static const char __pyx_k_next_id[] = "next_id"; +static const char __pyx_k_opening[] = "opening "; +static const char __pyx_k_options[] = "options"; +static const char __pyx_k_order_1[] = "\"order\"=1"; +static const char __pyx_k_out_dir[] = "out_dir"; +static const char __pyx_k_payload[] = "payload"; +static const char __pyx_k_reverse[] = "reverse"; +static const char __pyx_k_shapely[] = "shapely"; +static const char __pyx_k_tmp_dir[] = "tmp_dir"; +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_AddPoint[] = "AddPoint"; +static const char __pyx_k_GDT_Byte[] = "GDT_Byte"; +static const char __pyx_k_Geometry[] = "Geometry"; +static const char __pyx_k_GetField[] = "GetField"; +static const char __pyx_k_GetLayer[] = "GetLayer"; +static const char __pyx_k_SetField[] = "SetField"; +static const char __pyx_k_basename[] = "basename"; +static const char __pyx_k_complete[] = "% complete"; +static const char __pyx_k_copyfile[] = "copyfile"; +static const char __pyx_k_datatype[] = "datatype"; +static const char __pyx_k_dem_band[] = "dem_band"; +static const char __pyx_k_edge_dir[] = "edge_dir"; +static const char __pyx_k_flow_dir[] = "flow_dir"; +static const char __pyx_k_getstate[] = "__getstate__"; +static const char __pyx_k_is_drain[] = "is_drain"; +static const char __pyx_k_makedirs[] = "makedirs"; +static const char __pyx_k_n_height[] = "n_height"; +static const char __pyx_k_n_pixels[] = "n_pixels"; +static const char __pyx_k_n_points[] = "n_points"; +static const char __pyx_k_n_pushed[] = "n_pushed"; +static const char __pyx_k_open_set[] = "open_set"; +static const char __pyx_k_outlet_1[] = "\"outlet\"=1"; +static const char __pyx_k_outlet_x[] = "outlet_x"; +static const char __pyx_k_outlet_y[] = "outlet_y"; +static const char __pyx_k_priority[] = "priority"; +static const char __pyx_k_retrying[] = ", retrying..."; +static const char __pyx_k_right_in[] = "right_in"; +static const char __pyx_k_river_id[] = "river_id"; +static const char __pyx_k_setstate[] = "__setstate__"; +static const char __pyx_k_splitext[] = "splitext"; +static const char __pyx_k_strftime[] = "strftime"; +static const char __pyx_k_tempfile[] = "tempfile"; +static const char __pyx_k_test_dir[] = "test_dir"; +static const char __pyx_k_wkbPoint[] = "wkbPoint"; +static const char __pyx_k_FieldDefn[] = "FieldDefn"; +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_OF_VECTOR[] = "OF_VECTOR"; +static const char __pyx_k_TILED_YES[] = "TILED=YES"; +static const char __pyx_k_TypeError[] = "TypeError"; +static const char __pyx_k_discovery[] = "discovery"; +static const char __pyx_k_edge_side[] = "edge_side"; +static const char __pyx_k_enumerate[] = "enumerate"; +static const char __pyx_k_equal_var[] = "equal_var"; +static const char __pyx_k_exception[] = "exception"; +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_linemerge[] = "linemerge"; +static const char __pyx_k_min_p_val[] = "min_p_val"; +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_source_id[] = "source_id"; +static const char __pyx_k_stream_mr[] = "stream_mr"; +static const char __pyx_k_thresh_fa[] = "thresh_fa"; +static const char __pyx_k_ttest_ind[] = "ttest_ind"; +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_GetFeature[] = "GetFeature"; +static const char __pyx_k_OFTInteger[] = "OFTInteger"; +static const char __pyx_k_SetFeature[] = "SetFeature"; +static const char __pyx_k_ValueError[] = "ValueError"; +static const char __pyx_k_WriteArray[] = "WriteArray"; +static const char __pyx_k_block_size[] = "block_size"; +static const char __pyx_k_boundary_x[] = "boundary_x"; +static const char __pyx_k_boundary_y[] = "boundary_y"; +static const char __pyx_k_center_val[] = "center_val"; +static const char __pyx_k_complete_2[] = " complete"; +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_finish_tif[] = "finish.tif"; +static const char __pyx_k_flow_accum[] = "flow_accum"; +static const char __pyx_k_flow_dir_n[] = "flow_dir_n"; +static const char __pyx_k_flow_pixel[] = "flow_pixel"; +static const char __pyx_k_iterblocks[] = "iterblocks"; +static const char __pyx_k_more_times[] = " more times."; +static const char __pyx_k_multi_line[] = "multi_line"; +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_outlet_fid[] = "outlet_fid"; +static const char __pyx_k_pour_point[] = "pour_point"; +static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__"; +static const char __pyx_k_raster_srs[] = "raster_srs"; +static const char __pyx_k_stream_fid[] = "stream_fid"; +static const char __pyx_k_stream_val[] = "stream_val"; +static const char __pyx_k_test_order[] = "test_order"; +static const char __pyx_k_weight_val[] = "weight_val"; +static const char __pyx_k_wkbPolygon[] = "wkbPolygon"; +static const char __pyx_k_write_mode[] = "write_mode"; +static const char __pyx_k_1f_complete[] = "%.1f%% complete"; +static const char __pyx_k_AddGeometry[] = "AddGeometry"; +static const char __pyx_k_BIGTIFF_YES[] = "BIGTIFF=YES"; +static const char __pyx_k_CreateField[] = "CreateField"; +static const char __pyx_k_CreateLayer[] = "CreateLayer"; +static const char __pyx_k_DeleteField[] = "DeleteField"; +static const char __pyx_k_ExportToWkb[] = "ExportToWkb"; +static const char __pyx_k_GDT_Float64[] = "GDT_Float64"; +static const char __pyx_k_GDT_Unknown[] = "GDT_Unknown"; +static const char __pyx_k_ImportError[] = "ImportError"; +static const char __pyx_k_ReadAsArray[] = "ReadAsArray"; +static const char __pyx_k_SetGeometry[] = "SetGeometry"; +static const char __pyx_k_all_defined[] = "all_defined"; +static const char __pyx_k_base_nodata[] = "base_nodata"; +static const char __pyx_k_block_array[] = "block_array"; +static const char __pyx_k_collections[] = "collections"; +static const char __pyx_k_defaultdict[] = "defaultdict"; +static const char __pyx_k_deleted_set[] = "deleted_set"; +static const char __pyx_k_drain_queue[] = "drain_queue"; +static const char __pyx_k_fill_height[] = "fill_height"; +static const char __pyx_k_fill_pits_2[] = "fill_pits"; +static const char __pyx_k_flow_dir_d8[] = "(flow dir d8): "; +static const char __pyx_k_flow_nodata[] = "flow_nodata"; +static const char __pyx_k_for_writing[] = " for writing"; +static const char __pyx_k_gpkg_driver[] = "gpkg_driver"; +static const char __pyx_k_joined_line[] = "joined_line"; +static const char __pyx_k_mask_nodata[] = "mask_nodata"; +static const char __pyx_k_n_processed[] = "n_processed"; +static const char __pyx_k_offset_dict[] = "offset_dict"; +static const char __pyx_k_offset_info[] = "offset_info"; +static const char __pyx_k_offset_only[] = "offset_only"; +static const char __pyx_k_order_count[] = "order_count"; +static const char __pyx_k_outflow_dir[] = "outflow_dir"; +static const char __pyx_k_pixel_count[] = "pixel_count"; +static const char __pyx_k_raster_info[] = "raster_info"; +static const char __pyx_k_raster_path[] = "raster_path"; +static const char __pyx_k_raster_size[] = "raster_size"; +static const char __pyx_k_river_order[] = "river_order"; +static const char __pyx_k_root_height[] = "root_height"; +static const char __pyx_k_scipy_stats[] = "scipy.stats"; +static const char __pyx_k_shapely_ops[] = "shapely.ops"; +static const char __pyx_k_shapely_wkb[] = "shapely.wkb"; +static const char __pyx_k_stream_band[] = "stream_band"; +static const char __pyx_k_stream_line[] = "stream_line"; +static const char __pyx_k_upstream_id[] = "upstream_id"; +static const char __pyx_k_visit_count[] = "visit_count"; +static const char __pyx_k_visited_tif[] = "visited.tif"; +static const char __pyx_k_working_dir[] = "working_dir"; +static const char __pyx_k_working_fid[] = "working_fid"; +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_GetLayerDefn[] = "GetLayerDefn"; +static const char __pyx_k_OFTInteger64[] = "OFTInteger64"; +static const char __pyx_k_ResetReading[] = "ResetReading"; +static const char __pyx_k_RuntimeError[] = "RuntimeError"; +static const char __pyx_k_cell_to_test[] = "cell_to_test"; +static const char __pyx_k_channel_band[] = "channel_band"; +static const char __pyx_k_fid_to_order[] = "fid_to_order"; +static const char __pyx_k_fill_pits__s[] = "fill_pits_%s_"; +static const char __pyx_k_finish_stack[] = "finish_stack"; +static const char __pyx_k_flow_dir_mfd[] = "flow_dir_mfd"; +static const char __pyx_k_flow_dir_srs[] = "flow_dir_srs"; +static const char __pyx_k_geotransform[] = "geotransform"; +static const char __pyx_k_is_a_channel[] = "is_a_channel"; +static const char __pyx_k_mfd_flow_dir[] = "mfd_flow_dir_"; +static const char __pyx_k_n_iterations[] = "n_iterations"; +static const char __pyx_k_outlet_index[] = "outlet_index"; +static const char __pyx_k_outlet_layer[] = "outlet_layer"; +static const char __pyx_k_outlet_point[] = "outlet_point"; +static const char __pyx_k_pit_mask_tif[] = "pit_mask.tif"; +static const char __pyx_k_raster_coord[] = "raster_coord"; +static const char __pyx_k_search_queue[] = "search_queue"; +static const char __pyx_k_search_stack[] = "search_stack"; +static const char __pyx_k_search_steps[] = "search_steps"; +static const char __pyx_k_stream_array[] = "stream_array"; +static const char __pyx_k_stream_layer[] = "stream_layer"; +static const char __pyx_k_stream_order[] = "stream_order"; +static const char __pyx_k_tmp_dir_root[] = "tmp_dir_root"; +static const char __pyx_k_tmp_work_dir[] = "tmp_work_dir"; +static const char __pyx_k_upstream_dem[] = "upstream_dem"; +static const char __pyx_k_upstream_fid[] = "upstream_fid"; +static const char __pyx_k_working_geom[] = "working_geom"; +static const char __pyx_k_x_off_border[] = "x_off_border"; +static const char __pyx_k_y_off_border[] = "y_off_border"; +static const char __pyx_k_CreateFeature[] = "CreateFeature"; +static const char __pyx_k_DeleteFeature[] = "DeleteFeature"; +static const char __pyx_k_GetRasterBand[] = "GetRasterBand"; +static const char __pyx_k_ImportFromWkt[] = "ImportFromWkt"; +static const char __pyx_k_ManagedRaster[] = "_ManagedRaster"; +static const char __pyx_k_backtrace_set[] = "backtrace_set"; +static const char __pyx_k_base_datatype[] = "base_datatype"; +static const char __pyx_k_block_offsets[] = "block_offsets"; +static const char __pyx_k_boundary_list[] = "boundary_list"; +static const char __pyx_k_connected_fid[] = "connected_fid"; +static const char __pyx_k_current_pixel[] = "current_pixel"; +static const char __pyx_k_discovery_srs[] = "discovery_srs"; +static const char __pyx_k_discovery_tif[] = "discovery.tif"; +static const char __pyx_k_drop_distance[] = "drop_distance"; +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_flow_dir_d8_2[] = "flow_dir_d8"; +static const char __pyx_k_flow_dir_info[] = "flow_dir_info"; +static const char __pyx_k_flow_dir_type[] = "flow_dir_type"; +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_outlet_vector[] = "outlet_vector"; +static const char __pyx_k_pit_mask_path[] = "pit_mask_path"; +static const char __pyx_k_raster_driver[] = "raster_driver"; +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_stream_vector[] = "stream_vector"; +static const char __pyx_k_upstream_dirs[] = "upstream_dirs"; +static const char __pyx_k_upstream_fids[] = "upstream_fids"; +static const char __pyx_k_weight_nodata[] = "weight_nodata"; +static const char __pyx_k_weight_raster[] = "weight_raster"; +static const char __pyx_k_wkbLineString[] = "wkbLineString"; +static const char __pyx_k_wkbLinearRing[] = "wkbLinearRing"; +static const char __pyx_k_working_order[] = "working_order"; +static const char __pyx_k_working_stack[] = "working_stack"; +static const char __pyx_k_workspace_dir[] = "workspace_dir"; +static const char __pyx_k_100_0_complete[] = "100.0% complete"; +static const char __pyx_k_FindFieldIndex[] = "FindFieldIndex"; +static const char __pyx_k_GetGeometryRef[] = "GetGeometryRef"; +static const char __pyx_k_SPARSE_OK_TRUE[] = "SPARSE_OK=TRUE"; +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_connected_fids[] = "connected_fids"; +static const char __pyx_k_could_not_open[] = "could not open "; +static const char __pyx_k_delete_feature[] = "_delete_feature"; +static const char __pyx_k_detect_outlets[] = "detect_outlets"; +static const char __pyx_k_discovery_info[] = "discovery_info"; +static const char __pyx_k_downstream_dem[] = "downstream_dem"; +static const char __pyx_k_downstream_fid[] = "downstream_fid"; +static const char __pyx_k_drain_distance[] = "drain_distance"; +static const char __pyx_k_flow_dir_block[] = "flow_dir_block"; +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_outet_basename[] = "outet_basename"; +static const char __pyx_k_outlet_feature[] = "outlet_feature"; +static const char __pyx_k_projection_wkt[] = "projection_wkt"; +static const char __pyx_k_stream_feature[] = "stream_feature"; +static const char __pyx_k_unable_to_open[] = "unable to open "; +static const char __pyx_k_upstream_coord[] = "upstream_coord"; +static const char __pyx_k_upstream_count[] = "upstream_count"; +static const char __pyx_k_upstream_index[] = "upstream_index"; +static const char __pyx_k_upstream_order[] = "upstream_order"; +static const char __pyx_k_upstream_stack[] = "upstream_stack"; +static const char __pyx_k_GetDriverByName[] = "GetDriverByName"; +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_discovery_count[] = "discovery_count"; +static const char __pyx_k_discovery_stack[] = "discovery_stack"; +static const char __pyx_k_distance_nodata[] = "distance_nodata"; +static const char __pyx_k_downstream_geom[] = "downstream_geom"; +static const char __pyx_k_fill_value_list[] = "fill_value_list"; +static const char __pyx_k_filled_dem_band[] = "filled_dem_band"; +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_outlet_fid_list[] = "outlet_fid_list"; +static const char __pyx_k_pixels_complete[] = " pixels complete"; +static const char __pyx_k_processed_nodes[] = "processed_nodes"; +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_starting_search[] = "starting search"; +static const char __pyx_k_stream_basename[] = "stream_basename"; +static const char __pyx_k_upstream_d8_dir[] = "upstream_d8_dir"; +static const char __pyx_k_watershed_layer[] = "watershed_layer"; +static const char __pyx_k_working_feature[] = "working_feature"; +static const char __pyx_k_SpatialReference[] = "SpatialReference"; +static const char __pyx_k_StartTransaction[] = "StartTransaction"; +static const char __pyx_k_d8_flow_dir_mode[] = "d8_flow_dir_mode"; +static const char __pyx_k_dem_buffer_array[] = "dem_buffer_array"; +static const char __pyx_k_discovery_nodata[] = "discovery_nodata"; +static const char __pyx_k_downstream_order[] = "downstream_order"; +static const char __pyx_k_local_flow_accum[] = "local_flow_accum"; +static const char __pyx_k_n_drain_distance[] = "n_drain_distance"; +static const char __pyx_k_out_dir_increase[] = "out_dir_increase"; +static const char __pyx_k_outlet_detection[] = "outlet detection: "; +static const char __pyx_k_outlets_complete[] = " outlets complete"; +static const char __pyx_k_raster_path_band[] = "raster_path_band"; +static const char __pyx_k_streams_by_order[] = "streams_by_order"; +static const char __pyx_k_terminated_early[] = "terminated_early"; +static const char __pyx_k_upstream_feature[] = "upstream_feature"; +static const char __pyx_k_upstream_fid_map[] = "upstream_fid_map"; +static const char __pyx_k_upstream_id_list[] = "upstream_id_list"; +static const char __pyx_k_watershed_vector[] = "watershed_vector"; +static const char __pyx_k_win_xsize_border[] = "win_xsize_border"; +static const char __pyx_k_win_ysize_border[] = "win_ysize_border"; +static const char __pyx_k_working_dir_path[] = "working_dir_path"; +static const char __pyx_k_working_river_id[] = "working_river_id"; +static const char __pyx_k_ApplyGeoTransform[] = "ApplyGeoTransform"; +static const char __pyx_k_CommitTransaction[] = "CommitTransaction"; +static const char __pyx_k_downhill_neighbor[] = "downhill_neighbor"; +static const char __pyx_k_filled_dem_raster[] = "filled_dem_raster"; +static const char __pyx_k_finish_coordinate[] = "finish_coordinate"; +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_out_of_bounds_for[] = " out of bounds for "; +static const char __pyx_k_raw_weight_nodata[] = "raw_weight_nodata"; +static const char __pyx_k_segments_complete[] = " segments complete"; +static const char __pyx_k_stream_order_list[] = "stream_order_list"; +static const char __pyx_k_streams_to_retest[] = "streams_to_retest"; +static const char __pyx_k_upstream_fid_list[] = "upstream_fid_list"; +static const char __pyx_k_upstream_flow_dir[] = "upstream_flow_dir"; +static const char __pyx_k_visit_order_stack[] = "visit_order_stack"; +static const char __pyx_k_watershed_feature[] = "watershed_feature"; +static const char __pyx_k_watershed_polygon[] = "watershed_polygon"; +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_SetAttributeFilter[] = "SetAttributeFilter"; +static const char __pyx_k_base_feature_count[] = "base_feature_count"; +static const char __pyx_k_block_offsets_list[] = "block_offsets_list"; +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_downstream_feature[] = "downstream_feature"; +static const char __pyx_k_drain_search_queue[] = "drain_search_queue"; +static const char __pyx_k_fill_pits_complete[] = "(fill pits): complete"; +static const char __pyx_k_geoprocessing_core[] = "geoprocessing_core"; +static const char __pyx_k_nodata_drain_queue[] = "nodata_drain_queue"; +static const char __pyx_k_processed_segments[] = "processed_segments"; +static const char __pyx_k_source_point_stack[] = "source_point_stack"; +static const char __pyx_k_streams_to_process[] = "streams_to_process"; +static const char __pyx_k_target_offset_dict[] = "target_offset_dict"; +static const char __pyx_k_watershed_basename[] = "watershed_basename"; +static const char __pyx_k_watershed_boundary[] = "watershed_boundary"; +static const char __pyx_k_compressed_flow_dir[] = "compressed_flow_dir"; +static const char __pyx_k_coord_to_stream_ids[] = "coord_to_stream_ids"; +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_segments_to_process[] = "segments_to_process"; +static const char __pyx_k_source_stream_point[] = "source_stream_point"; +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_visited_raster_path[] = "visited_raster_path"; +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_d8_complete[] = "(flow dir d8): complete"; +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_max_pixel_fill_count[] = "max_pixel_fill_count"; +static const char __pyx_k_modified_offset_dict[] = "modified_offset_dict"; +static const char __pyx_k_natural_drain_exists[] = "natural_drain_exists"; +static const char __pyx_k_new_raster_from_base[] = "new_raster_from_base"; +static const char __pyx_k_outlet_at_confluence[] = "outlet_at_confluence"; +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_all_defined[] = "upstream_all_defined"; +static const char __pyx_k_upstream_flow_weight[] = "upstream_flow_weight"; +static const char __pyx_k_CreateGeometryFromWkb[] = "CreateGeometryFromWkb"; +static const char __pyx_k_direction_drain_queue[] = "direction_drain_queue"; +static const char __pyx_k_finish_managed_raster[] = "finish_managed_raster"; +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_outlet_detection_done[] = "outlet detection: done"; +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_SetAxisMappingStrategy[] = "SetAxisMappingStrategy"; +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_in_ManagedRaster_flush[] = " in ManagedRaster.flush"; +static const char __pyx_k_plateu_drain_mask_path[] = "plateu_drain_mask_path"; +static const char __pyx_k_source_points_complete[] = " source points complete"; +static const char __pyx_k_sum_of_downhill_slopes[] = "sum_of_downhill_slopes"; +static const char __pyx_k_visited_managed_raster[] = "visited_managed_raster"; +static const char __pyx_k_compatible_dem_complete[] = "compatible dem complete"; +static const char __pyx_k_connected_upstream_fids[] = "connected_upstream_fids"; +static const char __pyx_k_distance_to_channel_mfd[] = "distance_to_channel_mfd"; +static const char __pyx_k_finish_time_raster_path[] = "finish_time_raster_path"; +static const char __pyx_k_flow_dir_managed_raster[] = "flow_dir_managed_raster"; +static const char __pyx_k_max_steps_per_watershed[] = "max_steps_per_watershed"; +static const char __pyx_k_max_upstream_flow_accum[] = "max_upstream_flow_accum"; +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_quitting_too_many_steps[] = "quitting, too many steps"; +static const char __pyx_k_resulted_in_null_trying[] = " resulted in null, trying "; +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_couldn_t_remove_temp_dir[] = "couldn't remove temp dir"; +static const char __pyx_k_discovery_managed_raster[] = "discovery_managed_raster"; +static const char __pyx_k_drop_distance_collection[] = "drop_distance_collection"; +static const char __pyx_k_min_flow_accum_threshold[] = "min_flow_accum_threshold"; +static const char __pyx_k_sorted_stream_order_list[] = "sorted_stream_order_list"; +static const char __pyx_k_compressed_integer_slopes[] = "compressed_integer_slopes"; +static const char __pyx_k_discovery_time_processing[] = "(discovery time processing): "; +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_osr_axis_mapping_strategy[] = "osr_axis_mapping_strategy"; +static const char __pyx_k_stream_fragments_complete[] = " stream fragments complete"; +static const char __pyx_k_target_finish_raster_path[] = "target_finish_raster_path"; +static const char __pyx_k_target_outlet_vector_path[] = "target_outlet_vector_path"; +static const char __pyx_k_target_stream_raster_path[] = "target_stream_raster_path"; +static const char __pyx_k_target_stream_vector_path[] = "target_stream_vector_path"; +static const char __pyx_k_upstream_to_downstream_id[] = "upstream_to_downstream_id"; +static const char __pyx_k_autotune_flow_accumulation[] = "autotune_flow_accumulation"; +static const char __pyx_k_d8_flow_dir_managed_raster[] = "d8_flow_dir_managed_raster"; +static const char __pyx_k_discovery_time_raster_path[] = "discovery_time_raster_path"; +static const char __pyx_k_downstream_to_upstream_ids[] = "downstream_to_upstream_ids"; +static const char __pyx_k_flow_dir_d8_managed_raster[] = "flow_dir_d8_managed_raster"; +static const char __pyx_k_mfd_flow_accum_1f_complete[] = "mfd flow accum %.1f%% complete"; +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_extract_strahler_streams_d8[] = "extract_strahler_streams_d8"; +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_int_max_steps_per_watershed[] = "_int_max_steps_per_watershed"; +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_outlet_detection_0_complete[] = "outlet detection: 0% complete"; +static const char __pyx_k_strahler_stream_vector_path[] = "strahler_stream_vector_path"; +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_d8_flow_dir_raster_path_band[] = "d8_flow_dir_raster_path_band"; +static const char __pyx_k_dist_to_channel_mfd_work_dir[] = "dist_to_channel_mfd_work_dir"; +static const char __pyx_k_flow_dir_d8_raster_path_band[] = "flow_dir_d8_raster_path_band"; +static const char __pyx_k_raster_driver_creation_tuple[] = "raster_driver_creation_tuple"; +static const char __pyx_k_target_discovery_raster_path[] = "target_discovery_raster_path"; +static const char __pyx_k_working_downhill_slope_array[] = "working_downhill_slope_array"; +static const char __pyx_k_working_flow_accum_threshold[] = "working_flow_accum_threshold"; +static const char __pyx_k_creating_visited_raster_layer[] = "creating visited raster layer"; +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_build_discovery_finish_rasters[] = "_build_discovery_finish_rasters"; +static const char __pyx_k_Error_Block_size_is_not_a_power[] = "Error: Block size is not a power of two: block_xsize: "; +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\n 3 2 1\n 4 x 0\n 5 6 7\n"; +static const char __pyx_k_This_exception_is_happeningin_C[] = ". 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_calculate_subwatershed_boundary[] = "calculate_subwatershed_boundary_workspace_"; +static const char __pyx_k_compatable_dem_raster_path_band[] = "compatable_dem_raster_path_band"; +static const char __pyx_k_exists_removing_before_creating[] = " exists, removing before creating a new one."; +static const char __pyx_k_extract_strahler_streams_d8_all[] = "(extract_strahler_streams_d8): all done"; +static const char __pyx_k_extract_strahler_streams_d8_com[] = "(extract_strahler_streams_d8): commit transaction due to stream joining"; +static const char __pyx_k_extract_strahler_streams_d8_det[] = "(extract_strahler_streams_d8): determining stream order"; +static const char __pyx_k_extract_strahler_streams_d8_dra[] = "(extract_strahler_streams_d8): drain seeding "; +static const char __pyx_k_extract_strahler_streams_d8_fin[] = "(extract_strahler_streams_d8): final pass on stream order and geometry"; +static const char __pyx_k_extract_strahler_streams_d8_flo[] = "(extract_strahler_streams_d8): flow accumulation adjustment "; +static const char __pyx_k_extract_strahler_streams_d8_see[] = "(extract_strahler_streams_d8): seed the drains"; +static const char __pyx_k_extract_strahler_streams_d8_sta[] = "(extract_strahler_streams_d8): starting upstream walk"; +static const char __pyx_k_extract_strahler_streams_d8_str[] = "(extract_strahler_streams_d8): stream segment creation "; +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_DEFAULT_GTIFF_CREATION_TUPLE_OPT[] = "DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS"; +static const char __pyx_k_DEFAULT_OSR_AXIS_MAPPING_STRATEG[] = "DEFAULT_OSR_AXIS_MAPPING_STRATEGY"; +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_creating_target_flow_accum_raste[] = "creating target flow accum raster layer"; +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_expected_flow_dir_type_of_either[] = "expected flow dir type of either d8 or mfd but got "; +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_outlet_detection_100_complete_co[] = "outlet detection: 100% complete -- committing transaction"; +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_target_watershed_boundary_vector[] = "target_watershed_boundary_vector_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_calculate_subwatershed_boundary_2[] = "(calculate_subwatershed_boundary): watershed building "; +static const char __pyx_k_calculate_subwatershed_boundary_3[] = "(calculate_subwatershed_boundary): watershed building 100% complete"; +static const char __pyx_k_calculate_subwatershed_boundary_4[] = "calculate_subwatershed_boundary"; +static const char __pyx_k_extract_strahler_streams_d8_det_2[] = "(extract_strahler_streams_d8): determine rivers"; +static const char __pyx_k_extract_strahler_streams_d8_dra_2[] = "(extract_strahler_streams_d8): drain seeding complete"; +static const char __pyx_k_extract_strahler_streams_d8_fin_2[] = "(extract_strahler_streams_d8): final pass on stream order "; +static const char __pyx_k_extract_strahler_streams_d8_fin_3[] = "(extract_strahler_streams_d8): final pass on stream order complete"; +static const char __pyx_k_extract_strahler_streams_d8_flo_2[] = "(extract_strahler_streams_d8): flow accumulation adjustment complete"; +static const char __pyx_k_extract_strahler_streams_d8_str_2[] = "(extract_strahler_streams_d8): stream segment creation complete"; +static const char __pyx_k_extract_strahler_streams_d8_str_3[] = "(extract_strahler_streams_d8): stream order processing: "; +static const char __pyx_k_extract_strahler_streams_d8_str_4[] = "(extract_strahler_streams_d8): stream order processing complete"; +static PyObject *__pyx_kp_u_; +static PyObject *__pyx_kp_u_100_0_complete; +static PyObject *__pyx_kp_u_1f; +static PyObject *__pyx_kp_u_1f_complete; +static PyObject *__pyx_n_s_AddGeometry; +static PyObject *__pyx_n_s_AddPoint; +static PyObject *__pyx_n_s_ApplyGeoTransform; +static PyObject *__pyx_kp_u_BIGTIFF_YES; +static PyObject *__pyx_kp_u_BLOCKXSIZE_d; +static PyObject *__pyx_kp_u_BLOCKYSIZE_d; +static PyObject *__pyx_kp_u_COMPRESS_LZW; +static PyObject *__pyx_n_s_CommitTransaction; +static PyObject *__pyx_n_s_Create; +static PyObject *__pyx_n_s_CreateCopy; +static PyObject *__pyx_n_s_CreateFeature; +static PyObject *__pyx_n_s_CreateField; +static PyObject *__pyx_n_s_CreateGeometryFromWkb; +static PyObject *__pyx_n_s_CreateLayer; +static PyObject *__pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT; +static PyObject *__pyx_n_s_DEFAULT_OSR_AXIS_MAPPING_STRATEG; +static PyObject *__pyx_n_s_DeleteFeature; +static PyObject *__pyx_n_s_DeleteField; +static PyObject *__pyx_kp_u_Error_Block_size_is_not_a_power; +static PyObject *__pyx_kp_u_Error_band_ID_s_is_not_a_valid_b; +static PyObject *__pyx_n_s_ExportToWkb; +static PyObject *__pyx_n_s_Feature; +static PyObject *__pyx_n_s_FieldDefn; +static PyObject *__pyx_n_s_FindFieldIndex; +static PyObject *__pyx_n_s_FlushCache; +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_GDT_Unknown; +static PyObject *__pyx_n_u_GPKG; +static PyObject *__pyx_n_u_GTiff; +static PyObject *__pyx_n_s_Geometry; +static PyObject *__pyx_n_s_GetDriverByName; +static PyObject *__pyx_n_s_GetFID; +static PyObject *__pyx_n_s_GetFeature; +static PyObject *__pyx_n_s_GetField; +static PyObject *__pyx_n_s_GetGeometryRef; +static PyObject *__pyx_n_s_GetLayer; +static PyObject *__pyx_n_s_GetLayerDefn; +static PyObject *__pyx_n_s_GetRasterBand; +static PyObject *__pyx_n_u_ID; +static PyObject *__pyx_n_s_ImportError; +static PyObject *__pyx_n_s_ImportFromWkt; +static PyObject *__pyx_n_s_LOGGER; +static PyObject *__pyx_n_s_ManagedRaster; +static PyObject *__pyx_n_s_OFTInteger; +static PyObject *__pyx_n_s_OFTInteger64; +static PyObject *__pyx_n_s_OFTReal; +static PyObject *__pyx_n_s_OF_RASTER; +static PyObject *__pyx_n_s_OF_VECTOR; +static PyObject *__pyx_n_s_OSError; +static PyObject *__pyx_n_s_OpenEx; +static PyObject *__pyx_n_s_ReadAsArray; +static PyObject *__pyx_n_s_ResetReading; +static PyObject *__pyx_n_s_RuntimeError; +static PyObject *__pyx_kp_u_SPARSE_OK_TRUE; +static PyObject *__pyx_n_s_SetAttributeFilter; +static PyObject *__pyx_n_s_SetAxisMappingStrategy; +static PyObject *__pyx_n_s_SetFeature; +static PyObject *__pyx_n_s_SetField; +static PyObject *__pyx_n_s_SetGeometry; +static PyObject *__pyx_n_s_SpatialReference; +static PyObject *__pyx_n_s_StartTransaction; +static PyObject *__pyx_kp_u_TILED_YES; +static PyObject *__pyx_kp_u_This_exception_is_happeningin_C; +static PyObject *__pyx_n_s_TypeError; +static PyObject *__pyx_n_s_Union; +static PyObject *__pyx_n_s_ValueError; +static PyObject *__pyx_n_s_WriteArray; +static PyObject *__pyx_kp_u_Y_m_d__H__M__S; +static PyObject *__pyx_n_s__34; +static PyObject *__pyx_n_s_all_defined; +static PyObject *__pyx_n_s_append; +static PyObject *__pyx_n_s_astype; +static PyObject *__pyx_n_s_autotune_flow_accumulation; +static PyObject *__pyx_n_s_backtrace_set; +static PyObject *__pyx_kp_u_bak_tif; +static PyObject *__pyx_n_s_band_id; +static PyObject *__pyx_n_s_base_datatype; +static PyObject *__pyx_n_s_base_feature_count; +static PyObject *__pyx_n_s_base_nodata; +static PyObject *__pyx_n_s_basename; +static PyObject *__pyx_n_s_block_array; +static PyObject *__pyx_n_s_block_offsets; +static PyObject *__pyx_n_s_block_offsets_list; +static PyObject *__pyx_n_u_block_size; +static PyObject *__pyx_n_s_boundary_list; +static PyObject *__pyx_n_s_boundary_x; +static PyObject *__pyx_n_s_boundary_y; +static PyObject *__pyx_n_s_build_discovery_finish_rasters; +static PyObject *__pyx_n_u_calculate_subwatershed_boundary; +static PyObject *__pyx_kp_u_calculate_subwatershed_boundary_2; +static PyObject *__pyx_kp_u_calculate_subwatershed_boundary_3; +static PyObject *__pyx_n_s_calculate_subwatershed_boundary_4; +static PyObject *__pyx_n_s_cell_to_test; +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_collections; +static PyObject *__pyx_n_s_compatable_dem_raster_path_band; +static PyObject *__pyx_kp_u_compatable_dem_tif; +static PyObject *__pyx_kp_u_compatible_dem_complete; +static PyObject *__pyx_kp_u_complete; +static PyObject *__pyx_kp_u_complete_2; +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_connected_fid; +static PyObject *__pyx_n_s_connected_fids; +static PyObject *__pyx_n_s_connected_upstream_fids; +static PyObject *__pyx_n_s_coord_to_stream_ids; +static PyObject *__pyx_n_s_copy; +static PyObject *__pyx_n_s_copyfile; +static PyObject *__pyx_kp_u_could_not_open; +static PyObject *__pyx_kp_u_couldn_t_remove_temp_dir; +static PyObject *__pyx_kp_u_creating_target_flow_accum_raste; +static PyObject *__pyx_kp_u_creating_visited_raster_layer; +static PyObject *__pyx_n_s_current_pixel; +static PyObject *__pyx_n_s_d; +static PyObject *__pyx_n_u_d; +static PyObject *__pyx_n_u_d8; +static PyObject *__pyx_n_s_d8_flow_dir_managed_raster; +static PyObject *__pyx_n_s_d8_flow_dir_mode; +static PyObject *__pyx_n_s_d8_flow_dir_raster_path_band; +static PyObject *__pyx_n_s_d_n; +static PyObject *__pyx_n_u_datatype; +static PyObject *__pyx_n_s_debug; +static PyObject *__pyx_n_s_defaultdict; +static PyObject *__pyx_n_s_delete_feature; +static PyObject *__pyx_n_s_deleted_set; +static PyObject *__pyx_n_s_delta_x; +static PyObject *__pyx_n_s_delta_y; +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_u_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_detect_outlets; +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_dirname; +static PyObject *__pyx_n_s_discovery; +static PyObject *__pyx_n_s_discovery_count; +static PyObject *__pyx_n_s_discovery_info; +static PyObject *__pyx_n_s_discovery_managed_raster; +static PyObject *__pyx_n_s_discovery_nodata; +static PyObject *__pyx_n_s_discovery_srs; +static PyObject *__pyx_n_s_discovery_stack; +static PyObject *__pyx_kp_u_discovery_tif; +static PyObject *__pyx_kp_u_discovery_time_processing; +static PyObject *__pyx_n_s_discovery_time_raster_path; +static PyObject *__pyx_n_u_dist_to_channel_mfd_work_dir; +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_neighbor; +static PyObject *__pyx_n_s_downhill_slope_array; +static PyObject *__pyx_n_s_downstream_dem; +static PyObject *__pyx_n_s_downstream_feature; +static PyObject *__pyx_n_s_downstream_fid; +static PyObject *__pyx_n_s_downstream_geom; +static PyObject *__pyx_n_s_downstream_order; +static PyObject *__pyx_n_s_downstream_to_upstream_ids; +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_drop_distance; +static PyObject *__pyx_n_u_drop_distance; +static PyObject *__pyx_n_s_drop_distance_collection; +static PyObject *__pyx_n_u_ds_fa; +static PyObject *__pyx_n_s_ds_x; +static PyObject *__pyx_n_u_ds_x; +static PyObject *__pyx_n_s_ds_x_1; +static PyObject *__pyx_n_u_ds_x_1; +static PyObject *__pyx_n_s_ds_y; +static PyObject *__pyx_n_u_ds_y; +static PyObject *__pyx_n_s_ds_y_1; +static PyObject *__pyx_n_u_ds_y_1; +static PyObject *__pyx_n_s_dtype; +static PyObject *__pyx_n_s_edge_dir; +static PyObject *__pyx_n_s_edge_side; +static PyObject *__pyx_n_s_empty; +static PyObject *__pyx_n_s_enumerate; +static PyObject *__pyx_n_s_equal_var; +static PyObject *__pyx_n_s_error; +static PyObject *__pyx_n_s_exception; +static PyObject *__pyx_n_s_exists; +static PyObject *__pyx_kp_u_exists_removing_before_creating; +static PyObject *__pyx_kp_u_expected_flow_dir_type_of_either; +static PyObject *__pyx_n_s_extract_strahler_streams_d8; +static PyObject *__pyx_kp_u_extract_strahler_streams_d8_all; +static PyObject *__pyx_kp_u_extract_strahler_streams_d8_com; +static PyObject *__pyx_kp_u_extract_strahler_streams_d8_det; +static PyObject *__pyx_kp_u_extract_strahler_streams_d8_det_2; +static PyObject *__pyx_kp_u_extract_strahler_streams_d8_dra; +static PyObject *__pyx_kp_u_extract_strahler_streams_d8_dra_2; +static PyObject *__pyx_kp_u_extract_strahler_streams_d8_fin; +static PyObject *__pyx_kp_u_extract_strahler_streams_d8_fin_2; +static PyObject *__pyx_kp_u_extract_strahler_streams_d8_fin_3; +static PyObject *__pyx_kp_u_extract_strahler_streams_d8_flo; +static PyObject *__pyx_kp_u_extract_strahler_streams_d8_flo_2; +static PyObject *__pyx_kp_u_extract_strahler_streams_d8_see; +static PyObject *__pyx_kp_u_extract_strahler_streams_d8_sta; +static PyObject *__pyx_kp_u_extract_strahler_streams_d8_str; +static PyObject *__pyx_kp_u_extract_strahler_streams_d8_str_2; +static PyObject *__pyx_kp_u_extract_strahler_streams_d8_str_3; +static PyObject *__pyx_kp_u_extract_strahler_streams_d8_str_4; +static PyObject *__pyx_n_s_extract_streams_mfd; +static PyObject *__pyx_n_s_feature_id; +static PyObject *__pyx_n_s_fid; +static PyObject *__pyx_n_s_fid_to_order; +static PyObject *__pyx_n_s_fill_height; +static PyObject *__pyx_kp_u_fill_pits; +static PyObject *__pyx_n_s_fill_pits_2; +static PyObject *__pyx_kp_u_fill_pits__s; +static PyObject *__pyx_kp_u_fill_pits_complete; +static PyObject *__pyx_n_s_fill_queue; +static PyObject *__pyx_n_s_fill_value_list; +static PyObject *__pyx_n_s_filled_dem_band; +static PyObject *__pyx_n_s_filled_dem_managed_raster; +static PyObject *__pyx_n_s_filled_dem_raster; +static PyObject *__pyx_kp_u_filter_out_incomplete_divergent; +static PyObject *__pyx_n_s_finish; +static PyObject *__pyx_n_s_finish_coordinate; +static PyObject *__pyx_n_s_finish_managed_raster; +static PyObject *__pyx_n_s_finish_stack; +static PyObject *__pyx_kp_u_finish_tif; +static PyObject *__pyx_n_s_finish_time_raster_path; +static PyObject *__pyx_n_s_flat_region_mask_managed_raster; +static PyObject *__pyx_n_s_flat_region_mask_path; +static PyObject *__pyx_kp_u_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_block; +static PyObject *__pyx_n_s_flow_dir_buffer_array; +static PyObject *__pyx_kp_u_flow_dir_d8; +static PyObject *__pyx_n_s_flow_dir_d8_2; +static PyObject *__pyx_kp_u_flow_dir_d8__s; +static PyObject *__pyx_kp_u_flow_dir_d8_complete; +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_info; +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_u_flow_dir_multiple_flow_dir__s; +static PyObject *__pyx_n_s_flow_dir_n; +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_srs; +static PyObject *__pyx_n_s_flow_dir_type; +static PyObject *__pyx_n_s_flow_dir_weight; +static PyObject *__pyx_n_s_flow_nodata; +static PyObject *__pyx_n_s_flow_pixel; +static PyObject *__pyx_n_s_flow_threshold; +static PyObject *__pyx_kp_u_for_writing; +static PyObject *__pyx_n_s_g0; +static PyObject *__pyx_n_s_g1; +static PyObject *__pyx_n_s_g2; +static PyObject *__pyx_n_s_g3; +static PyObject *__pyx_n_s_g4; +static PyObject *__pyx_n_s_g5; +static PyObject *__pyx_n_s_gdal; +static PyObject *__pyx_n_s_generate_read_bounds; +static PyObject *__pyx_n_s_geoprocessing_core; +static PyObject *__pyx_n_s_geotransform; +static PyObject *__pyx_n_u_geotransform; +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_gpkg_driver; +static PyObject *__pyx_n_s_i; +static PyObject *__pyx_n_u_i; +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_kp_u_in_ManagedRaster_flush; +static PyObject *__pyx_n_s_index; +static PyObject *__pyx_n_s_info; +static PyObject *__pyx_n_s_int32; +static PyObject *__pyx_n_s_int8; +static PyObject *__pyx_n_s_int_max_steps_per_watershed; +static PyObject *__pyx_n_s_is_a_channel; +static PyObject *__pyx_n_s_is_drain; +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_isnan; +static PyObject *__pyx_n_s_iterblocks; +static PyObject *__pyx_n_s_j; +static PyObject *__pyx_n_u_j; +static PyObject *__pyx_n_s_join; +static PyObject *__pyx_n_s_joined_line; +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_left; +static PyObject *__pyx_n_s_left_in; +static PyObject *__pyx_n_s_linemerge; +static PyObject *__pyx_n_s_loads; +static PyObject *__pyx_n_s_local_flow_accum; +static PyObject *__pyx_n_s_log2; +static PyObject *__pyx_n_s_logging; +static PyObject *__pyx_n_s_lower; +static PyObject *__pyx_n_s_main; +static PyObject *__pyx_n_s_makedirs; +static PyObject *__pyx_n_s_mask_nodata; +static PyObject *__pyx_n_s_max; +static PyObject *__pyx_n_s_max_pixel_fill_count; +static PyObject *__pyx_n_s_max_steps_per_watershed; +static PyObject *__pyx_n_s_max_upstream_flow_accum; +static PyObject *__pyx_n_u_mfd; +static PyObject *__pyx_kp_u_mfd_flow_accum_1f_complete; +static PyObject *__pyx_n_u_mfd_flow_dir; +static PyObject *__pyx_n_s_min; +static PyObject *__pyx_n_s_min_flow_accum_threshold; +static PyObject *__pyx_n_s_min_p_val; +static PyObject *__pyx_n_s_mkdtemp; +static PyObject *__pyx_n_s_modified_offset_dict; +static PyObject *__pyx_kp_u_more_times; +static PyObject *__pyx_n_s_multi_line; +static PyObject *__pyx_n_u_n_bands; +static PyObject *__pyx_n_s_n_cols; +static PyObject *__pyx_n_s_n_dir; +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_pixels; +static PyObject *__pyx_n_s_n_points; +static PyObject *__pyx_n_s_n_processed; +static PyObject *__pyx_n_s_n_pushed; +static PyObject *__pyx_n_s_n_rows; +static PyObject *__pyx_n_s_n_slope; +static PyObject *__pyx_n_s_n_steps; +static PyObject *__pyx_n_s_n_x_blocks; +static PyObject *__pyx_n_s_name; +static PyObject *__pyx_n_s_natural_drain_exists; +static PyObject *__pyx_n_s_new_raster_from_base; +static PyObject *__pyx_n_s_next_id; +static PyObject *__pyx_kp_s_no_default___reduce___due_to_non; +static PyObject *__pyx_n_u_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_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_u_numpy_core_multiarray_failed_to; +static PyObject *__pyx_kp_u_numpy_core_umath_failed_to_impor; +static PyObject *__pyx_kp_u_of; +static PyObject *__pyx_n_s_offset_dict; +static PyObject *__pyx_n_s_offset_info; +static PyObject *__pyx_n_s_offset_only; +static PyObject *__pyx_n_s_ogr; +static PyObject *__pyx_n_s_open_set; +static PyObject *__pyx_kp_u_opening; +static PyObject *__pyx_n_s_ops; +static PyObject *__pyx_n_s_options; +static PyObject *__pyx_n_s_order; +static PyObject *__pyx_n_u_order; +static PyObject *__pyx_kp_u_order_1; +static PyObject *__pyx_n_s_order_count; +static PyObject *__pyx_n_s_os; +static PyObject *__pyx_n_s_osgeo; +static PyObject *__pyx_n_s_osr; +static PyObject *__pyx_n_s_osr_axis_mapping_strategy; +static PyObject *__pyx_n_s_out_dir; +static PyObject *__pyx_n_s_out_dir_increase; +static PyObject *__pyx_kp_u_out_of_bounds_for; +static PyObject *__pyx_n_s_outet_basename; +static PyObject *__pyx_n_s_outflow_dir; +static PyObject *__pyx_n_u_outlet; +static PyObject *__pyx_kp_u_outlet_1; +static PyObject *__pyx_n_s_outlet_at_confluence; +static PyObject *__pyx_kp_u_outlet_detection; +static PyObject *__pyx_kp_u_outlet_detection_0_complete; +static PyObject *__pyx_kp_u_outlet_detection_100_complete_co; +static PyObject *__pyx_kp_u_outlet_detection_done; +static PyObject *__pyx_n_s_outlet_feature; +static PyObject *__pyx_n_s_outlet_fid; +static PyObject *__pyx_n_s_outlet_fid_list; +static PyObject *__pyx_n_s_outlet_index; +static PyObject *__pyx_n_s_outlet_layer; +static PyObject *__pyx_n_s_outlet_point; +static PyObject *__pyx_n_s_outlet_vector; +static PyObject *__pyx_n_s_outlet_x; +static PyObject *__pyx_n_u_outlet_x; +static PyObject *__pyx_n_s_outlet_y; +static PyObject *__pyx_n_u_outlet_y; +static PyObject *__pyx_kp_u_outlets_complete; +static PyObject *__pyx_n_s_p_val; +static PyObject *__pyx_n_s_path; +static PyObject *__pyx_n_s_payload; +static PyObject *__pyx_n_s_pit_mask_managed_raster; +static PyObject *__pyx_n_s_pit_mask_path; +static PyObject *__pyx_kp_u_pit_mask_tif; +static PyObject *__pyx_n_s_pit_queue; +static PyObject *__pyx_n_s_pixel; +static PyObject *__pyx_n_s_pixel_count; +static PyObject *__pyx_n_s_pixel_val; +static PyObject *__pyx_kp_u_pixels_complete; +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_u_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_u_plateu_drain_mask_tif; +static PyObject *__pyx_n_s_pop; +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_processed_nodes; +static PyObject *__pyx_n_s_processed_segments; +static PyObject *__pyx_n_s_proj_x; +static PyObject *__pyx_n_s_proj_y; +static PyObject *__pyx_n_u_projection_wkt; +static PyObject *__pyx_n_s_pygeoprocessing; +static PyObject *__pyx_n_s_pygeoprocessing_routing_routing; +static PyObject *__pyx_n_s_pyx_vtable; +static PyObject *__pyx_kp_u_quitting_too_many_steps; +static PyObject *__pyx_n_s_range; +static PyObject *__pyx_kp_u_raster; +static PyObject *__pyx_n_s_raster_coord; +static PyObject *__pyx_n_s_raster_driver; +static PyObject *__pyx_n_s_raster_driver_creation_tuple; +static PyObject *__pyx_n_s_raster_info; +static PyObject *__pyx_n_s_raster_path; +static PyObject *__pyx_n_s_raster_path_band; +static PyObject *__pyx_n_u_raster_size; +static PyObject *__pyx_n_s_raster_srs; +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_remove; +static PyObject *__pyx_kp_u_resulted_in_null_trying; +static PyObject *__pyx_kp_u_retrying; +static PyObject *__pyx_n_s_reverse; +static PyObject *__pyx_n_s_right; +static PyObject *__pyx_n_s_right_in; +static PyObject *__pyx_n_u_river_id; +static PyObject *__pyx_n_s_river_order; +static PyObject *__pyx_n_s_rmtree; +static PyObject *__pyx_n_s_root_height; +static PyObject *__pyx_kp_u_s_is_not_a_file; +static PyObject *__pyx_kp_u_s_is_supposed_to_be_a_raster_ba; +static PyObject *__pyx_n_s_scipy; +static PyObject *__pyx_n_s_scipy_stats; +static PyObject *__pyx_n_s_search_queue; +static PyObject *__pyx_n_s_search_stack; +static PyObject *__pyx_n_s_search_steps; +static PyObject *__pyx_kp_u_segments_complete; +static PyObject *__pyx_n_s_segments_to_process; +static PyObject *__pyx_n_s_setstate; +static PyObject *__pyx_n_s_setstate_cython; +static PyObject *__pyx_n_s_shapely; +static PyObject *__pyx_n_s_shapely_ops; +static PyObject *__pyx_n_s_shapely_wkb; +static PyObject *__pyx_n_s_shutil; +static PyObject *__pyx_n_s_sleep; +static PyObject *__pyx_n_s_sorted; +static PyObject *__pyx_n_s_sorted_stream_order_list; +static PyObject *__pyx_n_s_source_id; +static PyObject *__pyx_n_s_source_point_stack; +static PyObject *__pyx_kp_u_source_points_complete; +static PyObject *__pyx_n_s_source_stream_point; +static PyObject *__pyx_n_s_splitext; +static PyObject *__pyx_kp_s_src_pygeoprocessing_routing_rout; +static PyObject *__pyx_kp_u_starting_search; +static PyObject *__pyx_n_s_stats; +static PyObject *__pyx_n_s_strahler_stream_vector_path; +static PyObject *__pyx_n_s_stream_array; +static PyObject *__pyx_n_s_stream_band; +static PyObject *__pyx_n_s_stream_basename; +static PyObject *__pyx_n_s_stream_feature; +static PyObject *__pyx_n_s_stream_fid; +static PyObject *__pyx_n_u_stream_fid; +static PyObject *__pyx_kp_u_stream_fragments_complete; +static PyObject *__pyx_n_s_stream_layer; +static PyObject *__pyx_n_s_stream_line; +static PyObject *__pyx_n_s_stream_mr; +static PyObject *__pyx_n_s_stream_nodata; +static PyObject *__pyx_n_s_stream_order; +static PyObject *__pyx_n_s_stream_order_list; +static PyObject *__pyx_n_s_stream_raster; +static PyObject *__pyx_n_s_stream_val; +static PyObject *__pyx_n_s_stream_vector; +static PyObject *__pyx_n_s_streams_by_order; +static PyObject *__pyx_n_s_streams_to_process; +static PyObject *__pyx_n_s_streams_to_retest; +static PyObject *__pyx_n_s_strftime; +static PyObject *__pyx_n_s_suffix; +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_discovery_raster_path; +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_finish_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_outlet_vector_path; +static PyObject *__pyx_n_s_target_stream_raster_path; +static PyObject *__pyx_n_s_target_stream_vector_path; +static PyObject *__pyx_n_s_target_watershed_boundary_vector; +static PyObject *__pyx_n_s_tempfile; +static PyObject *__pyx_n_s_terminated_early; +static PyObject *__pyx_n_u_terminated_early; +static PyObject *__pyx_n_s_test; +static PyObject *__pyx_n_s_test_dir; +static PyObject *__pyx_n_s_test_order; +static PyObject *__pyx_n_u_thresh_fa; +static PyObject *__pyx_n_s_time; +static PyObject *__pyx_n_s_tmp_dir; +static PyObject *__pyx_n_s_tmp_dir_root; +static PyObject *__pyx_n_s_tmp_flow_dir_nodata; +static PyObject *__pyx_n_s_tmp_work_dir; +static PyObject *__pyx_n_s_trace_flow_threshold; +static PyObject *__pyx_n_s_trace_threshold_proportion; +static PyObject *__pyx_kp_u_trace_threshold_proportion_shoul; +static PyObject *__pyx_n_s_ttest_ind; +static PyObject *__pyx_n_s_uint8; +static PyObject *__pyx_kp_u_unable_to_open; +static PyObject *__pyx_n_s_upstream_all_defined; +static PyObject *__pyx_n_s_upstream_coord; +static PyObject *__pyx_n_s_upstream_count; +static PyObject *__pyx_n_s_upstream_d8_dir; +static PyObject *__pyx_n_u_upstream_d8_dir; +static PyObject *__pyx_n_s_upstream_dem; +static PyObject *__pyx_n_s_upstream_dirs; +static PyObject *__pyx_n_s_upstream_feature; +static PyObject *__pyx_n_s_upstream_fid; +static PyObject *__pyx_n_s_upstream_fid_list; +static PyObject *__pyx_n_s_upstream_fid_map; +static PyObject *__pyx_n_s_upstream_fids; +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_upstream_id; +static PyObject *__pyx_n_s_upstream_id_list; +static PyObject *__pyx_n_s_upstream_index; +static PyObject *__pyx_n_s_upstream_order; +static PyObject *__pyx_n_s_upstream_stack; +static PyObject *__pyx_n_s_upstream_to_downstream_id; +static PyObject *__pyx_n_u_us_fa; +static PyObject *__pyx_n_s_us_x; +static PyObject *__pyx_n_u_us_x; +static PyObject *__pyx_n_s_us_y; +static PyObject *__pyx_n_u_us_y; +static PyObject *__pyx_n_s_value; +static PyObject *__pyx_n_s_visit_count; +static PyObject *__pyx_n_s_visit_order_stack; +static PyObject *__pyx_n_s_visited_managed_raster; +static PyObject *__pyx_n_s_visited_raster_path; +static PyObject *__pyx_kp_u_visited_tif; +static PyObject *__pyx_n_s_warning; +static PyObject *__pyx_n_s_watershed_basename; +static PyObject *__pyx_n_s_watershed_boundary; +static PyObject *__pyx_n_s_watershed_feature; +static PyObject *__pyx_n_s_watershed_layer; +static PyObject *__pyx_n_s_watershed_polygon; +static PyObject *__pyx_n_s_watershed_vector; +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_u_win_xsize; +static PyObject *__pyx_n_s_win_xsize_border; +static PyObject *__pyx_n_s_win_ysize; +static PyObject *__pyx_n_u_win_ysize; +static PyObject *__pyx_n_s_win_ysize_border; +static PyObject *__pyx_n_s_wkb; +static PyObject *__pyx_n_s_wkbLineString; +static PyObject *__pyx_n_s_wkbLinearRing; +static PyObject *__pyx_n_s_wkbPoint; +static PyObject *__pyx_n_s_wkbPolygon; +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_working_feature; +static PyObject *__pyx_n_s_working_fid; +static PyObject *__pyx_n_s_working_flow_accum_threshold; +static PyObject *__pyx_n_s_working_geom; +static PyObject *__pyx_n_s_working_order; +static PyObject *__pyx_n_s_working_river_id; +static PyObject *__pyx_n_s_working_stack; +static PyObject *__pyx_n_s_workspace_dir; +static PyObject *__pyx_n_s_write_mode; +static PyObject *__pyx_n_s_x; +static PyObject *__pyx_n_u_x; +static PyObject *__pyx_n_s_x_f; +static PyObject *__pyx_n_s_x_l; +static PyObject *__pyx_n_s_x_n; +static PyObject *__pyx_n_s_x_off_border; +static PyObject *__pyx_kp_u_x_out_of_bounds_s; +static PyObject *__pyx_n_s_x_p; +static PyObject *__pyx_n_s_x_u; +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_n_u_xoff; +static PyObject *__pyx_n_s_y_f; +static PyObject *__pyx_n_s_y_l; +static PyObject *__pyx_n_s_y_n; +static PyObject *__pyx_n_s_y_off_border; +static PyObject *__pyx_kp_u_y_out_of_bounds_s; +static PyObject *__pyx_n_s_y_p; +static PyObject *__pyx_n_s_y_u; +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 PyObject *__pyx_n_u_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, long __pyx_v_max_pixel_fill_count, PyObject *__pyx_v_raster_driver_creation_tuple); /* 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_raster_driver_creation_tuple); /* 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_raster_driver_creation_tuple); /* 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_raster_driver_creation_tuple); /* 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_raster_driver_creation_tuple); /* 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_raster_driver_creation_tuple); /* 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_raster_driver_creation_tuple); /* 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_raster_driver_creation_tuple); /* 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 PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_20extract_strahler_streams_d8(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_flow_dir_d8_raster_path_band, PyObject *__pyx_v_flow_accum_raster_path_band, PyObject *__pyx_v_dem_raster_path_band, PyObject *__pyx_v_target_stream_vector_path, long __pyx_v_min_flow_accum_threshold, int __pyx_v_river_order, float __pyx_v_min_p_val, PyObject *__pyx_v_autotune_flow_accumulation, PyObject *__pyx_v_osr_axis_mapping_strategy); /* proto */ +static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_22_build_discovery_finish_rasters(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_flow_dir_d8_raster_path_band, PyObject *__pyx_v_target_discovery_raster_path, PyObject *__pyx_v_target_finish_raster_path); /* proto */ +static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_24calculate_subwatershed_boundary(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_d8_flow_dir_raster_path_band, PyObject *__pyx_v_strahler_stream_vector_path, PyObject *__pyx_v_target_watershed_boundary_vector_path, PyObject *__pyx_v_max_steps_per_watershed, PyObject *__pyx_v_outlet_at_confluence); /* proto */ +static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_26detect_outlets(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_flow_dir_raster_path_band, PyObject *__pyx_v_flow_dir_type, PyObject *__pyx_v_target_outlet_vector_path); /* proto */ +static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_28_delete_feature(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_stream_feature, PyObject *__pyx_v_stream_layer, PyObject *__pyx_v_upstream_to_downstream_id, PyObject *__pyx_v_downstream_to_upstream_ids); /* proto */ +static PyObject *__pyx_tp_new_15pygeoprocessing_7routing_7routing__ManagedRaster(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static __Pyx_CachedCFunction __pyx_umethod_PyList_Type_pop = {0, &__pyx_n_s_pop, 0, 0, 0}; +static PyObject *__pyx_float_0_2; +static PyObject *__pyx_float_0_5; +static PyObject *__pyx_float_1_25; +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_5; +static PyObject *__pyx_int_100; +static PyObject *__pyx_int_1000000; +static PyObject *__pyx_int_neg_1; +static PyObject *__pyx_k__4; +static long __pyx_k__5; +static PyObject *__pyx_k__6; +static PyObject *__pyx_k__8; +static PyObject *__pyx_k__10; +static PyObject *__pyx_k__11; +static PyObject *__pyx_k__12; +static PyObject *__pyx_k__13; +static PyObject *__pyx_k__14; +static PyObject *__pyx_k__15; +static PyObject *__pyx_slice__7; +static PyObject *__pyx_tuple__2; +static PyObject *__pyx_tuple__3; +static PyObject *__pyx_tuple__9; +static PyObject *__pyx_tuple__16; +static PyObject *__pyx_tuple__17; +static PyObject *__pyx_tuple__18; +static PyObject *__pyx_tuple__19; +static PyObject *__pyx_tuple__20; +static PyObject *__pyx_tuple__21; +static PyObject *__pyx_tuple__22; +static PyObject *__pyx_tuple__23; +static PyObject *__pyx_tuple__24; +static PyObject *__pyx_tuple__25; +static PyObject *__pyx_tuple__26; +static PyObject *__pyx_tuple__28; +static PyObject *__pyx_tuple__30; +static PyObject *__pyx_tuple__32; +static PyObject *__pyx_tuple__35; +static PyObject *__pyx_tuple__37; +static PyObject *__pyx_tuple__39; +static PyObject *__pyx_tuple__41; +static PyObject *__pyx_tuple__43; +static PyObject *__pyx_tuple__45; +static PyObject *__pyx_tuple__47; +static PyObject *__pyx_tuple__49; +static PyObject *__pyx_tuple__51; +static PyObject *__pyx_tuple__53; +static PyObject *__pyx_tuple__55; +static PyObject *__pyx_codeobj__27; +static PyObject *__pyx_codeobj__29; +static PyObject *__pyx_codeobj__31; +static PyObject *__pyx_codeobj__33; +static PyObject *__pyx_codeobj__36; +static PyObject *__pyx_codeobj__38; +static PyObject *__pyx_codeobj__40; +static PyObject *__pyx_codeobj__42; +static PyObject *__pyx_codeobj__44; +static PyObject *__pyx_codeobj__46; +static PyObject *__pyx_codeobj__48; +static PyObject *__pyx_codeobj__50; +static PyObject *__pyx_codeobj__52; +static PyObject *__pyx_codeobj__54; +static PyObject *__pyx_codeobj__56; +/* Late includes */ + +/* "pygeoprocessing/routing/routing.pyx":169 + * # 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":172 + * # 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":173 + * # 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":172 + * # 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":174 + * 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":175 + * 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":176 + * if lhs.value == rhs.value: + * if lhs.priority > rhs.priority: + * return 1 # <<<<<<<<<<<<<< + * return 0 + * + */ + __pyx_r = 1; + goto __pyx_L0; + + /* "pygeoprocessing/routing/routing.pyx":175 + * return 1 + * if lhs.value == rhs.value: + * if lhs.priority > rhs.priority: # <<<<<<<<<<<<<< + * return 1 + * return 0 + */ + } + + /* "pygeoprocessing/routing/routing.pyx":174 + * if lhs.value > rhs.value: + * return 1 + * if lhs.value == rhs.value: # <<<<<<<<<<<<<< + * if lhs.priority > rhs.priority: + * return 1 + */ + } + + /* "pygeoprocessing/routing/routing.pyx":177 + * if lhs.priority > rhs.priority: + * return 1 + * return 0 # <<<<<<<<<<<<<< + * + * cdef int _is_close(double x, double y, double abs_delta, double rel_delta): + */ + __pyx_r = 0; + goto __pyx_L0; + + /* "pygeoprocessing/routing/routing.pyx":169 + * # 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":179 + * return 0 + * + * cdef int _is_close(double x, double y, double abs_delta, double rel_delta): # <<<<<<<<<<<<<< + * return abs(x-y) <= (abs_delta+rel_delta*abs(y)) + * + */ + +static int __pyx_f_15pygeoprocessing_7routing_7routing__is_close(double __pyx_v_x, double __pyx_v_y, double __pyx_v_abs_delta, double __pyx_v_rel_delta) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_is_close", 0); + + /* "pygeoprocessing/routing/routing.pyx":180 + * + * cdef int _is_close(double x, double y, double abs_delta, double rel_delta): + * return abs(x-y) <= (abs_delta+rel_delta*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)) <= (__pyx_v_abs_delta + (__pyx_v_rel_delta * fabs(__pyx_v_y)))); + goto __pyx_L0; + + /* "pygeoprocessing/routing/routing.pyx":179 + * return 0 + * + * cdef int _is_close(double x, double y, double abs_delta, double rel_delta): # <<<<<<<<<<<<<< + * return abs(x-y) <= (abs_delta+rel_delta*abs(y)) + * + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pygeoprocessing/routing/routing.pyx":202 + * 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_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 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, 202, __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, 202, __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, 202, __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, 202, __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; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *(*__pyx_t_8)(PyObject *); + int __pyx_t_9; + Py_ssize_t __pyx_t_10; + Py_UCS4 __pyx_t_11; + long __pyx_t_12; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "pygeoprocessing/routing/routing.pyx":217 + * None. + * """ + * if not os.path.isfile(raster_path): # <<<<<<<<<<<<<< + * LOGGER.error("%s is not a file.", raster_path) + * return + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 217, __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, 217, __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, 217, __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); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_raster_path); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 217, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __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, 217, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_5 = ((!__pyx_t_4) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":218 + * """ + * 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 218, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_error); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 218, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + __pyx_t_6 = 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_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_kp_u_s_is_not_a_file, __pyx_v_raster_path}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 218, __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_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_kp_u_s_is_not_a_file, __pyx_v_raster_path}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 218, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 218, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_2) { + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2); __pyx_t_2 = NULL; + } + __Pyx_INCREF(__pyx_kp_u_s_is_not_a_file); + __Pyx_GIVEREF(__pyx_kp_u_s_is_not_a_file); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_kp_u_s_is_not_a_file); + __Pyx_INCREF(__pyx_v_raster_path); + __Pyx_GIVEREF(__pyx_v_raster_path); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_raster_path); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 218, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":219 + * 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":217 + * None. + * """ + * if not os.path.isfile(raster_path): # <<<<<<<<<<<<<< + * LOGGER.error("%s is not a file.", raster_path) + * return + */ + } + + /* "pygeoprocessing/routing/routing.pyx":220 + * 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 220, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 220, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __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); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_3, __pyx_v_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_raster_path); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 220, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_raster_info = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":221 + * 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_u_raster_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 221, __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, 221, __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, 221, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 221, __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_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 221, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_2)->tp_iternext; + index = 0; __pyx_t_7 = __pyx_t_8(__pyx_t_2); if (unlikely(!__pyx_t_7)) goto __pyx_L4_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + index = 1; __pyx_t_3 = __pyx_t_8(__pyx_t_2); if (unlikely(!__pyx_t_3)) goto __pyx_L4_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_2), 2) < 0) __PYX_ERR(0, 221, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L5_unpacking_done; + __pyx_L4_unpacking_failed:; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 221, __pyx_L1_error) + __pyx_L5_unpacking_done:; + } + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 221, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 221, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_self->raster_x_size = __pyx_t_6; + __pyx_v_self->raster_y_size = __pyx_t_9; + + /* "pygeoprocessing/routing/routing.pyx":222 + * 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_u_block_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 222, __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, 222, __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_7 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_3 = PyList_GET_ITEM(sequence, 0); + __pyx_t_7 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_7); + #else + __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 222, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 222, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 222, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_2)->tp_iternext; + index = 0; __pyx_t_3 = __pyx_t_8(__pyx_t_2); if (unlikely(!__pyx_t_3)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + index = 1; __pyx_t_7 = __pyx_t_8(__pyx_t_2); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_2), 2) < 0) __PYX_ERR(0, 222, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L7_unpacking_done; + __pyx_L6_unpacking_failed:; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 222, __pyx_L1_error) + __pyx_L7_unpacking_done:; + } + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 222, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 222, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_self->block_xsize = __pyx_t_9; + __pyx_v_self->block_ysize = __pyx_t_6; + + /* "pygeoprocessing/routing/routing.pyx":223 + * 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":224 + * 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":226 + * 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, 226, __pyx_L1_error) + if (__Pyx_PyObject_IsTrue(__pyx_t_1)) { + __Pyx_DECREF(__pyx_t_1); + __pyx_t_7 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_n_bands); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 226, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = PyObject_RichCompare(__pyx_v_band_id, __pyx_t_7, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 226, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 226, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = ((!__pyx_t_5) != 0); + if (unlikely(__pyx_t_4)) { + + /* "pygeoprocessing/routing/routing.pyx":231 + * "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_PyUnicode_FormatSafe(__pyx_kp_u_Error_band_ID_s_is_not_a_valid_b, __pyx_v_band_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 231, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_err_msg = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":232 + * "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 + */ + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_print, __pyx_v_err_msg); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 232, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":233 + * "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, 233, __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, 233, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":226 + * 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":234 + * print(err_msg) + * raise ValueError(err_msg) + * self.band_id = band_id # <<<<<<<<<<<<<< + * + * if (self.block_xsize & (self.block_xsize - 1) != 0) or ( + */ + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_v_band_id); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 234, __pyx_L1_error) + __pyx_v_self->band_id = __pyx_t_6; + + /* "pygeoprocessing/routing/routing.pyx":236 + * 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_5 = (((__pyx_v_self->block_xsize & (__pyx_v_self->block_xsize - 1)) != 0) != 0); + if (!__pyx_t_5) { + } else { + __pyx_t_4 = __pyx_t_5; + goto __pyx_L10_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":237 + * + * 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_5 = (((__pyx_v_self->block_ysize & (__pyx_v_self->block_ysize - 1)) != 0) != 0); + __pyx_t_4 = __pyx_t_5; + __pyx_L10_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":236 + * 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 (unlikely(__pyx_t_4)) { + + /* "pygeoprocessing/routing/routing.pyx":243 + * # ValueError in here at least for readability. + * err_msg = ( + * "Error: Block size is not a power of two: " # <<<<<<<<<<<<<< + * "block_xsize: %d, %d, %s. This exception is happening" + * "in Cython, so it will cause a hard seg-fault, but it's" + */ + __pyx_t_1 = PyTuple_New(7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 243, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = 0; + __pyx_t_11 = 127; + __Pyx_INCREF(__pyx_kp_u_Error_Block_size_is_not_a_power); + __pyx_t_10 += 54; + __Pyx_GIVEREF(__pyx_kp_u_Error_Block_size_is_not_a_power); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_Error_Block_size_is_not_a_power); + + /* "pygeoprocessing/routing/routing.pyx":247 + * "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_7 = __Pyx_PyUnicode_From_int(__pyx_v_self->block_xsize, 0, ' ', 'd'); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 247, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_10 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_INCREF(__pyx_kp_u_); + __pyx_t_10 += 2; + __Pyx_GIVEREF(__pyx_kp_u_); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_); + __pyx_t_7 = __Pyx_PyUnicode_From_int(__pyx_v_self->block_ysize, 0, ' ', 'd'); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 247, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_10 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_INCREF(__pyx_kp_u_); + __pyx_t_10 += 2; + __Pyx_GIVEREF(__pyx_kp_u_); + PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u_); + __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_raster_path), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 247, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_11 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_11) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_11; + __pyx_t_10 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_INCREF(__pyx_kp_u_This_exception_is_happeningin_C); + __pyx_t_10 += 118; + __Pyx_GIVEREF(__pyx_kp_u_This_exception_is_happeningin_C); + PyTuple_SET_ITEM(__pyx_t_1, 6, __pyx_kp_u_This_exception_is_happeningin_C); + + /* "pygeoprocessing/routing/routing.pyx":243 + * # ValueError in here at least for readability. + * err_msg = ( + * "Error: Block size is not a power of two: " # <<<<<<<<<<<<<< + * "block_xsize: %d, %d, %s. This exception is happening" + * "in Cython, so it will cause a hard seg-fault, but it's" + */ + __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_1, 7, __pyx_t_10, __pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 243, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_err_msg = ((PyObject*)__pyx_t_7); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":248 + * "otherwise meant to be a ValueError." % ( + * self.block_xsize, self.block_ysize, raster_path)) + * print(err_msg) # <<<<<<<<<<<<<< + * raise ValueError(err_msg) + * + */ + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_print, __pyx_v_err_msg); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 248, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":249 + * 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_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_v_err_msg); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 249, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_Raise(__pyx_t_7, 0, 0, 0); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __PYX_ERR(0, 249, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":236 + * 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":251 + * raise ValueError(err_msg) + * + * self.block_xbits = numpy.log2(self.block_xsize) # <<<<<<<<<<<<<< + * self.block_ybits = numpy.log2(self.block_ysize) + * self.block_nx = ( + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 251, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_log2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 251, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->block_xsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 251, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = NULL; + 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_7 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 251, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 251, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_self->block_xbits = __pyx_t_6; + + /* "pygeoprocessing/routing/routing.pyx":252 + * + * 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 252, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_log2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 252, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->block_ysize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 252, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __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); + } + } + __pyx_t_7 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 252, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 252, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_self->block_ybits = __pyx_t_6; + + /* "pygeoprocessing/routing/routing.pyx":254 + * 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_12 = ((__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, 254, __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_12))) { + PyErr_SetString(PyExc_OverflowError, "value too large to perform division"); + __PYX_ERR(0, 254, __pyx_L1_error) + } + + /* "pygeoprocessing/routing/routing.pyx":253 + * 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_12, __pyx_v_self->block_xsize); + + /* "pygeoprocessing/routing/routing.pyx":256 + * 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_12 = ((__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, 256, __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_12))) { + PyErr_SetString(PyExc_OverflowError, "value too large to perform division"); + __PYX_ERR(0, 256, __pyx_L1_error) + } + + /* "pygeoprocessing/routing/routing.pyx":255 + * 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_12, __pyx_v_self->block_ysize); + + /* "pygeoprocessing/routing/routing.pyx":258 + * 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 = raster_path + * self.write_mode = write_mode + */ + __pyx_v_self->lru_cache = new LRUCache (__pyx_v_15pygeoprocessing_7routing_7routing_MANAGED_RASTER_N_BLOCKS); + + /* "pygeoprocessing/routing/routing.pyx":259 + * + * self.lru_cache = new LRUCache[int, double*](MANAGED_RASTER_N_BLOCKS) + * self.raster_path = raster_path # <<<<<<<<<<<<<< + * self.write_mode = write_mode + * self.closed = 0 + */ + __pyx_t_7 = __pyx_v_raster_path; + __Pyx_INCREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + __Pyx_GOTREF(__pyx_v_self->raster_path); + __Pyx_DECREF(__pyx_v_self->raster_path); + __pyx_v_self->raster_path = ((PyObject*)__pyx_t_7); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":260 + * self.lru_cache = new LRUCache[int, double*](MANAGED_RASTER_N_BLOCKS) + * self.raster_path = raster_path + * self.write_mode = write_mode # <<<<<<<<<<<<<< + * self.closed = 0 + * + */ + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_v_write_mode); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 260, __pyx_L1_error) + __pyx_v_self->write_mode = __pyx_t_6; + + /* "pygeoprocessing/routing/routing.pyx":261 + * self.raster_path = raster_path + * self.write_mode = write_mode + * self.closed = 0 # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->closed = 0; + + /* "pygeoprocessing/routing/routing.pyx":202 + * 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_7); + __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":263 + * 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "pygeoprocessing/routing/routing.pyx":269 + * 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, 269, __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); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 269, __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":263 + * 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":271 + * 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 ::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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __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":280 + * 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":281 + * """ + * 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":280 + * have undefined behavior. + * """ + * if self.closed: # <<<<<<<<<<<<<< + * return + * self.closed = 1 + */ + } + + /* "pygeoprocessing/routing/routing.pyx":282 + * 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":284 + * 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 284, __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, 284, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":285 + * 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, 285, __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, 285, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 285, __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); + } + } + __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_6); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 284, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":284 + * 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, 284, __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, 284, __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":298 + * 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":299 + * + * 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":300 + * 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":301 + * 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":303 + * 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":304 + * # write the changed value back if desired + * PyMem_Free(deref(it).second) + * inc(it) # <<<<<<<<<<<<<< + * return + * + */ + (void)((++__pyx_v_it)); + } + + /* "pygeoprocessing/routing/routing.pyx":305 + * 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":300 + * 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":307 + * return + * + * raster = gdal.OpenEx( # <<<<<<<<<<<<<< + * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) + * raster_band = raster.GetRasterBand(self.band_id) + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 307, __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, 307, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":308 + * + * raster = gdal.OpenEx( + * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) # <<<<<<<<<<<<<< + * raster_band = raster.GetRasterBand(self.band_id) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 308, __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, 308, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 308, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 308, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyNumber_Or(__pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 308, __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_t_3 = NULL; + __pyx_t_8 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(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); + __pyx_t_8 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_self->raster_path, __pyx_t_4}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 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_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_self->raster_path, __pyx_t_4}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_5 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_INCREF(__pyx_v_self->raster_path); + __Pyx_GIVEREF(__pyx_v_self->raster_path); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_8, __pyx_v_self->raster_path); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_8, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_raster = __pyx_t_2; + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":309 + * 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_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 309, __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, 309, __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); + } + } + __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 309, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_raster_band = __pyx_t_2; + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":313 + * # 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":314 + * 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":315 + * 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, 315, __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":318 + * + * # 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, 318, __pyx_L1_error) + __pyx_v_dirty_itr = __pyx_v_self->dirty_blocks.find(__pyx_t_8); + + /* "pygeoprocessing/routing/routing.pyx":319 + * # 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":320 + * 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 + */ + (void)(__pyx_v_self->dirty_blocks.erase(__pyx_v_dirty_itr)); + + /* "pygeoprocessing/routing/routing.pyx":321 + * 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, 321, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = PyNumber_Remainder(__pyx_v_block_index, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 321, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 321, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_block_xi = __pyx_t_8; + + /* "pygeoprocessing/routing/routing.pyx":322 + * 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_6 = __Pyx_PyInt_From_int(__pyx_v_self->block_nx); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 322, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_v_block_index, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 322, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 322, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_block_yi = __pyx_t_8; + + /* "pygeoprocessing/routing/routing.pyx":326 + * # 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":327 + * # 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":329 + * 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":330 + * + * 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":333 + * + * # 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":334 + * # 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":333 + * + * # 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":336 + * 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":337 + * 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":336 + * 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":340 + * 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":341 + * + * 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":342 + * 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, 342, __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":345 + * 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, 345, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + + /* "pygeoprocessing/routing/routing.pyx":346 + * (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_6 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 346, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = PySlice_New(__pyx_int_0, __pyx_t_6, Py_None); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 346, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 346, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = PySlice_New(__pyx_int_0, __pyx_t_6, Py_None); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 346, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 346, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_4); + __pyx_t_5 = 0; + __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_block_array), __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 346, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":345 + * 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_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 345, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":347 + * raster_band.WriteArray( + * block_array[0:win_ysize, 0:win_xsize], + * xoff=xoff, yoff=yoff) # <<<<<<<<<<<<<< + * PyMem_Free(double_buffer) + * inc(it) + */ + __pyx_t_4 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 347, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_xoff); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 347, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_xoff, __pyx_t_5) < 0) __PYX_ERR(0, 347, __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, 347, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_yoff, __pyx_t_5) < 0) __PYX_ERR(0, 347, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pygeoprocessing/routing/routing.pyx":345 + * 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_6, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 345, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __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":319 + * # 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":348 + * 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":349 + * xoff=xoff, yoff=yoff) + * PyMem_Free(double_buffer) + * inc(it) # <<<<<<<<<<<<<< + * raster_band.FlushCache() + * raster_band = None + */ + (void)((++__pyx_v_it)); + } + + /* "pygeoprocessing/routing/routing.pyx":350 + * PyMem_Free(double_buffer) + * inc(it) + * raster_band.FlushCache() # <<<<<<<<<<<<<< + * raster_band = None + * raster = None + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster_band, __pyx_n_s_FlushCache); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 350, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_5 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 350, __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":351 + * 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":352 + * 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":271 + * 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":354 + * 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 ::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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("set", 0); + + /* "pygeoprocessing/routing/routing.pyx":356 + * 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":357 + * """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_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 357, __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, 357, __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, 357, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = PyUnicode_Format(__pyx_kp_u_x_out_of_bounds_s, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 357, __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); + } + } + __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 357, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":356 + * 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":358 + * 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":359 + * 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_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 359, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_error); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 359, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __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, 359, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PyUnicode_Format(__pyx_kp_u_y_out_of_bounds_s, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 359, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 359, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":358 + * 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":360 + * 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":361 + * 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":363 + * 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":364 + * # 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":365 + * 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, 365, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":364 + * # 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":368 + * 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":370 + * ((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":371 + * (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":372 + * 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":373 + * 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, 373, __pyx_L1_error) + } + + /* "pygeoprocessing/routing/routing.pyx":372 + * 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":370 + * ((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":354 + * 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_WriteUnraisable("pygeoprocessing.routing.routing._ManagedRaster.set", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_L0:; + __Pyx_RefNannyFinishContext(); +} + +/* "pygeoprocessing/routing/routing.pyx":375 + * 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("get", 0); + + /* "pygeoprocessing/routing/routing.pyx":377 + * 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":378 + * """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_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 378, __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, 378, __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, 378, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = PyUnicode_Format(__pyx_kp_u_x_out_of_bounds_s, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 378, __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); + } + } + __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 378, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":377 + * 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":379 + * 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":380 + * 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_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 380, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_error); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 380, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __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, 380, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PyUnicode_Format(__pyx_kp_u_y_out_of_bounds_s, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 380, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 380, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":379 + * 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":381 + * 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":382 + * 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":384 + * 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":385 + * # 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":386 + * 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, 386, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":385 + * # 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":388 + * 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":375 + * 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_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":392 + * (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; + PyObject *__pyx_v_n_attempts = NULL; + std::set ::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; + int __pyx_t_20; + Py_ssize_t __pyx_t_21; + Py_UCS4 __pyx_t_22; + double *__pyx_t_23; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __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":393 + * + * 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, 393, __pyx_L1_error) + } + __pyx_v_block_xi = __Pyx_mod_int(__pyx_v_block_index, __pyx_v_self->block_nx); + + /* "pygeoprocessing/routing/routing.pyx":394 + * 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, 394, __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, 394, __pyx_L1_error) + } + __pyx_v_block_yi = __Pyx_div_int(__pyx_v_block_index, __pyx_v_self->block_nx); + + /* "pygeoprocessing/routing/routing.pyx":397 + * + * # 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":398 + * # 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":409 + * # 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":410 + * # 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":413 + * + * # 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":414 + * # 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":413 + * + * # 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":415 + * 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":416 + * 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":415 + * 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":418 + * 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_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 418, __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, 418, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 418, __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, 418, __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, 418, __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, 418, __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, 418, __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, 418, __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":419 + * + * 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, 419, __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, 419, __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); + } + } + __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_7); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 419, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_raster_band = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":420 + * 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, 420, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + + /* "pygeoprocessing/routing/routing.pyx":421 + * 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_7 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 421, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_xoff); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 421, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_xoff, __pyx_t_6) < 0) __PYX_ERR(0, 421, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_yoff); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 421, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_yoff, __pyx_t_6) < 0) __PYX_ERR(0, 421, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 421, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_win_xsize, __pyx_t_6) < 0) __PYX_ERR(0, 421, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":422 + * 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_6 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 422, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_win_ysize, __pyx_t_6) < 0) __PYX_ERR(0, 421, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":420 + * 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_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_empty_tuple, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 420, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":422 + * 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_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_astype); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 422, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_numpy); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 422, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_float64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 422, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 422, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 422, __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, 420, __pyx_L1_error) + } + __pyx_t_8 = 0; + __pyx_v_block_array = ((PyArrayObject *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":423 + * xoff=xoff, yoff=yoff, win_xsize=win_xsize, + * win_ysize=win_ysize).astype(numpy.float64) + * raster_band = None # <<<<<<<<<<<<<< + * raster = None + * double_buffer = PyMem_Malloc( + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_raster_band, Py_None); + + /* "pygeoprocessing/routing/routing.pyx":424 + * win_ysize=win_ysize).astype(numpy.float64) + * raster_band = None + * raster = None # <<<<<<<<<<<<<< + * double_buffer = 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":425 + * raster_band = None + * raster = None + * double_buffer = 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":427 + * double_buffer = 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":428 + * (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":430 + * 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( + * block_index, 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, 430, __pyx_L1_error) + } + + /* "pygeoprocessing/routing/routing.pyx":429 + * 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":431 + * double_buffer[(yi_copy << self.block_xbits)+xi_copy] = ( + * block_array[yi_copy, xi_copy]) + * self.lru_cache.put( # <<<<<<<<<<<<<< + * block_index, 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":434 + * block_index, double_buffer, removed_value_list) + * + * if self.write_mode: # <<<<<<<<<<<<<< + * n_attempts = 5 + * while True: + */ + __pyx_t_2 = (__pyx_v_self->write_mode != 0); + if (__pyx_t_2) { + + /* "pygeoprocessing/routing/routing.pyx":435 + * + * if self.write_mode: + * n_attempts = 5 # <<<<<<<<<<<<<< + * while True: + * raster = gdal.OpenEx( + */ + __Pyx_INCREF(__pyx_int_5); + __pyx_v_n_attempts = __pyx_int_5; + + /* "pygeoprocessing/routing/routing.pyx":436 + * if self.write_mode: + * n_attempts = 5 + * while True: # <<<<<<<<<<<<<< + * raster = gdal.OpenEx( + * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) + */ + while (1) { + + /* "pygeoprocessing/routing/routing.pyx":437 + * n_attempts = 5 + * while True: + * raster = gdal.OpenEx( # <<<<<<<<<<<<<< + * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) + * if raster is None: + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 437, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 437, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":438 + * while True: + * raster = gdal.OpenEx( + * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) # <<<<<<<<<<<<<< + * if raster is None: + * if n_attempts == 0: + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 438, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_GA_Update); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 438, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 438, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 438, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = PyNumber_Or(__pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 438, __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_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_7}; + __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, 437, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 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[3] = {__pyx_t_4, __pyx_v_self->raster_path, __pyx_t_7}; + __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, 437, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_6 = PyTuple_New(2+__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 437, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (__pyx_t_4) { + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 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_6, 0+__pyx_t_1, __pyx_v_self->raster_path); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_1, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 437, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF_SET(__pyx_v_raster, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":439 + * raster = gdal.OpenEx( + * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) + * if raster is None: # <<<<<<<<<<<<<< + * if n_attempts == 0: + * raise RuntimeError( + */ + __pyx_t_2 = (__pyx_v_raster == Py_None); + __pyx_t_20 = (__pyx_t_2 != 0); + if (__pyx_t_20) { + + /* "pygeoprocessing/routing/routing.pyx":440 + * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) + * if raster is None: + * if n_attempts == 0: # <<<<<<<<<<<<<< + * raise RuntimeError( + * f'could not open {self.raster_path} for writing') + */ + __pyx_t_3 = __Pyx_PyInt_EqObjC(__pyx_v_n_attempts, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 440, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_20 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_20 < 0)) __PYX_ERR(0, 440, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(__pyx_t_20)) { + + /* "pygeoprocessing/routing/routing.pyx":442 + * if n_attempts == 0: + * raise RuntimeError( + * f'could not open {self.raster_path} for writing') # <<<<<<<<<<<<<< + * LOGGER.warning( + * f'opening {self.raster_path} resulted in null, ' + */ + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 442, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_21 = 0; + __pyx_t_22 = 127; + __Pyx_INCREF(__pyx_kp_u_could_not_open); + __pyx_t_21 += 15; + __Pyx_GIVEREF(__pyx_kp_u_could_not_open); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_u_could_not_open); + __pyx_t_5 = __Pyx_PyObject_FormatSimple(__pyx_v_self->raster_path, __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 442, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_22 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_22) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_22; + __pyx_t_21 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_5); + __pyx_t_5 = 0; + __Pyx_INCREF(__pyx_kp_u_for_writing); + __pyx_t_21 += 12; + __Pyx_GIVEREF(__pyx_kp_u_for_writing); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_kp_u_for_writing); + __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_3, 3, __pyx_t_21, __pyx_t_22); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 442, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":441 + * if raster is None: + * if n_attempts == 0: + * raise RuntimeError( # <<<<<<<<<<<<<< + * f'could not open {self.raster_path} for writing') + * LOGGER.warning( + */ + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_RuntimeError, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 441, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 441, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":440 + * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) + * if raster is None: + * if n_attempts == 0: # <<<<<<<<<<<<<< + * raise RuntimeError( + * f'could not open {self.raster_path} for writing') + */ + } + + /* "pygeoprocessing/routing/routing.pyx":443 + * raise RuntimeError( + * f'could not open {self.raster_path} for writing') + * LOGGER.warning( # <<<<<<<<<<<<<< + * f'opening {self.raster_path} resulted in null, ' + * f'trying {n_attempts} more times.') + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 443, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_warning); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 443, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pygeoprocessing/routing/routing.pyx":444 + * f'could not open {self.raster_path} for writing') + * LOGGER.warning( + * f'opening {self.raster_path} resulted in null, ' # <<<<<<<<<<<<<< + * f'trying {n_attempts} more times.') + * n_attempts -= 1 + */ + __pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 444, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_21 = 0; + __pyx_t_22 = 127; + __Pyx_INCREF(__pyx_kp_u_opening); + __pyx_t_21 += 8; + __Pyx_GIVEREF(__pyx_kp_u_opening); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_kp_u_opening); + __pyx_t_7 = __Pyx_PyObject_FormatSimple(__pyx_v_self->raster_path, __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 444, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_22 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_22) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_22; + __pyx_t_21 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_INCREF(__pyx_kp_u_resulted_in_null_trying); + __pyx_t_21 += 26; + __Pyx_GIVEREF(__pyx_kp_u_resulted_in_null_trying); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_kp_u_resulted_in_null_trying); + + /* "pygeoprocessing/routing/routing.pyx":445 + * LOGGER.warning( + * f'opening {self.raster_path} resulted in null, ' + * f'trying {n_attempts} more times.') # <<<<<<<<<<<<<< + * n_attempts -= 1 + * time.sleep(0.5) + */ + __pyx_t_7 = __Pyx_PyObject_FormatSimple(__pyx_v_n_attempts, __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 445, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_22 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_22) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_22; + __pyx_t_21 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_INCREF(__pyx_kp_u_more_times); + __pyx_t_21 += 12; + __Pyx_GIVEREF(__pyx_kp_u_more_times); + PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_kp_u_more_times); + + /* "pygeoprocessing/routing/routing.pyx":444 + * f'could not open {self.raster_path} for writing') + * LOGGER.warning( + * f'opening {self.raster_path} resulted in null, ' # <<<<<<<<<<<<<< + * f'trying {n_attempts} more times.') + * n_attempts -= 1 + */ + __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_5, 5, __pyx_t_21, __pyx_t_22); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 444, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 443, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":446 + * f'opening {self.raster_path} resulted in null, ' + * f'trying {n_attempts} more times.') + * n_attempts -= 1 # <<<<<<<<<<<<<< + * time.sleep(0.5) + * raster_band = raster.GetRasterBand(self.band_id) + */ + __pyx_t_3 = __Pyx_PyInt_SubtractObjC(__pyx_v_n_attempts, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 446, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF_SET(__pyx_v_n_attempts, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":447 + * f'trying {n_attempts} more times.') + * n_attempts -= 1 + * time.sleep(0.5) # <<<<<<<<<<<<<< + * raster_band = raster.GetRasterBand(self.band_id) + * break + */ + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_time); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 447, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_sleep); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 447, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_6, __pyx_float_0_5) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_float_0_5); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 447, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":439 + * raster = gdal.OpenEx( + * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) + * if raster is None: # <<<<<<<<<<<<<< + * if n_attempts == 0: + * raise RuntimeError( + */ + } + + /* "pygeoprocessing/routing/routing.pyx":448 + * n_attempts -= 1 + * time.sleep(0.5) + * raster_band = raster.GetRasterBand(self.band_id) # <<<<<<<<<<<<<< + * break + * + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 448, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_self->band_id); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 448, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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); + } + } + __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 448, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF_SET(__pyx_v_raster_band, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":449 + * time.sleep(0.5) + * raster_band = raster.GetRasterBand(self.band_id) + * break # <<<<<<<<<<<<<< + * + * block_array = numpy.empty( + */ + goto __pyx_L11_break; + } + __pyx_L11_break:; + + /* "pygeoprocessing/routing/routing.pyx":434 + * block_index, double_buffer, removed_value_list) + * + * if self.write_mode: # <<<<<<<<<<<<<< + * n_attempts = 5 + * while True: + */ + } + + /* "pygeoprocessing/routing/routing.pyx":451 + * break + * + * block_array = numpy.empty( # <<<<<<<<<<<<<< + * (self.block_ysize, self.block_xsize), dtype=numpy.double) + * while not removed_value_list.empty(): + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 451, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 451, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":452 + * + * 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, 452, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_self->block_xsize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 452, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 452, __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_6); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_6); + __pyx_t_3 = 0; + __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":451 + * break + * + * block_array = numpy.empty( # <<<<<<<<<<<<<< + * (self.block_ysize, self.block_xsize), dtype=numpy.double) + * while not removed_value_list.empty(): + */ + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 451, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); + __pyx_t_5 = 0; + + /* "pygeoprocessing/routing/routing.pyx":452 + * + * 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, 452, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 452, __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, 452, __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, 452, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":451 + * break + * + * 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_7, __pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 451, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __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; + if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 451, __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, 451, __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":453 + * 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_20 = ((!(__pyx_v_removed_value_list.empty() != 0)) != 0); + if (!__pyx_t_20) break; + + /* "pygeoprocessing/routing/routing.pyx":455 + * 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_23 = __pyx_v_removed_value_list.front().second; + __pyx_v_double_buffer = __pyx_t_23; + + /* "pygeoprocessing/routing/routing.pyx":457 + * double_buffer = removed_value_list.front().second + * + * if self.write_mode: # <<<<<<<<<<<<<< + * block_index = removed_value_list.front().first + * + */ + __pyx_t_20 = (__pyx_v_self->write_mode != 0); + if (__pyx_t_20) { + + /* "pygeoprocessing/routing/routing.pyx":458 + * + * 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":461 + * + * # 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":462 + * # 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_20 = ((__pyx_v_dirty_itr != __pyx_v_self->dirty_blocks.end()) != 0); + if (__pyx_t_20) { + + /* "pygeoprocessing/routing/routing.pyx":463 + * 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 + */ + (void)(__pyx_v_self->dirty_blocks.erase(__pyx_v_dirty_itr)); + + /* "pygeoprocessing/routing/routing.pyx":465 + * 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, 465, __pyx_L1_error) + } + __pyx_v_block_xi = __Pyx_mod_int(__pyx_v_block_index, __pyx_v_self->block_nx); + + /* "pygeoprocessing/routing/routing.pyx":466 + * + * 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, 466, __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, 466, __pyx_L1_error) + } + __pyx_v_block_yi = __Pyx_div_int(__pyx_v_block_index, __pyx_v_self->block_nx); + + /* "pygeoprocessing/routing/routing.pyx":468 + * 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":469 + * + * 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":471 + * 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":472 + * + * 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":474 + * 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_20 = (((__pyx_v_xoff + __pyx_v_win_xsize) > __pyx_v_self->raster_x_size) != 0); + if (__pyx_t_20) { + + /* "pygeoprocessing/routing/routing.pyx":475 + * + * 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":474 + * 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":477 + * 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_20 = (((__pyx_v_yoff + __pyx_v_win_ysize) > __pyx_v_self->raster_y_size) != 0); + if (__pyx_t_20) { + + /* "pygeoprocessing/routing/routing.pyx":478 + * 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":477 + * 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":481 + * 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":482 + * + * 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":483 + * 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_18 = __pyx_v_yi_copy; + __pyx_t_17 = __pyx_v_xi_copy; + __pyx_t_19 = -1; + if (__pyx_t_18 < 0) { + __pyx_t_18 += __pyx_pybuffernd_block_array.diminfo[0].shape; + if (unlikely(__pyx_t_18 < 0)) __pyx_t_19 = 0; + } else if (unlikely(__pyx_t_18 >= __pyx_pybuffernd_block_array.diminfo[0].shape)) __pyx_t_19 = 0; + if (__pyx_t_17 < 0) { + __pyx_t_17 += __pyx_pybuffernd_block_array.diminfo[1].shape; + if (unlikely(__pyx_t_17 < 0)) __pyx_t_19 = 1; + } else if (unlikely(__pyx_t_17 >= __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, 483, __pyx_L1_error) + } + *__Pyx_BufPtrStrided2d(double *, __pyx_pybuffernd_block_array.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_block_array.diminfo[0].strides, __pyx_t_17, __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":485 + * 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, 485, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "pygeoprocessing/routing/routing.pyx":486 + * (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, 486, __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, 486, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __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, 486, __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, 486, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 486, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_7); + __pyx_t_6 = 0; + __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_block_array), __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 486, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pygeoprocessing/routing/routing.pyx":485 + * 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, 485, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":487 + * 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_7 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 487, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_xoff); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 487, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_xoff, __pyx_t_6) < 0) __PYX_ERR(0, 487, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_yoff); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 487, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_yoff, __pyx_t_6) < 0) __PYX_ERR(0, 487, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":485 + * 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_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 485, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":462 + * # 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":457 + * double_buffer = removed_value_list.front().second + * + * if self.write_mode: # <<<<<<<<<<<<<< + * block_index = removed_value_list.front().first + * + */ + } + + /* "pygeoprocessing/routing/routing.pyx":488 + * 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":489 + * 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":491 + * removed_value_list.pop_front() + * + * if self.write_mode: # <<<<<<<<<<<<<< + * raster_band = None + * raster = None + */ + __pyx_t_20 = (__pyx_v_self->write_mode != 0); + if (__pyx_t_20) { + + /* "pygeoprocessing/routing/routing.pyx":492 + * + * 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":493 + * if self.write_mode: + * raster_band = None + * raster = None # <<<<<<<<<<<<<< + * + * cdef void flush(self) except *: + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_raster, Py_None); + + /* "pygeoprocessing/routing/routing.pyx":491 + * removed_value_list.pop_front() + * + * if self.write_mode: # <<<<<<<<<<<<<< + * raster_band = None + * raster = None + */ + } + + /* "pygeoprocessing/routing/routing.pyx":392 + * (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_XDECREF(__pyx_v_n_attempts); + __Pyx_RefNannyFinishContext(); +} + +/* "pygeoprocessing/routing/routing.pyx":495 + * raster = None + * + * cdef void flush(self) except *: # <<<<<<<<<<<<<< + * cdef clist[BlockBufferPair] removed_value_list + * cdef double *double_buffer + */ + +static void __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_flush(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_self) { + std::list<__pyx_t_15pygeoprocessing_7routing_7routing_BlockBufferPair> __pyx_v_removed_value_list; + double *__pyx_v_double_buffer; + std::set ::iterator __pyx_v_dirty_itr; + 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_win_xsize; + int __pyx_v_win_ysize; + PyObject *__pyx_v_raster_band = NULL; + PyObject *__pyx_v_max_retries = NULL; + PyObject *__pyx_v_raster = NULL; + PyObject *__pyx_v_block_array = NULL; + PyObject *__pyx_v_xi_copy = NULL; + PyObject *__pyx_v_yi_copy = 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; + int __pyx_t_7; + int __pyx_t_8; + Py_ssize_t __pyx_t_9; + Py_UCS4 __pyx_t_10; + double *__pyx_t_11; + PyObject *(*__pyx_t_12)(PyObject *); + Py_ssize_t __pyx_t_13; + PyObject *(*__pyx_t_14)(PyObject *); + Py_ssize_t __pyx_t_15; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("flush", 0); + + /* "pygeoprocessing/routing/routing.pyx":502 + * cdef int xoff, yoff, win_xsize, win_ysize + * + * self.lru_cache.clean(removed_value_list, self.lru_cache.size()) # <<<<<<<<<<<<<< + * + * raster_band = None + */ + __pyx_v_self->lru_cache->clean(__pyx_v_removed_value_list, __pyx_v_self->lru_cache->size()); + + /* "pygeoprocessing/routing/routing.pyx":504 + * self.lru_cache.clean(removed_value_list, self.lru_cache.size()) + * + * raster_band = None # <<<<<<<<<<<<<< + * if self.write_mode: + * max_retries = 5 + */ + __Pyx_INCREF(Py_None); + __pyx_v_raster_band = Py_None; + + /* "pygeoprocessing/routing/routing.pyx":505 + * + * raster_band = None + * if self.write_mode: # <<<<<<<<<<<<<< + * max_retries = 5 + * while max_retries > 0: + */ + __pyx_t_1 = (__pyx_v_self->write_mode != 0); + if (__pyx_t_1) { + + /* "pygeoprocessing/routing/routing.pyx":506 + * raster_band = None + * if self.write_mode: + * max_retries = 5 # <<<<<<<<<<<<<< + * while max_retries > 0: + * raster = gdal.OpenEx( + */ + __Pyx_INCREF(__pyx_int_5); + __pyx_v_max_retries = __pyx_int_5; + + /* "pygeoprocessing/routing/routing.pyx":507 + * if self.write_mode: + * max_retries = 5 + * while max_retries > 0: # <<<<<<<<<<<<<< + * raster = gdal.OpenEx( + * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) + */ + while (1) { + __pyx_t_2 = PyObject_RichCompare(__pyx_v_max_retries, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 507, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 507, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (!__pyx_t_1) break; + + /* "pygeoprocessing/routing/routing.pyx":508 + * max_retries = 5 + * while max_retries > 0: + * raster = gdal.OpenEx( # <<<<<<<<<<<<<< + * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) + * if raster is None: + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 508, __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, 508, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":509 + * while max_retries > 0: + * raster = gdal.OpenEx( + * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) # <<<<<<<<<<<<<< + * if raster is None: + * max_retries -= 1 + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 509, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_GA_Update); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 509, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 509, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 509, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyNumber_Or(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 509, __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_t_6 = NULL; + __pyx_t_7 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_6); + __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_6, __pyx_v_self->raster_path, __pyx_t_3}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 508, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_2); + __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[3] = {__pyx_t_6, __pyx_v_self->raster_path, __pyx_t_3}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 508, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + { + __pyx_t_5 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 508, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_6) { + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6); __pyx_t_6 = NULL; + } + __Pyx_INCREF(__pyx_v_self->raster_path); + __Pyx_GIVEREF(__pyx_v_self->raster_path); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_7, __pyx_v_self->raster_path); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_7, __pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 508, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF_SET(__pyx_v_raster, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":510 + * raster = gdal.OpenEx( + * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) + * if raster is None: # <<<<<<<<<<<<<< + * max_retries -= 1 + * LOGGER.error( + */ + __pyx_t_1 = (__pyx_v_raster == Py_None); + __pyx_t_8 = (__pyx_t_1 != 0); + if (__pyx_t_8) { + + /* "pygeoprocessing/routing/routing.pyx":511 + * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) + * if raster is None: + * max_retries -= 1 # <<<<<<<<<<<<<< + * LOGGER.error( + * f'unable to open {self.raster_path}, retrying...') + */ + __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_v_max_retries, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 511, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF_SET(__pyx_v_max_retries, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":512 + * if raster is None: + * max_retries -= 1 + * LOGGER.error( # <<<<<<<<<<<<<< + * f'unable to open {self.raster_path}, retrying...') + * time.sleep(0.2) + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 512, __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, 512, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":513 + * max_retries -= 1 + * LOGGER.error( + * f'unable to open {self.raster_path}, retrying...') # <<<<<<<<<<<<<< + * time.sleep(0.2) + * continue + */ + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 513, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = 0; + __pyx_t_10 = 127; + __Pyx_INCREF(__pyx_kp_u_unable_to_open); + __pyx_t_9 += 15; + __Pyx_GIVEREF(__pyx_kp_u_unable_to_open); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_u_unable_to_open); + __pyx_t_3 = __Pyx_PyObject_FormatSimple(__pyx_v_self->raster_path, __pyx_empty_unicode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 513, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) > __pyx_t_10) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) : __pyx_t_10; + __pyx_t_9 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); + __pyx_t_3 = 0; + __Pyx_INCREF(__pyx_kp_u_retrying); + __pyx_t_9 += 13; + __Pyx_GIVEREF(__pyx_kp_u_retrying); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_kp_u_retrying); + __pyx_t_3 = __Pyx_PyUnicode_Join(__pyx_t_4, 3, __pyx_t_9, __pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 513, __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_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_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 512, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":514 + * LOGGER.error( + * f'unable to open {self.raster_path}, retrying...') + * time.sleep(0.2) # <<<<<<<<<<<<<< + * continue + * break + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 514, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_sleep); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 514, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + 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_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_float_0_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_float_0_2); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 514, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":515 + * f'unable to open {self.raster_path}, retrying...') + * time.sleep(0.2) + * continue # <<<<<<<<<<<<<< + * break + * if max_retries == 0: + */ + goto __pyx_L4_continue; + + /* "pygeoprocessing/routing/routing.pyx":510 + * raster = gdal.OpenEx( + * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) + * if raster is None: # <<<<<<<<<<<<<< + * max_retries -= 1 + * LOGGER.error( + */ + } + + /* "pygeoprocessing/routing/routing.pyx":516 + * time.sleep(0.2) + * continue + * break # <<<<<<<<<<<<<< + * if max_retries == 0: + * raise ValueError( + */ + goto __pyx_L5_break; + __pyx_L4_continue:; + } + __pyx_L5_break:; + + /* "pygeoprocessing/routing/routing.pyx":517 + * continue + * break + * if max_retries == 0: # <<<<<<<<<<<<<< + * raise ValueError( + * f'unable to open {self.raster_path} in ' + */ + __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_v_max_retries, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 517, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 517, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(__pyx_t_8)) { + + /* "pygeoprocessing/routing/routing.pyx":519 + * if max_retries == 0: + * raise ValueError( + * f'unable to open {self.raster_path} in ' # <<<<<<<<<<<<<< + * 'ManagedRaster.flush') + * raster_band = raster.GetRasterBand(self.band_id) + */ + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 519, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = 0; + __pyx_t_10 = 127; + __Pyx_INCREF(__pyx_kp_u_unable_to_open); + __pyx_t_9 += 15; + __Pyx_GIVEREF(__pyx_kp_u_unable_to_open); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_u_unable_to_open); + __pyx_t_3 = __Pyx_PyObject_FormatSimple(__pyx_v_self->raster_path, __pyx_empty_unicode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 519, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) > __pyx_t_10) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) : __pyx_t_10; + __pyx_t_9 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); + __pyx_t_3 = 0; + __Pyx_INCREF(__pyx_kp_u_in_ManagedRaster_flush); + __pyx_t_9 += 23; + __Pyx_GIVEREF(__pyx_kp_u_in_ManagedRaster_flush); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_kp_u_in_ManagedRaster_flush); + __pyx_t_3 = __Pyx_PyUnicode_Join(__pyx_t_2, 3, __pyx_t_9, __pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 519, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":518 + * break + * if max_retries == 0: + * raise ValueError( # <<<<<<<<<<<<<< + * f'unable to open {self.raster_path} in ' + * 'ManagedRaster.flush') + */ + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 518, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 518, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":517 + * continue + * break + * if max_retries == 0: # <<<<<<<<<<<<<< + * raise ValueError( + * f'unable to open {self.raster_path} in ' + */ + } + + /* "pygeoprocessing/routing/routing.pyx":521 + * f'unable to open {self.raster_path} in ' + * 'ManagedRaster.flush') + * raster_band = raster.GetRasterBand(self.band_id) # <<<<<<<<<<<<<< + * + * block_array = numpy.empty( + */ + if (unlikely(!__pyx_v_raster)) { __Pyx_RaiseUnboundLocalError("raster"); __PYX_ERR(0, 521, __pyx_L1_error) } + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 521, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_self->band_id); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 521, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __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); + } + } + __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 521, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF_SET(__pyx_v_raster_band, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":505 + * + * raster_band = None + * if self.write_mode: # <<<<<<<<<<<<<< + * max_retries = 5 + * while max_retries > 0: + */ + } + + /* "pygeoprocessing/routing/routing.pyx":523 + * 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 523, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 523, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":524 + * + * 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_2 = __Pyx_PyInt_From_int(__pyx_v_self->block_ysize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 524, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_self->block_xsize); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 524, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 524, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5); + __pyx_t_2 = 0; + __pyx_t_5 = 0; + + /* "pygeoprocessing/routing/routing.pyx":523 + * 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_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 523, __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 = 0; + + /* "pygeoprocessing/routing/routing.pyx":524 + * + * 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_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 524, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 524, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_double); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 524, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 524, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":523 + * 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_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 523, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_block_array = __pyx_t_6; + __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":525 + * 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_8 = ((!(__pyx_v_removed_value_list.empty() != 0)) != 0); + if (!__pyx_t_8) break; + + /* "pygeoprocessing/routing/routing.pyx":527 + * 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_11 = __pyx_v_removed_value_list.front().second; + __pyx_v_double_buffer = __pyx_t_11; + + /* "pygeoprocessing/routing/routing.pyx":529 + * double_buffer = removed_value_list.front().second + * + * if self.write_mode: # <<<<<<<<<<<<<< + * block_index = removed_value_list.front().first + * + */ + __pyx_t_8 = (__pyx_v_self->write_mode != 0); + if (__pyx_t_8) { + + /* "pygeoprocessing/routing/routing.pyx":530 + * + * if self.write_mode: + * block_index = removed_value_list.front().first # <<<<<<<<<<<<<< + * + * # write back the block if it's dirty + */ + __pyx_t_7 = __pyx_v_removed_value_list.front().first; + __pyx_v_block_index = __pyx_t_7; + + /* "pygeoprocessing/routing/routing.pyx":533 + * + * # 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":534 + * # 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_8 = ((__pyx_v_dirty_itr != __pyx_v_self->dirty_blocks.end()) != 0); + if (__pyx_t_8) { + + /* "pygeoprocessing/routing/routing.pyx":535 + * 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 + */ + (void)(__pyx_v_self->dirty_blocks.erase(__pyx_v_dirty_itr)); + + /* "pygeoprocessing/routing/routing.pyx":537 + * 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, 537, __pyx_L1_error) + } + __pyx_v_block_xi = __Pyx_mod_int(__pyx_v_block_index, __pyx_v_self->block_nx); + + /* "pygeoprocessing/routing/routing.pyx":538 + * + * 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, 538, __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, 538, __pyx_L1_error) + } + __pyx_v_block_yi = __Pyx_div_int(__pyx_v_block_index, __pyx_v_self->block_nx); + + /* "pygeoprocessing/routing/routing.pyx":540 + * 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":541 + * + * 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":543 + * yoff = block_yi << self.block_ybits + * + * win_xsize = self.block_xsize # <<<<<<<<<<<<<< + * win_ysize = self.block_ysize + * + */ + __pyx_t_7 = __pyx_v_self->block_xsize; + __pyx_v_win_xsize = __pyx_t_7; + + /* "pygeoprocessing/routing/routing.pyx":544 + * + * win_xsize = self.block_xsize + * win_ysize = self.block_ysize # <<<<<<<<<<<<<< + * + * if xoff+win_xsize > self.raster_x_size: + */ + __pyx_t_7 = __pyx_v_self->block_ysize; + __pyx_v_win_ysize = __pyx_t_7; + + /* "pygeoprocessing/routing/routing.pyx":546 + * 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_8 = (((__pyx_v_xoff + __pyx_v_win_xsize) > __pyx_v_self->raster_x_size) != 0); + if (__pyx_t_8) { + + /* "pygeoprocessing/routing/routing.pyx":547 + * + * 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":546 + * 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":549 + * 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_8 = (((__pyx_v_yoff + __pyx_v_win_ysize) > __pyx_v_self->raster_y_size) != 0); + if (__pyx_t_8) { + + /* "pygeoprocessing/routing/routing.pyx":550 + * 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":549 + * 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":553 + * 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_6 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 553, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 553, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) { + __pyx_t_6 = __pyx_t_4; __Pyx_INCREF(__pyx_t_6); __pyx_t_9 = 0; + __pyx_t_12 = NULL; + } else { + __pyx_t_9 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 553, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_12 = Py_TYPE(__pyx_t_6)->tp_iternext; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 553, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + for (;;) { + if (likely(!__pyx_t_12)) { + if (likely(PyList_CheckExact(__pyx_t_6))) { + if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_6)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_9); __Pyx_INCREF(__pyx_t_4); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 553, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_6, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 553, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } else { + if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_6)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_9); __Pyx_INCREF(__pyx_t_4); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 553, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_6, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 553, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } + } else { + __pyx_t_4 = __pyx_t_12(__pyx_t_6); + 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, 553, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XDECREF_SET(__pyx_v_xi_copy, __pyx_t_4); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":554 + * + * 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_4 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 554, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 554, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (likely(PyList_CheckExact(__pyx_t_5)) || PyTuple_CheckExact(__pyx_t_5)) { + __pyx_t_4 = __pyx_t_5; __Pyx_INCREF(__pyx_t_4); __pyx_t_13 = 0; + __pyx_t_14 = NULL; + } else { + __pyx_t_13 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 554, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_14 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 554, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + for (;;) { + if (likely(!__pyx_t_14)) { + if (likely(PyList_CheckExact(__pyx_t_4))) { + if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_13); __Pyx_INCREF(__pyx_t_5); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 554, __pyx_L1_error) + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_4, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 554, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + } else { + if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_13); __Pyx_INCREF(__pyx_t_5); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 554, __pyx_L1_error) + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_4, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 554, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + } + } else { + __pyx_t_5 = __pyx_t_14(__pyx_t_4); + 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, 554, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_5); + } + __Pyx_XDECREF_SET(__pyx_v_yi_copy, __pyx_t_5); + __pyx_t_5 = 0; + + /* "pygeoprocessing/routing/routing.pyx":556 + * 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( + * block_array[0:win_ysize, 0:win_xsize], + */ + __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_self->block_xbits); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 556, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = PyNumber_Lshift(__pyx_v_yi_copy, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 556, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyNumber_Add(__pyx_t_3, __pyx_v_xi_copy); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 556, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_15 = __Pyx_PyIndex_AsSsize_t(__pyx_t_5); if (unlikely((__pyx_t_15 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 556, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pygeoprocessing/routing/routing.pyx":555 + * 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_5 = PyFloat_FromDouble((__pyx_v_double_buffer[__pyx_t_15])); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 555, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 555, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_yi_copy); + __Pyx_GIVEREF(__pyx_v_yi_copy); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_yi_copy); + __Pyx_INCREF(__pyx_v_xi_copy); + __Pyx_GIVEREF(__pyx_v_xi_copy); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_xi_copy); + if (unlikely(PyObject_SetItem(__pyx_v_block_array, __pyx_t_3, __pyx_t_5) < 0)) __PYX_ERR(0, 555, __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":554 + * + * 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_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":553 + * 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_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":557 + * 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_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster_band, __pyx_n_s_WriteArray); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 557, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + + /* "pygeoprocessing/routing/routing.pyx":558 + * (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_4 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 558, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PySlice_New(__pyx_int_0, __pyx_t_4, Py_None); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 558, __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_win_xsize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 558, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PySlice_New(__pyx_int_0, __pyx_t_4, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 558, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 558, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); + __pyx_t_5 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_block_array, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 558, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":557 + * 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 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 557, __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 = 0; + + /* "pygeoprocessing/routing/routing.pyx":559 + * 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_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 559, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_xoff); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 559, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_xoff, __pyx_t_5) < 0) __PYX_ERR(0, 559, __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, 559, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_yoff, __pyx_t_5) < 0) __PYX_ERR(0, 559, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pygeoprocessing/routing/routing.pyx":557 + * 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 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 557, __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_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pygeoprocessing/routing/routing.pyx":534 + * # 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":529 + * double_buffer = removed_value_list.front().second + * + * if self.write_mode: # <<<<<<<<<<<<<< + * block_index = removed_value_list.front().first + * + */ + } + + /* "pygeoprocessing/routing/routing.pyx":560 + * 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":561 + * 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":563 + * removed_value_list.pop_front() + * + * if self.write_mode: # <<<<<<<<<<<<<< + * raster_band = None + * raster = None + */ + __pyx_t_8 = (__pyx_v_self->write_mode != 0); + if (__pyx_t_8) { + + /* "pygeoprocessing/routing/routing.pyx":564 + * + * 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":565 + * if self.write_mode: + * raster_band = None + * raster = None # <<<<<<<<<<<<<< + * + * + */ + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_raster, Py_None); + + /* "pygeoprocessing/routing/routing.pyx":563 + * removed_value_list.pop_front() + * + * if self.write_mode: # <<<<<<<<<<<<<< + * raster_band = None + * raster = None + */ + } + + /* "pygeoprocessing/routing/routing.pyx":495 + * raster = None + * + * cdef void flush(self) except *: # <<<<<<<<<<<<<< + * cdef clist[BlockBufferPair] removed_value_list + * cdef double *double_buffer + */ + + /* function exit code */ + 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); + __Pyx_AddTraceback("pygeoprocessing.routing.routing._ManagedRaster.flush", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_raster_band); + __Pyx_XDECREF(__pyx_v_max_retries); + __Pyx_XDECREF(__pyx_v_raster); + __Pyx_XDECREF(__pyx_v_block_array); + __Pyx_XDECREF(__pyx_v_xi_copy); + __Pyx_XDECREF(__pyx_v_yi_copy); + __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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __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__2, 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __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__3, 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":568 + * + * + * 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)(void*)(PyCFunctionWithKeywords)__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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 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, 568, __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, 568, __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, 568, __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, 568, __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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_generate_read_bounds", 0); + + /* "pygeoprocessing/routing/routing.pyx":590 + * 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":591 + * """ + * 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":592 + * 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":593 + * 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":594 + * 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, 594, __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); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 594, __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":595 + * 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_u_xoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 595, __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, 595, __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, 595, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_4) { + + /* "pygeoprocessing/routing/routing.pyx":596 + * 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":597 + * 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_u_xoff); + __pyx_t_5 = __pyx_n_u_xoff; + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_target_offset_dict, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 597, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyInt_SubtractObjC(__pyx_t_2, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 597, __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, 597, __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":598 + * xa = None + * target_offset_dict['xoff'] -= 1 + * target_offset_dict['win_xsize'] += 1 # <<<<<<<<<<<<<< + * if offset_dict['yoff'] > 0: + * ya = None + */ + __Pyx_INCREF(__pyx_n_u_win_xsize); + __pyx_t_5 = __pyx_n_u_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, 598, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 598, __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, 598, __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":595 + * yb = -1 + * target_offset_dict = offset_dict.copy() + * if offset_dict['xoff'] > 0: # <<<<<<<<<<<<<< + * xa = None + * target_offset_dict['xoff'] -= 1 + */ + } + + /* "pygeoprocessing/routing/routing.pyx":599 + * 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_u_yoff); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 599, __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, 599, __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, 599, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_4) { + + /* "pygeoprocessing/routing/routing.pyx":600 + * 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":601 + * 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_u_yoff); + __pyx_t_5 = __pyx_n_u_yoff; + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_target_offset_dict, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 601, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_t_1, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 601, __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, 601, __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":602 + * 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_u_win_ysize); + __pyx_t_5 = __pyx_n_u_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, 602, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 602, __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, 602, __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":599 + * 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":603 + * 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_u_xoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 603, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 603, __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, 603, __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, 603, __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, 603, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_4) { + + /* "pygeoprocessing/routing/routing.pyx":604 + * 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":605 + * 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_u_win_xsize); + __pyx_t_5 = __pyx_n_u_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, 605, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 605, __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, 605, __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":603 + * 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":606 + * 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_u_yoff); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 606, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 606, __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, 606, __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, 606, __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, 606, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_4) { + + /* "pygeoprocessing/routing/routing.pyx":607 + * 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":608 + * 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_u_win_ysize); + __pyx_t_5 = __pyx_n_u_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, 608, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 608, __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, 608, __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":606 + * 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":609 + * 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, 609, __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, 609, __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":568 + * + * + * 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":612 + * + * + * def fill_pits( # <<<<<<<<<<<<<< + * dem_raster_path_band, target_filled_dem_raster_path, + * working_dir=None, long max_pixel_fill_count=_MAX_PIXEL_FILL_COUNT, + */ + +/* 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 (str): path the pit filled dem,\n that's created by a call to this function. It is functionally a\n single band copy of ``dem_raster_path_band`` with the pit pixels\n raised to the pour point. For runtime efficiency, this raster is\n tiled and its blocksize is set to (``1< 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_max_pixel_fill_count); + 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_raster_driver_creation_tuple); + if (value) { values[4] = 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, 612, __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); + 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]; + if (values[3]) { + __pyx_v_max_pixel_fill_count = __Pyx_PyInt_As_long(values[3]); if (unlikely((__pyx_v_max_pixel_fill_count == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 614, __pyx_L3_error) + } else { + __pyx_v_max_pixel_fill_count = __pyx_k__5; + } + __pyx_v_raster_driver_creation_tuple = values[4]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("fill_pits", 0, 2, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 612, __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_max_pixel_fill_count, __pyx_v_raster_driver_creation_tuple); + + /* "pygeoprocessing/routing/routing.pyx":612 + * + * + * def fill_pits( # <<<<<<<<<<<<<< + * dem_raster_path_band, target_filled_dem_raster_path, + * working_dir=None, long max_pixel_fill_count=_MAX_PIXEL_FILL_COUNT, + */ + + /* 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, long __pyx_v_max_pixel_fill_count, PyObject *__pyx_v_raster_driver_creation_tuple) { + 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_natural_drain_exists; + int __pyx_v_search_steps; + std::queue __pyx_v_search_queue; + std::queue __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_base_datatype = NULL; + PyObject *__pyx_v_filled_dem_raster = NULL; + PyObject *__pyx_v_filled_dem_band = NULL; + PyObject *__pyx_v_offset_info = NULL; + PyObject *__pyx_v_block_array = NULL; + struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_filled_dem_managed_raster = NULL; + PyObject *__pyx_v_offset_dict = NULL; + int __pyx_v_current_pixel; + double __pyx_v_n_height; + long __pyx_v_pour_point; + 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; + double __pyx_t_7; + PyObject *(*__pyx_t_8)(PyObject *); + int __pyx_t_9; + int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + 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 *); + Py_ssize_t __pyx_t_19; + Py_UCS4 __pyx_t_20; + long __pyx_t_21; + long __pyx_t_22; + long __pyx_t_23; + long __pyx_t_24; + int __pyx_t_25; + struct __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateType __pyx_t_26; + struct __pyx_t_15pygeoprocessing_7routing_7routing_PixelType __pyx_t_27; + __pyx_t_15pygeoprocessing_7routing_7routing_PitPriorityQueueType __pyx_t_28; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("fill_pits", 0); + + /* "pygeoprocessing/routing/routing.pyx":701 + * # 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":705 + * # 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 705, __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, 705, __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, 705, __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); + } + } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 705, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __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":706 + * # 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_u_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 706, __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, 706, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_t_3, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 706, __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_v_base_nodata = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":707 + * 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_5 = (__pyx_v_base_nodata != Py_None); + __pyx_t_6 = (__pyx_t_5 != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/routing/routing.pyx":709 + * 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 709, __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, 709, __pyx_L1_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); + } + } + __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_v_base_nodata) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_base_nodata); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 709, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_7 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 709, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_dem_nodata = __pyx_t_7; + + /* "pygeoprocessing/routing/routing.pyx":707 + * 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":712 + * 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":715 + * + * # 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_u_raster_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 715, __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, 715, __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, 715, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 715, __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_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 715, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_4)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_8(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + 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, 715, __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, 715, __pyx_L1_error) + __pyx_L5_unpacking_done:; + } + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 715, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 715, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_raster_x_size = __pyx_t_9; + __pyx_v_raster_y_size = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":718 + * + * # 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":721 + * + * # 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_11, &__pyx_t_12, &__pyx_t_13); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_13); + /*try:*/ { + + /* "pygeoprocessing/routing/routing.pyx":722 + * # set up the working dir for the mask rasters + * try: + * if working_dir is not None: # <<<<<<<<<<<<<< + * os.makedirs(working_dir) + * except OSError: + */ + __pyx_t_6 = (__pyx_v_working_dir != Py_None); + __pyx_t_5 = (__pyx_t_6 != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":723 + * try: + * if working_dir is not None: + * os.makedirs(working_dir) # <<<<<<<<<<<<<< + * except OSError: + * pass + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 723, __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, 723, __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); + } + } + __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_v_working_dir) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_working_dir); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 723, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":722 + * # 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":721 + * + * # set up the working dir for the mask rasters + * try: # <<<<<<<<<<<<<< + * if working_dir is not None: + * os.makedirs(working_dir) + */ + } + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + goto __pyx_L11_try_end; + __pyx_L6_error:; + __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; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":724 + * if working_dir is not None: + * os.makedirs(working_dir) + * except OSError: # <<<<<<<<<<<<<< + * pass + * working_dir_path = tempfile.mkdtemp( + */ + __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OSError); + if (__pyx_t_10) { + __Pyx_ErrRestore(0,0,0); + goto __pyx_L7_exception_handled; + } + goto __pyx_L8_except_error; + __pyx_L8_except_error:; + + /* "pygeoprocessing/routing/routing.pyx":721 + * + * # set up the working dir for the mask rasters + * try: # <<<<<<<<<<<<<< + * if working_dir is not None: + * os.makedirs(working_dir) + */ + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_13); + __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13); + goto __pyx_L1_error; + __pyx_L7_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_13); + __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13); + __pyx_L11_try_end:; + } + + /* "pygeoprocessing/routing/routing.pyx":726 + * 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_tempfile); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 726, __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, 726, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":727 + * 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, 727, __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, 727, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_time); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 727, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_strftime); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 727, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":728 + * 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_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_time); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 728, __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, 728, __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); + } + } + __pyx_t_4 = (__pyx_t_15) ? __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_t_15) : __Pyx_PyObject_CallNoArg(__pyx_t_16); + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 728, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __pyx_t_16 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_16)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_16); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + __pyx_t_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_kp_u_Y_m_d__H__M__S, __pyx_t_4}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 727, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 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_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_kp_u_Y_m_d__H__M__S, __pyx_t_4}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 727, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_15 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 727, __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_u_Y_m_d__H__M__S); + __Pyx_GIVEREF(__pyx_kp_u_Y_m_d__H__M__S); + PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_10, __pyx_kp_u_Y_m_d__H__M__S); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_10, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_15, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 727, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":727 + * 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_14 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_fill_pits__s, __pyx_t_2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 727, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_prefix, __pyx_t_14) < 0) __PYX_ERR(0, 727, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":726 + * 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_14 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 726, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __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_14; + __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":733 + * # 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 733, __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, 733, __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, 733, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":734 + * # 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_10 = 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_10 = 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_u_flat_region_mask_tif}; + __pyx_t_14 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 733, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_14); + } 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_u_flat_region_mask_tif}; + __pyx_t_14 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 733, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_14); + } else + #endif + { + __pyx_t_2 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 733, __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_v_working_dir_path); + __Pyx_GIVEREF(__pyx_v_working_dir_path); + PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_10, __pyx_v_working_dir_path); + __Pyx_INCREF(__pyx_kp_u_flat_region_mask_tif); + __Pyx_GIVEREF(__pyx_kp_u_flat_region_mask_tif); + PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_10, __pyx_kp_u_flat_region_mask_tif); + __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 733, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_flat_region_mask_path = __pyx_t_14; + __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":735 + * 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":737 + * 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], + */ + __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 737, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 737, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":738 + * + * pygeoprocessing.new_raster_from_base( + * dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte, # <<<<<<<<<<<<<< + * [mask_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + */ + __pyx_t_14 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 738, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 738, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 738, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":739 + * pygeoprocessing.new_raster_from_base( + * dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte, + * [mask_nodata], # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * flat_region_mask_managed_raster = _ManagedRaster( + */ + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_mask_nodata); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 739, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_15 = PyList_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 739, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_GIVEREF(__pyx_t_2); + PyList_SET_ITEM(__pyx_t_15, 0, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":737 + * 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], + */ + __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 737, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_14); + __Pyx_INCREF(__pyx_v_flat_region_mask_path); + __Pyx_GIVEREF(__pyx_v_flat_region_mask_path); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_flat_region_mask_path); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_15); + PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_15); + __pyx_t_14 = 0; + __pyx_t_1 = 0; + __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":740 + * dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte, + * [mask_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< + * flat_region_mask_managed_raster = _ManagedRaster( + * flat_region_mask_path, 1, 1) + */ + __pyx_t_15 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 740, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 740, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":737 + * 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], + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 737, __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_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":741 + * [mask_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * flat_region_mask_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< + * flat_region_mask_path, 1, 1) + * + */ + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 741, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_flat_region_mask_path); + __Pyx_GIVEREF(__pyx_v_flat_region_mask_path); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_flat_region_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_15 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_1, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 741, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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":747 + * # 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_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 747, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_path); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 747, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_join); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 747, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && likely(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_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_working_dir_path, __pyx_kp_u_pit_mask_tif}; + __pyx_t_15 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 747, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_15); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_working_dir_path, __pyx_kp_u_pit_mask_tif}; + __pyx_t_15 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 747, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_15); + } else + #endif + { + __pyx_t_3 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 747, __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_v_working_dir_path); + __Pyx_GIVEREF(__pyx_v_working_dir_path); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_10, __pyx_v_working_dir_path); + __Pyx_INCREF(__pyx_kp_u_pit_mask_tif); + __Pyx_GIVEREF(__pyx_kp_u_pit_mask_tif); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_10, __pyx_kp_u_pit_mask_tif); + __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 747, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_pit_mask_path = __pyx_t_15; + __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":748 + * # `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], + */ + __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 748, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 748, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":749 + * 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], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + */ + __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, 749, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 749, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_GDT_Int32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 749, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":750 + * pygeoprocessing.new_raster_from_base( + * dem_raster_path_band[0], pit_mask_path, gdal.GDT_Int32, + * [mask_nodata], # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * pit_mask_managed_raster = _ManagedRaster( + */ + __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_mask_nodata); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 750, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_14 = PyList_New(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 750, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GIVEREF(__pyx_t_3); + PyList_SET_ITEM(__pyx_t_14, 0, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":748 + * # `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], + */ + __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 748, __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_2); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_14); + __pyx_t_15 = 0; + __pyx_t_2 = 0; + __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":751 + * dem_raster_path_band[0], pit_mask_path, gdal.GDT_Int32, + * [mask_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< + * pit_mask_managed_raster = _ManagedRaster( + * pit_mask_path, 1, 1) + */ + __pyx_t_14 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 751, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 751, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":748 + * # `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], + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_t_14); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 748, __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_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":752 + * [mask_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * pit_mask_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< + * pit_mask_path, 1, 1) + * + */ + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 752, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_pit_mask_path); + __Pyx_GIVEREF(__pyx_v_pit_mask_path); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_pit_mask_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_14 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_2, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 752, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_pit_mask_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_14); + __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":756 + * + * # copy the base DEM to the target and set up for writing + * base_datatype = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< + * dem_raster_path_band[0])['datatype'] + * pygeoprocessing.new_raster_from_base( + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 756, __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, 756, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":757 + * # copy the base DEM to the target and set up for writing + * base_datatype = pygeoprocessing.get_raster_info( + * dem_raster_path_band[0])['datatype'] # <<<<<<<<<<<<<< + * pygeoprocessing.new_raster_from_base( + * dem_raster_path_band[0], target_filled_dem_raster_path, + */ + __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, 757, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = NULL; + 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_14 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_1, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 756, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_t_14, __pyx_n_u_datatype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 757, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_v_base_datatype = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":758 + * base_datatype = pygeoprocessing.get_raster_info( + * dem_raster_path_band[0])['datatype'] + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * dem_raster_path_band[0], target_filled_dem_raster_path, + * base_datatype, [dem_nodata], + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 758, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 758, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":759 + * dem_raster_path_band[0])['datatype'] + * pygeoprocessing.new_raster_from_base( + * dem_raster_path_band[0], target_filled_dem_raster_path, # <<<<<<<<<<<<<< + * base_datatype, [dem_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + */ + __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, 759, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + + /* "pygeoprocessing/routing/routing.pyx":760 + * pygeoprocessing.new_raster_from_base( + * dem_raster_path_band[0], target_filled_dem_raster_path, + * base_datatype, [dem_nodata], # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * filled_dem_raster = gdal.OpenEx( + */ + __pyx_t_2 = PyFloat_FromDouble(__pyx_v_dem_nodata); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 760, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 760, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":758 + * base_datatype = pygeoprocessing.get_raster_info( + * dem_raster_path_band[0])['datatype'] + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * dem_raster_path_band[0], target_filled_dem_raster_path, + * base_datatype, [dem_nodata], + */ + __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 758, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 0, __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_2, 1, __pyx_v_target_filled_dem_raster_path); + __Pyx_INCREF(__pyx_v_base_datatype); + __Pyx_GIVEREF(__pyx_v_base_datatype); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_base_datatype); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_1); + __pyx_t_3 = 0; + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":761 + * dem_raster_path_band[0], target_filled_dem_raster_path, + * base_datatype, [dem_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< + * filled_dem_raster = gdal.OpenEx( + * target_filled_dem_raster_path, gdal.OF_RASTER | gdal.GA_Update) + */ + __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 761, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 761, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":758 + * base_datatype = pygeoprocessing.get_raster_info( + * dem_raster_path_band[0])['datatype'] + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * dem_raster_path_band[0], target_filled_dem_raster_path, + * base_datatype, [dem_nodata], + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 758, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":762 + * base_datatype, [dem_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * filled_dem_raster = gdal.OpenEx( # <<<<<<<<<<<<<< + * target_filled_dem_raster_path, gdal.OF_RASTER | gdal.GA_Update) + * filled_dem_band = filled_dem_raster.GetRasterBand(1) + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 762, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 762, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":763 + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * filled_dem_raster = gdal.OpenEx( + * target_filled_dem_raster_path, gdal.OF_RASTER | gdal.GA_Update) # <<<<<<<<<<<<<< + * filled_dem_band = filled_dem_raster.GetRasterBand(1) + * for offset_info, block_array in pygeoprocessing.iterblocks( + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 763, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 763, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 763, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GA_Update); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 763, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Or(__pyx_t_14, __pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 763, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_15)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_15); + __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_15, __pyx_v_target_filled_dem_raster_path, __pyx_t_1}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 762, __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_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_v_target_filled_dem_raster_path, __pyx_t_1}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 762, __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_14 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 762, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + if (__pyx_t_15) { + __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_15); __pyx_t_15 = NULL; + } + __Pyx_INCREF(__pyx_v_target_filled_dem_raster_path); + __Pyx_GIVEREF(__pyx_v_target_filled_dem_raster_path); + PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_10, __pyx_v_target_filled_dem_raster_path); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_10, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_14, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 762, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_filled_dem_raster = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":764 + * filled_dem_raster = gdal.OpenEx( + * target_filled_dem_raster_path, gdal.OF_RASTER | gdal.GA_Update) + * filled_dem_band = filled_dem_raster.GetRasterBand(1) # <<<<<<<<<<<<<< + * for offset_info, block_array in pygeoprocessing.iterblocks( + * dem_raster_path_band): + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_filled_dem_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 764, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_14 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_14)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_3 = (__pyx_t_14) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_14, __pyx_int_1) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_int_1); + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 764, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_filled_dem_band = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":765 + * target_filled_dem_raster_path, gdal.OF_RASTER | gdal.GA_Update) + * filled_dem_band = filled_dem_raster.GetRasterBand(1) + * for offset_info, block_array in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * dem_raster_path_band): + * filled_dem_band.WriteArray( + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 765, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 765, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":766 + * filled_dem_band = filled_dem_raster.GetRasterBand(1) + * for offset_info, block_array in pygeoprocessing.iterblocks( + * dem_raster_path_band): # <<<<<<<<<<<<<< + * filled_dem_band.WriteArray( + * block_array, xoff=offset_info['xoff'], yoff=offset_info['yoff']) + */ + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + } + } + __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_2, __pyx_v_dem_raster_path_band) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_v_dem_raster_path_band); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 765, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":765 + * target_filled_dem_raster_path, gdal.OF_RASTER | gdal.GA_Update) + * filled_dem_band = filled_dem_raster.GetRasterBand(1) + * for offset_info, block_array in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * dem_raster_path_band): + * filled_dem_band.WriteArray( + */ + if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) { + __pyx_t_14 = __pyx_t_3; __Pyx_INCREF(__pyx_t_14); __pyx_t_17 = 0; + __pyx_t_18 = NULL; + } else { + __pyx_t_17 = -1; __pyx_t_14 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 765, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_18 = Py_TYPE(__pyx_t_14)->tp_iternext; if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 765, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + for (;;) { + if (likely(!__pyx_t_18)) { + if (likely(PyList_CheckExact(__pyx_t_14))) { + if (__pyx_t_17 >= PyList_GET_SIZE(__pyx_t_14)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_14, __pyx_t_17); __Pyx_INCREF(__pyx_t_3); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 765, __pyx_L1_error) + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_14, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 765, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + } else { + if (__pyx_t_17 >= PyTuple_GET_SIZE(__pyx_t_14)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_14, __pyx_t_17); __Pyx_INCREF(__pyx_t_3); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 765, __pyx_L1_error) + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_14, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 765, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + } + } else { + __pyx_t_3 = __pyx_t_18(__pyx_t_14); + 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, 765, __pyx_L1_error) + } + break; + } + __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, 765, __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_1 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_2 = PyList_GET_ITEM(sequence, 0); + __pyx_t_1 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + #else + __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 765, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 765, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_15 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 765, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_15)->tp_iternext; + index = 0; __pyx_t_2 = __pyx_t_8(__pyx_t_15); if (unlikely(!__pyx_t_2)) goto __pyx_L15_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + index = 1; __pyx_t_1 = __pyx_t_8(__pyx_t_15); if (unlikely(!__pyx_t_1)) goto __pyx_L15_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_15), 2) < 0) __PYX_ERR(0, 765, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + goto __pyx_L16_unpacking_done; + __pyx_L15_unpacking_failed:; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 765, __pyx_L1_error) + __pyx_L16_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_offset_info, __pyx_t_2); + __pyx_t_2 = 0; + __Pyx_XDECREF_SET(__pyx_v_block_array, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":767 + * for offset_info, block_array in pygeoprocessing.iterblocks( + * dem_raster_path_band): + * filled_dem_band.WriteArray( # <<<<<<<<<<<<<< + * block_array, xoff=offset_info['xoff'], yoff=offset_info['yoff']) + * filled_dem_band.FlushCache() + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_filled_dem_band, __pyx_n_s_WriteArray); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 767, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + + /* "pygeoprocessing/routing/routing.pyx":768 + * dem_raster_path_band): + * filled_dem_band.WriteArray( + * block_array, xoff=offset_info['xoff'], yoff=offset_info['yoff']) # <<<<<<<<<<<<<< + * filled_dem_band.FlushCache() + * filled_dem_raster.FlushCache() + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 767, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_block_array); + __Pyx_GIVEREF(__pyx_v_block_array); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_block_array); + __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 768, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_15 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_info, __pyx_n_u_xoff); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 768, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_xoff, __pyx_t_15) < 0) __PYX_ERR(0, 768, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_info, __pyx_n_u_yoff); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 768, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_yoff, __pyx_t_15) < 0) __PYX_ERR(0, 768, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":767 + * for offset_info, block_array in pygeoprocessing.iterblocks( + * dem_raster_path_band): + * filled_dem_band.WriteArray( # <<<<<<<<<<<<<< + * block_array, xoff=offset_info['xoff'], yoff=offset_info['yoff']) + * filled_dem_band.FlushCache() + */ + __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 767, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":765 + * target_filled_dem_raster_path, gdal.OF_RASTER | gdal.GA_Update) + * filled_dem_band = filled_dem_raster.GetRasterBand(1) + * for offset_info, block_array in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * dem_raster_path_band): + * filled_dem_band.WriteArray( + */ + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":769 + * filled_dem_band.WriteArray( + * block_array, xoff=offset_info['xoff'], yoff=offset_info['yoff']) + * filled_dem_band.FlushCache() # <<<<<<<<<<<<<< + * filled_dem_raster.FlushCache() + * filled_dem_band = None + */ + __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_v_filled_dem_band, __pyx_n_s_FlushCache); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 769, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_14 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_15); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 769, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":770 + * block_array, xoff=offset_info['xoff'], yoff=offset_info['yoff']) + * filled_dem_band.FlushCache() + * filled_dem_raster.FlushCache() # <<<<<<<<<<<<<< + * filled_dem_band = None + * filled_dem_raster = None + */ + __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_v_filled_dem_raster, __pyx_n_s_FlushCache); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 770, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_14 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_15); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 770, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":771 + * filled_dem_band.FlushCache() + * filled_dem_raster.FlushCache() + * filled_dem_band = None # <<<<<<<<<<<<<< + * filled_dem_raster = None + * filled_dem_managed_raster = _ManagedRaster( + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_filled_dem_band, Py_None); + + /* "pygeoprocessing/routing/routing.pyx":772 + * filled_dem_raster.FlushCache() + * filled_dem_band = None + * filled_dem_raster = None # <<<<<<<<<<<<<< + * filled_dem_managed_raster = _ManagedRaster( + * target_filled_dem_raster_path, 1, 1) + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_filled_dem_raster, Py_None); + + /* "pygeoprocessing/routing/routing.pyx":773 + * filled_dem_band = None + * filled_dem_raster = None + * filled_dem_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< + * target_filled_dem_raster_path, 1, 1) + * + */ + __pyx_t_14 = PyTuple_New(3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 773, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_INCREF(__pyx_v_target_filled_dem_raster_path); + __Pyx_GIVEREF(__pyx_v_target_filled_dem_raster_path); + PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_v_target_filled_dem_raster_path); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_int_1); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_14, 2, __pyx_int_1); + __pyx_t_15 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_14, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 773, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_v_filled_dem_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_15); + __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":777 + * + * # 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":780 + * + * # this outer loop searches for a pixel that is locally undrained + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * dem_raster_path_band, offset_only=True, largest_block=0): + * win_xsize = offset_dict['win_xsize'] + */ + __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 780, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 780, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":781 + * # this outer loop searches for a pixel that is locally undrained + * for offset_dict in pygeoprocessing.iterblocks( + * dem_raster_path_band, offset_only=True, largest_block=0): # <<<<<<<<<<<<<< + * win_xsize = offset_dict['win_xsize'] + * win_ysize = offset_dict['win_ysize'] + */ + __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 780, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_INCREF(__pyx_v_dem_raster_path_band); + __Pyx_GIVEREF(__pyx_v_dem_raster_path_band); + PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_v_dem_raster_path_band); + __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 781, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 781, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_largest_block, __pyx_int_0) < 0) __PYX_ERR(0, 781, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":780 + * + * # this outer loop searches for a pixel that is locally undrained + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * dem_raster_path_band, offset_only=True, largest_block=0): + * win_xsize = offset_dict['win_xsize'] + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_15, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 780, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_17 = 0; + __pyx_t_18 = NULL; + } else { + __pyx_t_17 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 780, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_18 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 780, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (likely(!__pyx_t_18)) { + if (likely(PyList_CheckExact(__pyx_t_2))) { + if (__pyx_t_17 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_17); __Pyx_INCREF(__pyx_t_1); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 780, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 780, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } else { + if (__pyx_t_17 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_17); __Pyx_INCREF(__pyx_t_1); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 780, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 780, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } + } else { + __pyx_t_1 = __pyx_t_18(__pyx_t_2); + 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, 780, __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":782 + * for offset_dict in pygeoprocessing.iterblocks( + * dem_raster_path_band, 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_u_win_xsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 782, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 782, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_win_xsize = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":783 + * dem_raster_path_band, 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_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 783, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 783, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_win_ysize = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":784 + * 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_u_xoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 784, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 784, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_xoff = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":785 + * win_ysize = offset_dict['win_ysize'] + * xoff = offset_dict['xoff'] + * yoff = offset_dict['yoff'] # <<<<<<<<<<<<<< + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + */ + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_yoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 785, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 785, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_yoff = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":787 + * yoff = offset_dict['yoff'] + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + */ + __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":788 + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info( + */ + __pyx_v_last_log_time = time(NULL); + + /* "pygeoprocessing/routing/routing.pyx":789 + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size # <<<<<<<<<<<<<< + * LOGGER.info( + * '(fill pits): ' + */ + __pyx_v_current_pixel = (__pyx_v_xoff + (__pyx_v_yoff * __pyx_v_raster_x_size)); + + /* "pygeoprocessing/routing/routing.pyx":790 + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info( # <<<<<<<<<<<<<< + * '(fill pits): ' + * f'{current_pixel} of {raster_x_size * raster_y_size} ' + */ + __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 790, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_info); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 790, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":791 + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info( + * '(fill pits): ' # <<<<<<<<<<<<<< + * f'{current_pixel} of {raster_x_size * raster_y_size} ' + * 'pixels complete') + */ + __pyx_t_15 = PyTuple_New(5); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 791, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_19 = 0; + __pyx_t_20 = 127; + __Pyx_INCREF(__pyx_kp_u_fill_pits); + __pyx_t_19 += 13; + __Pyx_GIVEREF(__pyx_kp_u_fill_pits); + PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_kp_u_fill_pits); + + /* "pygeoprocessing/routing/routing.pyx":792 + * LOGGER.info( + * '(fill pits): ' + * f'{current_pixel} of {raster_x_size * raster_y_size} ' # <<<<<<<<<<<<<< + * 'pixels complete') + * + */ + __pyx_t_3 = __Pyx_PyUnicode_From_int(__pyx_v_current_pixel, 0, ' ', 'd'); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 792, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_19 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_3); + __pyx_t_3 = 0; + __Pyx_INCREF(__pyx_kp_u_of); + __pyx_t_19 += 4; + __Pyx_GIVEREF(__pyx_kp_u_of); + PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_kp_u_of); + __pyx_t_3 = __Pyx_PyUnicode_From_int((__pyx_v_raster_x_size * __pyx_v_raster_y_size), 0, ' ', 'd'); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 792, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_19 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_15, 3, __pyx_t_3); + __pyx_t_3 = 0; + __Pyx_INCREF(__pyx_kp_u_pixels_complete); + __pyx_t_19 += 16; + __Pyx_GIVEREF(__pyx_kp_u_pixels_complete); + PyTuple_SET_ITEM(__pyx_t_15, 4, __pyx_kp_u_pixels_complete); + + /* "pygeoprocessing/routing/routing.pyx":791 + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info( + * '(fill pits): ' # <<<<<<<<<<<<<< + * f'{current_pixel} of {raster_x_size * raster_y_size} ' + * 'pixels complete') + */ + __pyx_t_3 = __Pyx_PyUnicode_Join(__pyx_t_15, 5, __pyx_t_19, __pyx_t_20); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 791, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_15)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_15); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + } + } + __pyx_t_1 = (__pyx_t_15) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_15, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_t_3); + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 790, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":787 + * yoff = offset_dict['yoff'] + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + */ + } + + /* "pygeoprocessing/routing/routing.pyx":796 + * + * # search block for locally undrained pixels + * for yi in range(1, win_ysize+1): # <<<<<<<<<<<<<< + * yi_root = yi-1+yoff + * for xi in range(1, win_xsize+1): + */ + __pyx_t_21 = (__pyx_v_win_ysize + 1); + __pyx_t_22 = __pyx_t_21; + for (__pyx_t_10 = 1; __pyx_t_10 < __pyx_t_22; __pyx_t_10+=1) { + __pyx_v_yi = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":797 + * # search block for locally undrained pixels + * for yi in range(1, win_ysize+1): + * yi_root = yi-1+yoff # <<<<<<<<<<<<<< + * for xi in range(1, win_xsize+1): + * xi_root = xi-1+xoff + */ + __pyx_v_yi_root = ((__pyx_v_yi - 1) + __pyx_v_yoff); + + /* "pygeoprocessing/routing/routing.pyx":798 + * for yi in range(1, win_ysize+1): + * yi_root = yi-1+yoff + * for xi in range(1, win_xsize+1): # <<<<<<<<<<<<<< + * xi_root = xi-1+xoff + * # this value is set in case it turns out to be the root of a + */ + __pyx_t_23 = (__pyx_v_win_xsize + 1); + __pyx_t_24 = __pyx_t_23; + for (__pyx_t_9 = 1; __pyx_t_9 < __pyx_t_24; __pyx_t_9+=1) { + __pyx_v_xi = __pyx_t_9; + + /* "pygeoprocessing/routing/routing.pyx":799 + * yi_root = yi-1+yoff + * for xi in range(1, win_xsize+1): + * xi_root = xi-1+xoff # <<<<<<<<<<<<<< + * # this value is set in case it turns out to be the root of a + * # pit, we'll start the fill from this pixel in the last phase + */ + __pyx_v_xi_root = ((__pyx_v_xi - 1) + __pyx_v_xoff); + + /* "pygeoprocessing/routing/routing.pyx":803 + * # pit, we'll start the fill from this pixel in the last phase + * # of the algorithm + * center_val = filled_dem_managed_raster.get(xi_root, yi_root) # <<<<<<<<<<<<<< + * if _is_close(center_val, dem_nodata, 1e-8, 1e-5): + * continue + */ + __pyx_v_center_val = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_filled_dem_managed_raster, __pyx_v_xi_root, __pyx_v_yi_root); + + /* "pygeoprocessing/routing/routing.pyx":804 + * # of the algorithm + * center_val = filled_dem_managed_raster.get(xi_root, yi_root) + * if _is_close(center_val, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_center_val, __pyx_v_dem_nodata, 1e-8, 1e-5) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":805 + * center_val = filled_dem_managed_raster.get(xi_root, yi_root) + * if _is_close(center_val, dem_nodata, 1e-8, 1e-5): + * continue # <<<<<<<<<<<<<< + * + * if flat_region_mask_managed_raster.get( + */ + goto __pyx_L22_continue; + + /* "pygeoprocessing/routing/routing.pyx":804 + * # of the algorithm + * center_val = filled_dem_managed_raster.get(xi_root, yi_root) + * if _is_close(center_val, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * continue + * + */ + } + + /* "pygeoprocessing/routing/routing.pyx":808 + * + * if flat_region_mask_managed_raster.get( + * xi_root, yi_root) != mask_nodata: # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_5 = ((__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":807 + * continue + * + * if flat_region_mask_managed_raster.get( # <<<<<<<<<<<<<< + * xi_root, yi_root) != mask_nodata: + * continue + */ + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":809 + * if flat_region_mask_managed_raster.get( + * xi_root, yi_root) != mask_nodata: + * continue # <<<<<<<<<<<<<< + * + * # search neighbors for downhill or nodata + */ + goto __pyx_L22_continue; + + /* "pygeoprocessing/routing/routing.pyx":807 + * continue + * + * if flat_region_mask_managed_raster.get( # <<<<<<<<<<<<<< + * xi_root, yi_root) != mask_nodata: + * continue + */ + } + + /* "pygeoprocessing/routing/routing.pyx":812 + * + * # search neighbors for downhill or nodata + * downhill_neighbor = 0 # <<<<<<<<<<<<<< + * nodata_neighbor = 0 + * for i_n in range(8): + */ + __pyx_v_downhill_neighbor = 0; + + /* "pygeoprocessing/routing/routing.pyx":813 + * # search neighbors for downhill or nodata + * downhill_neighbor = 0 + * nodata_neighbor = 0 # <<<<<<<<<<<<<< + * for i_n in range(8): + * xi_n = xi_root+D8_XOFFSET[i_n] + */ + __pyx_v_nodata_neighbor = 0; + + /* "pygeoprocessing/routing/routing.pyx":814 + * downhill_neighbor = 0 + * nodata_neighbor = 0 + * for i_n in range(8): # <<<<<<<<<<<<<< + * xi_n = xi_root+D8_XOFFSET[i_n] + * yi_n = yi_root+D8_YOFFSET[i_n] + */ + for (__pyx_t_25 = 0; __pyx_t_25 < 8; __pyx_t_25+=1) { + __pyx_v_i_n = __pyx_t_25; + + /* "pygeoprocessing/routing/routing.pyx":815 + * nodata_neighbor = 0 + * for i_n in range(8): + * xi_n = xi_root+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< + * yi_n = yi_root+D8_YOFFSET[i_n] + * if (xi_n < 0 or xi_n >= raster_x_size or + */ + __pyx_v_xi_n = (__pyx_v_xi_root + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":816 + * for i_n in range(8): + * xi_n = xi_root+D8_XOFFSET[i_n] + * yi_n = yi_root+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< + * 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_D8_YOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":817 + * xi_n = xi_root+D8_XOFFSET[i_n] + * yi_n = yi_root+D8_YOFFSET[i_n] + * 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_6 = ((__pyx_v_xi_n < 0) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L29_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L29_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":818 + * yi_n = yi_root+D8_YOFFSET[i_n] + * 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_6 = ((__pyx_v_yi_n < 0) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L29_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0); + __pyx_t_5 = __pyx_t_6; + __pyx_L29_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":817 + * xi_n = xi_root+D8_XOFFSET[i_n] + * yi_n = yi_root+D8_YOFFSET[i_n] + * 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_5) { + + /* "pygeoprocessing/routing/routing.pyx":820 + * 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":821 + * # 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, 1e-8, 1e-5): + */ + goto __pyx_L27_break; + + /* "pygeoprocessing/routing/routing.pyx":817 + * xi_n = xi_root+D8_XOFFSET[i_n] + * yi_n = yi_root+D8_YOFFSET[i_n] + * 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":822 + * nodata_neighbor = 1 + * break + * n_height = filled_dem_managed_raster.get(xi_n, yi_n) # <<<<<<<<<<<<<< + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): + * # 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":823 + * break + * n_height = filled_dem_managed_raster.get(xi_n, yi_n) + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * # it'll drain to nodata + * nodata_neighbor = 1 + */ + __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_n_height, __pyx_v_dem_nodata, 1e-8, 1e-5) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":825 + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): + * # it'll drain to nodata + * nodata_neighbor = 1 # <<<<<<<<<<<<<< + * break + * if n_height < center_val: + */ + __pyx_v_nodata_neighbor = 1; + + /* "pygeoprocessing/routing/routing.pyx":826 + * # 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":823 + * break + * n_height = filled_dem_managed_raster.get(xi_n, yi_n) + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * # it'll drain to nodata + * nodata_neighbor = 1 + */ + } + + /* "pygeoprocessing/routing/routing.pyx":827 + * nodata_neighbor = 1 + * break + * if n_height < center_val: # <<<<<<<<<<<<<< + * # it'll drain downhill + * downhill_neighbor = 1 + */ + __pyx_t_5 = ((__pyx_v_n_height < __pyx_v_center_val) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":829 + * if n_height < center_val: + * # it'll drain downhill + * downhill_neighbor = 1 # <<<<<<<<<<<<<< + * break + * + */ + __pyx_v_downhill_neighbor = 1; + + /* "pygeoprocessing/routing/routing.pyx":830 + * # it'll drain downhill + * downhill_neighbor = 1 + * break # <<<<<<<<<<<<<< + * + * if downhill_neighbor or nodata_neighbor: + */ + goto __pyx_L27_break; + + /* "pygeoprocessing/routing/routing.pyx":827 + * nodata_neighbor = 1 + * break + * if n_height < center_val: # <<<<<<<<<<<<<< + * # it'll drain downhill + * downhill_neighbor = 1 + */ + } + } + __pyx_L27_break:; + + /* "pygeoprocessing/routing/routing.pyx":832 + * break + * + * if downhill_neighbor or nodata_neighbor: # <<<<<<<<<<<<<< + * # it drains, so skip + * continue + */ + __pyx_t_6 = (__pyx_v_downhill_neighbor != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L36_bool_binop_done; + } + __pyx_t_6 = (__pyx_v_nodata_neighbor != 0); + __pyx_t_5 = __pyx_t_6; + __pyx_L36_bool_binop_done:; + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":834 + * 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":832 + * break + * + * if downhill_neighbor or nodata_neighbor: # <<<<<<<<<<<<<< + * # it drains, so skip + * continue + */ + } + + /* "pygeoprocessing/routing/routing.pyx":838 + * # 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) + * natural_drain_exists = 0 + */ + __pyx_t_26.xi = __pyx_v_xi_root; + __pyx_t_26.yi = __pyx_v_yi_root; + __pyx_v_search_queue.push(__pyx_t_26); + + /* "pygeoprocessing/routing/routing.pyx":839 + * # 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) # <<<<<<<<<<<<<< + * natural_drain_exists = 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":840 + * search_queue.push(CoordinateType(xi_root, yi_root)) + * flat_region_mask_managed_raster.set(xi_root, yi_root, 1) + * natural_drain_exists = 0 # <<<<<<<<<<<<<< + * + * # this loop does a BFS starting at this pixel to all pixels + */ + __pyx_v_natural_drain_exists = 0; + + /* "pygeoprocessing/routing/routing.pyx":848 + * # it can be entirely marked as processed and not re-accessed + * # on later iterations + * search_steps = 0 # <<<<<<<<<<<<<< + * while not search_queue.empty(): + * xi_q = search_queue.front().xi + */ + __pyx_v_search_steps = 0; + + /* "pygeoprocessing/routing/routing.pyx":849 + * # on later iterations + * search_steps = 0 + * while not search_queue.empty(): # <<<<<<<<<<<<<< + * xi_q = search_queue.front().xi + * yi_q = search_queue.front().yi + */ + while (1) { + __pyx_t_5 = ((!(__pyx_v_search_queue.empty() != 0)) != 0); + if (!__pyx_t_5) break; + + /* "pygeoprocessing/routing/routing.pyx":850 + * search_steps = 0 + * while not search_queue.empty(): + * xi_q = search_queue.front().xi # <<<<<<<<<<<<<< + * yi_q = search_queue.front().yi + * search_queue.pop() + */ + __pyx_t_25 = __pyx_v_search_queue.front().xi; + __pyx_v_xi_q = __pyx_t_25; + + /* "pygeoprocessing/routing/routing.pyx":851 + * while not search_queue.empty(): + * xi_q = search_queue.front().xi + * yi_q = search_queue.front().yi # <<<<<<<<<<<<<< + * search_queue.pop() + * if search_steps > max_pixel_fill_count: + */ + __pyx_t_25 = __pyx_v_search_queue.front().yi; + __pyx_v_yi_q = __pyx_t_25; + + /* "pygeoprocessing/routing/routing.pyx":852 + * xi_q = search_queue.front().xi + * yi_q = search_queue.front().yi + * search_queue.pop() # <<<<<<<<<<<<<< + * if search_steps > max_pixel_fill_count: + * # clear the search queue and quit + */ + __pyx_v_search_queue.pop(); + + /* "pygeoprocessing/routing/routing.pyx":853 + * yi_q = search_queue.front().yi + * search_queue.pop() + * if search_steps > max_pixel_fill_count: # <<<<<<<<<<<<<< + * # clear the search queue and quit + * while not search_queue.empty(): + */ + __pyx_t_5 = ((__pyx_v_search_steps > __pyx_v_max_pixel_fill_count) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":855 + * if search_steps > max_pixel_fill_count: + * # clear the search queue and quit + * while not search_queue.empty(): # <<<<<<<<<<<<<< + * search_queue.pop() + * natural_drain_exists = 1 + */ + while (1) { + __pyx_t_5 = ((!(__pyx_v_search_queue.empty() != 0)) != 0); + if (!__pyx_t_5) break; + + /* "pygeoprocessing/routing/routing.pyx":856 + * # clear the search queue and quit + * while not search_queue.empty(): + * search_queue.pop() # <<<<<<<<<<<<<< + * natural_drain_exists = 1 + * break + */ + __pyx_v_search_queue.pop(); + } + + /* "pygeoprocessing/routing/routing.pyx":857 + * while not search_queue.empty(): + * search_queue.pop() + * natural_drain_exists = 1 # <<<<<<<<<<<<<< + * break + * search_steps += 1 + */ + __pyx_v_natural_drain_exists = 1; + + /* "pygeoprocessing/routing/routing.pyx":858 + * search_queue.pop() + * natural_drain_exists = 1 + * break # <<<<<<<<<<<<<< + * search_steps += 1 + * + */ + goto __pyx_L39_break; + + /* "pygeoprocessing/routing/routing.pyx":853 + * yi_q = search_queue.front().yi + * search_queue.pop() + * if search_steps > max_pixel_fill_count: # <<<<<<<<<<<<<< + * # clear the search queue and quit + * while not search_queue.empty(): + */ + } + + /* "pygeoprocessing/routing/routing.pyx":859 + * natural_drain_exists = 1 + * break + * search_steps += 1 # <<<<<<<<<<<<<< + * + * for i_n in range(8): + */ + __pyx_v_search_steps = (__pyx_v_search_steps + 1); + + /* "pygeoprocessing/routing/routing.pyx":861 + * search_steps += 1 + * + * for i_n in range(8): # <<<<<<<<<<<<<< + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] + */ + for (__pyx_t_25 = 0; __pyx_t_25 < 8; __pyx_t_25+=1) { + __pyx_v_i_n = __pyx_t_25; + + /* "pygeoprocessing/routing/routing.pyx":862 + * + * for i_n in range(8): + * xi_n = xi_q+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< + * yi_n = yi_q+D8_YOFFSET[i_n] + * if (xi_n < 0 or xi_n >= raster_x_size or + */ + __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":863 + * for i_n in range(8): + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< + * 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_D8_YOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":864 + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] + * if (xi_n < 0 or xi_n >= raster_x_size or # <<<<<<<<<<<<<< + * yi_n < 0 or yi_n >= raster_y_size): + * natural_drain_exists = 1 + */ + __pyx_t_6 = ((__pyx_v_xi_n < 0) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L46_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L46_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":865 + * yi_n = yi_q+D8_YOFFSET[i_n] + * if (xi_n < 0 or xi_n >= raster_x_size or + * yi_n < 0 or yi_n >= raster_y_size): # <<<<<<<<<<<<<< + * natural_drain_exists = 1 + * continue + */ + __pyx_t_6 = ((__pyx_v_yi_n < 0) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L46_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0); + __pyx_t_5 = __pyx_t_6; + __pyx_L46_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":864 + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] + * if (xi_n < 0 or xi_n >= raster_x_size or # <<<<<<<<<<<<<< + * yi_n < 0 or yi_n >= raster_y_size): + * natural_drain_exists = 1 + */ + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":866 + * if (xi_n < 0 or xi_n >= raster_x_size or + * yi_n < 0 or yi_n >= raster_y_size): + * natural_drain_exists = 1 # <<<<<<<<<<<<<< + * continue + * n_height = filled_dem_managed_raster.get( + */ + __pyx_v_natural_drain_exists = 1; + + /* "pygeoprocessing/routing/routing.pyx":867 + * yi_n < 0 or yi_n >= raster_y_size): + * natural_drain_exists = 1 + * continue # <<<<<<<<<<<<<< + * n_height = filled_dem_managed_raster.get( + * xi_n, yi_n) + */ + goto __pyx_L43_continue; + + /* "pygeoprocessing/routing/routing.pyx":864 + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] + * if (xi_n < 0 or xi_n >= raster_x_size or # <<<<<<<<<<<<<< + * yi_n < 0 or yi_n >= raster_y_size): + * natural_drain_exists = 1 + */ + } + + /* "pygeoprocessing/routing/routing.pyx":868 + * natural_drain_exists = 1 + * continue + * n_height = filled_dem_managed_raster.get( # <<<<<<<<<<<<<< + * xi_n, yi_n) + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): + */ + __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":870 + * n_height = filled_dem_managed_raster.get( + * xi_n, yi_n) + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * natural_drain_exists = 1 + * continue + */ + __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_n_height, __pyx_v_dem_nodata, 1e-8, 1e-5) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":871 + * xi_n, yi_n) + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): + * natural_drain_exists = 1 # <<<<<<<<<<<<<< + * continue + * if n_height < center_val: + */ + __pyx_v_natural_drain_exists = 1; + + /* "pygeoprocessing/routing/routing.pyx":872 + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): + * natural_drain_exists = 1 + * continue # <<<<<<<<<<<<<< + * if n_height < center_val: + * natural_drain_exists = 1 + */ + goto __pyx_L43_continue; + + /* "pygeoprocessing/routing/routing.pyx":870 + * n_height = filled_dem_managed_raster.get( + * xi_n, yi_n) + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * natural_drain_exists = 1 + * continue + */ + } + + /* "pygeoprocessing/routing/routing.pyx":873 + * natural_drain_exists = 1 + * continue + * if n_height < center_val: # <<<<<<<<<<<<<< + * natural_drain_exists = 1 + * continue + */ + __pyx_t_5 = ((__pyx_v_n_height < __pyx_v_center_val) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":874 + * continue + * if n_height < center_val: + * natural_drain_exists = 1 # <<<<<<<<<<<<<< + * continue + * if flat_region_mask_managed_raster.get( + */ + __pyx_v_natural_drain_exists = 1; + + /* "pygeoprocessing/routing/routing.pyx":875 + * if n_height < center_val: + * natural_drain_exists = 1 + * continue # <<<<<<<<<<<<<< + * if flat_region_mask_managed_raster.get( + * xi_n, yi_n) == 1: + */ + goto __pyx_L43_continue; + + /* "pygeoprocessing/routing/routing.pyx":873 + * natural_drain_exists = 1 + * continue + * if n_height < center_val: # <<<<<<<<<<<<<< + * natural_drain_exists = 1 + * continue + */ + } + + /* "pygeoprocessing/routing/routing.pyx":877 + * continue + * if flat_region_mask_managed_raster.get( + * xi_n, yi_n) == 1: # <<<<<<<<<<<<<< + * # been set before on a previous iteration, skip + * continue + */ + __pyx_t_5 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flat_region_mask_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n) == 1.0) != 0); + + /* "pygeoprocessing/routing/routing.pyx":876 + * natural_drain_exists = 1 + * continue + * if flat_region_mask_managed_raster.get( # <<<<<<<<<<<<<< + * xi_n, yi_n) == 1: + * # been set before on a previous iteration, skip + */ + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":879 + * xi_n, yi_n) == 1: + * # been set before on a previous iteration, skip + * continue # <<<<<<<<<<<<<< + * if n_height == center_val: + * # only grow if it's at the same level and not + */ + goto __pyx_L43_continue; + + /* "pygeoprocessing/routing/routing.pyx":876 + * natural_drain_exists = 1 + * continue + * if flat_region_mask_managed_raster.get( # <<<<<<<<<<<<<< + * xi_n, yi_n) == 1: + * # been set before on a previous iteration, skip + */ + } + + /* "pygeoprocessing/routing/routing.pyx":880 + * # been set before on a previous iteration, skip + * continue + * if n_height == center_val: # <<<<<<<<<<<<<< + * # only grow if it's at the same level and not + * # previously visited + */ + __pyx_t_5 = ((__pyx_v_n_height == __pyx_v_center_val) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":884 + * # previously visited + * search_queue.push( + * CoordinateType(xi_n, yi_n)) # <<<<<<<<<<<<<< + * flat_region_mask_managed_raster.set( + * xi_n, yi_n, 1) + */ + __pyx_t_26.xi = __pyx_v_xi_n; + __pyx_t_26.yi = __pyx_v_yi_n; + + /* "pygeoprocessing/routing/routing.pyx":883 + * # 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_26); + + /* "pygeoprocessing/routing/routing.pyx":885 + * 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":880 + * # been set before on a previous iteration, skip + * continue + * if n_height == center_val: # <<<<<<<<<<<<<< + * # only grow if it's at the same level and not + * # previously visited + */ + } + __pyx_L43_continue:; + } + } + __pyx_L39_break:; + + /* "pygeoprocessing/routing/routing.pyx":888 + * xi_n, yi_n, 1) + * + * if not natural_drain_exists: # <<<<<<<<<<<<<< + * # this space does not naturally drain, so fill it + * pixel = PixelType( + */ + __pyx_t_5 = ((!(__pyx_v_natural_drain_exists != 0)) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":891 + * # this space does not naturally drain, so fill it + * pixel = PixelType( + * center_val, xi_root, yi_root, ( # <<<<<<<<<<<<<< + * n_x_blocks * (yi_root >> BLOCK_BITS) + + * xi_root >> BLOCK_BITS)) + */ + __pyx_t_27.value = __pyx_v_center_val; + __pyx_t_27.xi = __pyx_v_xi_root; + __pyx_t_27.yi = __pyx_v_yi_root; + + /* "pygeoprocessing/routing/routing.pyx":893 + * 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_27.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_27; + + /* "pygeoprocessing/routing/routing.pyx":894 + * 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":895 + * 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":897 + * 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":888 + * xi_n, yi_n, 1) + * + * if not natural_drain_exists: # <<<<<<<<<<<<<< + * # this space does not naturally drain, so fill it + * pixel = PixelType( + */ + } + + /* "pygeoprocessing/routing/routing.pyx":902 + * # first non-processed pixel that's < pixel.height or nodata + * # will be the lowest pour point + * pour_point = 0 # <<<<<<<<<<<<<< + * fill_height = dem_nodata + * search_steps = 0 + */ + __pyx_v_pour_point = 0; + + /* "pygeoprocessing/routing/routing.pyx":903 + * # will be the lowest pour point + * pour_point = 0 + * fill_height = dem_nodata # <<<<<<<<<<<<<< + * search_steps = 0 + * while not pit_queue.empty(): + */ + __pyx_v_fill_height = __pyx_v_dem_nodata; + + /* "pygeoprocessing/routing/routing.pyx":904 + * pour_point = 0 + * fill_height = dem_nodata + * search_steps = 0 # <<<<<<<<<<<<<< + * while not pit_queue.empty(): + * pixel = pit_queue.top() + */ + __pyx_v_search_steps = 0; + + /* "pygeoprocessing/routing/routing.pyx":905 + * fill_height = dem_nodata + * search_steps = 0 + * while not pit_queue.empty(): # <<<<<<<<<<<<<< + * pixel = pit_queue.top() + * pit_queue.pop() + */ + while (1) { + __pyx_t_5 = ((!(__pyx_v_pit_queue.empty() != 0)) != 0); + if (!__pyx_t_5) break; + + /* "pygeoprocessing/routing/routing.pyx":906 + * search_steps = 0 + * 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":907 + * 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":908 + * pixel = pit_queue.top() + * pit_queue.pop() + * xi_q = pixel.xi # <<<<<<<<<<<<<< + * yi_q = pixel.yi + * + */ + __pyx_t_25 = __pyx_v_pixel.xi; + __pyx_v_xi_q = __pyx_t_25; + + /* "pygeoprocessing/routing/routing.pyx":909 + * pit_queue.pop() + * xi_q = pixel.xi + * yi_q = pixel.yi # <<<<<<<<<<<<<< + * + * # search to see if the fill has gone on too long + */ + __pyx_t_25 = __pyx_v_pixel.yi; + __pyx_v_yi_q = __pyx_t_25; + + /* "pygeoprocessing/routing/routing.pyx":912 + * + * # search to see if the fill has gone on too long + * if search_steps > max_pixel_fill_count: # <<<<<<<<<<<<<< + * # clear pit_queue and quit + * pit_queue = PitPriorityQueueType() + */ + __pyx_t_5 = ((__pyx_v_search_steps > __pyx_v_max_pixel_fill_count) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":914 + * if search_steps > max_pixel_fill_count: + * # clear pit_queue and quit + * pit_queue = PitPriorityQueueType() # <<<<<<<<<<<<<< + * natural_drain_exists = 1 + * break + */ + try { + __pyx_t_28 = __pyx_t_15pygeoprocessing_7routing_7routing_PitPriorityQueueType(); + } catch(...) { + __Pyx_CppExn2PyErr(); + __PYX_ERR(0, 914, __pyx_L1_error) + } + __pyx_v_pit_queue = __pyx_t_28; + + /* "pygeoprocessing/routing/routing.pyx":915 + * # clear pit_queue and quit + * pit_queue = PitPriorityQueueType() + * natural_drain_exists = 1 # <<<<<<<<<<<<<< + * break + * search_steps += 1 + */ + __pyx_v_natural_drain_exists = 1; + + /* "pygeoprocessing/routing/routing.pyx":916 + * pit_queue = PitPriorityQueueType() + * natural_drain_exists = 1 + * break # <<<<<<<<<<<<<< + * search_steps += 1 + * + */ + goto __pyx_L56_break; + + /* "pygeoprocessing/routing/routing.pyx":912 + * + * # search to see if the fill has gone on too long + * if search_steps > max_pixel_fill_count: # <<<<<<<<<<<<<< + * # clear pit_queue and quit + * pit_queue = PitPriorityQueueType() + */ + } + + /* "pygeoprocessing/routing/routing.pyx":917 + * natural_drain_exists = 1 + * break + * search_steps += 1 # <<<<<<<<<<<<<< + * + * # this is the potential fill height if pixel is pour point + */ + __pyx_v_search_steps = (__pyx_v_search_steps + 1); + + /* "pygeoprocessing/routing/routing.pyx":920 + * + * # this is the potential fill height if pixel is pour point + * fill_height = pixel.value # <<<<<<<<<<<<<< + * + * for i_n in range(8): + */ + __pyx_t_7 = __pyx_v_pixel.value; + __pyx_v_fill_height = __pyx_t_7; + + /* "pygeoprocessing/routing/routing.pyx":922 + * fill_height = pixel.value + * + * for i_n in range(8): # <<<<<<<<<<<<<< + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] + */ + for (__pyx_t_25 = 0; __pyx_t_25 < 8; __pyx_t_25+=1) { + __pyx_v_i_n = __pyx_t_25; + + /* "pygeoprocessing/routing/routing.pyx":923 + * + * for i_n in range(8): + * xi_n = xi_q+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< + * yi_n = yi_q+D8_YOFFSET[i_n] + * if (xi_n < 0 or xi_n >= raster_x_size or + */ + __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":924 + * for i_n in range(8): + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< + * 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_D8_YOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":925 + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] + * 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_6 = ((__pyx_v_xi_n < 0) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L61_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L61_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":926 + * yi_n = yi_q+D8_YOFFSET[i_n] + * 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_6 = ((__pyx_v_yi_n < 0) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L61_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0); + __pyx_t_5 = __pyx_t_6; + __pyx_L61_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":925 + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] + * 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_5) { + + /* "pygeoprocessing/routing/routing.pyx":928 + * 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":929 + * # drain off the edge of the raster + * pour_point = 1 + * break # <<<<<<<<<<<<<< + * + * if pit_mask_managed_raster.get( + */ + goto __pyx_L59_break; + + /* "pygeoprocessing/routing/routing.pyx":925 + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] + * 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":932 + * + * if pit_mask_managed_raster.get( + * xi_n, yi_n) == feature_id: # <<<<<<<<<<<<<< + * # this cell has already been processed + * continue + */ + __pyx_t_5 = ((__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":931 + * break + * + * if pit_mask_managed_raster.get( # <<<<<<<<<<<<<< + * xi_n, yi_n) == feature_id: + * # this cell has already been processed + */ + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":934 + * xi_n, yi_n) == feature_id: + * # this cell has already been processed + * continue # <<<<<<<<<<<<<< + * + * # mark as visited in the search for pour point + */ + goto __pyx_L58_continue; + + /* "pygeoprocessing/routing/routing.pyx":931 + * break + * + * if pit_mask_managed_raster.get( # <<<<<<<<<<<<<< + * xi_n, yi_n) == feature_id: + * # this cell has already been processed + */ + } + + /* "pygeoprocessing/routing/routing.pyx":937 + * + * # mark as visited in the search for pour point + * pit_mask_managed_raster.set(xi_n, yi_n, feature_id) # <<<<<<<<<<<<<< + * + * n_height = filled_dem_managed_raster.get(xi_n, yi_n) + */ + __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":939 + * pit_mask_managed_raster.set(xi_n, yi_n, feature_id) + * + * n_height = filled_dem_managed_raster.get(xi_n, yi_n) # <<<<<<<<<<<<<< + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5) 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":940 + * + * n_height = filled_dem_managed_raster.get(xi_n, yi_n) + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5) or ( # <<<<<<<<<<<<<< + * n_height < fill_height): + * # we encounter a neighbor not processed that is + */ + __pyx_t_6 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_n_height, __pyx_v_dem_nodata, 1e-8, 1e-5) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L67_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":941 + * n_height = filled_dem_managed_raster.get(xi_n, yi_n) + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5) or ( + * n_height < fill_height): # <<<<<<<<<<<<<< + * # we encounter a neighbor not processed that is + * # lower than the current pixel or nodata + */ + __pyx_t_6 = ((__pyx_v_n_height < __pyx_v_fill_height) != 0); + __pyx_t_5 = __pyx_t_6; + __pyx_L67_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":940 + * + * n_height = filled_dem_managed_raster.get(xi_n, yi_n) + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5) or ( # <<<<<<<<<<<<<< + * n_height < fill_height): + * # we encounter a neighbor not processed that is + */ + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":944 + * # 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":945 + * # lower than the current pixel or nodata + * pour_point = 1 + * break # <<<<<<<<<<<<<< + * + * # push onto queue, set the priority to be the block + */ + goto __pyx_L59_break; + + /* "pygeoprocessing/routing/routing.pyx":940 + * + * n_height = filled_dem_managed_raster.get(xi_n, yi_n) + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5) or ( # <<<<<<<<<<<<<< + * n_height < fill_height): + * # we encounter a neighbor not processed that is + */ + } + + /* "pygeoprocessing/routing/routing.pyx":950 + * # index + * pixel = PixelType( + * n_height, xi_n, yi_n, ( # <<<<<<<<<<<<<< + * n_x_blocks * (yi_n >> BLOCK_BITS) + + * xi_n >> BLOCK_BITS)) + */ + __pyx_t_27.value = __pyx_v_n_height; + __pyx_t_27.xi = __pyx_v_xi_n; + __pyx_t_27.yi = __pyx_v_yi_n; + + /* "pygeoprocessing/routing/routing.pyx":952 + * n_height, xi_n, yi_n, ( + * n_x_blocks * (yi_n >> BLOCK_BITS) + + * xi_n >> BLOCK_BITS)) # <<<<<<<<<<<<<< + * pit_queue.push(pixel) + * + */ + __pyx_t_27.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_27; + + /* "pygeoprocessing/routing/routing.pyx":953 + * 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_L58_continue:; + } + __pyx_L59_break:; + + /* "pygeoprocessing/routing/routing.pyx":955 + * pit_queue.push(pixel) + * + * if pour_point: # <<<<<<<<<<<<<< + * # found a pour point, clear the queue + * pit_queue = PitPriorityQueueType() + */ + __pyx_t_5 = (__pyx_v_pour_point != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":957 + * 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_28 = __pyx_t_15pygeoprocessing_7routing_7routing_PitPriorityQueueType(); + } catch(...) { + __Pyx_CppExn2PyErr(); + __PYX_ERR(0, 957, __pyx_L1_error) + } + __pyx_v_pit_queue = __pyx_t_28; + + /* "pygeoprocessing/routing/routing.pyx":965 + * # 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_26.xi = __pyx_v_xi_root; + __pyx_t_26.yi = __pyx_v_yi_root; + __pyx_v_fill_queue.push(__pyx_t_26); + + /* "pygeoprocessing/routing/routing.pyx":966 + * # 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":955 + * pit_queue.push(pixel) + * + * if pour_point: # <<<<<<<<<<<<<< + * # found a pour point, clear the queue + * pit_queue = PitPriorityQueueType() + */ + } + } + __pyx_L56_break:; + + /* "pygeoprocessing/routing/routing.pyx":970 + * + * # 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_5 = ((!(__pyx_v_fill_queue.empty() != 0)) != 0); + if (!__pyx_t_5) break; + + /* "pygeoprocessing/routing/routing.pyx":971 + * # 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_25 = __pyx_v_fill_queue.front().xi; + __pyx_v_xi_q = __pyx_t_25; + + /* "pygeoprocessing/routing/routing.pyx":972 + * while not fill_queue.empty(): + * xi_q = fill_queue.front().xi + * yi_q = fill_queue.front().yi # <<<<<<<<<<<<<< + * fill_queue.pop() + * + */ + __pyx_t_25 = __pyx_v_fill_queue.front().yi; + __pyx_v_yi_q = __pyx_t_25; + + /* "pygeoprocessing/routing/routing.pyx":973 + * 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":975 + * fill_queue.pop() + * + * for i_n in range(8): # <<<<<<<<<<<<<< + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] + */ + for (__pyx_t_25 = 0; __pyx_t_25 < 8; __pyx_t_25+=1) { + __pyx_v_i_n = __pyx_t_25; + + /* "pygeoprocessing/routing/routing.pyx":976 + * + * for i_n in range(8): + * xi_n = xi_q+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< + * yi_n = yi_q+D8_YOFFSET[i_n] + * if (xi_n < 0 or xi_n >= raster_x_size or + */ + __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":977 + * for i_n in range(8): + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< + * 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_D8_YOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":978 + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] + * if (xi_n < 0 or xi_n >= raster_x_size or # <<<<<<<<<<<<<< + * yi_n < 0 or yi_n >= raster_y_size): + * continue + */ + __pyx_t_6 = ((__pyx_v_xi_n < 0) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L75_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L75_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":979 + * yi_n = yi_q+D8_YOFFSET[i_n] + * if (xi_n < 0 or xi_n >= raster_x_size or + * yi_n < 0 or yi_n >= raster_y_size): # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_6 = ((__pyx_v_yi_n < 0) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L75_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0); + __pyx_t_5 = __pyx_t_6; + __pyx_L75_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":978 + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] + * 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":980 + * 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_L72_continue; + + /* "pygeoprocessing/routing/routing.pyx":978 + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] + * 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":983 + * + * 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_5 = ((__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":982 + * continue + * + * if filled_dem_managed_raster.get( # <<<<<<<<<<<<<< + * xi_n, yi_n) < fill_height: + * filled_dem_managed_raster.set( + */ + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":984 + * 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":986 + * 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_26.xi = __pyx_v_xi_n; + __pyx_t_26.yi = __pyx_v_yi_n; + __pyx_v_fill_queue.push(__pyx_t_26); + + /* "pygeoprocessing/routing/routing.pyx":982 + * continue + * + * if filled_dem_managed_raster.get( # <<<<<<<<<<<<<< + * xi_n, yi_n) < fill_height: + * filled_dem_managed_raster.set( + */ + } + __pyx_L72_continue:; + } + } + __pyx_L22_continue:; + } + } + + /* "pygeoprocessing/routing/routing.pyx":780 + * + * # this outer loop searches for a pixel that is locally undrained + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * dem_raster_path_band, offset_only=True, largest_block=0): + * win_xsize = offset_dict['win_xsize'] + */ + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":988 + * 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, 988, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_14 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_14)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_2 = (__pyx_t_14) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_14) : __Pyx_PyObject_CallNoArg(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 988, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":989 + * + * pit_mask_managed_raster.close() + * flat_region_mask_managed_raster.close() # <<<<<<<<<<<<<< + * shutil.rmtree(working_dir_path) + * LOGGER.info('(fill pits): complete') + */ + __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, 989, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_14 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_14)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_2 = (__pyx_t_14) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_14) : __Pyx_PyObject_CallNoArg(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 989, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":990 + * pit_mask_managed_raster.close() + * flat_region_mask_managed_raster.close() + * shutil.rmtree(working_dir_path) # <<<<<<<<<<<<<< + * LOGGER.info('(fill pits): complete') + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_shutil); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 990, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_rmtree); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 990, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + } + } + __pyx_t_2 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_1, __pyx_v_working_dir_path) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_v_working_dir_path); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 990, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":991 + * flat_region_mask_managed_raster.close() + * shutil.rmtree(working_dir_path) + * LOGGER.info('(fill pits): complete') # <<<<<<<<<<<<<< + * + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 991, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 991, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_14 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_14)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_2 = (__pyx_t_14) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_14, __pyx_kp_u_fill_pits_complete) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_kp_u_fill_pits_complete); + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 991, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":612 + * + * + * def fill_pits( # <<<<<<<<<<<<<< + * dem_raster_path_band, target_filled_dem_raster_path, + * working_dir=None, long max_pixel_fill_count=_MAX_PIXEL_FILL_COUNT, + */ + + /* 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_14); + __Pyx_XDECREF(__pyx_t_15); + __Pyx_XDECREF(__pyx_t_16); + __Pyx_AddTraceback("pygeoprocessing.routing.routing.fill_pits", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __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_base_datatype); + __Pyx_XDECREF(__pyx_v_filled_dem_raster); + __Pyx_XDECREF(__pyx_v_filled_dem_band); + __Pyx_XDECREF(__pyx_v_offset_info); + __Pyx_XDECREF(__pyx_v_block_array); + __Pyx_XDECREF((PyObject *)__pyx_v_filled_dem_managed_raster); + __Pyx_XDECREF(__pyx_v_offset_dict); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pygeoprocessing/routing/routing.pyx":994 + * + * + * 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 (str): 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 3 2 1\n 4 x 0\n 5 6 7\n\n working_dir (str): 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 raster_driver_creation_tuple (tuple): a tuple containing a GDAL driver\n name string as the first element and a GDAL creation options\n tuple/list as the second. Defaults to a GTiff driver tuple\n defined at geoprocessing.DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS.\n\n Returns:\n None.\n "; +static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_5flow_dir_d8 = {"flow_dir_d8", (PyCFunction)(void*)(PyCFunctionWithKeywords)__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_raster_driver_creation_tuple = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 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_raster_driver_creation_tuple,0}; + PyObject* values[4] = {0,0,0,0}; + + /* "pygeoprocessing/routing/routing.pyx":996 + * def flow_dir_d8( + * dem_raster_path_band, target_flow_dir_path, + * working_dir=None, # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): + * """D8 flow direction. + */ + values[2] = ((PyObject *)Py_None); + values[3] = __pyx_k__6; + 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, 994, __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_raster_driver_creation_tuple); + 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, 994, __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_raster_driver_creation_tuple = 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, 994, __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_raster_driver_creation_tuple); + + /* "pygeoprocessing/routing/routing.pyx":994 + * + * + * 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_raster_driver_creation_tuple) { + 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 __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 __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_raster_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; + int __pyx_v_current_pixel; + 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; + int __pyx_t_5; + int __pyx_t_6; + double __pyx_t_7; + PyObject *(*__pyx_t_8)(PyObject *); + int __pyx_t_9; + int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + 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 *); + Py_ssize_t __pyx_t_19; + Py_UCS4 __pyx_t_20; + PyArrayObject *__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; + 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __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":1070 + * # 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":1074 + * # 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1074, __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, 1074, __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, 1074, __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); + } + } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1074, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __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":1075 + * # 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_u_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1075, __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, 1075, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_t_3, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1075, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1075, __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_v_base_nodata = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1076 + * 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_5 = (__pyx_v_base_nodata != Py_None); + __pyx_t_6 = (__pyx_t_5 != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/routing/routing.pyx":1078 + * 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1078, __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, 1078, __pyx_L1_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); + } + } + __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_v_base_nodata) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_base_nodata); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1078, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_7 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 1078, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_dem_nodata = __pyx_t_7; + + /* "pygeoprocessing/routing/routing.pyx":1076 + * 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":1081 + * 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":1084 + * + * # 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_u_raster_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1084, __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, 1084, __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, 1084, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1084, __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_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1084, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_4)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_8(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + 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, 1084, __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, 1084, __pyx_L1_error) + __pyx_L5_unpacking_done:; + } + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1084, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1084, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_raster_x_size = __pyx_t_9; + __pyx_v_raster_y_size = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":1087 + * + * # 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":1090 + * + * # 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_11, &__pyx_t_12, &__pyx_t_13); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_13); + /*try:*/ { + + /* "pygeoprocessing/routing/routing.pyx":1091 + * # set up the working dir for the mask rasters + * try: + * if working_dir is not None: # <<<<<<<<<<<<<< + * os.makedirs(working_dir) + * except OSError: + */ + __pyx_t_6 = (__pyx_v_working_dir != Py_None); + __pyx_t_5 = (__pyx_t_6 != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1092 + * try: + * if working_dir is not None: + * os.makedirs(working_dir) # <<<<<<<<<<<<<< + * except OSError: + * pass + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1092, __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, 1092, __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); + } + } + __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_v_working_dir) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_working_dir); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1092, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1091 + * # 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":1090 + * + * # set up the working dir for the mask rasters + * try: # <<<<<<<<<<<<<< + * if working_dir is not None: + * os.makedirs(working_dir) + */ + } + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + goto __pyx_L11_try_end; + __pyx_L6_error:; + __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; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1093 + * if working_dir is not None: + * os.makedirs(working_dir) + * except OSError: # <<<<<<<<<<<<<< + * pass + * working_dir_path = tempfile.mkdtemp( + */ + __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OSError); + if (__pyx_t_10) { + __Pyx_ErrRestore(0,0,0); + goto __pyx_L7_exception_handled; + } + goto __pyx_L8_except_error; + __pyx_L8_except_error:; + + /* "pygeoprocessing/routing/routing.pyx":1090 + * + * # set up the working dir for the mask rasters + * try: # <<<<<<<<<<<<<< + * if working_dir is not None: + * os.makedirs(working_dir) + */ + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_13); + __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13); + goto __pyx_L1_error; + __pyx_L7_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_13); + __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13); + __pyx_L11_try_end:; + } + + /* "pygeoprocessing/routing/routing.pyx":1095 + * 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_tempfile); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1095, __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, 1095, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1096 + * 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, 1096, __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, 1096, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_time); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1096, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_strftime); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1096, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1097 + * 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_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_time); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1097, __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, 1097, __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); + } + } + __pyx_t_4 = (__pyx_t_15) ? __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_t_15) : __Pyx_PyObject_CallNoArg(__pyx_t_16); + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1097, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __pyx_t_16 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_16)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_16); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + __pyx_t_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_kp_u_Y_m_d__H__M__S, __pyx_t_4}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1096, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 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_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_kp_u_Y_m_d__H__M__S, __pyx_t_4}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1096, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_15 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1096, __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_u_Y_m_d__H__M__S); + __Pyx_GIVEREF(__pyx_kp_u_Y_m_d__H__M__S); + PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_10, __pyx_kp_u_Y_m_d__H__M__S); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_10, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_15, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1096, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1096 + * 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_14 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_flow_dir_d8__s, __pyx_t_2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1096, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_prefix, __pyx_t_14) < 0) __PYX_ERR(0, 1096, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1095 + * 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_14 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1095, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __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_14; + __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1102 + * # 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1102, __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, 1102, __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, 1102, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1103 + * # 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_10 = 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_10 = 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_u_flat_region_mask_tif}; + __pyx_t_14 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1102, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_14); + } 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_u_flat_region_mask_tif}; + __pyx_t_14 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1102, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_14); + } else + #endif + { + __pyx_t_2 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1102, __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_v_working_dir_path); + __Pyx_GIVEREF(__pyx_v_working_dir_path); + PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_10, __pyx_v_working_dir_path); + __Pyx_INCREF(__pyx_kp_u_flat_region_mask_tif); + __Pyx_GIVEREF(__pyx_kp_u_flat_region_mask_tif); + PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_10, __pyx_kp_u_flat_region_mask_tif); + __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1102, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_flat_region_mask_path = __pyx_t_14; + __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1104 + * 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], + */ + __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1104, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1104, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1105 + * 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], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + */ + __pyx_t_14 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1105, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1105, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1105, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1106 + * pygeoprocessing.new_raster_from_base( + * dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte, + * [mask_nodata], # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * flat_region_mask_managed_raster = _ManagedRaster( + */ + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_mask_nodata); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1106, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_15 = PyList_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1106, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_GIVEREF(__pyx_t_2); + PyList_SET_ITEM(__pyx_t_15, 0, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1104 + * 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], + */ + __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1104, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_14); + __Pyx_INCREF(__pyx_v_flat_region_mask_path); + __Pyx_GIVEREF(__pyx_v_flat_region_mask_path); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_flat_region_mask_path); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_15); + PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_15); + __pyx_t_14 = 0; + __pyx_t_1 = 0; + __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1107 + * dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte, + * [mask_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< + * flat_region_mask_managed_raster = _ManagedRaster( + * flat_region_mask_path, 1, 1) + */ + __pyx_t_15 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1107, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 1107, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":1104 + * 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], + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1104, __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_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1108 + * [mask_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * flat_region_mask_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< + * flat_region_mask_path, 1, 1) + * + */ + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1108, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_flat_region_mask_path); + __Pyx_GIVEREF(__pyx_v_flat_region_mask_path); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_flat_region_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_15 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_1, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1108, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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":1111 + * 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":1112 + * + * flow_dir_nodata = 128 + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Byte, + * [flow_dir_nodata], + */ + __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1112, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1112, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1113 + * flow_dir_nodata = 128 + * pygeoprocessing.new_raster_from_base( + * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Byte, # <<<<<<<<<<<<<< + * [flow_dir_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + */ + __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, 1113, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1113, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1113, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1114 + * pygeoprocessing.new_raster_from_base( + * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Byte, + * [flow_dir_nodata], # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * flow_dir_managed_raster = _ManagedRaster(target_flow_dir_path, 1, 1) + */ + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_flow_dir_nodata); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1114, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_14 = PyList_New(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1114, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GIVEREF(__pyx_t_2); + PyList_SET_ITEM(__pyx_t_14, 0, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1112 + * + * flow_dir_nodata = 128 + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Byte, + * [flow_dir_nodata], + */ + __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1112, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_15); + PyTuple_SET_ITEM(__pyx_t_2, 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_2, 1, __pyx_v_target_flow_dir_path); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_14); + __pyx_t_15 = 0; + __pyx_t_3 = 0; + __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1115 + * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Byte, + * [flow_dir_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< + * flow_dir_managed_raster = _ManagedRaster(target_flow_dir_path, 1, 1) + * + */ + __pyx_t_14 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1115, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 1115, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":1112 + * + * flow_dir_nodata = 128 + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Byte, + * [flow_dir_nodata], + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_14); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1112, __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_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1116 + * [flow_dir_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * 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_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1116, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_target_flow_dir_path); + __Pyx_GIVEREF(__pyx_v_target_flow_dir_path); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_target_flow_dir_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_14 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_3, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1116, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_flow_dir_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_14); + __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1122 + * # 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1122, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_path); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1122, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_join); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1122, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1123 + * # 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_2 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && likely(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_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_working_dir_path, __pyx_kp_u_plateau_distance_tif}; + __pyx_t_14 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1122, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_14); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_working_dir_path, __pyx_kp_u_plateau_distance_tif}; + __pyx_t_14 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1122, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_14); + } else + #endif + { + __pyx_t_1 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1122, __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_v_working_dir_path); + __Pyx_GIVEREF(__pyx_v_working_dir_path); + PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_10, __pyx_v_working_dir_path); + __Pyx_INCREF(__pyx_kp_u_plateau_distance_tif); + __Pyx_GIVEREF(__pyx_kp_u_plateau_distance_tif); + PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_10, __pyx_kp_u_plateau_distance_tif); + __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1122, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_plateau_distance_path = __pyx_t_14; + __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1124 + * 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_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1124, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1124, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1125 + * 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], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + */ + __pyx_t_14 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1125, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1125, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1125, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1126 + * 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], # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * plateau_distance_managed_raster = _ManagedRaster( + */ + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1126, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_int_neg_1); + __Pyx_GIVEREF(__pyx_int_neg_1); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_int_neg_1); + + /* "pygeoprocessing/routing/routing.pyx":1124 + * 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_15 = PyTuple_New(4); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1124, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_14); + __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_2); + PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_15, 3, __pyx_t_1); + __pyx_t_14 = 0; + __pyx_t_2 = 0; + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1126 + * 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], # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * plateau_distance_managed_raster = _ManagedRaster( + */ + __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1126, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_From_int((__pyx_v_raster_x_size * __pyx_v_raster_y_size)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1126, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_14 = PyList_New(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1126, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GIVEREF(__pyx_t_2); + PyList_SET_ITEM(__pyx_t_14, 0, __pyx_t_2); + __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_fill_value_list, __pyx_t_14) < 0) __PYX_ERR(0, 1126, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1127 + * dem_raster_path_band[0], plateau_distance_path, gdal.GDT_Float64, + * [-1], fill_value_list=[raster_x_size * raster_y_size], + * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< + * plateau_distance_managed_raster = _ManagedRaster( + * plateau_distance_path, 1, 1) + */ + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 1126, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":1124 + * 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_14 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_15, __pyx_t_1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1124, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1128 + * [-1], fill_value_list=[raster_x_size * raster_y_size], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * plateau_distance_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< + * plateau_distance_path, 1, 1) + * + */ + __pyx_t_14 = PyTuple_New(3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1128, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_INCREF(__pyx_v_plateau_distance_path); + __Pyx_GIVEREF(__pyx_v_plateau_distance_path); + PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_v_plateau_distance_path); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_int_1); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_14, 2, __pyx_int_1); + __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_14, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1128, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_v_plateau_distance_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1133 + * # 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":1134 + * + * 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_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_dem_raster_info, __pyx_n_u_block_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1134, __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, 1134, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_14 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_15 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_14 = PyList_GET_ITEM(sequence, 0); + __pyx_t_15 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(__pyx_t_15); + #else + __pyx_t_14 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1134, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1134, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + #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, 1134, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_3)->tp_iternext; + index = 0; __pyx_t_14 = __pyx_t_8(__pyx_t_3); if (unlikely(!__pyx_t_14)) goto __pyx_L13_unpacking_failed; + __Pyx_GOTREF(__pyx_t_14); + index = 1; __pyx_t_15 = __pyx_t_8(__pyx_t_3); if (unlikely(!__pyx_t_15)) goto __pyx_L13_unpacking_failed; + __Pyx_GOTREF(__pyx_t_15); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_3), 2) < 0) __PYX_ERR(0, 1134, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L14_unpacking_done; + __pyx_L13_unpacking_failed:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 1134, __pyx_L1_error) + __pyx_L14_unpacking_done:; + } + __pyx_v_dem_block_xsize = __pyx_t_14; + __pyx_t_14 = 0; + __pyx_v_dem_block_ysize = __pyx_t_15; + __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1135 + * 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_1 = __Pyx_PyInt_SubtractObjC(__pyx_v_dem_block_xsize, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1135, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_15 = PyNumber_And(__pyx_v_dem_block_xsize, __pyx_t_1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1135, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyInt_NeObjC(__pyx_t_15, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1135, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1135, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L16_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":1136 + * 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_1 = __Pyx_PyInt_SubtractObjC(__pyx_v_dem_block_ysize, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_15 = PyNumber_And(__pyx_v_dem_block_ysize, __pyx_t_1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyInt_NeObjC(__pyx_t_15, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1136, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_5 = __pyx_t_6; + __pyx_L16_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":1135 + * 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_5) { + + /* "pygeoprocessing/routing/routing.pyx":1137 + * 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_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1137, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_warning); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1137, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_15)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_15); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + } + } + __pyx_t_1 = (__pyx_t_15) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_15, __pyx_kp_u_dem_is_not_a_power_of_2_creating) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_kp_u_dem_is_not_a_power_of_2_creating); + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1137, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1139 + * 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]) + * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) + */ + __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_os); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1139, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_path); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1139, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_join); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1139, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_15)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_15); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + __pyx_t_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_v_working_dir_path, __pyx_kp_u_compatable_dem_tif}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1139, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_v_working_dir_path, __pyx_kp_u_compatable_dem_tif}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1139, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_3 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1139, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (__pyx_t_15) { + __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_3, 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_3, 0+__pyx_t_10, __pyx_v_working_dir_path); + __Pyx_INCREF(__pyx_kp_u_compatable_dem_tif); + __Pyx_GIVEREF(__pyx_kp_u_compatable_dem_tif); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_10, __pyx_kp_u_compatable_dem_tif); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1139, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1140 + * compatable_dem_raster_path_band = ( + * os.path.join(working_dir_path, 'compatable_dem.tif'), + * dem_raster_path_band[1]) # <<<<<<<<<<<<<< + * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) + * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) + */ + __pyx_t_14 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1140, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + + /* "pygeoprocessing/routing/routing.pyx":1139 + * 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]) + * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) + */ + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1139, __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_14); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_14); + __pyx_t_1 = 0; + __pyx_t_14 = 0; + __Pyx_DECREF_SET(__pyx_v_compatable_dem_raster_path_band, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1141 + * os.path.join(working_dir_path, 'compatable_dem.tif'), + * dem_raster_path_band[1]) + * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) # <<<<<<<<<<<<<< + * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) + * raster_driver.CreateCopy( + */ + __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_gdal); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1141, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_GetDriverByName); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1141, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_14 = __Pyx_GetItemInt(__pyx_v_raster_driver_creation_tuple, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1141, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_15)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_15); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_3 = (__pyx_t_15) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_15, __pyx_t_14) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_14); + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1141, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_raster_driver = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1142 + * dem_raster_path_band[1]) + * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) + * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) # <<<<<<<<<<<<<< + * raster_driver.CreateCopy( + * compatable_dem_raster_path_band[0], dem_raster, + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1142, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1142, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __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, 1142, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_gdal); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1142, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1142, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_15)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_15); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + __pyx_t_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_t_1, __pyx_t_2}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1142, __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; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_t_1, __pyx_t_2}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1142, __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; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + { + __pyx_t_4 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1142, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (__pyx_t_15) { + __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_15); __pyx_t_15 = NULL; + } + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_10, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_10, __pyx_t_2); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1142, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_v_dem_raster = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1143 + * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) + * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) + * raster_driver.CreateCopy( # <<<<<<<<<<<<<< + * compatable_dem_raster_path_band[0], dem_raster, + * options=raster_driver_creation_tuple[1]) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster_driver, __pyx_n_s_CreateCopy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1143, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + + /* "pygeoprocessing/routing/routing.pyx":1144 + * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) + * raster_driver.CreateCopy( + * compatable_dem_raster_path_band[0], dem_raster, # <<<<<<<<<<<<<< + * options=raster_driver_creation_tuple[1]) + * dem_raster = None + */ + __pyx_t_14 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1144, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + + /* "pygeoprocessing/routing/routing.pyx":1143 + * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) + * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) + * raster_driver.CreateCopy( # <<<<<<<<<<<<<< + * compatable_dem_raster_path_band[0], dem_raster, + * options=raster_driver_creation_tuple[1]) + */ + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1143, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_14); + __Pyx_INCREF(__pyx_v_dem_raster); + __Pyx_GIVEREF(__pyx_v_dem_raster); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_dem_raster); + __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1145 + * raster_driver.CreateCopy( + * compatable_dem_raster_path_band[0], dem_raster, + * options=raster_driver_creation_tuple[1]) # <<<<<<<<<<<<<< + * dem_raster = None + * LOGGER.info("compatible dem complete") + */ + __pyx_t_14 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1145, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_raster_driver_creation_tuple, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1145, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_options, __pyx_t_2) < 0) __PYX_ERR(0, 1145, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1143 + * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) + * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) + * raster_driver.CreateCopy( # <<<<<<<<<<<<<< + * compatable_dem_raster_path_band[0], dem_raster, + * options=raster_driver_creation_tuple[1]) + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_14); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1143, __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; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1146 + * compatable_dem_raster_path_band[0], dem_raster, + * options=raster_driver_creation_tuple[1]) + * 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":1147 + * options=raster_driver_creation_tuple[1]) + * dem_raster = None + * LOGGER.info("compatible dem complete") # <<<<<<<<<<<<<< + * else: + * compatable_dem_raster_path_band = dem_raster_path_band + */ + __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1147, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_info); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1147, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_14 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_14)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_2 = (__pyx_t_14) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_14, __pyx_kp_u_compatible_dem_complete) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_compatible_dem_complete); + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1147, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1135 + * 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":1149 + * 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":1151 + * 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 = __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, 1151, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + + /* "pygeoprocessing/routing/routing.pyx":1152 + * 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, 1152, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "pygeoprocessing/routing/routing.pyx":1150 + * 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_14 = PyTuple_New(3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1150, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_t_4); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_14, 2, __pyx_int_0); + __pyx_t_2 = 0; + __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_14, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1150, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_v_dem_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_4); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1155 + * + * # 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_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_gdal); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1155, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1155, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1156 + * # 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_14 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1156, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1156, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1156, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + __pyx_t_10 = 0; + 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); + __pyx_t_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_t_14, __pyx_t_1}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1155, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_t_14, __pyx_t_1}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1155, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + { + __pyx_t_15 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1155, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_10, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_10, __pyx_t_1); + __pyx_t_14 = 0; + __pyx_t_1 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_15, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1155, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF_SET(__pyx_v_dem_raster, __pyx_t_4); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1157 + * 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_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_dem_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1157, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_15 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1157, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_4 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_1, __pyx_t_15) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_15); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1157, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_dem_band = __pyx_t_4; + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1160 + * + * # this outer loop searches for a pixel that is locally undrained + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * compatable_dem_raster_path_band, offset_only=True, + * largest_block=0): + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1160, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1160, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1161 + * # this outer loop searches for a pixel that is locally undrained + * for offset_dict in pygeoprocessing.iterblocks( + * compatable_dem_raster_path_band, offset_only=True, # <<<<<<<<<<<<<< + * largest_block=0): + * win_xsize = offset_dict['win_xsize'] + */ + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1160, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_compatable_dem_raster_path_band); + __Pyx_GIVEREF(__pyx_v_compatable_dem_raster_path_band); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_compatable_dem_raster_path_band); + __pyx_t_15 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1161, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 1161, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_largest_block, __pyx_int_0) < 0) __PYX_ERR(0, 1161, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":1160 + * + * # this outer loop searches for a pixel that is locally undrained + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * compatable_dem_raster_path_band, offset_only=True, + * largest_block=0): + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, __pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1160, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_15 = __pyx_t_1; __Pyx_INCREF(__pyx_t_15); __pyx_t_17 = 0; + __pyx_t_18 = NULL; + } else { + __pyx_t_17 = -1; __pyx_t_15 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1160, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_18 = Py_TYPE(__pyx_t_15)->tp_iternext; if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 1160, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (likely(!__pyx_t_18)) { + if (likely(PyList_CheckExact(__pyx_t_15))) { + if (__pyx_t_17 >= PyList_GET_SIZE(__pyx_t_15)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_15, __pyx_t_17); __Pyx_INCREF(__pyx_t_1); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 1160, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_15, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1160, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } else { + if (__pyx_t_17 >= PyTuple_GET_SIZE(__pyx_t_15)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_15, __pyx_t_17); __Pyx_INCREF(__pyx_t_1); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 1160, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_15, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1160, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } + } else { + __pyx_t_1 = __pyx_t_18(__pyx_t_15); + 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, 1160, __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":1163 + * compatable_dem_raster_path_band, 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_u_win_xsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1163, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1163, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_win_xsize = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":1164 + * 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_u_win_ysize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1164, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1164, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_win_ysize = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":1165 + * 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_u_xoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1165, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1165, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_xoff = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":1166 + * win_ysize = offset_dict['win_ysize'] + * xoff = offset_dict['xoff'] + * yoff = offset_dict['yoff'] # <<<<<<<<<<<<<< + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + */ + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_yoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1166, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1166, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_yoff = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":1168 + * yoff = offset_dict['yoff'] + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + */ + __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1169 + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info( + */ + __pyx_v_last_log_time = time(NULL); + + /* "pygeoprocessing/routing/routing.pyx":1170 + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size # <<<<<<<<<<<<<< + * LOGGER.info( + * '(flow dir d8): ' + */ + __pyx_v_current_pixel = (__pyx_v_xoff + (__pyx_v_yoff * __pyx_v_raster_x_size)); + + /* "pygeoprocessing/routing/routing.pyx":1171 + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info( # <<<<<<<<<<<<<< + * '(flow dir d8): ' + * f'{current_pixel} of {raster_x_size*raster_y_size} ' + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1171, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1171, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1172 + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info( + * '(flow dir d8): ' # <<<<<<<<<<<<<< + * f'{current_pixel} of {raster_x_size*raster_y_size} ' + * f'pixels complete') + */ + __pyx_t_4 = PyTuple_New(5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1172, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_19 = 0; + __pyx_t_20 = 127; + __Pyx_INCREF(__pyx_kp_u_flow_dir_d8); + __pyx_t_19 += 15; + __Pyx_GIVEREF(__pyx_kp_u_flow_dir_d8); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_u_flow_dir_d8); + + /* "pygeoprocessing/routing/routing.pyx":1173 + * LOGGER.info( + * '(flow dir d8): ' + * f'{current_pixel} of {raster_x_size*raster_y_size} ' # <<<<<<<<<<<<<< + * f'pixels complete') + * + */ + __pyx_t_14 = __Pyx_PyUnicode_From_int(__pyx_v_current_pixel, 0, ' ', 'd'); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1173, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_19 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_14); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_14); + __pyx_t_14 = 0; + __Pyx_INCREF(__pyx_kp_u_of); + __pyx_t_19 += 4; + __Pyx_GIVEREF(__pyx_kp_u_of); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_kp_u_of); + __pyx_t_14 = __Pyx_PyUnicode_From_int((__pyx_v_raster_x_size * __pyx_v_raster_y_size), 0, ' ', 'd'); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1173, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_19 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_14); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_14); + __pyx_t_14 = 0; + __Pyx_INCREF(__pyx_kp_u_pixels_complete); + __pyx_t_19 += 16; + __Pyx_GIVEREF(__pyx_kp_u_pixels_complete); + PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_kp_u_pixels_complete); + + /* "pygeoprocessing/routing/routing.pyx":1172 + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info( + * '(flow dir d8): ' # <<<<<<<<<<<<<< + * f'{current_pixel} of {raster_x_size*raster_y_size} ' + * f'pixels complete') + */ + __pyx_t_14 = __Pyx_PyUnicode_Join(__pyx_t_4, 5, __pyx_t_19, __pyx_t_20); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1172, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_14) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_14); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1171, __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":1168 + * yoff = offset_dict['yoff'] + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + */ + } + + /* "pygeoprocessing/routing/routing.pyx":1177 + * + * # 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_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1177, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1177, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1178 + * # 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_u_win_ysize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1178, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_14 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1178, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1178, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1178, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1178, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_4); + __pyx_t_14 = 0; + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1177 + * + * # 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, 1177, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1179 + * 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, 1179, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_numpy); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1179, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_float64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1179, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 1179, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1177 + * + * # 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_2, __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1177, __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_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, 1177, __pyx_L1_error) + __pyx_t_21 = ((PyArrayObject *)__pyx_t_3); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer); + __pyx_t_10 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_21, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); + if (unlikely(__pyx_t_10 < 0)) { + PyErr_Fetch(&__pyx_t_13, &__pyx_t_12, &__pyx_t_11); + 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_13); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_11); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_13, __pyx_t_12, __pyx_t_11); + } + __pyx_t_13 = __pyx_t_12 = __pyx_t_11 = 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_10 < 0)) __PYX_ERR(0, 1177, __pyx_L1_error) + } + __pyx_t_21 = 0; + __Pyx_XDECREF_SET(__pyx_v_dem_buffer_array, ((PyArrayObject *)__pyx_t_3)); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1180 + * (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, 1180, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_dem_buffer_array), __pyx_slice__7, __pyx_t_3) < 0)) __PYX_ERR(0, 1180, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1183 + * + * # 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_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_generate_read_bounds); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1183, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":1184 + * # 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_4 = __Pyx_PyInt_From_int(__pyx_v_raster_x_size); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1184, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_raster_y_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1184, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_14 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_14)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + __pyx_t_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[4] = {__pyx_t_14, __pyx_v_offset_dict, __pyx_t_4, __pyx_t_2}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1183, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __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[4] = {__pyx_t_14, __pyx_v_offset_dict, __pyx_t_4, __pyx_t_2}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1183, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + { + __pyx_t_16 = PyTuple_New(3+__pyx_t_10); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1183, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + if (__pyx_t_14) { + __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_14); __pyx_t_14 = NULL; + } + __Pyx_INCREF(__pyx_v_offset_dict); + __Pyx_GIVEREF(__pyx_v_offset_dict); + PyTuple_SET_ITEM(__pyx_t_16, 0+__pyx_t_10, __pyx_v_offset_dict); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_16, 1+__pyx_t_10, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_16, 2+__pyx_t_10, __pyx_t_2); + __pyx_t_4 = 0; + __pyx_t_2 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_16, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1183, __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, 1183, __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, 1183, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_16 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1183, __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_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1183, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_2)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_8(__pyx_t_2); if (unlikely(!__pyx_t_1)) goto __pyx_L21_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 1; __pyx_t_16 = __pyx_t_8(__pyx_t_2); if (unlikely(!__pyx_t_16)) goto __pyx_L21_unpacking_failed; + __Pyx_GOTREF(__pyx_t_16); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_2), 2) < 0) __PYX_ERR(0, 1183, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L22_unpacking_done; + __pyx_L21_unpacking_failed:; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 1183, __pyx_L1_error) + __pyx_L22_unpacking_done:; + } + + /* "pygeoprocessing/routing/routing.pyx":1183 + * + * # 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, 1183, __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_4 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_14 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_22 = PyTuple_GET_ITEM(sequence, 3); + } else { + __pyx_t_2 = PyList_GET_ITEM(sequence, 0); + __pyx_t_4 = PyList_GET_ITEM(sequence, 1); + __pyx_t_14 = PyList_GET_ITEM(sequence, 2); + __pyx_t_22 = PyList_GET_ITEM(sequence, 3); + } + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(__pyx_t_22); + #else + { + Py_ssize_t i; + PyObject** temps[4] = {&__pyx_t_2,&__pyx_t_4,&__pyx_t_14,&__pyx_t_22}; + for (i=0; i < 4; i++) { + PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 1183, __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_2,&__pyx_t_4,&__pyx_t_14,&__pyx_t_22}; + __pyx_t_23 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 1183, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_23); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_23)->tp_iternext; + for (index=0; index < 4; index++) { + PyObject* item = __pyx_t_8(__pyx_t_23); if (unlikely(!item)) goto __pyx_L23_unpacking_failed; + __Pyx_GOTREF(item); + *(temps[index]) = item; + } + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_23), 4) < 0) __PYX_ERR(0, 1183, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; + goto __pyx_L24_unpacking_done; + __pyx_L23_unpacking_failed:; + __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 1183, __pyx_L1_error) + __pyx_L24_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_xa, __pyx_t_2); + __pyx_t_2 = 0; + __Pyx_XDECREF_SET(__pyx_v_xb, __pyx_t_4); + __pyx_t_4 = 0; + __Pyx_XDECREF_SET(__pyx_v_ya, __pyx_t_14); + __pyx_t_14 = 0; + __Pyx_XDECREF_SET(__pyx_v_yb, __pyx_t_22); + __pyx_t_22 = 0; + __Pyx_XDECREF_SET(__pyx_v_modified_offset_dict, __pyx_t_16); + __pyx_t_16 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1185 + * (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, 1185, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + + /* "pygeoprocessing/routing/routing.pyx":1186 + * 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, 1186, __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, 1186, __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, 1185, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } + + /* "pygeoprocessing/routing/routing.pyx":1185 + * (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_22 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 1185, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_22); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1186 + * 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_22, __pyx_n_s_astype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1186, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_22, __pyx_n_s_numpy); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 1186, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_22); + __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_22, __pyx_n_s_float64); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1186, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; + __pyx_t_22 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_22 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_22)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_22); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_3 = (__pyx_t_22) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_22, __pyx_t_16) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_16); + __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1186, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1185 + * (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, 1185, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_16 = PySlice_New(__pyx_v_xa, __pyx_v_xb, Py_None); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1185, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_22 = PyTuple_New(2); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 1185, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_22); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_22, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_16); + PyTuple_SET_ITEM(__pyx_t_22, 1, __pyx_t_16); + __pyx_t_1 = 0; + __pyx_t_16 = 0; + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_dem_buffer_array), __pyx_t_22, __pyx_t_3) < 0)) __PYX_ERR(0, 1185, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1189 + * + * # ensure these are set for the complier + * xi_n = -1 # <<<<<<<<<<<<<< + * yi_n = -1 + * + */ + __pyx_v_xi_n = -1; + + /* "pygeoprocessing/routing/routing.pyx":1190 + * # 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":1193 + * + * # 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_24 = (__pyx_v_win_ysize + 1); + __pyx_t_25 = __pyx_t_24; + for (__pyx_t_10 = 1; __pyx_t_10 < __pyx_t_25; __pyx_t_10+=1) { + __pyx_v_yi = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":1194 + * # 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, 1e-8, 1e-5): + */ + __pyx_t_26 = (__pyx_v_win_xsize + 1); + __pyx_t_27 = __pyx_t_26; + for (__pyx_t_9 = 1; __pyx_t_9 < __pyx_t_27; __pyx_t_9+=1) { + __pyx_v_xi = __pyx_t_9; + + /* "pygeoprocessing/routing/routing.pyx":1195 + * 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, 1e-8, 1e-5): + * continue + */ + __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_dem_buffer_array.diminfo[0].shape; + if (unlikely(__pyx_t_28 < 0)) __pyx_t_30 = 0; + } else if (unlikely(__pyx_t_28 >= __pyx_pybuffernd_dem_buffer_array.diminfo[0].shape)) __pyx_t_30 = 0; + if (__pyx_t_29 < 0) { + __pyx_t_29 += __pyx_pybuffernd_dem_buffer_array.diminfo[1].shape; + if (unlikely(__pyx_t_29 < 0)) __pyx_t_30 = 1; + } else if (unlikely(__pyx_t_29 >= __pyx_pybuffernd_dem_buffer_array.diminfo[1].shape)) __pyx_t_30 = 1; + if (unlikely(__pyx_t_30 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_30); + __PYX_ERR(0, 1195, __pyx_L1_error) + } + __pyx_v_root_height = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer.buf, __pyx_t_28, __pyx_pybuffernd_dem_buffer_array.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_dem_buffer_array.diminfo[1].strides)); + + /* "pygeoprocessing/routing/routing.pyx":1196 + * for xi in range(1, win_xsize+1): + * root_height = dem_buffer_array[yi, xi] + * if _is_close(root_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_root_height, __pyx_v_dem_nodata, 1e-8, 1e-5) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1197 + * root_height = dem_buffer_array[yi, xi] + * if _is_close(root_height, dem_nodata, 1e-8, 1e-5): + * continue # <<<<<<<<<<<<<< + * + * # this value is set in case it turns out to be the root of a + */ + goto __pyx_L27_continue; + + /* "pygeoprocessing/routing/routing.pyx":1196 + * for xi in range(1, win_xsize+1): + * root_height = dem_buffer_array[yi, xi] + * if _is_close(root_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * continue + * + */ + } + + /* "pygeoprocessing/routing/routing.pyx":1202 + * # 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":1203 + * # 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":1206 + * + * if flow_dir_managed_raster.get( + * xi_root, yi_root) != flow_dir_nodata: # <<<<<<<<<<<<<< + * # already been defined + * continue + */ + __pyx_t_5 = ((__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":1205 + * yi_root = yi-1+yoff + * + * if flow_dir_managed_raster.get( # <<<<<<<<<<<<<< + * xi_root, yi_root) != flow_dir_nodata: + * # already been defined + */ + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1208 + * 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":1205 + * 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":1213 + * # 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":1214 + * # 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":1216 + * largest_slope = 0.0 + * + * for i_n in range(8): # <<<<<<<<<<<<<< + * xi_n = xi+D8_XOFFSET[i_n] + * yi_n = yi+D8_YOFFSET[i_n] + */ + for (__pyx_t_30 = 0; __pyx_t_30 < 8; __pyx_t_30+=1) { + __pyx_v_i_n = __pyx_t_30; + + /* "pygeoprocessing/routing/routing.pyx":1217 + * + * for i_n in range(8): + * xi_n = xi+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< + * yi_n = yi+D8_YOFFSET[i_n] + * n_height = dem_buffer_array[yi_n, xi_n] + */ + __pyx_v_xi_n = (__pyx_v_xi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":1218 + * for i_n in range(8): + * xi_n = xi+D8_XOFFSET[i_n] + * yi_n = yi+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< + * n_height = dem_buffer_array[yi_n, xi_n] + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): + */ + __pyx_v_yi_n = (__pyx_v_yi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":1219 + * xi_n = xi+D8_XOFFSET[i_n] + * yi_n = yi+D8_YOFFSET[i_n] + * n_height = dem_buffer_array[yi_n, xi_n] # <<<<<<<<<<<<<< + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): + * continue + */ + __pyx_t_29 = __pyx_v_yi_n; + __pyx_t_28 = __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_28 < 0) { + __pyx_t_28 += __pyx_pybuffernd_dem_buffer_array.diminfo[1].shape; + if (unlikely(__pyx_t_28 < 0)) __pyx_t_31 = 1; + } else if (unlikely(__pyx_t_28 >= __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, 1219, __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_28, __pyx_pybuffernd_dem_buffer_array.diminfo[1].strides)); + + /* "pygeoprocessing/routing/routing.pyx":1220 + * yi_n = yi+D8_YOFFSET[i_n] + * n_height = dem_buffer_array[yi_n, xi_n] + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * continue + * n_slope = root_height - n_height + */ + __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_n_height, __pyx_v_dem_nodata, 1e-8, 1e-5) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1221 + * n_height = dem_buffer_array[yi_n, xi_n] + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): + * continue # <<<<<<<<<<<<<< + * n_slope = root_height - n_height + * if i_n & 1: + */ + goto __pyx_L31_continue; + + /* "pygeoprocessing/routing/routing.pyx":1220 + * yi_n = yi+D8_YOFFSET[i_n] + * n_height = dem_buffer_array[yi_n, xi_n] + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * continue + * n_slope = root_height - n_height + */ + } + + /* "pygeoprocessing/routing/routing.pyx":1222 + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): + * 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":1223 + * continue + * n_slope = root_height - n_height + * if i_n & 1: # <<<<<<<<<<<<<< + * # if diagonal, adjust the slope + * n_slope *= SQRT2_INV + */ + __pyx_t_5 = ((__pyx_v_i_n & 1) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1225 + * 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":1223 + * continue + * n_slope = root_height - n_height + * if i_n & 1: # <<<<<<<<<<<<<< + * # if diagonal, adjust the slope + * n_slope *= SQRT2_INV + */ + } + + /* "pygeoprocessing/routing/routing.pyx":1226 + * # 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_5 = ((__pyx_v_n_slope > __pyx_v_largest_slope) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1227 + * 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":1228 + * 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":1226 + * # 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":1230 + * largest_slope = n_slope + * + * if largest_slope_dir >= 0: # <<<<<<<<<<<<<< + * # define flow dir and move on + * flow_dir_managed_raster.set( + */ + __pyx_t_5 = ((__pyx_v_largest_slope_dir >= 0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1232 + * 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":1234 + * 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":1230 + * largest_slope = n_slope + * + * if largest_slope_dir >= 0: # <<<<<<<<<<<<<< + * # define flow dir and move on + * flow_dir_managed_raster.set( + */ + } + + /* "pygeoprocessing/routing/routing.pyx":1238 + * # 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":1239 + * # 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":1245 + * # 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_5 = ((!(__pyx_v_search_queue.empty() != 0)) != 0); + if (!__pyx_t_5) break; + + /* "pygeoprocessing/routing/routing.pyx":1246 + * + * while not search_queue.empty(): + * xi_q = search_queue.front().xi # <<<<<<<<<<<<<< + * yi_q = search_queue.front().yi + * search_queue.pop() + */ + __pyx_t_30 = __pyx_v_search_queue.front().xi; + __pyx_v_xi_q = __pyx_t_30; + + /* "pygeoprocessing/routing/routing.pyx":1247 + * while not search_queue.empty(): + * xi_q = search_queue.front().xi + * yi_q = search_queue.front().yi # <<<<<<<<<<<<<< + * search_queue.pop() + * + */ + __pyx_t_30 = __pyx_v_search_queue.front().yi; + __pyx_v_yi_q = __pyx_t_30; + + /* "pygeoprocessing/routing/routing.pyx":1248 + * 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":1250 + * search_queue.pop() + * + * largest_slope_dir = -1 # <<<<<<<<<<<<<< + * largest_slope = 0.0 + * diagonal_nodata = 1 + */ + __pyx_v_largest_slope_dir = -1L; + + /* "pygeoprocessing/routing/routing.pyx":1251 + * + * 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":1252 + * largest_slope_dir = -1 + * largest_slope = 0.0 + * diagonal_nodata = 1 # <<<<<<<<<<<<<< + * for i_n in range(8): + * xi_n = xi_q+D8_XOFFSET[i_n] + */ + __pyx_v_diagonal_nodata = 1; + + /* "pygeoprocessing/routing/routing.pyx":1253 + * largest_slope = 0.0 + * diagonal_nodata = 1 + * for i_n in range(8): # <<<<<<<<<<<<<< + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] + */ + for (__pyx_t_30 = 0; __pyx_t_30 < 8; __pyx_t_30+=1) { + __pyx_v_i_n = __pyx_t_30; + + /* "pygeoprocessing/routing/routing.pyx":1254 + * diagonal_nodata = 1 + * for i_n in range(8): + * xi_n = xi_q+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< + * yi_n = yi_q+D8_YOFFSET[i_n] + * + */ + __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":1255 + * for i_n in range(8): + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< + * + * if (xi_n < 0 or xi_n >= raster_x_size or + */ + __pyx_v_yi_n = (__pyx_v_yi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":1257 + * yi_n = yi_q+D8_YOFFSET[i_n] + * + * 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_6 = ((__pyx_v_xi_n < 0) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L42_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L42_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":1258 + * + * 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_6 = ((__pyx_v_yi_n < 0) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L42_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0); + __pyx_t_5 = __pyx_t_6; + __pyx_L42_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":1257 + * yi_n = yi_q+D8_YOFFSET[i_n] + * + * 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_5) { + + /* "pygeoprocessing/routing/routing.pyx":1259 + * 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":1257 + * yi_n = yi_q+D8_YOFFSET[i_n] + * + * 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":1261 + * n_height = dem_nodata + * else: + * n_height = dem_managed_raster.get(xi_n, yi_n) # <<<<<<<<<<<<<< + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): + * 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":1262 + * else: + * n_height = dem_managed_raster.get(xi_n, yi_n) + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * if diagonal_nodata and largest_slope == 0.0: + * largest_slope_dir = i_n + */ + __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_n_height, __pyx_v_dem_nodata, 1e-8, 1e-5) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1263 + * n_height = dem_managed_raster.get(xi_n, yi_n) + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): + * if diagonal_nodata and largest_slope == 0.0: # <<<<<<<<<<<<<< + * largest_slope_dir = i_n + * diagonal_nodata = i_n & 1 + */ + __pyx_t_6 = (__pyx_v_diagonal_nodata != 0); + if (__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L48_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_largest_slope == 0.0) != 0); + __pyx_t_5 = __pyx_t_6; + __pyx_L48_bool_binop_done:; + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1264 + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): + * 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":1265 + * 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":1263 + * n_height = dem_managed_raster.get(xi_n, yi_n) + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): + * if diagonal_nodata and largest_slope == 0.0: # <<<<<<<<<<<<<< + * largest_slope_dir = i_n + * diagonal_nodata = i_n & 1 + */ + } + + /* "pygeoprocessing/routing/routing.pyx":1266 + * 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":1262 + * else: + * n_height = dem_managed_raster.get(xi_n, yi_n) + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * if diagonal_nodata and largest_slope == 0.0: + * largest_slope_dir = i_n + */ + } + + /* "pygeoprocessing/routing/routing.pyx":1267 + * 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":1268 + * continue + * n_slope = root_height - n_height + * if n_slope < 0: # <<<<<<<<<<<<<< + * continue + * if n_slope == 0.0: + */ + __pyx_t_5 = ((__pyx_v_n_slope < 0.0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1269 + * 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":1268 + * continue + * n_slope = root_height - n_height + * if n_slope < 0: # <<<<<<<<<<<<<< + * continue + * if n_slope == 0.0: + */ + } + + /* "pygeoprocessing/routing/routing.pyx":1270 + * 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_5 = ((__pyx_v_n_slope == 0.0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1272 + * 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_5 = ((__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":1271 + * 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_5) { + + /* "pygeoprocessing/routing/routing.pyx":1275 + * # 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":1276 + * # 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":1271 + * 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":1278 + * 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":1270 + * 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":1279 + * xi_n, yi_n, 1) + * continue + * if i_n & 1: # <<<<<<<<<<<<<< + * n_slope *= SQRT2_INV + * if n_slope > largest_slope: + */ + __pyx_t_5 = ((__pyx_v_i_n & 1) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1280 + * 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":1279 + * xi_n, yi_n, 1) + * continue + * if i_n & 1: # <<<<<<<<<<<<<< + * n_slope *= SQRT2_INV + * if n_slope > largest_slope: + */ + } + + /* "pygeoprocessing/routing/routing.pyx":1281 + * if i_n & 1: + * n_slope *= SQRT2_INV + * if n_slope > largest_slope: # <<<<<<<<<<<<<< + * largest_slope = n_slope + * largest_slope_dir = i_n + */ + __pyx_t_5 = ((__pyx_v_n_slope > __pyx_v_largest_slope) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1282 + * 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":1283 + * 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":1281 + * 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":1285 + * largest_slope_dir = i_n + * + * if largest_slope_dir >= 0: # <<<<<<<<<<<<<< + * if largest_slope > 0.0: + * # regular downhill pixel + */ + __pyx_t_5 = ((__pyx_v_largest_slope_dir >= 0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1286 + * + * if largest_slope_dir >= 0: + * if largest_slope > 0.0: # <<<<<<<<<<<<<< + * # regular downhill pixel + * flow_dir_managed_raster.set( + */ + __pyx_t_5 = ((__pyx_v_largest_slope > 0.0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1288 + * 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":1290 + * 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":1292 + * 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":1286 + * + * 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":1295 + * 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":1296 + * # 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":1295 + * 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":1297 + * 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":1285 + * largest_slope_dir = i_n + * + * if largest_slope_dir >= 0: # <<<<<<<<<<<<<< + * if largest_slope > 0.0: + * # regular downhill pixel + */ + } + } + + /* "pygeoprocessing/routing/routing.pyx":1300 + * + * # 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_5 = (__pyx_v_drain_queue.empty() != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1304 + * # 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_5 = ((!(__pyx_v_nodata_drain_queue.empty() != 0)) != 0); + if (!__pyx_t_5) break; + + /* "pygeoprocessing/routing/routing.pyx":1305 + * # 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_30 = __pyx_v_nodata_drain_queue.front().xi; + __pyx_v_xi_q = __pyx_t_30; + + /* "pygeoprocessing/routing/routing.pyx":1306 + * 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_30 = __pyx_v_nodata_drain_queue.front().yi; + __pyx_v_yi_q = __pyx_t_30; + + /* "pygeoprocessing/routing/routing.pyx":1307 + * 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":1309 + * 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":1310 + * 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":1311 + * 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":1312 + * 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":1300 + * + * # 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":1315 + * 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, 1315, __pyx_L1_error) + } + __pyx_v_nodata_flow_dir_queue = __pyx_t_33; + + /* "pygeoprocessing/routing/routing.pyx":1316 + * # 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, 1316, __pyx_L1_error) + } + __pyx_v_nodata_drain_queue = __pyx_t_34; + } + __pyx_L57:; + + /* "pygeoprocessing/routing/routing.pyx":1320 + * # 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_5 = ((!(__pyx_v_drain_queue.empty() != 0)) != 0); + if (!__pyx_t_5) break; + + /* "pygeoprocessing/routing/routing.pyx":1321 + * # 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_30 = __pyx_v_drain_queue.front().xi; + __pyx_v_xi_q = __pyx_t_30; + + /* "pygeoprocessing/routing/routing.pyx":1322 + * while not drain_queue.empty(): + * xi_q = drain_queue.front().xi + * yi_q = drain_queue.front().yi # <<<<<<<<<<<<<< + * drain_queue.pop() + * + */ + __pyx_t_30 = __pyx_v_drain_queue.front().yi; + __pyx_v_yi_q = __pyx_t_30; + + /* "pygeoprocessing/routing/routing.pyx":1323 + * 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":1325 + * 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":1328 + * xi_q, yi_q) + * + * for i_n in range(8): # <<<<<<<<<<<<<< + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] + */ + for (__pyx_t_30 = 0; __pyx_t_30 < 8; __pyx_t_30+=1) { + __pyx_v_i_n = __pyx_t_30; + + /* "pygeoprocessing/routing/routing.pyx":1329 + * + * for i_n in range(8): + * xi_n = xi_q+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< + * yi_n = yi_q+D8_YOFFSET[i_n] + * if (xi_n < 0 or xi_n >= raster_x_size or + */ + __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":1330 + * for i_n in range(8): + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< + * 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_D8_YOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":1331 + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] + * if (xi_n < 0 or xi_n >= raster_x_size or # <<<<<<<<<<<<<< + * yi_n < 0 or yi_n >= raster_y_size): + * continue + */ + __pyx_t_6 = ((__pyx_v_xi_n < 0) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L65_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L65_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":1332 + * yi_n = yi_q+D8_YOFFSET[i_n] + * if (xi_n < 0 or xi_n >= raster_x_size or + * yi_n < 0 or yi_n >= raster_y_size): # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_6 = ((__pyx_v_yi_n < 0) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L65_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0); + __pyx_t_5 = __pyx_t_6; + __pyx_L65_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":1331 + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] + * 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":1333 + * 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":1331 + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] + * 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":1336 + * + * 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_7 = __pyx_v_15pygeoprocessing_7routing_7routing_SQRT2; + } else { + __pyx_t_7 = 1.0; + } + + /* "pygeoprocessing/routing/routing.pyx":1335 + * 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_7); + + /* "pygeoprocessing/routing/routing.pyx":1339 + * + * 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_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) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L70_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":1341 + * 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_6 = ((__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_5 = __pyx_t_6; + __pyx_L70_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":1338 + * 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_5) { + + /* "pygeoprocessing/routing/routing.pyx":1344 + * # 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":1346 + * 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":1348 + * 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":1338 + * 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":1160 + * + * # this outer loop searches for a pixel that is locally undrained + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * compatable_dem_raster_path_band, offset_only=True, + * largest_block=0): + */ + } + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1349 + * 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":1350 + * 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":1351 + * 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, 1351, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_22 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_22 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_22)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_22); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_15 = (__pyx_t_22) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_22) : __Pyx_PyObject_CallNoArg(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; + if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1351, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1352 + * 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, 1352, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_22 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_22 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_22)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_22); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_15 = (__pyx_t_22) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_22) : __Pyx_PyObject_CallNoArg(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; + if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1352, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1353 + * 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, 1353, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_22 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_22 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_22)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_22); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_15 = (__pyx_t_22) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_22) : __Pyx_PyObject_CallNoArg(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; + if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1353, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1354 + * flat_region_mask_managed_raster.close() + * dem_managed_raster.close() + * plateau_distance_managed_raster.close() # <<<<<<<<<<<<<< + * shutil.rmtree(working_dir_path) + * LOGGER.info('(flow dir d8): complete') + */ + __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, 1354, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_22 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_22 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_22)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_22); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_15 = (__pyx_t_22) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_22) : __Pyx_PyObject_CallNoArg(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; + if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1354, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1355 + * dem_managed_raster.close() + * plateau_distance_managed_raster.close() + * shutil.rmtree(working_dir_path) # <<<<<<<<<<<<<< + * LOGGER.info('(flow dir d8): complete') + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_shutil); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1355, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_22 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_rmtree); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 1355, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_22); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_22))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_22); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_22); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_22, function); + } + } + __pyx_t_15 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_22, __pyx_t_3, __pyx_v_working_dir_path) : __Pyx_PyObject_CallOneArg(__pyx_t_22, __pyx_v_working_dir_path); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1355, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1356 + * plateau_distance_managed_raster.close() + * shutil.rmtree(working_dir_path) + * LOGGER.info('(flow dir d8): complete') # <<<<<<<<<<<<<< + * + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_22, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 1356, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_22); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_22, __pyx_n_s_info); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1356, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; + __pyx_t_22 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_22 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_22)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_22); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_15 = (__pyx_t_22) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_22, __pyx_kp_u_flow_dir_d8_complete) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_flow_dir_d8_complete); + __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; + if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1356, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":994 + * + * + * 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_14); + __Pyx_XDECREF(__pyx_t_15); + __Pyx_XDECREF(__pyx_t_16); + __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_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_raster_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_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":1359 + * + * + * 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\n 3 2 1\n 4 x 0\n 5 6 7\n\n target_flow_accum_raster_path (str): 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 raster_driver_creation_tuple (tuple): a tuple containing a GDAL driver\n name string as the first element and a GDAL creation options\n tuple/list as the second. Defaults to a GTiff driver tuple\n defined at geoprocessing.DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS.\n\n Returns:\n None.\n "; +static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_7flow_accumulation_d8 = {"flow_accumulation_d8", (PyCFunction)(void*)(PyCFunctionWithKeywords)__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_raster_driver_creation_tuple = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 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_raster_driver_creation_tuple,0}; + PyObject* values[4] = {0,0,0,0}; + + /* "pygeoprocessing/routing/routing.pyx":1361 + * def flow_accumulation_d8( + * flow_dir_raster_path_band, target_flow_accum_raster_path, + * weight_raster_path_band=None, # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): + * """D8 flow accumulation. + */ + values[2] = ((PyObject *)Py_None); + values[3] = __pyx_k__8; + 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, 1359, __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_raster_driver_creation_tuple); + 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, 1359, __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_raster_driver_creation_tuple = 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, 1359, __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_raster_driver_creation_tuple); + + /* "pygeoprocessing/routing/routing.pyx":1359 + * + * + * 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_raster_driver_creation_tuple) { + 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 __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; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + 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; + struct __pyx_t_15pygeoprocessing_7routing_7routing_FlowPixelType __pyx_t_30; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __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":1420 + * # 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":1432 + * # 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":1434 + * 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_is_raster_path_band_formatted); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1434, __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); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_flow_dir_raster_path_band) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_flow_dir_raster_path_band); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1434, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __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, 1434, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_5 = ((!__pyx_t_4) != 0); + if (unlikely(__pyx_t_5)) { + + /* "pygeoprocessing/routing/routing.pyx":1436 + * 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_PyUnicode_FormatSafe(__pyx_kp_u_s_is_supposed_to_be_a_raster_ba, __pyx_v_flow_dir_raster_path_band); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1436, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":1435 + * + * 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, 1435, __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, 1435, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":1434 + * 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":1438 + * "%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_4 = __Pyx_PyObject_IsTrue(__pyx_v_weight_raster_path_band); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1438, __pyx_L1_error) + if (__pyx_t_4) { + } else { + __pyx_t_5 = __pyx_t_4; + goto __pyx_L5_bool_binop_done; + } + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_is_raster_path_band_formatted); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1438, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":1439 + * 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_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); + } + } + __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_3, __pyx_v_weight_raster_path_band) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_weight_raster_path_band); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1438, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1438 + * "%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_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1438, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_6 = ((!__pyx_t_4) != 0); + __pyx_t_5 = __pyx_t_6; + __pyx_L5_bool_binop_done:; + if (unlikely(__pyx_t_5)) { + + /* "pygeoprocessing/routing/routing.pyx":1441 + * 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_PyUnicode_FormatSafe(__pyx_kp_u_s_is_supposed_to_be_a_raster_ba, __pyx_v_weight_raster_path_band); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1441, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + + /* "pygeoprocessing/routing/routing.pyx":1440 + * 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, 1440, __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, 1440, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":1438 + * "%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":1444 + * 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":1445 + * + * 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_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1445, __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, 1445, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1446 + * 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], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + */ + __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, 1446, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":1447 + * pygeoprocessing.new_raster_from_base( + * flow_dir_raster_path_band[0], target_flow_accum_raster_path, + * gdal.GDT_Float64, [flow_accum_nodata], # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * flow_accum_managed_raster = _ManagedRaster( + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1447, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1447, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __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, 1447, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = PyList_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1447, __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":1445 + * + * 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, 1445, __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_7); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_8); + __pyx_t_1 = 0; + __pyx_t_7 = 0; + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1448 + * flow_dir_raster_path_band[0], target_flow_accum_raster_path, + * gdal.GDT_Float64, [flow_accum_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< + * flow_accum_managed_raster = _ManagedRaster( + * target_flow_accum_raster_path, 1, 1) + */ + __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1448, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 1448, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":1445 + * + * 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_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1445, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __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_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1449 + * gdal.GDT_Float64, [flow_accum_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * flow_accum_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< + * target_flow_accum_raster_path, 1, 1) + * + */ + __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1449, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_v_target_flow_accum_raster_path); + __Pyx_GIVEREF(__pyx_v_target_flow_accum_raster_path); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_target_flow_accum_raster_path); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_int_1); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_int_1); + __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1449, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 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":1453 + * + * 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, 1453, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_flow_dir_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1453, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + + /* "pygeoprocessing/routing/routing.pyx":1452 + * 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, 1452, __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_7); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_7); + __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_7 = 0; + __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_3, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1452, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_flow_dir_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_7); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1454 + * 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1454, __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, 1454, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1455 + * 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, 1455, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1455, __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, 1455, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __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_1}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1454, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __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[3] = {__pyx_t_2, __pyx_t_3, __pyx_t_1}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1454, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + { + __pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1454, __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_1); + PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_t_1); + __pyx_t_3 = 0; + __pyx_t_1 = 0; + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_10, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1454, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __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_7; + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1456 + * 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, 1456, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + + /* "pygeoprocessing/routing/routing.pyx":1457 + * 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, 1457, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_7 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_1, __pyx_t_10) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_10); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1456, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_flow_dir_band = __pyx_t_7; + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1459 + * 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":1460 + * + * 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_5 = __Pyx_PyObject_IsTrue(__pyx_v_weight_raster_path_band); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1460, __pyx_L1_error) + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1462 + * 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_7 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1462, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __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, 1462, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + + /* "pygeoprocessing/routing/routing.pyx":1461 + * 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_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1461, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_8); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_int_0); + __pyx_t_7 = 0; + __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_10, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1461, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 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":1463 + * 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_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1463, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1463, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1464 + * 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_10 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1464, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_8 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_1, __pyx_t_10) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_10); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1463, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_Dict_GetItem(__pyx_t_8, __pyx_n_u_nodata); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1464, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1465 + * 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, 1465, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_10 = __Pyx_PyInt_SubtractObjC(__pyx_t_8, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1465, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1464 + * 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_7, __pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1464, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_v_raw_weight_nodata = __pyx_t_8; + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1466 + * 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_5 = (__pyx_v_raw_weight_nodata != Py_None); + __pyx_t_6 = (__pyx_t_5 != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/routing/routing.pyx":1467 + * 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, 1467, __pyx_L1_error) + __pyx_v_weight_nodata = __pyx_t_11; + + /* "pygeoprocessing/routing/routing.pyx":1466 + * 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":1460 + * + * 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":1469 + * 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_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1469, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1469, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1470 + * + * 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_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, 1470, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_8 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_1, __pyx_t_10) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_10); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1469, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_flow_dir_raster_info = __pyx_t_8; + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1471 + * 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_u_raster_size); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1471, __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, 1471, __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_10 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_7 = PyList_GET_ITEM(sequence, 0); + __pyx_t_10 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_10); + #else + __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1471, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1471, __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_1 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1471, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_12 = Py_TYPE(__pyx_t_1)->tp_iternext; + index = 0; __pyx_t_7 = __pyx_t_12(__pyx_t_1); if (unlikely(!__pyx_t_7)) goto __pyx_L9_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_1); if (unlikely(!__pyx_t_10)) goto __pyx_L9_unpacking_failed; + __Pyx_GOTREF(__pyx_t_10); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_1), 2) < 0) __PYX_ERR(0, 1471, __pyx_L1_error) + __pyx_t_12 = NULL; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L10_unpacking_done; + __pyx_L9_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, 1471, __pyx_L1_error) + __pyx_L10_unpacking_done:; + } + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1471, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_10); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1471, __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":1473 + * 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_u_nodata); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1473, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + + /* "pygeoprocessing/routing/routing.pyx":1474 + * + * 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, 1474, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_7 = __Pyx_PyInt_SubtractObjC(__pyx_t_10, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1474, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1473 + * 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_7); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1473, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_tmp_flow_dir_nodata = __pyx_t_10; + __pyx_t_10 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1475 + * 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_6 = (__pyx_v_tmp_flow_dir_nodata == Py_None); + __pyx_t_5 = (__pyx_t_6 != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1476 + * 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":1475 + * 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":1478 + * 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, 1478, __pyx_L1_error) + __pyx_v_flow_dir_nodata = __pyx_t_13; + } + __pyx_L11:; + + /* "pygeoprocessing/routing/routing.pyx":1481 + * + * # this outer loop searches for a pixel that is locally undrained + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * flow_dir_raster_path_band, offset_only=True, largest_block=0): + * win_xsize = offset_dict['win_xsize'] + */ + __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1481, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1481, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1482 + * # this outer loop searches for a pixel that is locally undrained + * for offset_dict in pygeoprocessing.iterblocks( + * flow_dir_raster_path_band, offset_only=True, largest_block=0): # <<<<<<<<<<<<<< + * win_xsize = offset_dict['win_xsize'] + * win_ysize = offset_dict['win_ysize'] + */ + __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1481, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_v_flow_dir_raster_path_band); + __Pyx_GIVEREF(__pyx_v_flow_dir_raster_path_band); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_flow_dir_raster_path_band); + __pyx_t_8 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1482, __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, 1482, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_largest_block, __pyx_int_0) < 0) __PYX_ERR(0, 1482, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":1481 + * + * # this outer loop searches for a pixel that is locally undrained + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * flow_dir_raster_path_band, offset_only=True, largest_block=0): + * win_xsize = offset_dict['win_xsize'] + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_10, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1481, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_8 = __pyx_t_1; __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_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1481, __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, 1481, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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_1 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_14); __Pyx_INCREF(__pyx_t_1); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 1481, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_8, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1481, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } else { + if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_8)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_14); __Pyx_INCREF(__pyx_t_1); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 1481, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_8, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1481, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } + } else { + __pyx_t_1 = __pyx_t_15(__pyx_t_8); + 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, 1481, __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":1483 + * for offset_dict in pygeoprocessing.iterblocks( + * flow_dir_raster_path_band, 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_u_win_xsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1483, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1483, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_win_xsize = __pyx_t_13; + + /* "pygeoprocessing/routing/routing.pyx":1484 + * flow_dir_raster_path_band, 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_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1484, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1484, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_win_ysize = __pyx_t_13; + + /* "pygeoprocessing/routing/routing.pyx":1485 + * 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_u_xoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1485, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1485, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_xoff = __pyx_t_13; + + /* "pygeoprocessing/routing/routing.pyx":1486 + * win_ysize = offset_dict['win_ysize'] + * xoff = offset_dict['xoff'] + * yoff = offset_dict['yoff'] # <<<<<<<<<<<<<< + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + */ + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_yoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1486, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1486, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_yoff = __pyx_t_13; + + /* "pygeoprocessing/routing/routing.pyx":1488 + * yoff = offset_dict['yoff'] + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + */ + __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1489 + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + */ + __pyx_v_last_log_time = time(NULL); + + /* "pygeoprocessing/routing/routing.pyx":1490 + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size # <<<<<<<<<<<<<< + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + * 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, 1490, __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":1491 + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< + * raster_x_size * raster_y_size)) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1491, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1491, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = PyNumber_Multiply(__pyx_float_100_0, __pyx_v_current_pixel); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1491, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + + /* "pygeoprocessing/routing/routing.pyx":1492 + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + * 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, 1491, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + + /* "pygeoprocessing/routing/routing.pyx":1491 + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< + * raster_x_size * raster_y_size)) + * + */ + __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_t_10, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1491, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 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_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); + __pyx_t_13 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_kp_u_1f_complete, __pyx_t_2}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1491, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 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_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_kp_u_1f_complete, __pyx_t_2}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1491, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + { + __pyx_t_10 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1491, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_INCREF(__pyx_kp_u_1f_complete); + __Pyx_GIVEREF(__pyx_kp_u_1f_complete); + PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_13, __pyx_kp_u_1f_complete); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_13, __pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1491, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1488 + * yoff = offset_dict['yoff'] + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + */ + } + + /* "pygeoprocessing/routing/routing.pyx":1495 + * + * # 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_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1495, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1495, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1496 + * # 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_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1496, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1496, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1496, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1496, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1496, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2); + __pyx_t_10 = 0; + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1495 + * + * # 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, 1495, __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 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1497 + * 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_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1497, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_numpy); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1497, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_uint8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1497, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 1497, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1495 + * + * # 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_7, __pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1495, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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, 1495, __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, 1495, __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":1498 + * (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, 1498, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_buffer_array), __pyx_slice__7, __pyx_t_3) < 0)) __PYX_ERR(0, 1498, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1501 + * + * # 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_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_generate_read_bounds); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1501, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":1502 + * # 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, 1502, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_raster_y_size); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1502, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_10 = NULL; + __pyx_t_13 = 0; + 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); + __pyx_t_13 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[4] = {__pyx_t_10, __pyx_v_offset_dict, __pyx_t_2, __pyx_t_7}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_13, 3+__pyx_t_13); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1501, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_3); + __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_1)) { + PyObject *__pyx_temp[4] = {__pyx_t_10, __pyx_v_offset_dict, __pyx_t_2, __pyx_t_7}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_13, 3+__pyx_t_13); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1501, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_20 = PyTuple_New(3+__pyx_t_13); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1501, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + if (__pyx_t_10) { + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_10); __pyx_t_10 = 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_7); + PyTuple_SET_ITEM(__pyx_t_20, 2+__pyx_t_13, __pyx_t_7); + __pyx_t_2 = 0; + __pyx_t_7 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_20, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1501, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 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, 1501, __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_20 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_1 = PyList_GET_ITEM(sequence, 0); + __pyx_t_20 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_20); + #else + __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1501, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_20 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1501, __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_7 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1501, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_12 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_12(__pyx_t_7); if (unlikely(!__pyx_t_1)) goto __pyx_L15_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 1; __pyx_t_20 = __pyx_t_12(__pyx_t_7); if (unlikely(!__pyx_t_20)) goto __pyx_L15_unpacking_failed; + __Pyx_GOTREF(__pyx_t_20); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_7), 2) < 0) __PYX_ERR(0, 1501, __pyx_L1_error) + __pyx_t_12 = 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_12 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 1501, __pyx_L1_error) + __pyx_L16_unpacking_done:; + } + + /* "pygeoprocessing/routing/routing.pyx":1501 + * + * # 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_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, 1501, __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_2 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_21 = PyTuple_GET_ITEM(sequence, 3); + } else { + __pyx_t_7 = PyList_GET_ITEM(sequence, 0); + __pyx_t_2 = PyList_GET_ITEM(sequence, 1); + __pyx_t_10 = PyList_GET_ITEM(sequence, 2); + __pyx_t_21 = PyList_GET_ITEM(sequence, 3); + } + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_21); + #else + { + Py_ssize_t i; + PyObject** temps[4] = {&__pyx_t_7,&__pyx_t_2,&__pyx_t_10,&__pyx_t_21}; + for (i=0; i < 4; i++) { + PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 1501, __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_7,&__pyx_t_2,&__pyx_t_10,&__pyx_t_21}; + __pyx_t_22 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 1501, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_22); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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, 1501, __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, 1501, __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_2); + __pyx_t_2 = 0; + __Pyx_XDECREF_SET(__pyx_v_ya, __pyx_t_10); + __pyx_t_10 = 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":1503 + * (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, 1503, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + + /* "pygeoprocessing/routing/routing.pyx":1504 + * 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, 1504, __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, 1504, __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, 1503, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } + + /* "pygeoprocessing/routing/routing.pyx":1503 + * (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_1); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 1503, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_21); + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1504 + * 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_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_21, __pyx_n_s_astype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1504, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_21, __pyx_n_s_numpy); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 1504, __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, 1504, __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_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); + } + } + __pyx_t_3 = (__pyx_t_21) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_21, __pyx_t_20) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_20); + __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1504, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1503 + * (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_1 = PySlice_New(__pyx_v_ya, __pyx_v_yb, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1503, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_20 = PySlice_New(__pyx_v_xa, __pyx_v_xb, Py_None); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1503, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __pyx_t_21 = PyTuple_New(2); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 1503, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_21); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_21, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_20); + PyTuple_SET_ITEM(__pyx_t_21, 1, __pyx_t_20); + __pyx_t_1 = 0; + __pyx_t_20 = 0; + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_buffer_array), __pyx_t_21, __pyx_t_3) < 0)) __PYX_ERR(0, 1503, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1507 + * + * # ensure these are set for the complier + * xi_n = -1 # <<<<<<<<<<<<<< + * yi_n = -1 + * + */ + __pyx_v_xi_n = -1; + + /* "pygeoprocessing/routing/routing.pyx":1508 + * # 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":1511 + * + * # 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":1512 + * # 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":1513 + * 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, 1513, __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":1514 + * 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_5 = ((__pyx_v_flow_dir == __pyx_v_flow_dir_nodata) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1515 + * flow_dir = flow_dir_buffer_array[yi, xi] + * if flow_dir == flow_dir_nodata: + * continue # <<<<<<<<<<<<<< + * + * xi_n = xi+D8_XOFFSET[flow_dir] + */ + goto __pyx_L21_continue; + + /* "pygeoprocessing/routing/routing.pyx":1514 + * 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":1517 + * continue + * + * xi_n = xi+D8_XOFFSET[flow_dir] # <<<<<<<<<<<<<< + * yi_n = yi+D8_YOFFSET[flow_dir] + * + */ + __pyx_v_xi_n = (__pyx_v_xi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_flow_dir])); + + /* "pygeoprocessing/routing/routing.pyx":1518 + * + * xi_n = xi+D8_XOFFSET[flow_dir] + * yi_n = yi+D8_YOFFSET[flow_dir] # <<<<<<<<<<<<<< + * + * if flow_dir_buffer_array[yi_n, xi_n] == flow_dir_nodata: + */ + __pyx_v_yi_n = (__pyx_v_yi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_flow_dir])); + + /* "pygeoprocessing/routing/routing.pyx":1520 + * yi_n = yi+D8_YOFFSET[flow_dir] + * + * if flow_dir_buffer_array[yi_n, xi_n] == flow_dir_nodata: # <<<<<<<<<<<<<< + * xi_root = xi-1+xoff + * yi_root = yi-1+yoff + */ + __pyx_t_28 = __pyx_v_yi_n; + __pyx_t_27 = __pyx_v_xi_n; + __pyx_t_29 = -1; + if (__pyx_t_28 < 0) { + __pyx_t_28 += __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].shape; + if (unlikely(__pyx_t_28 < 0)) __pyx_t_29 = 0; + } else if (unlikely(__pyx_t_28 >= __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].shape)) __pyx_t_29 = 0; + if (__pyx_t_27 < 0) { + __pyx_t_27 += __pyx_pybuffernd_flow_dir_buffer_array.diminfo[1].shape; + if (unlikely(__pyx_t_27 < 0)) __pyx_t_29 = 1; + } else if (unlikely(__pyx_t_27 >= __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, 1520, __pyx_L1_error) + } + __pyx_t_5 = (((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer.buf, __pyx_t_28, __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].strides, __pyx_t_27, __pyx_pybuffernd_flow_dir_buffer_array.diminfo[1].strides)) == __pyx_v_flow_dir_nodata) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1521 + * + * 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":1522 + * 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":1524 + * yi_root = yi-1+yoff + * + * if weight_raster is not None: # <<<<<<<<<<<<<< + * weight_val = weight_raster.get( + * xi_root, yi_root) + */ + __pyx_t_5 = (((PyObject *)__pyx_v_weight_raster) != Py_None); + __pyx_t_6 = (__pyx_t_5 != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/routing/routing.pyx":1525 + * + * if weight_raster is not None: + * weight_val = weight_raster.get( # <<<<<<<<<<<<<< + * xi_root, yi_root) + * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): + */ + __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":1527 + * weight_val = weight_raster.get( + * xi_root, yi_root) + * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * weight_val = 0.0 + * else: + */ + __pyx_t_6 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_weight_val, __pyx_v_weight_nodata, 1e-8, 1e-5) != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/routing/routing.pyx":1528 + * xi_root, yi_root) + * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): + * weight_val = 0.0 # <<<<<<<<<<<<<< + * else: + * weight_val = 1.0 + */ + __pyx_v_weight_val = 0.0; + + /* "pygeoprocessing/routing/routing.pyx":1527 + * weight_val = weight_raster.get( + * xi_root, yi_root) + * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * weight_val = 0.0 + * else: + */ + } + + /* "pygeoprocessing/routing/routing.pyx":1524 + * yi_root = yi-1+yoff + * + * if weight_raster is not None: # <<<<<<<<<<<<<< + * weight_val = weight_raster.get( + * xi_root, yi_root) + */ + goto __pyx_L25; + } + + /* "pygeoprocessing/routing/routing.pyx":1530 + * 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":1532 + * weight_val = 1.0 + * search_stack.push( + * FlowPixelType(xi_root, yi_root, 0, weight_val)) # <<<<<<<<<<<<<< + * + * while not search_stack.empty(): + */ + __pyx_t_30.xi = __pyx_v_xi_root; + __pyx_t_30.yi = __pyx_v_yi_root; + __pyx_t_30.last_flow_dir = 0; + __pyx_t_30.value = __pyx_v_weight_val; + + /* "pygeoprocessing/routing/routing.pyx":1531 + * else: + * weight_val = 1.0 + * search_stack.push( # <<<<<<<<<<<<<< + * FlowPixelType(xi_root, yi_root, 0, weight_val)) + * + */ + __pyx_v_search_stack.push(__pyx_t_30); + + /* "pygeoprocessing/routing/routing.pyx":1520 + * yi_n = yi+D8_YOFFSET[flow_dir] + * + * 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":1534 + * 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_6 = ((!(__pyx_v_search_stack.empty() != 0)) != 0); + if (!__pyx_t_6) break; + + /* "pygeoprocessing/routing/routing.pyx":1535 + * + * 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":1536 + * while not search_stack.empty(): + * flow_pixel = search_stack.top() + * search_stack.pop() # <<<<<<<<<<<<<< + * + * preempted = 0 + */ + __pyx_v_search_stack.pop(); + + /* "pygeoprocessing/routing/routing.pyx":1538 + * search_stack.pop() + * + * preempted = 0 # <<<<<<<<<<<<<< + * for i_n in range(flow_pixel.last_flow_dir, 8): + * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] + */ + __pyx_v_preempted = 0; + + /* "pygeoprocessing/routing/routing.pyx":1539 + * + * preempted = 0 + * for i_n in range(flow_pixel.last_flow_dir, 8): # <<<<<<<<<<<<<< + * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] + * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] + */ + 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":1540 + * preempted = 0 + * for i_n in range(flow_pixel.last_flow_dir, 8): + * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< + * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] + * 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_D8_XOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":1541 + * for i_n in range(flow_pixel.last_flow_dir, 8): + * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] + * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< + * 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_D8_YOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":1542 + * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] + * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] + * 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_5 = ((__pyx_v_xi_n < 0) != 0); + if (!__pyx_t_5) { + } else { + __pyx_t_6 = __pyx_t_5; + goto __pyx_L32_bool_binop_done; + } + __pyx_t_5 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0); + if (!__pyx_t_5) { + } else { + __pyx_t_6 = __pyx_t_5; + goto __pyx_L32_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":1543 + * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] + * 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_5 = ((__pyx_v_yi_n < 0) != 0); + if (!__pyx_t_5) { + } else { + __pyx_t_6 = __pyx_t_5; + goto __pyx_L32_bool_binop_done; + } + __pyx_t_5 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0); + __pyx_t_6 = __pyx_t_5; + __pyx_L32_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":1542 + * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] + * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] + * 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":1545 + * yi_n < 0 or yi_n >= raster_y_size): + * # no upstream here + * continue # <<<<<<<<<<<<<< + * upstream_flow_dir = flow_dir_managed_raster.get( + * xi_n, yi_n) + */ + goto __pyx_L29_continue; + + /* "pygeoprocessing/routing/routing.pyx":1542 + * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] + * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] + * 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":1546 + * # no upstream here + * continue + * upstream_flow_dir = 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":1548 + * upstream_flow_dir = 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_5 = ((__pyx_v_upstream_flow_dir == __pyx_v_flow_dir_nodata) != 0); + if (!__pyx_t_5) { + } else { + __pyx_t_6 = __pyx_t_5; + goto __pyx_L37_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":1549 + * 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_5 = ((__pyx_v_upstream_flow_dir != (__pyx_v_15pygeoprocessing_7routing_7routing_D8_REVERSE_DIRECTION[__pyx_v_i_n])) != 0); + __pyx_t_6 = __pyx_t_5; + __pyx_L37_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":1548 + * upstream_flow_dir = 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_6) { + + /* "pygeoprocessing/routing/routing.pyx":1552 + * D8_REVERSE_DIRECTION[i_n]): + * # no upstream here + * continue # <<<<<<<<<<<<<< + * upstream_flow_accum = ( + * flow_accum_managed_raster.get(xi_n, yi_n)) + */ + goto __pyx_L29_continue; + + /* "pygeoprocessing/routing/routing.pyx":1548 + * upstream_flow_dir = 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":1553 + * # no upstream here + * continue + * upstream_flow_accum = ( # <<<<<<<<<<<<<< + * flow_accum_managed_raster.get(xi_n, yi_n)) + * if _is_close(upstream_flow_accum, flow_accum_nodata, 1e-8, 1e-5): + */ + __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":1555 + * upstream_flow_accum = ( + * flow_accum_managed_raster.get(xi_n, yi_n)) + * if _is_close(upstream_flow_accum, flow_accum_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * # 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, 1e-8, 1e-5) != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/routing/routing.pyx":1557 + * if _is_close(upstream_flow_accum, flow_accum_nodata, 1e-8, 1e-5): + * # 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":1558 + * # 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 = weight_raster.get( + */ + __pyx_v_search_stack.push(__pyx_v_flow_pixel); + + /* "pygeoprocessing/routing/routing.pyx":1559 + * flow_pixel.last_flow_dir = i_n + * search_stack.push(flow_pixel) + * if weight_raster is not None: # <<<<<<<<<<<<<< + * weight_val = weight_raster.get( + * xi_n, yi_n) + */ + __pyx_t_6 = (((PyObject *)__pyx_v_weight_raster) != Py_None); + __pyx_t_5 = (__pyx_t_6 != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1560 + * search_stack.push(flow_pixel) + * if weight_raster is not None: + * weight_val = weight_raster.get( # <<<<<<<<<<<<<< + * xi_n, yi_n) + * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): + */ + __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":1562 + * weight_val = weight_raster.get( + * xi_n, yi_n) + * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * weight_val = 0.0 + * else: + */ + __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_weight_val, __pyx_v_weight_nodata, 1e-8, 1e-5) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1563 + * xi_n, yi_n) + * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): + * weight_val = 0.0 # <<<<<<<<<<<<<< + * else: + * weight_val = 1.0 + */ + __pyx_v_weight_val = 0.0; + + /* "pygeoprocessing/routing/routing.pyx":1562 + * weight_val = weight_raster.get( + * xi_n, yi_n) + * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * weight_val = 0.0 + * else: + */ + } + + /* "pygeoprocessing/routing/routing.pyx":1559 + * flow_pixel.last_flow_dir = i_n + * search_stack.push(flow_pixel) + * if weight_raster is not None: # <<<<<<<<<<<<<< + * weight_val = weight_raster.get( + * xi_n, yi_n) + */ + goto __pyx_L40; + } + + /* "pygeoprocessing/routing/routing.pyx":1565 + * 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":1567 + * weight_val = 1.0 + * search_stack.push( + * FlowPixelType(xi_n, yi_n, 0, weight_val)) # <<<<<<<<<<<<<< + * preempted = 1 + * break + */ + __pyx_t_30.xi = __pyx_v_xi_n; + __pyx_t_30.yi = __pyx_v_yi_n; + __pyx_t_30.last_flow_dir = 0; + __pyx_t_30.value = __pyx_v_weight_val; + + /* "pygeoprocessing/routing/routing.pyx":1566 + * 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_30); + + /* "pygeoprocessing/routing/routing.pyx":1568 + * 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":1569 + * 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":1555 + * upstream_flow_accum = ( + * flow_accum_managed_raster.get(xi_n, yi_n)) + * if _is_close(upstream_flow_accum, flow_accum_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * # process upstream before this one + * flow_pixel.last_flow_dir = i_n + */ + } + + /* "pygeoprocessing/routing/routing.pyx":1570 + * 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":1571 + * break + * flow_pixel.value += upstream_flow_accum + * if not preempted: # <<<<<<<<<<<<<< + * flow_accum_managed_raster.set( + * flow_pixel.xi, flow_pixel.yi, + */ + __pyx_t_5 = ((!(__pyx_v_preempted != 0)) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1572 + * 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":1571 + * 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":1481 + * + * # this outer loop searches for a pixel that is locally undrained + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * flow_dir_raster_path_band, offset_only=True, largest_block=0): + * win_xsize = offset_dict['win_xsize'] + */ + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1575 + * 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, 1575, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_21 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_21)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_21); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_8 = (__pyx_t_21) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_21) : __Pyx_PyObject_CallNoArg(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1575, __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":1576 + * 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, 1576, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_21 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_21)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_21); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_8 = (__pyx_t_21) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_21) : __Pyx_PyObject_CallNoArg(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1576, __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":1577 + * 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_5 = (((PyObject *)__pyx_v_weight_raster) != Py_None); + __pyx_t_6 = (__pyx_t_5 != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/routing/routing.pyx":1578 + * 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, 1578, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_21 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_21)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_21); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_8 = (__pyx_t_21) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_21) : __Pyx_PyObject_CallNoArg(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1578, __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":1577 + * 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":1579 + * if weight_raster is not None: + * weight_raster.close() + * LOGGER.info('%.1f%% complete', 100.0) # <<<<<<<<<<<<<< + * + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1579, __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, 1579, __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__9, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1579, __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":1359 + * + * + * 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_7); + __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":1582 + * + * + * def flow_dir_mfd( # <<<<<<<<<<<<<< + * dem_raster_path_band, target_flow_dir_path, working_dir=None, + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_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 (str): 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 3 2 1\n 4 x 0\n 5 6 7\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``\n is one of the 8 directions indicated above.\n working_dir (str): 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 raster_driver_creation_tuple (tuple): a tuple containing a GDAL driver\n name string as the first element and a GDAL creation options\n tuple/list as the second. Defaults to a GTiff driver tuple\n defined at geoprocessing.DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS.\n\n Returns:\n None.\n "; +static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_9flow_dir_mfd = {"flow_dir_mfd", (PyCFunction)(void*)(PyCFunctionWithKeywords)__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_raster_driver_creation_tuple = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 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_raster_driver_creation_tuple,0}; + PyObject* values[4] = {0,0,0,0}; + + /* "pygeoprocessing/routing/routing.pyx":1583 + * + * def flow_dir_mfd( + * dem_raster_path_band, target_flow_dir_path, working_dir=None, # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): + * """Multiple flow direction. + */ + values[2] = ((PyObject *)Py_None); + values[3] = __pyx_k__10; + 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, 1582, __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_raster_driver_creation_tuple); + 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, 1582, __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_raster_driver_creation_tuple = 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, 1582, __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_raster_driver_creation_tuple); + + /* "pygeoprocessing/routing/routing.pyx":1582 + * + * + * def flow_dir_mfd( # <<<<<<<<<<<<<< + * dem_raster_path_band, target_flow_dir_path, working_dir=None, + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_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_raster_driver_creation_tuple) { + 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 __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 __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_raster_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; + int __pyx_t_5; + int __pyx_t_6; + double __pyx_t_7; + PyObject *(*__pyx_t_8)(PyObject *); + int __pyx_t_9; + int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + 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; + int __pyx_t_29; + struct __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateType __pyx_t_30; + __pyx_t_15pygeoprocessing_7routing_7routing_IntQueueType __pyx_t_31; + __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateQueueType __pyx_t_32; + size_t __pyx_t_33; + size_t __pyx_t_34; + size_t __pyx_t_35; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __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":1680 + * # 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":1684 + * # 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1684, __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, 1684, __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, 1684, __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); + } + } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1684, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __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":1685 + * # 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_u_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1685, __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, 1685, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_t_3, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1685, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1685, __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_v_base_nodata = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1686 + * 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_5 = (__pyx_v_base_nodata != Py_None); + __pyx_t_6 = (__pyx_t_5 != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/routing/routing.pyx":1688 + * 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1688, __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, 1688, __pyx_L1_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); + } + } + __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_v_base_nodata) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_base_nodata); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1688, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_7 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 1688, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_dem_nodata = __pyx_t_7; + + /* "pygeoprocessing/routing/routing.pyx":1686 + * 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":1691 + * 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":1694 + * + * # 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_u_raster_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1694, __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, 1694, __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, 1694, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1694, __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_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1694, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_4)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_8(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + 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, 1694, __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, 1694, __pyx_L1_error) + __pyx_L5_unpacking_done:; + } + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1694, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1694, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_raster_x_size = __pyx_t_9; + __pyx_v_raster_y_size = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":1697 + * + * # 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":1700 + * + * # 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_11, &__pyx_t_12, &__pyx_t_13); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_13); + /*try:*/ { + + /* "pygeoprocessing/routing/routing.pyx":1701 + * # set up the working dir for the mask rasters + * try: + * if working_dir is not None: # <<<<<<<<<<<<<< + * os.makedirs(working_dir) + * except OSError: + */ + __pyx_t_6 = (__pyx_v_working_dir != Py_None); + __pyx_t_5 = (__pyx_t_6 != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1702 + * try: + * if working_dir is not None: + * os.makedirs(working_dir) # <<<<<<<<<<<<<< + * except OSError: + * pass + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1702, __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, 1702, __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); + } + } + __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_v_working_dir) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_working_dir); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1702, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1701 + * # 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":1700 + * + * # set up the working dir for the mask rasters + * try: # <<<<<<<<<<<<<< + * if working_dir is not None: + * os.makedirs(working_dir) + */ + } + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + goto __pyx_L11_try_end; + __pyx_L6_error:; + __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; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1703 + * if working_dir is not None: + * os.makedirs(working_dir) + * except OSError: # <<<<<<<<<<<<<< + * pass + * working_dir_path = tempfile.mkdtemp( + */ + __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OSError); + if (__pyx_t_10) { + __Pyx_ErrRestore(0,0,0); + goto __pyx_L7_exception_handled; + } + goto __pyx_L8_except_error; + __pyx_L8_except_error:; + + /* "pygeoprocessing/routing/routing.pyx":1700 + * + * # set up the working dir for the mask rasters + * try: # <<<<<<<<<<<<<< + * if working_dir is not None: + * os.makedirs(working_dir) + */ + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_13); + __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13); + goto __pyx_L1_error; + __pyx_L7_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_13); + __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13); + __pyx_L11_try_end:; + } + + /* "pygeoprocessing/routing/routing.pyx":1705 + * except OSError: + * pass + * working_dir_path = tempfile.mkdtemp( # <<<<<<<<<<<<<< + * dir=working_dir, + * prefix='flow_dir_multiple_flow_dir_%s_' % time.strftime( + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_tempfile); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1705, __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, 1705, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1706 + * 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, 1706, __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, 1706, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":1707 + * 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_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_time); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1707, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_strftime); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1707, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1708 + * 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_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_time); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1708, __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, 1708, __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); + } + } + __pyx_t_4 = (__pyx_t_15) ? __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_t_15) : __Pyx_PyObject_CallNoArg(__pyx_t_16); + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1708, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __pyx_t_16 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_16)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_16); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + __pyx_t_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_kp_u_Y_m_d__H__M__S, __pyx_t_4}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1707, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 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_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_kp_u_Y_m_d__H__M__S, __pyx_t_4}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1707, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_15 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1707, __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_u_Y_m_d__H__M__S); + __Pyx_GIVEREF(__pyx_kp_u_Y_m_d__H__M__S); + PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_10, __pyx_kp_u_Y_m_d__H__M__S); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_10, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_15, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1707, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1707 + * 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_14 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_flow_dir_multiple_flow_dir__s, __pyx_t_2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1707, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_prefix, __pyx_t_14) < 0) __PYX_ERR(0, 1706, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1705 + * except OSError: + * pass + * working_dir_path = tempfile.mkdtemp( # <<<<<<<<<<<<<< + * dir=working_dir, + * prefix='flow_dir_multiple_flow_dir_%s_' % time.strftime( + */ + __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1705, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __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_14; + __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1713 + * # 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1713, __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, 1713, __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, 1713, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1714 + * # 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_10 = 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_10 = 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_u_flat_region_mask_tif}; + __pyx_t_14 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1713, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_14); + } 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_u_flat_region_mask_tif}; + __pyx_t_14 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1713, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_14); + } else + #endif + { + __pyx_t_2 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1713, __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_v_working_dir_path); + __Pyx_GIVEREF(__pyx_v_working_dir_path); + PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_10, __pyx_v_working_dir_path); + __Pyx_INCREF(__pyx_kp_u_flat_region_mask_tif); + __Pyx_GIVEREF(__pyx_kp_u_flat_region_mask_tif); + PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_10, __pyx_kp_u_flat_region_mask_tif); + __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1713, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_flat_region_mask_path = __pyx_t_14; + __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1715 + * 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], + */ + __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1715, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1715, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1716 + * 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], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + */ + __pyx_t_14 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1716, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1716, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1716, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1717 + * pygeoprocessing.new_raster_from_base( + * dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte, + * [mask_nodata], # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * flat_region_mask_managed_raster = _ManagedRaster( + */ + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_mask_nodata); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1717, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_15 = PyList_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1717, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_GIVEREF(__pyx_t_2); + PyList_SET_ITEM(__pyx_t_15, 0, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1715 + * 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], + */ + __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1715, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_14); + __Pyx_INCREF(__pyx_v_flat_region_mask_path); + __Pyx_GIVEREF(__pyx_v_flat_region_mask_path); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_flat_region_mask_path); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_15); + PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_15); + __pyx_t_14 = 0; + __pyx_t_1 = 0; + __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1718 + * dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte, + * [mask_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< + * flat_region_mask_managed_raster = _ManagedRaster( + * flat_region_mask_path, 1, 1) + */ + __pyx_t_15 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1718, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 1718, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":1715 + * 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], + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1715, __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_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1719 + * [mask_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * flat_region_mask_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< + * flat_region_mask_path, 1, 1) + * + */ + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1719, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_flat_region_mask_path); + __Pyx_GIVEREF(__pyx_v_flat_region_mask_path); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_flat_region_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_15 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_1, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1719, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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":1722 + * 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":1723 + * + * flow_dir_nodata = 0 + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Int32, + * [flow_dir_nodata], + */ + __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1723, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1723, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1724 + * flow_dir_nodata = 0 + * pygeoprocessing.new_raster_from_base( + * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Int32, # <<<<<<<<<<<<<< + * [flow_dir_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + */ + __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, 1724, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1724, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_GDT_Int32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1724, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1725 + * pygeoprocessing.new_raster_from_base( + * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Int32, + * [flow_dir_nodata], # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * flow_dir_managed_raster = _ManagedRaster(target_flow_dir_path, 1, 1) + */ + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_flow_dir_nodata); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1725, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_14 = PyList_New(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1725, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GIVEREF(__pyx_t_2); + PyList_SET_ITEM(__pyx_t_14, 0, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1723 + * + * flow_dir_nodata = 0 + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Int32, + * [flow_dir_nodata], + */ + __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1723, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_15); + PyTuple_SET_ITEM(__pyx_t_2, 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_2, 1, __pyx_v_target_flow_dir_path); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_14); + __pyx_t_15 = 0; + __pyx_t_3 = 0; + __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1726 + * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Int32, + * [flow_dir_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< + * flow_dir_managed_raster = _ManagedRaster(target_flow_dir_path, 1, 1) + * + */ + __pyx_t_14 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1726, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 1726, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":1723 + * + * flow_dir_nodata = 0 + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Int32, + * [flow_dir_nodata], + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_14); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1723, __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_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1727 + * [flow_dir_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * flow_dir_managed_raster = _ManagedRaster(target_flow_dir_path, 1, 1) # <<<<<<<<<<<<<< + * + * plateu_drain_mask_path = os.path.join( + */ + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1727, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_target_flow_dir_path); + __Pyx_GIVEREF(__pyx_v_target_flow_dir_path); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_target_flow_dir_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_14 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_3, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1727, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_flow_dir_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_14); + __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1729 + * 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1729, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_path); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1729, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_join); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1729, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1730 + * + * 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_2 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && likely(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_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_working_dir_path, __pyx_kp_u_plateu_drain_mask_tif}; + __pyx_t_14 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1729, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_14); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_working_dir_path, __pyx_kp_u_plateu_drain_mask_tif}; + __pyx_t_14 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1729, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_14); + } else + #endif + { + __pyx_t_1 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1729, __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_v_working_dir_path); + __Pyx_GIVEREF(__pyx_v_working_dir_path); + PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_10, __pyx_v_working_dir_path); + __Pyx_INCREF(__pyx_kp_u_plateu_drain_mask_tif); + __Pyx_GIVEREF(__pyx_kp_u_plateu_drain_mask_tif); + PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_10, __pyx_kp_u_plateu_drain_mask_tif); + __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1729, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_plateu_drain_mask_path = __pyx_t_14; + __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1731 + * 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], + */ + __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1731, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1731, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1732 + * 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], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + */ + __pyx_t_14 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1732, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1732, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1732, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1733 + * pygeoprocessing.new_raster_from_base( + * dem_raster_path_band[0], plateu_drain_mask_path, gdal.GDT_Byte, + * [mask_nodata], # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * plateau_drain_mask_managed_raster = _ManagedRaster( + */ + __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_mask_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1733, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_15 = PyList_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1733, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_GIVEREF(__pyx_t_1); + PyList_SET_ITEM(__pyx_t_15, 0, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1731 + * 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], + */ + __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1731, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_14); + __Pyx_INCREF(__pyx_v_plateu_drain_mask_path); + __Pyx_GIVEREF(__pyx_v_plateu_drain_mask_path); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_plateu_drain_mask_path); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_15); + PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_15); + __pyx_t_14 = 0; + __pyx_t_2 = 0; + __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1734 + * dem_raster_path_band[0], plateu_drain_mask_path, gdal.GDT_Byte, + * [mask_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< + * plateau_drain_mask_managed_raster = _ManagedRaster( + * plateu_drain_mask_path, 1, 1) + */ + __pyx_t_15 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1734, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 1734, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":1731 + * 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], + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, __pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1731, __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; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1735 + * [mask_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * plateau_drain_mask_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< + * plateu_drain_mask_path, 1, 1) + * + */ + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1735, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_plateu_drain_mask_path); + __Pyx_GIVEREF(__pyx_v_plateu_drain_mask_path); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_plateu_drain_mask_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_15 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_2, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1735, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_plateau_drain_mask_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_15); + __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1742 + * # 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1742, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1742, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_join); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1742, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1743 + * # 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_1 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + __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_1, __pyx_v_working_dir_path, __pyx_kp_u_plateau_distance_tif}; + __pyx_t_15 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1742, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_15); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_working_dir_path, __pyx_kp_u_plateau_distance_tif}; + __pyx_t_15 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1742, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_15); + } else + #endif + { + __pyx_t_3 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1742, __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_INCREF(__pyx_v_working_dir_path); + __Pyx_GIVEREF(__pyx_v_working_dir_path); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_10, __pyx_v_working_dir_path); + __Pyx_INCREF(__pyx_kp_u_plateau_distance_tif); + __Pyx_GIVEREF(__pyx_kp_u_plateau_distance_tif); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_10, __pyx_kp_u_plateau_distance_tif); + __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1742, __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_v_plateau_distance_path = __pyx_t_15; + __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1744 + * 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":1745 + * 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_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1745, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1745, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1746 + * 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_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, 1746, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1746, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1746, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1747 + * 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], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + */ + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_plateau_distance_nodata); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1747, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_14 = PyList_New(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1747, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GIVEREF(__pyx_t_3); + PyList_SET_ITEM(__pyx_t_14, 0, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1745 + * 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 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1745, __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_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_1); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_14); + __pyx_t_15 = 0; + __pyx_t_1 = 0; + __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1747 + * 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], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + */ + __pyx_t_14 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1747, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + + /* "pygeoprocessing/routing/routing.pyx":1748 + * dem_raster_path_band[0], plateau_distance_path, gdal.GDT_Float64, + * [plateau_distance_nodata], fill_value_list=[ + * raster_x_size * raster_y_size], # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * plateau_distance_managed_raster = _ManagedRaster( + */ + __pyx_t_1 = __Pyx_PyInt_From_int((__pyx_v_raster_x_size * __pyx_v_raster_y_size)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1748, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":1747 + * 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], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + */ + __pyx_t_15 = PyList_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1747, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_GIVEREF(__pyx_t_1); + PyList_SET_ITEM(__pyx_t_15, 0, __pyx_t_1); + __pyx_t_1 = 0; + if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_fill_value_list, __pyx_t_15) < 0) __PYX_ERR(0, 1747, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1749 + * [plateau_distance_nodata], fill_value_list=[ + * raster_x_size * raster_y_size], + * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< + * plateau_distance_managed_raster = _ManagedRaster( + * plateau_distance_path, 1, 1) + */ + if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 1747, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":1745 + * 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 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_14); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1745, __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_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1750 + * raster_x_size * raster_y_size], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * plateau_distance_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< + * plateau_distance_path, 1, 1) + * + */ + __pyx_t_15 = PyTuple_New(3); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1750, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_INCREF(__pyx_v_plateau_distance_path); + __Pyx_GIVEREF(__pyx_v_plateau_distance_path); + PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_v_plateau_distance_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_14 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_15, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1750, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_v_plateau_distance_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_14); + __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1754 + * + * # 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":1755 + * # 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_14 = __Pyx_PyObject_Dict_GetItem(__pyx_v_dem_raster_info, __pyx_n_u_block_size); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1755, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + if ((likely(PyTuple_CheckExact(__pyx_t_14))) || (PyList_CheckExact(__pyx_t_14))) { + PyObject* sequence = __pyx_t_14; + 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, 1755, __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_3 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_15 = PyList_GET_ITEM(sequence, 0); + __pyx_t_3 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_15); + __Pyx_INCREF(__pyx_t_3); + #else + __pyx_t_15 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1755, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1755, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_2 = PyObject_GetIter(__pyx_t_14); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1755, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_2)->tp_iternext; + index = 0; __pyx_t_15 = __pyx_t_8(__pyx_t_2); if (unlikely(!__pyx_t_15)) goto __pyx_L13_unpacking_failed; + __Pyx_GOTREF(__pyx_t_15); + index = 1; __pyx_t_3 = __pyx_t_8(__pyx_t_2); if (unlikely(!__pyx_t_3)) goto __pyx_L13_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_2), 2) < 0) __PYX_ERR(0, 1755, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L14_unpacking_done; + __pyx_L13_unpacking_failed:; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 1755, __pyx_L1_error) + __pyx_L14_unpacking_done:; + } + __pyx_v_dem_block_xsize = __pyx_t_15; + __pyx_t_15 = 0; + __pyx_v_dem_block_ysize = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1756 + * 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_14 = __Pyx_PyInt_SubtractObjC(__pyx_v_dem_block_xsize, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1756, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_3 = PyNumber_And(__pyx_v_dem_block_xsize, __pyx_t_14); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1756, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_14 = __Pyx_PyInt_NeObjC(__pyx_t_3, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1756, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1756, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L16_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":1757 + * 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_14 = __Pyx_PyInt_SubtractObjC(__pyx_v_dem_block_ysize, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1757, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_3 = PyNumber_And(__pyx_v_dem_block_ysize, __pyx_t_14); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1757, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_14 = __Pyx_PyInt_NeObjC(__pyx_t_3, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1757, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1757, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_5 = __pyx_t_6; + __pyx_L16_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":1756 + * 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_5) { + + /* "pygeoprocessing/routing/routing.pyx":1758 + * 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1758, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_warning); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1758, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(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_14 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_15, __pyx_t_3, __pyx_kp_u_dem_is_not_a_power_of_2_creating) : __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_kp_u_dem_is_not_a_power_of_2_creating); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1758, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1760 + * 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]) + * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) + */ + __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_os); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1760, __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, 1760, __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, 1760, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + __pyx_t_10 = 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_10 = 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_u_compatable_dem_tif}; + __pyx_t_14 = __Pyx_PyFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1760, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_14); + } 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_u_compatable_dem_tif}; + __pyx_t_14 = __Pyx_PyCFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1760, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_14); + } else + #endif + { + __pyx_t_2 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1760, __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_v_working_dir_path); + __Pyx_GIVEREF(__pyx_v_working_dir_path); + PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_10, __pyx_v_working_dir_path); + __Pyx_INCREF(__pyx_kp_u_compatable_dem_tif); + __Pyx_GIVEREF(__pyx_kp_u_compatable_dem_tif); + PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_10, __pyx_kp_u_compatable_dem_tif); + __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_2, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1760, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1761 + * compatable_dem_raster_path_band = ( + * os.path.join(working_dir_path, 'compatable_dem.tif'), + * dem_raster_path_band[1]) # <<<<<<<<<<<<<< + * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) + * 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, 1761, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + + /* "pygeoprocessing/routing/routing.pyx":1760 + * 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]) + * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) + */ + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1760, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_15); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_15); + __pyx_t_14 = 0; + __pyx_t_15 = 0; + __Pyx_DECREF_SET(__pyx_v_compatable_dem_raster_path_band, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1762 + * os.path.join(working_dir_path, 'compatable_dem.tif'), + * dem_raster_path_band[1]) + * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) # <<<<<<<<<<<<<< + * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) + * raster_driver.CreateCopy( + */ + __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_gdal); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1762, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_GetDriverByName); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1762, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = __Pyx_GetItemInt(__pyx_v_raster_driver_creation_tuple, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1762, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + } + } + __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_3, __pyx_t_15) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_t_15); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1762, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_v_raster_driver = __pyx_t_2; + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1763 + * dem_raster_path_band[1]) + * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) + * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) # <<<<<<<<<<<<<< + * raster_driver.CreateCopy( + * compatable_dem_raster_path_band[0], dem_raster, + */ + __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_gdal); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1763, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1763, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_14 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1763, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1763, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1763, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(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_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_15)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_t_14, __pyx_t_1}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1763, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_15)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_t_14, __pyx_t_1}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1763, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + { + __pyx_t_4 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1763, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_10, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_10, __pyx_t_1); + __pyx_t_14 = 0; + __pyx_t_1 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1763, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_v_dem_raster = __pyx_t_2; + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1764 + * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) + * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) + * raster_driver.CreateCopy( # <<<<<<<<<<<<<< + * compatable_dem_raster_path_band[0], dem_raster, + * options=raster_driver_creation_tuple[1]) + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster_driver, __pyx_n_s_CreateCopy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1764, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + + /* "pygeoprocessing/routing/routing.pyx":1765 + * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) + * raster_driver.CreateCopy( + * compatable_dem_raster_path_band[0], dem_raster, # <<<<<<<<<<<<<< + * options=raster_driver_creation_tuple[1]) + * dem_raster = None + */ + __pyx_t_15 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1765, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + + /* "pygeoprocessing/routing/routing.pyx":1764 + * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) + * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) + * raster_driver.CreateCopy( # <<<<<<<<<<<<<< + * compatable_dem_raster_path_band[0], dem_raster, + * options=raster_driver_creation_tuple[1]) + */ + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1764, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_15); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_15); + __Pyx_INCREF(__pyx_v_dem_raster); + __Pyx_GIVEREF(__pyx_v_dem_raster); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_dem_raster); + __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1766 + * raster_driver.CreateCopy( + * compatable_dem_raster_path_band[0], dem_raster, + * options=raster_driver_creation_tuple[1]) # <<<<<<<<<<<<<< + * dem_raster = None + * LOGGER.info("compatible dem complete") + */ + __pyx_t_15 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1766, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_raster_driver_creation_tuple, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1766, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_options, __pyx_t_1) < 0) __PYX_ERR(0, 1766, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1764 + * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) + * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) + * raster_driver.CreateCopy( # <<<<<<<<<<<<<< + * compatable_dem_raster_path_band[0], dem_raster, + * options=raster_driver_creation_tuple[1]) + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, __pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1764, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1767 + * compatable_dem_raster_path_band[0], dem_raster, + * options=raster_driver_creation_tuple[1]) + * 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":1768 + * options=raster_driver_creation_tuple[1]) + * dem_raster = None + * LOGGER.info("compatible dem complete") # <<<<<<<<<<<<<< + * else: + * compatable_dem_raster_path_band = dem_raster_path_band + */ + __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1768, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_info); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1768, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = NULL; + 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_1 = (__pyx_t_15) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_15, __pyx_kp_u_compatible_dem_complete) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_compatible_dem_complete); + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1768, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1756 + * 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":1770 + * 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":1772 + * 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_1 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1772, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":1773 + * 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, 1773, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "pygeoprocessing/routing/routing.pyx":1771 + * 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_15 = PyTuple_New(3); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1771, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_4); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_int_0); + __pyx_t_1 = 0; + __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_15, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1771, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_v_dem_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_4); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1776 + * + * # 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_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_gdal); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1776, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1776, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1777 + * # 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_15 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1777, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1777, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1777, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + __pyx_t_10 = 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_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_15, __pyx_t_14}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1776, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_15, __pyx_t_14}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1776, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } else + #endif + { + __pyx_t_3 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1776, __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_GIVEREF(__pyx_t_15); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_10, __pyx_t_15); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_10, __pyx_t_14); + __pyx_t_15 = 0; + __pyx_t_14 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1776, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_dem_raster, __pyx_t_4); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1778 + * 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_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_dem_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1778, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":1779 + * 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, 1779, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_14 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_14)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_4 = (__pyx_t_14) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_14, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3); + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1778, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_dem_band = __pyx_t_4; + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1782 + * + * # this outer loop searches for a pixel that is locally undrained + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * compatable_dem_raster_path_band, offset_only=True, + * largest_block=0): + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1782, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1782, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1783 + * # this outer loop searches for a pixel that is locally undrained + * for offset_dict in pygeoprocessing.iterblocks( + * compatable_dem_raster_path_band, offset_only=True, # <<<<<<<<<<<<<< + * largest_block=0): + * win_xsize = offset_dict['win_xsize'] + */ + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1782, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_compatable_dem_raster_path_band); + __Pyx_GIVEREF(__pyx_v_compatable_dem_raster_path_band); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_compatable_dem_raster_path_band); + __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1783, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 1783, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_largest_block, __pyx_int_0) < 0) __PYX_ERR(0, 1783, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":1782 + * + * # this outer loop searches for a pixel that is locally undrained + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * compatable_dem_raster_path_band, offset_only=True, + * largest_block=0): + */ + __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1782, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (likely(PyList_CheckExact(__pyx_t_14)) || PyTuple_CheckExact(__pyx_t_14)) { + __pyx_t_3 = __pyx_t_14; __Pyx_INCREF(__pyx_t_3); __pyx_t_17 = 0; + __pyx_t_18 = NULL; + } else { + __pyx_t_17 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_14); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1782, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_18 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 1782, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + for (;;) { + if (likely(!__pyx_t_18)) { + if (likely(PyList_CheckExact(__pyx_t_3))) { + if (__pyx_t_17 >= PyList_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_14 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_17); __Pyx_INCREF(__pyx_t_14); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 1782, __pyx_L1_error) + #else + __pyx_t_14 = PySequence_ITEM(__pyx_t_3, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1782, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + #endif + } else { + if (__pyx_t_17 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_14 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_17); __Pyx_INCREF(__pyx_t_14); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 1782, __pyx_L1_error) + #else + __pyx_t_14 = PySequence_ITEM(__pyx_t_3, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1782, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + #endif + } + } else { + __pyx_t_14 = __pyx_t_18(__pyx_t_3); + if (unlikely(!__pyx_t_14)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 1782, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_14); + } + __Pyx_XDECREF_SET(__pyx_v_offset_dict, __pyx_t_14); + __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1785 + * compatable_dem_raster_path_band, offset_only=True, + * largest_block=0): + * win_xsize = offset_dict['win_xsize'] # <<<<<<<<<<<<<< + * win_ysize = offset_dict['win_ysize'] + * xoff = offset_dict['xoff'] + */ + __pyx_t_14 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1785, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_14); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1785, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_v_win_xsize = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":1786 + * 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_14 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1786, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_14); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1786, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_v_win_ysize = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":1787 + * win_xsize = offset_dict['win_xsize'] + * win_ysize = offset_dict['win_ysize'] + * xoff = offset_dict['xoff'] # <<<<<<<<<<<<<< + * yoff = offset_dict['yoff'] + * + */ + __pyx_t_14 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_xoff); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1787, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_14); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1787, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_v_xoff = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":1788 + * win_ysize = offset_dict['win_ysize'] + * xoff = offset_dict['xoff'] + * yoff = offset_dict['yoff'] # <<<<<<<<<<<<<< + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + */ + __pyx_t_14 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_yoff); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1788, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_14); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1788, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_v_yoff = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":1790 + * yoff = offset_dict['yoff'] + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + */ + __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1791 + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + */ + __pyx_v_last_log_time = time(NULL); + + /* "pygeoprocessing/routing/routing.pyx":1792 + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size # <<<<<<<<<<<<<< + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + * raster_x_size * raster_y_size)) + */ + __pyx_t_14 = __Pyx_PyInt_From_int((__pyx_v_xoff + (__pyx_v_yoff * __pyx_v_raster_x_size))); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1792, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_XDECREF_SET(__pyx_v_current_pixel, __pyx_t_14); + __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1793 + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< + * raster_x_size * raster_y_size)) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1793, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1793, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyNumber_Multiply(__pyx_float_100_0, __pyx_v_current_pixel); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1793, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "pygeoprocessing/routing/routing.pyx":1794 + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + * 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, 1793, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + + /* "pygeoprocessing/routing/routing.pyx":1793 + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< + * raster_x_size * raster_y_size)) + * + */ + __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_t_4, __pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1793, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_15)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_15); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + __pyx_t_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_kp_u_1f_complete, __pyx_t_2}; + __pyx_t_14 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1793, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_GOTREF(__pyx_t_14); + __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_15, __pyx_kp_u_1f_complete, __pyx_t_2}; + __pyx_t_14 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1793, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + { + __pyx_t_4 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1793, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (__pyx_t_15) { + __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_15); __pyx_t_15 = NULL; + } + __Pyx_INCREF(__pyx_kp_u_1f_complete); + __Pyx_GIVEREF(__pyx_kp_u_1f_complete); + PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_10, __pyx_kp_u_1f_complete); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_10, __pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1793, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1790 + * yoff = offset_dict['yoff'] + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + */ + } + + /* "pygeoprocessing/routing/routing.pyx":1797 + * + * # 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_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_numpy); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1797, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1797, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1798 + * # 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_14 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1798, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_t_14, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1798, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_14 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1798, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_14, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1798, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_14 = PyTuple_New(2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1798, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_t_2); + __pyx_t_4 = 0; + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1797 + * + * # 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_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1797, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_14); + __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1799 + * 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_14 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1799, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_numpy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1799, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float64); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1799, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_dtype, __pyx_t_15) < 0) __PYX_ERR(0, 1799, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1797 + * + * # 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_1, __pyx_t_2, __pyx_t_14); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1797, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + if (!(likely(((__pyx_t_15) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_15, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1797, __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_10 = __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_10 < 0)) { + PyErr_Fetch(&__pyx_t_13, &__pyx_t_12, &__pyx_t_11); + 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_13); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_11); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_13, __pyx_t_12, __pyx_t_11); + } + __pyx_t_13 = __pyx_t_12 = __pyx_t_11 = 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_10 < 0)) __PYX_ERR(0, 1797, __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":1800 + * (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, 1800, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_dem_buffer_array), __pyx_slice__7, __pyx_t_15) < 0)) __PYX_ERR(0, 1800, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1804 + * # 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_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_generate_read_bounds); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1804, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + + /* "pygeoprocessing/routing/routing.pyx":1805 + * # 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_2 = __Pyx_PyInt_From_int(__pyx_v_raster_x_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1805, __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, 1805, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + __pyx_t_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_offset_dict, __pyx_t_2, __pyx_t_1}; + __pyx_t_15 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1804, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_15); + __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_14)) { + PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_offset_dict, __pyx_t_2, __pyx_t_1}; + __pyx_t_15 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1804, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + { + __pyx_t_16 = PyTuple_New(3+__pyx_t_10); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1804, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + if (__pyx_t_4) { + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_4); __pyx_t_4 = NULL; + } + __Pyx_INCREF(__pyx_v_offset_dict); + __Pyx_GIVEREF(__pyx_v_offset_dict); + PyTuple_SET_ITEM(__pyx_t_16, 0+__pyx_t_10, __pyx_v_offset_dict); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_16, 1+__pyx_t_10, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_16, 2+__pyx_t_10, __pyx_t_1); + __pyx_t_2 = 0; + __pyx_t_1 = 0; + __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_16, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1804, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 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, 1804, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_14 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_16 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_14 = PyList_GET_ITEM(sequence, 0); + __pyx_t_16 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(__pyx_t_16); + #else + __pyx_t_14 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1804, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_16 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1804, __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_1 = PyObject_GetIter(__pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1804, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_1)->tp_iternext; + index = 0; __pyx_t_14 = __pyx_t_8(__pyx_t_1); if (unlikely(!__pyx_t_14)) goto __pyx_L21_unpacking_failed; + __Pyx_GOTREF(__pyx_t_14); + index = 1; __pyx_t_16 = __pyx_t_8(__pyx_t_1); if (unlikely(!__pyx_t_16)) goto __pyx_L21_unpacking_failed; + __Pyx_GOTREF(__pyx_t_16); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_1), 2) < 0) __PYX_ERR(0, 1804, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L22_unpacking_done; + __pyx_L21_unpacking_failed:; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 1804, __pyx_L1_error) + __pyx_L22_unpacking_done:; + } + + /* "pygeoprocessing/routing/routing.pyx":1804 + * # 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_14))) || (PyList_CheckExact(__pyx_t_14))) { + PyObject* sequence = __pyx_t_14; + 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, 1804, __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_4 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_20 = PyTuple_GET_ITEM(sequence, 3); + } else { + __pyx_t_1 = PyList_GET_ITEM(sequence, 0); + __pyx_t_2 = PyList_GET_ITEM(sequence, 1); + __pyx_t_4 = PyList_GET_ITEM(sequence, 2); + __pyx_t_20 = PyList_GET_ITEM(sequence, 3); + } + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_20); + #else + { + Py_ssize_t i; + PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_2,&__pyx_t_4,&__pyx_t_20}; + for (i=0; i < 4; i++) { + PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 1804, __pyx_L1_error) + __Pyx_GOTREF(item); + *(temps[i]) = item; + } + } + #endif + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } else { + Py_ssize_t index = -1; + PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_2,&__pyx_t_4,&__pyx_t_20}; + __pyx_t_21 = PyObject_GetIter(__pyx_t_14); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 1804, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_21); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_21)->tp_iternext; + for (index=0; index < 4; index++) { + PyObject* item = __pyx_t_8(__pyx_t_21); if (unlikely(!item)) goto __pyx_L23_unpacking_failed; + __Pyx_GOTREF(item); + *(temps[index]) = item; + } + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_21), 4) < 0) __PYX_ERR(0, 1804, __pyx_L1_error) + __pyx_t_8 = 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_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 1804, __pyx_L1_error) + __pyx_L24_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_4); + __pyx_t_4 = 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":1806 + * (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, 1806, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + + /* "pygeoprocessing/routing/routing.pyx":1807 + * 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, 1807, __pyx_L1_error) + } + if (likely(PyDict_CheckExact(__pyx_v_modified_offset_dict))) { + __pyx_t_14 = PyDict_Copy(__pyx_v_modified_offset_dict); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1807, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + } else { + __pyx_t_14 = PyObject_CallFunctionObjArgs((PyObject*)&PyDict_Type, __pyx_v_modified_offset_dict, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1806, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + } + + /* "pygeoprocessing/routing/routing.pyx":1806 + * (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_14); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1806, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1807 + * 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_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_20, __pyx_n_s_astype); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1807, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_20, __pyx_n_s_numpy); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1807, __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, 1807, __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_14))) { + __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_20)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_20); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + } + } + __pyx_t_15 = (__pyx_t_20) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_20, __pyx_t_16) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_t_16); + __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1807, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1806 + * (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_14 = PySlice_New(__pyx_v_ya, __pyx_v_yb, Py_None); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1806, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_16 = PySlice_New(__pyx_v_xa, __pyx_v_xb, Py_None); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1806, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_20 = PyTuple_New(2); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1806, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_16); + PyTuple_SET_ITEM(__pyx_t_20, 1, __pyx_t_16); + __pyx_t_14 = 0; + __pyx_t_16 = 0; + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_dem_buffer_array), __pyx_t_20, __pyx_t_15) < 0)) __PYX_ERR(0, 1806, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1810 + * + * # ensure these are set for the complier + * xi_n = -1 # <<<<<<<<<<<<<< + * yi_n = -1 + * + */ + __pyx_v_xi_n = -1; + + /* "pygeoprocessing/routing/routing.pyx":1811 + * # 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":1814 + * + * # 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_10 = 1; __pyx_t_10 < __pyx_t_23; __pyx_t_10+=1) { + __pyx_v_yi = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":1815 + * # 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, 1e-8, 1e-5): + */ + __pyx_t_24 = (__pyx_v_win_xsize + 1); + __pyx_t_25 = __pyx_t_24; + for (__pyx_t_9 = 1; __pyx_t_9 < __pyx_t_25; __pyx_t_9+=1) { + __pyx_v_xi = __pyx_t_9; + + /* "pygeoprocessing/routing/routing.pyx":1816 + * 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, 1e-8, 1e-5): + * 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, 1816, __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":1817 + * for xi in range(1, win_xsize+1): + * root_height = dem_buffer_array[yi, xi] + * if _is_close(root_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_root_height, __pyx_v_dem_nodata, 1e-8, 1e-5) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1818 + * root_height = dem_buffer_array[yi, xi] + * if _is_close(root_height, dem_nodata, 1e-8, 1e-5): + * continue # <<<<<<<<<<<<<< + * + * # this value is set in case it turns out to be the root of a + */ + goto __pyx_L27_continue; + + /* "pygeoprocessing/routing/routing.pyx":1817 + * for xi in range(1, win_xsize+1): + * root_height = dem_buffer_array[yi, xi] + * if _is_close(root_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * continue + * + */ + } + + /* "pygeoprocessing/routing/routing.pyx":1823 + * # 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":1824 + * # 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":1827 + * + * if flow_dir_managed_raster.get( + * xi_root, yi_root) != flow_dir_nodata: # <<<<<<<<<<<<<< + * # already been defined + * continue + */ + __pyx_t_5 = ((__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":1826 + * yi_root = yi-1+yoff + * + * if flow_dir_managed_raster.get( # <<<<<<<<<<<<<< + * xi_root, yi_root) != flow_dir_nodata: + * # already been defined + */ + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1829 + * 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":1826 + * 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":1835 + * # 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":1836 + * # 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":1838 + * for i_n in range(8): + * # initialize downhill slopes to 0.0 + * downhill_slope_array[i_n] = 0.0 # <<<<<<<<<<<<<< + * xi_n = xi+D8_XOFFSET[i_n] + * yi_n = yi+D8_YOFFSET[i_n] + */ + (__pyx_v_downhill_slope_array[__pyx_v_i_n]) = 0.0; + + /* "pygeoprocessing/routing/routing.pyx":1839 + * # initialize downhill slopes to 0.0 + * downhill_slope_array[i_n] = 0.0 + * xi_n = xi+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< + * yi_n = yi+D8_YOFFSET[i_n] + * n_height = dem_buffer_array[yi_n, xi_n] + */ + __pyx_v_xi_n = (__pyx_v_xi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":1840 + * downhill_slope_array[i_n] = 0.0 + * xi_n = xi+D8_XOFFSET[i_n] + * yi_n = yi+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< + * n_height = dem_buffer_array[yi_n, xi_n] + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): + */ + __pyx_v_yi_n = (__pyx_v_yi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":1841 + * xi_n = xi+D8_XOFFSET[i_n] + * yi_n = yi+D8_YOFFSET[i_n] + * n_height = dem_buffer_array[yi_n, xi_n] # <<<<<<<<<<<<<< + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): + * continue + */ + __pyx_t_27 = __pyx_v_yi_n; + __pyx_t_26 = __pyx_v_xi_n; + __pyx_t_29 = -1; + if (__pyx_t_27 < 0) { + __pyx_t_27 += __pyx_pybuffernd_dem_buffer_array.diminfo[0].shape; + if (unlikely(__pyx_t_27 < 0)) __pyx_t_29 = 0; + } else if (unlikely(__pyx_t_27 >= __pyx_pybuffernd_dem_buffer_array.diminfo[0].shape)) __pyx_t_29 = 0; + if (__pyx_t_26 < 0) { + __pyx_t_26 += __pyx_pybuffernd_dem_buffer_array.diminfo[1].shape; + if (unlikely(__pyx_t_26 < 0)) __pyx_t_29 = 1; + } else if (unlikely(__pyx_t_26 >= __pyx_pybuffernd_dem_buffer_array.diminfo[1].shape)) __pyx_t_29 = 1; + if (unlikely(__pyx_t_29 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_29); + __PYX_ERR(0, 1841, __pyx_L1_error) + } + __pyx_v_n_height = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_dem_buffer_array.diminfo[0].strides, __pyx_t_26, __pyx_pybuffernd_dem_buffer_array.diminfo[1].strides)); + + /* "pygeoprocessing/routing/routing.pyx":1842 + * yi_n = yi+D8_YOFFSET[i_n] + * n_height = dem_buffer_array[yi_n, xi_n] + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * continue + * n_slope = root_height - n_height + */ + __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_n_height, __pyx_v_dem_nodata, 1e-8, 1e-5) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1843 + * n_height = dem_buffer_array[yi_n, xi_n] + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): + * continue # <<<<<<<<<<<<<< + * n_slope = root_height - n_height + * if n_slope > 0.0: + */ + goto __pyx_L31_continue; + + /* "pygeoprocessing/routing/routing.pyx":1842 + * yi_n = yi+D8_YOFFSET[i_n] + * n_height = dem_buffer_array[yi_n, xi_n] + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * continue + * n_slope = root_height - n_height + */ + } + + /* "pygeoprocessing/routing/routing.pyx":1844 + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): + * 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":1845 + * continue + * n_slope = root_height - n_height + * if n_slope > 0.0: # <<<<<<<<<<<<<< + * if i_n & 1: + * # if diagonal, adjust the slope + */ + __pyx_t_5 = ((__pyx_v_n_slope > 0.0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1846 + * 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_5 = ((__pyx_v_i_n & 1) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1848 + * 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":1846 + * 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":1849 + * # 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":1850 + * 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":1845 + * 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":1852 + * 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_5 = ((__pyx_v_sum_of_downhill_slopes > 0.0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1853 + * + * if sum_of_downhill_slopes > 0.0: + * compressed_integer_slopes = 0 # <<<<<<<<<<<<<< + * for i_n in range(8): + * compressed_integer_slopes |= (( + */ + __pyx_v_compressed_integer_slopes = 0; + + /* "pygeoprocessing/routing/routing.pyx":1854 + * if sum_of_downhill_slopes > 0.0: + * compressed_integer_slopes = 0 + * for i_n in range(8): # <<<<<<<<<<<<<< + * compressed_integer_slopes |= (( + * 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":1856 + * for i_n in range(8): + * compressed_integer_slopes |= (( + * 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, 1856, __pyx_L1_error) + } + + /* "pygeoprocessing/routing/routing.pyx":1855 + * compressed_integer_slopes = 0 + * for i_n in range(8): + * compressed_integer_slopes |= (( # <<<<<<<<<<<<<< + * 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":1859 + * 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":1861 + * 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":1852 + * 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":1869 + * # 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_30.xi = __pyx_v_xi_root; + __pyx_t_30.yi = __pyx_v_yi_root; + __pyx_v_drain_search_queue.push(__pyx_t_30); + + /* "pygeoprocessing/routing/routing.pyx":1870 + * # 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":1875 + * # 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_5 = ((!(__pyx_v_drain_search_queue.empty() != 0)) != 0); + if (!__pyx_t_5) break; + + /* "pygeoprocessing/routing/routing.pyx":1876 + * # 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":1877 + * 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":1878 + * 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":1880 + * 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":1881 + * + * 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":1882 + * 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":1884 + * 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+D8_XOFFSET[i_n] + */ + (__pyx_v_downhill_slope_array[__pyx_v_i_n]) = 0.0; + + /* "pygeoprocessing/routing/routing.pyx":1885 + * # 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+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] + */ + (__pyx_v_nodata_downhill_slope_array[__pyx_v_i_n]) = 0.0; + + /* "pygeoprocessing/routing/routing.pyx":1886 + * downhill_slope_array[i_n] = 0.0 + * nodata_downhill_slope_array[i_n] = 0.0 + * xi_n = xi_q+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< + * yi_n = yi_q+D8_YOFFSET[i_n] + * + */ + __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":1887 + * nodata_downhill_slope_array[i_n] = 0.0 + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< + * + * if (xi_n < 0 or xi_n >= raster_x_size or + */ + __pyx_v_yi_n = (__pyx_v_yi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":1889 + * yi_n = yi_q+D8_YOFFSET[i_n] + * + * 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_6 = ((__pyx_v_xi_n < 0) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L44_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L44_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":1890 + * + * 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_6 = ((__pyx_v_yi_n < 0) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L44_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0); + __pyx_t_5 = __pyx_t_6; + __pyx_L44_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":1889 + * yi_n = yi_q+D8_YOFFSET[i_n] + * + * 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_5) { + + /* "pygeoprocessing/routing/routing.pyx":1891 + * 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":1889 + * yi_n = yi_q+D8_YOFFSET[i_n] + * + * 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":1893 + * n_height = dem_nodata + * else: + * n_height = dem_managed_raster.get(xi_n, yi_n) # <<<<<<<<<<<<<< + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): + * 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":1894 + * else: + * n_height = dem_managed_raster.get(xi_n, yi_n) + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * n_slope = SQRT2_INV if i_n & 1 else 1.0 + * sum_of_nodata_slope_weights += n_slope + */ + __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_n_height, __pyx_v_dem_nodata, 1e-8, 1e-5) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1895 + * n_height = dem_managed_raster.get(xi_n, yi_n) + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): + * 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_7 = __pyx_v_15pygeoprocessing_7routing_7routing_SQRT2_INV; + } else { + __pyx_t_7 = 1.0; + } + __pyx_v_n_slope = __pyx_t_7; + + /* "pygeoprocessing/routing/routing.pyx":1896 + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): + * 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":1897 + * 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":1898 + * 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":1894 + * else: + * n_height = dem_managed_raster.get(xi_n, yi_n) + * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * n_slope = SQRT2_INV if i_n & 1 else 1.0 + * sum_of_nodata_slope_weights += n_slope + */ + } + + /* "pygeoprocessing/routing/routing.pyx":1899 + * 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":1900 + * continue + * n_slope = root_height - n_height + * if n_slope < 0: # <<<<<<<<<<<<<< + * continue + * if n_slope == 0.0: + */ + __pyx_t_5 = ((__pyx_v_n_slope < 0.0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1901 + * 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":1900 + * continue + * n_slope = root_height - n_height + * if n_slope < 0: # <<<<<<<<<<<<<< + * continue + * if n_slope == 0.0: + */ + } + + /* "pygeoprocessing/routing/routing.pyx":1902 + * 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_5 = ((__pyx_v_n_slope == 0.0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1904 + * 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_5 = ((__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":1903 + * 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_5) { + + /* "pygeoprocessing/routing/routing.pyx":1908 + * # previously visited + * drain_search_queue.push( + * CoordinateType(xi_n, yi_n)) # <<<<<<<<<<<<<< + * flat_region_mask_managed_raster.set( + * xi_n, yi_n, 1) + */ + __pyx_t_30.xi = __pyx_v_xi_n; + __pyx_t_30.yi = __pyx_v_yi_n; + + /* "pygeoprocessing/routing/routing.pyx":1907 + * # 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_30); + + /* "pygeoprocessing/routing/routing.pyx":1909 + * 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":1903 + * 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":1911 + * 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":1902 + * 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":1912 + * xi_n, yi_n, 1) + * continue + * if i_n & 1: # <<<<<<<<<<<<<< + * n_slope *= SQRT2_INV + * downhill_slope_array[i_n] = n_slope + */ + __pyx_t_5 = ((__pyx_v_i_n & 1) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1913 + * 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":1912 + * 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":1914 + * 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":1915 + * 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":1917 + * 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":1918 + * + * 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":1919 + * 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_5 = ((__pyx_v_sum_of_slope_weights > 0.0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1920 + * 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":1921 + * 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":1919 + * 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":1922 + * 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_5 = ((__pyx_v_sum_of_nodata_slope_weights > 0.0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1924 + * 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":1926 + * 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":1922 + * 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":1928 + * sum_of_nodata_slope_weights) + * + * if working_downhill_slope_sum > 0.0: # <<<<<<<<<<<<<< + * compressed_integer_slopes = 0 + * for i_n in range(8): + */ + __pyx_t_5 = ((__pyx_v_working_downhill_slope_sum > 0.0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1929 + * + * if working_downhill_slope_sum > 0.0: + * compressed_integer_slopes = 0 # <<<<<<<<<<<<<< + * for i_n in range(8): + * compressed_integer_slopes |= (( + */ + __pyx_v_compressed_integer_slopes = 0; + + /* "pygeoprocessing/routing/routing.pyx":1930 + * if working_downhill_slope_sum > 0.0: + * compressed_integer_slopes = 0 + * for i_n in range(8): # <<<<<<<<<<<<<< + * compressed_integer_slopes |= (( + * 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":1932 + * for i_n in range(8): + * compressed_integer_slopes |= (( + * 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, 1932, __pyx_L1_error) + } + + /* "pygeoprocessing/routing/routing.pyx":1931 + * compressed_integer_slopes = 0 + * for i_n in range(8): + * compressed_integer_slopes |= (( # <<<<<<<<<<<<<< + * 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":1935 + * 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_5 = ((__pyx_v_sum_of_slope_weights > 0.0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1937 + * 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":1939 + * 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":1941 + * 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":1944 + * xi_q, yi_q, 1) + * distance_drain_queue.push( + * CoordinateType(xi_q, yi_q)) # <<<<<<<<<<<<<< + * else: + * nodata_distance_drain_queue.push( + */ + __pyx_t_30.xi = __pyx_v_xi_q; + __pyx_t_30.yi = __pyx_v_yi_q; + + /* "pygeoprocessing/routing/routing.pyx":1943 + * 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_30); + + /* "pygeoprocessing/routing/routing.pyx":1935 + * 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":1946 + * 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":1947 + * else: + * nodata_distance_drain_queue.push( + * CoordinateType(xi_q, yi_q)) # <<<<<<<<<<<<<< + * nodata_flow_dir_queue.push( + * compressed_integer_slopes) + */ + __pyx_t_30.xi = __pyx_v_xi_q; + __pyx_t_30.yi = __pyx_v_yi_q; + + /* "pygeoprocessing/routing/routing.pyx":1946 + * 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_30); + + /* "pygeoprocessing/routing/routing.pyx":1948 + * 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":1928 + * 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":1952 + * + * # 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_5 = (__pyx_v_distance_drain_queue.empty() != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":1956 + * # 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_5 = ((!(__pyx_v_nodata_distance_drain_queue.empty() != 0)) != 0); + if (!__pyx_t_5) break; + + /* "pygeoprocessing/routing/routing.pyx":1957 + * # 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":1958 + * 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":1959 + * 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":1961 + * 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":1962 + * 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":1963 + * 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":1965 + * 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":1966 + * 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":1952 + * + * # 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":1969 + * else: + * # clear the nodata drain queues + * nodata_flow_dir_queue = IntQueueType() # <<<<<<<<<<<<<< + * nodata_distance_drain_queue = CoordinateQueueType() + * + */ + /*else*/ { + try { + __pyx_t_31 = __pyx_t_15pygeoprocessing_7routing_7routing_IntQueueType(); + } catch(...) { + __Pyx_CppExn2PyErr(); + __PYX_ERR(0, 1969, __pyx_L1_error) + } + __pyx_v_nodata_flow_dir_queue = __pyx_t_31; + + /* "pygeoprocessing/routing/routing.pyx":1970 + * # 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_32 = __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateQueueType(); + } catch(...) { + __Pyx_CppExn2PyErr(); + __PYX_ERR(0, 1970, __pyx_L1_error) + } + __pyx_v_nodata_distance_drain_queue = __pyx_t_32; + } + __pyx_L58:; + + /* "pygeoprocessing/routing/routing.pyx":1973 + * + * # copy the drain queue to another queue + * for _ in range(distance_drain_queue.size()): # <<<<<<<<<<<<<< + * distance_drain_queue.push( + * distance_drain_queue.front()) + */ + __pyx_t_33 = __pyx_v_distance_drain_queue.size(); + __pyx_t_34 = __pyx_t_33; + for (__pyx_t_35 = 0; __pyx_t_35 < __pyx_t_34; __pyx_t_35+=1) { + __pyx_v__ = __pyx_t_35; + + /* "pygeoprocessing/routing/routing.pyx":1974 + * # 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":1976 + * 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":1977 + * 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":1985 + * # 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_5 = ((!(__pyx_v_distance_drain_queue.empty() != 0)) != 0); + if (!__pyx_t_5) break; + + /* "pygeoprocessing/routing/routing.pyx":1986 + * # 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":1987 + * 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":1988 + * 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":1990 + * 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":1993 + * xi_q, yi_q) + * + * for i_n in range(8): # <<<<<<<<<<<<<< + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[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":1994 + * + * for i_n in range(8): + * xi_n = xi_q+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< + * yi_n = yi_q+D8_YOFFSET[i_n] + * if (xi_n < 0 or xi_n >= raster_x_size or + */ + __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":1995 + * for i_n in range(8): + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< + * 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_D8_YOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":1996 + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] + * if (xi_n < 0 or xi_n >= raster_x_size or # <<<<<<<<<<<<<< + * yi_n < 0 or yi_n >= raster_y_size): + * continue + */ + __pyx_t_6 = ((__pyx_v_xi_n < 0) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L68_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L68_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":1997 + * yi_n = yi_q+D8_YOFFSET[i_n] + * if (xi_n < 0 or xi_n >= raster_x_size or + * yi_n < 0 or yi_n >= raster_y_size): # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_6 = ((__pyx_v_yi_n < 0) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L68_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0); + __pyx_t_5 = __pyx_t_6; + __pyx_L68_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":1996 + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] + * 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":1998 + * 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":1996 + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] + * 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":2001 + * + * 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_7 = __pyx_v_15pygeoprocessing_7routing_7routing_SQRT2; + } else { + __pyx_t_7 = 1.0; + } + + /* "pygeoprocessing/routing/routing.pyx":2000 + * 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_7); + + /* "pygeoprocessing/routing/routing.pyx":2004 + * + * 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_6 = ((((double)__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) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L73_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":2006 + * 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_6 = ((__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_5 = __pyx_t_6; + __pyx_L73_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":2003 + * 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_5) { + + /* "pygeoprocessing/routing/routing.pyx":2009 + * # 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":2012 + * 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_30.xi = __pyx_v_xi_n; + __pyx_t_30.yi = __pyx_v_yi_n; + + /* "pygeoprocessing/routing/routing.pyx":2011 + * 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_30); + + /* "pygeoprocessing/routing/routing.pyx":2003 + * 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_L65_continue:; + } + } + + /* "pygeoprocessing/routing/routing.pyx":2016 + * # 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_5 = ((!(__pyx_v_direction_drain_queue.empty() != 0)) != 0); + if (!__pyx_t_5) break; + + /* "pygeoprocessing/routing/routing.pyx":2017 + * # 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":2018 + * 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":2019 + * 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":2021 + * 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":2024 + * xi_q, yi_q) + * + * sum_of_slope_weights = 0.0 # <<<<<<<<<<<<<< + * for i_n in range(8): + * xi_n = xi_q+D8_XOFFSET[i_n] + */ + __pyx_v_sum_of_slope_weights = 0.0; + + /* "pygeoprocessing/routing/routing.pyx":2025 + * + * sum_of_slope_weights = 0.0 + * for i_n in range(8): # <<<<<<<<<<<<<< + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[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":2026 + * sum_of_slope_weights = 0.0 + * for i_n in range(8): + * xi_n = xi_q+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< + * yi_n = yi_q+D8_YOFFSET[i_n] + * downhill_slope_array[i_n] = 0.0 + */ + __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":2027 + * for i_n in range(8): + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< + * downhill_slope_array[i_n] = 0.0 + * + */ + __pyx_v_yi_n = (__pyx_v_yi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":2028 + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] + * 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":2030 + * 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_6 = ((__pyx_v_xi_n < 0) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L80_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L80_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":2031 + * + * if (xi_n < 0 or xi_n >= raster_x_size or + * yi_n < 0 or yi_n >= raster_y_size): # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_6 = ((__pyx_v_yi_n < 0) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L80_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0); + __pyx_t_5 = __pyx_t_6; + __pyx_L80_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":2030 + * 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_5) { + + /* "pygeoprocessing/routing/routing.pyx":2032 + * 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":2030 + * 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":2034 + * continue + * + * if dem_managed_raster.get(xi_n, yi_n) != root_height: # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_5 = ((__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_5) { + + /* "pygeoprocessing/routing/routing.pyx":2035 + * + * 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":2034 + * continue + * + * if dem_managed_raster.get(xi_n, yi_n) != root_height: # <<<<<<<<<<<<<< + * continue + * + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2037 + * 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":2039 + * 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_5 = ((__pyx_v_n_distance == __pyx_v_plateau_distance_nodata) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":2040 + * 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":2039 + * 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":2041 + * 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_5 = ((__pyx_v_n_distance < __pyx_v_drain_distance) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":2042 + * 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_7 = __pyx_v_15pygeoprocessing_7routing_7routing_SQRT2_INV; + } else { + __pyx_t_7 = 1.0; + } + __pyx_v_n_slope = __pyx_t_7; + + /* "pygeoprocessing/routing/routing.pyx":2043 + * 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":2044 + * 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":2041 + * 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":2045 + * 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_5 = ((!(__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_5) { + + /* "pygeoprocessing/routing/routing.pyx":2048 + * 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_30.xi = __pyx_v_xi_n; + __pyx_t_30.yi = __pyx_v_yi_n; + + /* "pygeoprocessing/routing/routing.pyx":2047 + * 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_30); + + /* "pygeoprocessing/routing/routing.pyx":2049 + * 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":2045 + * 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":2052 + * xi_n, yi_n, 1) + * + * if sum_of_slope_weights == 0: # <<<<<<<<<<<<<< + * continue + * compressed_integer_slopes = 0 + */ + __pyx_t_5 = ((__pyx_v_sum_of_slope_weights == 0.0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":2053 + * + * 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":2052 + * xi_n, yi_n, 1) + * + * if sum_of_slope_weights == 0: # <<<<<<<<<<<<<< + * continue + * compressed_integer_slopes = 0 + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2054 + * if sum_of_slope_weights == 0: + * continue + * compressed_integer_slopes = 0 # <<<<<<<<<<<<<< + * for i_n in range(8): + * compressed_integer_slopes |= (( + */ + __pyx_v_compressed_integer_slopes = 0; + + /* "pygeoprocessing/routing/routing.pyx":2055 + * continue + * compressed_integer_slopes = 0 + * for i_n in range(8): # <<<<<<<<<<<<<< + * compressed_integer_slopes |= (( + * 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":2057 + * for i_n in range(8): + * compressed_integer_slopes |= (( + * 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, 2057, __pyx_L1_error) + } + + /* "pygeoprocessing/routing/routing.pyx":2056 + * compressed_integer_slopes = 0 + * for i_n in range(8): + * compressed_integer_slopes |= (( # <<<<<<<<<<<<<< + * 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":2059 + * 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":1782 + * + * # this outer loop searches for a pixel that is locally undrained + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * compatable_dem_raster_path_band, offset_only=True, + * largest_block=0): + */ + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2062 + * 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":2063 + * + * 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":2064 + * 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, 2064, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __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); + } + } + __pyx_t_3 = (__pyx_t_20) ? __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_20) : __Pyx_PyObject_CallNoArg(__pyx_t_15); + __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2064, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2065 + * 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, 2065, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __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); + } + } + __pyx_t_3 = (__pyx_t_20) ? __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_20) : __Pyx_PyObject_CallNoArg(__pyx_t_15); + __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2065, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2066 + * 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, 2066, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __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); + } + } + __pyx_t_3 = (__pyx_t_20) ? __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_20) : __Pyx_PyObject_CallNoArg(__pyx_t_15); + __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2066, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2067 + * 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, 2067, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __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); + } + } + __pyx_t_3 = (__pyx_t_20) ? __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_20) : __Pyx_PyObject_CallNoArg(__pyx_t_15); + __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2067, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2068 + * 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, 2068, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __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); + } + } + __pyx_t_3 = (__pyx_t_20) ? __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_20) : __Pyx_PyObject_CallNoArg(__pyx_t_15); + __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2068, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2069 + * dem_managed_raster.close() + * plateau_distance_managed_raster.close() + * shutil.rmtree(working_dir_path) # <<<<<<<<<<<<<< + * LOGGER.info('%.1f%% complete', 100.0) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_shutil); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2069, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_rmtree); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2069, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_20))) { + __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_20); + if (likely(__pyx_t_15)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_20); + __Pyx_INCREF(__pyx_t_15); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_20, function); + } + } + __pyx_t_3 = (__pyx_t_15) ? __Pyx_PyObject_Call2Args(__pyx_t_20, __pyx_t_15, __pyx_v_working_dir_path) : __Pyx_PyObject_CallOneArg(__pyx_t_20, __pyx_v_working_dir_path); + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2069, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2070 + * plateau_distance_managed_raster.close() + * shutil.rmtree(working_dir_path) + * LOGGER.info('%.1f%% complete', 100.0) # <<<<<<<<<<<<<< + * + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2070, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_info); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2070, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_20, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2070, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1582 + * + * + * def flow_dir_mfd( # <<<<<<<<<<<<<< + * dem_raster_path_band, target_flow_dir_path, working_dir=None, + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_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_14); + __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_raster_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":2073 + * + * + * 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 (str): 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 raster_driver_creation_tuple (tuple): a tuple containing a GDAL driver\n name string as the first element and a GDAL creation options\n tuple/list as the second. Defaults to a GTiff driver tuple\n defined at geoprocessing.DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS.\n\n Returns:\n None.\n\n "; +static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_11flow_accumulation_mfd = {"flow_accumulation_mfd", (PyCFunction)(void*)(PyCFunctionWithKeywords)__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_raster_driver_creation_tuple = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 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_raster_driver_creation_tuple,0}; + PyObject* values[4] = {0,0,0,0}; + + /* "pygeoprocessing/routing/routing.pyx":2075 + * def flow_accumulation_mfd( + * flow_dir_mfd_raster_path_band, target_flow_accum_raster_path, + * weight_raster_path_band=None, # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): + * """Multiple flow direction accumulation. + */ + values[2] = ((PyObject *)Py_None); + values[3] = __pyx_k__11; + 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, 2073, __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_raster_driver_creation_tuple); + 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, 2073, __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_raster_driver_creation_tuple = 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, 2073, __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_raster_driver_creation_tuple); + + /* "pygeoprocessing/routing/routing.pyx":2073 + * + * + * 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_raster_driver_creation_tuple) { + 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; + PY_LONG_LONG __pyx_v_visit_count; + PY_LONG_LONG __pyx_v_pixel_count; + 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 __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; + PyObject *__pyx_v_tmp_dir_root = NULL; + PyObject *__pyx_v_tmp_dir = NULL; + PyObject *__pyx_v_visited_raster_path = NULL; + struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_visited_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; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + 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; + int __pyx_t_30; + struct __pyx_t_15pygeoprocessing_7routing_7routing_FlowPixelType __pyx_t_31; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __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":2139 + * 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":2140 + * + * 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":2157 + * # 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":2159 + * 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_is_raster_path_band_formatted); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2159, __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); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_flow_dir_mfd_raster_path_band) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_flow_dir_mfd_raster_path_band); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2159, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __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, 2159, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_5 = ((!__pyx_t_4) != 0); + if (unlikely(__pyx_t_5)) { + + /* "pygeoprocessing/routing/routing.pyx":2161 + * 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_PyUnicode_FormatSafe(__pyx_kp_u_s_is_supposed_to_be_a_raster_ba, __pyx_v_flow_dir_mfd_raster_path_band); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2161, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":2160 + * + * 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, 2160, __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, 2160, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2159 + * 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":2163 + * "%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_4 = __Pyx_PyObject_IsTrue(__pyx_v_weight_raster_path_band); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2163, __pyx_L1_error) + if (__pyx_t_4) { + } else { + __pyx_t_5 = __pyx_t_4; + goto __pyx_L5_bool_binop_done; + } + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_is_raster_path_band_formatted); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2163, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":2164 + * 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_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); + } + } + __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_3, __pyx_v_weight_raster_path_band) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_weight_raster_path_band); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2163, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2163 + * "%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_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2163, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_6 = ((!__pyx_t_4) != 0); + __pyx_t_5 = __pyx_t_6; + __pyx_L5_bool_binop_done:; + if (unlikely(__pyx_t_5)) { + + /* "pygeoprocessing/routing/routing.pyx":2166 + * 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_PyUnicode_FormatSafe(__pyx_kp_u_s_is_supposed_to_be_a_raster_ba, __pyx_v_weight_raster_path_band); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2166, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + + /* "pygeoprocessing/routing/routing.pyx":2165 + * 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, 2165, __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, 2165, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2163 + * "%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":2169 + * weight_raster_path_band)) + * + * LOGGER.debug('creating target flow accum raster layer') # <<<<<<<<<<<<<< + * pygeoprocessing.new_raster_from_base( + * flow_dir_mfd_raster_path_band[0], target_flow_accum_raster_path, + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2169, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_debug); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2169, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + 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_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_kp_u_creating_target_flow_accum_raste) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_creating_target_flow_accum_raste); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2169, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2170 + * + * LOGGER.debug('creating target flow accum raster layer') + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * flow_dir_mfd_raster_path_band[0], target_flow_accum_raster_path, + * gdal.GDT_Float64, [flow_accum_nodata], + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2170, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2170, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2171 + * LOGGER.debug('creating target flow accum raster layer') + * pygeoprocessing.new_raster_from_base( + * flow_dir_mfd_raster_path_band[0], target_flow_accum_raster_path, # <<<<<<<<<<<<<< + * gdal.GDT_Float64, [flow_accum_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + */ + __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, 2171, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":2172 + * pygeoprocessing.new_raster_from_base( + * flow_dir_mfd_raster_path_band[0], target_flow_accum_raster_path, + * gdal.GDT_Float64, [flow_accum_nodata], # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2172, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2172, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyFloat_FromDouble(__pyx_v_flow_accum_nodata); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2172, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_8 = PyList_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2172, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_2); + PyList_SET_ITEM(__pyx_t_8, 0, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2170 + * + * LOGGER.debug('creating target flow accum raster layer') + * 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_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2170, __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_flow_accum_raster_path); + __Pyx_GIVEREF(__pyx_v_target_flow_accum_raster_path); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_target_flow_accum_raster_path); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_8); + __pyx_t_1 = 0; + __pyx_t_7 = 0; + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2173 + * flow_dir_mfd_raster_path_band[0], target_flow_accum_raster_path, + * gdal.GDT_Float64, [flow_accum_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< + * + * flow_accum_managed_raster = _ManagedRaster( + */ + __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2173, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 2173, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2170 + * + * LOGGER.debug('creating target flow accum raster layer') + * 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_7 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2170, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2175 + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * + * flow_accum_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< + * target_flow_accum_raster_path, 1, 1) + * + */ + __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2175, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_v_target_flow_accum_raster_path); + __Pyx_GIVEREF(__pyx_v_target_flow_accum_raster_path); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_target_flow_accum_raster_path); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_int_1); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_int_1); + __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2175, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 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":2179 + * + * # make a temporary raster to mark where we have visisted + * LOGGER.debug('creating visited raster layer') # <<<<<<<<<<<<<< + * tmp_dir_root = os.path.dirname(target_flow_accum_raster_path) + * tmp_dir = tempfile.mkdtemp(dir=tmp_dir_root, prefix='mfd_flow_dir_') + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2179, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_debug); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2179, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + 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_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_7, __pyx_kp_u_creating_visited_raster_layer) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_kp_u_creating_visited_raster_layer); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2179, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2180 + * # make a temporary raster to mark where we have visisted + * LOGGER.debug('creating visited raster layer') + * tmp_dir_root = os.path.dirname(target_flow_accum_raster_path) # <<<<<<<<<<<<<< + * tmp_dir = tempfile.mkdtemp(dir=tmp_dir_root, prefix='mfd_flow_dir_') + * visited_raster_path = os.path.join(tmp_dir, 'visited.tif') + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2180, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_path); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2180, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_dirname); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2180, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_7, __pyx_v_target_flow_accum_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_target_flow_accum_raster_path); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2180, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_tmp_dir_root = __pyx_t_8; + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2181 + * LOGGER.debug('creating visited raster layer') + * tmp_dir_root = os.path.dirname(target_flow_accum_raster_path) + * tmp_dir = tempfile.mkdtemp(dir=tmp_dir_root, prefix='mfd_flow_dir_') # <<<<<<<<<<<<<< + * visited_raster_path = os.path.join(tmp_dir, 'visited.tif') + * pygeoprocessing.new_raster_from_base( + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_tempfile); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2181, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_mkdtemp); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2181, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2181, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_dir, __pyx_v_tmp_dir_root) < 0) __PYX_ERR(0, 2181, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_prefix, __pyx_n_u_mfd_flow_dir) < 0) __PYX_ERR(0, 2181, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2181, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_tmp_dir = __pyx_t_7; + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2182 + * tmp_dir_root = os.path.dirname(target_flow_accum_raster_path) + * tmp_dir = tempfile.mkdtemp(dir=tmp_dir_root, prefix='mfd_flow_dir_') + * visited_raster_path = os.path.join(tmp_dir, 'visited.tif') # <<<<<<<<<<<<<< + * pygeoprocessing.new_raster_from_base( + * flow_dir_mfd_raster_path_band[0], visited_raster_path, + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_os); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2182, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_path); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2182, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_join); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2182, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && likely(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_v_tmp_dir, __pyx_kp_u_visited_tif}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2182, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_tmp_dir, __pyx_kp_u_visited_tif}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2182, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + { + __pyx_t_3 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2182, __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_v_tmp_dir); + __Pyx_GIVEREF(__pyx_v_tmp_dir); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_9, __pyx_v_tmp_dir); + __Pyx_INCREF(__pyx_kp_u_visited_tif); + __Pyx_GIVEREF(__pyx_kp_u_visited_tif); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_9, __pyx_kp_u_visited_tif); + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_3, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2182, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_visited_raster_path = __pyx_t_7; + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2183 + * tmp_dir = tempfile.mkdtemp(dir=tmp_dir_root, prefix='mfd_flow_dir_') + * visited_raster_path = os.path.join(tmp_dir, 'visited.tif') + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * flow_dir_mfd_raster_path_band[0], visited_raster_path, + * gdal.GDT_Byte, [0], + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2183, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2183, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2184 + * visited_raster_path = os.path.join(tmp_dir, 'visited.tif') + * pygeoprocessing.new_raster_from_base( + * flow_dir_mfd_raster_path_band[0], visited_raster_path, # <<<<<<<<<<<<<< + * gdal.GDT_Byte, [0], + * raster_driver_creation_tuple=('GTiff', ( + */ + __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2184, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + + /* "pygeoprocessing/routing/routing.pyx":2185 + * pygeoprocessing.new_raster_from_base( + * flow_dir_mfd_raster_path_band[0], visited_raster_path, + * gdal.GDT_Byte, [0], # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=('GTiff', ( + * 'SPARSE_OK=TRUE', 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2185, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2185, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2185, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyList_SET_ITEM(__pyx_t_3, 0, __pyx_int_0); + + /* "pygeoprocessing/routing/routing.pyx":2183 + * tmp_dir = tempfile.mkdtemp(dir=tmp_dir_root, prefix='mfd_flow_dir_') + * visited_raster_path = os.path.join(tmp_dir, 'visited.tif') + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * flow_dir_mfd_raster_path_band[0], visited_raster_path, + * gdal.GDT_Byte, [0], + */ + __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2183, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7); + __Pyx_INCREF(__pyx_v_visited_raster_path); + __Pyx_GIVEREF(__pyx_v_visited_raster_path); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_visited_raster_path); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_3); + __pyx_t_7 = 0; + __pyx_t_2 = 0; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2186 + * flow_dir_mfd_raster_path_band[0], visited_raster_path, + * gdal.GDT_Byte, [0], + * raster_driver_creation_tuple=('GTiff', ( # <<<<<<<<<<<<<< + * 'SPARSE_OK=TRUE', 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', + * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), + */ + __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2186, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + + /* "pygeoprocessing/routing/routing.pyx":2188 + * raster_driver_creation_tuple=('GTiff', ( + * 'SPARSE_OK=TRUE', 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', + * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), # <<<<<<<<<<<<<< + * 'BLOCKYSIZE=%d' % (1 << BLOCK_BITS)))) + * visited_managed_raster = _ManagedRaster(visited_raster_path, 1, 1) + */ + __pyx_t_2 = __Pyx_PyInt_From_long((1 << __pyx_v_15pygeoprocessing_7routing_7routing_BLOCK_BITS)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2188, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = PyUnicode_Format(__pyx_kp_u_BLOCKXSIZE_d, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2188, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2189 + * 'SPARSE_OK=TRUE', 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', + * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), + * 'BLOCKYSIZE=%d' % (1 << BLOCK_BITS)))) # <<<<<<<<<<<<<< + * visited_managed_raster = _ManagedRaster(visited_raster_path, 1, 1) + * + */ + __pyx_t_2 = __Pyx_PyInt_From_long((1 << __pyx_v_15pygeoprocessing_7routing_7routing_BLOCK_BITS)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = PyUnicode_Format(__pyx_kp_u_BLOCKYSIZE_d, __pyx_t_2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2187 + * gdal.GDT_Byte, [0], + * raster_driver_creation_tuple=('GTiff', ( + * 'SPARSE_OK=TRUE', 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', # <<<<<<<<<<<<<< + * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), + * 'BLOCKYSIZE=%d' % (1 << BLOCK_BITS)))) + */ + __pyx_t_2 = PyTuple_New(6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2187, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_kp_u_SPARSE_OK_TRUE); + __Pyx_GIVEREF(__pyx_kp_u_SPARSE_OK_TRUE); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_u_SPARSE_OK_TRUE); + __Pyx_INCREF(__pyx_kp_u_TILED_YES); + __Pyx_GIVEREF(__pyx_kp_u_TILED_YES); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_kp_u_TILED_YES); + __Pyx_INCREF(__pyx_kp_u_BIGTIFF_YES); + __Pyx_GIVEREF(__pyx_kp_u_BIGTIFF_YES); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_kp_u_BIGTIFF_YES); + __Pyx_INCREF(__pyx_kp_u_COMPRESS_LZW); + __Pyx_GIVEREF(__pyx_kp_u_COMPRESS_LZW); + PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_kp_u_COMPRESS_LZW); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_2, 4, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_2, 5, __pyx_t_10); + __pyx_t_7 = 0; + __pyx_t_10 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2186 + * flow_dir_mfd_raster_path_band[0], visited_raster_path, + * gdal.GDT_Byte, [0], + * raster_driver_creation_tuple=('GTiff', ( # <<<<<<<<<<<<<< + * 'SPARSE_OK=TRUE', 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', + * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), + */ + __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2186, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_n_u_GTiff); + __Pyx_GIVEREF(__pyx_n_u_GTiff); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_n_u_GTiff); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_2); + __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_raster_driver_creation_tuple, __pyx_t_10) < 0) __PYX_ERR(0, 2186, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2183 + * tmp_dir = tempfile.mkdtemp(dir=tmp_dir_root, prefix='mfd_flow_dir_') + * visited_raster_path = os.path.join(tmp_dir, 'visited.tif') + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * flow_dir_mfd_raster_path_band[0], visited_raster_path, + * gdal.GDT_Byte, [0], + */ + __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2183, __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_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2190 + * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), + * 'BLOCKYSIZE=%d' % (1 << BLOCK_BITS)))) + * visited_managed_raster = _ManagedRaster(visited_raster_path, 1, 1) # <<<<<<<<<<<<<< + * + * flow_dir_managed_raster = _ManagedRaster( + */ + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2190, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_v_visited_raster_path); + __Pyx_GIVEREF(__pyx_v_visited_raster_path); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_visited_raster_path); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_int_1); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_int_1); + __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2190, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_v_visited_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2193 + * + * 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_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, 2193, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __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, 2193, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + + /* "pygeoprocessing/routing/routing.pyx":2192 + * visited_managed_raster = _ManagedRaster(visited_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_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2192, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_10); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_int_0); + __pyx_t_3 = 0; + __pyx_t_10 = 0; + __pyx_t_10 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_1, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2192, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_flow_dir_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_10); + __pyx_t_10 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2194 + * 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_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2194, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2194, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2195 + * 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_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, 2195, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_gdal); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2195, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2195, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_1, __pyx_t_2}; + __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2194, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __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[3] = {__pyx_t_8, __pyx_t_1, __pyx_t_2}; + __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2194, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2194, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_8) { + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8); __pyx_t_8 = NULL; + } + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_9, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_9, __pyx_t_2); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2194, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_flow_dir_raster = __pyx_t_10; + __pyx_t_10 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2196 + * 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_PyObject_GetAttrStr(__pyx_v_flow_dir_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2196, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + + /* "pygeoprocessing/routing/routing.pyx":2197 + * 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_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, 2197, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_10 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_7); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2196, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_flow_dir_band = __pyx_t_10; + __pyx_t_10 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2199 + * 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":2200 + * + * 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_5 = __Pyx_PyObject_IsTrue(__pyx_v_weight_raster_path_band); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2200, __pyx_L1_error) + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":2202 + * 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_10 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2202, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2202, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + + /* "pygeoprocessing/routing/routing.pyx":2201 + * 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_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2201, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_3); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_int_0); + __pyx_t_10 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2201, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF_SET(__pyx_v_weight_raster, ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_3)); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2203 + * 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_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2203, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2203, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2204 + * 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_7 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2204, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __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); + } + } + __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_2, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_7); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2203, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = __Pyx_PyObject_Dict_GetItem(__pyx_t_3, __pyx_n_u_nodata); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2204, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2205 + * 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_3 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2205, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = __Pyx_PyInt_SubtractObjC(__pyx_t_3, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2205, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2204 + * 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_PyObject_GetItem(__pyx_t_10, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2204, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_raw_weight_nodata = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2206 + * 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_5 = (__pyx_v_raw_weight_nodata != Py_None); + __pyx_t_6 = (__pyx_t_5 != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/routing/routing.pyx":2207 + * 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, 2207, __pyx_L1_error) + __pyx_v_weight_nodata = __pyx_t_11; + + /* "pygeoprocessing/routing/routing.pyx":2206 + * 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":2200 + * + * 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":2209 + * 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_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2209, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2209, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2210 + * + * 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'] + * pixel_count = raster_x_size * raster_y_size + */ + __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2210, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __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); + } + } + __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_2, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_7); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2209, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_v_flow_dir_raster_info = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2211 + * 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'] # <<<<<<<<<<<<<< + * pixel_count = raster_x_size * raster_y_size + * visit_count = 0 + */ + __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_raster_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2211, __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, 2211, __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_7 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_10 = PyList_GET_ITEM(sequence, 0); + __pyx_t_7 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_7); + #else + __pyx_t_10 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2211, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2211, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2211, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_12 = Py_TYPE(__pyx_t_2)->tp_iternext; + index = 0; __pyx_t_10 = __pyx_t_12(__pyx_t_2); if (unlikely(!__pyx_t_10)) goto __pyx_L9_unpacking_failed; + __Pyx_GOTREF(__pyx_t_10); + index = 1; __pyx_t_7 = __pyx_t_12(__pyx_t_2); if (unlikely(!__pyx_t_7)) goto __pyx_L9_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_2), 2) < 0) __PYX_ERR(0, 2211, __pyx_L1_error) + __pyx_t_12 = NULL; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L10_unpacking_done; + __pyx_L9_unpacking_failed:; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_12 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 2211, __pyx_L1_error) + __pyx_L10_unpacking_done:; + } + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_10); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2211, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2211, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_raster_x_size = __pyx_t_9; + __pyx_v_raster_y_size = __pyx_t_13; + + /* "pygeoprocessing/routing/routing.pyx":2212 + * flow_dir_mfd_raster_path_band[0]) + * raster_x_size, raster_y_size = flow_dir_raster_info['raster_size'] + * pixel_count = raster_x_size * raster_y_size # <<<<<<<<<<<<<< + * visit_count = 0 + * + */ + __pyx_v_pixel_count = (__pyx_v_raster_x_size * __pyx_v_raster_y_size); + + /* "pygeoprocessing/routing/routing.pyx":2213 + * raster_x_size, raster_y_size = flow_dir_raster_info['raster_size'] + * pixel_count = raster_x_size * raster_y_size + * visit_count = 0 # <<<<<<<<<<<<<< + * + * LOGGER.debug('starting search') + */ + __pyx_v_visit_count = 0; + + /* "pygeoprocessing/routing/routing.pyx":2215 + * visit_count = 0 + * + * LOGGER.debug('starting search') # <<<<<<<<<<<<<< + * # this outer loop searches for a pixel that is locally undrained + * for offset_dict in pygeoprocessing.iterblocks( + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2215, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_debug); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2215, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_10); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_10, function); + } + } + __pyx_t_3 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_7, __pyx_kp_u_starting_search) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_kp_u_starting_search); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2215, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2217 + * LOGGER.debug('starting search') + * # this outer loop searches for a pixel that is locally undrained + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * flow_dir_mfd_raster_path_band, offset_only=True, + * largest_block=0): + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2217, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2217, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2218 + * # this outer loop searches for a pixel that is locally undrained + * for offset_dict in pygeoprocessing.iterblocks( + * flow_dir_mfd_raster_path_band, offset_only=True, # <<<<<<<<<<<<<< + * largest_block=0): + * win_xsize = offset_dict['win_xsize'] + */ + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2217, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __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_3, 0, __pyx_v_flow_dir_mfd_raster_path_band); + __pyx_t_7 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2218, __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, 2218, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_largest_block, __pyx_int_0) < 0) __PYX_ERR(0, 2218, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2217 + * LOGGER.debug('starting search') + * # this outer loop searches for a pixel that is locally undrained + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * flow_dir_mfd_raster_path_band, offset_only=True, + * largest_block=0): + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_3, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2217, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_7 = __pyx_t_2; __Pyx_INCREF(__pyx_t_7); __pyx_t_14 = 0; + __pyx_t_15 = NULL; + } else { + __pyx_t_14 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2217, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_15 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2217, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (likely(!__pyx_t_15)) { + if (likely(PyList_CheckExact(__pyx_t_7))) { + if (__pyx_t_14 >= PyList_GET_SIZE(__pyx_t_7)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_14); __Pyx_INCREF(__pyx_t_2); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 2217, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_7, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2217, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } else { + if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_7)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_14); __Pyx_INCREF(__pyx_t_2); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 2217, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_7, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2217, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } + } else { + __pyx_t_2 = __pyx_t_15(__pyx_t_7); + if (unlikely(!__pyx_t_2)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 2217, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XDECREF_SET(__pyx_v_offset_dict, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2220 + * flow_dir_mfd_raster_path_band, offset_only=True, + * largest_block=0): + * win_xsize = offset_dict['win_xsize'] # <<<<<<<<<<<<<< + * win_ysize = offset_dict['win_ysize'] + * xoff = offset_dict['xoff'] + */ + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2220, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2220, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_win_xsize = __pyx_t_13; + + /* "pygeoprocessing/routing/routing.pyx":2221 + * 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_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2221, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2221, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_win_ysize = __pyx_t_13; + + /* "pygeoprocessing/routing/routing.pyx":2222 + * win_xsize = offset_dict['win_xsize'] + * win_ysize = offset_dict['win_ysize'] + * xoff = offset_dict['xoff'] # <<<<<<<<<<<<<< + * yoff = offset_dict['yoff'] + * + */ + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_xoff); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2222, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2222, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_xoff = __pyx_t_13; + + /* "pygeoprocessing/routing/routing.pyx":2223 + * win_ysize = offset_dict['win_ysize'] + * xoff = offset_dict['xoff'] + * yoff = offset_dict['yoff'] # <<<<<<<<<<<<<< + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + */ + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_yoff); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2223, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2223, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_yoff = __pyx_t_13; + + /* "pygeoprocessing/routing/routing.pyx":2225 + * yoff = offset_dict['yoff'] + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + */ + __pyx_t_6 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/routing/routing.pyx":2226 + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + */ + __pyx_v_last_log_time = time(NULL); + + /* "pygeoprocessing/routing/routing.pyx":2227 + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size # <<<<<<<<<<<<<< + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + * raster_x_size * raster_y_size)) + */ + __pyx_t_2 = __Pyx_PyInt_From_int((__pyx_v_xoff + (__pyx_v_yoff * __pyx_v_raster_x_size))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2227, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XDECREF_SET(__pyx_v_current_pixel, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2228 + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< + * raster_x_size * raster_y_size)) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2228, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_info); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2228, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyNumber_Multiply(__pyx_float_100_0, __pyx_v_current_pixel); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2228, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + + /* "pygeoprocessing/routing/routing.pyx":2229 + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + * 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, 2228, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":2228 + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< + * raster_x_size * raster_y_size)) + * + */ + __pyx_t_8 = __Pyx_PyNumber_Divide(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2228, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + __pyx_t_13 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_10); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); + __Pyx_INCREF(__pyx_t_1); + __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_1, __pyx_kp_u_1f_complete, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2228, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_kp_u_1f_complete, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2228, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + { + __pyx_t_3 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2228, __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_INCREF(__pyx_kp_u_1f_complete); + __Pyx_GIVEREF(__pyx_kp_u_1f_complete); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_13, __pyx_kp_u_1f_complete); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_13, __pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2228, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2225 + * yoff = offset_dict['yoff'] + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2232 + * + * # 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2232, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2232, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2233 + * # 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_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2233, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2233, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2233, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_8 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2233, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2233, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_8); + __pyx_t_3 = 0; + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2232 + * + * # 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_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2232, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2234 + * 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_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2234, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2234, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2234, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 2234, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2232 + * + * # 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_1 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_8, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2232, __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_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, 2232, __pyx_L1_error) + __pyx_t_16 = ((PyArrayObject *)__pyx_t_1); + { + __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, 2232, __pyx_L1_error) + } + __pyx_t_16 = 0; + __Pyx_XDECREF_SET(__pyx_v_flow_dir_mfd_buffer_array, ((PyArrayObject *)__pyx_t_1)); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2235 + * (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__7, __pyx_int_0) < 0)) __PYX_ERR(0, 2235, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2239 + * # 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_generate_read_bounds); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2239, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + + /* "pygeoprocessing/routing/routing.pyx":2240 + * # 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_8 = __Pyx_PyInt_From_int(__pyx_v_raster_x_size); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2240, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_10 = __Pyx_PyInt_From_int(__pyx_v_raster_y_size); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2240, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_3 = NULL; + __pyx_t_13 = 0; + 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); + __pyx_t_13 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_offset_dict, __pyx_t_8, __pyx_t_10}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_13, 3+__pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2239, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_offset_dict, __pyx_t_8, __pyx_t_10}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_13, 3+__pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2239, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 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, 2239, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_3); __pyx_t_3 = 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_8); + PyTuple_SET_ITEM(__pyx_t_20, 1+__pyx_t_13, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_20, 2+__pyx_t_13, __pyx_t_10); + __pyx_t_8 = 0; + __pyx_t_10 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_20, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2239, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 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, 2239, __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_20 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_2 = PyList_GET_ITEM(sequence, 0); + __pyx_t_20 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_20); + #else + __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2239, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_20 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2239, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + #endif + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_10 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2239, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_12 = Py_TYPE(__pyx_t_10)->tp_iternext; + index = 0; __pyx_t_2 = __pyx_t_12(__pyx_t_10); if (unlikely(!__pyx_t_2)) goto __pyx_L14_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + 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, 2239, __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, 2239, __pyx_L1_error) + __pyx_L15_unpacking_done:; + } + + /* "pygeoprocessing/routing/routing.pyx":2239 + * # 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_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, 2239, __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_8 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_21 = PyTuple_GET_ITEM(sequence, 3); + } else { + __pyx_t_10 = PyList_GET_ITEM(sequence, 0); + __pyx_t_8 = PyList_GET_ITEM(sequence, 1); + __pyx_t_3 = PyList_GET_ITEM(sequence, 2); + __pyx_t_21 = PyList_GET_ITEM(sequence, 3); + } + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_21); + #else + { + Py_ssize_t i; + PyObject** temps[4] = {&__pyx_t_10,&__pyx_t_8,&__pyx_t_3,&__pyx_t_21}; + for (i=0; i < 4; i++) { + PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 2239, __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_10,&__pyx_t_8,&__pyx_t_3,&__pyx_t_21}; + __pyx_t_22 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2239, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_22); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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, 2239, __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, 2239, __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_8); + __pyx_t_8 = 0; + __Pyx_XDECREF_SET(__pyx_v_ya, __pyx_t_3); + __pyx_t_3 = 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":2241 + * (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, 2241, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + + /* "pygeoprocessing/routing/routing.pyx":2242 + * 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, 2242, __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, 2242, __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, 2241, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + } + + /* "pygeoprocessing/routing/routing.pyx":2241 + * (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_2); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2241, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_21); + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2242 + * 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_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_21, __pyx_n_s_astype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2242, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_21, __pyx_n_s_numpy); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2242, __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, 2242, __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_2))) { + __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_21)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_21); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_1 = (__pyx_t_21) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_21, __pyx_t_20) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_20); + __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2242, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2241 + * (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 = PySlice_New(__pyx_v_ya, __pyx_v_yb, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2241, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_20 = PySlice_New(__pyx_v_xa, __pyx_v_xb, Py_None); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2241, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __pyx_t_21 = PyTuple_New(2); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2241, __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_20); + PyTuple_SET_ITEM(__pyx_t_21, 1, __pyx_t_20); + __pyx_t_2 = 0; + __pyx_t_20 = 0; + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_mfd_buffer_array), __pyx_t_21, __pyx_t_1) < 0)) __PYX_ERR(0, 2241, __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":2245 + * + * # ensure these are set for the complier + * xi_n = -1 # <<<<<<<<<<<<<< + * yi_n = -1 + * + */ + __pyx_v_xi_n = -1; + + /* "pygeoprocessing/routing/routing.pyx":2246 + * # 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":2249 + * + * # 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":2250 + * # 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":2251 + * 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, 2251, __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":2252 + * 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_6 = ((__pyx_v_flow_dir_mfd == 0) != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/routing/routing.pyx":2254 + * 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":2252 + * 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":2256 + * 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":2257 + * + * for i_n in range(8): + * if ((flow_dir_mfd >> (i_n * 4)) & 0xF) == 0: # <<<<<<<<<<<<<< + * # no flow in that direction + * continue + */ + __pyx_t_6 = ((((__pyx_v_flow_dir_mfd >> (__pyx_v_i_n * 4)) & 0xF) == 0) != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/routing/routing.pyx":2259 + * if ((flow_dir_mfd >> (i_n * 4)) & 0xF) == 0: + * # no flow in that direction + * continue # <<<<<<<<<<<<<< + * xi_n = xi+D8_XOFFSET[i_n] + * yi_n = yi+D8_YOFFSET[i_n] + */ + goto __pyx_L23_continue; + + /* "pygeoprocessing/routing/routing.pyx":2257 + * + * 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":2260 + * # no flow in that direction + * continue + * xi_n = xi+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< + * yi_n = yi+D8_YOFFSET[i_n] + * + */ + __pyx_v_xi_n = (__pyx_v_xi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":2261 + * continue + * xi_n = xi+D8_XOFFSET[i_n] + * yi_n = yi+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< + * + * if flow_dir_mfd_buffer_array[yi_n, xi_n] == 0: + */ + __pyx_v_yi_n = (__pyx_v_yi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":2263 + * yi_n = yi+D8_YOFFSET[i_n] + * + * 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_28 = __pyx_v_yi_n; + __pyx_t_27 = __pyx_v_xi_n; + __pyx_t_30 = -1; + if (__pyx_t_28 < 0) { + __pyx_t_28 += __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[0].shape; + if (unlikely(__pyx_t_28 < 0)) __pyx_t_30 = 0; + } else if (unlikely(__pyx_t_28 >= __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[0].shape)) __pyx_t_30 = 0; + if (__pyx_t_27 < 0) { + __pyx_t_27 += __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[1].shape; + if (unlikely(__pyx_t_27 < 0)) __pyx_t_30 = 1; + } else if (unlikely(__pyx_t_27 >= __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[1].shape)) __pyx_t_30 = 1; + if (unlikely(__pyx_t_30 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_30); + __PYX_ERR(0, 2263, __pyx_L1_error) + } + __pyx_t_6 = (((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_flow_dir_mfd_buffer_array.rcbuffer->pybuffer.buf, __pyx_t_28, __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[0].strides, __pyx_t_27, __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[1].strides)) == 0) != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/routing/routing.pyx":2267 + * # 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":2268 + * # root must be a drain + * xi_root = xi-1+xoff + * yi_root = yi-1+yoff # <<<<<<<<<<<<<< + * if weight_raster is not None: + * weight_val = weight_raster.get( + */ + __pyx_v_yi_root = ((__pyx_v_yi - 1) + __pyx_v_yoff); + + /* "pygeoprocessing/routing/routing.pyx":2269 + * xi_root = xi-1+xoff + * yi_root = yi-1+yoff + * if weight_raster is not None: # <<<<<<<<<<<<<< + * weight_val = weight_raster.get( + * xi_root, yi_root) + */ + __pyx_t_6 = (((PyObject *)__pyx_v_weight_raster) != Py_None); + __pyx_t_5 = (__pyx_t_6 != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":2270 + * yi_root = yi-1+yoff + * if weight_raster is not None: + * weight_val = weight_raster.get( # <<<<<<<<<<<<<< + * xi_root, yi_root) + * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): + */ + __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":2272 + * weight_val = weight_raster.get( + * xi_root, yi_root) + * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * weight_val = 0.0 + * else: + */ + __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_weight_val, __pyx_v_weight_nodata, 1e-8, 1e-5) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":2273 + * xi_root, yi_root) + * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): + * weight_val = 0.0 # <<<<<<<<<<<<<< + * else: + * weight_val = 1.0 + */ + __pyx_v_weight_val = 0.0; + + /* "pygeoprocessing/routing/routing.pyx":2272 + * weight_val = weight_raster.get( + * xi_root, yi_root) + * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * weight_val = 0.0 + * else: + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2269 + * xi_root = xi-1+xoff + * yi_root = yi-1+yoff + * if weight_raster is not None: # <<<<<<<<<<<<<< + * weight_val = weight_raster.get( + * xi_root, yi_root) + */ + goto __pyx_L27; + } + + /* "pygeoprocessing/routing/routing.pyx":2275 + * 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":2277 + * weight_val = 1.0 + * search_stack.push( + * FlowPixelType(xi_root, yi_root, 0, weight_val)) # <<<<<<<<<<<<<< + * visited_managed_raster.set(xi_root, yi_root, 1) + * visit_count += 1 + */ + __pyx_t_31.xi = __pyx_v_xi_root; + __pyx_t_31.yi = __pyx_v_yi_root; + __pyx_t_31.last_flow_dir = 0; + __pyx_t_31.value = __pyx_v_weight_val; + + /* "pygeoprocessing/routing/routing.pyx":2276 + * else: + * weight_val = 1.0 + * search_stack.push( # <<<<<<<<<<<<<< + * FlowPixelType(xi_root, yi_root, 0, weight_val)) + * visited_managed_raster.set(xi_root, yi_root, 1) + */ + __pyx_v_search_stack.push(__pyx_t_31); + + /* "pygeoprocessing/routing/routing.pyx":2278 + * search_stack.push( + * FlowPixelType(xi_root, yi_root, 0, weight_val)) + * visited_managed_raster.set(xi_root, yi_root, 1) # <<<<<<<<<<<<<< + * visit_count += 1 + * break + */ + __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_visited_managed_raster, __pyx_v_xi_root, __pyx_v_yi_root, 1.0); + + /* "pygeoprocessing/routing/routing.pyx":2279 + * FlowPixelType(xi_root, yi_root, 0, weight_val)) + * visited_managed_raster.set(xi_root, yi_root, 1) + * visit_count += 1 # <<<<<<<<<<<<<< + * break + * + */ + __pyx_v_visit_count = (__pyx_v_visit_count + 1); + + /* "pygeoprocessing/routing/routing.pyx":2280 + * visited_managed_raster.set(xi_root, yi_root, 1) + * visit_count += 1 + * break # <<<<<<<<<<<<<< + * + * while not search_stack.empty(): + */ + goto __pyx_L24_break; + + /* "pygeoprocessing/routing/routing.pyx":2263 + * yi_n = yi+D8_YOFFSET[i_n] + * + * 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":2282 + * break + * + * while not search_stack.empty(): # <<<<<<<<<<<<<< + * flow_pixel = search_stack.top() + * search_stack.pop() + */ + while (1) { + __pyx_t_5 = ((!(__pyx_v_search_stack.empty() != 0)) != 0); + if (!__pyx_t_5) break; + + /* "pygeoprocessing/routing/routing.pyx":2283 + * + * 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":2284 + * while not search_stack.empty(): + * flow_pixel = search_stack.top() + * search_stack.pop() # <<<<<<<<<<<<<< + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + */ + __pyx_v_search_stack.pop(); + + /* "pygeoprocessing/routing/routing.pyx":2286 + * search_stack.pop() + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * LOGGER.info( + */ + __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":2287 + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< + * LOGGER.info( + * 'mfd flow accum %.1f%% complete', + */ + __pyx_v_last_log_time = time(NULL); + + /* "pygeoprocessing/routing/routing.pyx":2288 + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * last_log_time = ctime(NULL) + * LOGGER.info( # <<<<<<<<<<<<<< + * 'mfd flow accum %.1f%% complete', + * 100.0 * visit_count / float(pixel_count)) + */ + __Pyx_GetModuleGlobalName(__pyx_t_21, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2288, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_21); + __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_21, __pyx_n_s_info); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2288, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2290 + * LOGGER.info( + * 'mfd flow accum %.1f%% complete', + * 100.0 * visit_count / float(pixel_count)) # <<<<<<<<<<<<<< + * + * preempted = 0 + */ + __pyx_t_11 = (100.0 * __pyx_v_visit_count); + if (unlikely(((double)__pyx_v_pixel_count) == 0)) { + PyErr_SetString(PyExc_ZeroDivisionError, "float division"); + __PYX_ERR(0, 2290, __pyx_L1_error) + } + __pyx_t_21 = PyFloat_FromDouble((__pyx_t_11 / ((double)__pyx_v_pixel_count))); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2290, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_21); + __pyx_t_2 = NULL; + __pyx_t_29 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_20))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_20); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_20); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_20, function); + __pyx_t_29 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_20)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_kp_u_mfd_flow_accum_1f_complete, __pyx_t_21}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_20, __pyx_temp+1-__pyx_t_29, 2+__pyx_t_29); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2288, __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_20)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_kp_u_mfd_flow_accum_1f_complete, __pyx_t_21}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_20, __pyx_temp+1-__pyx_t_29, 2+__pyx_t_29); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2288, __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_3 = PyTuple_New(2+__pyx_t_29); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2288, __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_u_mfd_flow_accum_1f_complete); + __Pyx_GIVEREF(__pyx_kp_u_mfd_flow_accum_1f_complete); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_29, __pyx_kp_u_mfd_flow_accum_1f_complete); + __Pyx_GIVEREF(__pyx_t_21); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_29, __pyx_t_21); + __pyx_t_21 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_20, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2288, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2286 + * search_stack.pop() + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * LOGGER.info( + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2292 + * 100.0 * visit_count / float(pixel_count)) + * + * preempted = 0 # <<<<<<<<<<<<<< + * for i_n in range(flow_pixel.last_flow_dir, 8): + * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] + */ + __pyx_v_preempted = 0; + + /* "pygeoprocessing/routing/routing.pyx":2293 + * + * preempted = 0 + * for i_n in range(flow_pixel.last_flow_dir, 8): # <<<<<<<<<<<<<< + * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] + * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] + */ + 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":2294 + * preempted = 0 + * for i_n in range(flow_pixel.last_flow_dir, 8): + * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< + * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] + * 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_D8_XOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":2295 + * for i_n in range(flow_pixel.last_flow_dir, 8): + * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] + * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< + * 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_D8_YOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":2296 + * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] + * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] + * 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_5 = __pyx_t_6; + goto __pyx_L35_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L35_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":2297 + * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] + * 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_5 = __pyx_t_6; + goto __pyx_L35_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0); + __pyx_t_5 = __pyx_t_6; + __pyx_L35_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":2296 + * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] + * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] + * 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_5) { + + /* "pygeoprocessing/routing/routing.pyx":2299 + * yi_n < 0 or yi_n >= raster_y_size): + * # no upstream here + * continue # <<<<<<<<<<<<<< + * compressed_upstream_flow_dir = ( + * flow_dir_managed_raster.get(xi_n, yi_n)) + */ + goto __pyx_L32_continue; + + /* "pygeoprocessing/routing/routing.pyx":2296 + * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] + * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] + * 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":2301 + * continue + * compressed_upstream_flow_dir = ( + * 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":2304 + * 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":2305 + * 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_5 = ((__pyx_v_upstream_flow_weight == 0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":2307 + * 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_L32_continue; + + /* "pygeoprocessing/routing/routing.pyx":2305 + * 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":2309 + * continue + * upstream_flow_accum = ( + * flow_accum_managed_raster.get(xi_n, yi_n)) # <<<<<<<<<<<<<< + * if (_is_close(upstream_flow_accum, flow_accum_nodata, 1e-8, 1e-5) + * and not visited_managed_raster.get( + */ + __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":2310 + * upstream_flow_accum = ( + * flow_accum_managed_raster.get(xi_n, yi_n)) + * if (_is_close(upstream_flow_accum, flow_accum_nodata, 1e-8, 1e-5) # <<<<<<<<<<<<<< + * and not visited_managed_raster.get( + * xi_n, yi_n)): + */ + __pyx_t_6 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_upstream_flow_accum, __pyx_v_flow_accum_nodata, 1e-8, 1e-5) != 0); + if (__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L41_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":2311 + * flow_accum_managed_raster.get(xi_n, yi_n)) + * if (_is_close(upstream_flow_accum, flow_accum_nodata, 1e-8, 1e-5) + * and not visited_managed_raster.get( # <<<<<<<<<<<<<< + * xi_n, yi_n)): + * # process upstream before this one + */ + __pyx_t_6 = ((!(__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_visited_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n) != 0)) != 0); + __pyx_t_5 = __pyx_t_6; + __pyx_L41_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":2310 + * upstream_flow_accum = ( + * flow_accum_managed_raster.get(xi_n, yi_n)) + * if (_is_close(upstream_flow_accum, flow_accum_nodata, 1e-8, 1e-5) # <<<<<<<<<<<<<< + * and not visited_managed_raster.get( + * xi_n, yi_n)): + */ + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":2314 + * xi_n, yi_n)): + * # 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":2315 + * # 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 = weight_raster.get( + */ + __pyx_v_search_stack.push(__pyx_v_flow_pixel); + + /* "pygeoprocessing/routing/routing.pyx":2316 + * flow_pixel.last_flow_dir = i_n + * search_stack.push(flow_pixel) + * if weight_raster is not None: # <<<<<<<<<<<<<< + * weight_val = weight_raster.get( + * xi_n, yi_n) + */ + __pyx_t_5 = (((PyObject *)__pyx_v_weight_raster) != Py_None); + __pyx_t_6 = (__pyx_t_5 != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/routing/routing.pyx":2317 + * search_stack.push(flow_pixel) + * if weight_raster is not None: + * weight_val = weight_raster.get( # <<<<<<<<<<<<<< + * xi_n, yi_n) + * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): + */ + __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":2319 + * weight_val = weight_raster.get( + * xi_n, yi_n) + * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * weight_val = 0.0 + * else: + */ + __pyx_t_6 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_weight_val, __pyx_v_weight_nodata, 1e-8, 1e-5) != 0); + if (__pyx_t_6) { + + /* "pygeoprocessing/routing/routing.pyx":2320 + * xi_n, yi_n) + * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): + * weight_val = 0.0 # <<<<<<<<<<<<<< + * else: + * weight_val = 1.0 + */ + __pyx_v_weight_val = 0.0; + + /* "pygeoprocessing/routing/routing.pyx":2319 + * weight_val = weight_raster.get( + * xi_n, yi_n) + * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * weight_val = 0.0 + * else: + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2316 + * flow_pixel.last_flow_dir = i_n + * search_stack.push(flow_pixel) + * if weight_raster is not None: # <<<<<<<<<<<<<< + * weight_val = weight_raster.get( + * xi_n, yi_n) + */ + goto __pyx_L43; + } + + /* "pygeoprocessing/routing/routing.pyx":2322 + * 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_L43:; + + /* "pygeoprocessing/routing/routing.pyx":2324 + * weight_val = 1.0 + * search_stack.push( + * FlowPixelType(xi_n, yi_n, 0, weight_val)) # <<<<<<<<<<<<<< + * visited_managed_raster.set(xi_n, yi_n, 1) + * visit_count += 1 + */ + __pyx_t_31.xi = __pyx_v_xi_n; + __pyx_t_31.yi = __pyx_v_yi_n; + __pyx_t_31.last_flow_dir = 0; + __pyx_t_31.value = __pyx_v_weight_val; + + /* "pygeoprocessing/routing/routing.pyx":2323 + * else: + * weight_val = 1.0 + * search_stack.push( # <<<<<<<<<<<<<< + * FlowPixelType(xi_n, yi_n, 0, weight_val)) + * visited_managed_raster.set(xi_n, yi_n, 1) + */ + __pyx_v_search_stack.push(__pyx_t_31); + + /* "pygeoprocessing/routing/routing.pyx":2325 + * search_stack.push( + * FlowPixelType(xi_n, yi_n, 0, weight_val)) + * visited_managed_raster.set(xi_n, yi_n, 1) # <<<<<<<<<<<<<< + * visit_count += 1 + * preempted = 1 + */ + __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_visited_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n, 1.0); + + /* "pygeoprocessing/routing/routing.pyx":2326 + * FlowPixelType(xi_n, yi_n, 0, weight_val)) + * visited_managed_raster.set(xi_n, yi_n, 1) + * visit_count += 1 # <<<<<<<<<<<<<< + * preempted = 1 + * break + */ + __pyx_v_visit_count = (__pyx_v_visit_count + 1); + + /* "pygeoprocessing/routing/routing.pyx":2327 + * visited_managed_raster.set(xi_n, yi_n, 1) + * visit_count += 1 + * preempted = 1 # <<<<<<<<<<<<<< + * break + * upstream_flow_dir_sum = 0 + */ + __pyx_v_preempted = 1; + + /* "pygeoprocessing/routing/routing.pyx":2328 + * visit_count += 1 + * preempted = 1 + * break # <<<<<<<<<<<<<< + * upstream_flow_dir_sum = 0 + * for i_upstream_flow in range(8): + */ + goto __pyx_L33_break; + + /* "pygeoprocessing/routing/routing.pyx":2310 + * upstream_flow_accum = ( + * flow_accum_managed_raster.get(xi_n, yi_n)) + * if (_is_close(upstream_flow_accum, flow_accum_nodata, 1e-8, 1e-5) # <<<<<<<<<<<<<< + * and not visited_managed_raster.get( + * xi_n, yi_n)): + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2329 + * 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":2330 + * break + * upstream_flow_dir_sum = 0 + * for i_upstream_flow in range(8): # <<<<<<<<<<<<<< + * upstream_flow_dir_sum += ( + * compressed_upstream_flow_dir >> ( + */ + for (__pyx_t_30 = 0; __pyx_t_30 < 8; __pyx_t_30+=1) { + __pyx_v_i_upstream_flow = __pyx_t_30; + + /* "pygeoprocessing/routing/routing.pyx":2331 + * 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":2336 + * + * flow_pixel.value += ( + * upstream_flow_accum * upstream_flow_weight / # <<<<<<<<<<<<<< + * upstream_flow_dir_sum) + * if not preempted: + */ + __pyx_t_11 = (__pyx_v_upstream_flow_accum * __pyx_v_upstream_flow_weight); + + /* "pygeoprocessing/routing/routing.pyx":2337 + * flow_pixel.value += ( + * upstream_flow_accum * upstream_flow_weight / + * 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, 2336, __pyx_L1_error) + } + + /* "pygeoprocessing/routing/routing.pyx":2335 + * i_upstream_flow * 4)) & 0xF + * + * flow_pixel.value += ( # <<<<<<<<<<<<<< + * upstream_flow_accum * upstream_flow_weight / + * upstream_flow_dir_sum) + */ + __pyx_v_flow_pixel.value = (__pyx_v_flow_pixel.value + (__pyx_t_11 / ((double)((float)__pyx_v_upstream_flow_dir_sum)))); + __pyx_L32_continue:; + } + __pyx_L33_break:; + + /* "pygeoprocessing/routing/routing.pyx":2338 + * upstream_flow_accum * upstream_flow_weight / + * upstream_flow_dir_sum) + * 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":2339 + * 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":2338 + * upstream_flow_accum * upstream_flow_weight / + * 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":2217 + * LOGGER.debug('starting search') + * # this outer loop searches for a pixel that is locally undrained + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * flow_dir_mfd_raster_path_band, offset_only=True, + * largest_block=0): + */ + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2342 + * 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_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_flow_accum_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2342, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __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); + } + } + __pyx_t_7 = (__pyx_t_20) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_20) : __Pyx_PyObject_CallNoArg(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2342, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2343 + * flow_pixel.value) + * flow_accum_managed_raster.close() + * flow_dir_managed_raster.close() # <<<<<<<<<<<<<< + * if weight_raster is not None: + * weight_raster.close() + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_flow_dir_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2343, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __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); + } + } + __pyx_t_7 = (__pyx_t_20) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_20) : __Pyx_PyObject_CallNoArg(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2343, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2344 + * flow_accum_managed_raster.close() + * flow_dir_managed_raster.close() + * if weight_raster is not None: # <<<<<<<<<<<<<< + * weight_raster.close() + * visited_managed_raster.close() + */ + __pyx_t_6 = (((PyObject *)__pyx_v_weight_raster) != Py_None); + __pyx_t_5 = (__pyx_t_6 != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":2345 + * flow_dir_managed_raster.close() + * if weight_raster is not None: + * weight_raster.close() # <<<<<<<<<<<<<< + * visited_managed_raster.close() + * try: + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_weight_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2345, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __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); + } + } + __pyx_t_7 = (__pyx_t_20) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_20) : __Pyx_PyObject_CallNoArg(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2345, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2344 + * flow_accum_managed_raster.close() + * flow_dir_managed_raster.close() + * if weight_raster is not None: # <<<<<<<<<<<<<< + * weight_raster.close() + * visited_managed_raster.close() + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2346 + * if weight_raster is not None: + * weight_raster.close() + * visited_managed_raster.close() # <<<<<<<<<<<<<< + * try: + * shutil.rmtree(tmp_dir) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_visited_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2346, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __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); + } + } + __pyx_t_7 = (__pyx_t_20) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_20) : __Pyx_PyObject_CallNoArg(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2346, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2347 + * weight_raster.close() + * visited_managed_raster.close() + * try: # <<<<<<<<<<<<<< + * shutil.rmtree(tmp_dir) + * except OSError: + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_19, &__pyx_t_18, &__pyx_t_17); + __Pyx_XGOTREF(__pyx_t_19); + __Pyx_XGOTREF(__pyx_t_18); + __Pyx_XGOTREF(__pyx_t_17); + /*try:*/ { + + /* "pygeoprocessing/routing/routing.pyx":2348 + * visited_managed_raster.close() + * try: + * shutil.rmtree(tmp_dir) # <<<<<<<<<<<<<< + * except OSError: + * LOGGER.exception("couldn't remove temp dir") + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_shutil); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2348, __pyx_L49_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_rmtree); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2348, __pyx_L49_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_20))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_20); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_20); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_20, function); + } + } + __pyx_t_7 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_20, __pyx_t_1, __pyx_v_tmp_dir) : __Pyx_PyObject_CallOneArg(__pyx_t_20, __pyx_v_tmp_dir); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2348, __pyx_L49_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2347 + * weight_raster.close() + * visited_managed_raster.close() + * try: # <<<<<<<<<<<<<< + * shutil.rmtree(tmp_dir) + * except OSError: + */ + } + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + goto __pyx_L54_try_end; + __pyx_L49_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; + __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; + __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2349 + * try: + * shutil.rmtree(tmp_dir) + * except OSError: # <<<<<<<<<<<<<< + * LOGGER.exception("couldn't remove temp dir") + * LOGGER.info('%.1f%% complete', 100.0) + */ + __pyx_t_13 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OSError); + if (__pyx_t_13) { + __Pyx_AddTraceback("pygeoprocessing.routing.routing.flow_accumulation_mfd", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_20, &__pyx_t_1) < 0) __PYX_ERR(0, 2349, __pyx_L51_except_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GOTREF(__pyx_t_20); + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":2350 + * shutil.rmtree(tmp_dir) + * except OSError: + * LOGGER.exception("couldn't remove temp dir") # <<<<<<<<<<<<<< + * LOGGER.info('%.1f%% complete', 100.0) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_21, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2350, __pyx_L51_except_error) + __Pyx_GOTREF(__pyx_t_21); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_21, __pyx_n_s_exception); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2350, __pyx_L51_except_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; + __pyx_t_21 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_21)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_21); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_3 = (__pyx_t_21) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_21, __pyx_kp_u_couldn_t_remove_temp_dir) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_kp_u_couldn_t_remove_temp_dir); + __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2350, __pyx_L51_except_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L50_exception_handled; + } + goto __pyx_L51_except_error; + __pyx_L51_except_error:; + + /* "pygeoprocessing/routing/routing.pyx":2347 + * weight_raster.close() + * visited_managed_raster.close() + * try: # <<<<<<<<<<<<<< + * shutil.rmtree(tmp_dir) + * except OSError: + */ + __Pyx_XGIVEREF(__pyx_t_19); + __Pyx_XGIVEREF(__pyx_t_18); + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_ExceptionReset(__pyx_t_19, __pyx_t_18, __pyx_t_17); + goto __pyx_L1_error; + __pyx_L50_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_19); + __Pyx_XGIVEREF(__pyx_t_18); + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_ExceptionReset(__pyx_t_19, __pyx_t_18, __pyx_t_17); + __pyx_L54_try_end:; + } + + /* "pygeoprocessing/routing/routing.pyx":2351 + * except OSError: + * LOGGER.exception("couldn't remove temp dir") + * LOGGER.info('%.1f%% complete', 100.0) # <<<<<<<<<<<<<< + * + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2351, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_info); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2351, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_20, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2351, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2073 + * + * + * 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_7); + __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(__pyx_v_tmp_dir_root); + __Pyx_XDECREF(__pyx_v_tmp_dir); + __Pyx_XDECREF(__pyx_v_visited_raster_path); + __Pyx_XDECREF((PyObject *)__pyx_v_visited_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":2354 + * + * + * 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\n 3 2 1\n 4 x 0\n 5 6 7\n\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 (str): 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 raster_driver_creation_tuple (tuple): a tuple containing a GDAL driver\n name string as the first element and a GDAL creation options\n tuple/list as the second. Defaults to a GTiff driver tuple\n defined at geoprocessing.DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS.\n\n Returns:\n None.\n "; +static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_13distance_to_channel_d8 = {"distance_to_channel_d8", (PyCFunction)(void*)(PyCFunctionWithKeywords)__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_raster_driver_creation_tuple = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 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_raster_driver_creation_tuple,0}; + PyObject* values[5] = {0,0,0,0,0}; + + /* "pygeoprocessing/routing/routing.pyx":2357 + * flow_dir_d8_raster_path_band, channel_raster_path_band, + * target_distance_to_channel_raster_path, + * weight_raster_path_band=None, # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): + * """Calculate distance to channel with D8 flow. + */ + values[3] = ((PyObject *)Py_None); + values[4] = __pyx_k__12; + 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, 2354, __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, 2354, __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_raster_driver_creation_tuple); + 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, 2354, __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_raster_driver_creation_tuple = 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, 2354, __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_raster_driver_creation_tuple); + + /* "pygeoprocessing/routing/routing.pyx":2354 + * + * + * 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_raster_driver_creation_tuple) { + 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 __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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __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":2411 + * # 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":2415 + * # 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":2418 + * + * 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, 2418, __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":2417 + * 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, 2417, __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, 2417, __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":2420 + * 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_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_is_raster_path_band_formatted); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2420, __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); + } + } + __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_v_path) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_path); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2420, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __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, 2420, __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":2422 + * 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_PyUnicode_FormatSafe(__pyx_kp_u_s_is_supposed_to_be_a_raster_ba, __pyx_v_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2422, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":2421 + * 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, 2421, __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, 2421, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2420 + * 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":2417 + * 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":2425 + * 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":2426 + * + * distance_nodata = -1 + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band[0], + * target_distance_to_channel_raster_path, + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2426, __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, 2426, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2427 + * 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, 2427, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + + /* "pygeoprocessing/routing/routing.pyx":2429 + * flow_dir_d8_raster_path_band[0], + * target_distance_to_channel_raster_path, + * gdal.GDT_Float64, [distance_nodata], # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * distance_to_channel_managed_raster = _ManagedRaster( + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2429, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2429, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __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, 2429, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = PyList_New(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2429, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_1); + PyList_SET_ITEM(__pyx_t_9, 0, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2426 + * + * 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, 2426, __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_8); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_9); + __pyx_t_2 = 0; + __pyx_t_8 = 0; + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2430 + * target_distance_to_channel_raster_path, + * gdal.GDT_Float64, [distance_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< + * distance_to_channel_managed_raster = _ManagedRaster( + * target_distance_to_channel_raster_path, 1, 1) + */ + __pyx_t_9 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2430, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 2430, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2426 + * + * distance_nodata = -1 + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band[0], + * target_distance_to_channel_raster_path, + */ + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_1, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2426, __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_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2431 + * gdal.GDT_Float64, [distance_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * distance_to_channel_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< + * target_distance_to_channel_raster_path, 1, 1) + * + */ + __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2431, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __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_8, 0, __pyx_v_target_distance_to_channel_raster_path); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_int_1); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_int_1); + __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, 2431, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_distance_to_channel_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_9); + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2434 + * 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":2435 + * + * 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, 2435, __pyx_L1_error) + if (__pyx_t_4) { + + /* "pygeoprocessing/routing/routing.pyx":2437 + * 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_9 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2437, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __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, 2437, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + + /* "pygeoprocessing/routing/routing.pyx":2436 + * 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, 2436, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_8); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_1, 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_1, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2436, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __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_8)); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2438 + * 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_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2438, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2438, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2439 + * 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, 2439, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(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); + } + } + __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_7, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_1); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2438, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_PyObject_Dict_GetItem(__pyx_t_8, __pyx_n_u_nodata); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2439, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2440 + * 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, 2440, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = __Pyx_PyInt_SubtractObjC(__pyx_t_8, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2440, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2439 + * 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_9, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2439, __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_v_raw_weight_nodata = __pyx_t_8; + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2441 + * 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":2442 + * 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, 2442, __pyx_L1_error) + __pyx_v_weight_nodata = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":2441 + * 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":2435 + * + * 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":2445 + * + * channel_managed_raster = _ManagedRaster( + * channel_raster_path_band[0], channel_raster_path_band[1], 0) # <<<<<<<<<<<<<< + * + * flow_dir_d8_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, 2445, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_channel_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2445, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":2444 + * weight_nodata = raw_weight_nodata + * + * channel_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< + * channel_raster_path_band[0], channel_raster_path_band[1], 0) + * + */ + __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2444, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_1); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_9, 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_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2444, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_v_channel_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2448 + * + * 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_1 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2448, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2448, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + + /* "pygeoprocessing/routing/routing.pyx":2447 + * 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_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2447, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1); + __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_1 = 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, 2447, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_flow_dir_d8_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_9); + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2449 + * 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_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_gdal); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2449, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2449, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __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, 2449, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2449, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2449, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + __pyx_t_11 = 0; + 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); + __pyx_t_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_8, __pyx_t_2}; + __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2449, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __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_7, __pyx_t_8, __pyx_t_2}; + __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2449, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + { + __pyx_t_12 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2449, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_11, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_11, __pyx_t_2); + __pyx_t_8 = 0; + __pyx_t_2 = 0; + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_12, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2449, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_channel_raster = __pyx_t_9; + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2450 + * 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_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_channel_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2450, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __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, 2450, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_9 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_t_12) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_12); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2450, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_channel_band = __pyx_t_9; + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2452 + * 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_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2452, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2452, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2453 + * + * 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_1 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 0, 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); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + } + } + __pyx_t_9 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_2, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2452, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_v_flow_dir_raster_info = __pyx_t_9; + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2454 + * 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_9 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_raster_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2454, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + 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 != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 2454, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_12 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_12 = PyList_GET_ITEM(sequence, 0); + __pyx_t_1 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(__pyx_t_1); + #else + __pyx_t_12 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2454, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2454, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_2 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2454, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_13 = Py_TYPE(__pyx_t_2)->tp_iternext; + index = 0; __pyx_t_12 = __pyx_t_13(__pyx_t_2); if (unlikely(!__pyx_t_12)) goto __pyx_L10_unpacking_failed; + __Pyx_GOTREF(__pyx_t_12); + index = 1; __pyx_t_1 = __pyx_t_13(__pyx_t_2); if (unlikely(!__pyx_t_1)) goto __pyx_L10_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_2), 2) < 0) __PYX_ERR(0, 2454, __pyx_L1_error) + __pyx_t_13 = NULL; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L11_unpacking_done; + __pyx_L10_unpacking_failed:; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_13 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 2454, __pyx_L1_error) + __pyx_L11_unpacking_done:; + } + __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_12); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2454, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2454, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_raster_x_size = __pyx_t_11; + __pyx_v_raster_y_size = __pyx_t_14; + + /* "pygeoprocessing/routing/routing.pyx":2457 + * + * # this outer loop searches for undefined channels + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * channel_raster_path_band, offset_only=True, largest_block=0): + * win_xsize = offset_dict['win_xsize'] + */ + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2457, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2457, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2458 + * # this outer loop searches for undefined channels + * for offset_dict in pygeoprocessing.iterblocks( + * channel_raster_path_band, offset_only=True, largest_block=0): # <<<<<<<<<<<<<< + * win_xsize = offset_dict['win_xsize'] + * win_ysize = offset_dict['win_ysize'] + */ + __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2457, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_INCREF(__pyx_v_channel_raster_path_band); + __Pyx_GIVEREF(__pyx_v_channel_raster_path_band); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_channel_raster_path_band); + __pyx_t_12 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2458, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 2458, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_largest_block, __pyx_int_0) < 0) __PYX_ERR(0, 2458, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2457 + * + * # this outer loop searches for undefined channels + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * channel_raster_path_band, offset_only=True, largest_block=0): + * win_xsize = offset_dict['win_xsize'] + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, __pyx_t_12); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2457, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_12 = __pyx_t_2; __Pyx_INCREF(__pyx_t_12); __pyx_t_3 = 0; + __pyx_t_15 = NULL; + } else { + __pyx_t_3 = -1; __pyx_t_12 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2457, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_15 = Py_TYPE(__pyx_t_12)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2457, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (likely(!__pyx_t_15)) { + if (likely(PyList_CheckExact(__pyx_t_12))) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_12)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_12, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 2457, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_12, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2457, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } else { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_12)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_12, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 2457, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_12, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2457, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } + } else { + __pyx_t_2 = __pyx_t_15(__pyx_t_12); + if (unlikely(!__pyx_t_2)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 2457, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XDECREF_SET(__pyx_v_offset_dict, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2459 + * for offset_dict in pygeoprocessing.iterblocks( + * channel_raster_path_band, offset_only=True, largest_block=0): + * win_xsize = offset_dict['win_xsize'] # <<<<<<<<<<<<<< + * win_ysize = offset_dict['win_ysize'] + * xoff = offset_dict['xoff'] + */ + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2459, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2459, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_win_xsize = __pyx_t_14; + + /* "pygeoprocessing/routing/routing.pyx":2460 + * channel_raster_path_band, 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_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2460, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2460, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_win_ysize = __pyx_t_14; + + /* "pygeoprocessing/routing/routing.pyx":2461 + * win_xsize = offset_dict['win_xsize'] + * win_ysize = offset_dict['win_ysize'] + * xoff = offset_dict['xoff'] # <<<<<<<<<<<<<< + * yoff = offset_dict['yoff'] + * + */ + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_xoff); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2461, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2461, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_xoff = __pyx_t_14; + + /* "pygeoprocessing/routing/routing.pyx":2462 + * win_ysize = offset_dict['win_ysize'] + * xoff = offset_dict['xoff'] + * yoff = offset_dict['yoff'] # <<<<<<<<<<<<<< + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + */ + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_yoff); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2462, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2462, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_yoff = __pyx_t_14; + + /* "pygeoprocessing/routing/routing.pyx":2464 + * yoff = offset_dict['yoff'] + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + */ + __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":2465 + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + */ + __pyx_v_last_log_time = time(NULL); + + /* "pygeoprocessing/routing/routing.pyx":2466 + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size # <<<<<<<<<<<<<< + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + * raster_x_size * raster_y_size)) + */ + __pyx_t_2 = __Pyx_PyInt_From_int((__pyx_v_xoff + (__pyx_v_yoff * __pyx_v_raster_x_size))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2466, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XDECREF_SET(__pyx_v_current_pixel, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2467 + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< + * raster_x_size * raster_y_size)) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2467, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2467, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = PyNumber_Multiply(__pyx_float_100_0, __pyx_v_current_pixel); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2467, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + + /* "pygeoprocessing/routing/routing.pyx":2468 + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + * raster_x_size * raster_y_size)) # <<<<<<<<<<<<<< + * + * # make a buffer big enough to capture block and boundaries around it + */ + __pyx_t_8 = PyFloat_FromDouble(((float)(__pyx_v_raster_x_size * __pyx_v_raster_y_size))); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2467, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + + /* "pygeoprocessing/routing/routing.pyx":2467 + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< + * raster_x_size * raster_y_size)) + * + */ + __pyx_t_7 = __Pyx_PyNumber_Divide(__pyx_t_9, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2467, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + __pyx_t_14 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + __pyx_t_14 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_kp_u_1f_complete, __pyx_t_7}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2467, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_kp_u_1f_complete, __pyx_t_7}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2467, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_9 = PyTuple_New(2+__pyx_t_14); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2467, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + if (__pyx_t_8) { + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; + } + __Pyx_INCREF(__pyx_kp_u_1f_complete); + __Pyx_GIVEREF(__pyx_kp_u_1f_complete); + PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_14, __pyx_kp_u_1f_complete); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_14, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2467, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2464 + * yoff = offset_dict['yoff'] + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2471 + * + * # 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2471, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2471, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2472 + * # 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_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2472, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2472, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2472, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2472, __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, 2472, __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_7); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_7); + __pyx_t_9 = 0; + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2471 + * + * # 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_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2471, __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":2473 + * 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_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2473, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_numpy); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2473, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_uint8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2473, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 2473, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2471 + * + * # 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_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2471, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2471, __pyx_L1_error) + __pyx_t_16 = ((PyArrayObject *)__pyx_t_8); + { + __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, 2471, __pyx_L1_error) + } + __pyx_t_16 = 0; + __Pyx_XDECREF_SET(__pyx_v_channel_buffer_array, ((PyArrayObject *)__pyx_t_8)); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2474 + * (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__7, __pyx_int_0) < 0)) __PYX_ERR(0, 2474, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2478 + * # 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_generate_read_bounds); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2478, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + + /* "pygeoprocessing/routing/routing.pyx":2479 + * # 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, 2479, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_raster_y_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2479, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = NULL; + __pyx_t_14 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(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); + __pyx_t_14 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[4] = {__pyx_t_9, __pyx_v_offset_dict, __pyx_t_7, __pyx_t_1}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_14, 3+__pyx_t_14); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2478, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[4] = {__pyx_t_9, __pyx_v_offset_dict, __pyx_t_7, __pyx_t_1}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_14, 3+__pyx_t_14); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2478, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + { + __pyx_t_20 = PyTuple_New(3+__pyx_t_14); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2478, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + if (__pyx_t_9) { + __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_9); __pyx_t_9 = 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_7); + PyTuple_SET_ITEM(__pyx_t_20, 1+__pyx_t_14, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_20, 2+__pyx_t_14, __pyx_t_1); + __pyx_t_7 = 0; + __pyx_t_1 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_20, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2478, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + 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, 2478, __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_20 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_2 = PyList_GET_ITEM(sequence, 0); + __pyx_t_20 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_20); + #else + __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2478, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_20 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2478, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + #endif + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_1 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2478, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_13 = Py_TYPE(__pyx_t_1)->tp_iternext; + index = 0; __pyx_t_2 = __pyx_t_13(__pyx_t_1); if (unlikely(!__pyx_t_2)) goto __pyx_L15_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + index = 1; __pyx_t_20 = __pyx_t_13(__pyx_t_1); if (unlikely(!__pyx_t_20)) goto __pyx_L15_unpacking_failed; + __Pyx_GOTREF(__pyx_t_20); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_1), 2) < 0) __PYX_ERR(0, 2478, __pyx_L1_error) + __pyx_t_13 = 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_13 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 2478, __pyx_L1_error) + __pyx_L16_unpacking_done:; + } + + /* "pygeoprocessing/routing/routing.pyx":2478 + * # 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, 2478, __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); + __pyx_t_9 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_21 = PyTuple_GET_ITEM(sequence, 3); + } else { + __pyx_t_1 = PyList_GET_ITEM(sequence, 0); + __pyx_t_7 = PyList_GET_ITEM(sequence, 1); + __pyx_t_9 = PyList_GET_ITEM(sequence, 2); + __pyx_t_21 = PyList_GET_ITEM(sequence, 3); + } + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(__pyx_t_21); + #else + { + Py_ssize_t i; + PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_7,&__pyx_t_9,&__pyx_t_21}; + for (i=0; i < 4; i++) { + PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 2478, __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_1,&__pyx_t_7,&__pyx_t_9,&__pyx_t_21}; + __pyx_t_22 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2478, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_22); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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, 2478, __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, 2478, __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_7); + __pyx_t_7 = 0; + __Pyx_XDECREF_SET(__pyx_v_ya, __pyx_t_9); + __pyx_t_9 = 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":2480 + * (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, 2480, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + + /* "pygeoprocessing/routing/routing.pyx":2481 + * 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, 2481, __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, 2481, __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, 2480, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + } + + /* "pygeoprocessing/routing/routing.pyx":2480 + * (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_2); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2480, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_21); + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2481 + * 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_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_21, __pyx_n_s_astype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2481, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_21, __pyx_n_s_numpy); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2481, __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, 2481, __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_2))) { + __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_21)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_21); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_8 = (__pyx_t_21) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_21, __pyx_t_20) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_20); + __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2481, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2480 + * (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, 2480, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_20 = PySlice_New(__pyx_v_xa, __pyx_v_xb, Py_None); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2480, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __pyx_t_21 = PyTuple_New(2); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2480, __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_20); + PyTuple_SET_ITEM(__pyx_t_21, 1, __pyx_t_20); + __pyx_t_2 = 0; + __pyx_t_20 = 0; + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_channel_buffer_array), __pyx_t_21, __pyx_t_8) < 0)) __PYX_ERR(0, 2480, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2484 + * + * # ensure these are set for the complier + * xi_n = -1 # <<<<<<<<<<<<<< + * yi_n = -1 + * + */ + __pyx_v_xi_n = -1; + + /* "pygeoprocessing/routing/routing.pyx":2485 + * # 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":2488 + * + * # 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":2489 + * # 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":2490 + * 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, 2490, __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":2492 + * if channel_buffer_array[yi, xi] != 1: + * # no channel seed + * continue # <<<<<<<<<<<<<< + * + * distance_to_channel_stack.push( + */ + goto __pyx_L21_continue; + + /* "pygeoprocessing/routing/routing.pyx":2490 + * 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":2495 + * + * 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":2494 + * 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":2497 + * 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":2498 + * + * 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":2499 + * 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":2500 + * 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":2501 + * 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":2503 + * 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":2506 + * xi_q, yi_q, pixel_val) + * + * for i_n in range(8): # <<<<<<<<<<<<<< + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] + */ + for (__pyx_t_29 = 0; __pyx_t_29 < 8; __pyx_t_29+=1) { + __pyx_v_i_n = __pyx_t_29; + + /* "pygeoprocessing/routing/routing.pyx":2507 + * + * for i_n in range(8): + * xi_n = xi_q+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< + * yi_n = yi_q+D8_YOFFSET[i_n] + * + */ + __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":2508 + * for i_n in range(8): + * xi_n = xi_q+D8_XOFFSET[i_n] + * yi_n = yi_q+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< + * + * if (xi_n < 0 or xi_n >= raster_x_size or + */ + __pyx_v_yi_n = (__pyx_v_yi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":2510 + * yi_n = yi_q+D8_YOFFSET[i_n] + * + * 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":2511 + * + * 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":2510 + * yi_n = yi_q+D8_YOFFSET[i_n] + * + * 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":2512 + * 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":2510 + * yi_n = yi_q+D8_YOFFSET[i_n] + * + * 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":2514 + * 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":2517 + * # 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":2514 + * 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":2519 + * 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":2526 + * # 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, 1e-8, 1e-5): + */ + __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":2527 + * # 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, 1e-8, 1e-5): + * 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":2528 + * if weight_raster is not None: + * weight_val = weight_raster.get(xi_n, yi_n) + * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * weight_val = 0.0 + * else: + */ + __pyx_t_4 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_weight_val, __pyx_v_weight_nodata, 1e-8, 1e-5) != 0); + if (__pyx_t_4) { + + /* "pygeoprocessing/routing/routing.pyx":2529 + * weight_val = weight_raster.get(xi_n, yi_n) + * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): + * weight_val = 0.0 # <<<<<<<<<<<<<< + * else: + * weight_val = (SQRT2 if i_n % 2 else 1) + */ + __pyx_v_weight_val = 0.0; + + /* "pygeoprocessing/routing/routing.pyx":2528 + * if weight_raster is not None: + * weight_val = weight_raster.get(xi_n, yi_n) + * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * weight_val = 0.0 + * else: + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2526 + * # 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, 1e-8, 1e-5): + */ + goto __pyx_L35; + } + + /* "pygeoprocessing/routing/routing.pyx":2531 + * 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":2535 + * 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":2533 + * 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":2519 + * 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":2457 + * + * # this outer loop searches for undefined channels + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * channel_raster_path_band, offset_only=True, largest_block=0): + * win_xsize = offset_dict['win_xsize'] + */ + } + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2537 + * 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_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_distance_to_channel_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2537, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_21 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_21)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_21); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_12 = (__pyx_t_21) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_21) : __Pyx_PyObject_CallNoArg(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2537, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2538 + * + * distance_to_channel_managed_raster.close() + * flow_dir_d8_managed_raster.close() # <<<<<<<<<<<<<< + * channel_managed_raster.close() + * if weight_raster is not None: + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_flow_dir_d8_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2538, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_21 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_21)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_21); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_12 = (__pyx_t_21) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_21) : __Pyx_PyObject_CallNoArg(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2538, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2539 + * 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_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_channel_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2539, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_21 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_21)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_21); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_12 = (__pyx_t_21) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_21) : __Pyx_PyObject_CallNoArg(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2539, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2540 + * 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":2541 + * channel_managed_raster.close() + * if weight_raster is not None: + * weight_raster.close() # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_weight_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2541, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_21 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_21)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_21); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_12 = (__pyx_t_21) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_21) : __Pyx_PyObject_CallNoArg(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2541, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2540 + * flow_dir_d8_managed_raster.close() + * channel_managed_raster.close() + * if weight_raster is not None: # <<<<<<<<<<<<<< + * weight_raster.close() + * + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2354 + * + * + * 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":2544 + * + * + * 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 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 (str): 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 raster_driver_creation_tuple (tuple): a tuple containing a GDAL driver\n name string as the first element and a GDAL creation options\n tuple/list as the second. Defaults to a GTiff driver tuple\n defined at ``geoprocessing.DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS``.\n\n Returns:\n None.\n "; +static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_15distance_to_channel_mfd = {"distance_to_channel_mfd", (PyCFunction)(void*)(PyCFunctionWithKeywords)__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_raster_driver_creation_tuple = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 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_raster_driver_creation_tuple,0}; + PyObject* values[5] = {0,0,0,0,0}; + + /* "pygeoprocessing/routing/routing.pyx":2546 + * 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, # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): + * """Calculate distance to channel with multiple flow direction. + */ + values[3] = ((PyObject *)Py_None); + values[4] = __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 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, 2544, __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, 2544, __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_raster_driver_creation_tuple); + 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, 2544, __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_raster_driver_creation_tuple = 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, 2544, __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_raster_driver_creation_tuple); + + /* "pygeoprocessing/routing/routing.pyx":2544 + * + * + * 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_raster_driver_creation_tuple) { + 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 __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; + 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_channel_managed_raster = NULL; + PyObject *__pyx_v_tmp_work_dir = NULL; + PyObject *__pyx_v_visited_raster_path = NULL; + struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_visited_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; + struct __pyx_t_15pygeoprocessing_7routing_7routing_FlowPixelType __pyx_t_31; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __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":2600 + * # 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":2604 + * # 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":2607 + * + * 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, 2607, __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":2606 + * 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, 2606, __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, 2606, __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":2609 + * 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_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_is_raster_path_band_formatted); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2609, __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); + } + } + __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_v_path) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_path); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2609, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __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, 2609, __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":2611 + * 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_PyUnicode_FormatSafe(__pyx_kp_u_s_is_supposed_to_be_a_raster_ba, __pyx_v_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2611, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":2610 + * 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, 2610, __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, 2610, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2609 + * 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":2606 + * 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":2614 + * path)) + * + * distance_nodata = -1 # <<<<<<<<<<<<<< + * pygeoprocessing.new_raster_from_base( + * flow_dir_mfd_raster_path_band[0], + */ + __pyx_v_distance_nodata = -1L; + + /* "pygeoprocessing/routing/routing.pyx":2615 + * + * distance_nodata = -1 + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * flow_dir_mfd_raster_path_band[0], + * target_distance_to_channel_raster_path, + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2615, __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, 2615, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2616 + * distance_nodata = -1 + * 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, 2616, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + + /* "pygeoprocessing/routing/routing.pyx":2618 + * flow_dir_mfd_raster_path_band[0], + * target_distance_to_channel_raster_path, + * gdal.GDT_Float64, [distance_nodata], # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * distance_to_channel_managed_raster = _ManagedRaster( + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2618, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2618, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __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, 2618, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = PyList_New(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2618, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_1); + PyList_SET_ITEM(__pyx_t_9, 0, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2615 + * + * distance_nodata = -1 + * 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, 2615, __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_8); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_9); + __pyx_t_2 = 0; + __pyx_t_8 = 0; + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2619 + * target_distance_to_channel_raster_path, + * gdal.GDT_Float64, [distance_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< + * distance_to_channel_managed_raster = _ManagedRaster( + * target_distance_to_channel_raster_path, 1, 1) + */ + __pyx_t_9 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2619, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 2619, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2615 + * + * distance_nodata = -1 + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * flow_dir_mfd_raster_path_band[0], + * target_distance_to_channel_raster_path, + */ + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_1, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2615, __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_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2620 + * gdal.GDT_Float64, [distance_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * distance_to_channel_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< + * target_distance_to_channel_raster_path, 1, 1) + * channel_managed_raster = _ManagedRaster( + */ + __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2620, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __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_8, 0, __pyx_v_target_distance_to_channel_raster_path); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_int_1); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_int_1); + __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, 2620, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_distance_to_channel_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_9); + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2623 + * target_distance_to_channel_raster_path, 1, 1) + * channel_managed_raster = _ManagedRaster( + * channel_raster_path_band[0], channel_raster_path_band[1], 0) # <<<<<<<<<<<<<< + * + * tmp_work_dir = tempfile.mkdtemp( + */ + __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_channel_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2623, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_channel_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2623, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + + /* "pygeoprocessing/routing/routing.pyx":2622 + * distance_to_channel_managed_raster = _ManagedRaster( + * 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, 2622, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_8); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_1, 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_1, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2622, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_channel_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2625 + * channel_raster_path_band[0], channel_raster_path_band[1], 0) + * + * tmp_work_dir = tempfile.mkdtemp( # <<<<<<<<<<<<<< + * suffix=None, prefix='dist_to_channel_mfd_work_dir', + * dir=os.path.dirname(target_distance_to_channel_raster_path)) + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_tempfile); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2625, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_mkdtemp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2625, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2626 + * + * tmp_work_dir = tempfile.mkdtemp( + * suffix=None, prefix='dist_to_channel_mfd_work_dir', # <<<<<<<<<<<<<< + * dir=os.path.dirname(target_distance_to_channel_raster_path)) + * visited_raster_path = os.path.join(tmp_work_dir, 'visited.tif') + */ + __pyx_t_8 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2626, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_suffix, Py_None) < 0) __PYX_ERR(0, 2626, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_prefix, __pyx_n_u_dist_to_channel_mfd_work_dir) < 0) __PYX_ERR(0, 2626, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2627 + * tmp_work_dir = tempfile.mkdtemp( + * suffix=None, prefix='dist_to_channel_mfd_work_dir', + * dir=os.path.dirname(target_distance_to_channel_raster_path)) # <<<<<<<<<<<<<< + * visited_raster_path = os.path.join(tmp_work_dir, 'visited.tif') + * pygeoprocessing.new_raster_from_base( + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_os); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2627, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_path); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2627, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_dirname); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2627, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_9 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_2, __pyx_v_target_distance_to_channel_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_target_distance_to_channel_raster_path); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2627, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_dir, __pyx_t_9) < 0) __PYX_ERR(0, 2626, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2625 + * channel_raster_path_band[0], channel_raster_path_band[1], 0) + * + * tmp_work_dir = tempfile.mkdtemp( # <<<<<<<<<<<<<< + * suffix=None, prefix='dist_to_channel_mfd_work_dir', + * dir=os.path.dirname(target_distance_to_channel_raster_path)) + */ + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2625, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_tmp_work_dir = __pyx_t_9; + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2628 + * suffix=None, prefix='dist_to_channel_mfd_work_dir', + * dir=os.path.dirname(target_distance_to_channel_raster_path)) + * visited_raster_path = os.path.join(tmp_work_dir, 'visited.tif') # <<<<<<<<<<<<<< + * pygeoprocessing.new_raster_from_base( + * flow_dir_mfd_raster_path_band[0], + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_os); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2628, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2628, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_join); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2628, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_1); + __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_1, __pyx_v_tmp_work_dir, __pyx_kp_u_visited_tif}; + __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2628, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_9); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_tmp_work_dir, __pyx_kp_u_visited_tif}; + __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2628, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_9); + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2628, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_1) { + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1); __pyx_t_1 = NULL; + } + __Pyx_INCREF(__pyx_v_tmp_work_dir); + __Pyx_GIVEREF(__pyx_v_tmp_work_dir); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_10, __pyx_v_tmp_work_dir); + __Pyx_INCREF(__pyx_kp_u_visited_tif); + __Pyx_GIVEREF(__pyx_kp_u_visited_tif); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_10, __pyx_kp_u_visited_tif); + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_7, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2628, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_visited_raster_path = __pyx_t_9; + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2629 + * dir=os.path.dirname(target_distance_to_channel_raster_path)) + * visited_raster_path = os.path.join(tmp_work_dir, 'visited.tif') + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * flow_dir_mfd_raster_path_band[0], + * visited_raster_path, + */ + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2629, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2629, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2630 + * visited_raster_path = os.path.join(tmp_work_dir, 'visited.tif') + * pygeoprocessing.new_raster_from_base( + * flow_dir_mfd_raster_path_band[0], # <<<<<<<<<<<<<< + * visited_raster_path, + * gdal.GDT_Byte, [0], + */ + __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, 2630, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + + /* "pygeoprocessing/routing/routing.pyx":2632 + * flow_dir_mfd_raster_path_band[0], + * visited_raster_path, + * gdal.GDT_Byte, [0], # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * visited_managed_raster = _ManagedRaster(visited_raster_path, 1, 1) + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2632, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2632, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = PyList_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2632, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyList_SET_ITEM(__pyx_t_7, 0, __pyx_int_0); + + /* "pygeoprocessing/routing/routing.pyx":2629 + * dir=os.path.dirname(target_distance_to_channel_raster_path)) + * visited_raster_path = os.path.join(tmp_work_dir, 'visited.tif') + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * flow_dir_mfd_raster_path_band[0], + * visited_raster_path, + */ + __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2629, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_9); + __Pyx_INCREF(__pyx_v_visited_raster_path); + __Pyx_GIVEREF(__pyx_v_visited_raster_path); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_visited_raster_path); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_7); + __pyx_t_9 = 0; + __pyx_t_1 = 0; + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2633 + * visited_raster_path, + * gdal.GDT_Byte, [0], + * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< + * visited_managed_raster = _ManagedRaster(visited_raster_path, 1, 1) + * + */ + __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2633, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 2633, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2629 + * dir=os.path.dirname(target_distance_to_channel_raster_path)) + * visited_raster_path = os.path.join(tmp_work_dir, 'visited.tif') + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * flow_dir_mfd_raster_path_band[0], + * visited_raster_path, + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_2, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2629, __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_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2634 + * gdal.GDT_Byte, [0], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * visited_managed_raster = _ManagedRaster(visited_raster_path, 1, 1) # <<<<<<<<<<<<<< + * + * flow_dir_mfd_managed_raster = _ManagedRaster( + */ + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2634, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_visited_raster_path); + __Pyx_GIVEREF(__pyx_v_visited_raster_path); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_visited_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_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_1, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2634, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_visited_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_7); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2637 + * + * 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_7 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2637, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __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, 2637, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":2636 + * visited_managed_raster = _ManagedRaster(visited_raster_path, 1, 1) + * + * 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_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2636, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_int_0); + __pyx_t_7 = 0; + __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2636, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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":2638 + * 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2638, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2638, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __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, 2638, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_gdal); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2638, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2638, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + __pyx_t_10 = 0; + 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); + __pyx_t_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_2, __pyx_t_9}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2638, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 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_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_2, __pyx_t_9}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2638, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 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_11 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2638, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + if (__pyx_t_8) { + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_8); __pyx_t_8 = NULL; + } + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_t_9); + __pyx_t_2 = 0; + __pyx_t_9 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_11, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2638, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_channel_raster = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2639 + * 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_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_channel_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2639, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __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, 2639, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_9, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_11); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2639, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_channel_band = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2641 + * 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_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2641, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2641, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2642 + * + * 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_7 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2642, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_gdal); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2642, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2642, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + __pyx_t_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_7, __pyx_t_2}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2641, __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; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_7, __pyx_t_2}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2641, __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; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + { + __pyx_t_8 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2641, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + if (__pyx_t_9) { + __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_9); __pyx_t_9 = NULL; + } + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_10, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_10, __pyx_t_2); + __pyx_t_7 = 0; + __pyx_t_2 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2641, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_v_flow_dir_mfd_raster = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2643 + * 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_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_mfd_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2643, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + + /* "pygeoprocessing/routing/routing.pyx":2644 + * 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_8 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2644, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __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); + } + } + __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_2, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_8); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2643, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_v_flow_dir_mfd_band = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2646 + * 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":2647 + * + * 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, 2647, __pyx_L1_error) + if (__pyx_t_4) { + + /* "pygeoprocessing/routing/routing.pyx":2649 + * 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, 2649, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2649, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + + /* "pygeoprocessing/routing/routing.pyx":2648 + * 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_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2648, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_11); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_int_0); + __pyx_t_1 = 0; + __pyx_t_11 = 0; + __pyx_t_11 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_8, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2648, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF_SET(__pyx_v_weight_raster, ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_11)); + __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2650 + * 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_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2650, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2650, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2651 + * 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_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, 2651, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __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); + } + } + __pyx_t_11 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_8); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2650, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_t_11, __pyx_n_u_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2651, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2652 + * 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_11 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2652, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_8 = __Pyx_PyInt_SubtractObjC(__pyx_t_11, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2652, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2651 + * 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_11 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_8); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2651, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_raw_weight_nodata = __pyx_t_11; + __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2653 + * 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":2654 + * 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, 2654, __pyx_L1_error) + __pyx_v_weight_nodata = __pyx_t_12; + + /* "pygeoprocessing/routing/routing.pyx":2653 + * 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":2656 + * 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":2647 + * + * 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":2658 + * 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_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2658, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2658, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2659 + * + * 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_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, 2659, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __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); + } + } + __pyx_t_11 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_8); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2658, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_flow_dir_raster_info = __pyx_t_11; + __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2660 + * 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_11 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_raster_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2660, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + if ((likely(PyTuple_CheckExact(__pyx_t_11))) || (PyList_CheckExact(__pyx_t_11))) { + PyObject* sequence = __pyx_t_11; + 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, 2660, __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_8 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_1 = PyList_GET_ITEM(sequence, 0); + __pyx_t_8 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_8); + #else + __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2660, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2660, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + #endif + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_2 = PyObject_GetIter(__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2660, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_13 = Py_TYPE(__pyx_t_2)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_13(__pyx_t_2); if (unlikely(!__pyx_t_1)) goto __pyx_L10_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 1; __pyx_t_8 = __pyx_t_13(__pyx_t_2); if (unlikely(!__pyx_t_8)) goto __pyx_L10_unpacking_failed; + __Pyx_GOTREF(__pyx_t_8); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_2), 2) < 0) __PYX_ERR(0, 2660, __pyx_L1_error) + __pyx_t_13 = NULL; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L11_unpacking_done; + __pyx_L10_unpacking_failed:; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_13 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 2660, __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, 2660, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_8); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2660, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_raster_x_size = __pyx_t_10; + __pyx_v_raster_y_size = __pyx_t_14; + + /* "pygeoprocessing/routing/routing.pyx":2663 + * + * # this outer loop searches for undefined channels + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * channel_raster_path_band, offset_only=True, largest_block=0): + * win_xsize = offset_dict['win_xsize'] + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2663, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2663, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2664 + * # this outer loop searches for undefined channels + * for offset_dict in pygeoprocessing.iterblocks( + * channel_raster_path_band, offset_only=True, largest_block=0): # <<<<<<<<<<<<<< + * win_xsize = offset_dict['win_xsize'] + * win_ysize = offset_dict['win_ysize'] + */ + __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2663, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_INCREF(__pyx_v_channel_raster_path_band); + __Pyx_GIVEREF(__pyx_v_channel_raster_path_band); + PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_channel_raster_path_band); + __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2664, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 2664, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_largest_block, __pyx_int_0) < 0) __PYX_ERR(0, 2664, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2663 + * + * # this outer loop searches for undefined channels + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * channel_raster_path_band, offset_only=True, largest_block=0): + * win_xsize = offset_dict['win_xsize'] + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_11, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2663, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0; + __pyx_t_15 = NULL; + } else { + __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2663, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_15 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2663, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (likely(!__pyx_t_15)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 2663, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2663, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } else { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 2663, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2663, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } + } else { + __pyx_t_2 = __pyx_t_15(__pyx_t_1); + if (unlikely(!__pyx_t_2)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 2663, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XDECREF_SET(__pyx_v_offset_dict, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2665 + * for offset_dict in pygeoprocessing.iterblocks( + * channel_raster_path_band, offset_only=True, largest_block=0): + * win_xsize = offset_dict['win_xsize'] # <<<<<<<<<<<<<< + * win_ysize = offset_dict['win_ysize'] + * xoff = offset_dict['xoff'] + */ + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2665, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2665, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_win_xsize = __pyx_t_14; + + /* "pygeoprocessing/routing/routing.pyx":2666 + * channel_raster_path_band, 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_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2666, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2666, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_win_ysize = __pyx_t_14; + + /* "pygeoprocessing/routing/routing.pyx":2667 + * win_xsize = offset_dict['win_xsize'] + * win_ysize = offset_dict['win_ysize'] + * xoff = offset_dict['xoff'] # <<<<<<<<<<<<<< + * yoff = offset_dict['yoff'] + * + */ + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_xoff); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2667, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2667, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_xoff = __pyx_t_14; + + /* "pygeoprocessing/routing/routing.pyx":2668 + * win_ysize = offset_dict['win_ysize'] + * xoff = offset_dict['xoff'] + * yoff = offset_dict['yoff'] # <<<<<<<<<<<<<< + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + */ + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_yoff); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2668, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2668, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_yoff = __pyx_t_14; + + /* "pygeoprocessing/routing/routing.pyx":2670 + * yoff = offset_dict['yoff'] + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + */ + __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":2671 + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + */ + __pyx_v_last_log_time = time(NULL); + + /* "pygeoprocessing/routing/routing.pyx":2672 + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size # <<<<<<<<<<<<<< + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + * raster_x_size * raster_y_size)) + */ + __pyx_t_2 = __Pyx_PyInt_From_int((__pyx_v_xoff + (__pyx_v_yoff * __pyx_v_raster_x_size))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2672, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XDECREF_SET(__pyx_v_current_pixel, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2673 + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< + * raster_x_size * raster_y_size)) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2673, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_info); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2673, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = PyNumber_Multiply(__pyx_float_100_0, __pyx_v_current_pixel); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2673, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + + /* "pygeoprocessing/routing/routing.pyx":2674 + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + * raster_x_size * raster_y_size)) # <<<<<<<<<<<<<< + * + * # make a buffer big enough to capture block and boundaries around it + */ + __pyx_t_7 = PyFloat_FromDouble(((float)(__pyx_v_raster_x_size * __pyx_v_raster_y_size))); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2673, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + + /* "pygeoprocessing/routing/routing.pyx":2673 + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< + * raster_x_size * raster_y_size)) + * + */ + __pyx_t_9 = __Pyx_PyNumber_Divide(__pyx_t_11, __pyx_t_7); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2673, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + __pyx_t_14 = 0; + 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); + __pyx_t_14 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_kp_u_1f_complete, __pyx_t_9}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2673, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + __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_7, __pyx_kp_u_1f_complete, __pyx_t_9}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2673, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + { + __pyx_t_11 = PyTuple_New(2+__pyx_t_14); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2673, __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_INCREF(__pyx_kp_u_1f_complete); + __Pyx_GIVEREF(__pyx_kp_u_1f_complete); + PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_14, __pyx_kp_u_1f_complete); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_14, __pyx_t_9); + __pyx_t_9 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_11, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2673, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2670 + * yoff = offset_dict['yoff'] + * + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2677 + * + * # 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2677, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2677, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2678 + * # 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_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2678, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_11 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2678, __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_u_win_xsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2678, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2678, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2678, __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_9); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_9); + __pyx_t_11 = 0; + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2677 + * + * # 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 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2677, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2679 + * 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_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2679, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_numpy); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2679, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_uint8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2679, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 2679, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2677 + * + * # 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_7 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_9, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2677, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2677, __pyx_L1_error) + __pyx_t_16 = ((PyArrayObject *)__pyx_t_7); + { + __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, 2677, __pyx_L1_error) + } + __pyx_t_16 = 0; + __Pyx_XDECREF_SET(__pyx_v_channel_buffer_array, ((PyArrayObject *)__pyx_t_7)); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2680 + * (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_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_numpy); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2680, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2680, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2681 + * 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_7 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2681, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_9 = __Pyx_PyInt_AddObjC(__pyx_t_7, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2681, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2681, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyInt_AddObjC(__pyx_t_7, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2681, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2681, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_8); + __pyx_t_9 = 0; + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2680 + * (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_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2680, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2682 + * 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_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2682, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_numpy); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2682, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_int32); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2682, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_11) < 0) __PYX_ERR(0, 2682, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2680 + * (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_11 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2680, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2680, __pyx_L1_error) + __pyx_t_20 = ((PyArrayObject *)__pyx_t_11); + { + __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, 2680, __pyx_L1_error) + } + __pyx_t_20 = 0; + __Pyx_XDECREF_SET(__pyx_v_flow_dir_buffer_array, ((PyArrayObject *)__pyx_t_11)); + __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2683 + * (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__7, __pyx_int_0) < 0)) __PYX_ERR(0, 2683, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2684 + * 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__7, __pyx_int_0) < 0)) __PYX_ERR(0, 2684, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2688 + * # 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_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_generate_read_bounds); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2688, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + + /* "pygeoprocessing/routing/routing.pyx":2689 + * # 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_8 = __Pyx_PyInt_From_int(__pyx_v_raster_x_size); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2689, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_raster_y_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2689, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = NULL; + __pyx_t_14 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_9); + __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[4] = {__pyx_t_9, __pyx_v_offset_dict, __pyx_t_8, __pyx_t_2}; + __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_14, 3+__pyx_t_14); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2688, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[4] = {__pyx_t_9, __pyx_v_offset_dict, __pyx_t_8, __pyx_t_2}; + __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_14, 3+__pyx_t_14); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2688, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + { + __pyx_t_21 = PyTuple_New(3+__pyx_t_14); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2688, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_21); + if (__pyx_t_9) { + __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_21, 0, __pyx_t_9); __pyx_t_9 = 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_8); + PyTuple_SET_ITEM(__pyx_t_21, 1+__pyx_t_14, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_21, 2+__pyx_t_14, __pyx_t_2); + __pyx_t_8 = 0; + __pyx_t_2 = 0; + __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_21, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2688, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_11))) || (PyList_CheckExact(__pyx_t_11))) { + PyObject* sequence = __pyx_t_11; + 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, 2688, __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_21 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_7 = PyList_GET_ITEM(sequence, 0); + __pyx_t_21 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_21); + #else + __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2688, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_21 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2688, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_21); + #endif + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_2 = PyObject_GetIter(__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2688, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_13 = Py_TYPE(__pyx_t_2)->tp_iternext; + index = 0; __pyx_t_7 = __pyx_t_13(__pyx_t_2); if (unlikely(!__pyx_t_7)) goto __pyx_L15_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + index = 1; __pyx_t_21 = __pyx_t_13(__pyx_t_2); if (unlikely(!__pyx_t_21)) goto __pyx_L15_unpacking_failed; + __Pyx_GOTREF(__pyx_t_21); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_2), 2) < 0) __PYX_ERR(0, 2688, __pyx_L1_error) + __pyx_t_13 = NULL; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L16_unpacking_done; + __pyx_L15_unpacking_failed:; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_13 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 2688, __pyx_L1_error) + __pyx_L16_unpacking_done:; + } + + /* "pygeoprocessing/routing/routing.pyx":2688 + * # 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_7))) || (PyList_CheckExact(__pyx_t_7))) { + PyObject* sequence = __pyx_t_7; + 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, 2688, __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_8 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_9 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_22 = PyTuple_GET_ITEM(sequence, 3); + } else { + __pyx_t_2 = PyList_GET_ITEM(sequence, 0); + __pyx_t_8 = PyList_GET_ITEM(sequence, 1); + __pyx_t_9 = PyList_GET_ITEM(sequence, 2); + __pyx_t_22 = PyList_GET_ITEM(sequence, 3); + } + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(__pyx_t_22); + #else + { + Py_ssize_t i; + PyObject** temps[4] = {&__pyx_t_2,&__pyx_t_8,&__pyx_t_9,&__pyx_t_22}; + for (i=0; i < 4; i++) { + PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 2688, __pyx_L1_error) + __Pyx_GOTREF(item); + *(temps[i]) = item; + } + } + #endif + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else { + Py_ssize_t index = -1; + PyObject** temps[4] = {&__pyx_t_2,&__pyx_t_8,&__pyx_t_9,&__pyx_t_22}; + __pyx_t_23 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 2688, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_23); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 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, 2688, __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, 2688, __pyx_L1_error) + __pyx_L18_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_xa, __pyx_t_2); + __pyx_t_2 = 0; + __Pyx_XDECREF_SET(__pyx_v_xb, __pyx_t_8); + __pyx_t_8 = 0; + __Pyx_XDECREF_SET(__pyx_v_ya, __pyx_t_9); + __pyx_t_9 = 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":2690 + * (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, 2690, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_21); + + /* "pygeoprocessing/routing/routing.pyx":2691 + * 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, 2691, __pyx_L1_error) + } + if (likely(PyDict_CheckExact(__pyx_v_modified_offset_dict))) { + __pyx_t_7 = PyDict_Copy(__pyx_v_modified_offset_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2691, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + } else { + __pyx_t_7 = PyObject_CallFunctionObjArgs((PyObject*)&PyDict_Type, __pyx_v_modified_offset_dict, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2690, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + } + + /* "pygeoprocessing/routing/routing.pyx":2690 + * (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_7); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2690, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_22); + __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2691 + * 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_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_22, __pyx_n_s_astype); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2691, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_22, __pyx_n_s_numpy); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2691, __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, 2691, __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_7))) { + __pyx_t_22 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_22)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_22); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_11 = (__pyx_t_22) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_22, __pyx_t_21) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_21); + __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; + __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; + if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2691, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2690 + * (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 = PySlice_New(__pyx_v_ya, __pyx_v_yb, Py_None); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2690, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_21 = PySlice_New(__pyx_v_xa, __pyx_v_xb, Py_None); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2690, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_21); + __pyx_t_22 = PyTuple_New(2); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2690, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_22); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_22, 0, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_21); + PyTuple_SET_ITEM(__pyx_t_22, 1, __pyx_t_21); + __pyx_t_7 = 0; + __pyx_t_21 = 0; + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_channel_buffer_array), __pyx_t_22, __pyx_t_11) < 0)) __PYX_ERR(0, 2690, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2693 + * **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_22 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_mfd_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2693, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_22); + + /* "pygeoprocessing/routing/routing.pyx":2694 + * + * 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, 2694, __pyx_L1_error) + } + if (likely(PyDict_CheckExact(__pyx_v_modified_offset_dict))) { + __pyx_t_21 = PyDict_Copy(__pyx_v_modified_offset_dict); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2694, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_21); + } else { + __pyx_t_21 = PyObject_CallFunctionObjArgs((PyObject*)&PyDict_Type, __pyx_v_modified_offset_dict, NULL); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2693, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_21); + } + + /* "pygeoprocessing/routing/routing.pyx":2693 + * **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_7 = __Pyx_PyObject_Call(__pyx_t_22, __pyx_empty_tuple, __pyx_t_21); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2693, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; + __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2694 + * + * 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_21 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_astype); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2694, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_21); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_numpy); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2694, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_22 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_int32); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2694, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_22); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_21))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_21); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_21); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_21, function); + } + } + __pyx_t_11 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_21, __pyx_t_7, __pyx_t_22) : __Pyx_PyObject_CallOneArg(__pyx_t_21, __pyx_t_22); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; + if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2694, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2693 + * **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 = PySlice_New(__pyx_v_ya, __pyx_v_yb, Py_None); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2693, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_21); + __pyx_t_22 = PySlice_New(__pyx_v_xa, __pyx_v_xb, Py_None); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2693, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_22); + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2693, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_21); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_21); + __Pyx_GIVEREF(__pyx_t_22); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_22); + __pyx_t_21 = 0; + __pyx_t_22 = 0; + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_buffer_array), __pyx_t_7, __pyx_t_11) < 0)) __PYX_ERR(0, 2693, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2697 + * + * # ensure these are set for the complier + * xi_n = -1 # <<<<<<<<<<<<<< + * yi_n = -1 + * + */ + __pyx_v_xi_n = -1; + + /* "pygeoprocessing/routing/routing.pyx":2698 + * # 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":2701 + * + * # 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":2702 + * # 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":2703 + * 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":2704 + * 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":2706 + * 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, 2706, __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":2707 + * + * 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":2709 + * 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":2706 + * 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":2711 + * continue + * + * if flow_dir_buffer_array[yi, xi] == 0: # <<<<<<<<<<<<<< + * # nodata flow, so we skip + * continue + */ + __pyx_t_29 = __pyx_v_yi; + __pyx_t_28 = __pyx_v_xi; + __pyx_t_30 = -1; + if (__pyx_t_29 < 0) { + __pyx_t_29 += __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].shape; + if (unlikely(__pyx_t_29 < 0)) __pyx_t_30 = 0; + } else if (unlikely(__pyx_t_29 >= __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].shape)) __pyx_t_30 = 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_30 = 1; + } else if (unlikely(__pyx_t_28 >= __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, 2711, __pyx_L1_error) + } + __pyx_t_5 = (((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].strides, __pyx_t_28, __pyx_pybuffernd_flow_dir_buffer_array.diminfo[1].strides)) == 0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":2713 + * if flow_dir_buffer_array[yi, xi] == 0: + * # nodata flow, so we skip + * continue # <<<<<<<<<<<<<< + * + * if visited_managed_raster.get(xi_root, yi_root) == 0: + */ + goto __pyx_L21_continue; + + /* "pygeoprocessing/routing/routing.pyx":2711 + * continue + * + * if flow_dir_buffer_array[yi, xi] == 0: # <<<<<<<<<<<<<< + * # nodata flow, so we skip + * continue + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2715 + * continue + * + * if visited_managed_raster.get(xi_root, yi_root) == 0: # <<<<<<<<<<<<<< + * visited_managed_raster.set(xi_root, yi_root, 1) + * # arguments are x,y position of pixel, then last D8 flow + */ + __pyx_t_5 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_visited_managed_raster, __pyx_v_xi_root, __pyx_v_yi_root) == 0.0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":2716 + * + * if visited_managed_raster.get(xi_root, yi_root) == 0: + * visited_managed_raster.set(xi_root, yi_root, 1) # <<<<<<<<<<<<<< + * # arguments are x,y position of pixel, then last D8 flow + * # direction processed (0-7), and last is the running + */ + __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_visited_managed_raster, __pyx_v_xi_root, __pyx_v_yi_root, 1.0); + + /* "pygeoprocessing/routing/routing.pyx":2722 + * # initialized to nodata + * distance_to_channel_stack.push( + * FlowPixelType(xi_root, yi_root, 0, distance_nodata)) # <<<<<<<<<<<<<< + * + * while not distance_to_channel_stack.empty(): + */ + __pyx_t_31.xi = __pyx_v_xi_root; + __pyx_t_31.yi = __pyx_v_yi_root; + __pyx_t_31.last_flow_dir = 0; + __pyx_t_31.value = __pyx_v_distance_nodata; + + /* "pygeoprocessing/routing/routing.pyx":2721 + * # accumulation distance accumulated by this pixel so far + * # initialized to nodata + * distance_to_channel_stack.push( # <<<<<<<<<<<<<< + * FlowPixelType(xi_root, yi_root, 0, distance_nodata)) + * + */ + __pyx_v_distance_to_channel_stack.push(__pyx_t_31); + + /* "pygeoprocessing/routing/routing.pyx":2715 + * continue + * + * if visited_managed_raster.get(xi_root, yi_root) == 0: # <<<<<<<<<<<<<< + * visited_managed_raster.set(xi_root, yi_root, 1) + * # arguments are x,y position of pixel, then last D8 flow + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2724 + * FlowPixelType(xi_root, yi_root, 0, distance_nodata)) + * + * 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":2725 + * + * 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":2726 + * 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":2728 + * 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":2729 + * 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":2730 + * 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":2732 + * distance_to_channel_managed_raster.set( + * pixel.xi, pixel.yi, 0) + * continue # <<<<<<<<<<<<<< + * + * compressed_flow_dir = ( + */ + goto __pyx_L26_continue; + + /* "pygeoprocessing/routing/routing.pyx":2729 + * 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":2735 + * + * compressed_flow_dir = ( + * 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":2738 + * 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":2739 + * + * 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":2740 + * 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":2742 + * 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":2743 + * compressed_flow_dir >> (i_n * 4)) + * if flow_dir_weight == 0: + * continue # <<<<<<<<<<<<<< + * + * xi_n = pixel.xi+D8_XOFFSET[i_n] + */ + goto __pyx_L29_continue; + + /* "pygeoprocessing/routing/routing.pyx":2742 + * flow_dir_weight = 0xF & ( + * compressed_flow_dir >> (i_n * 4)) + * if flow_dir_weight == 0: # <<<<<<<<<<<<<< + * continue + * + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2745 + * continue + * + * xi_n = pixel.xi+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< + * yi_n = pixel.yi+D8_YOFFSET[i_n] + * + */ + __pyx_v_xi_n = (__pyx_v_pixel.xi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":2746 + * + * xi_n = pixel.xi+D8_XOFFSET[i_n] + * yi_n = pixel.yi+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< + * + * if (xi_n < 0 or xi_n >= raster_x_size or + */ + __pyx_v_yi_n = (__pyx_v_pixel.yi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":2748 + * yi_n = pixel.yi+D8_YOFFSET[i_n] + * + * 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":2749 + * + * 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":2748 + * yi_n = pixel.yi+D8_YOFFSET[i_n] + * + * 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":2750 + * if (xi_n < 0 or xi_n >= raster_x_size or + * yi_n < 0 or yi_n >= raster_y_size): + * continue # <<<<<<<<<<<<<< + * + * + */ + goto __pyx_L29_continue; + + /* "pygeoprocessing/routing/routing.pyx":2748 + * yi_n = pixel.yi+D8_YOFFSET[i_n] + * + * 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":2753 + * + * + * if visited_managed_raster.get(xi_n, yi_n) == 0: # <<<<<<<<<<<<<< + * visited_managed_raster.set(xi_n, yi_n, 1) + * preempted = 1 + */ + __pyx_t_5 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_visited_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n) == 0.0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":2754 + * + * if visited_managed_raster.get(xi_n, yi_n) == 0: + * visited_managed_raster.set(xi_n, yi_n, 1) # <<<<<<<<<<<<<< + * preempted = 1 + * pixel.last_flow_dir = i_n + */ + __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_visited_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n, 1.0); + + /* "pygeoprocessing/routing/routing.pyx":2755 + * if visited_managed_raster.get(xi_n, yi_n) == 0: + * visited_managed_raster.set(xi_n, yi_n, 1) + * preempted = 1 # <<<<<<<<<<<<<< + * pixel.last_flow_dir = i_n + * distance_to_channel_stack.push(pixel) + */ + __pyx_v_preempted = 1; + + /* "pygeoprocessing/routing/routing.pyx":2756 + * visited_managed_raster.set(xi_n, yi_n, 1) + * 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":2757 + * 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, distance_nodata)) + */ + __pyx_v_distance_to_channel_stack.push(__pyx_v_pixel); + + /* "pygeoprocessing/routing/routing.pyx":2759 + * distance_to_channel_stack.push(pixel) + * distance_to_channel_stack.push( + * FlowPixelType(xi_n, yi_n, 0, distance_nodata)) # <<<<<<<<<<<<<< + * break + * + */ + __pyx_t_31.xi = __pyx_v_xi_n; + __pyx_t_31.yi = __pyx_v_yi_n; + __pyx_t_31.last_flow_dir = 0; + __pyx_t_31.value = __pyx_v_distance_nodata; + + /* "pygeoprocessing/routing/routing.pyx":2758 + * pixel.last_flow_dir = i_n + * distance_to_channel_stack.push(pixel) + * distance_to_channel_stack.push( # <<<<<<<<<<<<<< + * FlowPixelType(xi_n, yi_n, 0, distance_nodata)) + * break + */ + __pyx_v_distance_to_channel_stack.push(__pyx_t_31); + + /* "pygeoprocessing/routing/routing.pyx":2760 + * distance_to_channel_stack.push( + * FlowPixelType(xi_n, yi_n, 0, distance_nodata)) + * break # <<<<<<<<<<<<<< + * + * n_distance = distance_to_channel_managed_raster.get( + */ + goto __pyx_L30_break; + + /* "pygeoprocessing/routing/routing.pyx":2753 + * + * + * if visited_managed_raster.get(xi_n, yi_n) == 0: # <<<<<<<<<<<<<< + * visited_managed_raster.set(xi_n, yi_n, 1) + * preempted = 1 + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2762 + * break + * + * 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":2765 + * xi_n, yi_n) + * + * if n_distance == distance_nodata: # <<<<<<<<<<<<<< + * # a channel was never found + * continue + */ + __pyx_t_5 = ((__pyx_v_n_distance == __pyx_v_distance_nodata) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":2767 + * if n_distance == distance_nodata: + * # a channel was never found + * continue # <<<<<<<<<<<<<< + * + * # if a weight is passed we use it directly and do + */ + goto __pyx_L29_continue; + + /* "pygeoprocessing/routing/routing.pyx":2765 + * xi_n, yi_n) + * + * if n_distance == distance_nodata: # <<<<<<<<<<<<<< + * # a channel was never found + * continue + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2774 + * # 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, 1e-8, 1e-5): + */ + __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":2775 + * # 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, 1e-8, 1e-5): + * 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":2776 + * if weight_raster is not None: + * weight_val = weight_raster.get(xi_n, yi_n) + * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * weight_val = 0.0 + * else: + */ + __pyx_t_4 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_weight_val, __pyx_v_weight_nodata, 1e-8, 1e-5) != 0); + if (__pyx_t_4) { + + /* "pygeoprocessing/routing/routing.pyx":2777 + * weight_val = weight_raster.get(xi_n, yi_n) + * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): + * weight_val = 0.0 # <<<<<<<<<<<<<< + * else: + * weight_val = (SQRT2 if i_n % 2 else 1) + */ + __pyx_v_weight_val = 0.0; + + /* "pygeoprocessing/routing/routing.pyx":2776 + * if weight_raster is not None: + * weight_val = weight_raster.get(xi_n, yi_n) + * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * weight_val = 0.0 + * else: + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2774 + * # 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, 1e-8, 1e-5): + */ + goto __pyx_L39; + } + + /* "pygeoprocessing/routing/routing.pyx":2779 + * weight_val = 0.0 + * else: + * weight_val = (SQRT2 if i_n % 2 else 1) # <<<<<<<<<<<<<< + * + * if pixel.value == distance_nodata: + */ + /*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_L39:; + + /* "pygeoprocessing/routing/routing.pyx":2781 + * weight_val = (SQRT2 if i_n % 2 else 1) + * + * if pixel.value == distance_nodata: # <<<<<<<<<<<<<< + * pixel.value = 0 + * pixel.value += flow_dir_weight * ( + */ + __pyx_t_4 = ((__pyx_v_pixel.value == __pyx_v_distance_nodata) != 0); + if (__pyx_t_4) { + + /* "pygeoprocessing/routing/routing.pyx":2782 + * + * if pixel.value == distance_nodata: + * pixel.value = 0 # <<<<<<<<<<<<<< + * pixel.value += flow_dir_weight * ( + * weight_val + n_distance) + */ + __pyx_v_pixel.value = 0.0; + + /* "pygeoprocessing/routing/routing.pyx":2781 + * weight_val = (SQRT2 if i_n % 2 else 1) + * + * if pixel.value == distance_nodata: # <<<<<<<<<<<<<< + * pixel.value = 0 + * pixel.value += flow_dir_weight * ( + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2783 + * if pixel.value == distance_nodata: + * pixel.value = 0 + * 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":2786 + * weight_val + n_distance) + * + * if preempted: # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_4 = (__pyx_v_preempted != 0); + if (__pyx_t_4) { + + /* "pygeoprocessing/routing/routing.pyx":2787 + * + * if preempted: + * continue # <<<<<<<<<<<<<< + * + * sum_of_flow_weights = 0 + */ + goto __pyx_L26_continue; + + /* "pygeoprocessing/routing/routing.pyx":2786 + * weight_val + n_distance) + * + * if preempted: # <<<<<<<<<<<<<< + * continue + * + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2789 + * 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":2790 + * + * 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":2791 + * 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":2794 + * 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":2795 + * + * 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, 2795, __pyx_L1_error) + } + __pyx_v_pixel.value = (__pyx_v_pixel.value / ((double)__pyx_v_sum_of_flow_weights)); + + /* "pygeoprocessing/routing/routing.pyx":2794 + * compressed_flow_dir >> (i_n * 4)) + * + * if sum_of_flow_weights != 0: # <<<<<<<<<<<<<< + * pixel.value = pixel.value / sum_of_flow_weights + * else: + */ + goto __pyx_L45; + } + + /* "pygeoprocessing/routing/routing.pyx":2797 + * 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_L45:; + + /* "pygeoprocessing/routing/routing.pyx":2798 + * 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":2663 + * + * # this outer loop searches for undefined channels + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * channel_raster_path_band, offset_only=True, largest_block=0): + * win_xsize = offset_dict['win_xsize'] + */ + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2801 + * pixel.xi, pixel.yi, pixel.value) + * + * distance_to_channel_managed_raster.close() # <<<<<<<<<<<<<< + * channel_managed_raster.close() + * flow_dir_mfd_managed_raster.close() + */ + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_distance_to_channel_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2801, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + } + } + __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2801, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2802 + * + * distance_to_channel_managed_raster.close() + * channel_managed_raster.close() # <<<<<<<<<<<<<< + * flow_dir_mfd_managed_raster.close() + * if weight_raster is not None: + */ + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_channel_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2802, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + } + } + __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2802, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2803 + * 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_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_flow_dir_mfd_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2803, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + } + } + __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2803, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2804 + * channel_managed_raster.close() + * flow_dir_mfd_managed_raster.close() + * if weight_raster is not None: # <<<<<<<<<<<<<< + * weight_raster.close() + * visited_managed_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":2805 + * flow_dir_mfd_managed_raster.close() + * if weight_raster is not None: + * weight_raster.close() # <<<<<<<<<<<<<< + * visited_managed_raster.close() + * shutil.rmtree(tmp_work_dir) + */ + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_weight_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2805, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + } + } + __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2805, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2804 + * channel_managed_raster.close() + * flow_dir_mfd_managed_raster.close() + * if weight_raster is not None: # <<<<<<<<<<<<<< + * weight_raster.close() + * visited_managed_raster.close() + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2806 + * if weight_raster is not None: + * weight_raster.close() + * visited_managed_raster.close() # <<<<<<<<<<<<<< + * shutil.rmtree(tmp_work_dir) + * LOGGER.info('%.1f%% complete', 100.0) + */ + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_visited_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2806, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + } + } + __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2806, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2807 + * weight_raster.close() + * visited_managed_raster.close() + * shutil.rmtree(tmp_work_dir) # <<<<<<<<<<<<<< + * LOGGER.info('%.1f%% complete', 100.0) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_shutil); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2807, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_rmtree); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2807, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_1 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_11, __pyx_v_tmp_work_dir) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_tmp_work_dir); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2807, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2808 + * visited_managed_raster.close() + * shutil.rmtree(tmp_work_dir) + * LOGGER.info('%.1f%% complete', 100.0) # <<<<<<<<<<<<<< + * + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2808, __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, 2808, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2808, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2544 + * + * + * 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(__pyx_v_tmp_work_dir); + __Pyx_XDECREF(__pyx_v_visited_raster_path); + __Pyx_XDECREF((PyObject *)__pyx_v_visited_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":2811 + * + * + * def extract_streams_mfd( # <<<<<<<<<<<<<< + * flow_accum_raster_path_band, flow_dir_mfd_path_band, + * double flow_threshold, target_stream_raster_path, + */ + +/* 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 raster_driver_creation_tuple (tuple): a tuple containing a GDAL driver\n name string as the first element and a GDAL creation options\n tuple/list as the second. Defaults to a GTiff driver tuple\n defined at geoprocessing.DEFAULT_GTIFF_CREATION_TUPLE_OPTION""S.\n\n Returns:\n None.\n "; +static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_17extract_streams_mfd = {"extract_streams_mfd", (PyCFunction)(void*)(PyCFunctionWithKeywords)__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_raster_driver_creation_tuple = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 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_raster_driver_creation_tuple,0}; + PyObject* values[6] = {0,0,0,0,0,0}; + values[5] = __pyx_k__14; + 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, 2811, __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, 2811, __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, 2811, __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_raster_driver_creation_tuple); + 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, 2811, __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, 2813, __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, 2814, __pyx_L3_error) + } else { + __pyx_v_trace_threshold_proportion = ((double)1.0); + } + __pyx_v_raster_driver_creation_tuple = 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, 2811, __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_raster_driver_creation_tuple); + + /* 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_raster_driver_creation_tuple) { + 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_block_offsets_list = 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; + double __pyx_t_7; + PyObject *(*__pyx_t_8)(PyObject *); + int __pyx_t_9; + int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("extract_streams_mfd", 0); + + /* "pygeoprocessing/routing/routing.pyx":2852 + * 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":2855 + * 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, 2855, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyUnicode_Format(__pyx_kp_u_trace_threshold_proportion_shoul, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2855, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2853 + * """ + * 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, 2853, __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, 2853, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2852 + * 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":2857 + * "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_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2857, __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, 2857, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2858 + * + * 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, 2858, __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); + } + } + __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2857, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __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":2859 + * 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_u_nodata); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2859, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + + /* "pygeoprocessing/routing/routing.pyx":2860 + * 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, 2860, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = __Pyx_PyInt_SubtractObjC(__pyx_t_5, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2860, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2859 + * 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_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2859, __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_t_7 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_7 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 2859, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_flow_accum_nodata = __pyx_t_7; + + /* "pygeoprocessing/routing/routing.pyx":2861 + * 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":2864 + * + * 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_u_raster_size); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2864, __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, 2864, __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_3 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_4 = PyList_GET_ITEM(sequence, 0); + __pyx_t_3 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_3); + #else + __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2864, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2864, __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_6 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2864, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_6)->tp_iternext; + index = 0; __pyx_t_4 = __pyx_t_8(__pyx_t_6); if (unlikely(!__pyx_t_4)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_4); + index = 1; __pyx_t_3 = __pyx_t_8(__pyx_t_6); if (unlikely(!__pyx_t_3)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_6), 2) < 0) __PYX_ERR(0, 2864, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L7_unpacking_done; + __pyx_L6_unpacking_failed:; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 2864, __pyx_L1_error) + __pyx_L7_unpacking_done:; + } + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2864, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2864, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_raster_x_size = __pyx_t_9; + __pyx_v_raster_y_size = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":2866 + * 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], + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2866, __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, 2866, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2867 + * + * pygeoprocessing.new_raster_from_base( + * flow_accum_raster_path_band[0], target_stream_raster_path, # <<<<<<<<<<<<<< + * gdal.GDT_Byte, [stream_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) + */ + __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, 2867, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + + /* "pygeoprocessing/routing/routing.pyx":2868 + * pygeoprocessing.new_raster_from_base( + * flow_accum_raster_path_band[0], target_stream_raster_path, + * gdal.GDT_Byte, [stream_nodata], # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2868, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2868, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_v_stream_nodata); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2868, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_11 = PyList_New(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2868, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_GIVEREF(__pyx_t_4); + PyList_SET_ITEM(__pyx_t_11, 0, __pyx_t_4); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2866 + * 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], + */ + __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2866, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_4, 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_4, 1, __pyx_v_target_stream_raster_path); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_11); + __pyx_t_5 = 0; + __pyx_t_6 = 0; + __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2869 + * flow_accum_raster_path_band[0], target_stream_raster_path, + * gdal.GDT_Byte, [stream_nodata], + * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< + * + * cdef _ManagedRaster flow_accum_mr = _ManagedRaster( + */ + __pyx_t_11 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2869, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 2869, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2866 + * 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], + */ + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2866, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2872 + * + * 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_6 = __Pyx_GetItemInt(__pyx_v_flow_accum_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2872, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_flow_accum_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2872, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + + /* "pygeoprocessing/routing/routing.pyx":2871 + * raster_driver_creation_tuple=raster_driver_creation_tuple) + * + * 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_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2871, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_11); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_int_0); + __pyx_t_6 = 0; + __pyx_t_11 = 0; + __pyx_t_11 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_4, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2871, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_flow_accum_mr = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_11); + __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2873 + * 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_11 = PyTuple_New(3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2873, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_INCREF(__pyx_v_target_stream_raster_path); + __Pyx_GIVEREF(__pyx_v_target_stream_raster_path); + PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_target_stream_raster_path); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_int_1); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_11, 2, __pyx_int_1); + __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_11, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2873, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_v_stream_mr = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_4); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2876 + * 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_4 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2876, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2876, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + + /* "pygeoprocessing/routing/routing.pyx":2875 + * 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_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2875, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_11); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_int_0); + __pyx_t_4 = 0; + __pyx_t_11 = 0; + __pyx_t_11 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_6, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2875, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_flow_dir_mfd_mr = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_11); + __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2883 + * 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":2884 + * 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":2887 + * 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_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2887, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2887, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2888 + * + * 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_6 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2888, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = NULL; + 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_11 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_6); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2887, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_t_11, __pyx_n_u_nodata); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2888, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2888, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_6 = __Pyx_PyInt_SubtractObjC(__pyx_t_11, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2888, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = __Pyx_PyObject_GetItem(__pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2888, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_11); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2888, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_v_flow_dir_nodata = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":2895 + * 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":2897 + * cdef time_t last_log_time = ctime(NULL) + * + * for block_offsets in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * (target_stream_raster_path, 1), offset_only=True): + * xoff = block_offsets['xoff'] + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2897, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2897, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2898 + * + * for block_offsets in pygeoprocessing.iterblocks( + * (target_stream_raster_path, 1), offset_only=True): # <<<<<<<<<<<<<< + * xoff = block_offsets['xoff'] + * yoff = block_offsets['yoff'] + */ + __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2898, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_INCREF(__pyx_v_target_stream_raster_path); + __Pyx_GIVEREF(__pyx_v_target_stream_raster_path); + PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_target_stream_raster_path); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_int_1); + + /* "pygeoprocessing/routing/routing.pyx":2897 + * cdef time_t last_log_time = ctime(NULL) + * + * for block_offsets in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * (target_stream_raster_path, 1), offset_only=True): + * xoff = block_offsets['xoff'] + */ + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2897, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_11); + __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2898 + * + * for block_offsets in pygeoprocessing.iterblocks( + * (target_stream_raster_path, 1), offset_only=True): # <<<<<<<<<<<<<< + * xoff = block_offsets['xoff'] + * yoff = block_offsets['yoff'] + */ + __pyx_t_11 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2898, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 2898, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2897 + * cdef time_t last_log_time = ctime(NULL) + * + * for block_offsets in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * (target_stream_raster_path, 1), offset_only=True): + * xoff = block_offsets['xoff'] + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, __pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2897, __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; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) { + __pyx_t_11 = __pyx_t_3; __Pyx_INCREF(__pyx_t_11); __pyx_t_12 = 0; + __pyx_t_13 = NULL; + } else { + __pyx_t_12 = -1; __pyx_t_11 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2897, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_13 = Py_TYPE(__pyx_t_11)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 2897, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + for (;;) { + if (likely(!__pyx_t_13)) { + if (likely(PyList_CheckExact(__pyx_t_11))) { + if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_11)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_11, __pyx_t_12); __Pyx_INCREF(__pyx_t_3); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 2897, __pyx_L1_error) + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_11, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2897, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + } else { + if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_11)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_11, __pyx_t_12); __Pyx_INCREF(__pyx_t_3); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 2897, __pyx_L1_error) + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_11, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2897, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + } + } else { + __pyx_t_3 = __pyx_t_13(__pyx_t_11); + 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, 2897, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF_SET(__pyx_v_block_offsets, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2899 + * for block_offsets in pygeoprocessing.iterblocks( + * (target_stream_raster_path, 1), offset_only=True): + * xoff = block_offsets['xoff'] # <<<<<<<<<<<<<< + * yoff = block_offsets['yoff'] + * win_xsize = block_offsets['win_xsize'] + */ + __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_u_xoff); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2899, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2899, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_xoff = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":2900 + * (target_stream_raster_path, 1), 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_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_u_yoff); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2900, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2900, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_yoff = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":2901 + * 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_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2901, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2901, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_win_xsize = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":2902 + * 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_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2902, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2902, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_win_ysize = __pyx_t_10; + + /* "pygeoprocessing/routing/routing.pyx":2903 + * 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 > _LOGGING_PERIOD: + */ + __pyx_t_10 = __pyx_v_win_ysize; + __pyx_t_9 = __pyx_t_10; + for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_9; __pyx_t_14+=1) { + __pyx_v_yi = __pyx_t_14; + + /* "pygeoprocessing/routing/routing.pyx":2904 + * win_ysize = block_offsets['win_ysize'] + * for yi in range(win_ysize): + * yi_root = yi+yoff # <<<<<<<<<<<<<< + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * last_log_time = ctime(NULL) + */ + __pyx_v_yi_root = (__pyx_v_yi + __pyx_v_yoff); + + /* "pygeoprocessing/routing/routing.pyx":2905 + * for yi in range(win_ysize): + * yi_root = yi+yoff + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + */ + __pyx_t_1 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); + if (__pyx_t_1) { + + /* "pygeoprocessing/routing/routing.pyx":2906 + * yi_root = yi+yoff + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + */ + __pyx_v_last_log_time = time(NULL); + + /* "pygeoprocessing/routing/routing.pyx":2907 + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size # <<<<<<<<<<<<<< + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + * 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, 2907, __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":2908 + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< + * raster_x_size * raster_y_size)) + * for xi in range(win_xsize): + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2908, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_info); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2908, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyNumber_Multiply(__pyx_float_100_0, __pyx_v_current_pixel); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2908, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "pygeoprocessing/routing/routing.pyx":2909 + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + * raster_x_size * raster_y_size)) # <<<<<<<<<<<<<< + * for xi in range(win_xsize): + * xi_root = xi+xoff + */ + __pyx_t_5 = PyFloat_FromDouble(((float)(__pyx_v_raster_x_size * __pyx_v_raster_y_size))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2908, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + + /* "pygeoprocessing/routing/routing.pyx":2908 + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< + * raster_x_size * raster_y_size)) + * for xi in range(win_xsize): + */ + __pyx_t_15 = __Pyx_PyNumber_Divide(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2908, __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_t_5 = NULL; + __pyx_t_16 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_16 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_kp_u_1f_complete, __pyx_t_15}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_16, 2+__pyx_t_16); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2908, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_kp_u_1f_complete, __pyx_t_15}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_16, 2+__pyx_t_16); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2908, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + } else + #endif + { + __pyx_t_4 = PyTuple_New(2+__pyx_t_16); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2908, __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_kp_u_1f_complete); + __Pyx_GIVEREF(__pyx_kp_u_1f_complete); + PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_16, __pyx_kp_u_1f_complete); + __Pyx_GIVEREF(__pyx_t_15); + PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_16, __pyx_t_15); + __pyx_t_15 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2908, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2905 + * for yi in range(win_ysize): + * yi_root = yi+yoff + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2910 + * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + * 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":2911 + * 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, 1e-8, 1e-5): + */ + __pyx_v_xi_root = (__pyx_v_xi + __pyx_v_xoff); + + /* "pygeoprocessing/routing/routing.pyx":2912 + * 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, 1e-8, 1e-5): + * 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":2913 + * xi_root = xi+xoff + * flow_accum = flow_accum_mr.get(xi_root, yi_root) + * if _is_close(flow_accum, flow_accum_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * 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, 1e-8, 1e-5) != 0); + if (__pyx_t_1) { + + /* "pygeoprocessing/routing/routing.pyx":2914 + * flow_accum = flow_accum_mr.get(xi_root, yi_root) + * if _is_close(flow_accum, flow_accum_nodata, 1e-8, 1e-5): + * continue # <<<<<<<<<<<<<< + * if stream_mr.get(xi_root, yi_root) != stream_nodata: + * continue + */ + goto __pyx_L13_continue; + + /* "pygeoprocessing/routing/routing.pyx":2913 + * xi_root = xi+xoff + * flow_accum = flow_accum_mr.get(xi_root, yi_root) + * if _is_close(flow_accum, flow_accum_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< + * continue + * if stream_mr.get(xi_root, yi_root) != stream_nodata: + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2915 + * if _is_close(flow_accum, flow_accum_nodata, 1e-8, 1e-5): + * 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":2916 + * 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":2915 + * if _is_close(flow_accum, flow_accum_nodata, 1e-8, 1e-5): + * continue + * if stream_mr.get(xi_root, yi_root) != stream_nodata: # <<<<<<<<<<<<<< + * continue + * stream_mr.set(xi_root, yi_root, 0) + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2917 + * 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":2918 + * 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":2919 + * stream_mr.set(xi_root, yi_root, 0) + * if flow_accum < flow_threshold: + * continue # <<<<<<<<<<<<<< + * + * flow_dir_mfd = flow_dir_mfd_mr.get(xi_root, yi_root) + */ + goto __pyx_L13_continue; + + /* "pygeoprocessing/routing/routing.pyx":2918 + * continue + * stream_mr.set(xi_root, yi_root, 0) + * if flow_accum < flow_threshold: # <<<<<<<<<<<<<< + * continue + * + */ + } + + /* "pygeoprocessing/routing/routing.pyx":2921 + * continue + * + * flow_dir_mfd = 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":2922 + * + * flow_dir_mfd = 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":2923 + * flow_dir_mfd = 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":2924 + * 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":2926 + * if ((flow_dir_mfd >> (i_n * 4)) & 0xF) == 0: + * # no flow in that direction + * continue # <<<<<<<<<<<<<< + * xi_n = xi_root+D8_XOFFSET[i_n] + * yi_n = yi_root+D8_YOFFSET[i_n] + */ + goto __pyx_L18_continue; + + /* "pygeoprocessing/routing/routing.pyx":2924 + * 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":2927 + * # no flow in that direction + * continue + * xi_n = xi_root+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< + * yi_n = yi_root+D8_YOFFSET[i_n] + * if (xi_n < 0 or xi_n >= raster_x_size or + */ + __pyx_v_xi_n = (__pyx_v_xi_root + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":2928 + * continue + * xi_n = xi_root+D8_XOFFSET[i_n] + * yi_n = yi_root+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< + * 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_D8_YOFFSET[__pyx_v_i_n])); + + /* "pygeoprocessing/routing/routing.pyx":2929 + * xi_n = xi_root+D8_XOFFSET[i_n] + * yi_n = yi_root+D8_YOFFSET[i_n] + * 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":2930 + * yi_n = yi_root+D8_YOFFSET[i_n] + * 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":2929 + * xi_n = xi_root+D8_XOFFSET[i_n] + * yi_n = yi_root+D8_YOFFSET[i_n] + * 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":2932 + * 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":2933 + * # 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":2929 + * xi_n = xi_root+D8_XOFFSET[i_n] + * yi_n = yi_root+D8_YOFFSET[i_n] + * 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":2934 + * 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":2935 + * 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":2936 + * 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":2934 + * 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":2937 + * 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":2938 + * 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":2939 + * 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":2937 + * 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":2941 + * 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":2942 + * + * 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":2943 + * 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":2944 + * 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":2945 + * 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":2946 + * yi_n = open_set.front().yi + * open_set.pop() + * n_iterations += 1 # <<<<<<<<<<<<<< + * for i_sn in range(8): + * xi_sn = xi_n+D8_XOFFSET[i_sn] + */ + __pyx_v_n_iterations = (__pyx_v_n_iterations + 1); + + /* "pygeoprocessing/routing/routing.pyx":2947 + * open_set.pop() + * n_iterations += 1 + * for i_sn in range(8): # <<<<<<<<<<<<<< + * xi_sn = xi_n+D8_XOFFSET[i_sn] + * yi_sn = yi_n+D8_YOFFSET[i_sn] + */ + for (__pyx_t_19 = 0; __pyx_t_19 < 8; __pyx_t_19+=1) { + __pyx_v_i_sn = __pyx_t_19; + + /* "pygeoprocessing/routing/routing.pyx":2948 + * n_iterations += 1 + * for i_sn in range(8): + * xi_sn = xi_n+D8_XOFFSET[i_sn] # <<<<<<<<<<<<<< + * yi_sn = yi_n+D8_YOFFSET[i_sn] + * if (xi_sn < 0 or xi_sn >= raster_x_size or + */ + __pyx_v_xi_sn = (__pyx_v_xi_n + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_sn])); + + /* "pygeoprocessing/routing/routing.pyx":2949 + * for i_sn in range(8): + * xi_sn = xi_n+D8_XOFFSET[i_sn] + * yi_sn = yi_n+D8_YOFFSET[i_sn] # <<<<<<<<<<<<<< + * 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_D8_YOFFSET[__pyx_v_i_sn])); + + /* "pygeoprocessing/routing/routing.pyx":2950 + * xi_sn = xi_n+D8_XOFFSET[i_sn] + * yi_sn = yi_n+D8_YOFFSET[i_sn] + * 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":2951 + * yi_sn = yi_n+D8_YOFFSET[i_sn] + * if (xi_sn < 0 or xi_sn >= raster_x_size or + * yi_sn < 0 or yi_sn >= raster_y_size): # <<<<<<<<<<<<<< + * continue + * flow_dir_mfd = 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":2950 + * xi_sn = xi_n+D8_XOFFSET[i_sn] + * yi_sn = yi_n+D8_YOFFSET[i_sn] + * 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":2952 + * if (xi_sn < 0 or xi_sn >= raster_x_size or + * yi_sn < 0 or yi_sn >= raster_y_size): + * continue # <<<<<<<<<<<<<< + * flow_dir_mfd = flow_dir_mfd_mr.get(xi_sn, yi_sn) + * if flow_dir_mfd == flow_dir_nodata: + */ + goto __pyx_L30_continue; + + /* "pygeoprocessing/routing/routing.pyx":2950 + * xi_sn = xi_n+D8_XOFFSET[i_sn] + * yi_sn = yi_n+D8_YOFFSET[i_sn] + * 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":2953 + * yi_sn < 0 or yi_sn >= raster_y_size): + * continue + * flow_dir_mfd = 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":2954 + * continue + * flow_dir_mfd = 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":2955 + * flow_dir_mfd = 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":2954 + * continue + * flow_dir_mfd = 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":2957 + * continue + * if ((flow_dir_mfd >> + * (D8_REVERSE_DIRECTION[i_sn] * 4)) & 0xF) > 0: # <<<<<<<<<<<<<< + * # upstream pixel flows into this one + * stream_val = 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":2956 + * 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":2959 + * (D8_REVERSE_DIRECTION[i_sn] * 4)) & 0xF) > 0: + * # upstream pixel flows into this one + * stream_val = 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":2960 + * # upstream pixel flows into this one + * stream_val = 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":2961 + * stream_val = 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":2963 + * 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":2964 + * 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":2966 + * 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":2965 + * 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":2970 + * # 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":2969 + * # 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":2971 + * 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":2972 + * 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":2973 + * while backtrace_set.size() > 0: + * xi_bn = backtrace_set.front().xi + * yi_bn = backtrace_set.front().yi # <<<<<<<<<<<<<< + * backtrace_set.pop() + * flow_dir_mfd = ( + */ + __pyx_t_21 = __pyx_v_backtrace_set.front().yi; + __pyx_v_yi_bn = __pyx_t_21; + + /* "pygeoprocessing/routing/routing.pyx":2974 + * xi_bn = backtrace_set.front().xi + * yi_bn = backtrace_set.front().yi + * backtrace_set.pop() # <<<<<<<<<<<<<< + * flow_dir_mfd = ( + * flow_dir_mfd_mr.get(xi_bn, yi_bn)) + */ + __pyx_v_backtrace_set.pop(); + + /* "pygeoprocessing/routing/routing.pyx":2975 + * yi_bn = backtrace_set.front().yi + * backtrace_set.pop() + * flow_dir_mfd = ( # <<<<<<<<<<<<<< + * 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":2977 + * flow_dir_mfd = ( + * 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+D8_XOFFSET[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":2978 + * 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+D8_XOFFSET[i_sn] + * yi_sn = yi_bn+D8_YOFFSET[i_sn] + */ + __pyx_t_1 = ((((__pyx_v_flow_dir_mfd >> (__pyx_v_i_sn * 4)) & 0xF) > 0) != 0); + if (__pyx_t_1) { + + /* "pygeoprocessing/routing/routing.pyx":2979 + * for i_sn in range(8): + * if (flow_dir_mfd >> (i_sn*4)) & 0xF > 0: + * xi_sn = xi_bn+D8_XOFFSET[i_sn] # <<<<<<<<<<<<<< + * yi_sn = yi_bn+D8_YOFFSET[i_sn] + * if (xi_sn < 0 or xi_sn >= raster_x_size or + */ + __pyx_v_xi_sn = (__pyx_v_xi_bn + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_sn])); + + /* "pygeoprocessing/routing/routing.pyx":2980 + * if (flow_dir_mfd >> (i_sn*4)) & 0xF > 0: + * xi_sn = xi_bn+D8_XOFFSET[i_sn] + * yi_sn = yi_bn+D8_YOFFSET[i_sn] # <<<<<<<<<<<<<< + * 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_D8_YOFFSET[__pyx_v_i_sn])); + + /* "pygeoprocessing/routing/routing.pyx":2981 + * xi_sn = xi_bn+D8_XOFFSET[i_sn] + * yi_sn = yi_bn+D8_YOFFSET[i_sn] + * 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":2982 + * yi_sn = yi_bn+D8_YOFFSET[i_sn] + * 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":2981 + * xi_sn = xi_bn+D8_XOFFSET[i_sn] + * yi_sn = yi_bn+D8_YOFFSET[i_sn] + * 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":2983 + * 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":2981 + * xi_sn = xi_bn+D8_XOFFSET[i_sn] + * yi_sn = yi_bn+D8_YOFFSET[i_sn] + * 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":2984 + * 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":2985 + * 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":2987 + * 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":2986 + * 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":2984 + * 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":2978 + * 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+D8_XOFFSET[i_sn] + * yi_sn = yi_bn+D8_YOFFSET[i_sn] + */ + } + __pyx_L43_continue:; + } + } + + /* "pygeoprocessing/routing/routing.pyx":2963 + * 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":2988 + * 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":2989 + * 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":2991 + * 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":2990 + * 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":2988 + * 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":2960 + * # upstream pixel flows into this one + * stream_val = 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":2956 + * 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":2897 + * cdef time_t last_log_time = ctime(NULL) + * + * for block_offsets in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * (target_stream_raster_path, 1), offset_only=True): + * xoff = block_offsets['xoff'] + */ + } + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2993 + * CoordinateType(xi_sn, yi_sn)) + * + * stream_mr.close() # <<<<<<<<<<<<<< + * LOGGER.info('filter out incomplete divergent streams') + * block_offsets_list = list(pygeoprocessing.iterblocks( + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_stream_mr), __pyx_n_s_close); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2993, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_11 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2993, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2994 + * + * stream_mr.close() + * LOGGER.info('filter out incomplete divergent streams') # <<<<<<<<<<<<<< + * block_offsets_list = list(pygeoprocessing.iterblocks( + * (target_stream_raster_path, 1), offset_only=True)) + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2994, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_info); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2994, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(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); + } + } + __pyx_t_11 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_3, __pyx_kp_u_filter_out_incomplete_divergent) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_kp_u_filter_out_incomplete_divergent); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2994, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2995 + * stream_mr.close() + * LOGGER.info('filter out incomplete divergent streams') + * block_offsets_list = list(pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * (target_stream_raster_path, 1), offset_only=True)) + * stream_raster = gdal.OpenEx( + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2995, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2995, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2996 + * LOGGER.info('filter out incomplete divergent streams') + * block_offsets_list = list(pygeoprocessing.iterblocks( + * (target_stream_raster_path, 1), offset_only=True)) # <<<<<<<<<<<<<< + * stream_raster = gdal.OpenEx( + * target_stream_raster_path, gdal.OF_RASTER | gdal.GA_Update) + */ + __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2996, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_INCREF(__pyx_v_target_stream_raster_path); + __Pyx_GIVEREF(__pyx_v_target_stream_raster_path); + PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_target_stream_raster_path); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_int_1); + + /* "pygeoprocessing/routing/routing.pyx":2995 + * stream_mr.close() + * LOGGER.info('filter out incomplete divergent streams') + * block_offsets_list = list(pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * (target_stream_raster_path, 1), offset_only=True)) + * stream_raster = gdal.OpenEx( + */ + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2995, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_11); + __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2996 + * LOGGER.info('filter out incomplete divergent streams') + * block_offsets_list = list(pygeoprocessing.iterblocks( + * (target_stream_raster_path, 1), offset_only=True)) # <<<<<<<<<<<<<< + * stream_raster = gdal.OpenEx( + * target_stream_raster_path, gdal.OF_RASTER | gdal.GA_Update) + */ + __pyx_t_11 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2996, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 2996, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2995 + * stream_mr.close() + * LOGGER.info('filter out incomplete divergent streams') + * block_offsets_list = list(pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * (target_stream_raster_path, 1), offset_only=True)) + * stream_raster = gdal.OpenEx( + */ + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_3, __pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2995, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = PySequence_List(__pyx_t_4); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2995, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_block_offsets_list = ((PyObject*)__pyx_t_11); + __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2997 + * block_offsets_list = list(pygeoprocessing.iterblocks( + * (target_stream_raster_path, 1), offset_only=True)) + * stream_raster = gdal.OpenEx( # <<<<<<<<<<<<<< + * target_stream_raster_path, gdal.OF_RASTER | gdal.GA_Update) + * stream_band = stream_raster.GetRasterBand(1) + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2997, __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, 2997, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2998 + * (target_stream_raster_path, 1), offset_only=True)) + * stream_raster = gdal.OpenEx( + * target_stream_raster_path, gdal.OF_RASTER | gdal.GA_Update) # <<<<<<<<<<<<<< + * stream_band = stream_raster.GetRasterBand(1) + * for block_offsets in block_offsets_list: + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2998, __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, 2998, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2998, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_GA_Update); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2998, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyNumber_Or(__pyx_t_6, __pyx_t_15); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2998, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_15)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_15); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_v_target_stream_raster_path, __pyx_t_4}; + __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2997, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_GOTREF(__pyx_t_11); + __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_15, __pyx_v_target_stream_raster_path, __pyx_t_4}; + __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2997, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_6 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2997, __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_10, __pyx_v_target_stream_raster_path); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_10, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2997, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_stream_raster = __pyx_t_11; + __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2999 + * stream_raster = gdal.OpenEx( + * target_stream_raster_path, gdal.OF_RASTER | gdal.GA_Update) + * stream_band = stream_raster.GetRasterBand(1) # <<<<<<<<<<<<<< + * for block_offsets in block_offsets_list: + * stream_array = stream_band.ReadAsArray(**block_offsets) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2999, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_11 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_6, __pyx_int_1) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_int_1); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2999, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_stream_band = __pyx_t_11; + __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3000 + * target_stream_raster_path, gdal.OF_RASTER | gdal.GA_Update) + * stream_band = stream_raster.GetRasterBand(1) + * for block_offsets in block_offsets_list: # <<<<<<<<<<<<<< + * stream_array = stream_band.ReadAsArray(**block_offsets) + * stream_array[stream_array == 2] = 0 + */ + __pyx_t_11 = __pyx_v_block_offsets_list; __Pyx_INCREF(__pyx_t_11); __pyx_t_12 = 0; + for (;;) { + if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_11)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_11, __pyx_t_12); __Pyx_INCREF(__pyx_t_3); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 3000, __pyx_L1_error) + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_11, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3000, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + __Pyx_XDECREF_SET(__pyx_v_block_offsets, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3001 + * stream_band = stream_raster.GetRasterBand(1) + * for block_offsets in block_offsets_list: + * stream_array = stream_band.ReadAsArray(**block_offsets) # <<<<<<<<<<<<<< + * stream_array[stream_array == 2] = 0 + * stream_band.WriteArray( + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3001, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (unlikely(__pyx_v_block_offsets == Py_None)) { + PyErr_SetString(PyExc_TypeError, "argument after ** must be a mapping, not NoneType"); + __PYX_ERR(0, 3001, __pyx_L1_error) + } + if (likely(PyDict_CheckExact(__pyx_v_block_offsets))) { + __pyx_t_6 = PyDict_Copy(__pyx_v_block_offsets); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3001, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + } else { + __pyx_t_6 = PyObject_CallFunctionObjArgs((PyObject*)&PyDict_Type, __pyx_v_block_offsets, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3001, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + } + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_empty_tuple, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3001, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF_SET(__pyx_v_stream_array, __pyx_t_4); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3002 + * for block_offsets in block_offsets_list: + * stream_array = stream_band.ReadAsArray(**block_offsets) + * stream_array[stream_array == 2] = 0 # <<<<<<<<<<<<<< + * stream_band.WriteArray( + * stream_array, xoff=block_offsets['xoff'], + */ + __pyx_t_4 = __Pyx_PyInt_EqObjC(__pyx_v_stream_array, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3002, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (unlikely(PyObject_SetItem(__pyx_v_stream_array, __pyx_t_4, __pyx_int_0) < 0)) __PYX_ERR(0, 3002, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3003 + * 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_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_band, __pyx_n_s_WriteArray); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3003, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "pygeoprocessing/routing/routing.pyx":3004 + * stream_array[stream_array == 2] = 0 + * stream_band.WriteArray( + * stream_array, xoff=block_offsets['xoff'], # <<<<<<<<<<<<<< + * yoff=block_offsets['yoff']) + * stream_band = None + */ + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3003, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(__pyx_v_stream_array); + __Pyx_GIVEREF(__pyx_v_stream_array); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_stream_array); + __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3004, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_15 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_u_xoff); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3004, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_xoff, __pyx_t_15) < 0) __PYX_ERR(0, 3004, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3005 + * 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_u_yoff); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3005, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_yoff, __pyx_t_15) < 0) __PYX_ERR(0, 3004, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3003 + * 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_4, __pyx_t_6, __pyx_t_3); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3003, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3000 + * target_stream_raster_path, gdal.OF_RASTER | gdal.GA_Update) + * stream_band = stream_raster.GetRasterBand(1) + * for block_offsets in block_offsets_list: # <<<<<<<<<<<<<< + * stream_array = stream_band.ReadAsArray(**block_offsets) + * stream_array[stream_array == 2] = 0 + */ + } + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3006 + * 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":3007 + * 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":3008 + * stream_band = None + * stream_raster = None + * LOGGER.info('100.0% complete') # <<<<<<<<<<<<<< + * + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3008, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_info); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3008, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_15)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_15); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_11 = (__pyx_t_15) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_15, __pyx_kp_u_100_0_complete) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_100_0_complete); + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 3008, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2811 + * + * + * def extract_streams_mfd( # <<<<<<<<<<<<<< + * flow_accum_raster_path_band, flow_dir_mfd_path_band, + * double flow_threshold, target_stream_raster_path, + */ + + /* 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_11); + __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_block_offsets_list); + __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":3011 + * + * + * 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_is_raster_path_band_formatted", 0); + + /* "pygeoprocessing/routing/routing.pyx":3013 + * 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":3014 + * """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":3013 + * 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":3015 + * 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, 3015, __pyx_L1_error) + __pyx_t_2 = ((__pyx_t_4 != 2) != 0); + if (__pyx_t_2) { + + /* "pygeoprocessing/routing/routing.pyx":3016 + * 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":3015 + * 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":3017 + * 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, 3017, __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":3018 + * 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":3017 + * 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":3019 + * 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, 3019, __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":3020 + * 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":3019 + * 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":3022 + * 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":3011 + * + * + * 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; +} + +/* "pygeoprocessing/routing/routing.pyx":3025 + * + * + * def extract_strahler_streams_d8( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band, flow_accum_raster_path_band, + * dem_raster_path_band, + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_21extract_strahler_streams_d8(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_15pygeoprocessing_7routing_7routing_20extract_strahler_streams_d8[] = "Extract Strahler order stream geometry from flow accumulation.\n\n Creates a Strahler ordered stream vector containing line segments\n representing each separate stream fragment. The final vector contains\n at least the fields:\n\n * \"order\" (int): an integer representing the stream order\n * \"river_id\" (int): unique ID used by all stream segments that\n connect to the same outlet.\n * \"drop_distance\" (float): this is the drop distance in DEM units\n from the upstream to downstream component of this stream\n segment.\n * \"outlet\" (int): 1 if this segment is an outlet, 0 if not.\n * \"river_id\": unique ID among all stream segments which are\n hydrologically connected.\n * \"us_fa\" (int): flow accumulation value at the upstream end of\n the stream segment.\n * \"ds_fa\" (int): flow accumulation value at the downstream end of\n the stream segment\n * \"thresh_fa\" (int): the final threshold flow accumulation value\n used to determine the river segments.\n * \"upstream_d8_dir\" (int): a bookkeeping parameter from stream\n calculations that is left in due to the overhead\n of deleting a field.\n * \"ds_x\" (int): the raster x coordinate for the outlet.\n * \"ds_y\" (int): the raster y coordinate for the outlet.\n * \"ds_x_1\" (int): the x raster space coordinate that is 1 pixel\n upstream from the outlet.\n * \"ds_y_1\" (int): the y raster space coordinate that is 1 pixel\n upstream from the outlet.\n * \"us_x\" (int): the raster x coordinate for the upstream inlet.\n * \"us_y\" (int): the raster y coordinate for the upstream inlet.\n\n Args:\n flow_dir_d8_raster_path_band (tuple): a path/band representing the D8\n flow direction raster.\n flow_accum_raster_path_band (tuple): a path/band representing th""e D8\n flow accumulation raster represented by\n ``flow_dir_d8_raster_path_band``.\n dem_raster_path_band (tuple): a path/band representing the DEM used to\n derive flow dir.\n target_stream_vector_path (tuple): a single layer line vector created\n by this function representing the stream segments extracted from\n the above arguments. Contains the fields \"order\" and \"parent\" as\n described above.\n min_flow_accum_threshold (int): minimum number of upstream pixels\n required to create a stream. If ``autotune_flow_accumulation``\n is True, then the final value may be adjusted based on\n significant differences in 1st and 2nd order streams.\n river_order (int): what stream order to define as a river in terms of\n automatically determining flow accumulation threshold for that\n stream collection.\n min_p_val (float): minimum p_value test for significance\n autotune_flow_accumulation (bool): If true, uses a t-test to test for\n significant distances in order 1 and order 2 streams. If it is\n significant the flow accumulation parameter is adjusted upwards\n until the drop distances are insignificant.\n osr_axis_mapping_strategy (int): OSR axis mapping strategy for\n ``SpatialReference`` objects. Defaults to\n ``geoprocessing.DEFAULT_OSR_AXIS_MAPPING_STRATEGY``. This parameter\n should not be changed unless you know what you are doing.\n\n Returns:\n None.\n "; +static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_21extract_strahler_streams_d8 = {"extract_strahler_streams_d8", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_7routing_7routing_21extract_strahler_streams_d8, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_7routing_7routing_20extract_strahler_streams_d8}; +static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_21extract_strahler_streams_d8(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_flow_dir_d8_raster_path_band = 0; + PyObject *__pyx_v_flow_accum_raster_path_band = 0; + PyObject *__pyx_v_dem_raster_path_band = 0; + PyObject *__pyx_v_target_stream_vector_path = 0; + long __pyx_v_min_flow_accum_threshold; + int __pyx_v_river_order; + float __pyx_v_min_p_val; + PyObject *__pyx_v_autotune_flow_accumulation = 0; + PyObject *__pyx_v_osr_axis_mapping_strategy = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("extract_strahler_streams_d8 (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_flow_dir_d8_raster_path_band,&__pyx_n_s_flow_accum_raster_path_band,&__pyx_n_s_dem_raster_path_band,&__pyx_n_s_target_stream_vector_path,&__pyx_n_s_min_flow_accum_threshold,&__pyx_n_s_river_order,&__pyx_n_s_min_p_val,&__pyx_n_s_autotune_flow_accumulation,&__pyx_n_s_osr_axis_mapping_strategy,0}; + PyObject* values[9] = {0,0,0,0,0,0,0,0,0}; + + /* "pygeoprocessing/routing/routing.pyx":3032 + * int river_order=5, + * float min_p_val=0.05, + * autotune_flow_accumulation=False, # <<<<<<<<<<<<<< + * osr_axis_mapping_strategy=DEFAULT_OSR_AXIS_MAPPING_STRATEGY): + * """Extract Strahler order stream geometry from flow accumulation. + */ + values[7] = ((PyObject *)Py_False); + values[8] = __pyx_k__15; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); + CYTHON_FALLTHROUGH; + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + CYTHON_FALLTHROUGH; + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + CYTHON_FALLTHROUGH; + 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_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_flow_accum_raster_path_band)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("extract_strahler_streams_d8", 0, 4, 9, 1); __PYX_ERR(0, 3025, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dem_raster_path_band)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("extract_strahler_streams_d8", 0, 4, 9, 2); __PYX_ERR(0, 3025, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 3: + if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_stream_vector_path)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("extract_strahler_streams_d8", 0, 4, 9, 3); __PYX_ERR(0, 3025, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 4: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_min_flow_accum_threshold); + 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_river_order); + if (value) { values[5] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 6: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_min_p_val); + if (value) { values[6] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 7: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_autotune_flow_accumulation); + if (value) { values[7] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 8: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_osr_axis_mapping_strategy); + if (value) { values[8] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "extract_strahler_streams_d8") < 0)) __PYX_ERR(0, 3025, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); + CYTHON_FALLTHROUGH; + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + CYTHON_FALLTHROUGH; + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + CYTHON_FALLTHROUGH; + 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_dir_d8_raster_path_band = values[0]; + __pyx_v_flow_accum_raster_path_band = values[1]; + __pyx_v_dem_raster_path_band = values[2]; + __pyx_v_target_stream_vector_path = values[3]; + if (values[4]) { + __pyx_v_min_flow_accum_threshold = __Pyx_PyInt_As_long(values[4]); if (unlikely((__pyx_v_min_flow_accum_threshold == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 3029, __pyx_L3_error) + } else { + __pyx_v_min_flow_accum_threshold = ((long)0x64); + } + if (values[5]) { + __pyx_v_river_order = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_river_order == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3030, __pyx_L3_error) + } else { + __pyx_v_river_order = ((int)5); + } + if (values[6]) { + __pyx_v_min_p_val = __pyx_PyFloat_AsFloat(values[6]); if (unlikely((__pyx_v_min_p_val == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 3031, __pyx_L3_error) + } else { + __pyx_v_min_p_val = ((float)0.05); + } + __pyx_v_autotune_flow_accumulation = values[7]; + __pyx_v_osr_axis_mapping_strategy = values[8]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("extract_strahler_streams_d8", 0, 4, 9, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3025, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pygeoprocessing.routing.routing.extract_strahler_streams_d8", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing_20extract_strahler_streams_d8(__pyx_self, __pyx_v_flow_dir_d8_raster_path_band, __pyx_v_flow_accum_raster_path_band, __pyx_v_dem_raster_path_band, __pyx_v_target_stream_vector_path, __pyx_v_min_flow_accum_threshold, __pyx_v_river_order, __pyx_v_min_p_val, __pyx_v_autotune_flow_accumulation, __pyx_v_osr_axis_mapping_strategy); + + /* "pygeoprocessing/routing/routing.pyx":3025 + * + * + * def extract_strahler_streams_d8( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band, flow_accum_raster_path_band, + * dem_raster_path_band, + */ + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_20extract_strahler_streams_d8(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_flow_dir_d8_raster_path_band, PyObject *__pyx_v_flow_accum_raster_path_band, PyObject *__pyx_v_dem_raster_path_band, PyObject *__pyx_v_target_stream_vector_path, long __pyx_v_min_flow_accum_threshold, int __pyx_v_river_order, float __pyx_v_min_p_val, PyObject *__pyx_v_autotune_flow_accumulation, PyObject *__pyx_v_osr_axis_mapping_strategy) { + PyObject *__pyx_v_flow_dir_info = NULL; + PyObject *__pyx_v_flow_dir_srs = NULL; + PyObject *__pyx_v_gpkg_driver = NULL; + PyObject *__pyx_v_stream_vector = NULL; + PyObject *__pyx_v_stream_basename = NULL; + PyObject *__pyx_v_stream_layer = NULL; + struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_flow_dir_managed_raster = NULL; + struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_flow_accum_managed_raster = NULL; + struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_dem_managed_raster = NULL; + int __pyx_v_flow_nodata; + int __pyx_v_xoff; + int __pyx_v_yoff; + int __pyx_v_i; + int __pyx_v_j; + int __pyx_v_d; + int __pyx_v_d_n; + int __pyx_v_n_cols; + int __pyx_v_n_rows; + int __pyx_v_win_xsize; + int __pyx_v_win_ysize; + long __pyx_v_n_pixels; + long __pyx_v_n_processed; + time_t __pyx_v_last_log_time; + std::stack __pyx_v_source_point_stack; + struct __pyx_t_15pygeoprocessing_7routing_7routing_StreamConnectivityPoint __pyx_v_source_stream_point; + int __pyx_v_x_l; + int __pyx_v_y_l; + int __pyx_v_x_n; + int __pyx_v_y_n; + int __pyx_v_upstream_count; + int __pyx_v_upstream_index; + int *__pyx_v_upstream_dirs; + long __pyx_v_local_flow_accum; + int __pyx_v_is_drain; + PyObject *__pyx_v_coord_to_stream_ids = NULL; + PyObject *__pyx_v_offset_dict = NULL; + PyObject *__pyx_v_stream_feature = NULL; + PyObject *__pyx_v_stream_fid = NULL; + PyObject *__pyx_v_n_points = NULL; + PyObject *__pyx_v_downstream_to_upstream_ids = NULL; + PyObject *__pyx_v_upstream_to_downstream_id = NULL; + PyObject *__pyx_v_payload = NULL; + PyObject *__pyx_v_x_u = NULL; + PyObject *__pyx_v_y_u = NULL; + PyObject *__pyx_v_ds_x_1 = NULL; + PyObject *__pyx_v_ds_y_1 = NULL; + PyObject *__pyx_v_upstream_id_list = NULL; + PyObject *__pyx_v_stream_line = NULL; + double __pyx_v_downstream_dem; + PyObject *__pyx_v_upstream_id = NULL; + double __pyx_v_upstream_dem; + double __pyx_v_drop_distance; + PyObject *__pyx_v_streams_to_process = NULL; + PyObject *__pyx_v_base_feature_count = NULL; + PyObject *__pyx_v_outlet_fid_list = NULL; + PyObject *__pyx_v_downstream_fid = NULL; + PyObject *__pyx_v_downstream_feature = NULL; + PyObject *__pyx_v_connected_upstream_fids = NULL; + PyObject *__pyx_v_stream_order_list = NULL; + int __pyx_v_all_defined; + PyObject *__pyx_v_upstream_fid = NULL; + PyObject *__pyx_v_upstream_feature = NULL; + PyObject *__pyx_v_upstream_order = NULL; + PyObject *__pyx_v_sorted_stream_order_list = NULL; + PyObject *__pyx_v_downstream_order = NULL; + PyObject *__pyx_v_working_river_id = NULL; + PyObject *__pyx_v_outlet_index = NULL; + PyObject *__pyx_v_outlet_fid = NULL; + PyObject *__pyx_v_search_stack = NULL; + PyObject *__pyx_v_feature_id = NULL; + PyObject *__pyx_v_stream_order = NULL; + PyObject *__pyx_v_upstream_stack = NULL; + PyObject *__pyx_v_streams_by_order = NULL; + PyObject *__pyx_v_drop_distance_collection = NULL; + PyObject *__pyx_v_max_upstream_flow_accum = NULL; + PyObject *__pyx_v_order = NULL; + PyObject *__pyx_v_working_flow_accum_threshold = NULL; + PyObject *__pyx_v_test_order = NULL; + CYTHON_UNUSED PyObject *__pyx_v__ = NULL; + PyObject *__pyx_v_p_val = NULL; + PyObject *__pyx_v_streams_to_retest = NULL; + PyObject *__pyx_v_ds_x = NULL; + PyObject *__pyx_v_ds_y = NULL; + PyObject *__pyx_v_upstream_d8_dir = NULL; + PyObject *__pyx_v_working_stack = NULL; + PyObject *__pyx_v_fid_to_order = NULL; + PyObject *__pyx_v_processed_segments = NULL; + Py_ssize_t __pyx_v_segments_to_process; + PyObject *__pyx_v_deleted_set = NULL; + PyObject *__pyx_v_working_fid = NULL; + PyObject *__pyx_v_upstream_fid_list = NULL; + PyObject *__pyx_v_order_count = NULL; + PyObject *__pyx_v_working_order = NULL; + PyObject *__pyx_v_working_feature = NULL; + PyObject *__pyx_v_connected_fids = NULL; + PyObject *__pyx_v_downstream_geom = NULL; + PyObject *__pyx_v_working_geom = NULL; + PyObject *__pyx_v_multi_line = NULL; + PyObject *__pyx_v_joined_line = NULL; + int __pyx_v_upstream_all_defined; + PyObject *__pyx_v_connected_fid = NULL; + PyObject *__pyx_7genexpr__pyx_v_stream_feature = NULL; + PyObject *__pyx_8genexpr1__pyx_v_fid = NULL; + 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; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *(*__pyx_t_10)(PyObject *); + int __pyx_t_11; + int __pyx_t_12[8]; + Py_ssize_t __pyx_t_13; + PyObject *(*__pyx_t_14)(PyObject *); + Py_ssize_t __pyx_t_15; + Py_UCS4 __pyx_t_16; + int __pyx_t_17; + int __pyx_t_18; + int __pyx_t_19; + int __pyx_t_20; + int __pyx_t_21; + int __pyx_t_22; + int __pyx_t_23; + int __pyx_t_24; + struct __pyx_t_15pygeoprocessing_7routing_7routing_StreamConnectivityPoint __pyx_t_25; + int __pyx_t_26; + int __pyx_t_27; + Py_ssize_t __pyx_t_28; + int __pyx_t_29; + PyObject *__pyx_t_30 = NULL; + PyObject *__pyx_t_31 = NULL; + PyObject *__pyx_t_32 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("extract_strahler_streams_d8", 0); + + /* "pygeoprocessing/routing/routing.pyx":3099 + * None. + * """ + * flow_dir_info = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band[0]) + * if flow_dir_info['projection_wkt']: + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3099, __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, 3099, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3100 + * """ + * flow_dir_info = pygeoprocessing.get_raster_info( + * flow_dir_d8_raster_path_band[0]) # <<<<<<<<<<<<<< + * if flow_dir_info['projection_wkt']: + * flow_dir_srs = osr.SpatialReference() + */ + __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, 3100, __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); + } + } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3099, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_flow_dir_info = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3101 + * flow_dir_info = pygeoprocessing.get_raster_info( + * flow_dir_d8_raster_path_band[0]) + * if flow_dir_info['projection_wkt']: # <<<<<<<<<<<<<< + * flow_dir_srs = osr.SpatialReference() + * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) + */ + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_projection_wkt); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3101, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 3101, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":3102 + * flow_dir_d8_raster_path_band[0]) + * if flow_dir_info['projection_wkt']: + * flow_dir_srs = osr.SpatialReference() # <<<<<<<<<<<<<< + * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) + * flow_dir_srs.SetAxisMappingStrategy(osr_axis_mapping_strategy) + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_osr); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3102, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_SpatialReference); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3102, __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 && 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); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3102, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_flow_dir_srs = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3103 + * if flow_dir_info['projection_wkt']: + * flow_dir_srs = osr.SpatialReference() + * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) # <<<<<<<<<<<<<< + * flow_dir_srs.SetAxisMappingStrategy(osr_axis_mapping_strategy) + * else: + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_srs, __pyx_n_s_ImportFromWkt); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3103, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_projection_wkt); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3103, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3103, __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":3104 + * flow_dir_srs = osr.SpatialReference() + * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) + * flow_dir_srs.SetAxisMappingStrategy(osr_axis_mapping_strategy) # <<<<<<<<<<<<<< + * else: + * flow_dir_srs = None + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_srs, __pyx_n_s_SetAxisMappingStrategy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3104, __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); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_osr_axis_mapping_strategy) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_osr_axis_mapping_strategy); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3104, __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":3101 + * flow_dir_info = pygeoprocessing.get_raster_info( + * flow_dir_d8_raster_path_band[0]) + * if flow_dir_info['projection_wkt']: # <<<<<<<<<<<<<< + * flow_dir_srs = osr.SpatialReference() + * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) + */ + goto __pyx_L3; + } + + /* "pygeoprocessing/routing/routing.pyx":3106 + * flow_dir_srs.SetAxisMappingStrategy(osr_axis_mapping_strategy) + * else: + * flow_dir_srs = None # <<<<<<<<<<<<<< + * gpkg_driver = gdal.GetDriverByName('GPKG') + * + */ + /*else*/ { + __Pyx_INCREF(Py_None); + __pyx_v_flow_dir_srs = Py_None; + } + __pyx_L3:; + + /* "pygeoprocessing/routing/routing.pyx":3107 + * else: + * flow_dir_srs = None + * gpkg_driver = gdal.GetDriverByName('GPKG') # <<<<<<<<<<<<<< + * + * stream_vector = gpkg_driver.Create( + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3107, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_GetDriverByName); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3107, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + 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_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_n_u_GPKG) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_n_u_GPKG); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3107, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_gpkg_driver = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3109 + * gpkg_driver = gdal.GetDriverByName('GPKG') + * + * stream_vector = gpkg_driver.Create( # <<<<<<<<<<<<<< + * target_stream_vector_path, 0, 0, 0, gdal.GDT_Unknown) + * stream_basename = os.path.basename( + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_gpkg_driver, __pyx_n_s_Create); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3109, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + + /* "pygeoprocessing/routing/routing.pyx":3110 + * + * stream_vector = gpkg_driver.Create( + * target_stream_vector_path, 0, 0, 0, gdal.GDT_Unknown) # <<<<<<<<<<<<<< + * stream_basename = os.path.basename( + * os.path.splitext(target_stream_vector_path)[0]) + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3110, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_GDT_Unknown); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3110, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && likely(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_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[6] = {__pyx_t_2, __pyx_v_target_stream_vector_path, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_t_4}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 5+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3109, __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; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[6] = {__pyx_t_2, __pyx_v_target_stream_vector_path, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_t_4}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 5+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3109, __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; + } else + #endif + { + __pyx_t_7 = PyTuple_New(5+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3109, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_2) { + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2); __pyx_t_2 = NULL; + } + __Pyx_INCREF(__pyx_v_target_stream_vector_path); + __Pyx_GIVEREF(__pyx_v_target_stream_vector_path); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_target_stream_vector_path); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_int_0); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_6, __pyx_int_0); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_7, 3+__pyx_t_6, __pyx_int_0); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_7, 4+__pyx_t_6, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3109, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_stream_vector = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3111 + * stream_vector = gpkg_driver.Create( + * target_stream_vector_path, 0, 0, 0, gdal.GDT_Unknown) + * stream_basename = os.path.basename( # <<<<<<<<<<<<<< + * os.path.splitext(target_stream_vector_path)[0]) + * stream_layer = stream_vector.CreateLayer( + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3111, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_path); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3111, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_basename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3111, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3112 + * target_stream_vector_path, 0, 0, 0, gdal.GDT_Unknown) + * stream_basename = os.path.basename( + * os.path.splitext(target_stream_vector_path)[0]) # <<<<<<<<<<<<<< + * stream_layer = stream_vector.CreateLayer( + * stream_basename, flow_dir_srs, ogr.wkbLineString) + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_os); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3112, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_path); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3112, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_splitext); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3112, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_2, __pyx_v_target_stream_vector_path) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_target_stream_vector_path); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3112, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_7, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3112, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_7, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3111, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_stream_basename = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3113 + * stream_basename = os.path.basename( + * os.path.splitext(target_stream_vector_path)[0]) + * stream_layer = stream_vector.CreateLayer( # <<<<<<<<<<<<<< + * stream_basename, flow_dir_srs, ogr.wkbLineString) + * stream_layer.CreateField(ogr.FieldDefn('order', ogr.OFTInteger)) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_vector, __pyx_n_s_CreateLayer); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3113, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + + /* "pygeoprocessing/routing/routing.pyx":3114 + * os.path.splitext(target_stream_vector_path)[0]) + * stream_layer = stream_vector.CreateLayer( + * stream_basename, flow_dir_srs, ogr.wkbLineString) # <<<<<<<<<<<<<< + * stream_layer.CreateField(ogr.FieldDefn('order', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('drop_distance', ogr.OFTReal)) + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ogr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3114, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_wkbLineString); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3114, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + __pyx_t_6 = 0; + 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); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_stream_basename, __pyx_v_flow_dir_srs, __pyx_t_7}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3113, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 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_3)) { + PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_stream_basename, __pyx_v_flow_dir_srs, __pyx_t_7}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3113, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_2 = PyTuple_New(3+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3113, __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_INCREF(__pyx_v_stream_basename); + __Pyx_GIVEREF(__pyx_v_stream_basename); + PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_6, __pyx_v_stream_basename); + __Pyx_INCREF(__pyx_v_flow_dir_srs); + __Pyx_GIVEREF(__pyx_v_flow_dir_srs); + PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_6, __pyx_v_flow_dir_srs); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_2, 2+__pyx_t_6, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3113, __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_stream_layer = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3115 + * stream_layer = stream_vector.CreateLayer( + * stream_basename, flow_dir_srs, ogr.wkbLineString) + * stream_layer.CreateField(ogr.FieldDefn('order', ogr.OFTInteger)) # <<<<<<<<<<<<<< + * stream_layer.CreateField(ogr.FieldDefn('drop_distance', ogr.OFTReal)) + * stream_layer.CreateField(ogr.FieldDefn('outlet', ogr.OFTInteger)) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3115, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3115, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3115, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3115, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3115, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(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); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_order, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3115, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_order, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3115, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + { + __pyx_t_9 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3115, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_n_u_order); + __Pyx_GIVEREF(__pyx_n_u_order); + PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_6, __pyx_n_u_order); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_6, __pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3115, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __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); + } + } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3115, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3116 + * stream_basename, flow_dir_srs, ogr.wkbLineString) + * stream_layer.CreateField(ogr.FieldDefn('order', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('drop_distance', ogr.OFTReal)) # <<<<<<<<<<<<<< + * stream_layer.CreateField(ogr.FieldDefn('outlet', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('river_id', ogr.OFTInteger)) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3116, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ogr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3116, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3116, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ogr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3116, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OFTReal); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3116, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_drop_distance, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3116, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_drop_distance, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3116, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3116, __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_n_u_drop_distance); + __Pyx_GIVEREF(__pyx_n_u_drop_distance); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_n_u_drop_distance); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3116, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_9, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3116, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3117 + * stream_layer.CreateField(ogr.FieldDefn('order', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('drop_distance', ogr.OFTReal)) + * stream_layer.CreateField(ogr.FieldDefn('outlet', ogr.OFTInteger)) # <<<<<<<<<<<<<< + * stream_layer.CreateField(ogr.FieldDefn('river_id', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('us_fa', ogr.OFTInteger64)) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3117, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_ogr); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3117, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3117, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_ogr); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3117, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3117, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_outlet, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3117, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_outlet, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3117, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + { + __pyx_t_4 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3117, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (__pyx_t_9) { + __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_9); __pyx_t_9 = NULL; + } + __Pyx_INCREF(__pyx_n_u_outlet); + __Pyx_GIVEREF(__pyx_n_u_outlet); + PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_6, __pyx_n_u_outlet); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_6, __pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3117, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_7, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3117, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3118 + * stream_layer.CreateField(ogr.FieldDefn('drop_distance', ogr.OFTReal)) + * stream_layer.CreateField(ogr.FieldDefn('outlet', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('river_id', ogr.OFTInteger)) # <<<<<<<<<<<<<< + * stream_layer.CreateField(ogr.FieldDefn('us_fa', ogr.OFTInteger64)) + * stream_layer.CreateField(ogr.FieldDefn('ds_fa', ogr.OFTInteger64)) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3118, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3118, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3118, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3118, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3118, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(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); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_river_id, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3118, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_river_id, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3118, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + { + __pyx_t_9 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3118, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_n_u_river_id); + __Pyx_GIVEREF(__pyx_n_u_river_id); + PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_6, __pyx_n_u_river_id); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_6, __pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3118, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __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); + } + } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3118, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3119 + * stream_layer.CreateField(ogr.FieldDefn('outlet', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('river_id', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('us_fa', ogr.OFTInteger64)) # <<<<<<<<<<<<<< + * stream_layer.CreateField(ogr.FieldDefn('ds_fa', ogr.OFTInteger64)) + * stream_layer.CreateField(ogr.FieldDefn('thresh_fa', ogr.OFTInteger64)) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3119, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ogr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3119, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3119, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ogr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3119, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OFTInteger64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3119, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_us_fa, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3119, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_us_fa, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3119, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3119, __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_n_u_us_fa); + __Pyx_GIVEREF(__pyx_n_u_us_fa); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_n_u_us_fa); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3119, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_9, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3119, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3120 + * stream_layer.CreateField(ogr.FieldDefn('river_id', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('us_fa', ogr.OFTInteger64)) + * stream_layer.CreateField(ogr.FieldDefn('ds_fa', ogr.OFTInteger64)) # <<<<<<<<<<<<<< + * stream_layer.CreateField(ogr.FieldDefn('thresh_fa', ogr.OFTInteger64)) + * stream_layer.CreateField(ogr.FieldDefn('upstream_d8_dir', ogr.OFTInteger)) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3120, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_ogr); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3120, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3120, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_ogr); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3120, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_OFTInteger64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3120, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_ds_fa, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3120, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_ds_fa, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3120, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + { + __pyx_t_4 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3120, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (__pyx_t_9) { + __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_9); __pyx_t_9 = NULL; + } + __Pyx_INCREF(__pyx_n_u_ds_fa); + __Pyx_GIVEREF(__pyx_n_u_ds_fa); + PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_6, __pyx_n_u_ds_fa); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_6, __pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3120, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_7, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3120, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3121 + * stream_layer.CreateField(ogr.FieldDefn('us_fa', ogr.OFTInteger64)) + * stream_layer.CreateField(ogr.FieldDefn('ds_fa', ogr.OFTInteger64)) + * stream_layer.CreateField(ogr.FieldDefn('thresh_fa', ogr.OFTInteger64)) # <<<<<<<<<<<<<< + * stream_layer.CreateField(ogr.FieldDefn('upstream_d8_dir', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('ds_x', ogr.OFTInteger)) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3121, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3121, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3121, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3121, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OFTInteger64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3121, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(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); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_thresh_fa, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3121, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_thresh_fa, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3121, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + { + __pyx_t_9 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3121, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_n_u_thresh_fa); + __Pyx_GIVEREF(__pyx_n_u_thresh_fa); + PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_6, __pyx_n_u_thresh_fa); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_6, __pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3121, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __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); + } + } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3121, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3122 + * stream_layer.CreateField(ogr.FieldDefn('ds_fa', ogr.OFTInteger64)) + * stream_layer.CreateField(ogr.FieldDefn('thresh_fa', ogr.OFTInteger64)) + * stream_layer.CreateField(ogr.FieldDefn('upstream_d8_dir', ogr.OFTInteger)) # <<<<<<<<<<<<<< + * stream_layer.CreateField(ogr.FieldDefn('ds_x', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('ds_y', ogr.OFTInteger)) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3122, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ogr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3122, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3122, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ogr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3122, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3122, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_upstream_d8_dir, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3122, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_upstream_d8_dir, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3122, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3122, __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_n_u_upstream_d8_dir); + __Pyx_GIVEREF(__pyx_n_u_upstream_d8_dir); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_n_u_upstream_d8_dir); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3122, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_9, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3122, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3123 + * stream_layer.CreateField(ogr.FieldDefn('thresh_fa', ogr.OFTInteger64)) + * stream_layer.CreateField(ogr.FieldDefn('upstream_d8_dir', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('ds_x', ogr.OFTInteger)) # <<<<<<<<<<<<<< + * stream_layer.CreateField(ogr.FieldDefn('ds_y', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('ds_x_1', ogr.OFTInteger)) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3123, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_ogr); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3123, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3123, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_ogr); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3123, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3123, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_ds_x, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3123, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_ds_x, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3123, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + { + __pyx_t_4 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3123, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (__pyx_t_9) { + __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_9); __pyx_t_9 = NULL; + } + __Pyx_INCREF(__pyx_n_u_ds_x); + __Pyx_GIVEREF(__pyx_n_u_ds_x); + PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_6, __pyx_n_u_ds_x); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_6, __pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3123, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_7, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3123, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3124 + * stream_layer.CreateField(ogr.FieldDefn('upstream_d8_dir', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('ds_x', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('ds_y', ogr.OFTInteger)) # <<<<<<<<<<<<<< + * stream_layer.CreateField(ogr.FieldDefn('ds_x_1', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('ds_y_1', ogr.OFTInteger)) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3124, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3124, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3124, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3124, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3124, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(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); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_ds_y, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3124, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_ds_y, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3124, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + { + __pyx_t_9 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3124, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_n_u_ds_y); + __Pyx_GIVEREF(__pyx_n_u_ds_y); + PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_6, __pyx_n_u_ds_y); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_6, __pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3124, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __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); + } + } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3124, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3125 + * stream_layer.CreateField(ogr.FieldDefn('ds_x', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('ds_y', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('ds_x_1', ogr.OFTInteger)) # <<<<<<<<<<<<<< + * stream_layer.CreateField(ogr.FieldDefn('ds_y_1', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('us_x', ogr.OFTInteger)) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3125, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ogr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3125, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3125, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ogr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3125, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3125, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_ds_x_1, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3125, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_ds_x_1, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3125, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3125, __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_n_u_ds_x_1); + __Pyx_GIVEREF(__pyx_n_u_ds_x_1); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_n_u_ds_x_1); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3125, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_9, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3125, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3126 + * stream_layer.CreateField(ogr.FieldDefn('ds_y', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('ds_x_1', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('ds_y_1', ogr.OFTInteger)) # <<<<<<<<<<<<<< + * stream_layer.CreateField(ogr.FieldDefn('us_x', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('us_y', ogr.OFTInteger)) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3126, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_ogr); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3126, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3126, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_ogr); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3126, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3126, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_ds_y_1, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3126, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_ds_y_1, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3126, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + { + __pyx_t_4 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3126, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (__pyx_t_9) { + __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_9); __pyx_t_9 = NULL; + } + __Pyx_INCREF(__pyx_n_u_ds_y_1); + __Pyx_GIVEREF(__pyx_n_u_ds_y_1); + PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_6, __pyx_n_u_ds_y_1); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_6, __pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3126, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_7, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3126, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3127 + * stream_layer.CreateField(ogr.FieldDefn('ds_x_1', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('ds_y_1', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('us_x', ogr.OFTInteger)) # <<<<<<<<<<<<<< + * stream_layer.CreateField(ogr.FieldDefn('us_y', ogr.OFTInteger)) + * flow_dir_managed_raster = _ManagedRaster( + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3127, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3127, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3127, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3127, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3127, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(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); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_us_x, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3127, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_us_x, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3127, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + { + __pyx_t_9 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3127, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_n_u_us_x); + __Pyx_GIVEREF(__pyx_n_u_us_x); + PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_6, __pyx_n_u_us_x); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_6, __pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3127, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __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); + } + } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3127, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3128 + * stream_layer.CreateField(ogr.FieldDefn('ds_y_1', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('us_x', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('us_y', ogr.OFTInteger)) # <<<<<<<<<<<<<< + * flow_dir_managed_raster = _ManagedRaster( + * flow_dir_d8_raster_path_band[0], flow_dir_d8_raster_path_band[1], 0) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3128, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ogr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3128, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3128, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ogr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3128, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3128, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_us_y, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3128, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_us_y, __pyx_t_8}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3128, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3128, __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_n_u_us_y); + __Pyx_GIVEREF(__pyx_n_u_us_y); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_n_u_us_y); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3128, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_9, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3128, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3130 + * stream_layer.CreateField(ogr.FieldDefn('us_y', ogr.OFTInteger)) + * flow_dir_managed_raster = _ManagedRaster( + * flow_dir_d8_raster_path_band[0], flow_dir_d8_raster_path_band[1], 0) # <<<<<<<<<<<<<< + * + * flow_accum_managed_raster = _ManagedRaster( + */ + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3130, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3130, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + + /* "pygeoprocessing/routing/routing.pyx":3129 + * stream_layer.CreateField(ogr.FieldDefn('us_x', ogr.OFTInteger)) + * stream_layer.CreateField(ogr.FieldDefn('us_y', ogr.OFTInteger)) + * flow_dir_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band[0], flow_dir_d8_raster_path_band[1], 0) + * + */ + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3129, __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_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_int_0); + __pyx_t_1 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3129, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_flow_dir_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3133 + * + * flow_accum_managed_raster = _ManagedRaster( + * flow_accum_raster_path_band[0], flow_accum_raster_path_band[1], 0) # <<<<<<<<<<<<<< + * + * dem_managed_raster = _ManagedRaster( + */ + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_flow_accum_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3133, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_flow_accum_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3133, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + + /* "pygeoprocessing/routing/routing.pyx":3132 + * flow_dir_d8_raster_path_band[0], flow_dir_d8_raster_path_band[1], 0) + * + * flow_accum_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< + * flow_accum_raster_path_band[0], flow_accum_raster_path_band[1], 0) + * + */ + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3132, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); + __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_3 = 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, 3132, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_flow_accum_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3136 + * + * dem_managed_raster = _ManagedRaster( + * dem_raster_path_band[0], dem_raster_path_band[1], 0) # <<<<<<<<<<<<<< + * + * cdef int flow_nodata = pygeoprocessing.get_raster_info( + */ + __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, 3136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":3135 + * flow_accum_raster_path_band[0], flow_accum_raster_path_band[1], 0) + * + * dem_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< + * dem_raster_path_band[0], dem_raster_path_band[1], 0) + * + */ + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3135, __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_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_3, 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_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3135, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_dem_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3138 + * dem_raster_path_band[0], dem_raster_path_band[1], 0) + * + * cdef int flow_nodata = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band[0])['nodata'][ + * flow_dir_d8_raster_path_band[1]-1] + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3138, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3138, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3139 + * + * cdef int flow_nodata = pygeoprocessing.get_raster_info( + * flow_dir_d8_raster_path_band[0])['nodata'][ # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band[1]-1] + * + */ + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3139, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(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); + } + } + __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_9, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3138, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_t_1, __pyx_n_u_nodata); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3139, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3140 + * cdef int flow_nodata = pygeoprocessing.get_raster_info( + * flow_dir_d8_raster_path_band[0])['nodata'][ + * flow_dir_d8_raster_path_band[1]-1] # <<<<<<<<<<<<<< + * + * # D8 flow directions encoded as + */ + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3140, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyInt_SubtractObjC(__pyx_t_1, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3140, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3139 + * + * cdef int flow_nodata = pygeoprocessing.get_raster_info( + * flow_dir_d8_raster_path_band[0])['nodata'][ # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band[1]-1] + * + */ + __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3139, __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_t_6 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3139, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_flow_nodata = __pyx_t_6; + + /* "pygeoprocessing/routing/routing.pyx":3149 + * cdef int win_xsize, win_ysize + * + * n_cols, n_rows = flow_dir_info['raster_size'] # <<<<<<<<<<<<<< + * + * LOGGER.info('(extract_strahler_streams_d8): seed the drains') + */ + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3149, __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, 3149, __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, 3149, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3149, __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_9 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3149, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext; + index = 0; __pyx_t_3 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_3)) goto __pyx_L4_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + index = 1; __pyx_t_2 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 2) < 0) __PYX_ERR(0, 3149, __pyx_L1_error) + __pyx_t_10 = NULL; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L5_unpacking_done; + __pyx_L4_unpacking_failed:; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_10 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 3149, __pyx_L1_error) + __pyx_L5_unpacking_done:; + } + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3149, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3149, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_n_cols = __pyx_t_6; + __pyx_v_n_rows = __pyx_t_11; + + /* "pygeoprocessing/routing/routing.pyx":3151 + * n_cols, n_rows = flow_dir_info['raster_size'] + * + * LOGGER.info('(extract_strahler_streams_d8): seed the drains') # <<<<<<<<<<<<<< + * cdef long n_pixels = n_cols * n_rows + * cdef long n_processed = 0 + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3151, __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, 3151, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + 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_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_kp_u_extract_strahler_streams_d8_see) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_extract_strahler_streams_d8_see); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3151, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3152 + * + * LOGGER.info('(extract_strahler_streams_d8): seed the drains') + * cdef long n_pixels = n_cols * n_rows # <<<<<<<<<<<<<< + * cdef long n_processed = 0 + * cdef time_t last_log_time + */ + __pyx_v_n_pixels = (__pyx_v_n_cols * __pyx_v_n_rows); + + /* "pygeoprocessing/routing/routing.pyx":3153 + * LOGGER.info('(extract_strahler_streams_d8): seed the drains') + * cdef long n_pixels = n_cols * n_rows + * cdef long n_processed = 0 # <<<<<<<<<<<<<< + * cdef time_t last_log_time + * last_log_time = ctime(NULL) + */ + __pyx_v_n_processed = 0; + + /* "pygeoprocessing/routing/routing.pyx":3155 + * cdef long n_processed = 0 + * cdef time_t last_log_time + * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< + * cdef stack[StreamConnectivityPoint] source_point_stack + * cdef StreamConnectivityPoint source_stream_point + */ + __pyx_v_last_log_time = time(NULL); + + /* "pygeoprocessing/routing/routing.pyx":3159 + * cdef StreamConnectivityPoint source_stream_point + * + * cdef int x_l=-1, y_l=-1 # the _l is for "local" aka "current" pixel # <<<<<<<<<<<<<< + * + * # D8 backflow directions encoded as + */ + __pyx_v_x_l = -1; + __pyx_v_y_l = -1; + + /* "pygeoprocessing/routing/routing.pyx":3166 + * # 123 + * cdef int x_n, y_n # the _n is for "neighbor" + * cdef int upstream_count=0, upstream_index # <<<<<<<<<<<<<< + * # this array is filled out as upstream directions are calculated and + * # indexed by `upstream_count` + */ + __pyx_v_upstream_count = 0; + + /* "pygeoprocessing/routing/routing.pyx":3169 + * # this array is filled out as upstream directions are calculated and + * # indexed by `upstream_count` + * cdef int *upstream_dirs = [0, 0, 0, 0, 0, 0, 0, 0] # <<<<<<<<<<<<<< + * cdef long local_flow_accum + * # used to determine if source is a drain and should be tracked + */ + __pyx_t_12[0] = 0; + __pyx_t_12[1] = 0; + __pyx_t_12[2] = 0; + __pyx_t_12[3] = 0; + __pyx_t_12[4] = 0; + __pyx_t_12[5] = 0; + __pyx_t_12[6] = 0; + __pyx_t_12[7] = 0; + __pyx_v_upstream_dirs = __pyx_t_12; + + /* "pygeoprocessing/routing/routing.pyx":3176 + * # map x/y tuple to list of streams originating from that point + * # 2 tuple -> list of int + * coord_to_stream_ids = collections.defaultdict(list) # <<<<<<<<<<<<<< + * + * # First pass - search for bifurcating stream points + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_collections); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3176, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3176, __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 && 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); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, ((PyObject *)(&PyList_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)(&PyList_Type))); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3176, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_coord_to_stream_ids = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3185 + * # * drains to edge or nodata pixel + * # record a seed point for that bifurcation for later processing. + * stream_layer.StartTransaction() # <<<<<<<<<<<<<< + * for offset_dict in pygeoprocessing.iterblocks( + * flow_dir_d8_raster_path_band, offset_only=True): + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_StartTransaction); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3185, __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); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3185, __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":3186 + * # record a seed point for that bifurcation for later processing. + * stream_layer.StartTransaction() + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band, offset_only=True): + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3186, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3186, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3187 + * stream_layer.StartTransaction() + * for offset_dict in pygeoprocessing.iterblocks( + * flow_dir_d8_raster_path_band, offset_only=True): # <<<<<<<<<<<<<< + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: + * LOGGER.info( + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3186, __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_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3187, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 3187, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3186 + * # record a seed point for that bifurcation for later processing. + * stream_layer.StartTransaction() + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band, offset_only=True): + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: + */ + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3186, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (likely(PyList_CheckExact(__pyx_t_9)) || PyTuple_CheckExact(__pyx_t_9)) { + __pyx_t_3 = __pyx_t_9; __Pyx_INCREF(__pyx_t_3); __pyx_t_13 = 0; + __pyx_t_14 = NULL; + } else { + __pyx_t_13 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3186, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_14 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 3186, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + for (;;) { + if (likely(!__pyx_t_14)) { + if (likely(PyList_CheckExact(__pyx_t_3))) { + if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_9 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_13); __Pyx_INCREF(__pyx_t_9); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 3186, __pyx_L1_error) + #else + __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3186, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + #endif + } else { + if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_13); __Pyx_INCREF(__pyx_t_9); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 3186, __pyx_L1_error) + #else + __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3186, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + #endif + } + } else { + __pyx_t_9 = __pyx_t_14(__pyx_t_3); + 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, 3186, __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":3188 + * for offset_dict in pygeoprocessing.iterblocks( + * flow_dir_d8_raster_path_band, offset_only=True): + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * LOGGER.info( + * '(extract_strahler_streams_d8): drain seeding ' + */ + __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":3189 + * flow_dir_d8_raster_path_band, offset_only=True): + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: + * LOGGER.info( # <<<<<<<<<<<<<< + * '(extract_strahler_streams_d8): drain seeding ' + * f'{n_processed} of {n_pixels} pixels complete') + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3190 + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: + * LOGGER.info( + * '(extract_strahler_streams_d8): drain seeding ' # <<<<<<<<<<<<<< + * f'{n_processed} of {n_pixels} pixels complete') + * last_log_time = ctime(NULL) + */ + __pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3190, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_15 = 0; + __pyx_t_16 = 127; + __Pyx_INCREF(__pyx_kp_u_extract_strahler_streams_d8_dra); + __pyx_t_15 += 45; + __Pyx_GIVEREF(__pyx_kp_u_extract_strahler_streams_d8_dra); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_extract_strahler_streams_d8_dra); + + /* "pygeoprocessing/routing/routing.pyx":3191 + * LOGGER.info( + * '(extract_strahler_streams_d8): drain seeding ' + * f'{n_processed} of {n_pixels} pixels complete') # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * xoff = offset_dict['xoff'] + */ + __pyx_t_7 = __Pyx_PyUnicode_From_long(__pyx_v_n_processed, 0, ' ', 'd'); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3191, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_15 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_INCREF(__pyx_kp_u_of); + __pyx_t_15 += 4; + __Pyx_GIVEREF(__pyx_kp_u_of); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_of); + __pyx_t_7 = __Pyx_PyUnicode_From_long(__pyx_v_n_pixels, 0, ' ', 'd'); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3191, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_15 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_INCREF(__pyx_kp_u_pixels_complete); + __pyx_t_15 += 16; + __Pyx_GIVEREF(__pyx_kp_u_pixels_complete); + PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u_pixels_complete); + + /* "pygeoprocessing/routing/routing.pyx":3190 + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: + * LOGGER.info( + * '(extract_strahler_streams_d8): drain seeding ' # <<<<<<<<<<<<<< + * f'{n_processed} of {n_pixels} pixels complete') + * last_log_time = ctime(NULL) + */ + __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_1, 5, __pyx_t_15, __pyx_t_16); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3190, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_9 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_1, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_7); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3192 + * '(extract_strahler_streams_d8): drain seeding ' + * f'{n_processed} of {n_pixels} pixels complete') + * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< + * xoff = offset_dict['xoff'] + * yoff = offset_dict['yoff'] + */ + __pyx_v_last_log_time = time(NULL); + + /* "pygeoprocessing/routing/routing.pyx":3188 + * for offset_dict in pygeoprocessing.iterblocks( + * flow_dir_d8_raster_path_band, offset_only=True): + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * LOGGER.info( + * '(extract_strahler_streams_d8): drain seeding ' + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3193 + * f'{n_processed} of {n_pixels} pixels complete') + * last_log_time = ctime(NULL) + * xoff = offset_dict['xoff'] # <<<<<<<<<<<<<< + * yoff = offset_dict['yoff'] + * win_xsize = offset_dict['win_xsize'] + */ + __pyx_t_9 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_xoff); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3193, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3193, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_v_xoff = __pyx_t_11; + + /* "pygeoprocessing/routing/routing.pyx":3194 + * last_log_time = ctime(NULL) + * xoff = offset_dict['xoff'] + * yoff = offset_dict['yoff'] # <<<<<<<<<<<<<< + * win_xsize = offset_dict['win_xsize'] + * win_ysize = offset_dict['win_ysize'] + */ + __pyx_t_9 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_yoff); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3194, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3194, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_v_yoff = __pyx_t_11; + + /* "pygeoprocessing/routing/routing.pyx":3195 + * xoff = offset_dict['xoff'] + * yoff = offset_dict['yoff'] + * win_xsize = offset_dict['win_xsize'] # <<<<<<<<<<<<<< + * win_ysize = offset_dict['win_ysize'] + * n_processed += win_xsize * win_ysize + */ + __pyx_t_9 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3195, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3195, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_v_win_xsize = __pyx_t_11; + + /* "pygeoprocessing/routing/routing.pyx":3196 + * yoff = offset_dict['yoff'] + * win_xsize = offset_dict['win_xsize'] + * win_ysize = offset_dict['win_ysize'] # <<<<<<<<<<<<<< + * n_processed += win_xsize * win_ysize + * + */ + __pyx_t_9 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3196, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3196, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_v_win_ysize = __pyx_t_11; + + /* "pygeoprocessing/routing/routing.pyx":3197 + * win_xsize = offset_dict['win_xsize'] + * win_ysize = offset_dict['win_ysize'] + * n_processed += win_xsize * win_ysize # <<<<<<<<<<<<<< + * + * for i in range(win_xsize): + */ + __pyx_v_n_processed = (__pyx_v_n_processed + (__pyx_v_win_xsize * __pyx_v_win_ysize)); + + /* "pygeoprocessing/routing/routing.pyx":3199 + * n_processed += win_xsize * win_ysize + * + * for i in range(win_xsize): # <<<<<<<<<<<<<< + * for j in range(win_ysize): + * is_drain = 0 + */ + __pyx_t_11 = __pyx_v_win_xsize; + __pyx_t_6 = __pyx_t_11; + for (__pyx_t_17 = 0; __pyx_t_17 < __pyx_t_6; __pyx_t_17+=1) { + __pyx_v_i = __pyx_t_17; + + /* "pygeoprocessing/routing/routing.pyx":3200 + * + * for i in range(win_xsize): + * for j in range(win_ysize): # <<<<<<<<<<<<<< + * is_drain = 0 + * x_l = xoff + i + */ + __pyx_t_18 = __pyx_v_win_ysize; + __pyx_t_19 = __pyx_t_18; + for (__pyx_t_20 = 0; __pyx_t_20 < __pyx_t_19; __pyx_t_20+=1) { + __pyx_v_j = __pyx_t_20; + + /* "pygeoprocessing/routing/routing.pyx":3201 + * for i in range(win_xsize): + * for j in range(win_ysize): + * is_drain = 0 # <<<<<<<<<<<<<< + * x_l = xoff + i + * y_l = yoff + j + */ + __pyx_v_is_drain = 0; + + /* "pygeoprocessing/routing/routing.pyx":3202 + * for j in range(win_ysize): + * is_drain = 0 + * x_l = xoff + i # <<<<<<<<<<<<<< + * y_l = yoff + j + * local_flow_accum = flow_accum_managed_raster.get( + */ + __pyx_v_x_l = (__pyx_v_xoff + __pyx_v_i); + + /* "pygeoprocessing/routing/routing.pyx":3203 + * is_drain = 0 + * x_l = xoff + i + * y_l = yoff + j # <<<<<<<<<<<<<< + * local_flow_accum = flow_accum_managed_raster.get( + * x_l, y_l) + */ + __pyx_v_y_l = (__pyx_v_yoff + __pyx_v_j); + + /* "pygeoprocessing/routing/routing.pyx":3204 + * x_l = xoff + i + * y_l = yoff + j + * local_flow_accum = flow_accum_managed_raster.get( # <<<<<<<<<<<<<< + * x_l, y_l) + * if local_flow_accum < min_flow_accum_threshold: + */ + __pyx_v_local_flow_accum = ((long)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_accum_managed_raster, __pyx_v_x_l, __pyx_v_y_l)); + + /* "pygeoprocessing/routing/routing.pyx":3206 + * local_flow_accum = flow_accum_managed_raster.get( + * x_l, y_l) + * if local_flow_accum < min_flow_accum_threshold: # <<<<<<<<<<<<<< + * continue + * # check to see if it's a drain + */ + __pyx_t_5 = ((__pyx_v_local_flow_accum < __pyx_v_min_flow_accum_threshold) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":3207 + * x_l, y_l) + * if local_flow_accum < min_flow_accum_threshold: + * continue # <<<<<<<<<<<<<< + * # check to see if it's a drain + * d_n = flow_dir_managed_raster.get(x_l, y_l) + */ + goto __pyx_L11_continue; + + /* "pygeoprocessing/routing/routing.pyx":3206 + * local_flow_accum = flow_accum_managed_raster.get( + * x_l, y_l) + * if local_flow_accum < min_flow_accum_threshold: # <<<<<<<<<<<<<< + * continue + * # check to see if it's a drain + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3209 + * continue + * # check to see if it's a drain + * d_n = flow_dir_managed_raster.get(x_l, y_l) # <<<<<<<<<<<<<< + * x_n = x_l + D8_XOFFSET[d_n] + * y_n = y_l + D8_YOFFSET[d_n] + */ + __pyx_v_d_n = ((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_dir_managed_raster, __pyx_v_x_l, __pyx_v_y_l)); + + /* "pygeoprocessing/routing/routing.pyx":3210 + * # check to see if it's a drain + * d_n = flow_dir_managed_raster.get(x_l, y_l) + * x_n = x_l + D8_XOFFSET[d_n] # <<<<<<<<<<<<<< + * y_n = y_l + D8_YOFFSET[d_n] + * + */ + __pyx_v_x_n = (__pyx_v_x_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_d_n])); + + /* "pygeoprocessing/routing/routing.pyx":3211 + * d_n = flow_dir_managed_raster.get(x_l, y_l) + * x_n = x_l + D8_XOFFSET[d_n] + * y_n = y_l + D8_YOFFSET[d_n] # <<<<<<<<<<<<<< + * + * if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_cols or + */ + __pyx_v_y_n = (__pyx_v_y_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_d_n])); + + /* "pygeoprocessing/routing/routing.pyx":3213 + * y_n = y_l + D8_YOFFSET[d_n] + * + * if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_cols or # <<<<<<<<<<<<<< + * flow_dir_managed_raster.get( + * x_n, y_n) == flow_nodata): + */ + __pyx_t_21 = ((__pyx_v_x_n < 0) != 0); + if (!__pyx_t_21) { + } else { + __pyx_t_5 = __pyx_t_21; + goto __pyx_L15_bool_binop_done; + } + __pyx_t_21 = ((__pyx_v_y_n < 0) != 0); + if (!__pyx_t_21) { + } else { + __pyx_t_5 = __pyx_t_21; + goto __pyx_L15_bool_binop_done; + } + __pyx_t_21 = ((__pyx_v_x_n >= __pyx_v_n_cols) != 0); + if (!__pyx_t_21) { + } else { + __pyx_t_5 = __pyx_t_21; + goto __pyx_L15_bool_binop_done; + } + __pyx_t_21 = ((__pyx_v_y_n >= __pyx_v_n_cols) != 0); + if (!__pyx_t_21) { + } else { + __pyx_t_5 = __pyx_t_21; + goto __pyx_L15_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":3215 + * if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_cols or + * flow_dir_managed_raster.get( + * x_n, y_n) == flow_nodata): # <<<<<<<<<<<<<< + * is_drain = 1 + * + */ + __pyx_t_21 = ((((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_dir_managed_raster, __pyx_v_x_n, __pyx_v_y_n)) == __pyx_v_flow_nodata) != 0); + __pyx_t_5 = __pyx_t_21; + __pyx_L15_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":3213 + * y_n = y_l + D8_YOFFSET[d_n] + * + * if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_cols or # <<<<<<<<<<<<<< + * flow_dir_managed_raster.get( + * x_n, y_n) == flow_nodata): + */ + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":3216 + * flow_dir_managed_raster.get( + * x_n, y_n) == flow_nodata): + * is_drain = 1 # <<<<<<<<<<<<<< + * + * if not is_drain and ( + */ + __pyx_v_is_drain = 1; + + /* "pygeoprocessing/routing/routing.pyx":3213 + * y_n = y_l + D8_YOFFSET[d_n] + * + * if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_cols or # <<<<<<<<<<<<<< + * flow_dir_managed_raster.get( + * x_n, y_n) == flow_nodata): + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3218 + * is_drain = 1 + * + * if not is_drain and ( # <<<<<<<<<<<<<< + * local_flow_accum < 2*min_flow_accum_threshold): + * # if current pixel is < 2*flow threshold then it can't + */ + __pyx_t_21 = ((!(__pyx_v_is_drain != 0)) != 0); + if (__pyx_t_21) { + } else { + __pyx_t_5 = __pyx_t_21; + goto __pyx_L21_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":3219 + * + * if not is_drain and ( + * local_flow_accum < 2*min_flow_accum_threshold): # <<<<<<<<<<<<<< + * # if current pixel is < 2*flow threshold then it can't + * # bifurcate into two pixels == flow threshold + */ + __pyx_t_21 = ((__pyx_v_local_flow_accum < (2 * __pyx_v_min_flow_accum_threshold)) != 0); + __pyx_t_5 = __pyx_t_21; + __pyx_L21_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":3218 + * is_drain = 1 + * + * if not is_drain and ( # <<<<<<<<<<<<<< + * local_flow_accum < 2*min_flow_accum_threshold): + * # if current pixel is < 2*flow threshold then it can't + */ + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":3222 + * # if current pixel is < 2*flow threshold then it can't + * # bifurcate into two pixels == flow threshold + * continue # <<<<<<<<<<<<<< + * + * upstream_count = 0 + */ + goto __pyx_L11_continue; + + /* "pygeoprocessing/routing/routing.pyx":3218 + * is_drain = 1 + * + * if not is_drain and ( # <<<<<<<<<<<<<< + * local_flow_accum < 2*min_flow_accum_threshold): + * # if current pixel is < 2*flow threshold then it can't + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3224 + * continue + * + * upstream_count = 0 # <<<<<<<<<<<<<< + * for d in range(8): + * x_n = x_l + D8_XOFFSET[d] + */ + __pyx_v_upstream_count = 0; + + /* "pygeoprocessing/routing/routing.pyx":3225 + * + * upstream_count = 0 + * for d in range(8): # <<<<<<<<<<<<<< + * x_n = x_l + D8_XOFFSET[d] + * y_n = y_l + D8_YOFFSET[d] + */ + for (__pyx_t_22 = 0; __pyx_t_22 < 8; __pyx_t_22+=1) { + __pyx_v_d = __pyx_t_22; + + /* "pygeoprocessing/routing/routing.pyx":3226 + * upstream_count = 0 + * for d in range(8): + * x_n = x_l + D8_XOFFSET[d] # <<<<<<<<<<<<<< + * y_n = y_l + D8_YOFFSET[d] + * # check if on border + */ + __pyx_v_x_n = (__pyx_v_x_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_d])); + + /* "pygeoprocessing/routing/routing.pyx":3227 + * for d in range(8): + * x_n = x_l + D8_XOFFSET[d] + * y_n = y_l + D8_YOFFSET[d] # <<<<<<<<<<<<<< + * # check if on border + * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: + */ + __pyx_v_y_n = (__pyx_v_y_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_d])); + + /* "pygeoprocessing/routing/routing.pyx":3229 + * y_n = y_l + D8_YOFFSET[d] + * # check if on border + * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: # <<<<<<<<<<<<<< + * continue + * d_n = flow_dir_managed_raster.get(x_n, y_n) + */ + __pyx_t_21 = ((__pyx_v_x_n < 0) != 0); + if (!__pyx_t_21) { + } else { + __pyx_t_5 = __pyx_t_21; + goto __pyx_L26_bool_binop_done; + } + __pyx_t_21 = ((__pyx_v_y_n < 0) != 0); + if (!__pyx_t_21) { + } else { + __pyx_t_5 = __pyx_t_21; + goto __pyx_L26_bool_binop_done; + } + __pyx_t_21 = ((__pyx_v_x_n >= __pyx_v_n_cols) != 0); + if (!__pyx_t_21) { + } else { + __pyx_t_5 = __pyx_t_21; + goto __pyx_L26_bool_binop_done; + } + __pyx_t_21 = ((__pyx_v_y_n >= __pyx_v_n_rows) != 0); + __pyx_t_5 = __pyx_t_21; + __pyx_L26_bool_binop_done:; + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":3230 + * # check if on border + * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: + * continue # <<<<<<<<<<<<<< + * d_n = flow_dir_managed_raster.get(x_n, y_n) + * if d_n == flow_nodata: + */ + goto __pyx_L23_continue; + + /* "pygeoprocessing/routing/routing.pyx":3229 + * y_n = y_l + D8_YOFFSET[d] + * # check if on border + * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: # <<<<<<<<<<<<<< + * continue + * d_n = flow_dir_managed_raster.get(x_n, y_n) + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3231 + * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: + * continue + * d_n = flow_dir_managed_raster.get(x_n, y_n) # <<<<<<<<<<<<<< + * if d_n == flow_nodata: + * continue + */ + __pyx_v_d_n = ((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_dir_managed_raster, __pyx_v_x_n, __pyx_v_y_n)); + + /* "pygeoprocessing/routing/routing.pyx":3232 + * continue + * d_n = flow_dir_managed_raster.get(x_n, y_n) + * if d_n == flow_nodata: # <<<<<<<<<<<<<< + * continue + * if (D8_REVERSE_DIRECTION[d] == d_n and + */ + __pyx_t_5 = ((__pyx_v_d_n == __pyx_v_flow_nodata) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":3233 + * d_n = flow_dir_managed_raster.get(x_n, y_n) + * if d_n == flow_nodata: + * continue # <<<<<<<<<<<<<< + * if (D8_REVERSE_DIRECTION[d] == d_n and + * flow_accum_managed_raster.get( + */ + goto __pyx_L23_continue; + + /* "pygeoprocessing/routing/routing.pyx":3232 + * continue + * d_n = flow_dir_managed_raster.get(x_n, y_n) + * if d_n == flow_nodata: # <<<<<<<<<<<<<< + * continue + * if (D8_REVERSE_DIRECTION[d] == d_n and + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3234 + * if d_n == flow_nodata: + * continue + * if (D8_REVERSE_DIRECTION[d] == d_n and # <<<<<<<<<<<<<< + * flow_accum_managed_raster.get( + * x_n, y_n) >= min_flow_accum_threshold): + */ + __pyx_t_21 = (((__pyx_v_15pygeoprocessing_7routing_7routing_D8_REVERSE_DIRECTION[__pyx_v_d]) == __pyx_v_d_n) != 0); + if (__pyx_t_21) { + } else { + __pyx_t_5 = __pyx_t_21; + goto __pyx_L32_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":3236 + * if (D8_REVERSE_DIRECTION[d] == d_n and + * flow_accum_managed_raster.get( + * x_n, y_n) >= min_flow_accum_threshold): # <<<<<<<<<<<<<< + * upstream_dirs[upstream_count] = d + * upstream_count += 1 + */ + __pyx_t_21 = ((((long)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_accum_managed_raster, __pyx_v_x_n, __pyx_v_y_n)) >= __pyx_v_min_flow_accum_threshold) != 0); + __pyx_t_5 = __pyx_t_21; + __pyx_L32_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":3234 + * if d_n == flow_nodata: + * continue + * if (D8_REVERSE_DIRECTION[d] == d_n and # <<<<<<<<<<<<<< + * flow_accum_managed_raster.get( + * x_n, y_n) >= min_flow_accum_threshold): + */ + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":3237 + * flow_accum_managed_raster.get( + * x_n, y_n) >= min_flow_accum_threshold): + * upstream_dirs[upstream_count] = d # <<<<<<<<<<<<<< + * upstream_count += 1 + * if upstream_count <= 1 and not is_drain: + */ + (__pyx_v_upstream_dirs[__pyx_v_upstream_count]) = __pyx_v_d; + + /* "pygeoprocessing/routing/routing.pyx":3238 + * x_n, y_n) >= min_flow_accum_threshold): + * upstream_dirs[upstream_count] = d + * upstream_count += 1 # <<<<<<<<<<<<<< + * if upstream_count <= 1 and not is_drain: + * continue + */ + __pyx_v_upstream_count = (__pyx_v_upstream_count + 1); + + /* "pygeoprocessing/routing/routing.pyx":3234 + * if d_n == flow_nodata: + * continue + * if (D8_REVERSE_DIRECTION[d] == d_n and # <<<<<<<<<<<<<< + * flow_accum_managed_raster.get( + * x_n, y_n) >= min_flow_accum_threshold): + */ + } + __pyx_L23_continue:; + } + + /* "pygeoprocessing/routing/routing.pyx":3239 + * upstream_dirs[upstream_count] = d + * upstream_count += 1 + * if upstream_count <= 1 and not is_drain: # <<<<<<<<<<<<<< + * continue + * for upstream_index in range(upstream_count): + */ + __pyx_t_21 = ((__pyx_v_upstream_count <= 1) != 0); + if (__pyx_t_21) { + } else { + __pyx_t_5 = __pyx_t_21; + goto __pyx_L35_bool_binop_done; + } + __pyx_t_21 = ((!(__pyx_v_is_drain != 0)) != 0); + __pyx_t_5 = __pyx_t_21; + __pyx_L35_bool_binop_done:; + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":3240 + * upstream_count += 1 + * if upstream_count <= 1 and not is_drain: + * continue # <<<<<<<<<<<<<< + * for upstream_index in range(upstream_count): + * # hit a branch! + */ + goto __pyx_L11_continue; + + /* "pygeoprocessing/routing/routing.pyx":3239 + * upstream_dirs[upstream_count] = d + * upstream_count += 1 + * if upstream_count <= 1 and not is_drain: # <<<<<<<<<<<<<< + * continue + * for upstream_index in range(upstream_count): + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3241 + * if upstream_count <= 1 and not is_drain: + * continue + * for upstream_index in range(upstream_count): # <<<<<<<<<<<<<< + * # hit a branch! + * stream_feature = ogr.Feature( + */ + __pyx_t_22 = __pyx_v_upstream_count; + __pyx_t_23 = __pyx_t_22; + for (__pyx_t_24 = 0; __pyx_t_24 < __pyx_t_23; __pyx_t_24+=1) { + __pyx_v_upstream_index = __pyx_t_24; + + /* "pygeoprocessing/routing/routing.pyx":3243 + * for upstream_index in range(upstream_count): + * # hit a branch! + * stream_feature = ogr.Feature( # <<<<<<<<<<<<<< + * stream_layer.GetLayerDefn()) + * stream_feature.SetField('outlet', 0) + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_ogr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3243, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_Feature); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3243, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3244 + * # hit a branch! + * stream_feature = ogr.Feature( + * stream_layer.GetLayerDefn()) # <<<<<<<<<<<<<< + * stream_feature.SetField('outlet', 0) + * stream_layer.CreateFeature(stream_feature) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_GetLayerDefn); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3244, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_2 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3244, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_9 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_1, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3243, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF_SET(__pyx_v_stream_feature, __pyx_t_9); + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3245 + * stream_feature = ogr.Feature( + * stream_layer.GetLayerDefn()) + * stream_feature.SetField('outlet', 0) # <<<<<<<<<<<<<< + * stream_layer.CreateFeature(stream_feature) + * stream_fid = stream_feature.GetFID() + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3245, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3245, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3246 + * stream_layer.GetLayerDefn()) + * stream_feature.SetField('outlet', 0) + * stream_layer.CreateFeature(stream_feature) # <<<<<<<<<<<<<< + * stream_fid = stream_feature.GetFID() + * source_point_stack.push(StreamConnectivityPoint( + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateFeature); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3246, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_7 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_2, __pyx_v_stream_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_stream_feature); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3246, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3247 + * stream_feature.SetField('outlet', 0) + * stream_layer.CreateFeature(stream_feature) + * stream_fid = stream_feature.GetFID() # <<<<<<<<<<<<<< + * source_point_stack.push(StreamConnectivityPoint( + * x_l, y_l, upstream_dirs[upstream_index], stream_fid)) + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetFID); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3247, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_7 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3247, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_XDECREF_SET(__pyx_v_stream_fid, __pyx_t_7); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3249 + * stream_fid = stream_feature.GetFID() + * source_point_stack.push(StreamConnectivityPoint( + * x_l, y_l, upstream_dirs[upstream_index], stream_fid)) # <<<<<<<<<<<<<< + * coord_to_stream_ids[(x_l, y_l)].append(stream_fid) + * LOGGER.info( + */ + __pyx_t_25.xi = __pyx_v_x_l; + __pyx_t_25.yi = __pyx_v_y_l; + __pyx_t_25.upstream_d8_dir = (__pyx_v_upstream_dirs[__pyx_v_upstream_index]); + __pyx_t_26 = __Pyx_PyInt_As_int(__pyx_v_stream_fid); if (unlikely((__pyx_t_26 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3249, __pyx_L1_error) + __pyx_t_25.source_id = __pyx_t_26; + + /* "pygeoprocessing/routing/routing.pyx":3248 + * stream_layer.CreateFeature(stream_feature) + * stream_fid = stream_feature.GetFID() + * source_point_stack.push(StreamConnectivityPoint( # <<<<<<<<<<<<<< + * x_l, y_l, upstream_dirs[upstream_index], stream_fid)) + * coord_to_stream_ids[(x_l, y_l)].append(stream_fid) + */ + __pyx_v_source_point_stack.push(__pyx_t_25); + + /* "pygeoprocessing/routing/routing.pyx":3250 + * source_point_stack.push(StreamConnectivityPoint( + * x_l, y_l, upstream_dirs[upstream_index], stream_fid)) + * coord_to_stream_ids[(x_l, y_l)].append(stream_fid) # <<<<<<<<<<<<<< + * LOGGER.info( + * '(extract_strahler_streams_d8): ' + */ + __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_x_l); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3250, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_9 = __Pyx_PyInt_From_int(__pyx_v_y_l); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3250, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3250, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_9); + __pyx_t_7 = 0; + __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_PyObject_GetItem(__pyx_v_coord_to_stream_ids, __pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3250, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_27 = __Pyx_PyObject_Append(__pyx_t_9, __pyx_v_stream_fid); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3250, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __pyx_L11_continue:; + } + } + + /* "pygeoprocessing/routing/routing.pyx":3186 + * # record a seed point for that bifurcation for later processing. + * stream_layer.StartTransaction() + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band, offset_only=True): + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: + */ + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3251 + * x_l, y_l, upstream_dirs[upstream_index], stream_fid)) + * coord_to_stream_ids[(x_l, y_l)].append(stream_fid) + * LOGGER.info( # <<<<<<<<<<<<<< + * '(extract_strahler_streams_d8): ' + * f'drain seeding complete') + */ + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3251, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3251, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(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); + } + } + __pyx_t_3 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_9, __pyx_kp_u_extract_strahler_streams_d8_dra_2) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_kp_u_extract_strahler_streams_d8_dra_2); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3251, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3254 + * '(extract_strahler_streams_d8): ' + * f'drain seeding complete') + * LOGGER.info('(extract_strahler_streams_d8): starting upstream walk') # <<<<<<<<<<<<<< + * n_points = source_point_stack.size() + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3254, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_info); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3254, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + 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_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_2, __pyx_kp_u_extract_strahler_streams_d8_sta) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_kp_u_extract_strahler_streams_d8_sta); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3254, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3255 + * f'drain seeding complete') + * LOGGER.info('(extract_strahler_streams_d8): starting upstream walk') + * n_points = source_point_stack.size() # <<<<<<<<<<<<<< + * + * # map downstream ids to list of upstream connected streams + */ + __pyx_t_3 = __Pyx_PyInt_FromSize_t(__pyx_v_source_point_stack.size()); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3255, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_n_points = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3259 + * # map downstream ids to list of upstream connected streams + * # id -> list of ids + * downstream_to_upstream_ids = {} # <<<<<<<<<<<<<< + * + * # map upstream id to downstream connected stream id -> id + */ + __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3259, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_downstream_to_upstream_ids = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3262 + * + * # map upstream id to downstream connected stream id -> id + * upstream_to_downstream_id = {} # <<<<<<<<<<<<<< + * + * while not source_point_stack.empty(): + */ + __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3262, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_upstream_to_downstream_id = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3264 + * upstream_to_downstream_id = {} + * + * while not source_point_stack.empty(): # <<<<<<<<<<<<<< + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: + * LOGGER.info( + */ + while (1) { + __pyx_t_5 = ((!(__pyx_v_source_point_stack.empty() != 0)) != 0); + if (!__pyx_t_5) break; + + /* "pygeoprocessing/routing/routing.pyx":3265 + * + * while not source_point_stack.empty(): + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * LOGGER.info( + * '(extract_strahler_streams_d8): ' + */ + __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":3266 + * while not source_point_stack.empty(): + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: + * LOGGER.info( # <<<<<<<<<<<<<< + * '(extract_strahler_streams_d8): ' + * 'stream segment creation ' + */ + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3266, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3266, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3267 + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: + * LOGGER.info( + * '(extract_strahler_streams_d8): ' # <<<<<<<<<<<<<< + * 'stream segment creation ' + * f'{n_points-source_point_stack.size()} of {n_points} ' + */ + __pyx_t_9 = PyTuple_New(5); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3267, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_13 = 0; + __pyx_t_16 = 127; + __Pyx_INCREF(__pyx_kp_u_extract_strahler_streams_d8_str); + __pyx_t_13 += 55; + __Pyx_GIVEREF(__pyx_kp_u_extract_strahler_streams_d8_str); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_kp_u_extract_strahler_streams_d8_str); + + /* "pygeoprocessing/routing/routing.pyx":3269 + * '(extract_strahler_streams_d8): ' + * 'stream segment creation ' + * f'{n_points-source_point_stack.size()} of {n_points} ' # <<<<<<<<<<<<<< + * 'source points complete') + * last_log_time = ctime(NULL) + */ + __pyx_t_7 = __Pyx_PyInt_FromSize_t(__pyx_v_source_point_stack.size()); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3269, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = PyNumber_Subtract(__pyx_v_n_points, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3269, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_FormatSimple(__pyx_t_1, __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3269, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_16 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_16) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_16; + __pyx_t_13 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_INCREF(__pyx_kp_u_of); + __pyx_t_13 += 4; + __Pyx_GIVEREF(__pyx_kp_u_of); + PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_kp_u_of); + __pyx_t_7 = __Pyx_PyObject_FormatSimple(__pyx_v_n_points, __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3269, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_16 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_16) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_16; + __pyx_t_13 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_INCREF(__pyx_kp_u_source_points_complete); + __pyx_t_13 += 23; + __Pyx_GIVEREF(__pyx_kp_u_source_points_complete); + PyTuple_SET_ITEM(__pyx_t_9, 4, __pyx_kp_u_source_points_complete); + + /* "pygeoprocessing/routing/routing.pyx":3267 + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: + * LOGGER.info( + * '(extract_strahler_streams_d8): ' # <<<<<<<<<<<<<< + * 'stream segment creation ' + * f'{n_points-source_point_stack.size()} of {n_points} ' + */ + __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_9, 5, __pyx_t_13, __pyx_t_16); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3267, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(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); + } + } + __pyx_t_3 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_9, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_7); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3266, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3271 + * f'{n_points-source_point_stack.size()} of {n_points} ' + * 'source points complete') + * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< + * + * # This coordinate is the downstream end of the stream + */ + __pyx_v_last_log_time = time(NULL); + + /* "pygeoprocessing/routing/routing.pyx":3265 + * + * while not source_point_stack.empty(): + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * LOGGER.info( + * '(extract_strahler_streams_d8): ' + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3274 + * + * # This coordinate is the downstream end of the stream + * source_stream_point = source_point_stack.top() # <<<<<<<<<<<<<< + * source_point_stack.pop() + * + */ + __pyx_v_source_stream_point = __pyx_v_source_point_stack.top(); + + /* "pygeoprocessing/routing/routing.pyx":3275 + * # This coordinate is the downstream end of the stream + * source_stream_point = source_point_stack.top() + * source_point_stack.pop() # <<<<<<<<<<<<<< + * + * payload = _calculate_stream_geometry( + */ + __pyx_v_source_point_stack.pop(); + + /* "pygeoprocessing/routing/routing.pyx":3280 + * source_stream_point.xi, source_stream_point.yi, + * source_stream_point.upstream_d8_dir, + * flow_dir_info['geotransform'], n_cols, n_rows, # <<<<<<<<<<<<<< + * flow_accum_managed_raster, flow_dir_managed_raster, flow_nodata, + * min_flow_accum_threshold, coord_to_stream_ids) + */ + __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_geotransform); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3280, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + + /* "pygeoprocessing/routing/routing.pyx":3277 + * source_point_stack.pop() + * + * payload = _calculate_stream_geometry( # <<<<<<<<<<<<<< + * source_stream_point.xi, source_stream_point.yi, + * source_stream_point.upstream_d8_dir, + */ + __pyx_t_2 = __pyx_f_15pygeoprocessing_7routing_7routing__calculate_stream_geometry(__pyx_v_source_stream_point.xi, __pyx_v_source_stream_point.yi, __pyx_v_source_stream_point.upstream_d8_dir, __pyx_t_3, __pyx_v_n_cols, __pyx_v_n_rows, __pyx_v_flow_accum_managed_raster, __pyx_v_flow_dir_managed_raster, __pyx_v_flow_nodata, __pyx_v_min_flow_accum_threshold, __pyx_v_coord_to_stream_ids); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3277, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF_SET(__pyx_v_payload, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3283 + * flow_accum_managed_raster, flow_dir_managed_raster, flow_nodata, + * min_flow_accum_threshold, coord_to_stream_ids) + * if payload is None: # <<<<<<<<<<<<<< + * continue + * x_u, y_u, ds_x_1, ds_y_1, upstream_id_list, stream_line = payload + */ + __pyx_t_5 = (__pyx_v_payload == Py_None); + __pyx_t_21 = (__pyx_t_5 != 0); + if (__pyx_t_21) { + + /* "pygeoprocessing/routing/routing.pyx":3284 + * min_flow_accum_threshold, coord_to_stream_ids) + * if payload is None: + * continue # <<<<<<<<<<<<<< + * x_u, y_u, ds_x_1, ds_y_1, upstream_id_list, stream_line = payload + * + */ + goto __pyx_L39_continue; + + /* "pygeoprocessing/routing/routing.pyx":3283 + * flow_accum_managed_raster, flow_dir_managed_raster, flow_nodata, + * min_flow_accum_threshold, coord_to_stream_ids) + * if payload is None: # <<<<<<<<<<<<<< + * continue + * x_u, y_u, ds_x_1, ds_y_1, upstream_id_list, stream_line = payload + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3285 + * if payload is None: + * continue + * x_u, y_u, ds_x_1, ds_y_1, upstream_id_list, stream_line = payload # <<<<<<<<<<<<<< + * + * downstream_dem = dem_managed_raster.get( + */ + if ((likely(PyTuple_CheckExact(__pyx_v_payload))) || (PyList_CheckExact(__pyx_v_payload))) { + PyObject* sequence = __pyx_v_payload; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 6)) { + if (size > 6) __Pyx_RaiseTooManyValuesError(6); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 3285, __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); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_9 = PyTuple_GET_ITEM(sequence, 3); + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 4); + __pyx_t_8 = PyTuple_GET_ITEM(sequence, 5); + } else { + __pyx_t_2 = PyList_GET_ITEM(sequence, 0); + __pyx_t_3 = PyList_GET_ITEM(sequence, 1); + __pyx_t_7 = PyList_GET_ITEM(sequence, 2); + __pyx_t_9 = PyList_GET_ITEM(sequence, 3); + __pyx_t_1 = PyList_GET_ITEM(sequence, 4); + __pyx_t_8 = PyList_GET_ITEM(sequence, 5); + } + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_8); + #else + { + Py_ssize_t i; + PyObject** temps[6] = {&__pyx_t_2,&__pyx_t_3,&__pyx_t_7,&__pyx_t_9,&__pyx_t_1,&__pyx_t_8}; + for (i=0; i < 6; i++) { + PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 3285, __pyx_L1_error) + __Pyx_GOTREF(item); + *(temps[i]) = item; + } + } + #endif + } else { + Py_ssize_t index = -1; + PyObject** temps[6] = {&__pyx_t_2,&__pyx_t_3,&__pyx_t_7,&__pyx_t_9,&__pyx_t_1,&__pyx_t_8}; + __pyx_t_4 = PyObject_GetIter(__pyx_v_payload); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3285, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_10 = Py_TYPE(__pyx_t_4)->tp_iternext; + for (index=0; index < 6; index++) { + PyObject* item = __pyx_t_10(__pyx_t_4); if (unlikely(!item)) goto __pyx_L43_unpacking_failed; + __Pyx_GOTREF(item); + *(temps[index]) = item; + } + if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_4), 6) < 0) __PYX_ERR(0, 3285, __pyx_L1_error) + __pyx_t_10 = NULL; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L44_unpacking_done; + __pyx_L43_unpacking_failed:; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_10 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 3285, __pyx_L1_error) + __pyx_L44_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_x_u, __pyx_t_2); + __pyx_t_2 = 0; + __Pyx_XDECREF_SET(__pyx_v_y_u, __pyx_t_3); + __pyx_t_3 = 0; + __Pyx_XDECREF_SET(__pyx_v_ds_x_1, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_XDECREF_SET(__pyx_v_ds_y_1, __pyx_t_9); + __pyx_t_9 = 0; + __Pyx_XDECREF_SET(__pyx_v_upstream_id_list, __pyx_t_1); + __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_stream_line, __pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3287 + * x_u, y_u, ds_x_1, ds_y_1, upstream_id_list, stream_line = payload + * + * downstream_dem = dem_managed_raster.get( # <<<<<<<<<<<<<< + * source_stream_point.xi, source_stream_point.yi) + * + */ + __pyx_v_downstream_dem = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_dem_managed_raster, __pyx_v_source_stream_point.xi, __pyx_v_source_stream_point.yi); + + /* "pygeoprocessing/routing/routing.pyx":3290 + * source_stream_point.xi, source_stream_point.yi) + * + * stream_feature = stream_layer.GetFeature( # <<<<<<<<<<<<<< + * source_stream_point.source_id) + * stream_feature.SetField( + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3290, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":3291 + * + * stream_feature = stream_layer.GetFeature( + * source_stream_point.source_id) # <<<<<<<<<<<<<< + * stream_feature.SetField( + * 'ds_fa', flow_accum_managed_raster.get( + */ + __pyx_t_9 = __Pyx_PyInt_From_int(__pyx_v_source_stream_point.source_id); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3291, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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); + } + } + __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_7, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_9); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3290, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_stream_feature, __pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3292 + * stream_feature = stream_layer.GetFeature( + * source_stream_point.source_id) + * stream_feature.SetField( # <<<<<<<<<<<<<< + * 'ds_fa', flow_accum_managed_raster.get( + * source_stream_point.xi, source_stream_point.yi)) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3292, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":3293 + * source_stream_point.source_id) + * stream_feature.SetField( + * 'ds_fa', flow_accum_managed_raster.get( # <<<<<<<<<<<<<< + * source_stream_point.xi, source_stream_point.yi)) + * stream_feature.SetField('ds_x', source_stream_point.xi) + */ + __pyx_t_9 = PyFloat_FromDouble(__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_accum_managed_raster, __pyx_v_source_stream_point.xi, __pyx_v_source_stream_point.yi)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3293, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_7 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(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); + __pyx_t_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_ds_fa, __pyx_t_9}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3292, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 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[3] = {__pyx_t_7, __pyx_n_u_ds_fa, __pyx_t_9}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3292, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + { + __pyx_t_3 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3292, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_n_u_ds_fa); + __Pyx_GIVEREF(__pyx_n_u_ds_fa); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_11, __pyx_n_u_ds_fa); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_11, __pyx_t_9); + __pyx_t_9 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3292, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3295 + * 'ds_fa', flow_accum_managed_raster.get( + * source_stream_point.xi, source_stream_point.yi)) + * stream_feature.SetField('ds_x', source_stream_point.xi) # <<<<<<<<<<<<<< + * stream_feature.SetField('ds_y', source_stream_point.yi) + * stream_feature.SetField('ds_x_1', ds_x_1) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3295, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_source_stream_point.xi); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3295, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_9 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_9); + __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_9, __pyx_n_u_ds_x, __pyx_t_3}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3295, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 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[3] = {__pyx_t_9, __pyx_n_u_ds_x, __pyx_t_3}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3295, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3295, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_9) { + __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_9); __pyx_t_9 = NULL; + } + __Pyx_INCREF(__pyx_n_u_ds_x); + __Pyx_GIVEREF(__pyx_n_u_ds_x); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_11, __pyx_n_u_ds_x); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_11, __pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3295, __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_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3296 + * source_stream_point.xi, source_stream_point.yi)) + * stream_feature.SetField('ds_x', source_stream_point.xi) + * stream_feature.SetField('ds_y', source_stream_point.yi) # <<<<<<<<<<<<<< + * stream_feature.SetField('ds_x_1', ds_x_1) + * stream_feature.SetField('ds_y_1', ds_y_1) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3296, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_source_stream_point.yi); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3296, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_3 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(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_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_ds_y, __pyx_t_7}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3296, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_ds_y, __pyx_t_7}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3296, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_9 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3296, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_INCREF(__pyx_n_u_ds_y); + __Pyx_GIVEREF(__pyx_n_u_ds_y); + PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_11, __pyx_n_u_ds_y); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_11, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3296, __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_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3297 + * stream_feature.SetField('ds_x', source_stream_point.xi) + * stream_feature.SetField('ds_y', source_stream_point.yi) + * stream_feature.SetField('ds_x_1', ds_x_1) # <<<<<<<<<<<<<< + * stream_feature.SetField('ds_y_1', ds_y_1) + * stream_feature.SetField('us_x', x_u) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3297, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_9); + __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_9, __pyx_n_u_ds_x_1, __pyx_v_ds_x_1}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3297, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_ds_x_1, __pyx_v_ds_x_1}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3297, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3297, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_9) { + __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_9); __pyx_t_9 = NULL; + } + __Pyx_INCREF(__pyx_n_u_ds_x_1); + __Pyx_GIVEREF(__pyx_n_u_ds_x_1); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_11, __pyx_n_u_ds_x_1); + __Pyx_INCREF(__pyx_v_ds_x_1); + __Pyx_GIVEREF(__pyx_v_ds_x_1); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_11, __pyx_v_ds_x_1); + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3297, __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_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3298 + * stream_feature.SetField('ds_y', source_stream_point.yi) + * stream_feature.SetField('ds_x_1', ds_x_1) + * stream_feature.SetField('ds_y_1', ds_y_1) # <<<<<<<<<<<<<< + * stream_feature.SetField('us_x', x_u) + * stream_feature.SetField('us_y', y_u) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3298, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(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); + __pyx_t_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_ds_y_1, __pyx_v_ds_y_1}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3298, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_ds_y_1, __pyx_v_ds_y_1}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3298, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + { + __pyx_t_9 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3298, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_n_u_ds_y_1); + __Pyx_GIVEREF(__pyx_n_u_ds_y_1); + PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_11, __pyx_n_u_ds_y_1); + __Pyx_INCREF(__pyx_v_ds_y_1); + __Pyx_GIVEREF(__pyx_v_ds_y_1); + PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_11, __pyx_v_ds_y_1); + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3298, __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_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3299 + * stream_feature.SetField('ds_x_1', ds_x_1) + * stream_feature.SetField('ds_y_1', ds_y_1) + * stream_feature.SetField('us_x', x_u) # <<<<<<<<<<<<<< + * stream_feature.SetField('us_y', y_u) + * stream_feature.SetField( + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3299, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_9); + __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_9, __pyx_n_u_us_x, __pyx_v_x_u}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3299, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_us_x, __pyx_v_x_u}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3299, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3299, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_9) { + __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_9); __pyx_t_9 = NULL; + } + __Pyx_INCREF(__pyx_n_u_us_x); + __Pyx_GIVEREF(__pyx_n_u_us_x); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_11, __pyx_n_u_us_x); + __Pyx_INCREF(__pyx_v_x_u); + __Pyx_GIVEREF(__pyx_v_x_u); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_11, __pyx_v_x_u); + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3299, __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_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3300 + * stream_feature.SetField('ds_y_1', ds_y_1) + * stream_feature.SetField('us_x', x_u) + * stream_feature.SetField('us_y', y_u) # <<<<<<<<<<<<<< + * stream_feature.SetField( + * 'upstream_d8_dir', source_stream_point.upstream_d8_dir) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3300, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(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); + __pyx_t_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_us_y, __pyx_v_y_u}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3300, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_us_y, __pyx_v_y_u}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3300, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + { + __pyx_t_9 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3300, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_n_u_us_y); + __Pyx_GIVEREF(__pyx_n_u_us_y); + PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_11, __pyx_n_u_us_y); + __Pyx_INCREF(__pyx_v_y_u); + __Pyx_GIVEREF(__pyx_v_y_u); + PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_11, __pyx_v_y_u); + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3300, __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_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3301 + * stream_feature.SetField('us_x', x_u) + * stream_feature.SetField('us_y', y_u) + * stream_feature.SetField( # <<<<<<<<<<<<<< + * 'upstream_d8_dir', source_stream_point.upstream_d8_dir) + * + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3301, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":3302 + * stream_feature.SetField('us_y', y_u) + * stream_feature.SetField( + * 'upstream_d8_dir', source_stream_point.upstream_d8_dir) # <<<<<<<<<<<<<< + * + * # record the downstream connected component for all the upstream + */ + __pyx_t_9 = __Pyx_PyInt_From_int(__pyx_v_source_stream_point.upstream_d8_dir); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3302, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_7 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(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); + __pyx_t_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_upstream_d8_dir, __pyx_t_9}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3301, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 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[3] = {__pyx_t_7, __pyx_n_u_upstream_d8_dir, __pyx_t_9}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3301, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + { + __pyx_t_3 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3301, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_n_u_upstream_d8_dir); + __Pyx_GIVEREF(__pyx_n_u_upstream_d8_dir); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_11, __pyx_n_u_upstream_d8_dir); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_11, __pyx_t_9); + __pyx_t_9 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3301, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3306 + * # record the downstream connected component for all the upstream + * # connected components + * for upstream_id in upstream_id_list: # <<<<<<<<<<<<<< + * upstream_to_downstream_id[upstream_id] = ( + * source_stream_point.source_id) + */ + if (likely(PyList_CheckExact(__pyx_v_upstream_id_list)) || PyTuple_CheckExact(__pyx_v_upstream_id_list)) { + __pyx_t_8 = __pyx_v_upstream_id_list; __Pyx_INCREF(__pyx_t_8); __pyx_t_13 = 0; + __pyx_t_14 = NULL; + } else { + __pyx_t_13 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_upstream_id_list); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3306, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_14 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 3306, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_14)) { + if (likely(PyList_CheckExact(__pyx_t_8))) { + if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_8)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_13); __Pyx_INCREF(__pyx_t_1); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 3306, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_8, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3306, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } else { + if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_8)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_13); __Pyx_INCREF(__pyx_t_1); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 3306, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_8, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3306, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } + } else { + __pyx_t_1 = __pyx_t_14(__pyx_t_8); + 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, 3306, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XDECREF_SET(__pyx_v_upstream_id, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3308 + * for upstream_id in upstream_id_list: + * upstream_to_downstream_id[upstream_id] = ( + * source_stream_point.source_id) # <<<<<<<<<<<<<< + * + * # record the upstream connected components for the downstream component + */ + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_source_stream_point.source_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3308, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":3307 + * # connected components + * for upstream_id in upstream_id_list: + * upstream_to_downstream_id[upstream_id] = ( # <<<<<<<<<<<<<< + * source_stream_point.source_id) + * + */ + if (unlikely(PyDict_SetItem(__pyx_v_upstream_to_downstream_id, __pyx_v_upstream_id, __pyx_t_1) < 0)) __PYX_ERR(0, 3307, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3306 + * # record the downstream connected component for all the upstream + * # connected components + * for upstream_id in upstream_id_list: # <<<<<<<<<<<<<< + * upstream_to_downstream_id[upstream_id] = ( + * source_stream_point.source_id) + */ + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3311 + * + * # record the upstream connected components for the downstream component + * downstream_to_upstream_ids[source_stream_point.source_id] = ( # <<<<<<<<<<<<<< + * upstream_id_list) + * + */ + __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_source_stream_point.source_id); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3311, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + if (unlikely(PyDict_SetItem(__pyx_v_downstream_to_upstream_ids, __pyx_t_8, __pyx_v_upstream_id_list) < 0)) __PYX_ERR(0, 3311, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3315 + * + * # if no upstream it means it is an order 1 source stream + * if not upstream_id_list: # <<<<<<<<<<<<<< + * stream_feature.SetField('order', 1) + * stream_feature.SetGeometry(stream_line) + */ + __pyx_t_21 = __Pyx_PyObject_IsTrue(__pyx_v_upstream_id_list); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3315, __pyx_L1_error) + __pyx_t_5 = ((!__pyx_t_21) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":3316 + * # if no upstream it means it is an order 1 source stream + * if not upstream_id_list: + * stream_feature.SetField('order', 1) # <<<<<<<<<<<<<< + * stream_feature.SetGeometry(stream_line) + * + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3316, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3316, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3315 + * + * # if no upstream it means it is an order 1 source stream + * if not upstream_id_list: # <<<<<<<<<<<<<< + * stream_feature.SetField('order', 1) + * stream_feature.SetGeometry(stream_line) + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3317 + * if not upstream_id_list: + * stream_feature.SetField('order', 1) + * stream_feature.SetGeometry(stream_line) # <<<<<<<<<<<<<< + * + * # calculate the drop distance + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetGeometry); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3317, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_3, __pyx_v_stream_line) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_stream_line); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3317, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3320 + * + * # calculate the drop distance + * upstream_dem = dem_managed_raster.get(x_u, y_u) # <<<<<<<<<<<<<< + * drop_distance = upstream_dem - downstream_dem + * stream_feature.SetField('drop_distance', drop_distance) + */ + __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_v_x_u); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3320, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_v_y_u); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3320, __pyx_L1_error) + __pyx_v_upstream_dem = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_dem_managed_raster, __pyx_t_11, __pyx_t_6); + + /* "pygeoprocessing/routing/routing.pyx":3321 + * # calculate the drop distance + * upstream_dem = dem_managed_raster.get(x_u, y_u) + * drop_distance = upstream_dem - downstream_dem # <<<<<<<<<<<<<< + * stream_feature.SetField('drop_distance', drop_distance) + * stream_feature.SetField( + */ + __pyx_v_drop_distance = (__pyx_v_upstream_dem - __pyx_v_downstream_dem); + + /* "pygeoprocessing/routing/routing.pyx":3322 + * upstream_dem = dem_managed_raster.get(x_u, y_u) + * drop_distance = upstream_dem - downstream_dem + * stream_feature.SetField('drop_distance', drop_distance) # <<<<<<<<<<<<<< + * stream_feature.SetField( + * 'us_fa', flow_accum_managed_raster.get(x_u, y_u)) + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3322, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = PyFloat_FromDouble(__pyx_v_drop_distance); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3322, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_9 = NULL; + __pyx_t_6 = 0; + 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); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_drop_distance, __pyx_t_3}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3322, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_drop_distance, __pyx_t_3}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3322, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3322, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_9) { + __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_9); __pyx_t_9 = NULL; + } + __Pyx_INCREF(__pyx_n_u_drop_distance); + __Pyx_GIVEREF(__pyx_n_u_drop_distance); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_n_u_drop_distance); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3322, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3323 + * drop_distance = upstream_dem - downstream_dem + * stream_feature.SetField('drop_distance', drop_distance) + * stream_feature.SetField( # <<<<<<<<<<<<<< + * 'us_fa', flow_accum_managed_raster.get(x_u, y_u)) + * stream_feature.SetField('thresh_fa', min_flow_accum_threshold) + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3323, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + + /* "pygeoprocessing/routing/routing.pyx":3324 + * stream_feature.SetField('drop_distance', drop_distance) + * stream_feature.SetField( + * 'us_fa', flow_accum_managed_raster.get(x_u, y_u)) # <<<<<<<<<<<<<< + * stream_feature.SetField('thresh_fa', min_flow_accum_threshold) + * stream_layer.SetFeature(stream_feature) + */ + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_v_x_u); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3324, __pyx_L1_error) + __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_v_y_u); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3324, __pyx_L1_error) + __pyx_t_7 = PyFloat_FromDouble(__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_accum_managed_raster, __pyx_t_6, __pyx_t_11)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3324, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_3 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + __pyx_t_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_us_fa, __pyx_t_7}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3323, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 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[3] = {__pyx_t_3, __pyx_n_u_us_fa, __pyx_t_7}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3323, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_9 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3323, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_INCREF(__pyx_n_u_us_fa); + __Pyx_GIVEREF(__pyx_n_u_us_fa); + PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_11, __pyx_n_u_us_fa); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_11, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3323, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3325 + * stream_feature.SetField( + * 'us_fa', flow_accum_managed_raster.get(x_u, y_u)) + * stream_feature.SetField('thresh_fa', min_flow_accum_threshold) # <<<<<<<<<<<<<< + * stream_layer.SetFeature(stream_feature) + * + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3325, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = __Pyx_PyInt_From_long(__pyx_v_min_flow_accum_threshold); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3325, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_7 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(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); + __pyx_t_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_thresh_fa, __pyx_t_9}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3325, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + __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_7, __pyx_n_u_thresh_fa, __pyx_t_9}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3325, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + { + __pyx_t_3 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3325, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_n_u_thresh_fa); + __Pyx_GIVEREF(__pyx_n_u_thresh_fa); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_11, __pyx_n_u_thresh_fa); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_11, __pyx_t_9); + __pyx_t_9 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3325, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3326 + * 'us_fa', flow_accum_managed_raster.get(x_u, y_u)) + * stream_feature.SetField('thresh_fa', min_flow_accum_threshold) + * stream_layer.SetFeature(stream_feature) # <<<<<<<<<<<<<< + * + * LOGGER.info( + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_SetFeature); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3326, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_3, __pyx_v_stream_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_stream_feature); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3326, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_L39_continue:; + } + + /* "pygeoprocessing/routing/routing.pyx":3328 + * stream_layer.SetFeature(stream_feature) + * + * LOGGER.info( # <<<<<<<<<<<<<< + * '(extract_strahler_streams_d8): stream segment creation complete') + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3328, __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, 3328, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_8, __pyx_kp_u_extract_strahler_streams_d8_str_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_extract_strahler_streams_d8_str_2); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3328, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3331 + * '(extract_strahler_streams_d8): stream segment creation complete') + * + * LOGGER.info('(extract_strahler_streams_d8): determining stream order') # <<<<<<<<<<<<<< + * # seed the list with all order 1 streams + * stream_layer.SetAttributeFilter('"order"=1') + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3331, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_info); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3331, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_3, __pyx_kp_u_extract_strahler_streams_d8_det) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_kp_u_extract_strahler_streams_d8_det); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3331, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3333 + * LOGGER.info('(extract_strahler_streams_d8): determining stream order') + * # seed the list with all order 1 streams + * stream_layer.SetAttributeFilter('"order"=1') # <<<<<<<<<<<<<< + * streams_to_process = [stream_feature for stream_feature in stream_layer] + * base_feature_count = len(streams_to_process) + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_SetAttributeFilter); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3333, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_3, __pyx_kp_u_order_1) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_kp_u_order_1); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3333, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3334 + * # seed the list with all order 1 streams + * stream_layer.SetAttributeFilter('"order"=1') + * streams_to_process = [stream_feature for stream_feature in stream_layer] # <<<<<<<<<<<<<< + * base_feature_count = len(streams_to_process) + * outlet_fid_list = [] + */ + { /* enter inner scope */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3334, __pyx_L50_error) + __Pyx_GOTREF(__pyx_t_1); + if (likely(PyList_CheckExact(__pyx_v_stream_layer)) || PyTuple_CheckExact(__pyx_v_stream_layer)) { + __pyx_t_8 = __pyx_v_stream_layer; __Pyx_INCREF(__pyx_t_8); __pyx_t_13 = 0; + __pyx_t_14 = NULL; + } else { + __pyx_t_13 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_stream_layer); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3334, __pyx_L50_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_14 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 3334, __pyx_L50_error) + } + for (;;) { + if (likely(!__pyx_t_14)) { + if (likely(PyList_CheckExact(__pyx_t_8))) { + if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_8)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_13); __Pyx_INCREF(__pyx_t_3); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 3334, __pyx_L50_error) + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_8, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3334, __pyx_L50_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + } else { + if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_8)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_13); __Pyx_INCREF(__pyx_t_3); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 3334, __pyx_L50_error) + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_8, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3334, __pyx_L50_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + } + } else { + __pyx_t_3 = __pyx_t_14(__pyx_t_8); + 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, 3334, __pyx_L50_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF_SET(__pyx_7genexpr__pyx_v_stream_feature, __pyx_t_3); + __pyx_t_3 = 0; + if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_7genexpr__pyx_v_stream_feature))) __PYX_ERR(0, 3334, __pyx_L50_error) + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_7genexpr__pyx_v_stream_feature); __pyx_7genexpr__pyx_v_stream_feature = 0; + goto __pyx_L53_exit_scope; + __pyx_L50_error:; + __Pyx_XDECREF(__pyx_7genexpr__pyx_v_stream_feature); __pyx_7genexpr__pyx_v_stream_feature = 0; + goto __pyx_L1_error; + __pyx_L53_exit_scope:; + } /* exit inner scope */ + __pyx_v_streams_to_process = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3335 + * stream_layer.SetAttributeFilter('"order"=1') + * streams_to_process = [stream_feature for stream_feature in stream_layer] + * base_feature_count = len(streams_to_process) # <<<<<<<<<<<<<< + * outlet_fid_list = [] + * while streams_to_process: + */ + __pyx_t_13 = PyList_GET_SIZE(__pyx_v_streams_to_process); if (unlikely(__pyx_t_13 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3335, __pyx_L1_error) + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3335, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_base_feature_count = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3336 + * streams_to_process = [stream_feature for stream_feature in stream_layer] + * base_feature_count = len(streams_to_process) + * outlet_fid_list = [] # <<<<<<<<<<<<<< + * while streams_to_process: + * if ctime(NULL)-last_log_time > 2.0: + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3336, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_outlet_fid_list = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3337 + * base_feature_count = len(streams_to_process) + * outlet_fid_list = [] + * while streams_to_process: # <<<<<<<<<<<<<< + * if ctime(NULL)-last_log_time > 2.0: + * LOGGER.info( + */ + while (1) { + __pyx_t_5 = (PyList_GET_SIZE(__pyx_v_streams_to_process) != 0); + if (!__pyx_t_5) break; + + /* "pygeoprocessing/routing/routing.pyx":3338 + * outlet_fid_list = [] + * while streams_to_process: + * if ctime(NULL)-last_log_time > 2.0: # <<<<<<<<<<<<<< + * LOGGER.info( + * '(extract_strahler_streams_d8): ' + */ + __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > 2.0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":3339 + * while streams_to_process: + * if ctime(NULL)-last_log_time > 2.0: + * LOGGER.info( # <<<<<<<<<<<<<< + * '(extract_strahler_streams_d8): ' + * 'stream order processing: ' + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3339, __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, 3339, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3340 + * if ctime(NULL)-last_log_time > 2.0: + * LOGGER.info( + * '(extract_strahler_streams_d8): ' # <<<<<<<<<<<<<< + * 'stream order processing: ' + * f'{base_feature_count-len(streams_to_process)} of ' + */ + __pyx_t_8 = PyTuple_New(5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3340, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_13 = 0; + __pyx_t_16 = 127; + __Pyx_INCREF(__pyx_kp_u_extract_strahler_streams_d8_str_3); + __pyx_t_13 += 56; + __Pyx_GIVEREF(__pyx_kp_u_extract_strahler_streams_d8_str_3); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_kp_u_extract_strahler_streams_d8_str_3); + + /* "pygeoprocessing/routing/routing.pyx":3342 + * '(extract_strahler_streams_d8): ' + * 'stream order processing: ' + * f'{base_feature_count-len(streams_to_process)} of ' # <<<<<<<<<<<<<< + * f'{base_feature_count} stream fragments complete') + * last_log_time = ctime(NULL) + */ + __pyx_t_15 = PyList_GET_SIZE(__pyx_v_streams_to_process); if (unlikely(__pyx_t_15 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3342, __pyx_L1_error) + __pyx_t_9 = PyInt_FromSsize_t(__pyx_t_15); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3342, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_7 = PyNumber_Subtract(__pyx_v_base_feature_count, __pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3342, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_PyObject_FormatSimple(__pyx_t_7, __pyx_empty_unicode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3342, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_16 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9) > __pyx_t_16) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9) : __pyx_t_16; + __pyx_t_13 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_9); + __pyx_t_9 = 0; + __Pyx_INCREF(__pyx_kp_u_of); + __pyx_t_13 += 4; + __Pyx_GIVEREF(__pyx_kp_u_of); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_kp_u_of); + + /* "pygeoprocessing/routing/routing.pyx":3343 + * 'stream order processing: ' + * f'{base_feature_count-len(streams_to_process)} of ' + * f'{base_feature_count} stream fragments complete') # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * # fetch the downstream and connected upstream ids + */ + __pyx_t_9 = __Pyx_PyObject_FormatSimple(__pyx_v_base_feature_count, __pyx_empty_unicode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3343, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_16 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9) > __pyx_t_16) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9) : __pyx_t_16; + __pyx_t_13 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_9); + __pyx_t_9 = 0; + __Pyx_INCREF(__pyx_kp_u_stream_fragments_complete); + __pyx_t_13 += 26; + __Pyx_GIVEREF(__pyx_kp_u_stream_fragments_complete); + PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_kp_u_stream_fragments_complete); + + /* "pygeoprocessing/routing/routing.pyx":3340 + * if ctime(NULL)-last_log_time > 2.0: + * LOGGER.info( + * '(extract_strahler_streams_d8): ' # <<<<<<<<<<<<<< + * 'stream order processing: ' + * f'{base_feature_count-len(streams_to_process)} of ' + */ + __pyx_t_9 = __Pyx_PyUnicode_Join(__pyx_t_8, 5, __pyx_t_13, __pyx_t_16); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3340, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_8, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_9); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3339, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3344 + * f'{base_feature_count-len(streams_to_process)} of ' + * f'{base_feature_count} stream fragments complete') + * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< + * # fetch the downstream and connected upstream ids + * stream_feature = streams_to_process.pop(0) + */ + __pyx_v_last_log_time = time(NULL); + + /* "pygeoprocessing/routing/routing.pyx":3338 + * outlet_fid_list = [] + * while streams_to_process: + * if ctime(NULL)-last_log_time > 2.0: # <<<<<<<<<<<<<< + * LOGGER.info( + * '(extract_strahler_streams_d8): ' + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3346 + * last_log_time = ctime(NULL) + * # fetch the downstream and connected upstream ids + * stream_feature = streams_to_process.pop(0) # <<<<<<<<<<<<<< + * stream_fid = stream_feature.GetFID() + * if stream_fid not in upstream_to_downstream_id: + */ + __pyx_t_1 = __Pyx_PyList_PopIndex(__pyx_v_streams_to_process, __pyx_int_0, 0, 1, Py_ssize_t, PyInt_FromSsize_t); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3346, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_XDECREF_SET(__pyx_v_stream_feature, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3347 + * # fetch the downstream and connected upstream ids + * stream_feature = streams_to_process.pop(0) + * stream_fid = stream_feature.GetFID() # <<<<<<<<<<<<<< + * if stream_fid not in upstream_to_downstream_id: + * # it's an outlet so no downstream to process + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetFID); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3347, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_9) : __Pyx_PyObject_CallNoArg(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3347, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF_SET(__pyx_v_stream_fid, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3348 + * stream_feature = streams_to_process.pop(0) + * stream_fid = stream_feature.GetFID() + * if stream_fid not in upstream_to_downstream_id: # <<<<<<<<<<<<<< + * # it's an outlet so no downstream to process + * stream_feature.SetField('outlet', 1) + */ + __pyx_t_5 = (__Pyx_PyDict_ContainsTF(__pyx_v_stream_fid, __pyx_v_upstream_to_downstream_id, Py_NE)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 3348, __pyx_L1_error) + __pyx_t_21 = (__pyx_t_5 != 0); + if (__pyx_t_21) { + + /* "pygeoprocessing/routing/routing.pyx":3350 + * if stream_fid not in upstream_to_downstream_id: + * # it's an outlet so no downstream to process + * stream_feature.SetField('outlet', 1) # <<<<<<<<<<<<<< + * stream_layer.SetFeature(stream_feature) + * outlet_fid_list.append(stream_feature.GetFID()) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3350, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3350, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3351 + * # it's an outlet so no downstream to process + * stream_feature.SetField('outlet', 1) + * stream_layer.SetFeature(stream_feature) # <<<<<<<<<<<<<< + * outlet_fid_list.append(stream_feature.GetFID()) + * stream_feature = None + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_SetFeature); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3351, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_3 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_9, __pyx_v_stream_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_stream_feature); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3351, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3352 + * stream_feature.SetField('outlet', 1) + * stream_layer.SetFeature(stream_feature) + * outlet_fid_list.append(stream_feature.GetFID()) # <<<<<<<<<<<<<< + * stream_feature = None + * continue + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetFID); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3352, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_3 = (__pyx_t_9) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_9) : __Pyx_PyObject_CallNoArg(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3352, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_27 = __Pyx_PyList_Append(__pyx_v_outlet_fid_list, __pyx_t_3); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3352, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3353 + * stream_layer.SetFeature(stream_feature) + * outlet_fid_list.append(stream_feature.GetFID()) + * stream_feature = None # <<<<<<<<<<<<<< + * continue + * downstream_fid = upstream_to_downstream_id[stream_fid] + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_stream_feature, Py_None); + + /* "pygeoprocessing/routing/routing.pyx":3354 + * outlet_fid_list.append(stream_feature.GetFID()) + * stream_feature = None + * continue # <<<<<<<<<<<<<< + * downstream_fid = upstream_to_downstream_id[stream_fid] + * downstream_feature = stream_layer.GetFeature(downstream_fid) + */ + goto __pyx_L54_continue; + + /* "pygeoprocessing/routing/routing.pyx":3348 + * stream_feature = streams_to_process.pop(0) + * stream_fid = stream_feature.GetFID() + * if stream_fid not in upstream_to_downstream_id: # <<<<<<<<<<<<<< + * # it's an outlet so no downstream to process + * stream_feature.SetField('outlet', 1) + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3355 + * stream_feature = None + * continue + * downstream_fid = upstream_to_downstream_id[stream_fid] # <<<<<<<<<<<<<< + * downstream_feature = stream_layer.GetFeature(downstream_fid) + * if downstream_feature.GetField('order') is not None: + */ + __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_upstream_to_downstream_id, __pyx_v_stream_fid); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3355, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XDECREF_SET(__pyx_v_downstream_fid, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3356 + * continue + * downstream_fid = upstream_to_downstream_id[stream_fid] + * downstream_feature = stream_layer.GetFeature(downstream_fid) # <<<<<<<<<<<<<< + * if downstream_feature.GetField('order') is not None: + * # downstream component already processed + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3356, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_3 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_9, __pyx_v_downstream_fid) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_downstream_fid); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3356, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_downstream_feature, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3357 + * downstream_fid = upstream_to_downstream_id[stream_fid] + * downstream_feature = stream_layer.GetFeature(downstream_fid) + * if downstream_feature.GetField('order') is not None: # <<<<<<<<<<<<<< + * # downstream component already processed + * downstream_feature = None + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_downstream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3357, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_3 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_9, __pyx_n_u_order) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_n_u_order); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3357, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_21 = (__pyx_t_3 != Py_None); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_5 = (__pyx_t_21 != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":3359 + * if downstream_feature.GetField('order') is not None: + * # downstream component already processed + * downstream_feature = None # <<<<<<<<<<<<<< + * continue + * connected_upstream_fids = downstream_to_upstream_ids[downstream_fid] + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_downstream_feature, Py_None); + + /* "pygeoprocessing/routing/routing.pyx":3360 + * # downstream component already processed + * downstream_feature = None + * continue # <<<<<<<<<<<<<< + * connected_upstream_fids = downstream_to_upstream_ids[downstream_fid] + * # check that all upstream IDs are defined and construct stream order + */ + goto __pyx_L54_continue; + + /* "pygeoprocessing/routing/routing.pyx":3357 + * downstream_fid = upstream_to_downstream_id[stream_fid] + * downstream_feature = stream_layer.GetFeature(downstream_fid) + * if downstream_feature.GetField('order') is not None: # <<<<<<<<<<<<<< + * # downstream component already processed + * downstream_feature = None + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3361 + * downstream_feature = None + * continue + * connected_upstream_fids = downstream_to_upstream_ids[downstream_fid] # <<<<<<<<<<<<<< + * # check that all upstream IDs are defined and construct stream order + * # list + */ + __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_downstream_to_upstream_ids, __pyx_v_downstream_fid); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3361, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XDECREF_SET(__pyx_v_connected_upstream_fids, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3364 + * # check that all upstream IDs are defined and construct stream order + * # list + * stream_order_list = [] # <<<<<<<<<<<<<< + * all_defined = True + * for upstream_fid in connected_upstream_fids: + */ + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3364, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XDECREF_SET(__pyx_v_stream_order_list, ((PyObject*)__pyx_t_3)); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3365 + * # list + * stream_order_list = [] + * all_defined = True # <<<<<<<<<<<<<< + * for upstream_fid in connected_upstream_fids: + * upstream_feature = stream_layer.GetFeature(upstream_fid) + */ + __pyx_v_all_defined = 1; + + /* "pygeoprocessing/routing/routing.pyx":3366 + * stream_order_list = [] + * all_defined = True + * for upstream_fid in connected_upstream_fids: # <<<<<<<<<<<<<< + * upstream_feature = stream_layer.GetFeature(upstream_fid) + * upstream_order = upstream_feature.GetField('order') + */ + if (likely(PyList_CheckExact(__pyx_v_connected_upstream_fids)) || PyTuple_CheckExact(__pyx_v_connected_upstream_fids)) { + __pyx_t_3 = __pyx_v_connected_upstream_fids; __Pyx_INCREF(__pyx_t_3); __pyx_t_13 = 0; + __pyx_t_14 = NULL; + } else { + __pyx_t_13 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_connected_upstream_fids); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3366, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_14 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 3366, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_14)) { + if (likely(PyList_CheckExact(__pyx_t_3))) { + if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_13); __Pyx_INCREF(__pyx_t_1); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 3366, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3366, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } else { + if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_13); __Pyx_INCREF(__pyx_t_1); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 3366, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3366, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } + } else { + __pyx_t_1 = __pyx_t_14(__pyx_t_3); + 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, 3366, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XDECREF_SET(__pyx_v_upstream_fid, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3367 + * all_defined = True + * for upstream_fid in connected_upstream_fids: + * upstream_feature = stream_layer.GetFeature(upstream_fid) # <<<<<<<<<<<<<< + * upstream_order = upstream_feature.GetField('order') + * if upstream_order is not None: + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3367, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + } + } + __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_8, __pyx_v_upstream_fid) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_upstream_fid); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3367, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_XDECREF_SET(__pyx_v_upstream_feature, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3368 + * for upstream_fid in connected_upstream_fids: + * upstream_feature = stream_layer.GetFeature(upstream_fid) + * upstream_order = upstream_feature.GetField('order') # <<<<<<<<<<<<<< + * if upstream_order is not None: + * stream_order_list.append(upstream_order) + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_upstream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3368, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + } + } + __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_8, __pyx_n_u_order) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_n_u_order); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3368, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_XDECREF_SET(__pyx_v_upstream_order, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3369 + * upstream_feature = stream_layer.GetFeature(upstream_fid) + * upstream_order = upstream_feature.GetField('order') + * if upstream_order is not None: # <<<<<<<<<<<<<< + * stream_order_list.append(upstream_order) + * else: + */ + __pyx_t_5 = (__pyx_v_upstream_order != Py_None); + __pyx_t_21 = (__pyx_t_5 != 0); + if (__pyx_t_21) { + + /* "pygeoprocessing/routing/routing.pyx":3370 + * upstream_order = upstream_feature.GetField('order') + * if upstream_order is not None: + * stream_order_list.append(upstream_order) # <<<<<<<<<<<<<< + * else: + * # found an upstream not defined, that means it'll be processed + */ + __pyx_t_27 = __Pyx_PyList_Append(__pyx_v_stream_order_list, __pyx_v_upstream_order); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3370, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3369 + * upstream_feature = stream_layer.GetFeature(upstream_fid) + * upstream_order = upstream_feature.GetField('order') + * if upstream_order is not None: # <<<<<<<<<<<<<< + * stream_order_list.append(upstream_order) + * else: + */ + goto __pyx_L61; + } + + /* "pygeoprocessing/routing/routing.pyx":3374 + * # found an upstream not defined, that means it'll be processed + * # later + * all_defined = False # <<<<<<<<<<<<<< + * break + * if not all_defined: + */ + /*else*/ { + __pyx_v_all_defined = 0; + + /* "pygeoprocessing/routing/routing.pyx":3375 + * # later + * all_defined = False + * break # <<<<<<<<<<<<<< + * if not all_defined: + * # we'll revisit this stream later when the other connected + */ + goto __pyx_L60_break; + } + __pyx_L61:; + + /* "pygeoprocessing/routing/routing.pyx":3366 + * stream_order_list = [] + * all_defined = True + * for upstream_fid in connected_upstream_fids: # <<<<<<<<<<<<<< + * upstream_feature = stream_layer.GetFeature(upstream_fid) + * upstream_order = upstream_feature.GetField('order') + */ + } + __pyx_L60_break:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3376 + * all_defined = False + * break + * if not all_defined: # <<<<<<<<<<<<<< + * # we'll revisit this stream later when the other connected + * # components are processed + */ + __pyx_t_21 = ((!(__pyx_v_all_defined != 0)) != 0); + if (__pyx_t_21) { + + /* "pygeoprocessing/routing/routing.pyx":3379 + * # we'll revisit this stream later when the other connected + * # components are processed + * continue # <<<<<<<<<<<<<< + * sorted_stream_order_list = sorted(stream_order_list) + * downstream_order = sorted_stream_order_list[-1] + */ + goto __pyx_L54_continue; + + /* "pygeoprocessing/routing/routing.pyx":3376 + * all_defined = False + * break + * if not all_defined: # <<<<<<<<<<<<<< + * # we'll revisit this stream later when the other connected + * # components are processed + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3380 + * # components are processed + * continue + * sorted_stream_order_list = sorted(stream_order_list) # <<<<<<<<<<<<<< + * downstream_order = sorted_stream_order_list[-1] + * if len(sorted_stream_order_list) > 1 and ( + */ + __pyx_t_1 = PySequence_List(__pyx_v_stream_order_list); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3380, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_27 = PyList_Sort(__pyx_t_3); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3380, __pyx_L1_error) + __Pyx_XDECREF_SET(__pyx_v_sorted_stream_order_list, ((PyObject*)__pyx_t_3)); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3381 + * continue + * sorted_stream_order_list = sorted(stream_order_list) + * downstream_order = sorted_stream_order_list[-1] # <<<<<<<<<<<<<< + * if len(sorted_stream_order_list) > 1 and ( + * sorted_stream_order_list[-1] == + */ + if (unlikely(__pyx_v_sorted_stream_order_list == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 3381, __pyx_L1_error) + } + __pyx_t_3 = __Pyx_GetItemInt_List(__pyx_v_sorted_stream_order_list, -1L, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3381, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XDECREF_SET(__pyx_v_downstream_order, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3382 + * sorted_stream_order_list = sorted(stream_order_list) + * downstream_order = sorted_stream_order_list[-1] + * if len(sorted_stream_order_list) > 1 and ( # <<<<<<<<<<<<<< + * sorted_stream_order_list[-1] == + * sorted_stream_order_list[-2]): + */ + if (unlikely(__pyx_v_sorted_stream_order_list == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + __PYX_ERR(0, 3382, __pyx_L1_error) + } + __pyx_t_13 = PyList_GET_SIZE(__pyx_v_sorted_stream_order_list); if (unlikely(__pyx_t_13 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3382, __pyx_L1_error) + __pyx_t_5 = ((__pyx_t_13 > 1) != 0); + if (__pyx_t_5) { + } else { + __pyx_t_21 = __pyx_t_5; + goto __pyx_L64_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":3383 + * downstream_order = sorted_stream_order_list[-1] + * if len(sorted_stream_order_list) > 1 and ( + * sorted_stream_order_list[-1] == # <<<<<<<<<<<<<< + * sorted_stream_order_list[-2]): + * # if there are at least two equal order streams feeding in, + */ + if (unlikely(__pyx_v_sorted_stream_order_list == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 3383, __pyx_L1_error) + } + __pyx_t_3 = __Pyx_GetItemInt_List(__pyx_v_sorted_stream_order_list, -1L, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3383, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + + /* "pygeoprocessing/routing/routing.pyx":3384 + * if len(sorted_stream_order_list) > 1 and ( + * sorted_stream_order_list[-1] == + * sorted_stream_order_list[-2]): # <<<<<<<<<<<<<< + * # if there are at least two equal order streams feeding in, + * # we go up one order + */ + if (unlikely(__pyx_v_sorted_stream_order_list == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 3384, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_sorted_stream_order_list, -2L, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3384, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = PyObject_RichCompare(__pyx_t_3, __pyx_t_1, Py_EQ); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3383, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3383 + * downstream_order = sorted_stream_order_list[-1] + * if len(sorted_stream_order_list) > 1 and ( + * sorted_stream_order_list[-1] == # <<<<<<<<<<<<<< + * sorted_stream_order_list[-2]): + * # if there are at least two equal order streams feeding in, + */ + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 3383, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_21 = __pyx_t_5; + __pyx_L64_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":3382 + * sorted_stream_order_list = sorted(stream_order_list) + * downstream_order = sorted_stream_order_list[-1] + * if len(sorted_stream_order_list) > 1 and ( # <<<<<<<<<<<<<< + * sorted_stream_order_list[-1] == + * sorted_stream_order_list[-2]): + */ + if (__pyx_t_21) { + + /* "pygeoprocessing/routing/routing.pyx":3387 + * # if there are at least two equal order streams feeding in, + * # we go up one order + * downstream_order += 1 # <<<<<<<<<<<<<< + * downstream_feature.SetField('order', downstream_order) + * stream_layer.SetFeature(downstream_feature) + */ + __pyx_t_9 = __Pyx_PyInt_AddObjC(__pyx_v_downstream_order, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3387, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF_SET(__pyx_v_downstream_order, __pyx_t_9); + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3382 + * sorted_stream_order_list = sorted(stream_order_list) + * downstream_order = sorted_stream_order_list[-1] + * if len(sorted_stream_order_list) > 1 and ( # <<<<<<<<<<<<<< + * sorted_stream_order_list[-1] == + * sorted_stream_order_list[-2]): + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3388 + * # we go up one order + * downstream_order += 1 + * downstream_feature.SetField('order', downstream_order) # <<<<<<<<<<<<<< + * stream_layer.SetFeature(downstream_feature) + * streams_to_process.append(downstream_feature) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_downstream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3388, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(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_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_order, __pyx_v_downstream_order}; + __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3388, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_9); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_order, __pyx_v_downstream_order}; + __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3388, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_9); + } else + #endif + { + __pyx_t_8 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3388, __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_n_u_order); + __Pyx_GIVEREF(__pyx_n_u_order); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_11, __pyx_n_u_order); + __Pyx_INCREF(__pyx_v_downstream_order); + __Pyx_GIVEREF(__pyx_v_downstream_order); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_11, __pyx_v_downstream_order); + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3388, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3389 + * downstream_order += 1 + * downstream_feature.SetField('order', downstream_order) + * stream_layer.SetFeature(downstream_feature) # <<<<<<<<<<<<<< + * streams_to_process.append(downstream_feature) + * downstream_feature = None + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_SetFeature); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3389, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_9 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_8, __pyx_v_downstream_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_downstream_feature); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3389, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3390 + * downstream_feature.SetField('order', downstream_order) + * stream_layer.SetFeature(downstream_feature) + * streams_to_process.append(downstream_feature) # <<<<<<<<<<<<<< + * downstream_feature = None + * LOGGER.info( + */ + __pyx_t_27 = __Pyx_PyList_Append(__pyx_v_streams_to_process, __pyx_v_downstream_feature); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3390, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3391 + * stream_layer.SetFeature(downstream_feature) + * streams_to_process.append(downstream_feature) + * downstream_feature = None # <<<<<<<<<<<<<< + * LOGGER.info( + * '(extract_strahler_streams_d8): stream order processing complete') + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_downstream_feature, Py_None); + __pyx_L54_continue:; + } + + /* "pygeoprocessing/routing/routing.pyx":3392 + * streams_to_process.append(downstream_feature) + * downstream_feature = None + * LOGGER.info( # <<<<<<<<<<<<<< + * '(extract_strahler_streams_d8): stream order processing complete') + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3392, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_info); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3392, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_9 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_1, __pyx_kp_u_extract_strahler_streams_d8_str_4) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_kp_u_extract_strahler_streams_d8_str_4); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3392, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3395 + * '(extract_strahler_streams_d8): stream order processing complete') + * + * LOGGER.info( # <<<<<<<<<<<<<< + * '(extract_strahler_streams_d8): determine rivers') + * working_river_id = 0 + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3395, __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, 3395, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_9 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_8, __pyx_kp_u_extract_strahler_streams_d8_det_2) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_kp_u_extract_strahler_streams_d8_det_2); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3395, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3397 + * LOGGER.info( + * '(extract_strahler_streams_d8): determine rivers') + * working_river_id = 0 # <<<<<<<<<<<<<< + * for outlet_index, outlet_fid in enumerate(outlet_fid_list): + * # walk upstream starting from this outlet to search for rivers + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_v_working_river_id = __pyx_int_0; + + /* "pygeoprocessing/routing/routing.pyx":3398 + * '(extract_strahler_streams_d8): determine rivers') + * working_river_id = 0 + * for outlet_index, outlet_fid in enumerate(outlet_fid_list): # <<<<<<<<<<<<<< + * # walk upstream starting from this outlet to search for rivers + * # defined as stream segments whose order is <= river_order. Note it + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_t_9 = __pyx_int_0; + __pyx_t_1 = __pyx_v_outlet_fid_list; __Pyx_INCREF(__pyx_t_1); __pyx_t_13 = 0; + for (;;) { + if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_8 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_13); __Pyx_INCREF(__pyx_t_8); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 3398, __pyx_L1_error) + #else + __pyx_t_8 = PySequence_ITEM(__pyx_t_1, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3398, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + #endif + __Pyx_XDECREF_SET(__pyx_v_outlet_fid, __pyx_t_8); + __pyx_t_8 = 0; + __Pyx_INCREF(__pyx_t_9); + __Pyx_XDECREF_SET(__pyx_v_outlet_index, __pyx_t_9); + __pyx_t_8 = __Pyx_PyInt_AddObjC(__pyx_t_9, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3398, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); + __pyx_t_9 = __pyx_t_8; + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3403 + * # can be < river_order because we may have some streams that have + * # outlets for shorter rivers that can't get to river_order. + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * LOGGER.info( + * '(extract_strahler_streams_d8): ' + */ + __pyx_t_21 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); + if (__pyx_t_21) { + + /* "pygeoprocessing/routing/routing.pyx":3404 + * # outlets for shorter rivers that can't get to river_order. + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: + * LOGGER.info( # <<<<<<<<<<<<<< + * '(extract_strahler_streams_d8): ' + * 'flow accumulation adjustment ' + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3404, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3404, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3405 + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: + * LOGGER.info( + * '(extract_strahler_streams_d8): ' # <<<<<<<<<<<<<< + * 'flow accumulation adjustment ' + * f'{outlet_index+1} of {len(outlet_fid_list)} ' + */ + __pyx_t_3 = PyTuple_New(5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3405, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_15 = 0; + __pyx_t_16 = 127; + __Pyx_INCREF(__pyx_kp_u_extract_strahler_streams_d8_flo); + __pyx_t_15 += 60; + __Pyx_GIVEREF(__pyx_kp_u_extract_strahler_streams_d8_flo); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_u_extract_strahler_streams_d8_flo); + + /* "pygeoprocessing/routing/routing.pyx":3407 + * '(extract_strahler_streams_d8): ' + * 'flow accumulation adjustment ' + * f'{outlet_index+1} of {len(outlet_fid_list)} ' # <<<<<<<<<<<<<< + * 'outlets complete') + * last_log_time = ctime(NULL) + */ + __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_v_outlet_index, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3407, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyObject_FormatSimple(__pyx_t_2, __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3407, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_16 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_16) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_16; + __pyx_t_15 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4); + __pyx_t_4 = 0; + __Pyx_INCREF(__pyx_kp_u_of); + __pyx_t_15 += 4; + __Pyx_GIVEREF(__pyx_kp_u_of); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_kp_u_of); + __pyx_t_28 = PyList_GET_SIZE(__pyx_v_outlet_fid_list); if (unlikely(__pyx_t_28 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3407, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyUnicode_From_Py_ssize_t(__pyx_t_28, 0, ' ', 'd'); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3407, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_15 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_4); + __pyx_t_4 = 0; + __Pyx_INCREF(__pyx_kp_u_outlets_complete); + __pyx_t_15 += 17; + __Pyx_GIVEREF(__pyx_kp_u_outlets_complete); + PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_kp_u_outlets_complete); + + /* "pygeoprocessing/routing/routing.pyx":3405 + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: + * LOGGER.info( + * '(extract_strahler_streams_d8): ' # <<<<<<<<<<<<<< + * 'flow accumulation adjustment ' + * f'{outlet_index+1} of {len(outlet_fid_list)} ' + */ + __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_3, 5, __pyx_t_15, __pyx_t_16); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3405, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __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); + } + } + __pyx_t_8 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_4); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3404, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3409 + * f'{outlet_index+1} of {len(outlet_fid_list)} ' + * 'outlets complete') + * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< + * search_stack = [outlet_fid] + * while search_stack: + */ + __pyx_v_last_log_time = time(NULL); + + /* "pygeoprocessing/routing/routing.pyx":3403 + * # can be < river_order because we may have some streams that have + * # outlets for shorter rivers that can't get to river_order. + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * LOGGER.info( + * '(extract_strahler_streams_d8): ' + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3410 + * 'outlets complete') + * last_log_time = ctime(NULL) + * search_stack = [outlet_fid] # <<<<<<<<<<<<<< + * while search_stack: + * stream_layer.CommitTransaction() + */ + __pyx_t_8 = PyList_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3410, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(__pyx_v_outlet_fid); + __Pyx_GIVEREF(__pyx_v_outlet_fid); + PyList_SET_ITEM(__pyx_t_8, 0, __pyx_v_outlet_fid); + __Pyx_XDECREF_SET(__pyx_v_search_stack, ((PyObject*)__pyx_t_8)); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3411 + * last_log_time = ctime(NULL) + * search_stack = [outlet_fid] + * while search_stack: # <<<<<<<<<<<<<< + * stream_layer.CommitTransaction() + * stream_layer.StartTransaction() + */ + while (1) { + __pyx_t_21 = (PyList_GET_SIZE(__pyx_v_search_stack) != 0); + if (!__pyx_t_21) break; + + /* "pygeoprocessing/routing/routing.pyx":3412 + * search_stack = [outlet_fid] + * while search_stack: + * stream_layer.CommitTransaction() # <<<<<<<<<<<<<< + * stream_layer.StartTransaction() + * feature_id = search_stack.pop() + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CommitTransaction); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3412, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_8 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3412, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3413 + * while search_stack: + * stream_layer.CommitTransaction() + * stream_layer.StartTransaction() # <<<<<<<<<<<<<< + * feature_id = search_stack.pop() + * stream_feature = stream_layer.GetFeature(feature_id) + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_StartTransaction); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3413, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_8 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3413, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3414 + * stream_layer.CommitTransaction() + * stream_layer.StartTransaction() + * feature_id = search_stack.pop() # <<<<<<<<<<<<<< + * stream_feature = stream_layer.GetFeature(feature_id) + * stream_order = stream_feature.GetField('order') + */ + __pyx_t_8 = __Pyx_PyList_Pop(__pyx_v_search_stack); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3414, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_XDECREF_SET(__pyx_v_feature_id, __pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3415 + * stream_layer.StartTransaction() + * feature_id = search_stack.pop() + * stream_feature = stream_layer.GetFeature(feature_id) # <<<<<<<<<<<<<< + * stream_order = stream_feature.GetField('order') + * + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3415, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_8 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_4, __pyx_v_feature_id) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_feature_id); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3415, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF_SET(__pyx_v_stream_feature, __pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3416 + * feature_id = search_stack.pop() + * stream_feature = stream_layer.GetFeature(feature_id) + * stream_order = stream_feature.GetField('order') # <<<<<<<<<<<<<< + * + * if (stream_order > river_order or + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3416, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_8 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_4, __pyx_n_u_order) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_n_u_order); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3416, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF_SET(__pyx_v_stream_order, __pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3418 + * stream_order = stream_feature.GetField('order') + * + * if (stream_order > river_order or # <<<<<<<<<<<<<< + * stream_feature.GetField('river_id') is not None): + * # keep walking upstream until there's an order <= river_order + */ + __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_river_order); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3418, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = PyObject_RichCompare(__pyx_v_stream_order, __pyx_t_8, Py_GT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3418, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 3418, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (!__pyx_t_5) { + } else { + __pyx_t_21 = __pyx_t_5; + goto __pyx_L72_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":3419 + * + * if (stream_order > river_order or + * stream_feature.GetField('river_id') is not None): # <<<<<<<<<<<<<< + * # keep walking upstream until there's an order <= river_order + * search_stack.extend( + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3419, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __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); + } + } + __pyx_t_7 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_4, __pyx_n_u_river_id) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_n_u_river_id); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3419, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_5 = (__pyx_t_7 != Py_None); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_29 = (__pyx_t_5 != 0); + __pyx_t_21 = __pyx_t_29; + __pyx_L72_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":3418 + * stream_order = stream_feature.GetField('order') + * + * if (stream_order > river_order or # <<<<<<<<<<<<<< + * stream_feature.GetField('river_id') is not None): + * # keep walking upstream until there's an order <= river_order + */ + if (__pyx_t_21) { + + /* "pygeoprocessing/routing/routing.pyx":3422 + * # keep walking upstream until there's an order <= river_order + * search_stack.extend( + * downstream_to_upstream_ids[feature_id]) # <<<<<<<<<<<<<< + * else: + * # walk up the stream setting every upstream segment's + */ + __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_downstream_to_upstream_ids, __pyx_v_feature_id); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3422, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + + /* "pygeoprocessing/routing/routing.pyx":3421 + * stream_feature.GetField('river_id') is not None): + * # keep walking upstream until there's an order <= river_order + * search_stack.extend( # <<<<<<<<<<<<<< + * downstream_to_upstream_ids[feature_id]) + * else: + */ + __pyx_t_27 = __Pyx_PyList_Extend(__pyx_v_search_stack, __pyx_t_7); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3421, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3418 + * stream_order = stream_feature.GetField('order') + * + * if (stream_order > river_order or # <<<<<<<<<<<<<< + * stream_feature.GetField('river_id') is not None): + * # keep walking upstream until there's an order <= river_order + */ + goto __pyx_L71; + } + + /* "pygeoprocessing/routing/routing.pyx":3426 + * # walk up the stream setting every upstream segment's + * # river_id to working_river_id + * stream_layer.SetFeature(stream_feature) # <<<<<<<<<<<<<< + * upstream_stack = [feature_id] + * + */ + /*else*/ { + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_SetFeature); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3426, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __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); + } + } + __pyx_t_7 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_4, __pyx_v_stream_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_stream_feature); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3426, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3427 + * # river_id to working_river_id + * stream_layer.SetFeature(stream_feature) + * upstream_stack = [feature_id] # <<<<<<<<<<<<<< + * + * streams_by_order = collections.defaultdict(list) + */ + __pyx_t_7 = PyList_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3427, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_v_feature_id); + __Pyx_GIVEREF(__pyx_v_feature_id); + PyList_SET_ITEM(__pyx_t_7, 0, __pyx_v_feature_id); + __Pyx_XDECREF_SET(__pyx_v_upstream_stack, ((PyObject*)__pyx_t_7)); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3429 + * upstream_stack = [feature_id] + * + * streams_by_order = collections.defaultdict(list) # <<<<<<<<<<<<<< + * drop_distance_collection = collections.defaultdict(list) + * max_upstream_flow_accum = collections.defaultdict(int) + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_collections); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3429, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3429, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + 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_7 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_8, ((PyObject *)(&PyList_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_4, ((PyObject *)(&PyList_Type))); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3429, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF_SET(__pyx_v_streams_by_order, __pyx_t_7); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3430 + * + * streams_by_order = collections.defaultdict(list) + * drop_distance_collection = collections.defaultdict(list) # <<<<<<<<<<<<<< + * max_upstream_flow_accum = collections.defaultdict(int) + * while upstream_stack: + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_collections); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3430, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3430, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(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); + } + } + __pyx_t_7 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_4, ((PyObject *)(&PyList_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_8, ((PyObject *)(&PyList_Type))); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3430, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF_SET(__pyx_v_drop_distance_collection, __pyx_t_7); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3431 + * streams_by_order = collections.defaultdict(list) + * drop_distance_collection = collections.defaultdict(list) + * max_upstream_flow_accum = collections.defaultdict(int) # <<<<<<<<<<<<<< + * while upstream_stack: + * feature_id = upstream_stack.pop() + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_collections); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3431, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3431, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + 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_7 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_8, ((PyObject *)(&PyInt_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_4, ((PyObject *)(&PyInt_Type))); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3431, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF_SET(__pyx_v_max_upstream_flow_accum, __pyx_t_7); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3432 + * drop_distance_collection = collections.defaultdict(list) + * max_upstream_flow_accum = collections.defaultdict(int) + * while upstream_stack: # <<<<<<<<<<<<<< + * feature_id = upstream_stack.pop() + * stream_feature = stream_layer.GetFeature(feature_id) + */ + while (1) { + __pyx_t_21 = (PyList_GET_SIZE(__pyx_v_upstream_stack) != 0); + if (!__pyx_t_21) break; + + /* "pygeoprocessing/routing/routing.pyx":3433 + * max_upstream_flow_accum = collections.defaultdict(int) + * while upstream_stack: + * feature_id = upstream_stack.pop() # <<<<<<<<<<<<<< + * stream_feature = stream_layer.GetFeature(feature_id) + * stream_feature.SetField('river_id', working_river_id) + */ + __pyx_t_7 = __Pyx_PyList_Pop(__pyx_v_upstream_stack); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3433, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF_SET(__pyx_v_feature_id, __pyx_t_7); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3434 + * while upstream_stack: + * feature_id = upstream_stack.pop() + * stream_feature = stream_layer.GetFeature(feature_id) # <<<<<<<<<<<<<< + * stream_feature.SetField('river_id', working_river_id) + * stream_layer.SetFeature(stream_feature) + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3434, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_7 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_8, __pyx_v_feature_id) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_feature_id); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3434, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF_SET(__pyx_v_stream_feature, __pyx_t_7); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3435 + * feature_id = upstream_stack.pop() + * stream_feature = stream_layer.GetFeature(feature_id) + * stream_feature.SetField('river_id', working_river_id) # <<<<<<<<<<<<<< + * stream_layer.SetFeature(stream_feature) + * order = stream_feature.GetField('order') + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3435, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(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_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_n_u_river_id, __pyx_v_working_river_id}; + __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, 3435, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_n_u_river_id, __pyx_v_working_river_id}; + __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, 3435, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + { + __pyx_t_3 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3435, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (__pyx_t_8) { + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8); __pyx_t_8 = NULL; + } + __Pyx_INCREF(__pyx_n_u_river_id); + __Pyx_GIVEREF(__pyx_n_u_river_id); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_11, __pyx_n_u_river_id); + __Pyx_INCREF(__pyx_v_working_river_id); + __Pyx_GIVEREF(__pyx_v_working_river_id); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_11, __pyx_v_working_river_id); + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3435, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3436 + * stream_feature = stream_layer.GetFeature(feature_id) + * stream_feature.SetField('river_id', working_river_id) + * stream_layer.SetFeature(stream_feature) # <<<<<<<<<<<<<< + * order = stream_feature.GetField('order') + * streams_by_order[order].append(stream_feature) + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_SetFeature); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3436, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_7 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_v_stream_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_stream_feature); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3436, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3437 + * stream_feature.SetField('river_id', working_river_id) + * stream_layer.SetFeature(stream_feature) + * order = stream_feature.GetField('order') # <<<<<<<<<<<<<< + * streams_by_order[order].append(stream_feature) + * drop_distance_collection[order].append( + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3437, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_7 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_n_u_order) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_n_u_order); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3437, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF_SET(__pyx_v_order, __pyx_t_7); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3438 + * stream_layer.SetFeature(stream_feature) + * order = stream_feature.GetField('order') + * streams_by_order[order].append(stream_feature) # <<<<<<<<<<<<<< + * drop_distance_collection[order].append( + * stream_feature.GetField('drop_distance')) + */ + __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_streams_by_order, __pyx_v_order); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3438, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_27 = __Pyx_PyObject_Append(__pyx_t_7, __pyx_v_stream_feature); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3438, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3439 + * order = stream_feature.GetField('order') + * streams_by_order[order].append(stream_feature) + * drop_distance_collection[order].append( # <<<<<<<<<<<<<< + * stream_feature.GetField('drop_distance')) + * max_upstream_flow_accum[order] = max( + */ + __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_drop_distance_collection, __pyx_v_order); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3439, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + + /* "pygeoprocessing/routing/routing.pyx":3440 + * streams_by_order[order].append(stream_feature) + * drop_distance_collection[order].append( + * stream_feature.GetField('drop_distance')) # <<<<<<<<<<<<<< + * max_upstream_flow_accum[order] = max( + * max_upstream_flow_accum[order], + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3440, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_4 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_8, __pyx_n_u_drop_distance) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_n_u_drop_distance); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3440, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3439 + * order = stream_feature.GetField('order') + * streams_by_order[order].append(stream_feature) + * drop_distance_collection[order].append( # <<<<<<<<<<<<<< + * stream_feature.GetField('drop_distance')) + * max_upstream_flow_accum[order] = max( + */ + __pyx_t_27 = __Pyx_PyObject_Append(__pyx_t_7, __pyx_t_4); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3439, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3443 + * max_upstream_flow_accum[order] = max( + * max_upstream_flow_accum[order], + * stream_feature.GetField('us_fa')) # <<<<<<<<<<<<<< + * stream_feature = None + * upstream_stack.extend( + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3443, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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); + } + } + __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_3, __pyx_n_u_us_fa) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_n_u_us_fa); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3443, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3442 + * stream_feature.GetField('drop_distance')) + * max_upstream_flow_accum[order] = max( + * max_upstream_flow_accum[order], # <<<<<<<<<<<<<< + * stream_feature.GetField('us_fa')) + * stream_feature = None + */ + __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_max_upstream_flow_accum, __pyx_v_order); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3442, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + + /* "pygeoprocessing/routing/routing.pyx":3443 + * max_upstream_flow_accum[order] = max( + * max_upstream_flow_accum[order], + * stream_feature.GetField('us_fa')) # <<<<<<<<<<<<<< + * stream_feature = None + * upstream_stack.extend( + */ + __pyx_t_8 = PyObject_RichCompare(__pyx_t_4, __pyx_t_7, Py_GT); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3443, __pyx_L1_error) + __pyx_t_21 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3443, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (__pyx_t_21) { + __Pyx_INCREF(__pyx_t_4); + __pyx_t_3 = __pyx_t_4; + } else { + __Pyx_INCREF(__pyx_t_7); + __pyx_t_3 = __pyx_t_7; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __pyx_t_3; + __Pyx_INCREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3441 + * drop_distance_collection[order].append( + * stream_feature.GetField('drop_distance')) + * max_upstream_flow_accum[order] = max( # <<<<<<<<<<<<<< + * max_upstream_flow_accum[order], + * stream_feature.GetField('us_fa')) + */ + if (unlikely(PyObject_SetItem(__pyx_v_max_upstream_flow_accum, __pyx_v_order, __pyx_t_4) < 0)) __PYX_ERR(0, 3441, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3444 + * max_upstream_flow_accum[order], + * stream_feature.GetField('us_fa')) + * stream_feature = None # <<<<<<<<<<<<<< + * upstream_stack.extend( + * downstream_to_upstream_ids[feature_id]) + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_stream_feature, Py_None); + + /* "pygeoprocessing/routing/routing.pyx":3446 + * stream_feature = None + * upstream_stack.extend( + * downstream_to_upstream_ids[feature_id]) # <<<<<<<<<<<<<< + * + * working_flow_accum_threshold = min_flow_accum_threshold + */ + __pyx_t_4 = __Pyx_PyDict_GetItem(__pyx_v_downstream_to_upstream_ids, __pyx_v_feature_id); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3446, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "pygeoprocessing/routing/routing.pyx":3445 + * stream_feature.GetField('us_fa')) + * stream_feature = None + * upstream_stack.extend( # <<<<<<<<<<<<<< + * downstream_to_upstream_ids[feature_id]) + * + */ + __pyx_t_27 = __Pyx_PyList_Extend(__pyx_v_upstream_stack, __pyx_t_4); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3445, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + + /* "pygeoprocessing/routing/routing.pyx":3448 + * downstream_to_upstream_ids[feature_id]) + * + * working_flow_accum_threshold = min_flow_accum_threshold # <<<<<<<<<<<<<< + * while drop_distance_collection and autotune_flow_accumulation: + * stream_layer.CommitTransaction() + */ + __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_v_min_flow_accum_threshold); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3448, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XDECREF_SET(__pyx_v_working_flow_accum_threshold, __pyx_t_4); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3449 + * + * working_flow_accum_threshold = min_flow_accum_threshold + * while drop_distance_collection and autotune_flow_accumulation: # <<<<<<<<<<<<<< + * stream_layer.CommitTransaction() + * stream_layer.StartTransaction() + */ + while (1) { + __pyx_t_29 = __Pyx_PyObject_IsTrue(__pyx_v_drop_distance_collection); if (unlikely(__pyx_t_29 < 0)) __PYX_ERR(0, 3449, __pyx_L1_error) + if (__pyx_t_29) { + } else { + __pyx_t_21 = __pyx_t_29; + goto __pyx_L78_bool_binop_done; + } + __pyx_t_29 = __Pyx_PyObject_IsTrue(__pyx_v_autotune_flow_accumulation); if (unlikely(__pyx_t_29 < 0)) __PYX_ERR(0, 3449, __pyx_L1_error) + __pyx_t_21 = __pyx_t_29; + __pyx_L78_bool_binop_done:; + if (!__pyx_t_21) break; + + /* "pygeoprocessing/routing/routing.pyx":3450 + * working_flow_accum_threshold = min_flow_accum_threshold + * while drop_distance_collection and autotune_flow_accumulation: + * stream_layer.CommitTransaction() # <<<<<<<<<<<<<< + * stream_layer.StartTransaction() + * # decide how much bigger to make the flow_accum + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CommitTransaction); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3450, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3450, __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":3451 + * while drop_distance_collection and autotune_flow_accumulation: + * stream_layer.CommitTransaction() + * stream_layer.StartTransaction() # <<<<<<<<<<<<<< + * # decide how much bigger to make the flow_accum + * # find a test_order that tests p_val > 0.5 then retest + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_StartTransaction); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3451, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3451, __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":3454 + * # decide how much bigger to make the flow_accum + * # find a test_order that tests p_val > 0.5 then retest + * test_order = min(drop_distance_collection) # <<<<<<<<<<<<<< + * while test_order+1 <= max(drop_distance_collection): + * if (len(drop_distance_collection[test_order]) < 3 or + */ + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_min, __pyx_v_drop_distance_collection); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3454, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XDECREF_SET(__pyx_v_test_order, __pyx_t_4); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3455 + * # find a test_order that tests p_val > 0.5 then retest + * test_order = min(drop_distance_collection) + * while test_order+1 <= max(drop_distance_collection): # <<<<<<<<<<<<<< + * if (len(drop_distance_collection[test_order]) < 3 or + * len(drop_distance_collection[ + */ + while (1) { + __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_v_test_order, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3455, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_max, __pyx_v_drop_distance_collection); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3455, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_LE); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3455, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_21 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3455, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (!__pyx_t_21) break; + + /* "pygeoprocessing/routing/routing.pyx":3456 + * test_order = min(drop_distance_collection) + * while test_order+1 <= max(drop_distance_collection): + * if (len(drop_distance_collection[test_order]) < 3 or # <<<<<<<<<<<<<< + * len(drop_distance_collection[ + * test_order+1]) < 3): + */ + __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_drop_distance_collection, __pyx_v_test_order); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3456, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_15 = PyObject_Length(__pyx_t_7); if (unlikely(__pyx_t_15 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3456, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_29 = ((__pyx_t_15 < 3) != 0); + if (!__pyx_t_29) { + } else { + __pyx_t_21 = __pyx_t_29; + goto __pyx_L83_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":3458 + * if (len(drop_distance_collection[test_order]) < 3 or + * len(drop_distance_collection[ + * test_order+1]) < 3): # <<<<<<<<<<<<<< + * # too small to test so it's not significant + * break + */ + __pyx_t_7 = __Pyx_PyInt_AddObjC(__pyx_v_test_order, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3458, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + + /* "pygeoprocessing/routing/routing.pyx":3457 + * while test_order+1 <= max(drop_distance_collection): + * if (len(drop_distance_collection[test_order]) < 3 or + * len(drop_distance_collection[ # <<<<<<<<<<<<<< + * test_order+1]) < 3): + * # too small to test so it's not significant + */ + __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_drop_distance_collection, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3457, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_15 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_15 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3457, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3458 + * if (len(drop_distance_collection[test_order]) < 3 or + * len(drop_distance_collection[ + * test_order+1]) < 3): # <<<<<<<<<<<<<< + * # too small to test so it's not significant + * break + */ + __pyx_t_29 = ((__pyx_t_15 < 3) != 0); + __pyx_t_21 = __pyx_t_29; + __pyx_L83_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":3456 + * test_order = min(drop_distance_collection) + * while test_order+1 <= max(drop_distance_collection): + * if (len(drop_distance_collection[test_order]) < 3 or # <<<<<<<<<<<<<< + * len(drop_distance_collection[ + * test_order+1]) < 3): + */ + if (__pyx_t_21) { + + /* "pygeoprocessing/routing/routing.pyx":3460 + * test_order+1]) < 3): + * # too small to test so it's not significant + * break # <<<<<<<<<<<<<< + * _, p_val = scipy.stats.ttest_ind( + * drop_distance_collection[test_order], + */ + goto __pyx_L81_break; + + /* "pygeoprocessing/routing/routing.pyx":3456 + * test_order = min(drop_distance_collection) + * while test_order+1 <= max(drop_distance_collection): + * if (len(drop_distance_collection[test_order]) < 3 or # <<<<<<<<<<<<<< + * len(drop_distance_collection[ + * test_order+1]) < 3): + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3461 + * # too small to test so it's not significant + * break + * _, p_val = scipy.stats.ttest_ind( # <<<<<<<<<<<<<< + * drop_distance_collection[test_order], + * drop_distance_collection[test_order+1], + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_scipy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3461, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_stats); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3461, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_ttest_ind); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3461, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3462 + * break + * _, p_val = scipy.stats.ttest_ind( + * drop_distance_collection[test_order], # <<<<<<<<<<<<<< + * drop_distance_collection[test_order+1], + * equal_var=True) + */ + __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_drop_distance_collection, __pyx_v_test_order); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3462, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + + /* "pygeoprocessing/routing/routing.pyx":3463 + * _, p_val = scipy.stats.ttest_ind( + * drop_distance_collection[test_order], + * drop_distance_collection[test_order+1], # <<<<<<<<<<<<<< + * equal_var=True) + * if p_val > min_p_val or numpy.isnan(p_val): + */ + __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_v_test_order, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3463, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_drop_distance_collection, __pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3463, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3461 + * # too small to test so it's not significant + * break + * _, p_val = scipy.stats.ttest_ind( # <<<<<<<<<<<<<< + * drop_distance_collection[test_order], + * drop_distance_collection[test_order+1], + */ + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3461, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_8); + __pyx_t_7 = 0; + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3464 + * drop_distance_collection[test_order], + * drop_distance_collection[test_order+1], + * equal_var=True) # <<<<<<<<<<<<<< + * if p_val > min_p_val or numpy.isnan(p_val): + * # not too big or just too few elements + */ + __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3464, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_equal_var, Py_True) < 0) __PYX_ERR(0, 3464, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3461 + * # too small to test so it's not significant + * break + * _, p_val = scipy.stats.ttest_ind( # <<<<<<<<<<<<<< + * drop_distance_collection[test_order], + * drop_distance_collection[test_order+1], + */ + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3461, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) { + PyObject* sequence = __pyx_t_7; + 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, 3461, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_8 = PyList_GET_ITEM(sequence, 0); + __pyx_t_4 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(__pyx_t_4); + #else + __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3461, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3461, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_3 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3461, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_10 = Py_TYPE(__pyx_t_3)->tp_iternext; + index = 0; __pyx_t_8 = __pyx_t_10(__pyx_t_3); if (unlikely(!__pyx_t_8)) goto __pyx_L85_unpacking_failed; + __Pyx_GOTREF(__pyx_t_8); + index = 1; __pyx_t_4 = __pyx_t_10(__pyx_t_3); if (unlikely(!__pyx_t_4)) goto __pyx_L85_unpacking_failed; + __Pyx_GOTREF(__pyx_t_4); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_3), 2) < 0) __PYX_ERR(0, 3461, __pyx_L1_error) + __pyx_t_10 = NULL; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L86_unpacking_done; + __pyx_L85_unpacking_failed:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_10 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 3461, __pyx_L1_error) + __pyx_L86_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_8); + __pyx_t_8 = 0; + __Pyx_XDECREF_SET(__pyx_v_p_val, __pyx_t_4); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3465 + * drop_distance_collection[test_order+1], + * equal_var=True) + * if p_val > min_p_val or numpy.isnan(p_val): # <<<<<<<<<<<<<< + * # not too big or just too few elements + * break + */ + __pyx_t_7 = PyFloat_FromDouble(__pyx_v_min_p_val); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3465, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_p_val, __pyx_t_7, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3465, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_29 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_29 < 0)) __PYX_ERR(0, 3465, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (!__pyx_t_29) { + } else { + __pyx_t_21 = __pyx_t_29; + goto __pyx_L88_bool_binop_done; + } + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_numpy); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3465, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_isnan); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3465, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __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); + } + } + __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_7, __pyx_v_p_val) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_p_val); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3465, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_29 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_29 < 0)) __PYX_ERR(0, 3465, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_21 = __pyx_t_29; + __pyx_L88_bool_binop_done:; + if (__pyx_t_21) { + + /* "pygeoprocessing/routing/routing.pyx":3467 + * if p_val > min_p_val or numpy.isnan(p_val): + * # not too big or just too few elements + * break # <<<<<<<<<<<<<< + * test_order += 1 + * if test_order == min(drop_distance_collection): + */ + goto __pyx_L81_break; + + /* "pygeoprocessing/routing/routing.pyx":3465 + * drop_distance_collection[test_order+1], + * equal_var=True) + * if p_val > min_p_val or numpy.isnan(p_val): # <<<<<<<<<<<<<< + * # not too big or just too few elements + * break + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3468 + * # not too big or just too few elements + * break + * test_order += 1 # <<<<<<<<<<<<<< + * if test_order == min(drop_distance_collection): + * # order 1/2 streams are not statistically different + */ + __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_v_test_order, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3468, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF_SET(__pyx_v_test_order, __pyx_t_4); + __pyx_t_4 = 0; + } + __pyx_L81_break:; + + /* "pygeoprocessing/routing/routing.pyx":3469 + * break + * test_order += 1 + * if test_order == min(drop_distance_collection): # <<<<<<<<<<<<<< + * # order 1/2 streams are not statistically different + * break + */ + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_min, __pyx_v_drop_distance_collection); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3469, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = PyObject_RichCompare(__pyx_v_test_order, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3469, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_21 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3469, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (__pyx_t_21) { + + /* "pygeoprocessing/routing/routing.pyx":3471 + * if test_order == min(drop_distance_collection): + * # order 1/2 streams are not statistically different + * break # <<<<<<<<<<<<<< + * # try to make a reasonable estimate for flow accum + * working_flow_accum_threshold *= 1.25 + */ + goto __pyx_L77_break; + + /* "pygeoprocessing/routing/routing.pyx":3469 + * break + * test_order += 1 + * if test_order == min(drop_distance_collection): # <<<<<<<<<<<<<< + * # order 1/2 streams are not statistically different + * break + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3473 + * break + * # try to make a reasonable estimate for flow accum + * working_flow_accum_threshold *= 1.25 # <<<<<<<<<<<<<< + * # reconstruct stream segments of <= test_order + * for order in range(1, test_order+1): + */ + __pyx_t_8 = PyNumber_InPlaceMultiply(__pyx_v_working_flow_accum_threshold, __pyx_float_1_25); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3473, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF_SET(__pyx_v_working_flow_accum_threshold, __pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3475 + * working_flow_accum_threshold *= 1.25 + * # reconstruct stream segments of <= test_order + * for order in range(1, test_order+1): # <<<<<<<<<<<<<< + * # This will build up a list of kept or reconstructed + * # streams. Other streams will be deleted. + */ + __pyx_t_8 = __Pyx_PyInt_AddObjC(__pyx_v_test_order, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3475, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3475, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_1); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_4, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3475, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (likely(PyList_CheckExact(__pyx_t_8)) || PyTuple_CheckExact(__pyx_t_8)) { + __pyx_t_4 = __pyx_t_8; __Pyx_INCREF(__pyx_t_4); __pyx_t_15 = 0; + __pyx_t_14 = NULL; + } else { + __pyx_t_15 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3475, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_14 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 3475, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + for (;;) { + if (likely(!__pyx_t_14)) { + if (likely(PyList_CheckExact(__pyx_t_4))) { + if (__pyx_t_15 >= PyList_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_8 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_15); __Pyx_INCREF(__pyx_t_8); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 3475, __pyx_L1_error) + #else + __pyx_t_8 = PySequence_ITEM(__pyx_t_4, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3475, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + #endif + } else { + if (__pyx_t_15 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_15); __Pyx_INCREF(__pyx_t_8); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 3475, __pyx_L1_error) + #else + __pyx_t_8 = PySequence_ITEM(__pyx_t_4, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3475, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + #endif + } + } else { + __pyx_t_8 = __pyx_t_14(__pyx_t_4); + if (unlikely(!__pyx_t_8)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 3475, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_8); + } + __Pyx_XDECREF_SET(__pyx_v_order, __pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3478 + * # This will build up a list of kept or reconstructed + * # streams. Other streams will be deleted. + * streams_to_retest = [] # <<<<<<<<<<<<<< + * # The drop distance set will be recalculated + * # dynamically for the next loop + */ + __pyx_t_8 = PyList_New(0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3478, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_XDECREF_SET(__pyx_v_streams_to_retest, ((PyObject*)__pyx_t_8)); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3481 + * # The drop distance set will be recalculated + * # dynamically for the next loop + * if order in max_upstream_flow_accum: # <<<<<<<<<<<<<< + * del max_upstream_flow_accum[order] + * if order in drop_distance_collection: + */ + __pyx_t_21 = (__Pyx_PySequence_ContainsTF(__pyx_v_order, __pyx_v_max_upstream_flow_accum, Py_EQ)); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3481, __pyx_L1_error) + __pyx_t_29 = (__pyx_t_21 != 0); + if (__pyx_t_29) { + + /* "pygeoprocessing/routing/routing.pyx":3482 + * # dynamically for the next loop + * if order in max_upstream_flow_accum: + * del max_upstream_flow_accum[order] # <<<<<<<<<<<<<< + * if order in drop_distance_collection: + * del drop_distance_collection[order] + */ + if (unlikely(PyObject_DelItem(__pyx_v_max_upstream_flow_accum, __pyx_v_order) < 0)) __PYX_ERR(0, 3482, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3481 + * # The drop distance set will be recalculated + * # dynamically for the next loop + * if order in max_upstream_flow_accum: # <<<<<<<<<<<<<< + * del max_upstream_flow_accum[order] + * if order in drop_distance_collection: + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3483 + * if order in max_upstream_flow_accum: + * del max_upstream_flow_accum[order] + * if order in drop_distance_collection: # <<<<<<<<<<<<<< + * del drop_distance_collection[order] + * while streams_by_order[order]: + */ + __pyx_t_29 = (__Pyx_PySequence_ContainsTF(__pyx_v_order, __pyx_v_drop_distance_collection, Py_EQ)); if (unlikely(__pyx_t_29 < 0)) __PYX_ERR(0, 3483, __pyx_L1_error) + __pyx_t_21 = (__pyx_t_29 != 0); + if (__pyx_t_21) { + + /* "pygeoprocessing/routing/routing.pyx":3484 + * del max_upstream_flow_accum[order] + * if order in drop_distance_collection: + * del drop_distance_collection[order] # <<<<<<<<<<<<<< + * while streams_by_order[order]: + * stream_feature = streams_by_order[order].pop() + */ + if (unlikely(PyObject_DelItem(__pyx_v_drop_distance_collection, __pyx_v_order) < 0)) __PYX_ERR(0, 3484, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3483 + * if order in max_upstream_flow_accum: + * del max_upstream_flow_accum[order] + * if order in drop_distance_collection: # <<<<<<<<<<<<<< + * del drop_distance_collection[order] + * while streams_by_order[order]: + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3485 + * if order in drop_distance_collection: + * del drop_distance_collection[order] + * while streams_by_order[order]: # <<<<<<<<<<<<<< + * stream_feature = streams_by_order[order].pop() + * if (stream_feature.GetField('ds_fa') < + */ + while (1) { + __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_streams_by_order, __pyx_v_order); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3485, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_21 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3485, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (!__pyx_t_21) break; + + /* "pygeoprocessing/routing/routing.pyx":3486 + * del drop_distance_collection[order] + * while streams_by_order[order]: + * stream_feature = streams_by_order[order].pop() # <<<<<<<<<<<<<< + * if (stream_feature.GetField('ds_fa') < + * working_flow_accum_threshold): + */ + __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_streams_by_order, __pyx_v_order); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3486, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = __Pyx_PyObject_Pop(__pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3486, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF_SET(__pyx_v_stream_feature, __pyx_t_7); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3487 + * while streams_by_order[order]: + * stream_feature = streams_by_order[order].pop() + * if (stream_feature.GetField('ds_fa') < # <<<<<<<<<<<<<< + * working_flow_accum_threshold): + * # this flow accumulation is too small, it's + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3487, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_7 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_3, __pyx_n_u_ds_fa) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_n_u_ds_fa); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3487, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3488 + * stream_feature = streams_by_order[order].pop() + * if (stream_feature.GetField('ds_fa') < + * working_flow_accum_threshold): # <<<<<<<<<<<<<< + * # this flow accumulation is too small, it's + * # not relevant anymore + */ + __pyx_t_8 = PyObject_RichCompare(__pyx_t_7, __pyx_v_working_flow_accum_threshold, Py_LT); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3487, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3487 + * while streams_by_order[order]: + * stream_feature = streams_by_order[order].pop() + * if (stream_feature.GetField('ds_fa') < # <<<<<<<<<<<<<< + * working_flow_accum_threshold): + * # this flow accumulation is too small, it's + */ + __pyx_t_21 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3487, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (__pyx_t_21) { + + /* "pygeoprocessing/routing/routing.pyx":3492 + * # not relevant anymore + * # remove from connectivity and delete + * _delete_feature( # <<<<<<<<<<<<<< + * stream_feature, stream_layer, + * upstream_to_downstream_id, + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_delete_feature); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3492, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + + /* "pygeoprocessing/routing/routing.pyx":3495 + * stream_feature, stream_layer, + * upstream_to_downstream_id, + * downstream_to_upstream_ids) # <<<<<<<<<<<<<< + * continue + * if (stream_feature.GetField('us_fa') >= + */ + __pyx_t_3 = NULL; + __pyx_t_11 = 0; + 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); + __pyx_t_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[5] = {__pyx_t_3, __pyx_v_stream_feature, __pyx_v_stream_layer, __pyx_v_upstream_to_downstream_id, __pyx_v_downstream_to_upstream_ids}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 4+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3492, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[5] = {__pyx_t_3, __pyx_v_stream_feature, __pyx_v_stream_layer, __pyx_v_upstream_to_downstream_id, __pyx_v_downstream_to_upstream_ids}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 4+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3492, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + { + __pyx_t_2 = PyTuple_New(4+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3492, __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_v_stream_feature); + __Pyx_GIVEREF(__pyx_v_stream_feature); + PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_11, __pyx_v_stream_feature); + __Pyx_INCREF(__pyx_v_stream_layer); + __Pyx_GIVEREF(__pyx_v_stream_layer); + PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_11, __pyx_v_stream_layer); + __Pyx_INCREF(__pyx_v_upstream_to_downstream_id); + __Pyx_GIVEREF(__pyx_v_upstream_to_downstream_id); + PyTuple_SET_ITEM(__pyx_t_2, 2+__pyx_t_11, __pyx_v_upstream_to_downstream_id); + __Pyx_INCREF(__pyx_v_downstream_to_upstream_ids); + __Pyx_GIVEREF(__pyx_v_downstream_to_upstream_ids); + PyTuple_SET_ITEM(__pyx_t_2, 3+__pyx_t_11, __pyx_v_downstream_to_upstream_ids); + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_2, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3492, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3496 + * upstream_to_downstream_id, + * downstream_to_upstream_ids) + * continue # <<<<<<<<<<<<<< + * if (stream_feature.GetField('us_fa') >= + * working_flow_accum_threshold): + */ + goto __pyx_L95_continue; + + /* "pygeoprocessing/routing/routing.pyx":3487 + * while streams_by_order[order]: + * stream_feature = streams_by_order[order].pop() + * if (stream_feature.GetField('ds_fa') < # <<<<<<<<<<<<<< + * working_flow_accum_threshold): + * # this flow accumulation is too small, it's + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3497 + * downstream_to_upstream_ids) + * continue + * if (stream_feature.GetField('us_fa') >= # <<<<<<<<<<<<<< + * working_flow_accum_threshold): + * # this whole stream still fits in the + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3497, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_8 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_2, __pyx_n_u_us_fa) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_n_u_us_fa); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3497, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3498 + * continue + * if (stream_feature.GetField('us_fa') >= + * working_flow_accum_threshold): # <<<<<<<<<<<<<< + * # this whole stream still fits in the + * # threshold so keep it + */ + __pyx_t_7 = PyObject_RichCompare(__pyx_t_8, __pyx_v_working_flow_accum_threshold, Py_GE); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3497, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3497 + * downstream_to_upstream_ids) + * continue + * if (stream_feature.GetField('us_fa') >= # <<<<<<<<<<<<<< + * working_flow_accum_threshold): + * # this whole stream still fits in the + */ + __pyx_t_21 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3497, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (__pyx_t_21) { + + /* "pygeoprocessing/routing/routing.pyx":3502 + * # threshold so keep it + * # add drop distance to working set + * drop_distance_collection[order].append( # <<<<<<<<<<<<<< + * stream_feature.GetField('drop_distance')) + * max_upstream_flow_accum[order] = max( + */ + __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_drop_distance_collection, __pyx_v_order); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3502, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + + /* "pygeoprocessing/routing/routing.pyx":3503 + * # add drop distance to working set + * drop_distance_collection[order].append( + * stream_feature.GetField('drop_distance')) # <<<<<<<<<<<<<< + * max_upstream_flow_accum[order] = max( + * max_upstream_flow_accum[order], + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3503, __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); + } + } + __pyx_t_8 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_n_u_drop_distance) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_n_u_drop_distance); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3503, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3502 + * # threshold so keep it + * # add drop distance to working set + * drop_distance_collection[order].append( # <<<<<<<<<<<<<< + * stream_feature.GetField('drop_distance')) + * max_upstream_flow_accum[order] = max( + */ + __pyx_t_27 = __Pyx_PyObject_Append(__pyx_t_7, __pyx_t_8); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3502, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3506 + * max_upstream_flow_accum[order] = max( + * max_upstream_flow_accum[order], + * stream_feature.GetField('us_fa')) # <<<<<<<<<<<<<< + * stream_layer.SetFeature(stream_feature) + * streams_to_retest.append(stream_feature) + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3506, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_8 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_2, __pyx_n_u_us_fa) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_n_u_us_fa); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3506, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3505 + * stream_feature.GetField('drop_distance')) + * max_upstream_flow_accum[order] = max( + * max_upstream_flow_accum[order], # <<<<<<<<<<<<<< + * stream_feature.GetField('us_fa')) + * stream_layer.SetFeature(stream_feature) + */ + __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_max_upstream_flow_accum, __pyx_v_order); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3505, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + + /* "pygeoprocessing/routing/routing.pyx":3506 + * max_upstream_flow_accum[order] = max( + * max_upstream_flow_accum[order], + * stream_feature.GetField('us_fa')) # <<<<<<<<<<<<<< + * stream_layer.SetFeature(stream_feature) + * streams_to_retest.append(stream_feature) + */ + __pyx_t_3 = PyObject_RichCompare(__pyx_t_8, __pyx_t_7, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3506, __pyx_L1_error) + __pyx_t_21 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3506, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_21) { + __Pyx_INCREF(__pyx_t_8); + __pyx_t_2 = __pyx_t_8; + } else { + __Pyx_INCREF(__pyx_t_7); + __pyx_t_2 = __pyx_t_7; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = __pyx_t_2; + __Pyx_INCREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3504 + * drop_distance_collection[order].append( + * stream_feature.GetField('drop_distance')) + * max_upstream_flow_accum[order] = max( # <<<<<<<<<<<<<< + * max_upstream_flow_accum[order], + * stream_feature.GetField('us_fa')) + */ + if (unlikely(PyObject_SetItem(__pyx_v_max_upstream_flow_accum, __pyx_v_order, __pyx_t_8) < 0)) __PYX_ERR(0, 3504, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3507 + * max_upstream_flow_accum[order], + * stream_feature.GetField('us_fa')) + * stream_layer.SetFeature(stream_feature) # <<<<<<<<<<<<<< + * streams_to_retest.append(stream_feature) + * continue + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_SetFeature); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3507, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_7, __pyx_v_stream_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_stream_feature); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3507, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3508 + * stream_feature.GetField('us_fa')) + * stream_layer.SetFeature(stream_feature) + * streams_to_retest.append(stream_feature) # <<<<<<<<<<<<<< + * continue + * # recalculate stream geometry + */ + __pyx_t_27 = __Pyx_PyList_Append(__pyx_v_streams_to_retest, __pyx_v_stream_feature); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3508, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3509 + * stream_layer.SetFeature(stream_feature) + * streams_to_retest.append(stream_feature) + * continue # <<<<<<<<<<<<<< + * # recalculate stream geometry + * ds_x = stream_feature.GetField('ds_x') + */ + goto __pyx_L95_continue; + + /* "pygeoprocessing/routing/routing.pyx":3497 + * downstream_to_upstream_ids) + * continue + * if (stream_feature.GetField('us_fa') >= # <<<<<<<<<<<<<< + * working_flow_accum_threshold): + * # this whole stream still fits in the + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3511 + * continue + * # recalculate stream geometry + * ds_x = stream_feature.GetField('ds_x') # <<<<<<<<<<<<<< + * ds_y = stream_feature.GetField('ds_y') + * upstream_d8_dir = stream_feature.GetField( + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3511, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_7, __pyx_n_u_ds_x) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_n_u_ds_x); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3511, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF_SET(__pyx_v_ds_x, __pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3512 + * # recalculate stream geometry + * ds_x = stream_feature.GetField('ds_x') + * ds_y = stream_feature.GetField('ds_y') # <<<<<<<<<<<<<< + * upstream_d8_dir = stream_feature.GetField( + * 'upstream_d8_dir') + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3512, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_7, __pyx_n_u_ds_y) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_n_u_ds_y); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3512, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF_SET(__pyx_v_ds_y, __pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3513 + * ds_x = stream_feature.GetField('ds_x') + * ds_y = stream_feature.GetField('ds_y') + * upstream_d8_dir = stream_feature.GetField( # <<<<<<<<<<<<<< + * 'upstream_d8_dir') + * payload = _calculate_stream_geometry( + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3513, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_7, __pyx_n_u_upstream_d8_dir) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_n_u_upstream_d8_dir); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3513, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF_SET(__pyx_v_upstream_d8_dir, __pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3516 + * 'upstream_d8_dir') + * payload = _calculate_stream_geometry( + * ds_x, ds_y, upstream_d8_dir, # <<<<<<<<<<<<<< + * flow_dir_info['geotransform'], n_cols, n_rows, + * flow_accum_managed_raster, + */ + __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_v_ds_x); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3516, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_v_ds_y); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3516, __pyx_L1_error) + __pyx_t_17 = __Pyx_PyInt_As_int(__pyx_v_upstream_d8_dir); if (unlikely((__pyx_t_17 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3516, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3517 + * payload = _calculate_stream_geometry( + * ds_x, ds_y, upstream_d8_dir, + * flow_dir_info['geotransform'], n_cols, n_rows, # <<<<<<<<<<<<<< + * flow_accum_managed_raster, + * flow_dir_managed_raster, flow_nodata, + */ + __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_geotransform); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3517, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + + /* "pygeoprocessing/routing/routing.pyx":3520 + * flow_accum_managed_raster, + * flow_dir_managed_raster, flow_nodata, + * working_flow_accum_threshold, # <<<<<<<<<<<<<< + * coord_to_stream_ids) + * if payload is None: + */ + __pyx_t_18 = __Pyx_PyInt_As_int(__pyx_v_working_flow_accum_threshold); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3520, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3515 + * upstream_d8_dir = stream_feature.GetField( + * 'upstream_d8_dir') + * payload = _calculate_stream_geometry( # <<<<<<<<<<<<<< + * ds_x, ds_y, upstream_d8_dir, + * flow_dir_info['geotransform'], n_cols, n_rows, + */ + __pyx_t_2 = __pyx_f_15pygeoprocessing_7routing_7routing__calculate_stream_geometry(__pyx_t_11, __pyx_t_6, __pyx_t_17, __pyx_t_8, __pyx_v_n_cols, __pyx_v_n_rows, __pyx_v_flow_accum_managed_raster, __pyx_v_flow_dir_managed_raster, __pyx_v_flow_nodata, __pyx_t_18, __pyx_v_coord_to_stream_ids); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3515, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF_SET(__pyx_v_payload, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3522 + * working_flow_accum_threshold, + * coord_to_stream_ids) + * if payload is None: # <<<<<<<<<<<<<< + * _delete_feature( + * stream_feature, stream_layer, + */ + __pyx_t_21 = (__pyx_v_payload == Py_None); + __pyx_t_29 = (__pyx_t_21 != 0); + if (__pyx_t_29) { + + /* "pygeoprocessing/routing/routing.pyx":3523 + * coord_to_stream_ids) + * if payload is None: + * _delete_feature( # <<<<<<<<<<<<<< + * stream_feature, stream_layer, + * upstream_to_downstream_id, + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_delete_feature); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3523, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + + /* "pygeoprocessing/routing/routing.pyx":3526 + * stream_feature, stream_layer, + * upstream_to_downstream_id, + * downstream_to_upstream_ids) # <<<<<<<<<<<<<< + * continue + * (x_u, y_u, ds_x_1, ds_y_1, upstream_id_list, + */ + __pyx_t_7 = NULL; + __pyx_t_18 = 0; + 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); + __pyx_t_18 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[5] = {__pyx_t_7, __pyx_v_stream_feature, __pyx_v_stream_layer, __pyx_v_upstream_to_downstream_id, __pyx_v_downstream_to_upstream_ids}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_18, 4+__pyx_t_18); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3523, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[5] = {__pyx_t_7, __pyx_v_stream_feature, __pyx_v_stream_layer, __pyx_v_upstream_to_downstream_id, __pyx_v_downstream_to_upstream_ids}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_18, 4+__pyx_t_18); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3523, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_3 = PyTuple_New(4+__pyx_t_18); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3523, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_v_stream_feature); + __Pyx_GIVEREF(__pyx_v_stream_feature); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_18, __pyx_v_stream_feature); + __Pyx_INCREF(__pyx_v_stream_layer); + __Pyx_GIVEREF(__pyx_v_stream_layer); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_18, __pyx_v_stream_layer); + __Pyx_INCREF(__pyx_v_upstream_to_downstream_id); + __Pyx_GIVEREF(__pyx_v_upstream_to_downstream_id); + PyTuple_SET_ITEM(__pyx_t_3, 2+__pyx_t_18, __pyx_v_upstream_to_downstream_id); + __Pyx_INCREF(__pyx_v_downstream_to_upstream_ids); + __Pyx_GIVEREF(__pyx_v_downstream_to_upstream_ids); + PyTuple_SET_ITEM(__pyx_t_3, 3+__pyx_t_18, __pyx_v_downstream_to_upstream_ids); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3523, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3527 + * upstream_to_downstream_id, + * downstream_to_upstream_ids) + * continue # <<<<<<<<<<<<<< + * (x_u, y_u, ds_x_1, ds_y_1, upstream_id_list, + * stream_line) = payload + */ + goto __pyx_L95_continue; + + /* "pygeoprocessing/routing/routing.pyx":3522 + * working_flow_accum_threshold, + * coord_to_stream_ids) + * if payload is None: # <<<<<<<<<<<<<< + * _delete_feature( + * stream_feature, stream_layer, + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3529 + * continue + * (x_u, y_u, ds_x_1, ds_y_1, upstream_id_list, + * stream_line) = payload # <<<<<<<<<<<<<< + * # recalculate the drop distance set + * stream_feature.SetGeometry(stream_line) + */ + if ((likely(PyTuple_CheckExact(__pyx_v_payload))) || (PyList_CheckExact(__pyx_v_payload))) { + PyObject* sequence = __pyx_v_payload; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 6)) { + if (size > 6) __Pyx_RaiseTooManyValuesError(6); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 3528, __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_8 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 3); + __pyx_t_30 = PyTuple_GET_ITEM(sequence, 4); + __pyx_t_31 = PyTuple_GET_ITEM(sequence, 5); + } else { + __pyx_t_2 = PyList_GET_ITEM(sequence, 0); + __pyx_t_8 = PyList_GET_ITEM(sequence, 1); + __pyx_t_3 = PyList_GET_ITEM(sequence, 2); + __pyx_t_7 = PyList_GET_ITEM(sequence, 3); + __pyx_t_30 = PyList_GET_ITEM(sequence, 4); + __pyx_t_31 = PyList_GET_ITEM(sequence, 5); + } + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_30); + __Pyx_INCREF(__pyx_t_31); + #else + { + Py_ssize_t i; + PyObject** temps[6] = {&__pyx_t_2,&__pyx_t_8,&__pyx_t_3,&__pyx_t_7,&__pyx_t_30,&__pyx_t_31}; + for (i=0; i < 6; i++) { + PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 3528, __pyx_L1_error) + __Pyx_GOTREF(item); + *(temps[i]) = item; + } + } + #endif + } else { + Py_ssize_t index = -1; + PyObject** temps[6] = {&__pyx_t_2,&__pyx_t_8,&__pyx_t_3,&__pyx_t_7,&__pyx_t_30,&__pyx_t_31}; + __pyx_t_32 = PyObject_GetIter(__pyx_v_payload); if (unlikely(!__pyx_t_32)) __PYX_ERR(0, 3528, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_32); + __pyx_t_10 = Py_TYPE(__pyx_t_32)->tp_iternext; + for (index=0; index < 6; index++) { + PyObject* item = __pyx_t_10(__pyx_t_32); if (unlikely(!item)) goto __pyx_L100_unpacking_failed; + __Pyx_GOTREF(item); + *(temps[index]) = item; + } + if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_32), 6) < 0) __PYX_ERR(0, 3528, __pyx_L1_error) + __pyx_t_10 = NULL; + __Pyx_DECREF(__pyx_t_32); __pyx_t_32 = 0; + goto __pyx_L101_unpacking_done; + __pyx_L100_unpacking_failed:; + __Pyx_DECREF(__pyx_t_32); __pyx_t_32 = 0; + __pyx_t_10 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 3528, __pyx_L1_error) + __pyx_L101_unpacking_done:; + } + + /* "pygeoprocessing/routing/routing.pyx":3528 + * downstream_to_upstream_ids) + * continue + * (x_u, y_u, ds_x_1, ds_y_1, upstream_id_list, # <<<<<<<<<<<<<< + * stream_line) = payload + * # recalculate the drop distance set + */ + __Pyx_XDECREF_SET(__pyx_v_x_u, __pyx_t_2); + __pyx_t_2 = 0; + __Pyx_XDECREF_SET(__pyx_v_y_u, __pyx_t_8); + __pyx_t_8 = 0; + __Pyx_XDECREF_SET(__pyx_v_ds_x_1, __pyx_t_3); + __pyx_t_3 = 0; + __Pyx_XDECREF_SET(__pyx_v_ds_y_1, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_XDECREF_SET(__pyx_v_upstream_id_list, __pyx_t_30); + __pyx_t_30 = 0; + __Pyx_XDECREF_SET(__pyx_v_stream_line, __pyx_t_31); + __pyx_t_31 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3531 + * stream_line) = payload + * # recalculate the drop distance set + * stream_feature.SetGeometry(stream_line) # <<<<<<<<<<<<<< + * upstream_dem = dem_managed_raster.get(x_u, y_u) + * downstream_dem = dem_managed_raster.get( + */ + __pyx_t_30 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetGeometry); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3531, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_30); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_30))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_30); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_30); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_30, function); + } + } + __pyx_t_31 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_30, __pyx_t_7, __pyx_v_stream_line) : __Pyx_PyObject_CallOneArg(__pyx_t_30, __pyx_v_stream_line); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3531, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3532 + * # recalculate the drop distance set + * stream_feature.SetGeometry(stream_line) + * upstream_dem = dem_managed_raster.get(x_u, y_u) # <<<<<<<<<<<<<< + * downstream_dem = dem_managed_raster.get( + * ds_x, ds_y) + */ + __pyx_t_18 = __Pyx_PyInt_As_int(__pyx_v_x_u); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3532, __pyx_L1_error) + __pyx_t_17 = __Pyx_PyInt_As_int(__pyx_v_y_u); if (unlikely((__pyx_t_17 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3532, __pyx_L1_error) + __pyx_v_upstream_dem = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_dem_managed_raster, __pyx_t_18, __pyx_t_17); + + /* "pygeoprocessing/routing/routing.pyx":3534 + * upstream_dem = dem_managed_raster.get(x_u, y_u) + * downstream_dem = dem_managed_raster.get( + * ds_x, ds_y) # <<<<<<<<<<<<<< + * drop_distance = upstream_dem - downstream_dem + * drop_distance_collection[order].append( + */ + __pyx_t_17 = __Pyx_PyInt_As_int(__pyx_v_ds_x); if (unlikely((__pyx_t_17 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3534, __pyx_L1_error) + __pyx_t_18 = __Pyx_PyInt_As_int(__pyx_v_ds_y); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3534, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3533 + * stream_feature.SetGeometry(stream_line) + * upstream_dem = dem_managed_raster.get(x_u, y_u) + * downstream_dem = dem_managed_raster.get( # <<<<<<<<<<<<<< + * ds_x, ds_y) + * drop_distance = upstream_dem - downstream_dem + */ + __pyx_v_downstream_dem = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_dem_managed_raster, __pyx_t_17, __pyx_t_18); + + /* "pygeoprocessing/routing/routing.pyx":3535 + * downstream_dem = dem_managed_raster.get( + * ds_x, ds_y) + * drop_distance = upstream_dem - downstream_dem # <<<<<<<<<<<<<< + * drop_distance_collection[order].append( + * drop_distance) + */ + __pyx_v_drop_distance = (__pyx_v_upstream_dem - __pyx_v_downstream_dem); + + /* "pygeoprocessing/routing/routing.pyx":3536 + * ds_x, ds_y) + * drop_distance = upstream_dem - downstream_dem + * drop_distance_collection[order].append( # <<<<<<<<<<<<<< + * drop_distance) + * stream_feature.SetField( + */ + __pyx_t_31 = __Pyx_PyObject_GetItem(__pyx_v_drop_distance_collection, __pyx_v_order); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3536, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + + /* "pygeoprocessing/routing/routing.pyx":3537 + * drop_distance = upstream_dem - downstream_dem + * drop_distance_collection[order].append( + * drop_distance) # <<<<<<<<<<<<<< + * stream_feature.SetField( + * 'drop_distance', drop_distance) + */ + __pyx_t_30 = PyFloat_FromDouble(__pyx_v_drop_distance); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3537, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_30); + + /* "pygeoprocessing/routing/routing.pyx":3536 + * ds_x, ds_y) + * drop_distance = upstream_dem - downstream_dem + * drop_distance_collection[order].append( # <<<<<<<<<<<<<< + * drop_distance) + * stream_feature.SetField( + */ + __pyx_t_27 = __Pyx_PyObject_Append(__pyx_t_31, __pyx_t_30); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3536, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3538 + * drop_distance_collection[order].append( + * drop_distance) + * stream_feature.SetField( # <<<<<<<<<<<<<< + * 'drop_distance', drop_distance) + * stream_feature.SetField( + */ + __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3538, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + + /* "pygeoprocessing/routing/routing.pyx":3539 + * drop_distance) + * stream_feature.SetField( + * 'drop_distance', drop_distance) # <<<<<<<<<<<<<< + * stream_feature.SetField( + * 'us_fa', flow_accum_managed_raster.get( + */ + __pyx_t_7 = PyFloat_FromDouble(__pyx_v_drop_distance); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3539, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_3 = NULL; + __pyx_t_18 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_31); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_31, function); + __pyx_t_18 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_31)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_drop_distance, __pyx_t_7}; + __pyx_t_30 = __Pyx_PyFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_18, 2+__pyx_t_18); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3538, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_30); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_31)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_drop_distance, __pyx_t_7}; + __pyx_t_30 = __Pyx_PyCFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_18, 2+__pyx_t_18); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3538, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_30); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_8 = PyTuple_New(2+__pyx_t_18); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3538, __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_n_u_drop_distance); + __Pyx_GIVEREF(__pyx_n_u_drop_distance); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_18, __pyx_n_u_drop_distance); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_18, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_30 = __Pyx_PyObject_Call(__pyx_t_31, __pyx_t_8, NULL); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3538, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_30); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3540 + * stream_feature.SetField( + * 'drop_distance', drop_distance) + * stream_feature.SetField( # <<<<<<<<<<<<<< + * 'us_fa', flow_accum_managed_raster.get( + * x_u, y_u)) + */ + __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3540, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + + /* "pygeoprocessing/routing/routing.pyx":3542 + * stream_feature.SetField( + * 'us_fa', flow_accum_managed_raster.get( + * x_u, y_u)) # <<<<<<<<<<<<<< + * stream_feature.SetField( + * 'thresh_fa', working_flow_accum_threshold) + */ + __pyx_t_18 = __Pyx_PyInt_As_int(__pyx_v_x_u); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3542, __pyx_L1_error) + __pyx_t_17 = __Pyx_PyInt_As_int(__pyx_v_y_u); if (unlikely((__pyx_t_17 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3542, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3541 + * 'drop_distance', drop_distance) + * stream_feature.SetField( + * 'us_fa', flow_accum_managed_raster.get( # <<<<<<<<<<<<<< + * x_u, y_u)) + * stream_feature.SetField( + */ + __pyx_t_8 = PyFloat_FromDouble(__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_accum_managed_raster, __pyx_t_18, __pyx_t_17)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3541, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = NULL; + __pyx_t_17 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_31); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_31, function); + __pyx_t_17 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_31)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_us_fa, __pyx_t_8}; + __pyx_t_30 = __Pyx_PyFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3540, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_30); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_31)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_us_fa, __pyx_t_8}; + __pyx_t_30 = __Pyx_PyCFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3540, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_30); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + { + __pyx_t_3 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3540, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_n_u_us_fa); + __Pyx_GIVEREF(__pyx_n_u_us_fa); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_17, __pyx_n_u_us_fa); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_17, __pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_30 = __Pyx_PyObject_Call(__pyx_t_31, __pyx_t_3, NULL); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3540, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_30); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3543 + * 'us_fa', flow_accum_managed_raster.get( + * x_u, y_u)) + * stream_feature.SetField( # <<<<<<<<<<<<<< + * 'thresh_fa', working_flow_accum_threshold) + * stream_feature.SetField( + */ + __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3543, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + + /* "pygeoprocessing/routing/routing.pyx":3544 + * x_u, y_u)) + * stream_feature.SetField( + * 'thresh_fa', working_flow_accum_threshold) # <<<<<<<<<<<<<< + * stream_feature.SetField( + * 'ds_x', ds_x) + */ + __pyx_t_3 = NULL; + __pyx_t_17 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_31); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_31, function); + __pyx_t_17 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_31)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_thresh_fa, __pyx_v_working_flow_accum_threshold}; + __pyx_t_30 = __Pyx_PyFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3543, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_30); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_31)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_thresh_fa, __pyx_v_working_flow_accum_threshold}; + __pyx_t_30 = __Pyx_PyCFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3543, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_30); + } else + #endif + { + __pyx_t_8 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3543, __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_n_u_thresh_fa); + __Pyx_GIVEREF(__pyx_n_u_thresh_fa); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_17, __pyx_n_u_thresh_fa); + __Pyx_INCREF(__pyx_v_working_flow_accum_threshold); + __Pyx_GIVEREF(__pyx_v_working_flow_accum_threshold); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_17, __pyx_v_working_flow_accum_threshold); + __pyx_t_30 = __Pyx_PyObject_Call(__pyx_t_31, __pyx_t_8, NULL); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3543, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_30); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3545 + * stream_feature.SetField( + * 'thresh_fa', working_flow_accum_threshold) + * stream_feature.SetField( # <<<<<<<<<<<<<< + * 'ds_x', ds_x) + * stream_feature.SetField( + */ + __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3545, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + + /* "pygeoprocessing/routing/routing.pyx":3546 + * 'thresh_fa', working_flow_accum_threshold) + * stream_feature.SetField( + * 'ds_x', ds_x) # <<<<<<<<<<<<<< + * stream_feature.SetField( + * 'ds_y', ds_y) + */ + __pyx_t_8 = NULL; + __pyx_t_17 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_31); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_31, function); + __pyx_t_17 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_31)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_n_u_ds_x, __pyx_v_ds_x}; + __pyx_t_30 = __Pyx_PyFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3545, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_30); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_31)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_n_u_ds_x, __pyx_v_ds_x}; + __pyx_t_30 = __Pyx_PyCFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3545, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_30); + } else + #endif + { + __pyx_t_3 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3545, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (__pyx_t_8) { + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8); __pyx_t_8 = NULL; + } + __Pyx_INCREF(__pyx_n_u_ds_x); + __Pyx_GIVEREF(__pyx_n_u_ds_x); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_17, __pyx_n_u_ds_x); + __Pyx_INCREF(__pyx_v_ds_x); + __Pyx_GIVEREF(__pyx_v_ds_x); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_17, __pyx_v_ds_x); + __pyx_t_30 = __Pyx_PyObject_Call(__pyx_t_31, __pyx_t_3, NULL); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3545, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_30); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3547 + * stream_feature.SetField( + * 'ds_x', ds_x) + * stream_feature.SetField( # <<<<<<<<<<<<<< + * 'ds_y', ds_y) + * stream_feature.SetField( + */ + __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3547, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + + /* "pygeoprocessing/routing/routing.pyx":3548 + * 'ds_x', ds_x) + * stream_feature.SetField( + * 'ds_y', ds_y) # <<<<<<<<<<<<<< + * stream_feature.SetField( + * 'ds_x_1', ds_x_1) + */ + __pyx_t_3 = NULL; + __pyx_t_17 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_31); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_31, function); + __pyx_t_17 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_31)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_ds_y, __pyx_v_ds_y}; + __pyx_t_30 = __Pyx_PyFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3547, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_30); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_31)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_ds_y, __pyx_v_ds_y}; + __pyx_t_30 = __Pyx_PyCFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3547, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_30); + } else + #endif + { + __pyx_t_8 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3547, __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_n_u_ds_y); + __Pyx_GIVEREF(__pyx_n_u_ds_y); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_17, __pyx_n_u_ds_y); + __Pyx_INCREF(__pyx_v_ds_y); + __Pyx_GIVEREF(__pyx_v_ds_y); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_17, __pyx_v_ds_y); + __pyx_t_30 = __Pyx_PyObject_Call(__pyx_t_31, __pyx_t_8, NULL); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3547, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_30); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3549 + * stream_feature.SetField( + * 'ds_y', ds_y) + * stream_feature.SetField( # <<<<<<<<<<<<<< + * 'ds_x_1', ds_x_1) + * stream_feature.SetField( + */ + __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3549, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + + /* "pygeoprocessing/routing/routing.pyx":3550 + * 'ds_y', ds_y) + * stream_feature.SetField( + * 'ds_x_1', ds_x_1) # <<<<<<<<<<<<<< + * stream_feature.SetField( + * 'ds_y_1', ds_y_1) + */ + __pyx_t_8 = NULL; + __pyx_t_17 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_31); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_31, function); + __pyx_t_17 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_31)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_n_u_ds_x_1, __pyx_v_ds_x_1}; + __pyx_t_30 = __Pyx_PyFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3549, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_30); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_31)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_n_u_ds_x_1, __pyx_v_ds_x_1}; + __pyx_t_30 = __Pyx_PyCFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3549, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_30); + } else + #endif + { + __pyx_t_3 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3549, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (__pyx_t_8) { + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8); __pyx_t_8 = NULL; + } + __Pyx_INCREF(__pyx_n_u_ds_x_1); + __Pyx_GIVEREF(__pyx_n_u_ds_x_1); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_17, __pyx_n_u_ds_x_1); + __Pyx_INCREF(__pyx_v_ds_x_1); + __Pyx_GIVEREF(__pyx_v_ds_x_1); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_17, __pyx_v_ds_x_1); + __pyx_t_30 = __Pyx_PyObject_Call(__pyx_t_31, __pyx_t_3, NULL); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3549, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_30); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3551 + * stream_feature.SetField( + * 'ds_x_1', ds_x_1) + * stream_feature.SetField( # <<<<<<<<<<<<<< + * 'ds_y_1', ds_y_1) + * stream_feature.SetField('us_x', x_u) + */ + __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3551, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + + /* "pygeoprocessing/routing/routing.pyx":3552 + * 'ds_x_1', ds_x_1) + * stream_feature.SetField( + * 'ds_y_1', ds_y_1) # <<<<<<<<<<<<<< + * stream_feature.SetField('us_x', x_u) + * stream_feature.SetField('us_y', y_u) + */ + __pyx_t_3 = NULL; + __pyx_t_17 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_31); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_31, function); + __pyx_t_17 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_31)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_ds_y_1, __pyx_v_ds_y_1}; + __pyx_t_30 = __Pyx_PyFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3551, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_30); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_31)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_ds_y_1, __pyx_v_ds_y_1}; + __pyx_t_30 = __Pyx_PyCFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3551, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_30); + } else + #endif + { + __pyx_t_8 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3551, __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_n_u_ds_y_1); + __Pyx_GIVEREF(__pyx_n_u_ds_y_1); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_17, __pyx_n_u_ds_y_1); + __Pyx_INCREF(__pyx_v_ds_y_1); + __Pyx_GIVEREF(__pyx_v_ds_y_1); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_17, __pyx_v_ds_y_1); + __pyx_t_30 = __Pyx_PyObject_Call(__pyx_t_31, __pyx_t_8, NULL); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3551, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_30); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3553 + * stream_feature.SetField( + * 'ds_y_1', ds_y_1) + * stream_feature.SetField('us_x', x_u) # <<<<<<<<<<<<<< + * stream_feature.SetField('us_y', y_u) + * + */ + __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3553, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + __pyx_t_8 = NULL; + __pyx_t_17 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_31); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_31, function); + __pyx_t_17 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_31)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_n_u_us_x, __pyx_v_x_u}; + __pyx_t_30 = __Pyx_PyFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3553, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_30); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_31)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_n_u_us_x, __pyx_v_x_u}; + __pyx_t_30 = __Pyx_PyCFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3553, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_30); + } else + #endif + { + __pyx_t_3 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3553, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (__pyx_t_8) { + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8); __pyx_t_8 = NULL; + } + __Pyx_INCREF(__pyx_n_u_us_x); + __Pyx_GIVEREF(__pyx_n_u_us_x); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_17, __pyx_n_u_us_x); + __Pyx_INCREF(__pyx_v_x_u); + __Pyx_GIVEREF(__pyx_v_x_u); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_17, __pyx_v_x_u); + __pyx_t_30 = __Pyx_PyObject_Call(__pyx_t_31, __pyx_t_3, NULL); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3553, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_30); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3554 + * 'ds_y_1', ds_y_1) + * stream_feature.SetField('us_x', x_u) + * stream_feature.SetField('us_y', y_u) # <<<<<<<<<<<<<< + * + * streams_to_retest.append(stream_feature) + */ + __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3554, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + __pyx_t_3 = NULL; + __pyx_t_17 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_31); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_31, function); + __pyx_t_17 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_31)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_us_y, __pyx_v_y_u}; + __pyx_t_30 = __Pyx_PyFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3554, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_30); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_31)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_us_y, __pyx_v_y_u}; + __pyx_t_30 = __Pyx_PyCFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3554, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_30); + } else + #endif + { + __pyx_t_8 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3554, __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_n_u_us_y); + __Pyx_GIVEREF(__pyx_n_u_us_y); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_17, __pyx_n_u_us_y); + __Pyx_INCREF(__pyx_v_y_u); + __Pyx_GIVEREF(__pyx_v_y_u); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_17, __pyx_v_y_u); + __pyx_t_30 = __Pyx_PyObject_Call(__pyx_t_31, __pyx_t_8, NULL); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3554, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_30); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3556 + * stream_feature.SetField('us_y', y_u) + * + * streams_to_retest.append(stream_feature) # <<<<<<<<<<<<<< + * stream_layer.SetFeature(stream_feature) + * + */ + __pyx_t_27 = __Pyx_PyList_Append(__pyx_v_streams_to_retest, __pyx_v_stream_feature); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3556, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3557 + * + * streams_to_retest.append(stream_feature) + * stream_layer.SetFeature(stream_feature) # <<<<<<<<<<<<<< + * + * streams_by_order[order] = streams_to_retest + */ + __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_SetFeature); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3557, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_31); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_31, function); + } + } + __pyx_t_30 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_31, __pyx_t_8, __pyx_v_stream_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_31, __pyx_v_stream_feature); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3557, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_30); + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + __pyx_L95_continue:; + } + + /* "pygeoprocessing/routing/routing.pyx":3559 + * stream_layer.SetFeature(stream_feature) + * + * streams_by_order[order] = streams_to_retest # <<<<<<<<<<<<<< + * working_river_id += 1 + * + */ + if (unlikely(PyObject_SetItem(__pyx_v_streams_by_order, __pyx_v_order, __pyx_v_streams_to_retest) < 0)) __PYX_ERR(0, 3559, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3475 + * working_flow_accum_threshold *= 1.25 + * # reconstruct stream segments of <= test_order + * for order in range(1, test_order+1): # <<<<<<<<<<<<<< + * # This will build up a list of kept or reconstructed + * # streams. Other streams will be deleted. + */ + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __pyx_L77_break:; + + /* "pygeoprocessing/routing/routing.pyx":3560 + * + * streams_by_order[order] = streams_to_retest + * working_river_id += 1 # <<<<<<<<<<<<<< + * + * LOGGER.info( + */ + __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_v_working_river_id, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3560, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF_SET(__pyx_v_working_river_id, __pyx_t_4); + __pyx_t_4 = 0; + } + __pyx_L71:; + } + + /* "pygeoprocessing/routing/routing.pyx":3398 + * '(extract_strahler_streams_d8): determine rivers') + * working_river_id = 0 + * for outlet_index, outlet_fid in enumerate(outlet_fid_list): # <<<<<<<<<<<<<< + * # walk upstream starting from this outlet to search for rivers + * # defined as stream segments whose order is <= river_order. Note it + */ + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3562 + * working_river_id += 1 + * + * LOGGER.info( # <<<<<<<<<<<<<< + * '(extract_strahler_streams_d8): ' + * 'flow accumulation adjustment complete') + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_info); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + 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_9 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, __pyx_kp_u_extract_strahler_streams_d8_flo_2) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_extract_strahler_streams_d8_flo_2); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3566 + * 'flow accumulation adjustment complete') + * + * stream_layer.DeleteField( # <<<<<<<<<<<<<< + * stream_layer.FindFieldIndex('upstream_d8_dir', 1)) + * stream_layer.CommitTransaction() + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_DeleteField); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3566, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "pygeoprocessing/routing/routing.pyx":3567 + * + * stream_layer.DeleteField( + * stream_layer.FindFieldIndex('upstream_d8_dir', 1)) # <<<<<<<<<<<<<< + * stream_layer.CommitTransaction() + * stream_layer.StartTransaction() + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_FindFieldIndex); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3567, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_30 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3567, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_30); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_9 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, __pyx_t_30) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_30); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3566, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3568 + * stream_layer.DeleteField( + * stream_layer.FindFieldIndex('upstream_d8_dir', 1)) + * stream_layer.CommitTransaction() # <<<<<<<<<<<<<< + * stream_layer.StartTransaction() + * LOGGER.info( + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CommitTransaction); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3568, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_30 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_30 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_30)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_30); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_9 = (__pyx_t_30) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_30) : __Pyx_PyObject_CallNoArg(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_30); __pyx_t_30 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3568, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3569 + * stream_layer.FindFieldIndex('upstream_d8_dir', 1)) + * stream_layer.CommitTransaction() + * stream_layer.StartTransaction() # <<<<<<<<<<<<<< + * LOGGER.info( + * '(extract_strahler_streams_d8): ' + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_StartTransaction); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3569, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_30 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_30 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_30)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_30); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_9 = (__pyx_t_30) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_30) : __Pyx_PyObject_CallNoArg(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_30); __pyx_t_30 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3569, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3570 + * stream_layer.CommitTransaction() + * stream_layer.StartTransaction() + * LOGGER.info( # <<<<<<<<<<<<<< + * '(extract_strahler_streams_d8): ' + * 'final pass on stream order and geometry') + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3570, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_30 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_info); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3570, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_30); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_30))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_30); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_30); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_30, function); + } + } + __pyx_t_9 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_30, __pyx_t_4, __pyx_kp_u_extract_strahler_streams_d8_fin) : __Pyx_PyObject_CallOneArg(__pyx_t_30, __pyx_kp_u_extract_strahler_streams_d8_fin); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3570, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3575 + * + * # seed the stack with all the upstream orders + * working_stack = [ # <<<<<<<<<<<<<< + * fid for fid in downstream_to_upstream_ids if + * not downstream_to_upstream_ids[fid]] + */ + { /* enter inner scope */ + __pyx_t_9 = PyList_New(0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3575, __pyx_L104_error) + __Pyx_GOTREF(__pyx_t_9); + + /* "pygeoprocessing/routing/routing.pyx":3576 + * # seed the stack with all the upstream orders + * working_stack = [ + * fid for fid in downstream_to_upstream_ids if # <<<<<<<<<<<<<< + * not downstream_to_upstream_ids[fid]] + * fid_to_order = {} + */ + __pyx_t_13 = 0; + __pyx_t_4 = __Pyx_dict_iterator(__pyx_v_downstream_to_upstream_ids, 1, ((PyObject *)NULL), (&__pyx_t_15), (&__pyx_t_17)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3576, __pyx_L104_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_30); + __pyx_t_30 = __pyx_t_4; + __pyx_t_4 = 0; + while (1) { + __pyx_t_18 = __Pyx_dict_iter_next(__pyx_t_30, __pyx_t_15, &__pyx_t_13, &__pyx_t_4, NULL, NULL, __pyx_t_17); + if (unlikely(__pyx_t_18 == 0)) break; + if (unlikely(__pyx_t_18 == -1)) __PYX_ERR(0, 3576, __pyx_L104_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XDECREF_SET(__pyx_8genexpr1__pyx_v_fid, __pyx_t_4); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3577 + * working_stack = [ + * fid for fid in downstream_to_upstream_ids if + * not downstream_to_upstream_ids[fid]] # <<<<<<<<<<<<<< + * fid_to_order = {} + * processed_segments = 0 + */ + __pyx_t_4 = __Pyx_PyDict_GetItem(__pyx_v_downstream_to_upstream_ids, __pyx_8genexpr1__pyx_v_fid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3577, __pyx_L104_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_29 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_29 < 0)) __PYX_ERR(0, 3577, __pyx_L104_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_21 = ((!__pyx_t_29) != 0); + + /* "pygeoprocessing/routing/routing.pyx":3576 + * # seed the stack with all the upstream orders + * working_stack = [ + * fid for fid in downstream_to_upstream_ids if # <<<<<<<<<<<<<< + * not downstream_to_upstream_ids[fid]] + * fid_to_order = {} + */ + if (__pyx_t_21) { + if (unlikely(__Pyx_ListComp_Append(__pyx_t_9, (PyObject*)__pyx_8genexpr1__pyx_v_fid))) __PYX_ERR(0, 3575, __pyx_L104_error) + } + } + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + __Pyx_XDECREF(__pyx_8genexpr1__pyx_v_fid); __pyx_8genexpr1__pyx_v_fid = 0; + goto __pyx_L108_exit_scope; + __pyx_L104_error:; + __Pyx_XDECREF(__pyx_8genexpr1__pyx_v_fid); __pyx_8genexpr1__pyx_v_fid = 0; + goto __pyx_L1_error; + __pyx_L108_exit_scope:; + } /* exit inner scope */ + __pyx_v_working_stack = ((PyObject*)__pyx_t_9); + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3578 + * fid for fid in downstream_to_upstream_ids if + * not downstream_to_upstream_ids[fid]] + * fid_to_order = {} # <<<<<<<<<<<<<< + * processed_segments = 0 + * segments_to_process = len(downstream_to_upstream_ids) + */ + __pyx_t_9 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3578, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_v_fid_to_order = ((PyObject*)__pyx_t_9); + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3579 + * not downstream_to_upstream_ids[fid]] + * fid_to_order = {} + * processed_segments = 0 # <<<<<<<<<<<<<< + * segments_to_process = len(downstream_to_upstream_ids) + * deleted_set = set() + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_v_processed_segments = __pyx_int_0; + + /* "pygeoprocessing/routing/routing.pyx":3580 + * fid_to_order = {} + * processed_segments = 0 + * segments_to_process = len(downstream_to_upstream_ids) # <<<<<<<<<<<<<< + * deleted_set = set() + * while working_stack: + */ + __pyx_t_15 = PyDict_Size(__pyx_v_downstream_to_upstream_ids); if (unlikely(__pyx_t_15 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3580, __pyx_L1_error) + __pyx_v_segments_to_process = __pyx_t_15; + + /* "pygeoprocessing/routing/routing.pyx":3581 + * processed_segments = 0 + * segments_to_process = len(downstream_to_upstream_ids) + * deleted_set = set() # <<<<<<<<<<<<<< + * while working_stack: + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: + */ + __pyx_t_9 = PySet_New(0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3581, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_v_deleted_set = ((PyObject*)__pyx_t_9); + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3582 + * segments_to_process = len(downstream_to_upstream_ids) + * deleted_set = set() + * while working_stack: # <<<<<<<<<<<<<< + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: + * LOGGER.info( + */ + while (1) { + __pyx_t_21 = (PyList_GET_SIZE(__pyx_v_working_stack) != 0); + if (!__pyx_t_21) break; + + /* "pygeoprocessing/routing/routing.pyx":3583 + * deleted_set = set() + * while working_stack: + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * LOGGER.info( + * '(extract_strahler_streams_d8): ' + */ + __pyx_t_21 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); + if (__pyx_t_21) { + + /* "pygeoprocessing/routing/routing.pyx":3584 + * while working_stack: + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: + * LOGGER.info( # <<<<<<<<<<<<<< + * '(extract_strahler_streams_d8): ' + * 'final pass on stream order ' + */ + __Pyx_GetModuleGlobalName(__pyx_t_30, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3584, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_30); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_30, __pyx_n_s_info); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3584, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3585 + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: + * LOGGER.info( + * '(extract_strahler_streams_d8): ' # <<<<<<<<<<<<<< + * 'final pass on stream order ' + * f'{processed_segments} of {segments_to_process} ' + */ + __pyx_t_30 = PyTuple_New(5); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3585, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_30); + __pyx_t_15 = 0; + __pyx_t_16 = 127; + __Pyx_INCREF(__pyx_kp_u_extract_strahler_streams_d8_fin_2); + __pyx_t_15 += 58; + __Pyx_GIVEREF(__pyx_kp_u_extract_strahler_streams_d8_fin_2); + PyTuple_SET_ITEM(__pyx_t_30, 0, __pyx_kp_u_extract_strahler_streams_d8_fin_2); + + /* "pygeoprocessing/routing/routing.pyx":3587 + * '(extract_strahler_streams_d8): ' + * 'final pass on stream order ' + * f'{processed_segments} of {segments_to_process} ' # <<<<<<<<<<<<<< + * 'segments complete') + * last_log_time = ctime(NULL) + */ + __pyx_t_1 = __Pyx_PyObject_FormatSimple(__pyx_v_processed_segments, __pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3587, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_16 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) > __pyx_t_16) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) : __pyx_t_16; + __pyx_t_15 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_30, 1, __pyx_t_1); + __pyx_t_1 = 0; + __Pyx_INCREF(__pyx_kp_u_of); + __pyx_t_15 += 4; + __Pyx_GIVEREF(__pyx_kp_u_of); + PyTuple_SET_ITEM(__pyx_t_30, 2, __pyx_kp_u_of); + __pyx_t_1 = __Pyx_PyUnicode_From_Py_ssize_t(__pyx_v_segments_to_process, 0, ' ', 'd'); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3587, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_15 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_30, 3, __pyx_t_1); + __pyx_t_1 = 0; + __Pyx_INCREF(__pyx_kp_u_segments_complete); + __pyx_t_15 += 18; + __Pyx_GIVEREF(__pyx_kp_u_segments_complete); + PyTuple_SET_ITEM(__pyx_t_30, 4, __pyx_kp_u_segments_complete); + + /* "pygeoprocessing/routing/routing.pyx":3585 + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: + * LOGGER.info( + * '(extract_strahler_streams_d8): ' # <<<<<<<<<<<<<< + * 'final pass on stream order ' + * f'{processed_segments} of {segments_to_process} ' + */ + __pyx_t_1 = __Pyx_PyUnicode_Join(__pyx_t_30, 5, __pyx_t_15, __pyx_t_16); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3585, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + __pyx_t_30 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_30 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_30)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_30); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_9 = (__pyx_t_30) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_30, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_1); + __Pyx_XDECREF(__pyx_t_30); __pyx_t_30 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3584, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3589 + * f'{processed_segments} of {segments_to_process} ' + * 'segments complete') + * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< + * processed_segments += 1 + * + */ + __pyx_v_last_log_time = time(NULL); + + /* "pygeoprocessing/routing/routing.pyx":3583 + * deleted_set = set() + * while working_stack: + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * LOGGER.info( + * '(extract_strahler_streams_d8): ' + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3590 + * 'segments complete') + * last_log_time = ctime(NULL) + * processed_segments += 1 # <<<<<<<<<<<<<< + * + * working_fid = working_stack.pop() + */ + __pyx_t_9 = __Pyx_PyInt_AddObjC(__pyx_v_processed_segments, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3590, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF_SET(__pyx_v_processed_segments, __pyx_t_9); + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3592 + * processed_segments += 1 + * + * working_fid = working_stack.pop() # <<<<<<<<<<<<<< + * # invariant: working_fid and all upstream are processed, order not set + * + */ + __pyx_t_9 = __Pyx_PyList_Pop(__pyx_v_working_stack); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3592, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_XDECREF_SET(__pyx_v_working_fid, __pyx_t_9); + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3595 + * # invariant: working_fid and all upstream are processed, order not set + * + * upstream_fid_list = downstream_to_upstream_ids[working_fid] # <<<<<<<<<<<<<< + * if upstream_fid_list: + * order_count = collections.defaultdict(int) + */ + __pyx_t_9 = __Pyx_PyDict_GetItem(__pyx_v_downstream_to_upstream_ids, __pyx_v_working_fid); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3595, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_XDECREF_SET(__pyx_v_upstream_fid_list, __pyx_t_9); + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3596 + * + * upstream_fid_list = downstream_to_upstream_ids[working_fid] + * if upstream_fid_list: # <<<<<<<<<<<<<< + * order_count = collections.defaultdict(int) + * for upstream_fid in upstream_fid_list: + */ + __pyx_t_21 = __Pyx_PyObject_IsTrue(__pyx_v_upstream_fid_list); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3596, __pyx_L1_error) + if (__pyx_t_21) { + + /* "pygeoprocessing/routing/routing.pyx":3597 + * upstream_fid_list = downstream_to_upstream_ids[working_fid] + * if upstream_fid_list: + * order_count = collections.defaultdict(int) # <<<<<<<<<<<<<< + * for upstream_fid in upstream_fid_list: + * order_count[fid_to_order[upstream_fid]] += 1 + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_collections); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3597, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3597, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __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); + } + } + __pyx_t_9 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_4, ((PyObject *)(&PyInt_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_1, ((PyObject *)(&PyInt_Type))); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3597, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_order_count, __pyx_t_9); + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3598 + * if upstream_fid_list: + * order_count = collections.defaultdict(int) + * for upstream_fid in upstream_fid_list: # <<<<<<<<<<<<<< + * order_count[fid_to_order[upstream_fid]] += 1 + * working_order = max(order_count) + */ + if (likely(PyList_CheckExact(__pyx_v_upstream_fid_list)) || PyTuple_CheckExact(__pyx_v_upstream_fid_list)) { + __pyx_t_9 = __pyx_v_upstream_fid_list; __Pyx_INCREF(__pyx_t_9); __pyx_t_15 = 0; + __pyx_t_14 = NULL; + } else { + __pyx_t_15 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_v_upstream_fid_list); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3598, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_14 = Py_TYPE(__pyx_t_9)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 3598, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_14)) { + if (likely(PyList_CheckExact(__pyx_t_9))) { + if (__pyx_t_15 >= PyList_GET_SIZE(__pyx_t_9)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_15); __Pyx_INCREF(__pyx_t_1); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 3598, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_9, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3598, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } else { + if (__pyx_t_15 >= PyTuple_GET_SIZE(__pyx_t_9)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_15); __Pyx_INCREF(__pyx_t_1); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 3598, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_9, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3598, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } + } else { + __pyx_t_1 = __pyx_t_14(__pyx_t_9); + 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, 3598, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XDECREF_SET(__pyx_v_upstream_fid, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3599 + * order_count = collections.defaultdict(int) + * for upstream_fid in upstream_fid_list: + * order_count[fid_to_order[upstream_fid]] += 1 # <<<<<<<<<<<<<< + * working_order = max(order_count) + * if order_count[working_order] > 1: + */ + __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_fid_to_order, __pyx_v_upstream_fid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3599, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_order_count, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3599, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_30 = __Pyx_PyInt_AddObjC(__pyx_t_4, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3599, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_30); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(PyObject_SetItem(__pyx_v_order_count, __pyx_t_1, __pyx_t_30) < 0)) __PYX_ERR(0, 3599, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3598 + * if upstream_fid_list: + * order_count = collections.defaultdict(int) + * for upstream_fid in upstream_fid_list: # <<<<<<<<<<<<<< + * order_count[fid_to_order[upstream_fid]] += 1 + * working_order = max(order_count) + */ + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3600 + * for upstream_fid in upstream_fid_list: + * order_count[fid_to_order[upstream_fid]] += 1 + * working_order = max(order_count) # <<<<<<<<<<<<<< + * if order_count[working_order] > 1: + * working_order += 1 + */ + __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_max, __pyx_v_order_count); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3600, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_XDECREF_SET(__pyx_v_working_order, __pyx_t_9); + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3601 + * order_count[fid_to_order[upstream_fid]] += 1 + * working_order = max(order_count) + * if order_count[working_order] > 1: # <<<<<<<<<<<<<< + * working_order += 1 + * fid_to_order[working_fid] = working_order + */ + __pyx_t_9 = __Pyx_PyObject_GetItem(__pyx_v_order_count, __pyx_v_working_order); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3601, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_1 = PyObject_RichCompare(__pyx_t_9, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3601, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_21 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3601, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_21) { + + /* "pygeoprocessing/routing/routing.pyx":3602 + * working_order = max(order_count) + * if order_count[working_order] > 1: + * working_order += 1 # <<<<<<<<<<<<<< + * fid_to_order[working_fid] = working_order + * else: + */ + __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_v_working_order, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3602, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF_SET(__pyx_v_working_order, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3601 + * order_count[fid_to_order[upstream_fid]] += 1 + * working_order = max(order_count) + * if order_count[working_order] > 1: # <<<<<<<<<<<<<< + * working_order += 1 + * fid_to_order[working_fid] = working_order + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3603 + * if order_count[working_order] > 1: + * working_order += 1 + * fid_to_order[working_fid] = working_order # <<<<<<<<<<<<<< + * else: + * fid_to_order[working_fid] = 1 + */ + if (unlikely(PyDict_SetItem(__pyx_v_fid_to_order, __pyx_v_working_fid, __pyx_v_working_order) < 0)) __PYX_ERR(0, 3603, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3596 + * + * upstream_fid_list = downstream_to_upstream_ids[working_fid] + * if upstream_fid_list: # <<<<<<<<<<<<<< + * order_count = collections.defaultdict(int) + * for upstream_fid in upstream_fid_list: + */ + goto __pyx_L112; + } + + /* "pygeoprocessing/routing/routing.pyx":3605 + * fid_to_order[working_fid] = working_order + * else: + * fid_to_order[working_fid] = 1 # <<<<<<<<<<<<<< + * + * working_feature = stream_layer.GetFeature(working_fid) + */ + /*else*/ { + if (unlikely(PyDict_SetItem(__pyx_v_fid_to_order, __pyx_v_working_fid, __pyx_int_1) < 0)) __PYX_ERR(0, 3605, __pyx_L1_error) + } + __pyx_L112:; + + /* "pygeoprocessing/routing/routing.pyx":3607 + * fid_to_order[working_fid] = 1 + * + * working_feature = stream_layer.GetFeature(working_fid) # <<<<<<<<<<<<<< + * working_feature.SetField('order', fid_to_order[working_fid]) + * stream_layer.SetFeature(working_feature) + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3607, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_30 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_30 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_30)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_30); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + } + } + __pyx_t_1 = (__pyx_t_30) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_30, __pyx_v_working_fid) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_working_fid); + __Pyx_XDECREF(__pyx_t_30); __pyx_t_30 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3607, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_XDECREF_SET(__pyx_v_working_feature, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3608 + * + * working_feature = stream_layer.GetFeature(working_fid) + * working_feature.SetField('order', fid_to_order[working_fid]) # <<<<<<<<<<<<<< + * stream_layer.SetFeature(working_feature) + * working_feature = None + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3608, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_30 = __Pyx_PyDict_GetItem(__pyx_v_fid_to_order, __pyx_v_working_fid); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3608, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_30); + __pyx_t_4 = NULL; + __pyx_t_17 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + __pyx_t_17 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_order, __pyx_t_30}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3608, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_order, __pyx_t_30}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3608, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + } else + #endif + { + __pyx_t_31 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3608, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + if (__pyx_t_4) { + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_31, 0, __pyx_t_4); __pyx_t_4 = NULL; + } + __Pyx_INCREF(__pyx_n_u_order); + __Pyx_GIVEREF(__pyx_n_u_order); + PyTuple_SET_ITEM(__pyx_t_31, 0+__pyx_t_17, __pyx_n_u_order); + __Pyx_GIVEREF(__pyx_t_30); + PyTuple_SET_ITEM(__pyx_t_31, 1+__pyx_t_17, __pyx_t_30); + __pyx_t_30 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_31, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3608, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3609 + * working_feature = stream_layer.GetFeature(working_fid) + * working_feature.SetField('order', fid_to_order[working_fid]) + * stream_layer.SetFeature(working_feature) # <<<<<<<<<<<<<< + * working_feature = None + * + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_SetFeature); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3609, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_31 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_31 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_31)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_31); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + } + } + __pyx_t_1 = (__pyx_t_31) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_31, __pyx_v_working_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_working_feature); + __Pyx_XDECREF(__pyx_t_31); __pyx_t_31 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3609, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3610 + * working_feature.SetField('order', fid_to_order[working_fid]) + * stream_layer.SetFeature(working_feature) + * working_feature = None # <<<<<<<<<<<<<< + * + * if working_fid not in upstream_to_downstream_id: + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_working_feature, Py_None); + + /* "pygeoprocessing/routing/routing.pyx":3612 + * working_feature = None + * + * if working_fid not in upstream_to_downstream_id: # <<<<<<<<<<<<<< + * # nothing downstream so it's done + * continue + */ + __pyx_t_21 = (__Pyx_PyDict_ContainsTF(__pyx_v_working_fid, __pyx_v_upstream_to_downstream_id, Py_NE)); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3612, __pyx_L1_error) + __pyx_t_29 = (__pyx_t_21 != 0); + if (__pyx_t_29) { + + /* "pygeoprocessing/routing/routing.pyx":3614 + * if working_fid not in upstream_to_downstream_id: + * # nothing downstream so it's done + * continue # <<<<<<<<<<<<<< + * + * downstream_fid = upstream_to_downstream_id[working_fid] + */ + goto __pyx_L109_continue; + + /* "pygeoprocessing/routing/routing.pyx":3612 + * working_feature = None + * + * if working_fid not in upstream_to_downstream_id: # <<<<<<<<<<<<<< + * # nothing downstream so it's done + * continue + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3616 + * continue + * + * downstream_fid = upstream_to_downstream_id[working_fid] # <<<<<<<<<<<<<< + * connected_fids = downstream_to_upstream_ids[downstream_fid] + * if len(connected_fids) == 1: + */ + __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_upstream_to_downstream_id, __pyx_v_working_fid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3616, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_XDECREF_SET(__pyx_v_downstream_fid, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3617 + * + * downstream_fid = upstream_to_downstream_id[working_fid] + * connected_fids = downstream_to_upstream_ids[downstream_fid] # <<<<<<<<<<<<<< + * if len(connected_fids) == 1: + * # There's only one downstream, join it. + */ + __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_downstream_to_upstream_ids, __pyx_v_downstream_fid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3617, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_XDECREF_SET(__pyx_v_connected_fids, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3618 + * downstream_fid = upstream_to_downstream_id[working_fid] + * connected_fids = downstream_to_upstream_ids[downstream_fid] + * if len(connected_fids) == 1: # <<<<<<<<<<<<<< + * # There's only one downstream, join it. + * # Downstream order is the same as upstream + */ + __pyx_t_15 = PyObject_Length(__pyx_v_connected_fids); if (unlikely(__pyx_t_15 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3618, __pyx_L1_error) + __pyx_t_29 = ((__pyx_t_15 == 1) != 0); + if (__pyx_t_29) { + + /* "pygeoprocessing/routing/routing.pyx":3621 + * # There's only one downstream, join it. + * # Downstream order is the same as upstream + * fid_to_order[downstream_fid] = fid_to_order[working_fid] # <<<<<<<<<<<<<< + * del fid_to_order[working_fid] + * + */ + __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_fid_to_order, __pyx_v_working_fid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3621, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (unlikely(PyDict_SetItem(__pyx_v_fid_to_order, __pyx_v_downstream_fid, __pyx_t_1) < 0)) __PYX_ERR(0, 3621, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3622 + * # Downstream order is the same as upstream + * fid_to_order[downstream_fid] = fid_to_order[working_fid] + * del fid_to_order[working_fid] # <<<<<<<<<<<<<< + * + * # set downstream order to working order + */ + if (unlikely(PyDict_DelItem(__pyx_v_fid_to_order, __pyx_v_working_fid) < 0)) __PYX_ERR(0, 3622, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3626 + * # set downstream order to working order + * downstream_to_upstream_ids[downstream_fid] = ( + * downstream_to_upstream_ids[working_fid]) # <<<<<<<<<<<<<< + * # since we're deleting the upstream segment we need upstream + * # connecting segments to connect to the new downstream + */ + __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_downstream_to_upstream_ids, __pyx_v_working_fid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3626, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":3625 + * + * # set downstream order to working order + * downstream_to_upstream_ids[downstream_fid] = ( # <<<<<<<<<<<<<< + * downstream_to_upstream_ids[working_fid]) + * # since we're deleting the upstream segment we need upstream + */ + if (unlikely(PyDict_SetItem(__pyx_v_downstream_to_upstream_ids, __pyx_v_downstream_fid, __pyx_t_1) < 0)) __PYX_ERR(0, 3625, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3629 + * # since we're deleting the upstream segment we need upstream + * # connecting segments to connect to the new downstream + * for upstream_fid in downstream_to_upstream_ids[downstream_fid]: # <<<<<<<<<<<<<< + * upstream_to_downstream_id[upstream_fid] = downstream_fid + * del downstream_to_upstream_ids[working_fid] + */ + __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_downstream_to_upstream_ids, __pyx_v_downstream_fid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3629, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_9 = __pyx_t_1; __Pyx_INCREF(__pyx_t_9); __pyx_t_15 = 0; + __pyx_t_14 = NULL; + } else { + __pyx_t_15 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3629, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_14 = Py_TYPE(__pyx_t_9)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 3629, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (likely(!__pyx_t_14)) { + if (likely(PyList_CheckExact(__pyx_t_9))) { + if (__pyx_t_15 >= PyList_GET_SIZE(__pyx_t_9)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_15); __Pyx_INCREF(__pyx_t_1); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 3629, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_9, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3629, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } else { + if (__pyx_t_15 >= PyTuple_GET_SIZE(__pyx_t_9)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_15); __Pyx_INCREF(__pyx_t_1); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 3629, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_9, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3629, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } + } else { + __pyx_t_1 = __pyx_t_14(__pyx_t_9); + 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, 3629, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XDECREF_SET(__pyx_v_upstream_fid, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3630 + * # connecting segments to connect to the new downstream + * for upstream_fid in downstream_to_upstream_ids[downstream_fid]: + * upstream_to_downstream_id[upstream_fid] = downstream_fid # <<<<<<<<<<<<<< + * del downstream_to_upstream_ids[working_fid] + * del upstream_to_downstream_id[working_fid] + */ + if (unlikely(PyDict_SetItem(__pyx_v_upstream_to_downstream_id, __pyx_v_upstream_fid, __pyx_v_downstream_fid) < 0)) __PYX_ERR(0, 3630, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3629 + * # since we're deleting the upstream segment we need upstream + * # connecting segments to connect to the new downstream + * for upstream_fid in downstream_to_upstream_ids[downstream_fid]: # <<<<<<<<<<<<<< + * upstream_to_downstream_id[upstream_fid] = downstream_fid + * del downstream_to_upstream_ids[working_fid] + */ + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3631 + * for upstream_fid in downstream_to_upstream_ids[downstream_fid]: + * upstream_to_downstream_id[upstream_fid] = downstream_fid + * del downstream_to_upstream_ids[working_fid] # <<<<<<<<<<<<<< + * del upstream_to_downstream_id[working_fid] + * + */ + if (unlikely(PyDict_DelItem(__pyx_v_downstream_to_upstream_ids, __pyx_v_working_fid) < 0)) __PYX_ERR(0, 3631, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3632 + * upstream_to_downstream_id[upstream_fid] = downstream_fid + * del downstream_to_upstream_ids[working_fid] + * del upstream_to_downstream_id[working_fid] # <<<<<<<<<<<<<< + * + * # join working line with downstream line + */ + if (unlikely(PyDict_DelItem(__pyx_v_upstream_to_downstream_id, __pyx_v_working_fid) < 0)) __PYX_ERR(0, 3632, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3635 + * + * # join working line with downstream line + * working_feature = stream_layer.GetFeature(working_fid) # <<<<<<<<<<<<<< + * downstream_feature = stream_layer.GetFeature(downstream_fid) + * downstream_geom = downstream_feature.GetGeometryRef() + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3635, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_31 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_31 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_31)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_31); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_9 = (__pyx_t_31) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_31, __pyx_v_working_fid) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_working_fid); + __Pyx_XDECREF(__pyx_t_31); __pyx_t_31 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3635, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF_SET(__pyx_v_working_feature, __pyx_t_9); + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3636 + * # join working line with downstream line + * working_feature = stream_layer.GetFeature(working_fid) + * downstream_feature = stream_layer.GetFeature(downstream_fid) # <<<<<<<<<<<<<< + * downstream_geom = downstream_feature.GetGeometryRef() + * working_geom = working_feature.GetGeometryRef() + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3636, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_31 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_31 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_31)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_31); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_9 = (__pyx_t_31) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_31, __pyx_v_downstream_fid) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_downstream_fid); + __Pyx_XDECREF(__pyx_t_31); __pyx_t_31 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3636, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_downstream_feature, __pyx_t_9); + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3637 + * working_feature = stream_layer.GetFeature(working_fid) + * downstream_feature = stream_layer.GetFeature(downstream_fid) + * downstream_geom = downstream_feature.GetGeometryRef() # <<<<<<<<<<<<<< + * working_geom = working_feature.GetGeometryRef() + * + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_downstream_feature, __pyx_n_s_GetGeometryRef); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3637, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_31 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_31 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_31)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_31); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_9 = (__pyx_t_31) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_31) : __Pyx_PyObject_CallNoArg(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_31); __pyx_t_31 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3637, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_downstream_geom, __pyx_t_9); + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3638 + * downstream_feature = stream_layer.GetFeature(downstream_fid) + * downstream_geom = downstream_feature.GetGeometryRef() + * working_geom = working_feature.GetGeometryRef() # <<<<<<<<<<<<<< + * + * # Union creates a multiline string by default but we know it's + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_GetGeometryRef); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3638, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_31 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_31 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_31)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_31); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_9 = (__pyx_t_31) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_31) : __Pyx_PyObject_CallNoArg(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_31); __pyx_t_31 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3638, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_working_geom, __pyx_t_9); + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3643 + * # connected only at one point, so the next step ensures it's a + * # regular linestring + * multi_line = working_geom.Union(downstream_geom) # <<<<<<<<<<<<<< + * joined_line = ogr.CreateGeometryFromWkb( + * shapely.ops.linemerge(shapely.wkb.loads( + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_geom, __pyx_n_s_Union); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3643, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_31 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_31 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_31)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_31); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_9 = (__pyx_t_31) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_31, __pyx_v_downstream_geom) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_downstream_geom); + __Pyx_XDECREF(__pyx_t_31); __pyx_t_31 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3643, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_multi_line, __pyx_t_9); + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3644 + * # regular linestring + * multi_line = working_geom.Union(downstream_geom) + * joined_line = ogr.CreateGeometryFromWkb( # <<<<<<<<<<<<<< + * shapely.ops.linemerge(shapely.wkb.loads( + * multi_line.ExportToWkb())).wkb) + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3644, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_CreateGeometryFromWkb); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3644, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3645 + * multi_line = working_geom.Union(downstream_geom) + * joined_line = ogr.CreateGeometryFromWkb( + * shapely.ops.linemerge(shapely.wkb.loads( # <<<<<<<<<<<<<< + * multi_line.ExportToWkb())).wkb) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_30, __pyx_n_s_shapely); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3645, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_30); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_30, __pyx_n_s_ops); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3645, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + __pyx_t_30 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_linemerge); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3645, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_30); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_shapely); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3645, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_wkb); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3645, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_loads); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3645, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3646 + * joined_line = ogr.CreateGeometryFromWkb( + * shapely.ops.linemerge(shapely.wkb.loads( + * multi_line.ExportToWkb())).wkb) # <<<<<<<<<<<<<< + * + * downstream_feature.SetGeometry(joined_line) + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_multi_line, __pyx_n_s_ExportToWkb); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3646, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_3 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3646, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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); + } + } + __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_7, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_3); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3645, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_30))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_30); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_30); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_30, function); + } + } + __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_30, __pyx_t_8, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_30, __pyx_t_4); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3645, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + __pyx_t_30 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_wkb); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3646, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_30); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_31))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_31); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_31, function); + } + } + __pyx_t_9 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_31, __pyx_t_1, __pyx_t_30) : __Pyx_PyObject_CallOneArg(__pyx_t_31, __pyx_t_30); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3644, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + __Pyx_XDECREF_SET(__pyx_v_joined_line, __pyx_t_9); + __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3648 + * multi_line.ExportToWkb())).wkb) + * + * downstream_feature.SetGeometry(joined_line) # <<<<<<<<<<<<<< + * downstream_feature.SetField( + * 'us_x', working_feature.GetField('us_x')) + */ + __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_downstream_feature, __pyx_n_s_SetGeometry); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3648, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + __pyx_t_30 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { + __pyx_t_30 = PyMethod_GET_SELF(__pyx_t_31); + if (likely(__pyx_t_30)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); + __Pyx_INCREF(__pyx_t_30); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_31, function); + } + } + __pyx_t_9 = (__pyx_t_30) ? __Pyx_PyObject_Call2Args(__pyx_t_31, __pyx_t_30, __pyx_v_joined_line) : __Pyx_PyObject_CallOneArg(__pyx_t_31, __pyx_v_joined_line); + __Pyx_XDECREF(__pyx_t_30); __pyx_t_30 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3648, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3649 + * + * downstream_feature.SetGeometry(joined_line) + * downstream_feature.SetField( # <<<<<<<<<<<<<< + * 'us_x', working_feature.GetField('us_x')) + * downstream_feature.SetField( + */ + __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_downstream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3649, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + + /* "pygeoprocessing/routing/routing.pyx":3650 + * downstream_feature.SetGeometry(joined_line) + * downstream_feature.SetField( + * 'us_x', working_feature.GetField('us_x')) # <<<<<<<<<<<<<< + * downstream_feature.SetField( + * 'us_y', working_feature.GetField('us_y')) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3650, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = NULL; + 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_30 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_4, __pyx_n_u_us_x) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_n_u_us_x); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3650, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_30); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + __pyx_t_17 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_31); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_31, function); + __pyx_t_17 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_31)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_n_u_us_x, __pyx_t_30}; + __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3649, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_31)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_n_u_us_x, __pyx_t_30}; + __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3649, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + } else + #endif + { + __pyx_t_4 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3649, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (__pyx_t_1) { + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __pyx_t_1 = NULL; + } + __Pyx_INCREF(__pyx_n_u_us_x); + __Pyx_GIVEREF(__pyx_n_u_us_x); + PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_17, __pyx_n_u_us_x); + __Pyx_GIVEREF(__pyx_t_30); + PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_17, __pyx_t_30); + __pyx_t_30 = 0; + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_31, __pyx_t_4, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3649, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3651 + * downstream_feature.SetField( + * 'us_x', working_feature.GetField('us_x')) + * downstream_feature.SetField( # <<<<<<<<<<<<<< + * 'us_y', working_feature.GetField('us_y')) + * stream_layer.SetFeature(downstream_feature) + */ + __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_downstream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3651, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + + /* "pygeoprocessing/routing/routing.pyx":3652 + * 'us_x', working_feature.GetField('us_x')) + * downstream_feature.SetField( + * 'us_y', working_feature.GetField('us_y')) # <<<<<<<<<<<<<< + * stream_layer.SetFeature(downstream_feature) + * working_feature = None + */ + __pyx_t_30 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3652, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_30); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_30))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_30); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_30); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_30, function); + } + } + __pyx_t_4 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_30, __pyx_t_1, __pyx_n_u_us_y) : __Pyx_PyObject_CallOneArg(__pyx_t_30, __pyx_n_u_us_y); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3652, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; + __pyx_t_30 = NULL; + __pyx_t_17 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { + __pyx_t_30 = PyMethod_GET_SELF(__pyx_t_31); + if (likely(__pyx_t_30)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); + __Pyx_INCREF(__pyx_t_30); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_31, function); + __pyx_t_17 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_31)) { + PyObject *__pyx_temp[3] = {__pyx_t_30, __pyx_n_u_us_y, __pyx_t_4}; + __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3651, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_30); __pyx_t_30 = 0; + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_31)) { + PyObject *__pyx_temp[3] = {__pyx_t_30, __pyx_n_u_us_y, __pyx_t_4}; + __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3651, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_30); __pyx_t_30 = 0; + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_1 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3651, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (__pyx_t_30) { + __Pyx_GIVEREF(__pyx_t_30); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_30); __pyx_t_30 = NULL; + } + __Pyx_INCREF(__pyx_n_u_us_y); + __Pyx_GIVEREF(__pyx_n_u_us_y); + PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_17, __pyx_n_u_us_y); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_17, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_31, __pyx_t_1, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3651, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3653 + * downstream_feature.SetField( + * 'us_y', working_feature.GetField('us_y')) + * stream_layer.SetFeature(downstream_feature) # <<<<<<<<<<<<<< + * working_feature = None + * downstream_feature = None + */ + __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_SetFeature); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3653, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_31); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_31, function); + } + } + __pyx_t_9 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_31, __pyx_t_1, __pyx_v_downstream_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_31, __pyx_v_downstream_feature); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3653, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3654 + * 'us_y', working_feature.GetField('us_y')) + * stream_layer.SetFeature(downstream_feature) + * working_feature = None # <<<<<<<<<<<<<< + * downstream_feature = None + * multi_line = None + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_working_feature, Py_None); + + /* "pygeoprocessing/routing/routing.pyx":3655 + * stream_layer.SetFeature(downstream_feature) + * working_feature = None + * downstream_feature = None # <<<<<<<<<<<<<< + * multi_line = None + * joined_line = None + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_downstream_feature, Py_None); + + /* "pygeoprocessing/routing/routing.pyx":3656 + * working_feature = None + * downstream_feature = None + * multi_line = None # <<<<<<<<<<<<<< + * joined_line = None + * + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_multi_line, Py_None); + + /* "pygeoprocessing/routing/routing.pyx":3657 + * downstream_feature = None + * multi_line = None + * joined_line = None # <<<<<<<<<<<<<< + * + * # delete working line + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_joined_line, Py_None); + + /* "pygeoprocessing/routing/routing.pyx":3660 + * + * # delete working line + * stream_layer.DeleteFeature(working_fid) # <<<<<<<<<<<<<< + * deleted_set.add(working_fid) + * + */ + __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_DeleteFeature); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3660, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_31); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_31, function); + } + } + __pyx_t_9 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_31, __pyx_t_1, __pyx_v_working_fid) : __Pyx_PyObject_CallOneArg(__pyx_t_31, __pyx_v_working_fid); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3660, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3661 + * # delete working line + * stream_layer.DeleteFeature(working_fid) + * deleted_set.add(working_fid) # <<<<<<<<<<<<<< + * + * # push downstream line for processing + */ + __pyx_t_27 = PySet_Add(__pyx_v_deleted_set, __pyx_v_working_fid); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3661, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3664 + * + * # push downstream line for processing + * working_stack.append(downstream_fid) # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_27 = __Pyx_PyList_Append(__pyx_v_working_stack, __pyx_v_downstream_fid); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3664, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3665 + * # push downstream line for processing + * working_stack.append(downstream_fid) + * continue # <<<<<<<<<<<<<< + * + * # otherwise check if connected streams are all defined and if so + */ + goto __pyx_L109_continue; + + /* "pygeoprocessing/routing/routing.pyx":3618 + * downstream_fid = upstream_to_downstream_id[working_fid] + * connected_fids = downstream_to_upstream_ids[downstream_fid] + * if len(connected_fids) == 1: # <<<<<<<<<<<<<< + * # There's only one downstream, join it. + * # Downstream order is the same as upstream + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3669 + * # otherwise check if connected streams are all defined and if so + * # set a new downstream order + * upstream_all_defined = True # <<<<<<<<<<<<<< + * for connected_fid in connected_fids: + * if connected_fid == working_fid: + */ + __pyx_v_upstream_all_defined = 1; + + /* "pygeoprocessing/routing/routing.pyx":3670 + * # set a new downstream order + * upstream_all_defined = True + * for connected_fid in connected_fids: # <<<<<<<<<<<<<< + * if connected_fid == working_fid: + * # skip current + */ + if (likely(PyList_CheckExact(__pyx_v_connected_fids)) || PyTuple_CheckExact(__pyx_v_connected_fids)) { + __pyx_t_9 = __pyx_v_connected_fids; __Pyx_INCREF(__pyx_t_9); __pyx_t_15 = 0; + __pyx_t_14 = NULL; + } else { + __pyx_t_15 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_v_connected_fids); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3670, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_14 = Py_TYPE(__pyx_t_9)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 3670, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_14)) { + if (likely(PyList_CheckExact(__pyx_t_9))) { + if (__pyx_t_15 >= PyList_GET_SIZE(__pyx_t_9)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_31 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_15); __Pyx_INCREF(__pyx_t_31); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 3670, __pyx_L1_error) + #else + __pyx_t_31 = PySequence_ITEM(__pyx_t_9, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3670, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + #endif + } else { + if (__pyx_t_15 >= PyTuple_GET_SIZE(__pyx_t_9)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_31 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_15); __Pyx_INCREF(__pyx_t_31); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 3670, __pyx_L1_error) + #else + __pyx_t_31 = PySequence_ITEM(__pyx_t_9, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3670, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + #endif + } + } else { + __pyx_t_31 = __pyx_t_14(__pyx_t_9); + if (unlikely(!__pyx_t_31)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 3670, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_31); + } + __Pyx_XDECREF_SET(__pyx_v_connected_fid, __pyx_t_31); + __pyx_t_31 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3671 + * upstream_all_defined = True + * for connected_fid in connected_fids: + * if connected_fid == working_fid: # <<<<<<<<<<<<<< + * # skip current + * continue + */ + __pyx_t_31 = PyObject_RichCompare(__pyx_v_connected_fid, __pyx_v_working_fid, Py_EQ); __Pyx_XGOTREF(__pyx_t_31); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3671, __pyx_L1_error) + __pyx_t_29 = __Pyx_PyObject_IsTrue(__pyx_t_31); if (unlikely(__pyx_t_29 < 0)) __PYX_ERR(0, 3671, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + if (__pyx_t_29) { + + /* "pygeoprocessing/routing/routing.pyx":3673 + * if connected_fid == working_fid: + * # skip current + * continue # <<<<<<<<<<<<<< + * if connected_fid not in fid_to_order: + * # upstream not defined so skip it and it will be processed + */ + goto __pyx_L120_continue; + + /* "pygeoprocessing/routing/routing.pyx":3671 + * upstream_all_defined = True + * for connected_fid in connected_fids: + * if connected_fid == working_fid: # <<<<<<<<<<<<<< + * # skip current + * continue + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3674 + * # skip current + * continue + * if connected_fid not in fid_to_order: # <<<<<<<<<<<<<< + * # upstream not defined so skip it and it will be processed + * # on another iteration + */ + __pyx_t_29 = (__Pyx_PyDict_ContainsTF(__pyx_v_connected_fid, __pyx_v_fid_to_order, Py_NE)); if (unlikely(__pyx_t_29 < 0)) __PYX_ERR(0, 3674, __pyx_L1_error) + __pyx_t_21 = (__pyx_t_29 != 0); + if (__pyx_t_21) { + + /* "pygeoprocessing/routing/routing.pyx":3677 + * # upstream not defined so skip it and it will be processed + * # on another iteration + * upstream_all_defined = False # <<<<<<<<<<<<<< + * break + * + */ + __pyx_v_upstream_all_defined = 0; + + /* "pygeoprocessing/routing/routing.pyx":3678 + * # on another iteration + * upstream_all_defined = False + * break # <<<<<<<<<<<<<< + * + * if not upstream_all_defined: + */ + goto __pyx_L121_break; + + /* "pygeoprocessing/routing/routing.pyx":3674 + * # skip current + * continue + * if connected_fid not in fid_to_order: # <<<<<<<<<<<<<< + * # upstream not defined so skip it and it will be processed + * # on another iteration + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3670 + * # set a new downstream order + * upstream_all_defined = True + * for connected_fid in connected_fids: # <<<<<<<<<<<<<< + * if connected_fid == working_fid: + * # skip current + */ + __pyx_L120_continue:; + } + __pyx_L121_break:; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3680 + * break + * + * if not upstream_all_defined: # <<<<<<<<<<<<<< + * # wait for other upstream components to be defined + * continue + */ + __pyx_t_21 = ((!(__pyx_v_upstream_all_defined != 0)) != 0); + if (__pyx_t_21) { + + /* "pygeoprocessing/routing/routing.pyx":3682 + * if not upstream_all_defined: + * # wait for other upstream components to be defined + * continue # <<<<<<<<<<<<<< + * + * # all upstream components of this fid are calculated so it can be + */ + goto __pyx_L109_continue; + + /* "pygeoprocessing/routing/routing.pyx":3680 + * break + * + * if not upstream_all_defined: # <<<<<<<<<<<<<< + * # wait for other upstream components to be defined + * continue + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3686 + * # all upstream components of this fid are calculated so it can be + * # calculated now too + * working_stack.append(downstream_fid) # <<<<<<<<<<<<<< + * + * LOGGER.info( + */ + __pyx_t_27 = __Pyx_PyList_Append(__pyx_v_working_stack, __pyx_v_downstream_fid); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3686, __pyx_L1_error) + __pyx_L109_continue:; + } + + /* "pygeoprocessing/routing/routing.pyx":3688 + * working_stack.append(downstream_fid) + * + * LOGGER.info( # <<<<<<<<<<<<<< + * '(extract_strahler_streams_d8): ' + * 'final pass on stream order complete') + */ + __Pyx_GetModuleGlobalName(__pyx_t_31, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3688, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_31, __pyx_n_s_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3688, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + __pyx_t_31 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_31 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_31)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_31); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_9 = (__pyx_t_31) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_31, __pyx_kp_u_extract_strahler_streams_d8_fin_3) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_kp_u_extract_strahler_streams_d8_fin_3); + __Pyx_XDECREF(__pyx_t_31); __pyx_t_31 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3688, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3691 + * '(extract_strahler_streams_d8): ' + * 'final pass on stream order complete') + * LOGGER.info( # <<<<<<<<<<<<<< + * '(extract_strahler_streams_d8): ' + * 'commit transaction due to stream joining') + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3691, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_info); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3691, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_31))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_31); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_31, function); + } + } + __pyx_t_9 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_31, __pyx_t_1, __pyx_kp_u_extract_strahler_streams_d8_com) : __Pyx_PyObject_CallOneArg(__pyx_t_31, __pyx_kp_u_extract_strahler_streams_d8_com); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3691, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3694 + * '(extract_strahler_streams_d8): ' + * 'commit transaction due to stream joining') + * stream_layer.CommitTransaction() # <<<<<<<<<<<<<< + * stream_layer = None + * stream_vector = None + */ + __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CommitTransaction); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3694, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_31); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_31, function); + } + } + __pyx_t_9 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_31, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_31); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3694, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3695 + * 'commit transaction due to stream joining') + * stream_layer.CommitTransaction() + * stream_layer = None # <<<<<<<<<<<<<< + * stream_vector = None + * LOGGER.info('(extract_strahler_streams_d8): all done') + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_stream_layer, Py_None); + + /* "pygeoprocessing/routing/routing.pyx":3696 + * stream_layer.CommitTransaction() + * stream_layer = None + * stream_vector = None # <<<<<<<<<<<<<< + * LOGGER.info('(extract_strahler_streams_d8): all done') + * + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_stream_vector, Py_None); + + /* "pygeoprocessing/routing/routing.pyx":3697 + * stream_layer = None + * stream_vector = None + * LOGGER.info('(extract_strahler_streams_d8): all done') # <<<<<<<<<<<<<< + * + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_31, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3697, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_31); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_31, __pyx_n_s_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3697, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; + __pyx_t_31 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_31 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_31)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_31); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_9 = (__pyx_t_31) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_31, __pyx_kp_u_extract_strahler_streams_d8_all) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_kp_u_extract_strahler_streams_d8_all); + __Pyx_XDECREF(__pyx_t_31); __pyx_t_31 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3697, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3025 + * + * + * def extract_strahler_streams_d8( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band, flow_accum_raster_path_band, + * dem_raster_path_band, + */ + + /* 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_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_30); + __Pyx_XDECREF(__pyx_t_31); + __Pyx_XDECREF(__pyx_t_32); + __Pyx_AddTraceback("pygeoprocessing.routing.routing.extract_strahler_streams_d8", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_flow_dir_info); + __Pyx_XDECREF(__pyx_v_flow_dir_srs); + __Pyx_XDECREF(__pyx_v_gpkg_driver); + __Pyx_XDECREF(__pyx_v_stream_vector); + __Pyx_XDECREF(__pyx_v_stream_basename); + __Pyx_XDECREF(__pyx_v_stream_layer); + __Pyx_XDECREF((PyObject *)__pyx_v_flow_dir_managed_raster); + __Pyx_XDECREF((PyObject *)__pyx_v_flow_accum_managed_raster); + __Pyx_XDECREF((PyObject *)__pyx_v_dem_managed_raster); + __Pyx_XDECREF(__pyx_v_coord_to_stream_ids); + __Pyx_XDECREF(__pyx_v_offset_dict); + __Pyx_XDECREF(__pyx_v_stream_feature); + __Pyx_XDECREF(__pyx_v_stream_fid); + __Pyx_XDECREF(__pyx_v_n_points); + __Pyx_XDECREF(__pyx_v_downstream_to_upstream_ids); + __Pyx_XDECREF(__pyx_v_upstream_to_downstream_id); + __Pyx_XDECREF(__pyx_v_payload); + __Pyx_XDECREF(__pyx_v_x_u); + __Pyx_XDECREF(__pyx_v_y_u); + __Pyx_XDECREF(__pyx_v_ds_x_1); + __Pyx_XDECREF(__pyx_v_ds_y_1); + __Pyx_XDECREF(__pyx_v_upstream_id_list); + __Pyx_XDECREF(__pyx_v_stream_line); + __Pyx_XDECREF(__pyx_v_upstream_id); + __Pyx_XDECREF(__pyx_v_streams_to_process); + __Pyx_XDECREF(__pyx_v_base_feature_count); + __Pyx_XDECREF(__pyx_v_outlet_fid_list); + __Pyx_XDECREF(__pyx_v_downstream_fid); + __Pyx_XDECREF(__pyx_v_downstream_feature); + __Pyx_XDECREF(__pyx_v_connected_upstream_fids); + __Pyx_XDECREF(__pyx_v_stream_order_list); + __Pyx_XDECREF(__pyx_v_upstream_fid); + __Pyx_XDECREF(__pyx_v_upstream_feature); + __Pyx_XDECREF(__pyx_v_upstream_order); + __Pyx_XDECREF(__pyx_v_sorted_stream_order_list); + __Pyx_XDECREF(__pyx_v_downstream_order); + __Pyx_XDECREF(__pyx_v_working_river_id); + __Pyx_XDECREF(__pyx_v_outlet_index); + __Pyx_XDECREF(__pyx_v_outlet_fid); + __Pyx_XDECREF(__pyx_v_search_stack); + __Pyx_XDECREF(__pyx_v_feature_id); + __Pyx_XDECREF(__pyx_v_stream_order); + __Pyx_XDECREF(__pyx_v_upstream_stack); + __Pyx_XDECREF(__pyx_v_streams_by_order); + __Pyx_XDECREF(__pyx_v_drop_distance_collection); + __Pyx_XDECREF(__pyx_v_max_upstream_flow_accum); + __Pyx_XDECREF(__pyx_v_order); + __Pyx_XDECREF(__pyx_v_working_flow_accum_threshold); + __Pyx_XDECREF(__pyx_v_test_order); + __Pyx_XDECREF(__pyx_v__); + __Pyx_XDECREF(__pyx_v_p_val); + __Pyx_XDECREF(__pyx_v_streams_to_retest); + __Pyx_XDECREF(__pyx_v_ds_x); + __Pyx_XDECREF(__pyx_v_ds_y); + __Pyx_XDECREF(__pyx_v_upstream_d8_dir); + __Pyx_XDECREF(__pyx_v_working_stack); + __Pyx_XDECREF(__pyx_v_fid_to_order); + __Pyx_XDECREF(__pyx_v_processed_segments); + __Pyx_XDECREF(__pyx_v_deleted_set); + __Pyx_XDECREF(__pyx_v_working_fid); + __Pyx_XDECREF(__pyx_v_upstream_fid_list); + __Pyx_XDECREF(__pyx_v_order_count); + __Pyx_XDECREF(__pyx_v_working_order); + __Pyx_XDECREF(__pyx_v_working_feature); + __Pyx_XDECREF(__pyx_v_connected_fids); + __Pyx_XDECREF(__pyx_v_downstream_geom); + __Pyx_XDECREF(__pyx_v_working_geom); + __Pyx_XDECREF(__pyx_v_multi_line); + __Pyx_XDECREF(__pyx_v_joined_line); + __Pyx_XDECREF(__pyx_v_connected_fid); + __Pyx_XDECREF(__pyx_7genexpr__pyx_v_stream_feature); + __Pyx_XDECREF(__pyx_8genexpr1__pyx_v_fid); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pygeoprocessing/routing/routing.pyx":3700 + * + * + * def _build_discovery_finish_rasters( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band, target_discovery_raster_path, + * target_finish_raster_path): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_23_build_discovery_finish_rasters(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_15pygeoprocessing_7routing_7routing_22_build_discovery_finish_rasters[] = "Generates a discovery and finish time raster for a given d8 flow path.\n\n Args:\n flow_dir_d8_raster_path_band (tuple): a D8 flow raster path band tuple\n target_discovery_raster_path (str): path to a generated raster that\n creates discovery time (i.e. what count the pixel is visited in)\n target_finish_raster_path (str): path to generated raster that creates\n maximum upstream finish time.\n\n Returns:\n None\n "; +static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_23_build_discovery_finish_rasters = {"_build_discovery_finish_rasters", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_7routing_7routing_23_build_discovery_finish_rasters, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_7routing_7routing_22_build_discovery_finish_rasters}; +static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_23_build_discovery_finish_rasters(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_flow_dir_d8_raster_path_band = 0; + PyObject *__pyx_v_target_discovery_raster_path = 0; + PyObject *__pyx_v_target_finish_raster_path = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_build_discovery_finish_rasters (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_flow_dir_d8_raster_path_band,&__pyx_n_s_target_discovery_raster_path,&__pyx_n_s_target_finish_raster_path,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_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_target_discovery_raster_path)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_build_discovery_finish_rasters", 1, 3, 3, 1); __PYX_ERR(0, 3700, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_finish_raster_path)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_build_discovery_finish_rasters", 1, 3, 3, 2); __PYX_ERR(0, 3700, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_build_discovery_finish_rasters") < 0)) __PYX_ERR(0, 3700, __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_flow_dir_d8_raster_path_band = values[0]; + __pyx_v_target_discovery_raster_path = values[1]; + __pyx_v_target_finish_raster_path = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("_build_discovery_finish_rasters", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3700, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pygeoprocessing.routing.routing._build_discovery_finish_rasters", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing_22_build_discovery_finish_rasters(__pyx_self, __pyx_v_flow_dir_d8_raster_path_band, __pyx_v_target_discovery_raster_path, __pyx_v_target_finish_raster_path); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_22_build_discovery_finish_rasters(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_flow_dir_d8_raster_path_band, PyObject *__pyx_v_target_discovery_raster_path, PyObject *__pyx_v_target_finish_raster_path) { + PyObject *__pyx_v_flow_dir_info = NULL; + int __pyx_v_n_cols; + int __pyx_v_n_rows; + int __pyx_v_flow_dir_nodata; + struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_flow_dir_managed_raster = NULL; + struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_discovery_managed_raster = NULL; + struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_finish_managed_raster = NULL; + std::stack __pyx_v_discovery_stack; + std::stack __pyx_v_finish_stack; + struct __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateType __pyx_v_raster_coord; + struct __pyx_t_15pygeoprocessing_7routing_7routing_FinishType __pyx_v_finish_coordinate; + long __pyx_v_discovery_count; + int __pyx_v_n_processed; + int __pyx_v_n_pixels; + time_t __pyx_v_last_log_time; + int __pyx_v_n_pushed; + int __pyx_v_i; + int __pyx_v_j; + int __pyx_v_xoff; + int __pyx_v_yoff; + int __pyx_v_win_xsize; + int __pyx_v_win_ysize; + int __pyx_v_x_l; + int __pyx_v_y_l; + int __pyx_v_x_n; + int __pyx_v_y_n; + int __pyx_v_n_dir; + int __pyx_v_test_dir; + PyObject *__pyx_v_offset_dict = NULL; + int __pyx_v_d_n; + 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)(PyObject *); + int __pyx_t_6; + int __pyx_t_7; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + Py_ssize_t __pyx_t_11; + PyObject *(*__pyx_t_12)(PyObject *); + int __pyx_t_13; + Py_ssize_t __pyx_t_14; + Py_UCS4 __pyx_t_15; + int __pyx_t_16; + int __pyx_t_17; + int __pyx_t_18; + int __pyx_t_19; + int __pyx_t_20; + struct __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateType __pyx_t_21; + struct __pyx_t_15pygeoprocessing_7routing_7routing_FinishType __pyx_t_22; + int __pyx_t_23; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_build_discovery_finish_rasters", 0); + + /* "pygeoprocessing/routing/routing.pyx":3715 + * None + * """ + * flow_dir_info = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band[0]) + * cdef int n_cols, n_rows + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3715, __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, 3715, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3716 + * """ + * flow_dir_info = pygeoprocessing.get_raster_info( + * flow_dir_d8_raster_path_band[0]) # <<<<<<<<<<<<<< + * cdef int n_cols, n_rows + * n_cols, n_rows = flow_dir_info['raster_size'] + */ + __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, 3716, __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); + } + } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3715, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_flow_dir_info = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3718 + * flow_dir_d8_raster_path_band[0]) + * cdef int n_cols, n_rows + * n_cols, n_rows = flow_dir_info['raster_size'] # <<<<<<<<<<<<<< + * cdef int flow_dir_nodata = ( + * flow_dir_info['nodata'][flow_dir_d8_raster_path_band[1]-1]) + */ + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3718, __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, 3718, __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, 3718, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3718, __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, 3718, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext; + index = 0; __pyx_t_3 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L3_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + index = 1; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L3_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) __PYX_ERR(0, 3718, __pyx_L1_error) + __pyx_t_5 = NULL; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L4_unpacking_done; + __pyx_L3_unpacking_failed:; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 3718, __pyx_L1_error) + __pyx_L4_unpacking_done:; + } + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3718, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3718, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_n_cols = __pyx_t_6; + __pyx_v_n_rows = __pyx_t_7; + + /* "pygeoprocessing/routing/routing.pyx":3720 + * n_cols, n_rows = flow_dir_info['raster_size'] + * cdef int flow_dir_nodata = ( + * flow_dir_info['nodata'][flow_dir_d8_raster_path_band[1]-1]) # <<<<<<<<<<<<<< + * + * flow_dir_managed_raster = _ManagedRaster( + */ + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3720, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3720, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyInt_SubtractObjC(__pyx_t_2, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3720, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3720, __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_7 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3720, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_flow_dir_nodata = __pyx_t_7; + + /* "pygeoprocessing/routing/routing.pyx":3723 + * + * flow_dir_managed_raster = _ManagedRaster( + * flow_dir_d8_raster_path_band[0], flow_dir_d8_raster_path_band[1], 0) # <<<<<<<<<<<<<< + * pygeoprocessing.new_raster_from_base( + * flow_dir_d8_raster_path_band[0], target_discovery_raster_path, + */ + __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, 3723, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3723, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + + /* "pygeoprocessing/routing/routing.pyx":3722 + * flow_dir_info['nodata'][flow_dir_d8_raster_path_band[1]-1]) + * + * flow_dir_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band[0], flow_dir_d8_raster_path_band[1], 0) + * pygeoprocessing.new_raster_from_base( + */ + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3722, __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_3); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_int_0); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __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, 3722, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_flow_dir_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3724 + * flow_dir_managed_raster = _ManagedRaster( + * flow_dir_d8_raster_path_band[0], flow_dir_d8_raster_path_band[1], 0) + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band[0], target_discovery_raster_path, + * gdal.GDT_Float64, [-1]) + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3724, __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, 3724, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3725 + * flow_dir_d8_raster_path_band[0], flow_dir_d8_raster_path_band[1], 0) + * pygeoprocessing.new_raster_from_base( + * flow_dir_d8_raster_path_band[0], target_discovery_raster_path, # <<<<<<<<<<<<<< + * gdal.GDT_Float64, [-1]) + * discovery_managed_raster = _ManagedRaster( + */ + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3725, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":3726 + * pygeoprocessing.new_raster_from_base( + * flow_dir_d8_raster_path_band[0], target_discovery_raster_path, + * gdal.GDT_Float64, [-1]) # <<<<<<<<<<<<<< + * discovery_managed_raster = _ManagedRaster( + * target_discovery_raster_path, 1, 1) + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3726, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3726, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3726, __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); + __pyx_t_9 = NULL; + __pyx_t_7 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(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); + __pyx_t_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[5] = {__pyx_t_9, __pyx_t_1, __pyx_v_target_discovery_raster_path, __pyx_t_8, __pyx_t_4}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_7, 4+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3724, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[5] = {__pyx_t_9, __pyx_t_1, __pyx_v_target_discovery_raster_path, __pyx_t_8, __pyx_t_4}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_7, 4+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3724, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_10 = PyTuple_New(4+__pyx_t_7); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3724, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + if (__pyx_t_9) { + __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); __pyx_t_9 = NULL; + } + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_7, __pyx_t_1); + __Pyx_INCREF(__pyx_v_target_discovery_raster_path); + __Pyx_GIVEREF(__pyx_v_target_discovery_raster_path); + PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_7, __pyx_v_target_discovery_raster_path); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_10, 2+__pyx_t_7, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_10, 3+__pyx_t_7, __pyx_t_4); + __pyx_t_1 = 0; + __pyx_t_8 = 0; + __pyx_t_4 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3724, __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_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3727 + * flow_dir_d8_raster_path_band[0], target_discovery_raster_path, + * gdal.GDT_Float64, [-1]) + * discovery_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< + * target_discovery_raster_path, 1, 1) + * pygeoprocessing.new_raster_from_base( + */ + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3727, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_target_discovery_raster_path); + __Pyx_GIVEREF(__pyx_v_target_discovery_raster_path); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_target_discovery_raster_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_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3727, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_discovery_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3729 + * discovery_managed_raster = _ManagedRaster( + * target_discovery_raster_path, 1, 1) + * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band[0], target_finish_raster_path, + * gdal.GDT_Float64, [-1]) + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3729, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3729, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3730 + * target_discovery_raster_path, 1, 1) + * pygeoprocessing.new_raster_from_base( + * flow_dir_d8_raster_path_band[0], target_finish_raster_path, # <<<<<<<<<<<<<< + * gdal.GDT_Float64, [-1]) + * finish_managed_raster = _ManagedRaster(target_finish_raster_path, 1, 1) + */ + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3730, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + + /* "pygeoprocessing/routing/routing.pyx":3731 + * pygeoprocessing.new_raster_from_base( + * flow_dir_d8_raster_path_band[0], target_finish_raster_path, + * gdal.GDT_Float64, [-1]) # <<<<<<<<<<<<<< + * finish_managed_raster = _ManagedRaster(target_finish_raster_path, 1, 1) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3731, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3731, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3731, __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); + __pyx_t_1 = NULL; + __pyx_t_7 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_10); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_10, function); + __pyx_t_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_10)) { + PyObject *__pyx_temp[5] = {__pyx_t_1, __pyx_t_3, __pyx_v_target_finish_raster_path, __pyx_t_8, __pyx_t_4}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_7, 4+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3729, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) { + PyObject *__pyx_temp[5] = {__pyx_t_1, __pyx_t_3, __pyx_v_target_finish_raster_path, __pyx_t_8, __pyx_t_4}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_7, 4+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3729, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_9 = PyTuple_New(4+__pyx_t_7); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3729, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + if (__pyx_t_1) { + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1); __pyx_t_1 = NULL; + } + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_7, __pyx_t_3); + __Pyx_INCREF(__pyx_v_target_finish_raster_path); + __Pyx_GIVEREF(__pyx_v_target_finish_raster_path); + PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_7, __pyx_v_target_finish_raster_path); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_9, 2+__pyx_t_7, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_9, 3+__pyx_t_7, __pyx_t_4); + __pyx_t_3 = 0; + __pyx_t_8 = 0; + __pyx_t_4 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3729, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3732 + * flow_dir_d8_raster_path_band[0], target_finish_raster_path, + * gdal.GDT_Float64, [-1]) + * finish_managed_raster = _ManagedRaster(target_finish_raster_path, 1, 1) # <<<<<<<<<<<<<< + * + * cdef stack[CoordinateType] discovery_stack + */ + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3732, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_target_finish_raster_path); + __Pyx_GIVEREF(__pyx_v_target_finish_raster_path); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_target_finish_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_10 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_2, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3732, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_finish_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_10); + __pyx_t_10 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3739 + * cdef FinishType finish_coordinate + * + * cdef long discovery_count = 0 # <<<<<<<<<<<<<< + * cdef int n_processed, n_pixels + * n_pixels = n_rows * n_cols + */ + __pyx_v_discovery_count = 0; + + /* "pygeoprocessing/routing/routing.pyx":3741 + * cdef long discovery_count = 0 + * cdef int n_processed, n_pixels + * n_pixels = n_rows * n_cols # <<<<<<<<<<<<<< + * n_processed = 0 + * cdef time_t last_log_time = ctime(NULL) + */ + __pyx_v_n_pixels = (__pyx_v_n_rows * __pyx_v_n_cols); + + /* "pygeoprocessing/routing/routing.pyx":3742 + * cdef int n_processed, n_pixels + * n_pixels = n_rows * n_cols + * n_processed = 0 # <<<<<<<<<<<<<< + * cdef time_t last_log_time = ctime(NULL) + * cdef int n_pushed + */ + __pyx_v_n_processed = 0; + + /* "pygeoprocessing/routing/routing.pyx":3743 + * n_pixels = n_rows * n_cols + * n_processed = 0 + * cdef time_t last_log_time = ctime(NULL) # <<<<<<<<<<<<<< + * cdef int n_pushed + * + */ + __pyx_v_last_log_time = time(NULL); + + /* "pygeoprocessing/routing/routing.pyx":3749 + * cdef int n_dir, test_dir + * + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band, offset_only=True): + * # search raster block by raster block + */ + __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3749, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3749, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3750 + * + * for offset_dict in pygeoprocessing.iterblocks( + * flow_dir_d8_raster_path_band, offset_only=True): # <<<<<<<<<<<<<< + * # search raster block by raster block + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: + */ + __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3749, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __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_10, 0, __pyx_v_flow_dir_d8_raster_path_band); + __pyx_t_9 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3750, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 3750, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3749 + * cdef int n_dir, test_dir + * + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band, offset_only=True): + * # search raster block by raster block + */ + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_10, __pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3749, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) { + __pyx_t_9 = __pyx_t_4; __Pyx_INCREF(__pyx_t_9); __pyx_t_11 = 0; + __pyx_t_12 = NULL; + } else { + __pyx_t_11 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3749, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_12 = Py_TYPE(__pyx_t_9)->tp_iternext; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 3749, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + for (;;) { + if (likely(!__pyx_t_12)) { + if (likely(PyList_CheckExact(__pyx_t_9))) { + if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_9)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_11); __Pyx_INCREF(__pyx_t_4); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 3749, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_9, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3749, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } else { + if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_9)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_11); __Pyx_INCREF(__pyx_t_4); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 3749, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_9, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3749, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } + } else { + __pyx_t_4 = __pyx_t_12(__pyx_t_9); + 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, 3749, __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":3752 + * flow_dir_d8_raster_path_band, offset_only=True): + * # search raster block by raster block + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * LOGGER.info( + * f'(discovery time processing): ' + */ + __pyx_t_13 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); + if (__pyx_t_13) { + + /* "pygeoprocessing/routing/routing.pyx":3753 + * # search raster block by raster block + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: + * LOGGER.info( # <<<<<<<<<<<<<< + * f'(discovery time processing): ' + * f'{n_processed/n_pixels*100:.1f}% complete') + */ + __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3753, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3753, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3754 + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: + * LOGGER.info( + * f'(discovery time processing): ' # <<<<<<<<<<<<<< + * f'{n_processed/n_pixels*100:.1f}% complete') + * last_log_time = ctime(NULL) + */ + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3754, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_14 = 0; + __pyx_t_15 = 127; + __Pyx_INCREF(__pyx_kp_u_discovery_time_processing); + __pyx_t_14 += 29; + __Pyx_GIVEREF(__pyx_kp_u_discovery_time_processing); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_kp_u_discovery_time_processing); + + /* "pygeoprocessing/routing/routing.pyx":3755 + * LOGGER.info( + * f'(discovery time processing): ' + * f'{n_processed/n_pixels*100:.1f}% complete') # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * xoff = offset_dict['xoff'] + */ + if (unlikely(__pyx_v_n_pixels == 0)) { + PyErr_SetString(PyExc_ZeroDivisionError, "float division"); + __PYX_ERR(0, 3755, __pyx_L1_error) + } + __pyx_t_8 = PyFloat_FromDouble(((((double)__pyx_v_n_processed) / ((double)__pyx_v_n_pixels)) * 100.0)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3755, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = __Pyx_PyObject_Format(__pyx_t_8, __pyx_kp_u_1f); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3755, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_15 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) > __pyx_t_15) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) : __pyx_t_15; + __pyx_t_14 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_3); + __pyx_t_3 = 0; + __Pyx_INCREF(__pyx_kp_u_complete); + __pyx_t_14 += 10; + __Pyx_GIVEREF(__pyx_kp_u_complete); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_kp_u_complete); + + /* "pygeoprocessing/routing/routing.pyx":3754 + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: + * LOGGER.info( + * f'(discovery time processing): ' # <<<<<<<<<<<<<< + * f'{n_processed/n_pixels*100:.1f}% complete') + * last_log_time = ctime(NULL) + */ + __pyx_t_3 = __Pyx_PyUnicode_Join(__pyx_t_10, 3, __pyx_t_14, __pyx_t_15); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3754, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_4 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_10, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3753, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3756 + * f'(discovery time processing): ' + * f'{n_processed/n_pixels*100:.1f}% complete') + * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< + * xoff = offset_dict['xoff'] + * yoff = offset_dict['yoff'] + */ + __pyx_v_last_log_time = time(NULL); + + /* "pygeoprocessing/routing/routing.pyx":3752 + * flow_dir_d8_raster_path_band, offset_only=True): + * # search raster block by raster block + * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * LOGGER.info( + * f'(discovery time processing): ' + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3757 + * f'{n_processed/n_pixels*100:.1f}% complete') + * last_log_time = ctime(NULL) + * xoff = offset_dict['xoff'] # <<<<<<<<<<<<<< + * yoff = offset_dict['yoff'] + * win_xsize = offset_dict['win_xsize'] + */ + __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_xoff); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3757, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3757, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_xoff = __pyx_t_7; + + /* "pygeoprocessing/routing/routing.pyx":3758 + * last_log_time = ctime(NULL) + * xoff = offset_dict['xoff'] + * yoff = offset_dict['yoff'] # <<<<<<<<<<<<<< + * win_xsize = offset_dict['win_xsize'] + * win_ysize = offset_dict['win_ysize'] + */ + __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_yoff); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3758, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3758, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_yoff = __pyx_t_7; + + /* "pygeoprocessing/routing/routing.pyx":3759 + * xoff = offset_dict['xoff'] + * yoff = offset_dict['yoff'] + * win_xsize = offset_dict['win_xsize'] # <<<<<<<<<<<<<< + * win_ysize = offset_dict['win_ysize'] + * n_processed += win_xsize * win_ysize + */ + __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3759, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3759, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_win_xsize = __pyx_t_7; + + /* "pygeoprocessing/routing/routing.pyx":3760 + * yoff = offset_dict['yoff'] + * win_xsize = offset_dict['win_xsize'] + * win_ysize = offset_dict['win_ysize'] # <<<<<<<<<<<<<< + * n_processed += win_xsize * win_ysize + * + */ + __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3760, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3760, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_win_ysize = __pyx_t_7; + + /* "pygeoprocessing/routing/routing.pyx":3761 + * win_xsize = offset_dict['win_xsize'] + * win_ysize = offset_dict['win_ysize'] + * n_processed += win_xsize * win_ysize # <<<<<<<<<<<<<< + * + * for i in range(win_xsize): + */ + __pyx_v_n_processed = (__pyx_v_n_processed + (__pyx_v_win_xsize * __pyx_v_win_ysize)); + + /* "pygeoprocessing/routing/routing.pyx":3763 + * n_processed += win_xsize * win_ysize + * + * for i in range(win_xsize): # <<<<<<<<<<<<<< + * for j in range(win_ysize): + * x_l = xoff + i + */ + __pyx_t_7 = __pyx_v_win_xsize; + __pyx_t_6 = __pyx_t_7; + for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_6; __pyx_t_16+=1) { + __pyx_v_i = __pyx_t_16; + + /* "pygeoprocessing/routing/routing.pyx":3764 + * + * for i in range(win_xsize): + * for j in range(win_ysize): # <<<<<<<<<<<<<< + * x_l = xoff + i + * y_l = yoff + j + */ + __pyx_t_17 = __pyx_v_win_ysize; + __pyx_t_18 = __pyx_t_17; + for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_18; __pyx_t_19+=1) { + __pyx_v_j = __pyx_t_19; + + /* "pygeoprocessing/routing/routing.pyx":3765 + * for i in range(win_xsize): + * for j in range(win_ysize): + * x_l = xoff + i # <<<<<<<<<<<<<< + * y_l = yoff + j + * # check to see if this pixel is a drain + */ + __pyx_v_x_l = (__pyx_v_xoff + __pyx_v_i); + + /* "pygeoprocessing/routing/routing.pyx":3766 + * for j in range(win_ysize): + * x_l = xoff + i + * y_l = yoff + j # <<<<<<<<<<<<<< + * # check to see if this pixel is a drain + * d_n = flow_dir_managed_raster.get(x_l, y_l) + */ + __pyx_v_y_l = (__pyx_v_yoff + __pyx_v_j); + + /* "pygeoprocessing/routing/routing.pyx":3768 + * y_l = yoff + j + * # check to see if this pixel is a drain + * d_n = flow_dir_managed_raster.get(x_l, y_l) # <<<<<<<<<<<<<< + * if d_n == flow_dir_nodata: + * continue + */ + __pyx_v_d_n = ((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_dir_managed_raster, __pyx_v_x_l, __pyx_v_y_l)); + + /* "pygeoprocessing/routing/routing.pyx":3769 + * # check to see if this pixel is a drain + * d_n = flow_dir_managed_raster.get(x_l, y_l) + * if d_n == flow_dir_nodata: # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_13 = ((__pyx_v_d_n == __pyx_v_flow_dir_nodata) != 0); + if (__pyx_t_13) { + + /* "pygeoprocessing/routing/routing.pyx":3770 + * d_n = flow_dir_managed_raster.get(x_l, y_l) + * if d_n == flow_dir_nodata: + * continue # <<<<<<<<<<<<<< + * + * # check if downstream neighbor runs off raster or is nodata + */ + goto __pyx_L10_continue; + + /* "pygeoprocessing/routing/routing.pyx":3769 + * # check to see if this pixel is a drain + * d_n = flow_dir_managed_raster.get(x_l, y_l) + * if d_n == flow_dir_nodata: # <<<<<<<<<<<<<< + * continue + * + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3773 + * + * # check if downstream neighbor runs off raster or is nodata + * x_n = x_l + D8_XOFFSET[d_n] # <<<<<<<<<<<<<< + * y_n = y_l + D8_YOFFSET[d_n] + * + */ + __pyx_v_x_n = (__pyx_v_x_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_d_n])); + + /* "pygeoprocessing/routing/routing.pyx":3774 + * # check if downstream neighbor runs off raster or is nodata + * x_n = x_l + D8_XOFFSET[d_n] + * y_n = y_l + D8_YOFFSET[d_n] # <<<<<<<<<<<<<< + * + * if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows or + */ + __pyx_v_y_n = (__pyx_v_y_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_d_n])); + + /* "pygeoprocessing/routing/routing.pyx":3776 + * y_n = y_l + D8_YOFFSET[d_n] + * + * if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows or # <<<<<<<<<<<<<< + * flow_dir_managed_raster.get( + * x_n, y_n) == flow_dir_nodata): + */ + __pyx_t_20 = ((__pyx_v_x_n < 0) != 0); + if (!__pyx_t_20) { + } else { + __pyx_t_13 = __pyx_t_20; + goto __pyx_L14_bool_binop_done; + } + __pyx_t_20 = ((__pyx_v_y_n < 0) != 0); + if (!__pyx_t_20) { + } else { + __pyx_t_13 = __pyx_t_20; + goto __pyx_L14_bool_binop_done; + } + __pyx_t_20 = ((__pyx_v_x_n >= __pyx_v_n_cols) != 0); + if (!__pyx_t_20) { + } else { + __pyx_t_13 = __pyx_t_20; + goto __pyx_L14_bool_binop_done; + } + __pyx_t_20 = ((__pyx_v_y_n >= __pyx_v_n_rows) != 0); + if (!__pyx_t_20) { + } else { + __pyx_t_13 = __pyx_t_20; + goto __pyx_L14_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":3778 + * if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows or + * flow_dir_managed_raster.get( + * x_n, y_n) == flow_dir_nodata): # <<<<<<<<<<<<<< + * discovery_stack.push(CoordinateType(x_l, y_l)) + * finish_stack.push(FinishType(x_l, y_l, 1)) + */ + __pyx_t_20 = ((((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_dir_managed_raster, __pyx_v_x_n, __pyx_v_y_n)) == __pyx_v_flow_dir_nodata) != 0); + __pyx_t_13 = __pyx_t_20; + __pyx_L14_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":3776 + * y_n = y_l + D8_YOFFSET[d_n] + * + * if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows or # <<<<<<<<<<<<<< + * flow_dir_managed_raster.get( + * x_n, y_n) == flow_dir_nodata): + */ + if (__pyx_t_13) { + + /* "pygeoprocessing/routing/routing.pyx":3779 + * flow_dir_managed_raster.get( + * x_n, y_n) == flow_dir_nodata): + * discovery_stack.push(CoordinateType(x_l, y_l)) # <<<<<<<<<<<<<< + * finish_stack.push(FinishType(x_l, y_l, 1)) + * + */ + __pyx_t_21.xi = __pyx_v_x_l; + __pyx_t_21.yi = __pyx_v_y_l; + __pyx_v_discovery_stack.push(__pyx_t_21); + + /* "pygeoprocessing/routing/routing.pyx":3780 + * x_n, y_n) == flow_dir_nodata): + * discovery_stack.push(CoordinateType(x_l, y_l)) + * finish_stack.push(FinishType(x_l, y_l, 1)) # <<<<<<<<<<<<<< + * + * while not discovery_stack.empty(): + */ + __pyx_t_22.xi = __pyx_v_x_l; + __pyx_t_22.yi = __pyx_v_y_l; + __pyx_t_22.n_pushed = 1; + __pyx_v_finish_stack.push(__pyx_t_22); + + /* "pygeoprocessing/routing/routing.pyx":3776 + * y_n = y_l + D8_YOFFSET[d_n] + * + * if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows or # <<<<<<<<<<<<<< + * flow_dir_managed_raster.get( + * x_n, y_n) == flow_dir_nodata): + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3782 + * finish_stack.push(FinishType(x_l, y_l, 1)) + * + * while not discovery_stack.empty(): # <<<<<<<<<<<<<< + * # This coordinate is the downstream end of the stream + * raster_coord = discovery_stack.top() + */ + while (1) { + __pyx_t_13 = ((!(__pyx_v_discovery_stack.empty() != 0)) != 0); + if (!__pyx_t_13) break; + + /* "pygeoprocessing/routing/routing.pyx":3784 + * while not discovery_stack.empty(): + * # This coordinate is the downstream end of the stream + * raster_coord = discovery_stack.top() # <<<<<<<<<<<<<< + * discovery_stack.pop() + * + */ + __pyx_v_raster_coord = __pyx_v_discovery_stack.top(); + + /* "pygeoprocessing/routing/routing.pyx":3785 + * # This coordinate is the downstream end of the stream + * raster_coord = discovery_stack.top() + * discovery_stack.pop() # <<<<<<<<<<<<<< + * + * discovery_managed_raster.set( + */ + __pyx_v_discovery_stack.pop(); + + /* "pygeoprocessing/routing/routing.pyx":3787 + * discovery_stack.pop() + * + * discovery_managed_raster.set( # <<<<<<<<<<<<<< + * raster_coord.xi, raster_coord.yi, discovery_count) + * discovery_count += 1 + */ + __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_discovery_managed_raster, __pyx_v_raster_coord.xi, __pyx_v_raster_coord.yi, __pyx_v_discovery_count); + + /* "pygeoprocessing/routing/routing.pyx":3789 + * discovery_managed_raster.set( + * raster_coord.xi, raster_coord.yi, discovery_count) + * discovery_count += 1 # <<<<<<<<<<<<<< + * + * n_pushed = 0 + */ + __pyx_v_discovery_count = (__pyx_v_discovery_count + 1); + + /* "pygeoprocessing/routing/routing.pyx":3791 + * discovery_count += 1 + * + * n_pushed = 0 # <<<<<<<<<<<<<< + * # check each neighbor to see if it drains to this cell + * # if so, it's on the traversal path + */ + __pyx_v_n_pushed = 0; + + /* "pygeoprocessing/routing/routing.pyx":3794 + * # check each neighbor to see if it drains to this cell + * # if so, it's on the traversal path + * for test_dir in range(8): # <<<<<<<<<<<<<< + * x_n = raster_coord.xi + D8_XOFFSET[test_dir % 8] + * y_n = raster_coord.yi + D8_YOFFSET[test_dir % 8] + */ + for (__pyx_t_23 = 0; __pyx_t_23 < 8; __pyx_t_23+=1) { + __pyx_v_test_dir = __pyx_t_23; + + /* "pygeoprocessing/routing/routing.pyx":3795 + * # if so, it's on the traversal path + * for test_dir in range(8): + * x_n = raster_coord.xi + D8_XOFFSET[test_dir % 8] # <<<<<<<<<<<<<< + * y_n = raster_coord.yi + D8_YOFFSET[test_dir % 8] + * if x_n < 0 or y_n < 0 or \ + */ + __pyx_v_x_n = (__pyx_v_raster_coord.xi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__Pyx_mod_long(__pyx_v_test_dir, 8)])); + + /* "pygeoprocessing/routing/routing.pyx":3796 + * for test_dir in range(8): + * x_n = raster_coord.xi + D8_XOFFSET[test_dir % 8] + * y_n = raster_coord.yi + D8_YOFFSET[test_dir % 8] # <<<<<<<<<<<<<< + * if x_n < 0 or y_n < 0 or \ + * x_n >= n_cols or y_n >= n_rows: + */ + __pyx_v_y_n = (__pyx_v_raster_coord.yi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__Pyx_mod_long(__pyx_v_test_dir, 8)])); + + /* "pygeoprocessing/routing/routing.pyx":3797 + * x_n = raster_coord.xi + D8_XOFFSET[test_dir % 8] + * y_n = raster_coord.yi + D8_YOFFSET[test_dir % 8] + * if x_n < 0 or y_n < 0 or \ # <<<<<<<<<<<<<< + * x_n >= n_cols or y_n >= n_rows: + * continue + */ + __pyx_t_20 = ((__pyx_v_x_n < 0) != 0); + if (!__pyx_t_20) { + } else { + __pyx_t_13 = __pyx_t_20; + goto __pyx_L24_bool_binop_done; + } + __pyx_t_20 = ((__pyx_v_y_n < 0) != 0); + if (!__pyx_t_20) { + } else { + __pyx_t_13 = __pyx_t_20; + goto __pyx_L24_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":3798 + * y_n = raster_coord.yi + D8_YOFFSET[test_dir % 8] + * if x_n < 0 or y_n < 0 or \ + * x_n >= n_cols or y_n >= n_rows: # <<<<<<<<<<<<<< + * continue + * n_dir = flow_dir_managed_raster.get(x_n, y_n) + */ + __pyx_t_20 = ((__pyx_v_x_n >= __pyx_v_n_cols) != 0); + if (!__pyx_t_20) { + } else { + __pyx_t_13 = __pyx_t_20; + goto __pyx_L24_bool_binop_done; + } + __pyx_t_20 = ((__pyx_v_y_n >= __pyx_v_n_rows) != 0); + __pyx_t_13 = __pyx_t_20; + __pyx_L24_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":3797 + * x_n = raster_coord.xi + D8_XOFFSET[test_dir % 8] + * y_n = raster_coord.yi + D8_YOFFSET[test_dir % 8] + * if x_n < 0 or y_n < 0 or \ # <<<<<<<<<<<<<< + * x_n >= n_cols or y_n >= n_rows: + * continue + */ + if (__pyx_t_13) { + + /* "pygeoprocessing/routing/routing.pyx":3799 + * if x_n < 0 or y_n < 0 or \ + * x_n >= n_cols or y_n >= n_rows: + * continue # <<<<<<<<<<<<<< + * n_dir = flow_dir_managed_raster.get(x_n, y_n) + * if n_dir == flow_dir_nodata: + */ + goto __pyx_L21_continue; + + /* "pygeoprocessing/routing/routing.pyx":3797 + * x_n = raster_coord.xi + D8_XOFFSET[test_dir % 8] + * y_n = raster_coord.yi + D8_YOFFSET[test_dir % 8] + * if x_n < 0 or y_n < 0 or \ # <<<<<<<<<<<<<< + * x_n >= n_cols or y_n >= n_rows: + * continue + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3800 + * x_n >= n_cols or y_n >= n_rows: + * continue + * n_dir = flow_dir_managed_raster.get(x_n, y_n) # <<<<<<<<<<<<<< + * if n_dir == flow_dir_nodata: + * continue + */ + __pyx_v_n_dir = ((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_dir_managed_raster, __pyx_v_x_n, __pyx_v_y_n)); + + /* "pygeoprocessing/routing/routing.pyx":3801 + * continue + * n_dir = flow_dir_managed_raster.get(x_n, y_n) + * if n_dir == flow_dir_nodata: # <<<<<<<<<<<<<< + * continue + * if D8_REVERSE_DIRECTION[test_dir] == n_dir: + */ + __pyx_t_13 = ((__pyx_v_n_dir == __pyx_v_flow_dir_nodata) != 0); + if (__pyx_t_13) { + + /* "pygeoprocessing/routing/routing.pyx":3802 + * n_dir = flow_dir_managed_raster.get(x_n, y_n) + * if n_dir == flow_dir_nodata: + * continue # <<<<<<<<<<<<<< + * if D8_REVERSE_DIRECTION[test_dir] == n_dir: + * discovery_stack.push(CoordinateType(x_n, y_n)) + */ + goto __pyx_L21_continue; + + /* "pygeoprocessing/routing/routing.pyx":3801 + * continue + * n_dir = flow_dir_managed_raster.get(x_n, y_n) + * if n_dir == flow_dir_nodata: # <<<<<<<<<<<<<< + * continue + * if D8_REVERSE_DIRECTION[test_dir] == n_dir: + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3803 + * if n_dir == flow_dir_nodata: + * continue + * if D8_REVERSE_DIRECTION[test_dir] == n_dir: # <<<<<<<<<<<<<< + * discovery_stack.push(CoordinateType(x_n, y_n)) + * n_pushed += 1 + */ + __pyx_t_13 = (((__pyx_v_15pygeoprocessing_7routing_7routing_D8_REVERSE_DIRECTION[__pyx_v_test_dir]) == __pyx_v_n_dir) != 0); + if (__pyx_t_13) { + + /* "pygeoprocessing/routing/routing.pyx":3804 + * continue + * if D8_REVERSE_DIRECTION[test_dir] == n_dir: + * discovery_stack.push(CoordinateType(x_n, y_n)) # <<<<<<<<<<<<<< + * n_pushed += 1 + * # this reference is for the previous top and represents + */ + __pyx_t_21.xi = __pyx_v_x_n; + __pyx_t_21.yi = __pyx_v_y_n; + __pyx_v_discovery_stack.push(__pyx_t_21); + + /* "pygeoprocessing/routing/routing.pyx":3805 + * if D8_REVERSE_DIRECTION[test_dir] == n_dir: + * discovery_stack.push(CoordinateType(x_n, y_n)) + * n_pushed += 1 # <<<<<<<<<<<<<< + * # this reference is for the previous top and represents + * # how many elements must be processed before finish + */ + __pyx_v_n_pushed = (__pyx_v_n_pushed + 1); + + /* "pygeoprocessing/routing/routing.pyx":3803 + * if n_dir == flow_dir_nodata: + * continue + * if D8_REVERSE_DIRECTION[test_dir] == n_dir: # <<<<<<<<<<<<<< + * discovery_stack.push(CoordinateType(x_n, y_n)) + * n_pushed += 1 + */ + } + __pyx_L21_continue:; + } + + /* "pygeoprocessing/routing/routing.pyx":3811 + * finish_stack.push( + * FinishType( + * raster_coord.xi, raster_coord.yi, n_pushed)) # <<<<<<<<<<<<<< + * + * # pop the finish stack until n_pushed > 1 + */ + __pyx_t_22.xi = __pyx_v_raster_coord.xi; + __pyx_t_22.yi = __pyx_v_raster_coord.yi; + __pyx_t_22.n_pushed = __pyx_v_n_pushed; + + /* "pygeoprocessing/routing/routing.pyx":3809 + * # how many elements must be processed before finish + * # time can be defined + * finish_stack.push( # <<<<<<<<<<<<<< + * FinishType( + * raster_coord.xi, raster_coord.yi, n_pushed)) + */ + __pyx_v_finish_stack.push(__pyx_t_22); + + /* "pygeoprocessing/routing/routing.pyx":3814 + * + * # pop the finish stack until n_pushed > 1 + * if n_pushed == 0: # <<<<<<<<<<<<<< + * while (not finish_stack.empty() and + * finish_stack.top().n_pushed <= 1): + */ + __pyx_t_13 = ((__pyx_v_n_pushed == 0) != 0); + if (__pyx_t_13) { + + /* "pygeoprocessing/routing/routing.pyx":3815 + * # pop the finish stack until n_pushed > 1 + * if n_pushed == 0: + * while (not finish_stack.empty() and # <<<<<<<<<<<<<< + * finish_stack.top().n_pushed <= 1): + * finish_coordinate = finish_stack.top() + */ + while (1) { + __pyx_t_20 = ((!(__pyx_v_finish_stack.empty() != 0)) != 0); + if (__pyx_t_20) { + } else { + __pyx_t_13 = __pyx_t_20; + goto __pyx_L33_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":3816 + * if n_pushed == 0: + * while (not finish_stack.empty() and + * finish_stack.top().n_pushed <= 1): # <<<<<<<<<<<<<< + * finish_coordinate = finish_stack.top() + * finish_stack.pop() + */ + __pyx_t_20 = ((__pyx_v_finish_stack.top().n_pushed <= 1) != 0); + __pyx_t_13 = __pyx_t_20; + __pyx_L33_bool_binop_done:; + if (!__pyx_t_13) break; + + /* "pygeoprocessing/routing/routing.pyx":3817 + * while (not finish_stack.empty() and + * finish_stack.top().n_pushed <= 1): + * finish_coordinate = finish_stack.top() # <<<<<<<<<<<<<< + * finish_stack.pop() + * finish_managed_raster.set( + */ + __pyx_v_finish_coordinate = __pyx_v_finish_stack.top(); + + /* "pygeoprocessing/routing/routing.pyx":3818 + * finish_stack.top().n_pushed <= 1): + * finish_coordinate = finish_stack.top() + * finish_stack.pop() # <<<<<<<<<<<<<< + * finish_managed_raster.set( + * finish_coordinate.xi, finish_coordinate.yi, + */ + __pyx_v_finish_stack.pop(); + + /* "pygeoprocessing/routing/routing.pyx":3819 + * finish_coordinate = finish_stack.top() + * finish_stack.pop() + * finish_managed_raster.set( # <<<<<<<<<<<<<< + * finish_coordinate.xi, finish_coordinate.yi, + * discovery_count-1) + */ + __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_finish_managed_raster, __pyx_v_finish_coordinate.xi, __pyx_v_finish_coordinate.yi, (__pyx_v_discovery_count - 1)); + } + + /* "pygeoprocessing/routing/routing.pyx":3822 + * finish_coordinate.xi, finish_coordinate.yi, + * discovery_count-1) + * if not finish_stack.empty(): # <<<<<<<<<<<<<< + * # then take one more because one branch is done + * finish_coordinate = finish_stack.top() + */ + __pyx_t_13 = ((!(__pyx_v_finish_stack.empty() != 0)) != 0); + if (__pyx_t_13) { + + /* "pygeoprocessing/routing/routing.pyx":3824 + * if not finish_stack.empty(): + * # then take one more because one branch is done + * finish_coordinate = finish_stack.top() # <<<<<<<<<<<<<< + * finish_stack.pop() + * finish_coordinate.n_pushed -= 1 + */ + __pyx_v_finish_coordinate = __pyx_v_finish_stack.top(); + + /* "pygeoprocessing/routing/routing.pyx":3825 + * # then take one more because one branch is done + * finish_coordinate = finish_stack.top() + * finish_stack.pop() # <<<<<<<<<<<<<< + * finish_coordinate.n_pushed -= 1 + * finish_stack.push(finish_coordinate) + */ + __pyx_v_finish_stack.pop(); + + /* "pygeoprocessing/routing/routing.pyx":3826 + * finish_coordinate = finish_stack.top() + * finish_stack.pop() + * finish_coordinate.n_pushed -= 1 # <<<<<<<<<<<<<< + * finish_stack.push(finish_coordinate) + * + */ + __pyx_v_finish_coordinate.n_pushed = (__pyx_v_finish_coordinate.n_pushed - 1); + + /* "pygeoprocessing/routing/routing.pyx":3827 + * finish_stack.pop() + * finish_coordinate.n_pushed -= 1 + * finish_stack.push(finish_coordinate) # <<<<<<<<<<<<<< + * + * + */ + __pyx_v_finish_stack.push(__pyx_v_finish_coordinate); + + /* "pygeoprocessing/routing/routing.pyx":3822 + * finish_coordinate.xi, finish_coordinate.yi, + * discovery_count-1) + * if not finish_stack.empty(): # <<<<<<<<<<<<<< + * # then take one more because one branch is done + * finish_coordinate = finish_stack.top() + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3814 + * + * # pop the finish stack until n_pushed > 1 + * if n_pushed == 0: # <<<<<<<<<<<<<< + * while (not finish_stack.empty() and + * finish_stack.top().n_pushed <= 1): + */ + } + } + __pyx_L10_continue:; + } + } + + /* "pygeoprocessing/routing/routing.pyx":3749 + * cdef int n_dir, test_dir + * + * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band, offset_only=True): + * # search raster block by raster block + */ + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3700 + * + * + * def _build_discovery_finish_rasters( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band, target_discovery_raster_path, + * target_finish_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_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("pygeoprocessing.routing.routing._build_discovery_finish_rasters", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_flow_dir_info); + __Pyx_XDECREF((PyObject *)__pyx_v_flow_dir_managed_raster); + __Pyx_XDECREF((PyObject *)__pyx_v_discovery_managed_raster); + __Pyx_XDECREF((PyObject *)__pyx_v_finish_managed_raster); + __Pyx_XDECREF(__pyx_v_offset_dict); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pygeoprocessing/routing/routing.pyx":3830 + * + * + * def calculate_subwatershed_boundary( # <<<<<<<<<<<<<< + * d8_flow_dir_raster_path_band, + * strahler_stream_vector_path, target_watershed_boundary_vector_path, + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_25calculate_subwatershed_boundary(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_15pygeoprocessing_7routing_7routing_24calculate_subwatershed_boundary[] = "Calculate a linestring boundary around all subwatersheds.\n\n Subwatersheds start where the ``strahler_stream_vector`` has a junction\n starting at this highest upstream to lowest and ending at the outlet of\n a river.\n\n Args:\n d8_flow_dir_raster_path_band (tuple): raster/path band for d8 flow dir\n raster\n strahler_stream_vector_path (str): path to stream segment vector\n target_watershed_boundary_vector_path (str): path to created vector\n of linestring for watershed boundaries. Contains the fields:\n\n * \"stream_id\": this is the stream ID from the\n ``strahler_stream_vector_path`` that corresponds to this\n subwatershed.\n * \"terminated_early\": if set to 1 this watershed generation was\n terminated before it could be complete. This value should\n always be 0 unless something is wrong as a software bug\n or some degenerate case of data.\n * \"outlet_x\", \"outlet_y\": this is the x/y coordinate in raster\n space of the outlet of the watershed. It can be useful when\n determining other properties about the watershed when indexed\n with underlying raster data that created the streams in\n ``strahler_stream_vector_path``.\n\n max_steps_per_watershed (int): maximum number of steps to take when\n defining a watershed boundary. Useful if the DEM is large and\n degenerate or some other user known condition to limit long large\n polygons. Defaults to 1000000.\n outlet_at_confluence (bool): If True the outlet of subwatersheds\n starts at the confluence of streams. If False (the default)\n subwatersheds will start one pixel up from the confluence.\n\n Returns:\n None.\n "; +static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_25calculate_subwatershed_boundary = {"calculate_subwatershed_boundary", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_7routing_7routing_25calculate_subwatershed_boundary, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_7routing_7routing_24calculate_subwatershed_boundary}; +static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_25calculate_subwatershed_boundary(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_d8_flow_dir_raster_path_band = 0; + PyObject *__pyx_v_strahler_stream_vector_path = 0; + PyObject *__pyx_v_target_watershed_boundary_vector_path = 0; + PyObject *__pyx_v_max_steps_per_watershed = 0; + PyObject *__pyx_v_outlet_at_confluence = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("calculate_subwatershed_boundary (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_d8_flow_dir_raster_path_band,&__pyx_n_s_strahler_stream_vector_path,&__pyx_n_s_target_watershed_boundary_vector,&__pyx_n_s_max_steps_per_watershed,&__pyx_n_s_outlet_at_confluence,0}; + PyObject* values[5] = {0,0,0,0,0}; + values[3] = ((PyObject *)__pyx_int_1000000); + + /* "pygeoprocessing/routing/routing.pyx":3834 + * strahler_stream_vector_path, target_watershed_boundary_vector_path, + * max_steps_per_watershed=1000000, + * outlet_at_confluence=False): # <<<<<<<<<<<<<< + * """Calculate a linestring boundary around all subwatersheds. + * + */ + values[4] = ((PyObject *)Py_False); + 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_d8_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_strahler_stream_vector_path)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("calculate_subwatershed_boundary", 0, 3, 5, 1); __PYX_ERR(0, 3830, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_watershed_boundary_vector)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("calculate_subwatershed_boundary", 0, 3, 5, 2); __PYX_ERR(0, 3830, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 3: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_max_steps_per_watershed); + 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_outlet_at_confluence); + if (value) { values[4] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "calculate_subwatershed_boundary") < 0)) __PYX_ERR(0, 3830, __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_d8_flow_dir_raster_path_band = values[0]; + __pyx_v_strahler_stream_vector_path = values[1]; + __pyx_v_target_watershed_boundary_vector_path = values[2]; + __pyx_v_max_steps_per_watershed = values[3]; + __pyx_v_outlet_at_confluence = values[4]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("calculate_subwatershed_boundary", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3830, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pygeoprocessing.routing.routing.calculate_subwatershed_boundary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing_24calculate_subwatershed_boundary(__pyx_self, __pyx_v_d8_flow_dir_raster_path_band, __pyx_v_strahler_stream_vector_path, __pyx_v_target_watershed_boundary_vector_path, __pyx_v_max_steps_per_watershed, __pyx_v_outlet_at_confluence); + + /* "pygeoprocessing/routing/routing.pyx":3830 + * + * + * def calculate_subwatershed_boundary( # <<<<<<<<<<<<<< + * d8_flow_dir_raster_path_band, + * strahler_stream_vector_path, target_watershed_boundary_vector_path, + */ + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_24calculate_subwatershed_boundary(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_d8_flow_dir_raster_path_band, PyObject *__pyx_v_strahler_stream_vector_path, PyObject *__pyx_v_target_watershed_boundary_vector_path, PyObject *__pyx_v_max_steps_per_watershed, PyObject *__pyx_v_outlet_at_confluence) { + PyObject *__pyx_v_workspace_dir = NULL; + PyObject *__pyx_v_discovery_time_raster_path = NULL; + PyObject *__pyx_v_finish_time_raster_path = NULL; + struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_discovery_managed_raster = NULL; + struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_finish_managed_raster = NULL; + struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_d8_flow_dir_managed_raster = NULL; + PyObject *__pyx_v_discovery_info = NULL; + long __pyx_v_discovery_nodata; + int __pyx_v_n_cols; + int __pyx_v_n_rows; + PyObject *__pyx_v_geotransform = NULL; + double __pyx_v_g0; + double __pyx_v_g1; + double __pyx_v_g2; + double __pyx_v_g3; + double __pyx_v_g4; + double __pyx_v_g5; + PyObject *__pyx_v_discovery_srs = NULL; + PyObject *__pyx_v_gpkg_driver = NULL; + PyObject *__pyx_v_watershed_vector = NULL; + PyObject *__pyx_v_watershed_basename = NULL; + PyObject *__pyx_v_watershed_layer = NULL; + int __pyx_v_x_l; + int __pyx_v_y_l; + int __pyx_v_outflow_dir; + double __pyx_v_x_f; + double __pyx_v_y_f; + double __pyx_v_x_p; + double __pyx_v_y_p; + long __pyx_v_discovery; + long __pyx_v_finish; + time_t __pyx_v_last_log_time; + PyObject *__pyx_v_stream_vector = NULL; + PyObject *__pyx_v_stream_layer = NULL; + PyObject *__pyx_v_upstream_fid_map = NULL; + PyObject *__pyx_v_stream_feature = NULL; + PyObject *__pyx_v_ds_x = NULL; + PyObject *__pyx_v_ds_y = NULL; + PyObject *__pyx_v_visit_order_stack = NULL; + CYTHON_UNUSED PyObject *__pyx_v__ = NULL; + PyObject *__pyx_v_outlet_fid = NULL; + PyObject *__pyx_v_working_stack = NULL; + PyObject *__pyx_v_processed_nodes = NULL; + PyObject *__pyx_v_working_fid = NULL; + PyObject *__pyx_v_working_feature = NULL; + PyObject *__pyx_v_us_x = NULL; + PyObject *__pyx_v_us_y = NULL; + PyObject *__pyx_v_ds_x_1 = NULL; + PyObject *__pyx_v_ds_y_1 = NULL; + PyObject *__pyx_v_upstream_coord = NULL; + PyObject *__pyx_v_upstream_fids = NULL; + int __pyx_v_edge_side; + int __pyx_v_edge_dir; + int __pyx_v_cell_to_test; + int __pyx_v_out_dir_increase; + int __pyx_v_left; + int __pyx_v_right; + int __pyx_v_n_steps; + int __pyx_v_terminated_early; + int __pyx_v_delta_x; + int __pyx_v_delta_y; + int __pyx_v__int_max_steps_per_watershed; + PyObject *__pyx_v_index = NULL; + PyObject *__pyx_v_stream_fid = NULL; + PyObject *__pyx_v_boundary_list = NULL; + int __pyx_v_outlet_x; + int __pyx_v_outlet_y; + PyObject *__pyx_v_watershed_boundary = NULL; + int __pyx_v_left_in; + int __pyx_v_right_in; + int __pyx_v_out_dir; + PyObject *__pyx_v_watershed_feature = NULL; + PyObject *__pyx_v_watershed_polygon = NULL; + PyObject *__pyx_v_boundary_x = NULL; + PyObject *__pyx_v_boundary_y = NULL; + PyObject *__pyx_8genexpr2__pyx_v_x = NULL; + PyObject *__pyx_8genexpr3__pyx_v_fid = NULL; + 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; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + int __pyx_t_8; + long __pyx_t_9; + PyObject *(*__pyx_t_10)(PyObject *); + int __pyx_t_11; + double __pyx_t_12; + double __pyx_t_13; + double __pyx_t_14; + double __pyx_t_15; + double __pyx_t_16; + double __pyx_t_17; + int __pyx_t_18; + Py_ssize_t __pyx_t_19; + PyObject *(*__pyx_t_20)(PyObject *); + int __pyx_t_21; + Py_ssize_t __pyx_t_22; + PyObject *(*__pyx_t_23)(PyObject *); + int __pyx_t_24; + int __pyx_t_25; + Py_UCS4 __pyx_t_26; + Py_ssize_t __pyx_t_27; + PyObject *__pyx_t_28 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("calculate_subwatershed_boundary", 0); + + /* "pygeoprocessing/routing/routing.pyx":3872 + * None. + * """ + * workspace_dir = tempfile.mkdtemp( # <<<<<<<<<<<<<< + * prefix='calculate_subwatershed_boundary_workspace_', + * dir=os.path.join( + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_tempfile); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3872, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_mkdtemp); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3872, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3873 + * """ + * workspace_dir = tempfile.mkdtemp( + * prefix='calculate_subwatershed_boundary_workspace_', # <<<<<<<<<<<<<< + * dir=os.path.join( + * os.path.dirname(target_watershed_boundary_vector_path))) + */ + __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3873, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_prefix, __pyx_n_u_calculate_subwatershed_boundary) < 0) __PYX_ERR(0, 3873, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3874 + * workspace_dir = tempfile.mkdtemp( + * prefix='calculate_subwatershed_boundary_workspace_', + * dir=os.path.join( # <<<<<<<<<<<<<< + * os.path.dirname(target_watershed_boundary_vector_path))) + * discovery_time_raster_path = os.path.join(workspace_dir, 'discovery.tif') + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_os); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3874, __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, 3874, __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, 3874, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3875 + * prefix='calculate_subwatershed_boundary_workspace_', + * dir=os.path.join( + * os.path.dirname(target_watershed_boundary_vector_path))) # <<<<<<<<<<<<<< + * discovery_time_raster_path = os.path.join(workspace_dir, 'discovery.tif') + * finish_time_raster_path = os.path.join(workspace_dir, 'finish.tif') + */ + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_os); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3875, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_path); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3875, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_dirname); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3875, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_5 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_7, __pyx_v_target_watershed_boundary_vector_path) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_target_watershed_boundary_vector_path); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3875, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3874, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dir, __pyx_t_3) < 0) __PYX_ERR(0, 3873, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3872 + * None. + * """ + * workspace_dir = tempfile.mkdtemp( # <<<<<<<<<<<<<< + * prefix='calculate_subwatershed_boundary_workspace_', + * dir=os.path.join( + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3872, __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_v_workspace_dir = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3876 + * dir=os.path.join( + * os.path.dirname(target_watershed_boundary_vector_path))) + * discovery_time_raster_path = os.path.join(workspace_dir, 'discovery.tif') # <<<<<<<<<<<<<< + * finish_time_raster_path = os.path.join(workspace_dir, 'finish.tif') + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3876, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_path); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3876, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_join); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3876, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + __pyx_t_8 = 0; + if (CYTHON_UNPACK_METHODS && likely(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_8 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_workspace_dir, __pyx_kp_u_discovery_tif}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3876, __pyx_L1_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[3] = {__pyx_t_2, __pyx_v_workspace_dir, __pyx_kp_u_discovery_tif}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3876, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_4 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3876, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (__pyx_t_2) { + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __pyx_t_2 = NULL; + } + __Pyx_INCREF(__pyx_v_workspace_dir); + __Pyx_GIVEREF(__pyx_v_workspace_dir); + PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_8, __pyx_v_workspace_dir); + __Pyx_INCREF(__pyx_kp_u_discovery_tif); + __Pyx_GIVEREF(__pyx_kp_u_discovery_tif); + PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_8, __pyx_kp_u_discovery_tif); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3876, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_discovery_time_raster_path = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3877 + * os.path.dirname(target_watershed_boundary_vector_path))) + * discovery_time_raster_path = os.path.join(workspace_dir, 'discovery.tif') + * finish_time_raster_path = os.path.join(workspace_dir, 'finish.tif') # <<<<<<<<<<<<<< + * + * # construct the discovery/finish time rasters for fast individual cell + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3877, __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, 3877, __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, 3877, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + __pyx_t_8 = 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_8 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_workspace_dir, __pyx_kp_u_finish_tif}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3877, __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_workspace_dir, __pyx_kp_u_finish_tif}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3877, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_2 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3877, __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_INCREF(__pyx_v_workspace_dir); + __Pyx_GIVEREF(__pyx_v_workspace_dir); + PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_8, __pyx_v_workspace_dir); + __Pyx_INCREF(__pyx_kp_u_finish_tif); + __Pyx_GIVEREF(__pyx_kp_u_finish_tif); + PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_8, __pyx_kp_u_finish_tif); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3877, __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_v_finish_time_raster_path = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3881 + * # construct the discovery/finish time rasters for fast individual cell + * # watershed detection + * _build_discovery_finish_rasters( # <<<<<<<<<<<<<< + * d8_flow_dir_raster_path_band, discovery_time_raster_path, + * finish_time_raster_path) + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_build_discovery_finish_rasters); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3881, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":3883 + * _build_discovery_finish_rasters( + * d8_flow_dir_raster_path_band, discovery_time_raster_path, + * finish_time_raster_path) # <<<<<<<<<<<<<< + * + * shutil.copyfile( + */ + __pyx_t_2 = NULL; + __pyx_t_8 = 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_8 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_v_d8_flow_dir_raster_path_band, __pyx_v_discovery_time_raster_path, __pyx_v_finish_time_raster_path}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3881, __pyx_L1_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[4] = {__pyx_t_2, __pyx_v_d8_flow_dir_raster_path_band, __pyx_v_discovery_time_raster_path, __pyx_v_finish_time_raster_path}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3881, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_4 = PyTuple_New(3+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3881, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (__pyx_t_2) { + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __pyx_t_2 = NULL; + } + __Pyx_INCREF(__pyx_v_d8_flow_dir_raster_path_band); + __Pyx_GIVEREF(__pyx_v_d8_flow_dir_raster_path_band); + PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_8, __pyx_v_d8_flow_dir_raster_path_band); + __Pyx_INCREF(__pyx_v_discovery_time_raster_path); + __Pyx_GIVEREF(__pyx_v_discovery_time_raster_path); + PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_8, __pyx_v_discovery_time_raster_path); + __Pyx_INCREF(__pyx_v_finish_time_raster_path); + __Pyx_GIVEREF(__pyx_v_finish_time_raster_path); + PyTuple_SET_ITEM(__pyx_t_4, 2+__pyx_t_8, __pyx_v_finish_time_raster_path); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3881, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __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; + + /* "pygeoprocessing/routing/routing.pyx":3885 + * finish_time_raster_path) + * + * shutil.copyfile( # <<<<<<<<<<<<<< + * discovery_time_raster_path, f'{discovery_time_raster_path}_bak.tif') + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_shutil); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3885, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_copyfile); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3885, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3886 + * + * shutil.copyfile( + * discovery_time_raster_path, f'{discovery_time_raster_path}_bak.tif') # <<<<<<<<<<<<<< + * + * # the discovery raster is filled with nodata around the edges of + */ + __pyx_t_1 = __Pyx_PyObject_FormatSimple(__pyx_v_discovery_time_raster_path, __pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3886, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyUnicode_Concat(__pyx_t_1, __pyx_kp_u_bak_tif); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3886, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + __pyx_t_8 = 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_8 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_discovery_time_raster_path, __pyx_t_2}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3885, __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; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_discovery_time_raster_path, __pyx_t_2}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3885, __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; + } else + #endif + { + __pyx_t_5 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3885, __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_discovery_time_raster_path); + __Pyx_GIVEREF(__pyx_v_discovery_time_raster_path); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_8, __pyx_v_discovery_time_raster_path); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_8, __pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3885, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3890 + * # the discovery raster is filled with nodata around the edges of + * # discovered watersheds, so it is opened for writing + * discovery_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< + * discovery_time_raster_path, 1, 1) + * finish_managed_raster = _ManagedRaster(finish_time_raster_path, 1, 0) + */ + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3890, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_discovery_time_raster_path); + __Pyx_GIVEREF(__pyx_v_discovery_time_raster_path); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_discovery_time_raster_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_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3890, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_discovery_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_4); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3892 + * discovery_managed_raster = _ManagedRaster( + * discovery_time_raster_path, 1, 1) + * finish_managed_raster = _ManagedRaster(finish_time_raster_path, 1, 0) # <<<<<<<<<<<<<< + * d8_flow_dir_managed_raster = _ManagedRaster( + * d8_flow_dir_raster_path_band[0], d8_flow_dir_raster_path_band[1], 0) + */ + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3892, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_finish_time_raster_path); + __Pyx_GIVEREF(__pyx_v_finish_time_raster_path); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_finish_time_raster_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_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_int_0); + __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3892, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_finish_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3894 + * finish_managed_raster = _ManagedRaster(finish_time_raster_path, 1, 0) + * d8_flow_dir_managed_raster = _ManagedRaster( + * d8_flow_dir_raster_path_band[0], d8_flow_dir_raster_path_band[1], 0) # <<<<<<<<<<<<<< + * + * discovery_info = pygeoprocessing.get_raster_info( + */ + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_d8_flow_dir_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3894, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_d8_flow_dir_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3894, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "pygeoprocessing/routing/routing.pyx":3893 + * discovery_time_raster_path, 1, 1) + * finish_managed_raster = _ManagedRaster(finish_time_raster_path, 1, 0) + * d8_flow_dir_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< + * d8_flow_dir_raster_path_band[0], d8_flow_dir_raster_path_band[1], 0) + * + */ + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3893, __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_4); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_int_0); + __pyx_t_3 = 0; + __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3893, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_d8_flow_dir_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_4); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3896 + * d8_flow_dir_raster_path_band[0], d8_flow_dir_raster_path_band[1], 0) + * + * discovery_info = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< + * discovery_time_raster_path) + * cdef long discovery_nodata = discovery_info['nodata'][0] + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3896, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3896, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3897 + * + * discovery_info = pygeoprocessing.get_raster_info( + * discovery_time_raster_path) # <<<<<<<<<<<<<< + * cdef long discovery_nodata = discovery_info['nodata'][0] + * + */ + __pyx_t_5 = NULL; + 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_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_v_discovery_time_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_discovery_time_raster_path); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3896, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_discovery_info = __pyx_t_4; + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3898 + * discovery_info = pygeoprocessing.get_raster_info( + * discovery_time_raster_path) + * cdef long discovery_nodata = discovery_info['nodata'][0] # <<<<<<<<<<<<<< + * + * cdef int n_cols, n_rows + */ + __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_discovery_info, __pyx_n_u_nodata); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3898, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_4, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3898, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_9 = __Pyx_PyInt_As_long(__pyx_t_3); if (unlikely((__pyx_t_9 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 3898, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_discovery_nodata = __pyx_t_9; + + /* "pygeoprocessing/routing/routing.pyx":3901 + * + * cdef int n_cols, n_rows + * n_cols, n_rows = discovery_info['raster_size'] # <<<<<<<<<<<<<< + * + * geotransform = discovery_info['geotransform'] + */ + __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_discovery_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3901, __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, 3901, __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_5 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_4 = PyList_GET_ITEM(sequence, 0); + __pyx_t_5 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + #else + __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3901, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3901, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3901, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_10 = Py_TYPE(__pyx_t_2)->tp_iternext; + index = 0; __pyx_t_4 = __pyx_t_10(__pyx_t_2); if (unlikely(!__pyx_t_4)) goto __pyx_L3_unpacking_failed; + __Pyx_GOTREF(__pyx_t_4); + index = 1; __pyx_t_5 = __pyx_t_10(__pyx_t_2); if (unlikely(!__pyx_t_5)) goto __pyx_L3_unpacking_failed; + __Pyx_GOTREF(__pyx_t_5); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_2), 2) < 0) __PYX_ERR(0, 3901, __pyx_L1_error) + __pyx_t_10 = NULL; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L4_unpacking_done; + __pyx_L3_unpacking_failed:; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_10 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 3901, __pyx_L1_error) + __pyx_L4_unpacking_done:; + } + __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3901, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3901, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_n_cols = __pyx_t_8; + __pyx_v_n_rows = __pyx_t_11; + + /* "pygeoprocessing/routing/routing.pyx":3903 + * n_cols, n_rows = discovery_info['raster_size'] + * + * geotransform = discovery_info['geotransform'] # <<<<<<<<<<<<<< + * cdef double g0, g1, g2, g3, g4, g5 + * g0, g1, g2, g3, g4, g5 = geotransform + */ + __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_discovery_info, __pyx_n_u_geotransform); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3903, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_geotransform = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3905 + * geotransform = discovery_info['geotransform'] + * cdef double g0, g1, g2, g3, g4, g5 + * g0, g1, g2, g3, g4, g5 = geotransform # <<<<<<<<<<<<<< + * + * if discovery_info['projection_wkt']: + */ + if ((likely(PyTuple_CheckExact(__pyx_v_geotransform))) || (PyList_CheckExact(__pyx_v_geotransform))) { + PyObject* sequence = __pyx_v_geotransform; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 6)) { + if (size > 6) __Pyx_RaiseTooManyValuesError(6); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 3905, __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_5 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_2 = PyTuple_GET_ITEM(sequence, 3); + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 4); + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 5); + } else { + __pyx_t_3 = PyList_GET_ITEM(sequence, 0); + __pyx_t_5 = PyList_GET_ITEM(sequence, 1); + __pyx_t_4 = PyList_GET_ITEM(sequence, 2); + __pyx_t_2 = PyList_GET_ITEM(sequence, 3); + __pyx_t_1 = PyList_GET_ITEM(sequence, 4); + __pyx_t_6 = PyList_GET_ITEM(sequence, 5); + } + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_6); + #else + { + Py_ssize_t i; + PyObject** temps[6] = {&__pyx_t_3,&__pyx_t_5,&__pyx_t_4,&__pyx_t_2,&__pyx_t_1,&__pyx_t_6}; + for (i=0; i < 6; i++) { + PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 3905, __pyx_L1_error) + __Pyx_GOTREF(item); + *(temps[i]) = item; + } + } + #endif + } else { + Py_ssize_t index = -1; + PyObject** temps[6] = {&__pyx_t_3,&__pyx_t_5,&__pyx_t_4,&__pyx_t_2,&__pyx_t_1,&__pyx_t_6}; + __pyx_t_7 = PyObject_GetIter(__pyx_v_geotransform); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3905, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_10 = Py_TYPE(__pyx_t_7)->tp_iternext; + for (index=0; index < 6; index++) { + PyObject* item = __pyx_t_10(__pyx_t_7); if (unlikely(!item)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(item); + *(temps[index]) = item; + } + if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_7), 6) < 0) __PYX_ERR(0, 3905, __pyx_L1_error) + __pyx_t_10 = NULL; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L6_unpacking_done; + __pyx_L5_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_10 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 3905, __pyx_L1_error) + __pyx_L6_unpacking_done:; + } + __pyx_t_12 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_12 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 3905, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_13 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_13 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 3905, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_14 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_14 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 3905, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_15 = __pyx_PyFloat_AsDouble(__pyx_t_2); if (unlikely((__pyx_t_15 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 3905, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_16 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_16 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 3905, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_17 = __pyx_PyFloat_AsDouble(__pyx_t_6); if (unlikely((__pyx_t_17 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 3905, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_g0 = __pyx_t_12; + __pyx_v_g1 = __pyx_t_13; + __pyx_v_g2 = __pyx_t_14; + __pyx_v_g3 = __pyx_t_15; + __pyx_v_g4 = __pyx_t_16; + __pyx_v_g5 = __pyx_t_17; + + /* "pygeoprocessing/routing/routing.pyx":3907 + * g0, g1, g2, g3, g4, g5 = geotransform + * + * if discovery_info['projection_wkt']: # <<<<<<<<<<<<<< + * discovery_srs = osr.SpatialReference() + * discovery_srs.ImportFromWkt(discovery_info['projection_wkt']) + */ + __pyx_t_6 = __Pyx_PyObject_Dict_GetItem(__pyx_v_discovery_info, __pyx_n_u_projection_wkt); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3907, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_18 < 0)) __PYX_ERR(0, 3907, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (__pyx_t_18) { + + /* "pygeoprocessing/routing/routing.pyx":3908 + * + * if discovery_info['projection_wkt']: + * discovery_srs = osr.SpatialReference() # <<<<<<<<<<<<<< + * discovery_srs.ImportFromWkt(discovery_info['projection_wkt']) + * else: + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_osr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3908, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_SpatialReference); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3908, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_6 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3908, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_discovery_srs = __pyx_t_6; + __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3909 + * if discovery_info['projection_wkt']: + * discovery_srs = osr.SpatialReference() + * discovery_srs.ImportFromWkt(discovery_info['projection_wkt']) # <<<<<<<<<<<<<< + * else: + * discovery_srs = None + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_discovery_srs, __pyx_n_s_ImportFromWkt); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3909, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_discovery_info, __pyx_n_u_projection_wkt); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3909, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_6 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3909, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3907 + * g0, g1, g2, g3, g4, g5 = geotransform + * + * if discovery_info['projection_wkt']: # <<<<<<<<<<<<<< + * discovery_srs = osr.SpatialReference() + * discovery_srs.ImportFromWkt(discovery_info['projection_wkt']) + */ + goto __pyx_L7; + } + + /* "pygeoprocessing/routing/routing.pyx":3911 + * discovery_srs.ImportFromWkt(discovery_info['projection_wkt']) + * else: + * discovery_srs = None # <<<<<<<<<<<<<< + * gpkg_driver = gdal.GetDriverByName('GPKG') + * + */ + /*else*/ { + __Pyx_INCREF(Py_None); + __pyx_v_discovery_srs = Py_None; + } + __pyx_L7:; + + /* "pygeoprocessing/routing/routing.pyx":3912 + * else: + * discovery_srs = None + * gpkg_driver = gdal.GetDriverByName('GPKG') # <<<<<<<<<<<<<< + * + * if os.path.exists(target_watershed_boundary_vector_path): + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3912, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_GetDriverByName); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3912, __pyx_L1_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); + } + } + __pyx_t_6 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_n_u_GPKG) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_n_u_GPKG); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3912, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_gpkg_driver = __pyx_t_6; + __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3914 + * gpkg_driver = gdal.GetDriverByName('GPKG') + * + * if os.path.exists(target_watershed_boundary_vector_path): # <<<<<<<<<<<<<< + * LOGGER.warning( + * f'{target_watershed_boundary_vector_path} exists, removing ' + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3914, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_path); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3914, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_exists); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3914, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_6 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_v_target_watershed_boundary_vector_path) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_target_watershed_boundary_vector_path); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3914, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_18 < 0)) __PYX_ERR(0, 3914, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (__pyx_t_18) { + + /* "pygeoprocessing/routing/routing.pyx":3915 + * + * if os.path.exists(target_watershed_boundary_vector_path): + * LOGGER.warning( # <<<<<<<<<<<<<< + * f'{target_watershed_boundary_vector_path} exists, removing ' + * 'before creating a new one.') + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3915, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_warning); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3915, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3916 + * if os.path.exists(target_watershed_boundary_vector_path): + * LOGGER.warning( + * f'{target_watershed_boundary_vector_path} exists, removing ' # <<<<<<<<<<<<<< + * 'before creating a new one.') + * os.remove(target_watershed_boundary_vector_path) + */ + __pyx_t_1 = __Pyx_PyObject_FormatSimple(__pyx_v_target_watershed_boundary_vector_path, __pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3916, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyUnicode_Concat(__pyx_t_1, __pyx_kp_u_exists_removing_before_creating); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3916, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_6 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_1, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3915, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3918 + * f'{target_watershed_boundary_vector_path} exists, removing ' + * 'before creating a new one.') + * os.remove(target_watershed_boundary_vector_path) # <<<<<<<<<<<<<< + * watershed_vector = gpkg_driver.Create( + * target_watershed_boundary_vector_path, 0, 0, 0, gdal.GDT_Unknown) + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3918, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_remove); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3918, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + 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_6 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_2, __pyx_v_target_watershed_boundary_vector_path) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_target_watershed_boundary_vector_path); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3918, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3914 + * gpkg_driver = gdal.GetDriverByName('GPKG') + * + * if os.path.exists(target_watershed_boundary_vector_path): # <<<<<<<<<<<<<< + * LOGGER.warning( + * f'{target_watershed_boundary_vector_path} exists, removing ' + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3919 + * 'before creating a new one.') + * os.remove(target_watershed_boundary_vector_path) + * watershed_vector = gpkg_driver.Create( # <<<<<<<<<<<<<< + * target_watershed_boundary_vector_path, 0, 0, 0, gdal.GDT_Unknown) + * watershed_basename = os.path.basename(os.path.splitext( + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_gpkg_driver, __pyx_n_s_Create); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3919, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "pygeoprocessing/routing/routing.pyx":3920 + * os.remove(target_watershed_boundary_vector_path) + * watershed_vector = gpkg_driver.Create( + * target_watershed_boundary_vector_path, 0, 0, 0, gdal.GDT_Unknown) # <<<<<<<<<<<<<< + * watershed_basename = os.path.basename(os.path.splitext( + * target_watershed_boundary_vector_path)[0]) + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3920, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_GDT_Unknown); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3920, __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 && likely(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_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[6] = {__pyx_t_2, __pyx_v_target_watershed_boundary_vector_path, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_t_1}; + __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 5+__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3919, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_6); + __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[6] = {__pyx_t_2, __pyx_v_target_watershed_boundary_vector_path, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_t_1}; + __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 5+__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3919, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + { + __pyx_t_5 = PyTuple_New(5+__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3919, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_2) { + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __pyx_t_2 = NULL; + } + __Pyx_INCREF(__pyx_v_target_watershed_boundary_vector_path); + __Pyx_GIVEREF(__pyx_v_target_watershed_boundary_vector_path); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_11, __pyx_v_target_watershed_boundary_vector_path); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_11, __pyx_int_0); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_11, __pyx_int_0); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_5, 3+__pyx_t_11, __pyx_int_0); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_5, 4+__pyx_t_11, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3919, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_watershed_vector = __pyx_t_6; + __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3921 + * watershed_vector = gpkg_driver.Create( + * target_watershed_boundary_vector_path, 0, 0, 0, gdal.GDT_Unknown) + * watershed_basename = os.path.basename(os.path.splitext( # <<<<<<<<<<<<<< + * target_watershed_boundary_vector_path)[0]) + * watershed_layer = watershed_vector.CreateLayer( + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_os); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3921, __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, 3921, __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_basename); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3921, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3921, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_path); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3921, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_splitext); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3921, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3922 + * target_watershed_boundary_vector_path, 0, 0, 0, gdal.GDT_Unknown) + * watershed_basename = os.path.basename(os.path.splitext( + * target_watershed_boundary_vector_path)[0]) # <<<<<<<<<<<<<< + * watershed_layer = watershed_vector.CreateLayer( + * watershed_basename, discovery_srs, ogr.wkbPolygon) + */ + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_5 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_v_target_watershed_boundary_vector_path) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_target_watershed_boundary_vector_path); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3921, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_5, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3922, __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 && 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_6 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3921, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_watershed_basename = __pyx_t_6; + __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3923 + * watershed_basename = os.path.basename(os.path.splitext( + * target_watershed_boundary_vector_path)[0]) + * watershed_layer = watershed_vector.CreateLayer( # <<<<<<<<<<<<<< + * watershed_basename, discovery_srs, ogr.wkbPolygon) + * watershed_layer.CreateField(ogr.FieldDefn('stream_fid', ogr.OFTInteger)) + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_vector, __pyx_n_s_CreateLayer); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3923, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "pygeoprocessing/routing/routing.pyx":3924 + * target_watershed_boundary_vector_path)[0]) + * watershed_layer = watershed_vector.CreateLayer( + * watershed_basename, discovery_srs, ogr.wkbPolygon) # <<<<<<<<<<<<<< + * watershed_layer.CreateField(ogr.FieldDefn('stream_fid', ogr.OFTInteger)) + * watershed_layer.CreateField( + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3924, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_wkbPolygon); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3924, __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 && likely(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[4] = {__pyx_t_1, __pyx_v_watershed_basename, __pyx_v_discovery_srs, __pyx_t_5}; + __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 3+__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3923, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 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_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_v_watershed_basename, __pyx_v_discovery_srs, __pyx_t_5}; + __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 3+__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3923, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_2 = PyTuple_New(3+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3923, __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_v_watershed_basename); + __Pyx_GIVEREF(__pyx_v_watershed_basename); + PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_11, __pyx_v_watershed_basename); + __Pyx_INCREF(__pyx_v_discovery_srs); + __Pyx_GIVEREF(__pyx_v_discovery_srs); + PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_11, __pyx_v_discovery_srs); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_2, 2+__pyx_t_11, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3923, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_watershed_layer = __pyx_t_6; + __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3925 + * watershed_layer = watershed_vector.CreateLayer( + * watershed_basename, discovery_srs, ogr.wkbPolygon) + * watershed_layer.CreateField(ogr.FieldDefn('stream_fid', ogr.OFTInteger)) # <<<<<<<<<<<<<< + * watershed_layer.CreateField( + * ogr.FieldDefn('terminated_early', ogr.OFTInteger)) + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3925, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_ogr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3925, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3925, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_ogr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3925, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3925, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + __pyx_t_11 = 0; + 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); + __pyx_t_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_n_u_stream_fid, __pyx_t_3}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3925, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + __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[3] = {__pyx_t_5, __pyx_n_u_stream_fid, __pyx_t_3}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3925, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3925, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_5) { + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL; + } + __Pyx_INCREF(__pyx_n_u_stream_fid); + __Pyx_GIVEREF(__pyx_n_u_stream_fid); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_11, __pyx_n_u_stream_fid); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_11, __pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3925, __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_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_6 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3925, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3926 + * watershed_basename, discovery_srs, ogr.wkbPolygon) + * watershed_layer.CreateField(ogr.FieldDefn('stream_fid', ogr.OFTInteger)) + * watershed_layer.CreateField( # <<<<<<<<<<<<<< + * ogr.FieldDefn('terminated_early', ogr.OFTInteger)) + * watershed_layer.CreateField(ogr.FieldDefn('outlet_x', ogr.OFTInteger)) + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3926, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "pygeoprocessing/routing/routing.pyx":3927 + * watershed_layer.CreateField(ogr.FieldDefn('stream_fid', ogr.OFTInteger)) + * watershed_layer.CreateField( + * ogr.FieldDefn('terminated_early', ogr.OFTInteger)) # <<<<<<<<<<<<<< + * watershed_layer.CreateField(ogr.FieldDefn('outlet_x', ogr.OFTInteger)) + * watershed_layer.CreateField(ogr.FieldDefn('outlet_y', ogr.OFTInteger)) + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3927, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3927, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3927, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3927, __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 && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + __pyx_t_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_n_u_terminated_early, __pyx_t_3}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3927, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_n_u_terminated_early, __pyx_t_3}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3927, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + { + __pyx_t_5 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3927, __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_n_u_terminated_early); + __Pyx_GIVEREF(__pyx_n_u_terminated_early); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_11, __pyx_n_u_terminated_early); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_11, __pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3927, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __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); + } + } + __pyx_t_6 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_7, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3926, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3928 + * watershed_layer.CreateField( + * ogr.FieldDefn('terminated_early', ogr.OFTInteger)) + * watershed_layer.CreateField(ogr.FieldDefn('outlet_x', ogr.OFTInteger)) # <<<<<<<<<<<<<< + * watershed_layer.CreateField(ogr.FieldDefn('outlet_y', ogr.OFTInteger)) + * watershed_layer.StartTransaction() + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3928, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3928, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3928, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3928, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3928, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_7); + __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_7, __pyx_n_u_outlet_x, __pyx_t_3}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3928, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + __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_7, __pyx_n_u_outlet_x, __pyx_t_3}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3928, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + __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, 3928, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_n_u_outlet_x); + __Pyx_GIVEREF(__pyx_n_u_outlet_x); + PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_11, __pyx_n_u_outlet_x); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_11, __pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3928, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + 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_6 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3928, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3929 + * ogr.FieldDefn('terminated_early', ogr.OFTInteger)) + * watershed_layer.CreateField(ogr.FieldDefn('outlet_x', ogr.OFTInteger)) + * watershed_layer.CreateField(ogr.FieldDefn('outlet_y', ogr.OFTInteger)) # <<<<<<<<<<<<<< + * watershed_layer.StartTransaction() + * + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3929, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_ogr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3929, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3929, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_ogr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3929, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3929, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + __pyx_t_11 = 0; + 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); + __pyx_t_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_n_u_outlet_y, __pyx_t_3}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3929, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + __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[3] = {__pyx_t_5, __pyx_n_u_outlet_y, __pyx_t_3}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3929, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3929, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_5) { + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL; + } + __Pyx_INCREF(__pyx_n_u_outlet_y); + __Pyx_GIVEREF(__pyx_n_u_outlet_y); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_11, __pyx_n_u_outlet_y); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_11, __pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3929, __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_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_6 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3929, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3930 + * watershed_layer.CreateField(ogr.FieldDefn('outlet_x', ogr.OFTInteger)) + * watershed_layer.CreateField(ogr.FieldDefn('outlet_y', ogr.OFTInteger)) + * watershed_layer.StartTransaction() # <<<<<<<<<<<<<< + * + * cdef int x_l, y_l, outflow_dir + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_layer, __pyx_n_s_StartTransaction); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3930, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_6 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3930, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3937 + * cdef long discovery, finish + * + * cdef time_t last_log_time = ctime(NULL) # <<<<<<<<<<<<<< + * + * stream_vector = gdal.OpenEx(strahler_stream_vector_path, gdal.OF_VECTOR) + */ + __pyx_v_last_log_time = time(NULL); + + /* "pygeoprocessing/routing/routing.pyx":3939 + * cdef time_t last_log_time = ctime(NULL) + * + * stream_vector = gdal.OpenEx(strahler_stream_vector_path, gdal.OF_VECTOR) # <<<<<<<<<<<<<< + * stream_layer = stream_vector.GetLayer() + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3939, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3939, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3939, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OF_VECTOR); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3939, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __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_2))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + __pyx_t_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_strahler_stream_vector_path, __pyx_t_1}; + __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3939, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_strahler_stream_vector_path, __pyx_t_1}; + __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3939, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3939, __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_strahler_stream_vector_path); + __Pyx_GIVEREF(__pyx_v_strahler_stream_vector_path); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_11, __pyx_v_strahler_stream_vector_path); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_11, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_7, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3939, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_stream_vector = __pyx_t_6; + __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3940 + * + * stream_vector = gdal.OpenEx(strahler_stream_vector_path, gdal.OF_VECTOR) + * stream_layer = stream_vector.GetLayer() # <<<<<<<<<<<<<< + * + * # construct linkage data structure for upstream streams + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_vector, __pyx_n_s_GetLayer); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3940, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_6 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3940, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_stream_layer = __pyx_t_6; + __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3943 + * + * # construct linkage data structure for upstream streams + * upstream_fid_map = collections.defaultdict(list) # <<<<<<<<<<<<<< + * for stream_feature in stream_layer: + * ds_x = int(stream_feature.GetField('ds_x')) + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_collections); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3943, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3943, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + 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_6 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_2, ((PyObject *)(&PyList_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_7, ((PyObject *)(&PyList_Type))); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3943, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_upstream_fid_map = __pyx_t_6; + __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3944 + * # construct linkage data structure for upstream streams + * upstream_fid_map = collections.defaultdict(list) + * for stream_feature in stream_layer: # <<<<<<<<<<<<<< + * ds_x = int(stream_feature.GetField('ds_x')) + * ds_y = int(stream_feature.GetField('ds_y')) + */ + if (likely(PyList_CheckExact(__pyx_v_stream_layer)) || PyTuple_CheckExact(__pyx_v_stream_layer)) { + __pyx_t_6 = __pyx_v_stream_layer; __Pyx_INCREF(__pyx_t_6); __pyx_t_19 = 0; + __pyx_t_20 = NULL; + } else { + __pyx_t_19 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_v_stream_layer); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3944, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_20 = Py_TYPE(__pyx_t_6)->tp_iternext; if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 3944, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_20)) { + if (likely(PyList_CheckExact(__pyx_t_6))) { + if (__pyx_t_19 >= PyList_GET_SIZE(__pyx_t_6)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_19); __Pyx_INCREF(__pyx_t_7); __pyx_t_19++; if (unlikely(0 < 0)) __PYX_ERR(0, 3944, __pyx_L1_error) + #else + __pyx_t_7 = PySequence_ITEM(__pyx_t_6, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3944, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + } else { + if (__pyx_t_19 >= PyTuple_GET_SIZE(__pyx_t_6)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_19); __Pyx_INCREF(__pyx_t_7); __pyx_t_19++; if (unlikely(0 < 0)) __PYX_ERR(0, 3944, __pyx_L1_error) + #else + __pyx_t_7 = PySequence_ITEM(__pyx_t_6, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3944, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + } + } else { + __pyx_t_7 = __pyx_t_20(__pyx_t_6); + if (unlikely(!__pyx_t_7)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 3944, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_7); + } + __Pyx_XDECREF_SET(__pyx_v_stream_feature, __pyx_t_7); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3945 + * upstream_fid_map = collections.defaultdict(list) + * for stream_feature in stream_layer: + * ds_x = int(stream_feature.GetField('ds_x')) # <<<<<<<<<<<<<< + * ds_y = int(stream_feature.GetField('ds_y')) + * upstream_fid_map[(ds_x, ds_y)].append( + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3945, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_7 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_1, __pyx_n_u_ds_x) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_n_u_ds_x); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3945, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyNumber_Int(__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3945, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF_SET(__pyx_v_ds_x, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3946 + * for stream_feature in stream_layer: + * ds_x = int(stream_feature.GetField('ds_x')) + * ds_y = int(stream_feature.GetField('ds_y')) # <<<<<<<<<<<<<< + * upstream_fid_map[(ds_x, ds_y)].append( + * stream_feature.GetFID()) + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3946, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_2 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_1, __pyx_n_u_ds_y) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_n_u_ds_y); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3946, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyNumber_Int(__pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3946, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF_SET(__pyx_v_ds_y, __pyx_t_7); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3947 + * ds_x = int(stream_feature.GetField('ds_x')) + * ds_y = int(stream_feature.GetField('ds_y')) + * upstream_fid_map[(ds_x, ds_y)].append( # <<<<<<<<<<<<<< + * stream_feature.GetFID()) + * + */ + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3947, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_v_ds_x); + __Pyx_GIVEREF(__pyx_v_ds_x); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_ds_x); + __Pyx_INCREF(__pyx_v_ds_y); + __Pyx_GIVEREF(__pyx_v_ds_y); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_ds_y); + __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_upstream_fid_map, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3947, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3948 + * ds_y = int(stream_feature.GetField('ds_y')) + * upstream_fid_map[(ds_x, ds_y)].append( + * stream_feature.GetFID()) # <<<<<<<<<<<<<< + * + * stream_layer.ResetReading() + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetFID); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3948, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = NULL; + 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_7 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3948, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3947 + * ds_x = int(stream_feature.GetField('ds_x')) + * ds_y = int(stream_feature.GetField('ds_y')) + * upstream_fid_map[(ds_x, ds_y)].append( # <<<<<<<<<<<<<< + * stream_feature.GetFID()) + * + */ + __pyx_t_21 = __Pyx_PyObject_Append(__pyx_t_2, __pyx_t_7); if (unlikely(__pyx_t_21 == ((int)-1))) __PYX_ERR(0, 3947, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3944 + * # construct linkage data structure for upstream streams + * upstream_fid_map = collections.defaultdict(list) + * for stream_feature in stream_layer: # <<<<<<<<<<<<<< + * ds_x = int(stream_feature.GetField('ds_x')) + * ds_y = int(stream_feature.GetField('ds_y')) + */ + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3950 + * stream_feature.GetFID()) + * + * stream_layer.ResetReading() # <<<<<<<<<<<<<< + * # construct visit order, this list will have a tuple of (fid, 0/1) + * # this stack will be used to build watersheds from upstream to downstream + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_ResetReading); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3950, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_6 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3950, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3953 + * # construct visit order, this list will have a tuple of (fid, 0/1) + * # this stack will be used to build watersheds from upstream to downstream + * visit_order_stack = [] # <<<<<<<<<<<<<< + * # visit the highest order to lowest order in case there's a branching + * # junction of a order 1 and order 5 stream... visit order 5 upstream + */ + __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3953, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_v_visit_order_stack = ((PyObject*)__pyx_t_6); + __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3957 + * # junction of a order 1 and order 5 stream... visit order 5 upstream + * # first + * stream_layer.SetAttributeFilter(f'"outlet"=1') # <<<<<<<<<<<<<< + * # these are done last + * for _, outlet_fid in sorted([ + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_SetAttributeFilter); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3957, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_6 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_2, __pyx_kp_u_outlet_1) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_kp_u_outlet_1); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3957, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3959 + * stream_layer.SetAttributeFilter(f'"outlet"=1') + * # these are done last + * for _, outlet_fid in sorted([ # <<<<<<<<<<<<<< + * (x.GetField('order'), x.GetFID()) for x in stream_layer], + * reverse=True): + */ + { /* enter inner scope */ + __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3959, __pyx_L15_error) + __Pyx_GOTREF(__pyx_t_6); + + /* "pygeoprocessing/routing/routing.pyx":3960 + * # these are done last + * for _, outlet_fid in sorted([ + * (x.GetField('order'), x.GetFID()) for x in stream_layer], # <<<<<<<<<<<<<< + * reverse=True): + * working_stack = [outlet_fid] + */ + if (likely(PyList_CheckExact(__pyx_v_stream_layer)) || PyTuple_CheckExact(__pyx_v_stream_layer)) { + __pyx_t_7 = __pyx_v_stream_layer; __Pyx_INCREF(__pyx_t_7); __pyx_t_19 = 0; + __pyx_t_20 = NULL; + } else { + __pyx_t_19 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_v_stream_layer); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3960, __pyx_L15_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_20 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 3960, __pyx_L15_error) + } + for (;;) { + if (likely(!__pyx_t_20)) { + if (likely(PyList_CheckExact(__pyx_t_7))) { + if (__pyx_t_19 >= PyList_GET_SIZE(__pyx_t_7)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_19); __Pyx_INCREF(__pyx_t_2); __pyx_t_19++; if (unlikely(0 < 0)) __PYX_ERR(0, 3960, __pyx_L15_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_7, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3960, __pyx_L15_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } else { + if (__pyx_t_19 >= PyTuple_GET_SIZE(__pyx_t_7)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_19); __Pyx_INCREF(__pyx_t_2); __pyx_t_19++; if (unlikely(0 < 0)) __PYX_ERR(0, 3960, __pyx_L15_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_7, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3960, __pyx_L15_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } + } else { + __pyx_t_2 = __pyx_t_20(__pyx_t_7); + if (unlikely(!__pyx_t_2)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 3960, __pyx_L15_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XDECREF_SET(__pyx_8genexpr2__pyx_v_x, __pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_8genexpr2__pyx_v_x, __pyx_n_s_GetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3960, __pyx_L15_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = NULL; + 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_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_4, __pyx_n_u_order) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_n_u_order); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3960, __pyx_L15_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_8genexpr2__pyx_v_x, __pyx_n_s_GetFID); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3960, __pyx_L15_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3960, __pyx_L15_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3960, __pyx_L15_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1); + __pyx_t_2 = 0; + __pyx_t_1 = 0; + if (unlikely(__Pyx_ListComp_Append(__pyx_t_6, (PyObject*)__pyx_t_4))) __PYX_ERR(0, 3959, __pyx_L15_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_x); __pyx_8genexpr2__pyx_v_x = 0; + goto __pyx_L18_exit_scope; + __pyx_L15_error:; + __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_x); __pyx_8genexpr2__pyx_v_x = 0; + goto __pyx_L1_error; + __pyx_L18_exit_scope:; + } /* exit inner scope */ + + /* "pygeoprocessing/routing/routing.pyx":3959 + * stream_layer.SetAttributeFilter(f'"outlet"=1') + * # these are done last + * for _, outlet_fid in sorted([ # <<<<<<<<<<<<<< + * (x.GetField('order'), x.GetFID()) for x in stream_layer], + * reverse=True): + */ + __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3959, __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 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3961 + * for _, outlet_fid in sorted([ + * (x.GetField('order'), x.GetFID()) for x in stream_layer], + * reverse=True): # <<<<<<<<<<<<<< + * working_stack = [outlet_fid] + * processed_nodes = set() + */ + __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3961, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_reverse, Py_True) < 0) __PYX_ERR(0, 3961, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3959 + * stream_layer.SetAttributeFilter(f'"outlet"=1') + * # these are done last + * for _, outlet_fid in sorted([ # <<<<<<<<<<<<<< + * (x.GetField('order'), x.GetFID()) for x in stream_layer], + * reverse=True): + */ + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_sorted, __pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3959, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) { + __pyx_t_6 = __pyx_t_4; __Pyx_INCREF(__pyx_t_6); __pyx_t_19 = 0; + __pyx_t_20 = NULL; + } else { + __pyx_t_19 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3959, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_20 = Py_TYPE(__pyx_t_6)->tp_iternext; if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 3959, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + for (;;) { + if (likely(!__pyx_t_20)) { + if (likely(PyList_CheckExact(__pyx_t_6))) { + if (__pyx_t_19 >= PyList_GET_SIZE(__pyx_t_6)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_19); __Pyx_INCREF(__pyx_t_4); __pyx_t_19++; if (unlikely(0 < 0)) __PYX_ERR(0, 3959, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_6, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3959, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } else { + if (__pyx_t_19 >= PyTuple_GET_SIZE(__pyx_t_6)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_19); __Pyx_INCREF(__pyx_t_4); __pyx_t_19++; if (unlikely(0 < 0)) __PYX_ERR(0, 3959, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_6, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3959, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } + } else { + __pyx_t_4 = __pyx_t_20(__pyx_t_6); + 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, 3959, __pyx_L1_error) + } + break; + } + __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, 3959, __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); + } else { + __pyx_t_7 = PyList_GET_ITEM(sequence, 0); + __pyx_t_1 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_1); + #else + __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3959, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3959, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_2 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3959, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_10 = Py_TYPE(__pyx_t_2)->tp_iternext; + index = 0; __pyx_t_7 = __pyx_t_10(__pyx_t_2); if (unlikely(!__pyx_t_7)) goto __pyx_L19_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + index = 1; __pyx_t_1 = __pyx_t_10(__pyx_t_2); if (unlikely(!__pyx_t_1)) goto __pyx_L19_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_2), 2) < 0) __PYX_ERR(0, 3959, __pyx_L1_error) + __pyx_t_10 = NULL; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L20_unpacking_done; + __pyx_L19_unpacking_failed:; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_10 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 3959, __pyx_L1_error) + __pyx_L20_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_XDECREF_SET(__pyx_v_outlet_fid, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3962 + * (x.GetField('order'), x.GetFID()) for x in stream_layer], + * reverse=True): + * working_stack = [outlet_fid] # <<<<<<<<<<<<<< + * processed_nodes = set() + * while working_stack: + */ + __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3962, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_outlet_fid); + __Pyx_GIVEREF(__pyx_v_outlet_fid); + PyList_SET_ITEM(__pyx_t_4, 0, __pyx_v_outlet_fid); + __Pyx_XDECREF_SET(__pyx_v_working_stack, ((PyObject*)__pyx_t_4)); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3963 + * reverse=True): + * working_stack = [outlet_fid] + * processed_nodes = set() # <<<<<<<<<<<<<< + * while working_stack: + * working_fid = working_stack[-1] + */ + __pyx_t_4 = PySet_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3963, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XDECREF_SET(__pyx_v_processed_nodes, ((PyObject*)__pyx_t_4)); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3964 + * working_stack = [outlet_fid] + * processed_nodes = set() + * while working_stack: # <<<<<<<<<<<<<< + * working_fid = working_stack[-1] + * processed_nodes.add(working_fid) + */ + while (1) { + __pyx_t_18 = (PyList_GET_SIZE(__pyx_v_working_stack) != 0); + if (!__pyx_t_18) break; + + /* "pygeoprocessing/routing/routing.pyx":3965 + * processed_nodes = set() + * while working_stack: + * working_fid = working_stack[-1] # <<<<<<<<<<<<<< + * processed_nodes.add(working_fid) + * working_feature = stream_layer.GetFeature(working_fid) + */ + __pyx_t_4 = __Pyx_GetItemInt_List(__pyx_v_working_stack, -1L, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3965, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XDECREF_SET(__pyx_v_working_fid, __pyx_t_4); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3966 + * while working_stack: + * working_fid = working_stack[-1] + * processed_nodes.add(working_fid) # <<<<<<<<<<<<<< + * working_feature = stream_layer.GetFeature(working_fid) + * + */ + __pyx_t_21 = PySet_Add(__pyx_v_processed_nodes, __pyx_v_working_fid); if (unlikely(__pyx_t_21 == ((int)-1))) __PYX_ERR(0, 3966, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3967 + * working_fid = working_stack[-1] + * processed_nodes.add(working_fid) + * working_feature = stream_layer.GetFeature(working_fid) # <<<<<<<<<<<<<< + * + * us_x = int(working_feature.GetField('us_x')) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3967, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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); + } + } + __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_7, __pyx_v_working_fid) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_working_fid); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3967, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_working_feature, __pyx_t_4); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3969 + * working_feature = stream_layer.GetFeature(working_fid) + * + * us_x = int(working_feature.GetField('us_x')) # <<<<<<<<<<<<<< + * us_y = int(working_feature.GetField('us_y')) + * ds_x_1 = int(working_feature.GetField('ds_x_1')) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3969, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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); + } + } + __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_7, __pyx_n_u_us_x) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_n_u_us_x); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3969, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3969, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF_SET(__pyx_v_us_x, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3970 + * + * us_x = int(working_feature.GetField('us_x')) + * us_y = int(working_feature.GetField('us_y')) # <<<<<<<<<<<<<< + * ds_x_1 = int(working_feature.GetField('ds_x_1')) + * ds_y_1 = int(working_feature.GetField('ds_y_1')) + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3970, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __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); + } + } + __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_7, __pyx_n_u_us_y) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_n_u_us_y); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3970, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3970, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_us_y, __pyx_t_4); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3971 + * us_x = int(working_feature.GetField('us_x')) + * us_y = int(working_feature.GetField('us_y')) + * ds_x_1 = int(working_feature.GetField('ds_x_1')) # <<<<<<<<<<<<<< + * ds_y_1 = int(working_feature.GetField('ds_y_1')) + * + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3971, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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); + } + } + __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_7, __pyx_n_u_ds_x_1) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_n_u_ds_x_1); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3971, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3971, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF_SET(__pyx_v_ds_x_1, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3972 + * us_y = int(working_feature.GetField('us_y')) + * ds_x_1 = int(working_feature.GetField('ds_x_1')) + * ds_y_1 = int(working_feature.GetField('ds_y_1')) # <<<<<<<<<<<<<< + * + * upstream_coord = (us_x, us_y) + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3972, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __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); + } + } + __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_7, __pyx_n_u_ds_y_1) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_n_u_ds_y_1); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3972, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3972, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_ds_y_1, __pyx_t_4); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3974 + * ds_y_1 = int(working_feature.GetField('ds_y_1')) + * + * upstream_coord = (us_x, us_y) # <<<<<<<<<<<<<< + * upstream_fids = [ + * fid for fid in upstream_fid_map[upstream_coord] + */ + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3974, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_us_x); + __Pyx_GIVEREF(__pyx_v_us_x); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_us_x); + __Pyx_INCREF(__pyx_v_us_y); + __Pyx_GIVEREF(__pyx_v_us_y); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_us_y); + __Pyx_XDECREF_SET(__pyx_v_upstream_coord, ((PyObject*)__pyx_t_4)); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3975 + * + * upstream_coord = (us_x, us_y) + * upstream_fids = [ # <<<<<<<<<<<<<< + * fid for fid in upstream_fid_map[upstream_coord] + * if fid not in processed_nodes] + */ + { /* enter inner scope */ + __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3975, __pyx_L25_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "pygeoprocessing/routing/routing.pyx":3976 + * upstream_coord = (us_x, us_y) + * upstream_fids = [ + * fid for fid in upstream_fid_map[upstream_coord] # <<<<<<<<<<<<<< + * if fid not in processed_nodes] + * if upstream_fids: + */ + __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_upstream_fid_map, __pyx_v_upstream_coord); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3976, __pyx_L25_error) + __Pyx_GOTREF(__pyx_t_1); + if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_7 = __pyx_t_1; __Pyx_INCREF(__pyx_t_7); __pyx_t_22 = 0; + __pyx_t_23 = NULL; + } else { + __pyx_t_22 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3976, __pyx_L25_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_23 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 3976, __pyx_L25_error) + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (likely(!__pyx_t_23)) { + if (likely(PyList_CheckExact(__pyx_t_7))) { + if (__pyx_t_22 >= PyList_GET_SIZE(__pyx_t_7)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_22); __Pyx_INCREF(__pyx_t_1); __pyx_t_22++; if (unlikely(0 < 0)) __PYX_ERR(0, 3976, __pyx_L25_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_7, __pyx_t_22); __pyx_t_22++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3976, __pyx_L25_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } else { + if (__pyx_t_22 >= PyTuple_GET_SIZE(__pyx_t_7)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_22); __Pyx_INCREF(__pyx_t_1); __pyx_t_22++; if (unlikely(0 < 0)) __PYX_ERR(0, 3976, __pyx_L25_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_7, __pyx_t_22); __pyx_t_22++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3976, __pyx_L25_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } + } else { + __pyx_t_1 = __pyx_t_23(__pyx_t_7); + 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, 3976, __pyx_L25_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XDECREF_SET(__pyx_8genexpr3__pyx_v_fid, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3977 + * upstream_fids = [ + * fid for fid in upstream_fid_map[upstream_coord] + * if fid not in processed_nodes] # <<<<<<<<<<<<<< + * if upstream_fids: + * working_stack.extend(upstream_fids) + */ + __pyx_t_18 = (__Pyx_PySet_ContainsTF(__pyx_8genexpr3__pyx_v_fid, __pyx_v_processed_nodes, Py_NE)); if (unlikely(__pyx_t_18 < 0)) __PYX_ERR(0, 3977, __pyx_L25_error) + __pyx_t_24 = (__pyx_t_18 != 0); + if (__pyx_t_24) { + + /* "pygeoprocessing/routing/routing.pyx":3976 + * upstream_coord = (us_x, us_y) + * upstream_fids = [ + * fid for fid in upstream_fid_map[upstream_coord] # <<<<<<<<<<<<<< + * if fid not in processed_nodes] + * if upstream_fids: + */ + if (unlikely(__Pyx_ListComp_Append(__pyx_t_4, (PyObject*)__pyx_8genexpr3__pyx_v_fid))) __PYX_ERR(0, 3975, __pyx_L25_error) + + /* "pygeoprocessing/routing/routing.pyx":3977 + * upstream_fids = [ + * fid for fid in upstream_fid_map[upstream_coord] + * if fid not in processed_nodes] # <<<<<<<<<<<<<< + * if upstream_fids: + * working_stack.extend(upstream_fids) + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3976 + * upstream_coord = (us_x, us_y) + * upstream_fids = [ + * fid for fid in upstream_fid_map[upstream_coord] # <<<<<<<<<<<<<< + * if fid not in processed_nodes] + * if upstream_fids: + */ + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_8genexpr3__pyx_v_fid); __pyx_8genexpr3__pyx_v_fid = 0; + goto __pyx_L29_exit_scope; + __pyx_L25_error:; + __Pyx_XDECREF(__pyx_8genexpr3__pyx_v_fid); __pyx_8genexpr3__pyx_v_fid = 0; + goto __pyx_L1_error; + __pyx_L29_exit_scope:; + } /* exit inner scope */ + __Pyx_XDECREF_SET(__pyx_v_upstream_fids, ((PyObject*)__pyx_t_4)); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3978 + * fid for fid in upstream_fid_map[upstream_coord] + * if fid not in processed_nodes] + * if upstream_fids: # <<<<<<<<<<<<<< + * working_stack.extend(upstream_fids) + * else: + */ + __pyx_t_24 = (PyList_GET_SIZE(__pyx_v_upstream_fids) != 0); + if (__pyx_t_24) { + + /* "pygeoprocessing/routing/routing.pyx":3979 + * if fid not in processed_nodes] + * if upstream_fids: + * working_stack.extend(upstream_fids) # <<<<<<<<<<<<<< + * else: + * working_stack.pop() + */ + __pyx_t_21 = __Pyx_PyList_Extend(__pyx_v_working_stack, __pyx_v_upstream_fids); if (unlikely(__pyx_t_21 == ((int)-1))) __PYX_ERR(0, 3979, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3978 + * fid for fid in upstream_fid_map[upstream_coord] + * if fid not in processed_nodes] + * if upstream_fids: # <<<<<<<<<<<<<< + * working_stack.extend(upstream_fids) + * else: + */ + goto __pyx_L30; + } + + /* "pygeoprocessing/routing/routing.pyx":3981 + * working_stack.extend(upstream_fids) + * else: + * working_stack.pop() # <<<<<<<<<<<<<< + * # the `not outlet_at_confluence` bit allows us to seed + * # even if the order is 1, otherwise confluences fill + */ + /*else*/ { + __pyx_t_4 = __Pyx_PyList_Pop(__pyx_v_working_stack); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3981, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3985 + * # even if the order is 1, otherwise confluences fill + * # the order 1 streams + * if (working_feature.GetField('order') > 1 or # <<<<<<<<<<<<<< + * not outlet_at_confluence): + * if outlet_at_confluence: + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3985, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_4 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_1, __pyx_n_u_order) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_n_u_order); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3985, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = PyObject_RichCompare(__pyx_t_4, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3985, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_18 < 0)) __PYX_ERR(0, 3985, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (!__pyx_t_18) { + } else { + __pyx_t_24 = __pyx_t_18; + goto __pyx_L32_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":3986 + * # the order 1 streams + * if (working_feature.GetField('order') > 1 or + * not outlet_at_confluence): # <<<<<<<<<<<<<< + * if outlet_at_confluence: + * # seed the upstream point + */ + __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_v_outlet_at_confluence); if (unlikely(__pyx_t_18 < 0)) __PYX_ERR(0, 3986, __pyx_L1_error) + __pyx_t_25 = ((!__pyx_t_18) != 0); + __pyx_t_24 = __pyx_t_25; + __pyx_L32_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":3985 + * # even if the order is 1, otherwise confluences fill + * # the order 1 streams + * if (working_feature.GetField('order') > 1 or # <<<<<<<<<<<<<< + * not outlet_at_confluence): + * if outlet_at_confluence: + */ + if (__pyx_t_24) { + + /* "pygeoprocessing/routing/routing.pyx":3987 + * if (working_feature.GetField('order') > 1 or + * not outlet_at_confluence): + * if outlet_at_confluence: # <<<<<<<<<<<<<< + * # seed the upstream point + * visit_order_stack.append((working_fid, us_x, us_y)) + */ + __pyx_t_24 = __Pyx_PyObject_IsTrue(__pyx_v_outlet_at_confluence); if (unlikely(__pyx_t_24 < 0)) __PYX_ERR(0, 3987, __pyx_L1_error) + if (__pyx_t_24) { + + /* "pygeoprocessing/routing/routing.pyx":3989 + * if outlet_at_confluence: + * # seed the upstream point + * visit_order_stack.append((working_fid, us_x, us_y)) # <<<<<<<<<<<<<< + * else: + * # seed the downstream but +1 step point + */ + __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3989, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_v_working_fid); + __Pyx_GIVEREF(__pyx_v_working_fid); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_working_fid); + __Pyx_INCREF(__pyx_v_us_x); + __Pyx_GIVEREF(__pyx_v_us_x); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_us_x); + __Pyx_INCREF(__pyx_v_us_y); + __Pyx_GIVEREF(__pyx_v_us_y); + PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_v_us_y); + __pyx_t_21 = __Pyx_PyList_Append(__pyx_v_visit_order_stack, __pyx_t_7); if (unlikely(__pyx_t_21 == ((int)-1))) __PYX_ERR(0, 3989, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3987 + * if (working_feature.GetField('order') > 1 or + * not outlet_at_confluence): + * if outlet_at_confluence: # <<<<<<<<<<<<<< + * # seed the upstream point + * visit_order_stack.append((working_fid, us_x, us_y)) + */ + goto __pyx_L34; + } + + /* "pygeoprocessing/routing/routing.pyx":3992 + * else: + * # seed the downstream but +1 step point + * visit_order_stack.append( # <<<<<<<<<<<<<< + * (working_fid, ds_x_1, ds_y_1)) + * if working_feature.GetField('outlet') == 1: + */ + /*else*/ { + + /* "pygeoprocessing/routing/routing.pyx":3993 + * # seed the downstream but +1 step point + * visit_order_stack.append( + * (working_fid, ds_x_1, ds_y_1)) # <<<<<<<<<<<<<< + * if working_feature.GetField('outlet') == 1: + * # an outlet is a special case where the outlet itself + */ + __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3993, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_v_working_fid); + __Pyx_GIVEREF(__pyx_v_working_fid); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_working_fid); + __Pyx_INCREF(__pyx_v_ds_x_1); + __Pyx_GIVEREF(__pyx_v_ds_x_1); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_ds_x_1); + __Pyx_INCREF(__pyx_v_ds_y_1); + __Pyx_GIVEREF(__pyx_v_ds_y_1); + PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_v_ds_y_1); + + /* "pygeoprocessing/routing/routing.pyx":3992 + * else: + * # seed the downstream but +1 step point + * visit_order_stack.append( # <<<<<<<<<<<<<< + * (working_fid, ds_x_1, ds_y_1)) + * if working_feature.GetField('outlet') == 1: + */ + __pyx_t_21 = __Pyx_PyList_Append(__pyx_v_visit_order_stack, __pyx_t_7); if (unlikely(__pyx_t_21 == ((int)-1))) __PYX_ERR(0, 3992, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __pyx_L34:; + + /* "pygeoprocessing/routing/routing.pyx":3985 + * # even if the order is 1, otherwise confluences fill + * # the order 1 streams + * if (working_feature.GetField('order') > 1 or # <<<<<<<<<<<<<< + * not outlet_at_confluence): + * if outlet_at_confluence: + */ + } + + /* "pygeoprocessing/routing/routing.pyx":3994 + * visit_order_stack.append( + * (working_fid, ds_x_1, ds_y_1)) + * if working_feature.GetField('outlet') == 1: # <<<<<<<<<<<<<< + * # an outlet is a special case where the outlet itself + * # should be a subwatershed done last. + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3994, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_7 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, __pyx_n_u_outlet) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_n_u_outlet); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3994, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyInt_EqObjC(__pyx_t_7, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3994, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_24 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_24 < 0)) __PYX_ERR(0, 3994, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_24) { + + /* "pygeoprocessing/routing/routing.pyx":3997 + * # an outlet is a special case where the outlet itself + * # should be a subwatershed done last. + * ds_x = int(working_feature.GetField('ds_x')) # <<<<<<<<<<<<<< + * ds_y = int(working_feature.GetField('ds_y')) + * if not outlet_at_confluence: + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3997, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_4 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_1, __pyx_n_u_ds_x) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_n_u_ds_x); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3997, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyNumber_Int(__pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3997, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF_SET(__pyx_v_ds_x, __pyx_t_7); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3998 + * # should be a subwatershed done last. + * ds_x = int(working_feature.GetField('ds_x')) + * ds_y = int(working_feature.GetField('ds_y')) # <<<<<<<<<<<<<< + * if not outlet_at_confluence: + * # undo the previous visit because it will be at + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3998, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_7 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, __pyx_n_u_ds_y) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_n_u_ds_y); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3998, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyNumber_Int(__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3998, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF_SET(__pyx_v_ds_y, __pyx_t_4); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3999 + * ds_x = int(working_feature.GetField('ds_x')) + * ds_y = int(working_feature.GetField('ds_y')) + * if not outlet_at_confluence: # <<<<<<<<<<<<<< + * # undo the previous visit because it will be at + * # one pixel up and we want the pixel right at + */ + __pyx_t_24 = __Pyx_PyObject_IsTrue(__pyx_v_outlet_at_confluence); if (unlikely(__pyx_t_24 < 0)) __PYX_ERR(0, 3999, __pyx_L1_error) + __pyx_t_25 = ((!__pyx_t_24) != 0); + if (__pyx_t_25) { + + /* "pygeoprocessing/routing/routing.pyx":4003 + * # one pixel up and we want the pixel right at + * # the outlet + * visit_order_stack.pop() # <<<<<<<<<<<<<< + * visit_order_stack.append((working_fid, ds_x, ds_y)) + * + */ + __pyx_t_4 = __Pyx_PyList_Pop(__pyx_v_visit_order_stack); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4003, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3999 + * ds_x = int(working_feature.GetField('ds_x')) + * ds_y = int(working_feature.GetField('ds_y')) + * if not outlet_at_confluence: # <<<<<<<<<<<<<< + * # undo the previous visit because it will be at + * # one pixel up and we want the pixel right at + */ + } + + /* "pygeoprocessing/routing/routing.pyx":4004 + * # the outlet + * visit_order_stack.pop() + * visit_order_stack.append((working_fid, ds_x, ds_y)) # <<<<<<<<<<<<<< + * + * cdef int edge_side, edge_dir, cell_to_test, out_dir_increase=-1 + */ + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4004, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_working_fid); + __Pyx_GIVEREF(__pyx_v_working_fid); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_working_fid); + __Pyx_INCREF(__pyx_v_ds_x); + __Pyx_GIVEREF(__pyx_v_ds_x); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_ds_x); + __Pyx_INCREF(__pyx_v_ds_y); + __Pyx_GIVEREF(__pyx_v_ds_y); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_ds_y); + __pyx_t_21 = __Pyx_PyList_Append(__pyx_v_visit_order_stack, __pyx_t_4); if (unlikely(__pyx_t_21 == ((int)-1))) __PYX_ERR(0, 4004, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3994 + * visit_order_stack.append( + * (working_fid, ds_x_1, ds_y_1)) + * if working_feature.GetField('outlet') == 1: # <<<<<<<<<<<<<< + * # an outlet is a special case where the outlet itself + * # should be a subwatershed done last. + */ + } + } + __pyx_L30:; + } + + /* "pygeoprocessing/routing/routing.pyx":3959 + * stream_layer.SetAttributeFilter(f'"outlet"=1') + * # these are done last + * for _, outlet_fid in sorted([ # <<<<<<<<<<<<<< + * (x.GetField('order'), x.GetFID()) for x in stream_layer], + * reverse=True): + */ + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4006 + * visit_order_stack.append((working_fid, ds_x, ds_y)) + * + * cdef int edge_side, edge_dir, cell_to_test, out_dir_increase=-1 # <<<<<<<<<<<<<< + * cdef int left, right, n_steps, terminated_early + * cdef int delta_x, delta_y + */ + __pyx_v_out_dir_increase = -1; + + /* "pygeoprocessing/routing/routing.pyx":4009 + * cdef int left, right, n_steps, terminated_early + * cdef int delta_x, delta_y + * cdef int _int_max_steps_per_watershed = max_steps_per_watershed # <<<<<<<<<<<<<< + * + * for index, (stream_fid, x_l, y_l) in enumerate(visit_order_stack): + */ + __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_v_max_steps_per_watershed); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4009, __pyx_L1_error) + __pyx_v__int_max_steps_per_watershed = __pyx_t_11; + + /* "pygeoprocessing/routing/routing.pyx":4011 + * cdef int _int_max_steps_per_watershed = max_steps_per_watershed + * + * for index, (stream_fid, x_l, y_l) in enumerate(visit_order_stack): # <<<<<<<<<<<<<< + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * LOGGER.info( + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_t_6 = __pyx_int_0; + __pyx_t_4 = __pyx_v_visit_order_stack; __Pyx_INCREF(__pyx_t_4); __pyx_t_19 = 0; + for (;;) { + if (__pyx_t_19 >= PyList_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_19); __Pyx_INCREF(__pyx_t_7); __pyx_t_19++; if (unlikely(0 < 0)) __PYX_ERR(0, 4011, __pyx_L1_error) + #else + __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4011, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) { + PyObject* sequence = __pyx_t_7; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 3)) { + if (size > 3) __Pyx_RaiseTooManyValuesError(3); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 4011, __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_3 = PyTuple_GET_ITEM(sequence, 2); + } else { + __pyx_t_1 = PyList_GET_ITEM(sequence, 0); + __pyx_t_2 = PyList_GET_ITEM(sequence, 1); + __pyx_t_3 = PyList_GET_ITEM(sequence, 2); + } + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + #else + __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4011, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4011, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4011, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_5 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4011, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_10 = Py_TYPE(__pyx_t_5)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_10(__pyx_t_5); if (unlikely(!__pyx_t_1)) goto __pyx_L39_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 1; __pyx_t_2 = __pyx_t_10(__pyx_t_5); if (unlikely(!__pyx_t_2)) goto __pyx_L39_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + index = 2; __pyx_t_3 = __pyx_t_10(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L39_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_5), 3) < 0) __PYX_ERR(0, 4011, __pyx_L1_error) + __pyx_t_10 = NULL; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L40_unpacking_done; + __pyx_L39_unpacking_failed:; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_10 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 4011, __pyx_L1_error) + __pyx_L40_unpacking_done:; + } + __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4011, __pyx_L1_error) + __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, 4011, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF_SET(__pyx_v_stream_fid, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_v_x_l = __pyx_t_11; + __pyx_v_y_l = __pyx_t_8; + __Pyx_INCREF(__pyx_t_6); + __Pyx_XDECREF_SET(__pyx_v_index, __pyx_t_6); + __pyx_t_7 = __Pyx_PyInt_AddObjC(__pyx_t_6, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4011, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); + __pyx_t_6 = __pyx_t_7; + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4012 + * + * for index, (stream_fid, x_l, y_l) in enumerate(visit_order_stack): + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * LOGGER.info( + * f'(calculate_subwatershed_boundary): watershed building ' + */ + __pyx_t_25 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); + if (__pyx_t_25) { + + /* "pygeoprocessing/routing/routing.pyx":4013 + * for index, (stream_fid, x_l, y_l) in enumerate(visit_order_stack): + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * LOGGER.info( # <<<<<<<<<<<<<< + * f'(calculate_subwatershed_boundary): watershed building ' + * f'{(index/len(visit_order_stack))*100:.1f}% complete') + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4013, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4013, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4014 + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * LOGGER.info( + * f'(calculate_subwatershed_boundary): watershed building ' # <<<<<<<<<<<<<< + * f'{(index/len(visit_order_stack))*100:.1f}% complete') + * last_log_time = ctime(NULL) + */ + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4014, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_22 = 0; + __pyx_t_26 = 127; + __Pyx_INCREF(__pyx_kp_u_calculate_subwatershed_boundary_2); + __pyx_t_22 += 54; + __Pyx_GIVEREF(__pyx_kp_u_calculate_subwatershed_boundary_2); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_u_calculate_subwatershed_boundary_2); + + /* "pygeoprocessing/routing/routing.pyx":4015 + * LOGGER.info( + * f'(calculate_subwatershed_boundary): watershed building ' + * f'{(index/len(visit_order_stack))*100:.1f}% complete') # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * discovery = discovery_managed_raster.get(x_l, y_l) + */ + __pyx_t_27 = PyList_GET_SIZE(__pyx_v_visit_order_stack); if (unlikely(__pyx_t_27 == ((Py_ssize_t)-1))) __PYX_ERR(0, 4015, __pyx_L1_error) + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_27); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4015, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyNumber_Divide(__pyx_v_index, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4015, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Multiply(__pyx_t_5, __pyx_int_100); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4015, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_Format(__pyx_t_1, __pyx_kp_u_1f); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4015, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_26 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_26) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_26; + __pyx_t_22 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_5); + __pyx_t_5 = 0; + __Pyx_INCREF(__pyx_kp_u_complete); + __pyx_t_22 += 10; + __Pyx_GIVEREF(__pyx_kp_u_complete); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_kp_u_complete); + + /* "pygeoprocessing/routing/routing.pyx":4014 + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * LOGGER.info( + * f'(calculate_subwatershed_boundary): watershed building ' # <<<<<<<<<<<<<< + * f'{(index/len(visit_order_stack))*100:.1f}% complete') + * last_log_time = ctime(NULL) + */ + __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_3, 3, __pyx_t_22, __pyx_t_26); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4014, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __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); + } + } + __pyx_t_7 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_5); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4013, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4016 + * f'(calculate_subwatershed_boundary): watershed building ' + * f'{(index/len(visit_order_stack))*100:.1f}% complete') + * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< + * discovery = discovery_managed_raster.get(x_l, y_l) + * if discovery == -1: + */ + __pyx_v_last_log_time = time(NULL); + + /* "pygeoprocessing/routing/routing.pyx":4012 + * + * for index, (stream_fid, x_l, y_l) in enumerate(visit_order_stack): + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< + * LOGGER.info( + * f'(calculate_subwatershed_boundary): watershed building ' + */ + } + + /* "pygeoprocessing/routing/routing.pyx":4017 + * f'{(index/len(visit_order_stack))*100:.1f}% complete') + * last_log_time = ctime(NULL) + * discovery = discovery_managed_raster.get(x_l, y_l) # <<<<<<<<<<<<<< + * if discovery == -1: + * continue + */ + __pyx_v_discovery = ((long)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_discovery_managed_raster, __pyx_v_x_l, __pyx_v_y_l)); + + /* "pygeoprocessing/routing/routing.pyx":4018 + * last_log_time = ctime(NULL) + * discovery = discovery_managed_raster.get(x_l, y_l) + * if discovery == -1: # <<<<<<<<<<<<<< + * continue + * boundary_list = [(x_l, y_l)] + */ + __pyx_t_25 = ((__pyx_v_discovery == -1L) != 0); + if (__pyx_t_25) { + + /* "pygeoprocessing/routing/routing.pyx":4019 + * discovery = discovery_managed_raster.get(x_l, y_l) + * if discovery == -1: + * continue # <<<<<<<<<<<<<< + * boundary_list = [(x_l, y_l)] + * finish = finish_managed_raster.get(x_l, y_l) + */ + goto __pyx_L37_continue; + + /* "pygeoprocessing/routing/routing.pyx":4018 + * last_log_time = ctime(NULL) + * discovery = discovery_managed_raster.get(x_l, y_l) + * if discovery == -1: # <<<<<<<<<<<<<< + * continue + * boundary_list = [(x_l, y_l)] + */ + } + + /* "pygeoprocessing/routing/routing.pyx":4020 + * if discovery == -1: + * continue + * boundary_list = [(x_l, y_l)] # <<<<<<<<<<<<<< + * finish = finish_managed_raster.get(x_l, y_l) + * outlet_x = x_l + */ + __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_x_l); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4020, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_y_l); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4020, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4020, __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_2); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2); + __pyx_t_7 = 0; + __pyx_t_2 = 0; + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4020, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_5); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_5); + __pyx_t_5 = 0; + __Pyx_XDECREF_SET(__pyx_v_boundary_list, ((PyObject*)__pyx_t_2)); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4021 + * continue + * boundary_list = [(x_l, y_l)] + * finish = finish_managed_raster.get(x_l, y_l) # <<<<<<<<<<<<<< + * outlet_x = x_l + * outlet_y = y_l + */ + __pyx_v_finish = ((long)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_finish_managed_raster, __pyx_v_x_l, __pyx_v_y_l)); + + /* "pygeoprocessing/routing/routing.pyx":4022 + * boundary_list = [(x_l, y_l)] + * finish = finish_managed_raster.get(x_l, y_l) + * outlet_x = x_l # <<<<<<<<<<<<<< + * outlet_y = y_l + * + */ + __pyx_v_outlet_x = __pyx_v_x_l; + + /* "pygeoprocessing/routing/routing.pyx":4023 + * finish = finish_managed_raster.get(x_l, y_l) + * outlet_x = x_l + * outlet_y = y_l # <<<<<<<<<<<<<< + * + * watershed_boundary = ogr.Geometry(ogr.wkbLinearRing) + */ + __pyx_v_outlet_y = __pyx_v_y_l; + + /* "pygeoprocessing/routing/routing.pyx":4025 + * outlet_y = y_l + * + * watershed_boundary = ogr.Geometry(ogr.wkbLinearRing) # <<<<<<<<<<<<<< + * outflow_dir = d8_flow_dir_managed_raster.get(x_l, y_l) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_ogr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4025, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_Geometry); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4025, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_ogr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4025, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_wkbLinearRing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4025, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __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); + } + } + __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_3); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4025, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF_SET(__pyx_v_watershed_boundary, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4026 + * + * watershed_boundary = ogr.Geometry(ogr.wkbLinearRing) + * outflow_dir = d8_flow_dir_managed_raster.get(x_l, y_l) # <<<<<<<<<<<<<< + * + * # this is the center point of the pixel that will be offset to + */ + __pyx_v_outflow_dir = ((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_d8_flow_dir_managed_raster, __pyx_v_x_l, __pyx_v_y_l)); + + /* "pygeoprocessing/routing/routing.pyx":4030 + * # this is the center point of the pixel that will be offset to + * # make the edge + * x_f = x_l+0.5 # <<<<<<<<<<<<<< + * y_f = y_l+0.5 + * + */ + __pyx_v_x_f = (__pyx_v_x_l + 0.5); + + /* "pygeoprocessing/routing/routing.pyx":4031 + * # make the edge + * x_f = x_l+0.5 + * y_f = y_l+0.5 # <<<<<<<<<<<<<< + * + * x_f += D8_XOFFSET[outflow_dir]*0.5 + */ + __pyx_v_y_f = (__pyx_v_y_l + 0.5); + + /* "pygeoprocessing/routing/routing.pyx":4033 + * y_f = y_l+0.5 + * + * x_f += D8_XOFFSET[outflow_dir]*0.5 # <<<<<<<<<<<<<< + * y_f += D8_YOFFSET[outflow_dir]*0.5 + * if outflow_dir % 2 == 0: + */ + __pyx_v_x_f = (__pyx_v_x_f + ((__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_outflow_dir]) * 0.5)); + + /* "pygeoprocessing/routing/routing.pyx":4034 + * + * x_f += D8_XOFFSET[outflow_dir]*0.5 + * y_f += D8_YOFFSET[outflow_dir]*0.5 # <<<<<<<<<<<<<< + * if outflow_dir % 2 == 0: + * # need to back up the point a bit + */ + __pyx_v_y_f = (__pyx_v_y_f + ((__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_outflow_dir]) * 0.5)); + + /* "pygeoprocessing/routing/routing.pyx":4035 + * x_f += D8_XOFFSET[outflow_dir]*0.5 + * y_f += D8_YOFFSET[outflow_dir]*0.5 + * if outflow_dir % 2 == 0: # <<<<<<<<<<<<<< + * # need to back up the point a bit + * x_f -= D8_YOFFSET[outflow_dir]*0.5 + */ + __pyx_t_25 = ((__Pyx_mod_long(__pyx_v_outflow_dir, 2) == 0) != 0); + if (__pyx_t_25) { + + /* "pygeoprocessing/routing/routing.pyx":4037 + * if outflow_dir % 2 == 0: + * # need to back up the point a bit + * x_f -= D8_YOFFSET[outflow_dir]*0.5 # <<<<<<<<<<<<<< + * y_f += D8_XOFFSET[outflow_dir]*0.5 + * + */ + __pyx_v_x_f = (__pyx_v_x_f - ((__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_outflow_dir]) * 0.5)); + + /* "pygeoprocessing/routing/routing.pyx":4038 + * # need to back up the point a bit + * x_f -= D8_YOFFSET[outflow_dir]*0.5 + * y_f += D8_XOFFSET[outflow_dir]*0.5 # <<<<<<<<<<<<<< + * + * x_p, y_p = gdal.ApplyGeoTransform(geotransform, x_f, y_f) + */ + __pyx_v_y_f = (__pyx_v_y_f + ((__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_outflow_dir]) * 0.5)); + + /* "pygeoprocessing/routing/routing.pyx":4035 + * x_f += D8_XOFFSET[outflow_dir]*0.5 + * y_f += D8_YOFFSET[outflow_dir]*0.5 + * if outflow_dir % 2 == 0: # <<<<<<<<<<<<<< + * # need to back up the point a bit + * x_f -= D8_YOFFSET[outflow_dir]*0.5 + */ + } + + /* "pygeoprocessing/routing/routing.pyx":4040 + * y_f += D8_XOFFSET[outflow_dir]*0.5 + * + * x_p, y_p = gdal.ApplyGeoTransform(geotransform, x_f, y_f) # <<<<<<<<<<<<<< + * watershed_boundary.AddPoint(x_p, y_p) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4040, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_ApplyGeoTransform); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4040, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = PyFloat_FromDouble(__pyx_v_x_f); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4040, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_5 = PyFloat_FromDouble(__pyx_v_y_f); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4040, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = NULL; + __pyx_t_8 = 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_8 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_v_geotransform, __pyx_t_7, __pyx_t_5}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4040, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 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[4] = {__pyx_t_1, __pyx_v_geotransform, __pyx_t_7, __pyx_t_5}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4040, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_28 = PyTuple_New(3+__pyx_t_8); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4040, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_28); + if (__pyx_t_1) { + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_28, 0, __pyx_t_1); __pyx_t_1 = NULL; + } + __Pyx_INCREF(__pyx_v_geotransform); + __Pyx_GIVEREF(__pyx_v_geotransform); + PyTuple_SET_ITEM(__pyx_t_28, 0+__pyx_t_8, __pyx_v_geotransform); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_28, 1+__pyx_t_8, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_28, 2+__pyx_t_8, __pyx_t_5); + __pyx_t_7 = 0; + __pyx_t_5 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_28, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4040, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + 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 != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 4040, __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_28 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_3 = PyList_GET_ITEM(sequence, 0); + __pyx_t_28 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_28); + #else + __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4040, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_28 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4040, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_28); + #endif + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_5 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4040, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_10 = Py_TYPE(__pyx_t_5)->tp_iternext; + index = 0; __pyx_t_3 = __pyx_t_10(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L44_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + index = 1; __pyx_t_28 = __pyx_t_10(__pyx_t_5); if (unlikely(!__pyx_t_28)) goto __pyx_L44_unpacking_failed; + __Pyx_GOTREF(__pyx_t_28); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_5), 2) < 0) __PYX_ERR(0, 4040, __pyx_L1_error) + __pyx_t_10 = NULL; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L45_unpacking_done; + __pyx_L44_unpacking_failed:; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_10 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 4040, __pyx_L1_error) + __pyx_L45_unpacking_done:; + } + __pyx_t_17 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_17 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 4040, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_16 = __pyx_PyFloat_AsDouble(__pyx_t_28); if (unlikely((__pyx_t_16 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 4040, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; + __pyx_v_x_p = __pyx_t_17; + __pyx_v_y_p = __pyx_t_16; + + /* "pygeoprocessing/routing/routing.pyx":4041 + * + * x_p, y_p = gdal.ApplyGeoTransform(geotransform, x_f, y_f) + * watershed_boundary.AddPoint(x_p, y_p) # <<<<<<<<<<<<<< + * + * # keep track of how many steps x/y and when we get back to 0 we've + */ + __pyx_t_28 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_boundary, __pyx_n_s_AddPoint); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4041, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_28); + __pyx_t_3 = PyFloat_FromDouble(__pyx_v_x_p); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4041, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyFloat_FromDouble(__pyx_v_y_p); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4041, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = NULL; + __pyx_t_8 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_28))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_28); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_28); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_28, function); + __pyx_t_8 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_28)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_3, __pyx_t_5}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_28, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4041, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + __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_28)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_3, __pyx_t_5}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_28, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4041, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_1 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4041, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_8, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_8, __pyx_t_5); + __pyx_t_3 = 0; + __pyx_t_5 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_28, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4041, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4045 + * # keep track of how many steps x/y and when we get back to 0 we've + * # made a loop + * delta_x, delta_y = 0, 0 # <<<<<<<<<<<<<< + * + * # determine the first edge + */ + __pyx_t_8 = 0; + __pyx_t_11 = 0; + __pyx_v_delta_x = __pyx_t_8; + __pyx_v_delta_y = __pyx_t_11; + + /* "pygeoprocessing/routing/routing.pyx":4048 + * + * # determine the first edge + * if outflow_dir % 2 == 0: # <<<<<<<<<<<<<< + * # outflow through a straight side, so trivial edge detection + * edge_side = outflow_dir + */ + __pyx_t_25 = ((__Pyx_mod_long(__pyx_v_outflow_dir, 2) == 0) != 0); + if (__pyx_t_25) { + + /* "pygeoprocessing/routing/routing.pyx":4050 + * if outflow_dir % 2 == 0: + * # outflow through a straight side, so trivial edge detection + * edge_side = outflow_dir # <<<<<<<<<<<<<< + * edge_dir = (2+edge_side) % 8 + * else: + */ + __pyx_v_edge_side = __pyx_v_outflow_dir; + + /* "pygeoprocessing/routing/routing.pyx":4051 + * # outflow through a straight side, so trivial edge detection + * edge_side = outflow_dir + * edge_dir = (2+edge_side) % 8 # <<<<<<<<<<<<<< + * else: + * # diagonal outflow requires testing neighboring cells to + */ + __pyx_v_edge_dir = __Pyx_mod_long((2 + __pyx_v_edge_side), 8); + + /* "pygeoprocessing/routing/routing.pyx":4048 + * + * # determine the first edge + * if outflow_dir % 2 == 0: # <<<<<<<<<<<<<< + * # outflow through a straight side, so trivial edge detection + * edge_side = outflow_dir + */ + goto __pyx_L46; + } + + /* "pygeoprocessing/routing/routing.pyx":4055 + * # diagonal outflow requires testing neighboring cells to + * # determine first edge + * cell_to_test = (outflow_dir+1) % 8 # <<<<<<<<<<<<<< + * edge_side = cell_to_test + * edge_dir = (cell_to_test+2) % 8 + */ + /*else*/ { + __pyx_v_cell_to_test = __Pyx_mod_long((__pyx_v_outflow_dir + 1), 8); + + /* "pygeoprocessing/routing/routing.pyx":4056 + * # determine first edge + * cell_to_test = (outflow_dir+1) % 8 + * edge_side = cell_to_test # <<<<<<<<<<<<<< + * edge_dir = (cell_to_test+2) % 8 + * if _in_watershed( + */ + __pyx_v_edge_side = __pyx_v_cell_to_test; + + /* "pygeoprocessing/routing/routing.pyx":4057 + * cell_to_test = (outflow_dir+1) % 8 + * edge_side = cell_to_test + * edge_dir = (cell_to_test+2) % 8 # <<<<<<<<<<<<<< + * if _in_watershed( + * x_l, y_l, cell_to_test, discovery, finish, + */ + __pyx_v_edge_dir = __Pyx_mod_long((__pyx_v_cell_to_test + 2), 8); + + /* "pygeoprocessing/routing/routing.pyx":4058 + * edge_side = cell_to_test + * edge_dir = (cell_to_test+2) % 8 + * if _in_watershed( # <<<<<<<<<<<<<< + * x_l, y_l, cell_to_test, discovery, finish, + * n_cols, n_rows, + */ + __pyx_t_25 = (__pyx_f_15pygeoprocessing_7routing_7routing__in_watershed(__pyx_v_x_l, __pyx_v_y_l, __pyx_v_cell_to_test, __pyx_v_discovery, __pyx_v_finish, __pyx_v_n_cols, __pyx_v_n_rows, __pyx_v_discovery_managed_raster, __pyx_v_discovery_nodata) != 0); + if (__pyx_t_25) { + + /* "pygeoprocessing/routing/routing.pyx":4062 + * n_cols, n_rows, + * discovery_managed_raster, discovery_nodata): + * edge_side = (edge_side-2) % 8 # <<<<<<<<<<<<<< + * edge_dir = (edge_dir-2) % 8 + * x_l += D8_XOFFSET[edge_dir] + */ + __pyx_v_edge_side = __Pyx_mod_long((__pyx_v_edge_side - 2), 8); + + /* "pygeoprocessing/routing/routing.pyx":4063 + * discovery_managed_raster, discovery_nodata): + * edge_side = (edge_side-2) % 8 + * edge_dir = (edge_dir-2) % 8 # <<<<<<<<<<<<<< + * x_l += D8_XOFFSET[edge_dir] + * y_l += D8_YOFFSET[edge_dir] + */ + __pyx_v_edge_dir = __Pyx_mod_long((__pyx_v_edge_dir - 2), 8); + + /* "pygeoprocessing/routing/routing.pyx":4064 + * edge_side = (edge_side-2) % 8 + * edge_dir = (edge_dir-2) % 8 + * x_l += D8_XOFFSET[edge_dir] # <<<<<<<<<<<<<< + * y_l += D8_YOFFSET[edge_dir] + * # note the pixel moved + */ + __pyx_v_x_l = (__pyx_v_x_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_edge_dir])); + + /* "pygeoprocessing/routing/routing.pyx":4065 + * edge_dir = (edge_dir-2) % 8 + * x_l += D8_XOFFSET[edge_dir] + * y_l += D8_YOFFSET[edge_dir] # <<<<<<<<<<<<<< + * # note the pixel moved + * boundary_list.append((x_l, y_l)) + */ + __pyx_v_y_l = (__pyx_v_y_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_edge_dir])); + + /* "pygeoprocessing/routing/routing.pyx":4067 + * y_l += D8_YOFFSET[edge_dir] + * # note the pixel moved + * boundary_list.append((x_l, y_l)) # <<<<<<<<<<<<<< + * + * n_steps = 0 + */ + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_x_l); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4067, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_28 = __Pyx_PyInt_From_int(__pyx_v_y_l); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4067, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_28); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4067, __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_28); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_28); + __pyx_t_2 = 0; + __pyx_t_28 = 0; + __pyx_t_21 = __Pyx_PyList_Append(__pyx_v_boundary_list, __pyx_t_1); if (unlikely(__pyx_t_21 == ((int)-1))) __PYX_ERR(0, 4067, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4058 + * edge_side = cell_to_test + * edge_dir = (cell_to_test+2) % 8 + * if _in_watershed( # <<<<<<<<<<<<<< + * x_l, y_l, cell_to_test, discovery, finish, + * n_cols, n_rows, + */ + } + } + __pyx_L46:; + + /* "pygeoprocessing/routing/routing.pyx":4069 + * boundary_list.append((x_l, y_l)) + * + * n_steps = 0 # <<<<<<<<<<<<<< + * terminated_early = 0 + * while True: + */ + __pyx_v_n_steps = 0; + + /* "pygeoprocessing/routing/routing.pyx":4070 + * + * n_steps = 0 + * terminated_early = 0 # <<<<<<<<<<<<<< + * while True: + * # step the edge then determine the projected coordinates + */ + __pyx_v_terminated_early = 0; + + /* "pygeoprocessing/routing/routing.pyx":4071 + * n_steps = 0 + * terminated_early = 0 + * while True: # <<<<<<<<<<<<<< + * # step the edge then determine the projected coordinates + * x_f += D8_XOFFSET[edge_dir] + */ + while (1) { + + /* "pygeoprocessing/routing/routing.pyx":4073 + * while True: + * # step the edge then determine the projected coordinates + * x_f += D8_XOFFSET[edge_dir] # <<<<<<<<<<<<<< + * y_f += D8_YOFFSET[edge_dir] + * delta_x += D8_XOFFSET[edge_dir] + */ + __pyx_v_x_f = (__pyx_v_x_f + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_edge_dir])); + + /* "pygeoprocessing/routing/routing.pyx":4074 + * # step the edge then determine the projected coordinates + * x_f += D8_XOFFSET[edge_dir] + * y_f += D8_YOFFSET[edge_dir] # <<<<<<<<<<<<<< + * delta_x += D8_XOFFSET[edge_dir] + * delta_y += D8_YOFFSET[edge_dir] + */ + __pyx_v_y_f = (__pyx_v_y_f + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_edge_dir])); + + /* "pygeoprocessing/routing/routing.pyx":4075 + * x_f += D8_XOFFSET[edge_dir] + * y_f += D8_YOFFSET[edge_dir] + * delta_x += D8_XOFFSET[edge_dir] # <<<<<<<<<<<<<< + * delta_y += D8_YOFFSET[edge_dir] + * # equivalent to gdal.ApplyGeoTransform(geotransform, x_f, y_f) + */ + __pyx_v_delta_x = (__pyx_v_delta_x + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_edge_dir])); + + /* "pygeoprocessing/routing/routing.pyx":4076 + * y_f += D8_YOFFSET[edge_dir] + * delta_x += D8_XOFFSET[edge_dir] + * delta_y += D8_YOFFSET[edge_dir] # <<<<<<<<<<<<<< + * # equivalent to gdal.ApplyGeoTransform(geotransform, x_f, y_f) + * # to eliminate python function call overhead + */ + __pyx_v_delta_y = (__pyx_v_delta_y + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_edge_dir])); + + /* "pygeoprocessing/routing/routing.pyx":4079 + * # equivalent to gdal.ApplyGeoTransform(geotransform, x_f, y_f) + * # to eliminate python function call overhead + * x_p = g0 + g1*x_f + g2*y_f # <<<<<<<<<<<<<< + * y_p = g3 + g4*x_f + g5*y_f + * watershed_boundary.AddPoint(x_p, y_p) + */ + __pyx_v_x_p = ((__pyx_v_g0 + (__pyx_v_g1 * __pyx_v_x_f)) + (__pyx_v_g2 * __pyx_v_y_f)); + + /* "pygeoprocessing/routing/routing.pyx":4080 + * # to eliminate python function call overhead + * x_p = g0 + g1*x_f + g2*y_f + * y_p = g3 + g4*x_f + g5*y_f # <<<<<<<<<<<<<< + * watershed_boundary.AddPoint(x_p, y_p) + * n_steps += 1 + */ + __pyx_v_y_p = ((__pyx_v_g3 + (__pyx_v_g4 * __pyx_v_x_f)) + (__pyx_v_g5 * __pyx_v_y_f)); + + /* "pygeoprocessing/routing/routing.pyx":4081 + * x_p = g0 + g1*x_f + g2*y_f + * y_p = g3 + g4*x_f + g5*y_f + * watershed_boundary.AddPoint(x_p, y_p) # <<<<<<<<<<<<<< + * n_steps += 1 + * if n_steps > _int_max_steps_per_watershed: + */ + __pyx_t_28 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_boundary, __pyx_n_s_AddPoint); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4081, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_28); + __pyx_t_2 = PyFloat_FromDouble(__pyx_v_x_p); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4081, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = PyFloat_FromDouble(__pyx_v_y_p); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4081, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_28))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_28); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_28); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_28, function); + __pyx_t_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_28)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_t_2, __pyx_t_5}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_28, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4081, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_28)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_t_2, __pyx_t_5}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_28, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4081, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4081, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_11, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_11, __pyx_t_5); + __pyx_t_2 = 0; + __pyx_t_5 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_28, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4081, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4082 + * y_p = g3 + g4*x_f + g5*y_f + * watershed_boundary.AddPoint(x_p, y_p) + * n_steps += 1 # <<<<<<<<<<<<<< + * if n_steps > _int_max_steps_per_watershed: + * LOGGER.warning('quitting, too many steps') + */ + __pyx_v_n_steps = (__pyx_v_n_steps + 1); + + /* "pygeoprocessing/routing/routing.pyx":4083 + * watershed_boundary.AddPoint(x_p, y_p) + * n_steps += 1 + * if n_steps > _int_max_steps_per_watershed: # <<<<<<<<<<<<<< + * LOGGER.warning('quitting, too many steps') + * terminated_early = 1 + */ + __pyx_t_25 = ((__pyx_v_n_steps > __pyx_v__int_max_steps_per_watershed) != 0); + if (__pyx_t_25) { + + /* "pygeoprocessing/routing/routing.pyx":4084 + * n_steps += 1 + * if n_steps > _int_max_steps_per_watershed: + * LOGGER.warning('quitting, too many steps') # <<<<<<<<<<<<<< + * terminated_early = 1 + * break + */ + __Pyx_GetModuleGlobalName(__pyx_t_28, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4084, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_28); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_28, __pyx_n_s_warning); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4084, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; + __pyx_t_28 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_28 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_28)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_28); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_1 = (__pyx_t_28) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_28, __pyx_kp_u_quitting_too_many_steps) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_kp_u_quitting_too_many_steps); + __Pyx_XDECREF(__pyx_t_28); __pyx_t_28 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4084, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4085 + * if n_steps > _int_max_steps_per_watershed: + * LOGGER.warning('quitting, too many steps') + * terminated_early = 1 # <<<<<<<<<<<<<< + * break + * if x_l < 0 or y_l < 0 or x_l >= n_cols or y_l >= n_rows: + */ + __pyx_v_terminated_early = 1; + + /* "pygeoprocessing/routing/routing.pyx":4086 + * LOGGER.warning('quitting, too many steps') + * terminated_early = 1 + * break # <<<<<<<<<<<<<< + * if x_l < 0 or y_l < 0 or x_l >= n_cols or y_l >= n_rows: + * # This is unexpected but worth checking since missing this + */ + goto __pyx_L49_break; + + /* "pygeoprocessing/routing/routing.pyx":4083 + * watershed_boundary.AddPoint(x_p, y_p) + * n_steps += 1 + * if n_steps > _int_max_steps_per_watershed: # <<<<<<<<<<<<<< + * LOGGER.warning('quitting, too many steps') + * terminated_early = 1 + */ + } + + /* "pygeoprocessing/routing/routing.pyx":4087 + * terminated_early = 1 + * break + * if x_l < 0 or y_l < 0 or x_l >= n_cols or y_l >= n_rows: # <<<<<<<<<<<<<< + * # This is unexpected but worth checking since missing this + * # error would be very difficult to debug. + */ + __pyx_t_24 = ((__pyx_v_x_l < 0) != 0); + if (!__pyx_t_24) { + } else { + __pyx_t_25 = __pyx_t_24; + goto __pyx_L52_bool_binop_done; + } + __pyx_t_24 = ((__pyx_v_y_l < 0) != 0); + if (!__pyx_t_24) { + } else { + __pyx_t_25 = __pyx_t_24; + goto __pyx_L52_bool_binop_done; + } + __pyx_t_24 = ((__pyx_v_x_l >= __pyx_v_n_cols) != 0); + if (!__pyx_t_24) { + } else { + __pyx_t_25 = __pyx_t_24; + goto __pyx_L52_bool_binop_done; + } + __pyx_t_24 = ((__pyx_v_y_l >= __pyx_v_n_rows) != 0); + __pyx_t_25 = __pyx_t_24; + __pyx_L52_bool_binop_done:; + if (unlikely(__pyx_t_25)) { + + /* "pygeoprocessing/routing/routing.pyx":4091 + * # error would be very difficult to debug. + * raise RuntimeError( + * f'{x_l}, {y_l} out of bounds for ' # <<<<<<<<<<<<<< + * f'{n_cols}x{n_rows} raster.') + * if edge_side - ((edge_dir-2) % 8) == 0: + */ + __pyx_t_1 = PyTuple_New(8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4091, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_22 = 0; + __pyx_t_26 = 127; + __pyx_t_7 = __Pyx_PyUnicode_From_int(__pyx_v_x_l, 0, ' ', 'd'); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4091, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_22 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_INCREF(__pyx_kp_u_); + __pyx_t_22 += 2; + __Pyx_GIVEREF(__pyx_kp_u_); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_kp_u_); + __pyx_t_7 = __Pyx_PyUnicode_From_int(__pyx_v_y_l, 0, ' ', 'd'); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4091, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_22 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_INCREF(__pyx_kp_u_out_of_bounds_for); + __pyx_t_22 += 19; + __Pyx_GIVEREF(__pyx_kp_u_out_of_bounds_for); + PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_kp_u_out_of_bounds_for); + + /* "pygeoprocessing/routing/routing.pyx":4092 + * raise RuntimeError( + * f'{x_l}, {y_l} out of bounds for ' + * f'{n_cols}x{n_rows} raster.') # <<<<<<<<<<<<<< + * if edge_side - ((edge_dir-2) % 8) == 0: + * # counterclockwise configuration + */ + __pyx_t_7 = __Pyx_PyUnicode_From_int(__pyx_v_n_cols, 0, ' ', 'd'); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4092, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_22 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_INCREF(__pyx_n_u_x); + __pyx_t_22 += 1; + __Pyx_GIVEREF(__pyx_n_u_x); + PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_n_u_x); + __pyx_t_7 = __Pyx_PyUnicode_From_int(__pyx_v_n_rows, 0, ' ', 'd'); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4092, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_22 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_1, 6, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_INCREF(__pyx_kp_u_raster); + __pyx_t_22 += 8; + __Pyx_GIVEREF(__pyx_kp_u_raster); + PyTuple_SET_ITEM(__pyx_t_1, 7, __pyx_kp_u_raster); + + /* "pygeoprocessing/routing/routing.pyx":4091 + * # error would be very difficult to debug. + * raise RuntimeError( + * f'{x_l}, {y_l} out of bounds for ' # <<<<<<<<<<<<<< + * f'{n_cols}x{n_rows} raster.') + * if edge_side - ((edge_dir-2) % 8) == 0: + */ + __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_1, 8, __pyx_t_22, __pyx_t_26); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4091, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4090 + * # This is unexpected but worth checking since missing this + * # error would be very difficult to debug. + * raise RuntimeError( # <<<<<<<<<<<<<< + * f'{x_l}, {y_l} out of bounds for ' + * f'{n_cols}x{n_rows} raster.') + */ + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_RuntimeError, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4090, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 4090, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":4087 + * terminated_early = 1 + * break + * if x_l < 0 or y_l < 0 or x_l >= n_cols or y_l >= n_rows: # <<<<<<<<<<<<<< + * # This is unexpected but worth checking since missing this + * # error would be very difficult to debug. + */ + } + + /* "pygeoprocessing/routing/routing.pyx":4093 + * f'{x_l}, {y_l} out of bounds for ' + * f'{n_cols}x{n_rows} raster.') + * if edge_side - ((edge_dir-2) % 8) == 0: # <<<<<<<<<<<<<< + * # counterclockwise configuration + * left = edge_dir + */ + __pyx_t_25 = (((__pyx_v_edge_side - __Pyx_mod_long((__pyx_v_edge_dir - 2), 8)) == 0) != 0); + if (__pyx_t_25) { + + /* "pygeoprocessing/routing/routing.pyx":4095 + * if edge_side - ((edge_dir-2) % 8) == 0: + * # counterclockwise configuration + * left = edge_dir # <<<<<<<<<<<<<< + * right = (left-1) % 8 + * out_dir_increase = 2 + */ + __pyx_v_left = __pyx_v_edge_dir; + + /* "pygeoprocessing/routing/routing.pyx":4096 + * # counterclockwise configuration + * left = edge_dir + * right = (left-1) % 8 # <<<<<<<<<<<<<< + * out_dir_increase = 2 + * else: + */ + __pyx_v_right = __Pyx_mod_long((__pyx_v_left - 1), 8); + + /* "pygeoprocessing/routing/routing.pyx":4097 + * left = edge_dir + * right = (left-1) % 8 + * out_dir_increase = 2 # <<<<<<<<<<<<<< + * else: + * # clockwise configuration (swapping "left" and "right") + */ + __pyx_v_out_dir_increase = 2; + + /* "pygeoprocessing/routing/routing.pyx":4093 + * f'{x_l}, {y_l} out of bounds for ' + * f'{n_cols}x{n_rows} raster.') + * if edge_side - ((edge_dir-2) % 8) == 0: # <<<<<<<<<<<<<< + * # counterclockwise configuration + * left = edge_dir + */ + goto __pyx_L56; + } + + /* "pygeoprocessing/routing/routing.pyx":4100 + * else: + * # clockwise configuration (swapping "left" and "right") + * right = edge_dir # <<<<<<<<<<<<<< + * left = (edge_side+1) + * out_dir_increase = -2 + */ + /*else*/ { + __pyx_v_right = __pyx_v_edge_dir; + + /* "pygeoprocessing/routing/routing.pyx":4101 + * # clockwise configuration (swapping "left" and "right") + * right = edge_dir + * left = (edge_side+1) # <<<<<<<<<<<<<< + * out_dir_increase = -2 + * left_in = _in_watershed( + */ + __pyx_v_left = (__pyx_v_edge_side + 1); + + /* "pygeoprocessing/routing/routing.pyx":4102 + * right = edge_dir + * left = (edge_side+1) + * out_dir_increase = -2 # <<<<<<<<<<<<<< + * left_in = _in_watershed( + * x_l, y_l, left, discovery, finish, n_cols, n_rows, + */ + __pyx_v_out_dir_increase = -2; + } + __pyx_L56:; + + /* "pygeoprocessing/routing/routing.pyx":4103 + * left = (edge_side+1) + * out_dir_increase = -2 + * left_in = _in_watershed( # <<<<<<<<<<<<<< + * x_l, y_l, left, discovery, finish, n_cols, n_rows, + * discovery_managed_raster, discovery_nodata) + */ + __pyx_v_left_in = __pyx_f_15pygeoprocessing_7routing_7routing__in_watershed(__pyx_v_x_l, __pyx_v_y_l, __pyx_v_left, __pyx_v_discovery, __pyx_v_finish, __pyx_v_n_cols, __pyx_v_n_rows, __pyx_v_discovery_managed_raster, __pyx_v_discovery_nodata); + + /* "pygeoprocessing/routing/routing.pyx":4106 + * x_l, y_l, left, discovery, finish, n_cols, n_rows, + * discovery_managed_raster, discovery_nodata) + * right_in = _in_watershed( # <<<<<<<<<<<<<< + * x_l, y_l, right, discovery, finish, n_cols, n_rows, + * discovery_managed_raster, discovery_nodata) + */ + __pyx_v_right_in = __pyx_f_15pygeoprocessing_7routing_7routing__in_watershed(__pyx_v_x_l, __pyx_v_y_l, __pyx_v_right, __pyx_v_discovery, __pyx_v_finish, __pyx_v_n_cols, __pyx_v_n_rows, __pyx_v_discovery_managed_raster, __pyx_v_discovery_nodata); + + /* "pygeoprocessing/routing/routing.pyx":4109 + * x_l, y_l, right, discovery, finish, n_cols, n_rows, + * discovery_managed_raster, discovery_nodata) + * if right_in: # <<<<<<<<<<<<<< + * # turn right + * out_dir = edge_side + */ + __pyx_t_25 = (__pyx_v_right_in != 0); + if (__pyx_t_25) { + + /* "pygeoprocessing/routing/routing.pyx":4111 + * if right_in: + * # turn right + * out_dir = edge_side # <<<<<<<<<<<<<< + * edge_side = (edge_side-out_dir_increase) % 8 + * edge_dir = out_dir + */ + __pyx_v_out_dir = __pyx_v_edge_side; + + /* "pygeoprocessing/routing/routing.pyx":4112 + * # turn right + * out_dir = edge_side + * edge_side = (edge_side-out_dir_increase) % 8 # <<<<<<<<<<<<<< + * edge_dir = out_dir + * # pixel moves to be the right cell + */ + __pyx_v_edge_side = __Pyx_mod_long((__pyx_v_edge_side - __pyx_v_out_dir_increase), 8); + + /* "pygeoprocessing/routing/routing.pyx":4113 + * out_dir = edge_side + * edge_side = (edge_side-out_dir_increase) % 8 + * edge_dir = out_dir # <<<<<<<<<<<<<< + * # pixel moves to be the right cell + * x_l += D8_XOFFSET[right] + */ + __pyx_v_edge_dir = __pyx_v_out_dir; + + /* "pygeoprocessing/routing/routing.pyx":4115 + * edge_dir = out_dir + * # pixel moves to be the right cell + * x_l += D8_XOFFSET[right] # <<<<<<<<<<<<<< + * y_l += D8_YOFFSET[right] + * _diagonal_fill_step( + */ + __pyx_v_x_l = (__pyx_v_x_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_right])); + + /* "pygeoprocessing/routing/routing.pyx":4116 + * # pixel moves to be the right cell + * x_l += D8_XOFFSET[right] + * y_l += D8_YOFFSET[right] # <<<<<<<<<<<<<< + * _diagonal_fill_step( + * x_l, y_l, right, + */ + __pyx_v_y_l = (__pyx_v_y_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_right])); + + /* "pygeoprocessing/routing/routing.pyx":4117 + * x_l += D8_XOFFSET[right] + * y_l += D8_YOFFSET[right] + * _diagonal_fill_step( # <<<<<<<<<<<<<< + * x_l, y_l, right, + * discovery, finish, discovery_managed_raster, + */ + __pyx_f_15pygeoprocessing_7routing_7routing__diagonal_fill_step(__pyx_v_x_l, __pyx_v_y_l, __pyx_v_right, __pyx_v_discovery, __pyx_v_finish, __pyx_v_discovery_managed_raster, __pyx_v_discovery_nodata, __pyx_v_boundary_list); + + /* "pygeoprocessing/routing/routing.pyx":4109 + * x_l, y_l, right, discovery, finish, n_cols, n_rows, + * discovery_managed_raster, discovery_nodata) + * if right_in: # <<<<<<<<<<<<<< + * # turn right + * out_dir = edge_side + */ + goto __pyx_L57; + } + + /* "pygeoprocessing/routing/routing.pyx":4122 + * discovery_nodata, + * boundary_list) + * elif left_in: # <<<<<<<<<<<<<< + * # step forward + * x_l += D8_XOFFSET[edge_dir] + */ + __pyx_t_25 = (__pyx_v_left_in != 0); + if (__pyx_t_25) { + + /* "pygeoprocessing/routing/routing.pyx":4124 + * elif left_in: + * # step forward + * x_l += D8_XOFFSET[edge_dir] # <<<<<<<<<<<<<< + * y_l += D8_YOFFSET[edge_dir] + * # the pixel moves forward + */ + __pyx_v_x_l = (__pyx_v_x_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_edge_dir])); + + /* "pygeoprocessing/routing/routing.pyx":4125 + * # step forward + * x_l += D8_XOFFSET[edge_dir] + * y_l += D8_YOFFSET[edge_dir] # <<<<<<<<<<<<<< + * # the pixel moves forward + * boundary_list.append((x_l, y_l)) + */ + __pyx_v_y_l = (__pyx_v_y_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_edge_dir])); + + /* "pygeoprocessing/routing/routing.pyx":4127 + * y_l += D8_YOFFSET[edge_dir] + * # the pixel moves forward + * boundary_list.append((x_l, y_l)) # <<<<<<<<<<<<<< + * else: + * # turn left + */ + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_x_l); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4127, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_y_l); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4127, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_28 = PyTuple_New(2); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4127, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_28); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_28, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_28, 1, __pyx_t_7); + __pyx_t_1 = 0; + __pyx_t_7 = 0; + __pyx_t_21 = __Pyx_PyList_Append(__pyx_v_boundary_list, __pyx_t_28); if (unlikely(__pyx_t_21 == ((int)-1))) __PYX_ERR(0, 4127, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4122 + * discovery_nodata, + * boundary_list) + * elif left_in: # <<<<<<<<<<<<<< + * # step forward + * x_l += D8_XOFFSET[edge_dir] + */ + goto __pyx_L57; + } + + /* "pygeoprocessing/routing/routing.pyx":4130 + * else: + * # turn left + * edge_side = edge_dir # <<<<<<<<<<<<<< + * edge_dir = (edge_side + out_dir_increase) % 8 + * + */ + /*else*/ { + __pyx_v_edge_side = __pyx_v_edge_dir; + + /* "pygeoprocessing/routing/routing.pyx":4131 + * # turn left + * edge_side = edge_dir + * edge_dir = (edge_side + out_dir_increase) % 8 # <<<<<<<<<<<<<< + * + * if delta_x == 0 and delta_y == 0: + */ + __pyx_v_edge_dir = __Pyx_mod_long((__pyx_v_edge_side + __pyx_v_out_dir_increase), 8); + } + __pyx_L57:; + + /* "pygeoprocessing/routing/routing.pyx":4133 + * edge_dir = (edge_side + out_dir_increase) % 8 + * + * if delta_x == 0 and delta_y == 0: # <<<<<<<<<<<<<< + * # met the start point so we completed the watershed loop + * break + */ + __pyx_t_24 = ((__pyx_v_delta_x == 0) != 0); + if (__pyx_t_24) { + } else { + __pyx_t_25 = __pyx_t_24; + goto __pyx_L59_bool_binop_done; + } + __pyx_t_24 = ((__pyx_v_delta_y == 0) != 0); + __pyx_t_25 = __pyx_t_24; + __pyx_L59_bool_binop_done:; + if (__pyx_t_25) { + + /* "pygeoprocessing/routing/routing.pyx":4135 + * if delta_x == 0 and delta_y == 0: + * # met the start point so we completed the watershed loop + * break # <<<<<<<<<<<<<< + * + * watershed_feature = ogr.Feature(watershed_layer.GetLayerDefn()) + */ + goto __pyx_L49_break; + + /* "pygeoprocessing/routing/routing.pyx":4133 + * edge_dir = (edge_side + out_dir_increase) % 8 + * + * if delta_x == 0 and delta_y == 0: # <<<<<<<<<<<<<< + * # met the start point so we completed the watershed loop + * break + */ + } + } + __pyx_L49_break:; + + /* "pygeoprocessing/routing/routing.pyx":4137 + * break + * + * watershed_feature = ogr.Feature(watershed_layer.GetLayerDefn()) # <<<<<<<<<<<<<< + * watershed_polygon = ogr.Geometry(ogr.wkbPolygon) + * watershed_polygon.AddGeometry(watershed_boundary) + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4137, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_Feature); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4137, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_layer, __pyx_n_s_GetLayerDefn); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4137, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + __pyx_t_7 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4137, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __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); + } + } + __pyx_t_28 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_5, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_7); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4137, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_28); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_watershed_feature, __pyx_t_28); + __pyx_t_28 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4138 + * + * watershed_feature = ogr.Feature(watershed_layer.GetLayerDefn()) + * watershed_polygon = ogr.Geometry(ogr.wkbPolygon) # <<<<<<<<<<<<<< + * watershed_polygon.AddGeometry(watershed_boundary) + * watershed_feature.SetGeometry(watershed_polygon) + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4138, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_Geometry); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4138, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4138, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_wkbPolygon); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4138, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_28 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_1, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_5); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4138, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_28); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF_SET(__pyx_v_watershed_polygon, __pyx_t_28); + __pyx_t_28 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4139 + * watershed_feature = ogr.Feature(watershed_layer.GetLayerDefn()) + * watershed_polygon = ogr.Geometry(ogr.wkbPolygon) + * watershed_polygon.AddGeometry(watershed_boundary) # <<<<<<<<<<<<<< + * watershed_feature.SetGeometry(watershed_polygon) + * watershed_feature.SetField('stream_fid', stream_fid) + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_polygon, __pyx_n_s_AddGeometry); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4139, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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); + } + } + __pyx_t_28 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_5, __pyx_v_watershed_boundary) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_watershed_boundary); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4139, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_28); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4140 + * watershed_polygon = ogr.Geometry(ogr.wkbPolygon) + * watershed_polygon.AddGeometry(watershed_boundary) + * watershed_feature.SetGeometry(watershed_polygon) # <<<<<<<<<<<<<< + * watershed_feature.SetField('stream_fid', stream_fid) + * watershed_feature.SetField('terminated_early', terminated_early) + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_feature, __pyx_n_s_SetGeometry); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4140, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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); + } + } + __pyx_t_28 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_5, __pyx_v_watershed_polygon) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_watershed_polygon); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4140, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_28); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4141 + * watershed_polygon.AddGeometry(watershed_boundary) + * watershed_feature.SetGeometry(watershed_polygon) + * watershed_feature.SetField('stream_fid', stream_fid) # <<<<<<<<<<<<<< + * watershed_feature.SetField('terminated_early', terminated_early) + * watershed_feature.SetField('outlet_x', outlet_x) + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4141, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_5 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(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); + __pyx_t_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_n_u_stream_fid, __pyx_v_stream_fid}; + __pyx_t_28 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4141, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_28); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_n_u_stream_fid, __pyx_v_stream_fid}; + __pyx_t_28 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4141, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_28); + } else + #endif + { + __pyx_t_1 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4141, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (__pyx_t_5) { + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5); __pyx_t_5 = NULL; + } + __Pyx_INCREF(__pyx_n_u_stream_fid); + __Pyx_GIVEREF(__pyx_n_u_stream_fid); + PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_11, __pyx_n_u_stream_fid); + __Pyx_INCREF(__pyx_v_stream_fid); + __Pyx_GIVEREF(__pyx_v_stream_fid); + PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_11, __pyx_v_stream_fid); + __pyx_t_28 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_1, NULL); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4141, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_28); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4142 + * watershed_feature.SetGeometry(watershed_polygon) + * watershed_feature.SetField('stream_fid', stream_fid) + * watershed_feature.SetField('terminated_early', terminated_early) # <<<<<<<<<<<<<< + * watershed_feature.SetField('outlet_x', outlet_x) + * watershed_feature.SetField('outlet_y', outlet_y) + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4142, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_terminated_early); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4142, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(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); + __pyx_t_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_n_u_terminated_early, __pyx_t_1}; + __pyx_t_28 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4142, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_28); + __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_5, __pyx_n_u_terminated_early, __pyx_t_1}; + __pyx_t_28 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4142, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_28); + __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, 4142, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (__pyx_t_5) { + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5); __pyx_t_5 = NULL; + } + __Pyx_INCREF(__pyx_n_u_terminated_early); + __Pyx_GIVEREF(__pyx_n_u_terminated_early); + PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_11, __pyx_n_u_terminated_early); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_11, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_28 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_2, NULL); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4142, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_28); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4143 + * watershed_feature.SetField('stream_fid', stream_fid) + * watershed_feature.SetField('terminated_early', terminated_early) + * watershed_feature.SetField('outlet_x', outlet_x) # <<<<<<<<<<<<<< + * watershed_feature.SetField('outlet_y', outlet_y) + * watershed_layer.CreateFeature(watershed_feature) + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4143, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_outlet_x); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4143, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + __pyx_t_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_n_u_outlet_x, __pyx_t_2}; + __pyx_t_28 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4143, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_28); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_n_u_outlet_x, __pyx_t_2}; + __pyx_t_28 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4143, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_28); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + { + __pyx_t_5 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4143, __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_n_u_outlet_x); + __Pyx_GIVEREF(__pyx_n_u_outlet_x); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_11, __pyx_n_u_outlet_x); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_11, __pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_28 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_5, NULL); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4143, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_28); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4144 + * watershed_feature.SetField('terminated_early', terminated_early) + * watershed_feature.SetField('outlet_x', outlet_x) + * watershed_feature.SetField('outlet_y', outlet_y) # <<<<<<<<<<<<<< + * watershed_layer.CreateFeature(watershed_feature) + * + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4144, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_outlet_y); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4144, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(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_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_n_u_outlet_y, __pyx_t_5}; + __pyx_t_28 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4144, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_28); + __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[3] = {__pyx_t_2, __pyx_n_u_outlet_y, __pyx_t_5}; + __pyx_t_28 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4144, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_28); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_1 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4144, __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_n_u_outlet_y); + __Pyx_GIVEREF(__pyx_n_u_outlet_y); + PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_11, __pyx_n_u_outlet_y); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_11, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_28 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_1, NULL); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4144, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_28); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4145 + * watershed_feature.SetField('outlet_x', outlet_x) + * watershed_feature.SetField('outlet_y', outlet_y) + * watershed_layer.CreateFeature(watershed_feature) # <<<<<<<<<<<<<< + * + * # this loop fills in the raster at the boundary, done at end so it + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_layer, __pyx_n_s_CreateFeature); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4145, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_28 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_1, __pyx_v_watershed_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_watershed_feature); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4145, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_28); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4150 + * # doesn't interfere with the loop return to think the cells are no + * # longer in the watershed + * for boundary_x, boundary_y in boundary_list: # <<<<<<<<<<<<<< + * discovery_managed_raster.set(boundary_x, boundary_y, -1) + * watershed_layer.CommitTransaction() + */ + __pyx_t_28 = __pyx_v_boundary_list; __Pyx_INCREF(__pyx_t_28); __pyx_t_22 = 0; + for (;;) { + if (__pyx_t_22 >= PyList_GET_SIZE(__pyx_t_28)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_28, __pyx_t_22); __Pyx_INCREF(__pyx_t_7); __pyx_t_22++; if (unlikely(0 < 0)) __PYX_ERR(0, 4150, __pyx_L1_error) + #else + __pyx_t_7 = PySequence_ITEM(__pyx_t_28, __pyx_t_22); __pyx_t_22++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4150, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) { + PyObject* sequence = __pyx_t_7; + 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, 4150, __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_5 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_1 = PyList_GET_ITEM(sequence, 0); + __pyx_t_5 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_5); + #else + __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4150, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4150, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_2 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4150, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_10 = Py_TYPE(__pyx_t_2)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_10(__pyx_t_2); if (unlikely(!__pyx_t_1)) goto __pyx_L63_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 1; __pyx_t_5 = __pyx_t_10(__pyx_t_2); if (unlikely(!__pyx_t_5)) goto __pyx_L63_unpacking_failed; + __Pyx_GOTREF(__pyx_t_5); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_2), 2) < 0) __PYX_ERR(0, 4150, __pyx_L1_error) + __pyx_t_10 = NULL; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L64_unpacking_done; + __pyx_L63_unpacking_failed:; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_10 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 4150, __pyx_L1_error) + __pyx_L64_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_boundary_x, __pyx_t_1); + __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_boundary_y, __pyx_t_5); + __pyx_t_5 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4151 + * # longer in the watershed + * for boundary_x, boundary_y in boundary_list: + * discovery_managed_raster.set(boundary_x, boundary_y, -1) # <<<<<<<<<<<<<< + * watershed_layer.CommitTransaction() + * watershed_layer = None + */ + __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_v_boundary_x); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4151, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_v_boundary_y); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4151, __pyx_L1_error) + __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_discovery_managed_raster, __pyx_t_11, __pyx_t_8, -1.0); + + /* "pygeoprocessing/routing/routing.pyx":4150 + * # doesn't interfere with the loop return to think the cells are no + * # longer in the watershed + * for boundary_x, boundary_y in boundary_list: # <<<<<<<<<<<<<< + * discovery_managed_raster.set(boundary_x, boundary_y, -1) + * watershed_layer.CommitTransaction() + */ + } + __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4011 + * cdef int _int_max_steps_per_watershed = max_steps_per_watershed + * + * for index, (stream_fid, x_l, y_l) in enumerate(visit_order_stack): # <<<<<<<<<<<<<< + * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + * LOGGER.info( + */ + __pyx_L37_continue:; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4152 + * for boundary_x, boundary_y in boundary_list: + * discovery_managed_raster.set(boundary_x, boundary_y, -1) + * watershed_layer.CommitTransaction() # <<<<<<<<<<<<<< + * watershed_layer = None + * watershed_vector = None + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_layer, __pyx_n_s_CommitTransaction); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4152, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_28 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_28 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_28)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_28); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_6 = (__pyx_t_28) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_28) : __Pyx_PyObject_CallNoArg(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_28); __pyx_t_28 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4152, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4153 + * discovery_managed_raster.set(boundary_x, boundary_y, -1) + * watershed_layer.CommitTransaction() + * watershed_layer = None # <<<<<<<<<<<<<< + * watershed_vector = None + * discovery_managed_raster.close() + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_watershed_layer, Py_None); + + /* "pygeoprocessing/routing/routing.pyx":4154 + * watershed_layer.CommitTransaction() + * watershed_layer = None + * watershed_vector = None # <<<<<<<<<<<<<< + * discovery_managed_raster.close() + * finish_managed_raster.close() + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_watershed_vector, Py_None); + + /* "pygeoprocessing/routing/routing.pyx":4155 + * watershed_layer = None + * watershed_vector = None + * discovery_managed_raster.close() # <<<<<<<<<<<<<< + * finish_managed_raster.close() + * shutil.rmtree(workspace_dir) + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_discovery_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4155, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_28 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_28 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_28)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_28); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_6 = (__pyx_t_28) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_28) : __Pyx_PyObject_CallNoArg(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_28); __pyx_t_28 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4155, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4156 + * watershed_vector = None + * discovery_managed_raster.close() + * finish_managed_raster.close() # <<<<<<<<<<<<<< + * shutil.rmtree(workspace_dir) + * LOGGER.info( + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_finish_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4156, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_28 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_28 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_28)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_28); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_6 = (__pyx_t_28) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_28) : __Pyx_PyObject_CallNoArg(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_28); __pyx_t_28 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4156, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4157 + * discovery_managed_raster.close() + * finish_managed_raster.close() + * shutil.rmtree(workspace_dir) # <<<<<<<<<<<<<< + * LOGGER.info( + * '(calculate_subwatershed_boundary): watershed building 100% complete') + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_shutil); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4157, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_28 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_rmtree); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4157, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_28); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_28))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_28); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_28); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_28, function); + } + } + __pyx_t_6 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_28, __pyx_t_4, __pyx_v_workspace_dir) : __Pyx_PyObject_CallOneArg(__pyx_t_28, __pyx_v_workspace_dir); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4157, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4158 + * finish_managed_raster.close() + * shutil.rmtree(workspace_dir) + * LOGGER.info( # <<<<<<<<<<<<<< + * '(calculate_subwatershed_boundary): watershed building 100% complete') + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_28, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4158, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_28); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_28, __pyx_n_s_info); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4158, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; + __pyx_t_28 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_28 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_28)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_28); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_6 = (__pyx_t_28) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_28, __pyx_kp_u_calculate_subwatershed_boundary_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_calculate_subwatershed_boundary_3); + __Pyx_XDECREF(__pyx_t_28); __pyx_t_28 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4158, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3830 + * + * + * def calculate_subwatershed_boundary( # <<<<<<<<<<<<<< + * d8_flow_dir_raster_path_band, + * strahler_stream_vector_path, target_watershed_boundary_vector_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_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_28); + __Pyx_AddTraceback("pygeoprocessing.routing.routing.calculate_subwatershed_boundary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_workspace_dir); + __Pyx_XDECREF(__pyx_v_discovery_time_raster_path); + __Pyx_XDECREF(__pyx_v_finish_time_raster_path); + __Pyx_XDECREF((PyObject *)__pyx_v_discovery_managed_raster); + __Pyx_XDECREF((PyObject *)__pyx_v_finish_managed_raster); + __Pyx_XDECREF((PyObject *)__pyx_v_d8_flow_dir_managed_raster); + __Pyx_XDECREF(__pyx_v_discovery_info); + __Pyx_XDECREF(__pyx_v_geotransform); + __Pyx_XDECREF(__pyx_v_discovery_srs); + __Pyx_XDECREF(__pyx_v_gpkg_driver); + __Pyx_XDECREF(__pyx_v_watershed_vector); + __Pyx_XDECREF(__pyx_v_watershed_basename); + __Pyx_XDECREF(__pyx_v_watershed_layer); + __Pyx_XDECREF(__pyx_v_stream_vector); + __Pyx_XDECREF(__pyx_v_stream_layer); + __Pyx_XDECREF(__pyx_v_upstream_fid_map); + __Pyx_XDECREF(__pyx_v_stream_feature); + __Pyx_XDECREF(__pyx_v_ds_x); + __Pyx_XDECREF(__pyx_v_ds_y); + __Pyx_XDECREF(__pyx_v_visit_order_stack); + __Pyx_XDECREF(__pyx_v__); + __Pyx_XDECREF(__pyx_v_outlet_fid); + __Pyx_XDECREF(__pyx_v_working_stack); + __Pyx_XDECREF(__pyx_v_processed_nodes); + __Pyx_XDECREF(__pyx_v_working_fid); + __Pyx_XDECREF(__pyx_v_working_feature); + __Pyx_XDECREF(__pyx_v_us_x); + __Pyx_XDECREF(__pyx_v_us_y); + __Pyx_XDECREF(__pyx_v_ds_x_1); + __Pyx_XDECREF(__pyx_v_ds_y_1); + __Pyx_XDECREF(__pyx_v_upstream_coord); + __Pyx_XDECREF(__pyx_v_upstream_fids); + __Pyx_XDECREF(__pyx_v_index); + __Pyx_XDECREF(__pyx_v_stream_fid); + __Pyx_XDECREF(__pyx_v_boundary_list); + __Pyx_XDECREF(__pyx_v_watershed_boundary); + __Pyx_XDECREF(__pyx_v_watershed_feature); + __Pyx_XDECREF(__pyx_v_watershed_polygon); + __Pyx_XDECREF(__pyx_v_boundary_x); + __Pyx_XDECREF(__pyx_v_boundary_y); + __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_x); + __Pyx_XDECREF(__pyx_8genexpr3__pyx_v_fid); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pygeoprocessing/routing/routing.pyx":4162 + * + * + * def detect_outlets( # <<<<<<<<<<<<<< + * flow_dir_raster_path_band, flow_dir_type, target_outlet_vector_path): + * """Create point vector indicating flow raster outlets. + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_27detect_outlets(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_15pygeoprocessing_7routing_7routing_26detect_outlets[] = "Create point vector indicating flow raster outlets.\n\n If either D8 or MFD rasters have a flow direction to the edge of the\n raster or to a nodata flow direction pixel the originating pixel is\n considered an outlet.\n\n Args:\n flow_dir_raster_path_band (tuple): raster path/band tuple\n indicating D8 or MFD flow direction created by\n `routing.flow_dir_d8` or `routing.flow_dir_mfd`.\n flow_dir_type (str): one of 'd8' or 'mfd' to indicate the\n ``flow_dir_raster_path_band`` is either a D8 or MFD flow\n direction raster.\n target_outlet_vector_path (str): path to a vector that is created\n by this call that will be in the same projection units as the\n raster and have a point feature in the center of each pixel that\n is a raster outlet. Additional fields include:\n\n * \"i\" - the column raster coordinate where the outlet exists\n * \"j\" - the row raster coordinate where the outlet exists\n * \"ID\" - unique identification for the outlet.\n\n Return:\n None.\n "; +static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_27detect_outlets = {"detect_outlets", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_7routing_7routing_27detect_outlets, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_7routing_7routing_26detect_outlets}; +static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_27detect_outlets(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_flow_dir_raster_path_band = 0; + PyObject *__pyx_v_flow_dir_type = 0; + PyObject *__pyx_v_target_outlet_vector_path = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("detect_outlets (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_flow_dir_raster_path_band,&__pyx_n_s_flow_dir_type,&__pyx_n_s_target_outlet_vector_path,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_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_flow_dir_type)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("detect_outlets", 1, 3, 3, 1); __PYX_ERR(0, 4162, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_outlet_vector_path)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("detect_outlets", 1, 3, 3, 2); __PYX_ERR(0, 4162, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "detect_outlets") < 0)) __PYX_ERR(0, 4162, __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_flow_dir_raster_path_band = values[0]; + __pyx_v_flow_dir_type = values[1]; + __pyx_v_target_outlet_vector_path = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("detect_outlets", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 4162, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pygeoprocessing.routing.routing.detect_outlets", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing_26detect_outlets(__pyx_self, __pyx_v_flow_dir_raster_path_band, __pyx_v_flow_dir_type, __pyx_v_target_outlet_vector_path); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_26detect_outlets(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_flow_dir_raster_path_band, PyObject *__pyx_v_flow_dir_type, PyObject *__pyx_v_target_outlet_vector_path) { + int __pyx_v_d8_flow_dir_mode; + 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_raster_x_size; + int __pyx_v_raster_y_size; + int __pyx_v_flow_dir; + int __pyx_v_flow_dir_n; + int __pyx_v_next_id; + int __pyx_v_n_dir; + int __pyx_v_is_outlet; + char __pyx_v_x_off_border; + char __pyx_v_y_off_border; + char __pyx_v_win_xsize_border; + char __pyx_v_win_ysize_border; + PyArrayObject *__pyx_v_flow_dir_block = 0; + PyObject *__pyx_v_raster_info = NULL; + int __pyx_v_flow_dir_nodata; + PyObject *__pyx_v_flow_dir_raster = NULL; + PyObject *__pyx_v_flow_dir_band = NULL; + PyObject *__pyx_v_raster_srs = NULL; + PyObject *__pyx_v_gpkg_driver = NULL; + PyObject *__pyx_v_outlet_vector = NULL; + PyObject *__pyx_v_outet_basename = NULL; + PyObject *__pyx_v_outlet_layer = NULL; + time_t __pyx_v_last_log_time; + PyObject *__pyx_v_block_offsets = NULL; + PyObject *__pyx_v_current_pixel = NULL; + PyObject *__pyx_v_outlet_point = NULL; + PyObject *__pyx_v_proj_x = NULL; + PyObject *__pyx_v_proj_y = NULL; + PyObject *__pyx_v_outlet_feature = NULL; + __Pyx_LocalBuf_ND __pyx_pybuffernd_flow_dir_block; + __Pyx_Buffer __pyx_pybuffer_flow_dir_block; + 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; + int __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *(*__pyx_t_8)(PyObject *); + int __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + Py_ssize_t __pyx_t_12; + Py_UCS4 __pyx_t_13; + PyObject *__pyx_t_14 = NULL; + 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; + long __pyx_t_20; + long __pyx_t_21; + Py_ssize_t __pyx_t_22; + long __pyx_t_23; + long __pyx_t_24; + Py_ssize_t __pyx_t_25; + Py_ssize_t __pyx_t_26; + int __pyx_t_27; + int __pyx_t_28; + PyObject *__pyx_t_29 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("detect_outlets", 0); + __Pyx_INCREF(__pyx_v_flow_dir_type); + __pyx_pybuffer_flow_dir_block.pybuffer.buf = NULL; + __pyx_pybuffer_flow_dir_block.refcount = 0; + __pyx_pybuffernd_flow_dir_block.data = NULL; + __pyx_pybuffernd_flow_dir_block.rcbuffer = &__pyx_pybuffer_flow_dir_block; + + /* "pygeoprocessing/routing/routing.pyx":4189 + * None. + * """ + * flow_dir_type = flow_dir_type.lower() # <<<<<<<<<<<<<< + * if flow_dir_type not in ['d8', 'mfd']: + * raise ValueError( + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_type, __pyx_n_s_lower); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4189, __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); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF_SET(__pyx_v_flow_dir_type, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4190 + * """ + * flow_dir_type = flow_dir_type.lower() + * if flow_dir_type not in ['d8', 'mfd']: # <<<<<<<<<<<<<< + * raise ValueError( + * f'expected flow dir type of either d8 or mfd but got ' + */ + __Pyx_INCREF(__pyx_v_flow_dir_type); + __pyx_t_1 = __pyx_v_flow_dir_type; + __pyx_t_5 = (__Pyx_PyUnicode_Equals(__pyx_t_1, __pyx_n_u_d8, Py_NE)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 4190, __pyx_L1_error) + if (__pyx_t_5) { + } else { + __pyx_t_4 = __pyx_t_5; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_5 = (__Pyx_PyUnicode_Equals(__pyx_t_1, __pyx_n_u_mfd, Py_NE)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 4190, __pyx_L1_error) + __pyx_t_4 = __pyx_t_5; + __pyx_L4_bool_binop_done:; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_5 = (__pyx_t_4 != 0); + if (unlikely(__pyx_t_5)) { + + /* "pygeoprocessing/routing/routing.pyx":4193 + * raise ValueError( + * f'expected flow dir type of either d8 or mfd but got ' + * f'{flow_dir_type}') # <<<<<<<<<<<<<< + * cdef int d8_flow_dir_mode = (flow_dir_type == 'd8') + * + */ + __pyx_t_1 = __Pyx_PyObject_FormatSimple(__pyx_v_flow_dir_type, __pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4193, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":4192 + * if flow_dir_type not in ['d8', 'mfd']: + * raise ValueError( + * f'expected flow dir type of either d8 or mfd but got ' # <<<<<<<<<<<<<< + * f'{flow_dir_type}') + * cdef int d8_flow_dir_mode = (flow_dir_type == 'd8') + */ + __pyx_t_2 = __Pyx_PyUnicode_Concat(__pyx_kp_u_expected_flow_dir_type_of_either, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4192, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4191 + * flow_dir_type = flow_dir_type.lower() + * if flow_dir_type not in ['d8', 'mfd']: + * raise ValueError( # <<<<<<<<<<<<<< + * f'expected flow dir type of either d8 or mfd but got ' + * f'{flow_dir_type}') + */ + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4191, __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, 4191, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":4190 + * """ + * flow_dir_type = flow_dir_type.lower() + * if flow_dir_type not in ['d8', 'mfd']: # <<<<<<<<<<<<<< + * raise ValueError( + * f'expected flow dir type of either d8 or mfd but got ' + */ + } + + /* "pygeoprocessing/routing/routing.pyx":4194 + * f'expected flow dir type of either d8 or mfd but got ' + * f'{flow_dir_type}') + * cdef int d8_flow_dir_mode = (flow_dir_type == 'd8') # <<<<<<<<<<<<<< + * + * cdef int xoff, yoff, win_xsize, win_ysize, xi, yi + */ + __pyx_t_1 = PyObject_RichCompare(__pyx_v_flow_dir_type, __pyx_n_u_d8, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4194, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4194, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_d8_flow_dir_mode = __pyx_t_6; + + /* "pygeoprocessing/routing/routing.pyx":4199 + * cdef int xi_root, yi_root, raster_x_size, raster_y_size + * cdef int flow_dir, flow_dir_n + * cdef int next_id=0, n_dir, is_outlet # <<<<<<<<<<<<<< + * cdef char x_off_border, y_off_border, win_xsize_border, win_ysize_border + * + */ + __pyx_v_next_id = 0; + + /* "pygeoprocessing/routing/routing.pyx":4204 + * cdef numpy.ndarray[numpy.npy_int32, ndim=2] flow_dir_block + * + * raster_info = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< + * flow_dir_raster_path_band[0]) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4204, __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, 4204, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4205 + * + * raster_info = pygeoprocessing.get_raster_info( + * flow_dir_raster_path_band[0]) # <<<<<<<<<<<<<< + * + * cdef int flow_dir_nodata = raster_info['nodata'][ + */ + __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_flow_dir_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4205, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_7, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4204, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_raster_info = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4207 + * flow_dir_raster_path_band[0]) + * + * cdef int flow_dir_nodata = raster_info['nodata'][ # <<<<<<<<<<<<<< + * flow_dir_raster_path_band[1]-1] + * + */ + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4207, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/routing.pyx":4208 + * + * cdef int flow_dir_nodata = raster_info['nodata'][ + * flow_dir_raster_path_band[1]-1] # <<<<<<<<<<<<<< + * + * raster_x_size, raster_y_size = raster_info['raster_size'] + */ + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_flow_dir_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4208, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_t_3, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4208, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4207 + * flow_dir_raster_path_band[0]) + * + * cdef int flow_dir_nodata = raster_info['nodata'][ # <<<<<<<<<<<<<< + * flow_dir_raster_path_band[1]-1] + * + */ + __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4207, __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_6 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4207, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_flow_dir_nodata = __pyx_t_6; + + /* "pygeoprocessing/routing/routing.pyx":4210 + * flow_dir_raster_path_band[1]-1] + * + * raster_x_size, raster_y_size = raster_info['raster_size'] # <<<<<<<<<<<<<< + * + * flow_dir_raster = gdal.OpenEx( + */ + __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4210, __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, 4210, __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_1 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_2 = PyList_GET_ITEM(sequence, 0); + __pyx_t_1 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + #else + __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4210, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4210, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_7 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4210, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_2 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_2)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + index = 1; __pyx_t_1 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_1)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 4210, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L7_unpacking_done; + __pyx_L6_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 4210, __pyx_L1_error) + __pyx_L7_unpacking_done:; + } + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4210, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4210, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_raster_x_size = __pyx_t_6; + __pyx_v_raster_y_size = __pyx_t_9; + + /* "pygeoprocessing/routing/routing.pyx":4212 + * raster_x_size, raster_y_size = raster_info['raster_size'] + * + * flow_dir_raster = gdal.OpenEx( # <<<<<<<<<<<<<< + * flow_dir_raster_path_band[0], gdal.OF_RASTER) + * flow_dir_band = flow_dir_raster.GetRasterBand( + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4212, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4212, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4213 + * + * 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_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, 4213, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4213, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4213, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + __pyx_t_9 = 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_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_1, __pyx_t_10}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4212, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_1, __pyx_t_10}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4212, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } else + #endif + { + __pyx_t_11 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4212, __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_1); + PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_9, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_9, __pyx_t_10); + __pyx_t_1 = 0; + __pyx_t_10 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_11, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4212, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_flow_dir_raster = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4214 + * 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_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4214, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + + /* "pygeoprocessing/routing/routing.pyx":4215 + * flow_dir_raster_path_band[0], gdal.OF_RASTER) + * flow_dir_band = flow_dir_raster.GetRasterBand( + * flow_dir_raster_path_band[1]) # <<<<<<<<<<<<<< + * + * if raster_info['projection_wkt']: + */ + __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_flow_dir_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4215, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_10 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_3 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_10, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_11); + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4214, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_flow_dir_band = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4217 + * flow_dir_raster_path_band[1]) + * + * if raster_info['projection_wkt']: # <<<<<<<<<<<<<< + * raster_srs = osr.SpatialReference() + * raster_srs.ImportFromWkt(raster_info['projection_wkt']) + */ + __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_projection_wkt); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4217, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 4217, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":4218 + * + * if raster_info['projection_wkt']: + * raster_srs = osr.SpatialReference() # <<<<<<<<<<<<<< + * raster_srs.ImportFromWkt(raster_info['projection_wkt']) + * else: + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_osr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4218, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_SpatialReference); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4218, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(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); + } + } + __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4218, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_v_raster_srs = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4219 + * if raster_info['projection_wkt']: + * raster_srs = osr.SpatialReference() + * raster_srs.ImportFromWkt(raster_info['projection_wkt']) # <<<<<<<<<<<<<< + * else: + * raster_srs = None + */ + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster_srs, __pyx_n_s_ImportFromWkt); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4219, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_projection_wkt); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4219, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + } + } + __pyx_t_3 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_10, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4219, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4217 + * flow_dir_raster_path_band[1]) + * + * if raster_info['projection_wkt']: # <<<<<<<<<<<<<< + * raster_srs = osr.SpatialReference() + * raster_srs.ImportFromWkt(raster_info['projection_wkt']) + */ + goto __pyx_L8; + } + + /* "pygeoprocessing/routing/routing.pyx":4221 + * raster_srs.ImportFromWkt(raster_info['projection_wkt']) + * else: + * raster_srs = None # <<<<<<<<<<<<<< + * + * gpkg_driver = gdal.GetDriverByName('GPKG') + */ + /*else*/ { + __Pyx_INCREF(Py_None); + __pyx_v_raster_srs = Py_None; + } + __pyx_L8:; + + /* "pygeoprocessing/routing/routing.pyx":4223 + * raster_srs = None + * + * gpkg_driver = gdal.GetDriverByName('GPKG') # <<<<<<<<<<<<<< + * + * if os.path.exists(target_outlet_vector_path): + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_gdal); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4223, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_GetDriverByName); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4223, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = NULL; + 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_3 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_11, __pyx_n_u_GPKG) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_n_u_GPKG); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4223, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_gpkg_driver = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4225 + * gpkg_driver = gdal.GetDriverByName('GPKG') + * + * if os.path.exists(target_outlet_vector_path): # <<<<<<<<<<<<<< + * LOGGER.warning( + * f'outlet detection: {target_outlet_vector_path} exists, ' + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4225, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_path); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4225, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_exists); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4225, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_3 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_11, __pyx_v_target_outlet_vector_path) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_target_outlet_vector_path); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4225, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 4225, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":4226 + * + * if os.path.exists(target_outlet_vector_path): + * LOGGER.warning( # <<<<<<<<<<<<<< + * f'outlet detection: {target_outlet_vector_path} exists, ' + * 'removing before creating a new one.') + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4226, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_warning); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4226, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4227 + * if os.path.exists(target_outlet_vector_path): + * LOGGER.warning( + * f'outlet detection: {target_outlet_vector_path} exists, ' # <<<<<<<<<<<<<< + * 'removing before creating a new one.') + * os.remove(target_outlet_vector_path) + */ + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4227, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_12 = 0; + __pyx_t_13 = 127; + __Pyx_INCREF(__pyx_kp_u_outlet_detection); + __pyx_t_12 += 18; + __Pyx_GIVEREF(__pyx_kp_u_outlet_detection); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_u_outlet_detection); + __pyx_t_10 = __Pyx_PyObject_FormatSimple(__pyx_v_target_outlet_vector_path, __pyx_empty_unicode); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4227, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_13 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_10) > __pyx_t_13) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_10) : __pyx_t_13; + __pyx_t_12 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_10); + __pyx_t_10 = 0; + __Pyx_INCREF(__pyx_kp_u_exists_removing_before_creating); + __pyx_t_12 += 44; + __Pyx_GIVEREF(__pyx_kp_u_exists_removing_before_creating); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_kp_u_exists_removing_before_creating); + __pyx_t_10 = __Pyx_PyUnicode_Join(__pyx_t_2, 3, __pyx_t_12, __pyx_t_13); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4227, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(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); + } + } + __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_2, __pyx_t_10) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_10); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4226, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4229 + * f'outlet detection: {target_outlet_vector_path} exists, ' + * 'removing before creating a new one.') + * os.remove(target_outlet_vector_path) # <<<<<<<<<<<<<< + * outlet_vector = gpkg_driver.Create( + * target_outlet_vector_path, 0, 0, 0, gdal.GDT_Unknown) + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_os); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4229, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_remove); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4229, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_10); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_10, function); + } + } + __pyx_t_3 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_11, __pyx_v_target_outlet_vector_path) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_v_target_outlet_vector_path); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4229, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4225 + * gpkg_driver = gdal.GetDriverByName('GPKG') + * + * if os.path.exists(target_outlet_vector_path): # <<<<<<<<<<<<<< + * LOGGER.warning( + * f'outlet detection: {target_outlet_vector_path} exists, ' + */ + } + + /* "pygeoprocessing/routing/routing.pyx":4230 + * 'removing before creating a new one.') + * os.remove(target_outlet_vector_path) + * outlet_vector = gpkg_driver.Create( # <<<<<<<<<<<<<< + * target_outlet_vector_path, 0, 0, 0, gdal.GDT_Unknown) + * outet_basename = os.path.basename( + */ + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_gpkg_driver, __pyx_n_s_Create); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4230, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + + /* "pygeoprocessing/routing/routing.pyx":4231 + * os.remove(target_outlet_vector_path) + * outlet_vector = gpkg_driver.Create( + * target_outlet_vector_path, 0, 0, 0, gdal.GDT_Unknown) # <<<<<<<<<<<<<< + * outet_basename = os.path.basename( + * os.path.splitext(target_outlet_vector_path)[0]) + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_gdal); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4231, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_GDT_Unknown); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4231, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_10); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_10, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_10)) { + PyObject *__pyx_temp[6] = {__pyx_t_11, __pyx_v_target_outlet_vector_path, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_t_2}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_9, 5+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4230, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 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_10)) { + PyObject *__pyx_temp[6] = {__pyx_t_11, __pyx_v_target_outlet_vector_path, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_t_2}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_9, 5+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4230, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + { + __pyx_t_1 = PyTuple_New(5+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4230, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (__pyx_t_11) { + __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_11); __pyx_t_11 = NULL; + } + __Pyx_INCREF(__pyx_v_target_outlet_vector_path); + __Pyx_GIVEREF(__pyx_v_target_outlet_vector_path); + PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_9, __pyx_v_target_outlet_vector_path); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_9, __pyx_int_0); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_1, 2+__pyx_t_9, __pyx_int_0); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_1, 3+__pyx_t_9, __pyx_int_0); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_1, 4+__pyx_t_9, __pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4230, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_v_outlet_vector = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4232 + * outlet_vector = gpkg_driver.Create( + * target_outlet_vector_path, 0, 0, 0, gdal.GDT_Unknown) + * outet_basename = os.path.basename( # <<<<<<<<<<<<<< + * os.path.splitext(target_outlet_vector_path)[0]) + * outlet_layer = outlet_vector.CreateLayer( + */ + __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_os); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4232, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4232, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_basename); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4232, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4233 + * target_outlet_vector_path, 0, 0, 0, gdal.GDT_Unknown) + * outet_basename = os.path.basename( + * os.path.splitext(target_outlet_vector_path)[0]) # <<<<<<<<<<<<<< + * outlet_layer = outlet_vector.CreateLayer( + * outet_basename, raster_srs, ogr.wkbPoint) + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4233, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_path); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4233, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_splitext); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4233, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_1 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_11, __pyx_v_target_outlet_vector_path) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_target_outlet_vector_path); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4233, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4233, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_10); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_10, function); + } + } + __pyx_t_3 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_1, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4232, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_v_outet_basename = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4234 + * outet_basename = os.path.basename( + * os.path.splitext(target_outlet_vector_path)[0]) + * outlet_layer = outlet_vector.CreateLayer( # <<<<<<<<<<<<<< + * outet_basename, raster_srs, ogr.wkbPoint) + * # i and j indicate the coordinates of the point in raster space whereas + */ + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_vector, __pyx_n_s_CreateLayer); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4234, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + + /* "pygeoprocessing/routing/routing.pyx":4235 + * os.path.splitext(target_outlet_vector_path)[0]) + * outlet_layer = outlet_vector.CreateLayer( + * outet_basename, raster_srs, ogr.wkbPoint) # <<<<<<<<<<<<<< + * # i and j indicate the coordinates of the point in raster space whereas + * # the geometry is in projected space + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_ogr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4235, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_wkbPoint); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4235, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && likely(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); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_10)) { + PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_v_outet_basename, __pyx_v_raster_srs, __pyx_t_1}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4234, __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[4] = {__pyx_t_2, __pyx_v_outet_basename, __pyx_v_raster_srs, __pyx_t_1}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4234, __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_11 = PyTuple_New(3+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4234, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + if (__pyx_t_2) { + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_2); __pyx_t_2 = NULL; + } + __Pyx_INCREF(__pyx_v_outet_basename); + __Pyx_GIVEREF(__pyx_v_outet_basename); + PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_9, __pyx_v_outet_basename); + __Pyx_INCREF(__pyx_v_raster_srs); + __Pyx_GIVEREF(__pyx_v_raster_srs); + PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_9, __pyx_v_raster_srs); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_11, 2+__pyx_t_9, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_11, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4234, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_v_outlet_layer = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4238 + * # i and j indicate the coordinates of the point in raster space whereas + * # the geometry is in projected space + * outlet_layer.CreateField(ogr.FieldDefn('i', ogr.OFTInteger)) # <<<<<<<<<<<<<< + * outlet_layer.CreateField(ogr.FieldDefn('j', ogr.OFTInteger)) + * outlet_layer.CreateField(ogr.FieldDefn('ID', ogr.OFTInteger)) + */ + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4238, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4238, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4238, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4238, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4238, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_n_u_i, __pyx_t_7}; + __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4238, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_n_u_i, __pyx_t_7}; + __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4238, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_14 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4238, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + if (__pyx_t_1) { + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_1); __pyx_t_1 = NULL; + } + __Pyx_INCREF(__pyx_n_u_i); + __Pyx_GIVEREF(__pyx_n_u_i); + PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_9, __pyx_n_u_i); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_9, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_14, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4238, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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); + } + } + __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_2, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_11); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4238, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4239 + * # the geometry is in projected space + * outlet_layer.CreateField(ogr.FieldDefn('i', ogr.OFTInteger)) + * outlet_layer.CreateField(ogr.FieldDefn('j', ogr.OFTInteger)) # <<<<<<<<<<<<<< + * outlet_layer.CreateField(ogr.FieldDefn('ID', ogr.OFTInteger)) + * outlet_layer.StartTransaction() + */ + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4239, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_ogr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4239, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4239, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_ogr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4239, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4239, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __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_14))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_n_u_j, __pyx_t_7}; + __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4239, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_n_u_j, __pyx_t_7}; + __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4239, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_1 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4239, __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_n_u_j); + __Pyx_GIVEREF(__pyx_n_u_j); + PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_9, __pyx_n_u_j); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_9, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_1, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4239, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_14 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { + __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_10); + if (likely(__pyx_t_14)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_10, function); + } + } + __pyx_t_3 = (__pyx_t_14) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_14, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_11); + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4239, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4240 + * outlet_layer.CreateField(ogr.FieldDefn('i', ogr.OFTInteger)) + * outlet_layer.CreateField(ogr.FieldDefn('j', ogr.OFTInteger)) + * outlet_layer.CreateField(ogr.FieldDefn('ID', ogr.OFTInteger)) # <<<<<<<<<<<<<< + * outlet_layer.StartTransaction() + * + */ + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4240, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_ogr); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4240, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4240, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_ogr); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4240, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4240, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_14 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_14)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_14, __pyx_n_u_ID, __pyx_t_7}; + __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4240, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_14, __pyx_n_u_ID, __pyx_t_7}; + __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4240, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_2 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4240, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (__pyx_t_14) { + __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_14); __pyx_t_14 = NULL; + } + __Pyx_INCREF(__pyx_n_u_ID); + __Pyx_GIVEREF(__pyx_n_u_ID); + PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_9, __pyx_n_u_ID); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_9, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4240, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_10); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_10, function); + } + } + __pyx_t_3 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_1, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_11); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4240, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4241 + * outlet_layer.CreateField(ogr.FieldDefn('j', ogr.OFTInteger)) + * outlet_layer.CreateField(ogr.FieldDefn('ID', ogr.OFTInteger)) + * outlet_layer.StartTransaction() # <<<<<<<<<<<<<< + * + * cdef time_t last_log_time = ctime(NULL) + */ + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_layer, __pyx_n_s_StartTransaction); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4241, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_10); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_10, function); + } + } + __pyx_t_3 = (__pyx_t_11) ? __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_11) : __Pyx_PyObject_CallNoArg(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4241, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4243 + * outlet_layer.StartTransaction() + * + * cdef time_t last_log_time = ctime(NULL) # <<<<<<<<<<<<<< + * # iterate by iterblocks so ReadAsArray can efficiently cache reads + * # and writes + */ + __pyx_v_last_log_time = time(NULL); + + /* "pygeoprocessing/routing/routing.pyx":4246 + * # iterate by iterblocks so ReadAsArray can efficiently cache reads + * # and writes + * LOGGER.info('outlet detection: 0% complete') # <<<<<<<<<<<<<< + * for block_offsets in pygeoprocessing.iterblocks( + * flow_dir_raster_path_band, offset_only=True): + */ + __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4246, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_info); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4246, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + } + } + __pyx_t_3 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_10, __pyx_kp_u_outlet_detection_0_complete) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_kp_u_outlet_detection_0_complete); + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4246, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4247 + * # and writes + * LOGGER.info('outlet detection: 0% complete') + * for block_offsets in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * flow_dir_raster_path_band, offset_only=True): + * xoff = block_offsets['xoff'] + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4247, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4247, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4248 + * LOGGER.info('outlet detection: 0% complete') + * for block_offsets in pygeoprocessing.iterblocks( + * flow_dir_raster_path_band, offset_only=True): # <<<<<<<<<<<<<< + * xoff = block_offsets['xoff'] + * yoff = block_offsets['yoff'] + */ + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4247, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_flow_dir_raster_path_band); + __Pyx_GIVEREF(__pyx_v_flow_dir_raster_path_band); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_flow_dir_raster_path_band); + __pyx_t_10 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4248, __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, 4248, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":4247 + * # and writes + * LOGGER.info('outlet detection: 0% complete') + * for block_offsets in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * flow_dir_raster_path_band, offset_only=True): + * xoff = block_offsets['xoff'] + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_3, __pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4247, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_10 = __pyx_t_1; __Pyx_INCREF(__pyx_t_10); __pyx_t_12 = 0; + __pyx_t_15 = NULL; + } else { + __pyx_t_12 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4247, __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, 4247, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (likely(!__pyx_t_15)) { + if (likely(PyList_CheckExact(__pyx_t_10))) { + if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_10)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_12); __Pyx_INCREF(__pyx_t_1); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 4247, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_10, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4247, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } else { + if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_10)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_12); __Pyx_INCREF(__pyx_t_1); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 4247, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_10, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4247, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } + } else { + __pyx_t_1 = __pyx_t_15(__pyx_t_10); + 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, 4247, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XDECREF_SET(__pyx_v_block_offsets, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4249 + * for block_offsets in pygeoprocessing.iterblocks( + * flow_dir_raster_path_band, offset_only=True): + * xoff = block_offsets['xoff'] # <<<<<<<<<<<<<< + * yoff = block_offsets['yoff'] + * win_xsize = block_offsets['win_xsize'] + */ + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_u_xoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4249, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4249, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_xoff = __pyx_t_9; + + /* "pygeoprocessing/routing/routing.pyx":4250 + * flow_dir_raster_path_band, 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_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_u_yoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4250, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4250, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_yoff = __pyx_t_9; + + /* "pygeoprocessing/routing/routing.pyx":4251 + * xoff = block_offsets['xoff'] + * yoff = block_offsets['yoff'] + * win_xsize = block_offsets['win_xsize'] # <<<<<<<<<<<<<< + * win_ysize = block_offsets['win_ysize'] + * + */ + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4251, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4251, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_win_xsize = __pyx_t_9; + + /* "pygeoprocessing/routing/routing.pyx":4252 + * yoff = block_offsets['yoff'] + * win_xsize = block_offsets['win_xsize'] + * win_ysize = block_offsets['win_ysize'] # <<<<<<<<<<<<<< + * + * # Make an array with a 1 pixel border around the iterblocks window + */ + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4252, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4252, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_win_ysize = __pyx_t_9; + + /* "pygeoprocessing/routing/routing.pyx":4257 + * # That border will be filled in with nodata or data from the raster + * # if the window does not align with a top/bottom/left/right edge + * flow_dir_block = numpy.empty( # <<<<<<<<<<<<<< + * (win_ysize+2, win_xsize+2), dtype=numpy.int32) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4257, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4257, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4258 + * # if the window does not align with a top/bottom/left/right edge + * flow_dir_block = numpy.empty( + * (win_ysize+2, win_xsize+2), dtype=numpy.int32) # <<<<<<<<<<<<<< + * + * # Test for left border and if so stripe nodata on the left margin + */ + __pyx_t_1 = __Pyx_PyInt_From_long((__pyx_v_win_ysize + 2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4258, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_11 = __Pyx_PyInt_From_long((__pyx_v_win_xsize + 2)); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4258, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4258, __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_11); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_11); + __pyx_t_1 = 0; + __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4257 + * # That border will be filled in with nodata or data from the raster + * # if the window does not align with a top/bottom/left/right edge + * flow_dir_block = numpy.empty( # <<<<<<<<<<<<<< + * (win_ysize+2, win_xsize+2), dtype=numpy.int32) + * + */ + __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4257, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4258 + * # if the window does not align with a top/bottom/left/right edge + * flow_dir_block = numpy.empty( + * (win_ysize+2, win_xsize+2), dtype=numpy.int32) # <<<<<<<<<<<<<< + * + * # Test for left border and if so stripe nodata on the left margin + */ + __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4258, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4258, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_int32); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4258, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 4258, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4257 + * # That border will be filled in with nodata or data from the raster + * # if the window does not align with a top/bottom/left/right edge + * flow_dir_block = numpy.empty( # <<<<<<<<<<<<<< + * (win_ysize+2, win_xsize+2), dtype=numpy.int32) + * + */ + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_11, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4257, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 4257, __pyx_L1_error) + __pyx_t_16 = ((PyArrayObject *)__pyx_t_7); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_flow_dir_block.rcbuffer->pybuffer); + __pyx_t_9 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_flow_dir_block.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo_nn_npy_int32, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); + if (unlikely(__pyx_t_9 < 0)) { + PyErr_Fetch(&__pyx_t_17, &__pyx_t_18, &__pyx_t_19); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_flow_dir_block.rcbuffer->pybuffer, (PyObject*)__pyx_v_flow_dir_block, &__Pyx_TypeInfo_nn_npy_int32, 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_block.diminfo[0].strides = __pyx_pybuffernd_flow_dir_block.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_flow_dir_block.diminfo[0].shape = __pyx_pybuffernd_flow_dir_block.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_flow_dir_block.diminfo[1].strides = __pyx_pybuffernd_flow_dir_block.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_flow_dir_block.diminfo[1].shape = __pyx_pybuffernd_flow_dir_block.rcbuffer->pybuffer.shape[1]; + if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 4257, __pyx_L1_error) + } + __pyx_t_16 = 0; + __Pyx_XDECREF_SET(__pyx_v_flow_dir_block, ((PyArrayObject *)__pyx_t_7)); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4261 + * + * # Test for left border and if so stripe nodata on the left margin + * x_off_border = 0 # <<<<<<<<<<<<<< + * if xoff > 0: + * x_off_border = 1 + */ + __pyx_v_x_off_border = 0; + + /* "pygeoprocessing/routing/routing.pyx":4262 + * # Test for left border and if so stripe nodata on the left margin + * x_off_border = 0 + * if xoff > 0: # <<<<<<<<<<<<<< + * x_off_border = 1 + * else: + */ + __pyx_t_5 = ((__pyx_v_xoff > 0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":4263 + * x_off_border = 0 + * if xoff > 0: + * x_off_border = 1 # <<<<<<<<<<<<<< + * else: + * flow_dir_block[:, 0] = flow_dir_nodata + */ + __pyx_v_x_off_border = 1; + + /* "pygeoprocessing/routing/routing.pyx":4262 + * # Test for left border and if so stripe nodata on the left margin + * x_off_border = 0 + * if xoff > 0: # <<<<<<<<<<<<<< + * x_off_border = 1 + * else: + */ + goto __pyx_L12; + } + + /* "pygeoprocessing/routing/routing.pyx":4265 + * x_off_border = 1 + * else: + * flow_dir_block[:, 0] = flow_dir_nodata # <<<<<<<<<<<<<< + * + * # Test for top border and if so stripe nodata on the top margin + */ + /*else*/ { + __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_flow_dir_nodata); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4265, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_block), __pyx_tuple__20, __pyx_t_7) < 0)) __PYX_ERR(0, 4265, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __pyx_L12:; + + /* "pygeoprocessing/routing/routing.pyx":4268 + * + * # Test for top border and if so stripe nodata on the top margin + * y_off_border = 0 # <<<<<<<<<<<<<< + * if yoff > 0: + * y_off_border = 1 + */ + __pyx_v_y_off_border = 0; + + /* "pygeoprocessing/routing/routing.pyx":4269 + * # Test for top border and if so stripe nodata on the top margin + * y_off_border = 0 + * if yoff > 0: # <<<<<<<<<<<<<< + * y_off_border = 1 + * else: + */ + __pyx_t_5 = ((__pyx_v_yoff > 0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":4270 + * y_off_border = 0 + * if yoff > 0: + * y_off_border = 1 # <<<<<<<<<<<<<< + * else: + * flow_dir_block[0, :] = flow_dir_nodata + */ + __pyx_v_y_off_border = 1; + + /* "pygeoprocessing/routing/routing.pyx":4269 + * # Test for top border and if so stripe nodata on the top margin + * y_off_border = 0 + * if yoff > 0: # <<<<<<<<<<<<<< + * y_off_border = 1 + * else: + */ + goto __pyx_L13; + } + + /* "pygeoprocessing/routing/routing.pyx":4272 + * y_off_border = 1 + * else: + * flow_dir_block[0, :] = flow_dir_nodata # <<<<<<<<<<<<<< + * + * # Test for right border and if so stripe nodata on the right margin + */ + /*else*/ { + __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_flow_dir_nodata); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4272, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_block), __pyx_tuple__21, __pyx_t_7) < 0)) __PYX_ERR(0, 4272, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __pyx_L13:; + + /* "pygeoprocessing/routing/routing.pyx":4275 + * + * # Test for right border and if so stripe nodata on the right margin + * win_xsize_border = 0 # <<<<<<<<<<<<<< + * if xoff+win_xsize < raster_x_size-1: + * win_xsize_border += 1 + */ + __pyx_v_win_xsize_border = 0; + + /* "pygeoprocessing/routing/routing.pyx":4276 + * # Test for right border and if so stripe nodata on the right margin + * win_xsize_border = 0 + * if xoff+win_xsize < raster_x_size-1: # <<<<<<<<<<<<<< + * win_xsize_border += 1 + * else: + */ + __pyx_t_5 = (((__pyx_v_xoff + __pyx_v_win_xsize) < (__pyx_v_raster_x_size - 1)) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":4277 + * win_xsize_border = 0 + * if xoff+win_xsize < raster_x_size-1: + * win_xsize_border += 1 # <<<<<<<<<<<<<< + * else: + * flow_dir_block[:, -1] = flow_dir_nodata + */ + __pyx_v_win_xsize_border = (__pyx_v_win_xsize_border + 1); + + /* "pygeoprocessing/routing/routing.pyx":4276 + * # Test for right border and if so stripe nodata on the right margin + * win_xsize_border = 0 + * if xoff+win_xsize < raster_x_size-1: # <<<<<<<<<<<<<< + * win_xsize_border += 1 + * else: + */ + goto __pyx_L14; + } + + /* "pygeoprocessing/routing/routing.pyx":4279 + * win_xsize_border += 1 + * else: + * flow_dir_block[:, -1] = flow_dir_nodata # <<<<<<<<<<<<<< + * + * # Test for bottom border and if so stripe nodata on the bottom margin + */ + /*else*/ { + __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_flow_dir_nodata); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4279, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_block), __pyx_tuple__22, __pyx_t_7) < 0)) __PYX_ERR(0, 4279, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __pyx_L14:; + + /* "pygeoprocessing/routing/routing.pyx":4282 + * + * # Test for bottom border and if so stripe nodata on the bottom margin + * win_ysize_border = 0 # <<<<<<<<<<<<<< + * if yoff+win_ysize < raster_y_size-1: + * win_ysize_border += 1 + */ + __pyx_v_win_ysize_border = 0; + + /* "pygeoprocessing/routing/routing.pyx":4283 + * # Test for bottom border and if so stripe nodata on the bottom margin + * win_ysize_border = 0 + * if yoff+win_ysize < raster_y_size-1: # <<<<<<<<<<<<<< + * win_ysize_border += 1 + * else: + */ + __pyx_t_5 = (((__pyx_v_yoff + __pyx_v_win_ysize) < (__pyx_v_raster_y_size - 1)) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":4284 + * win_ysize_border = 0 + * if yoff+win_ysize < raster_y_size-1: + * win_ysize_border += 1 # <<<<<<<<<<<<<< + * else: + * flow_dir_block[-1, :] = flow_dir_nodata + */ + __pyx_v_win_ysize_border = (__pyx_v_win_ysize_border + 1); + + /* "pygeoprocessing/routing/routing.pyx":4283 + * # Test for bottom border and if so stripe nodata on the bottom margin + * win_ysize_border = 0 + * if yoff+win_ysize < raster_y_size-1: # <<<<<<<<<<<<<< + * win_ysize_border += 1 + * else: + */ + goto __pyx_L15; + } + + /* "pygeoprocessing/routing/routing.pyx":4286 + * win_ysize_border += 1 + * else: + * flow_dir_block[-1, :] = flow_dir_nodata # <<<<<<<<<<<<<< + * + * # Read iterblock plus a possible margin on top/bottom/left/right side + */ + /*else*/ { + __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_flow_dir_nodata); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4286, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_block), __pyx_tuple__23, __pyx_t_7) < 0)) __PYX_ERR(0, 4286, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __pyx_L15:; + + /* "pygeoprocessing/routing/routing.pyx":4293 + * 1-y_off_border:win_ysize+1+win_ysize_border, + * 1-x_off_border:win_xsize+1+win_xsize_border] = \ + * flow_dir_band.ReadAsArray( # <<<<<<<<<<<<<< + * xoff=xoff-x_off_border, + * yoff=yoff-y_off_border, + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4293, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + + /* "pygeoprocessing/routing/routing.pyx":4294 + * 1-x_off_border:win_xsize+1+win_xsize_border] = \ + * flow_dir_band.ReadAsArray( + * xoff=xoff-x_off_border, # <<<<<<<<<<<<<< + * yoff=yoff-y_off_border, + * win_xsize=win_xsize+win_xsize_border+x_off_border, + */ + __pyx_t_11 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4294, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_3 = __Pyx_PyInt_From_int((__pyx_v_xoff - __pyx_v_x_off_border)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4294, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_xoff, __pyx_t_3) < 0) __PYX_ERR(0, 4294, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4295 + * flow_dir_band.ReadAsArray( + * xoff=xoff-x_off_border, + * yoff=yoff-y_off_border, # <<<<<<<<<<<<<< + * win_xsize=win_xsize+win_xsize_border+x_off_border, + * win_ysize=win_ysize+win_ysize_border+y_off_border).astype( + */ + __pyx_t_3 = __Pyx_PyInt_From_int((__pyx_v_yoff - __pyx_v_y_off_border)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4295, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_yoff, __pyx_t_3) < 0) __PYX_ERR(0, 4294, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4296 + * xoff=xoff-x_off_border, + * yoff=yoff-y_off_border, + * win_xsize=win_xsize+win_xsize_border+x_off_border, # <<<<<<<<<<<<<< + * win_ysize=win_ysize+win_ysize_border+y_off_border).astype( + * numpy.int32) + */ + __pyx_t_3 = __Pyx_PyInt_From_int(((__pyx_v_win_xsize + __pyx_v_win_xsize_border) + __pyx_v_x_off_border)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4296, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_win_xsize, __pyx_t_3) < 0) __PYX_ERR(0, 4294, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4297 + * yoff=yoff-y_off_border, + * win_xsize=win_xsize+win_xsize_border+x_off_border, + * win_ysize=win_ysize+win_ysize_border+y_off_border).astype( # <<<<<<<<<<<<<< + * numpy.int32) + * + */ + __pyx_t_3 = __Pyx_PyInt_From_int(((__pyx_v_win_ysize + __pyx_v_win_ysize_border) + __pyx_v_y_off_border)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4297, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_win_ysize, __pyx_t_3) < 0) __PYX_ERR(0, 4294, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4293 + * 1-y_off_border:win_ysize+1+win_ysize_border, + * 1-x_off_border:win_xsize+1+win_xsize_border] = \ + * flow_dir_band.ReadAsArray( # <<<<<<<<<<<<<< + * xoff=xoff-x_off_border, + * yoff=yoff-y_off_border, + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4293, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4297 + * yoff=yoff-y_off_border, + * win_xsize=win_xsize+win_xsize_border+x_off_border, + * win_ysize=win_ysize+win_ysize_border+y_off_border).astype( # <<<<<<<<<<<<<< + * numpy.int32) + * + */ + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_astype); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4297, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4298 + * win_xsize=win_xsize+win_xsize_border+x_off_border, + * win_ysize=win_ysize+win_ysize_border+y_off_border).astype( + * numpy.int32) # <<<<<<<<<<<<<< + * + * for yi in range(1, win_ysize+1): + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4298, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4298, __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_11))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + } + } + __pyx_t_7 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4297, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4291 + * # and read as type int32 to handle both d8 or mfd formats + * flow_dir_block[ + * 1-y_off_border:win_ysize+1+win_ysize_border, # <<<<<<<<<<<<<< + * 1-x_off_border:win_xsize+1+win_xsize_border] = \ + * flow_dir_band.ReadAsArray( + */ + __pyx_t_11 = __Pyx_PyInt_From_long((1 - __pyx_v_y_off_border)); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4291, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_2 = __Pyx_PyInt_From_long(((__pyx_v_win_ysize + 1) + __pyx_v_win_ysize_border)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4291, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + + /* "pygeoprocessing/routing/routing.pyx":4290 + * # Read iterblock plus a possible margin on top/bottom/left/right side + * # and read as type int32 to handle both d8 or mfd formats + * flow_dir_block[ # <<<<<<<<<<<<<< + * 1-y_off_border:win_ysize+1+win_ysize_border, + * 1-x_off_border:win_xsize+1+win_xsize_border] = \ + */ + __pyx_t_3 = PySlice_New(__pyx_t_11, __pyx_t_2, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4290, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4292 + * flow_dir_block[ + * 1-y_off_border:win_ysize+1+win_ysize_border, + * 1-x_off_border:win_xsize+1+win_xsize_border] = \ # <<<<<<<<<<<<<< + * flow_dir_band.ReadAsArray( + * xoff=xoff-x_off_border, + */ + __pyx_t_2 = __Pyx_PyInt_From_long((1 - __pyx_v_x_off_border)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4292, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_11 = __Pyx_PyInt_From_long(((__pyx_v_win_xsize + 1) + __pyx_v_win_xsize_border)); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4292, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + + /* "pygeoprocessing/routing/routing.pyx":4290 + * # Read iterblock plus a possible margin on top/bottom/left/right side + * # and read as type int32 to handle both d8 or mfd formats + * flow_dir_block[ # <<<<<<<<<<<<<< + * 1-y_off_border:win_ysize+1+win_ysize_border, + * 1-x_off_border:win_xsize+1+win_xsize_border] = \ + */ + __pyx_t_1 = PySlice_New(__pyx_t_2, __pyx_t_11, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4290, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4290, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_1); + __pyx_t_3 = 0; + __pyx_t_1 = 0; + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_block), __pyx_t_11, __pyx_t_7) < 0)) __PYX_ERR(0, 4290, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4300 + * numpy.int32) + * + * for yi in range(1, win_ysize+1): # <<<<<<<<<<<<<< + * if ctime(NULL) - last_log_time > 5.0: + * last_log_time = ctime(NULL) + */ + __pyx_t_20 = (__pyx_v_win_ysize + 1); + __pyx_t_21 = __pyx_t_20; + for (__pyx_t_9 = 1; __pyx_t_9 < __pyx_t_21; __pyx_t_9+=1) { + __pyx_v_yi = __pyx_t_9; + + /* "pygeoprocessing/routing/routing.pyx":4301 + * + * for yi in range(1, win_ysize+1): + * 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":4302 + * for yi in range(1, win_ysize+1): + * if ctime(NULL) - last_log_time > 5.0: + * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info( + */ + __pyx_v_last_log_time = time(NULL); + + /* "pygeoprocessing/routing/routing.pyx":4303 + * if ctime(NULL) - last_log_time > 5.0: + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size # <<<<<<<<<<<<<< + * LOGGER.info( + * f'''outlet detection: { + */ + __pyx_t_7 = __Pyx_PyInt_From_int((__pyx_v_xoff + (__pyx_v_yoff * __pyx_v_raster_x_size))); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4303, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_XDECREF_SET(__pyx_v_current_pixel, __pyx_t_7); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4304 + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info( # <<<<<<<<<<<<<< + * f'''outlet detection: { + * 100.0 * current_pixel / ( + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4304, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4304, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4305 + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info( + * f'''outlet detection: { # <<<<<<<<<<<<<< + * 100.0 * current_pixel / ( + * raster_x_size * raster_y_size):.1f} complete''') + */ + __pyx_t_11 = PyTuple_New(3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4305, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_22 = 0; + __pyx_t_13 = 127; + __Pyx_INCREF(__pyx_kp_u_outlet_detection); + __pyx_t_22 += 18; + __Pyx_GIVEREF(__pyx_kp_u_outlet_detection); + PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_kp_u_outlet_detection); + + /* "pygeoprocessing/routing/routing.pyx":4306 + * LOGGER.info( + * f'''outlet detection: { + * 100.0 * current_pixel / ( # <<<<<<<<<<<<<< + * raster_x_size * raster_y_size):.1f} complete''') + * for xi in range(1, win_xsize+1): + */ + __pyx_t_3 = PyNumber_Multiply(__pyx_float_100_0, __pyx_v_current_pixel); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4306, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + + /* "pygeoprocessing/routing/routing.pyx":4307 + * f'''outlet detection: { + * 100.0 * current_pixel / ( + * raster_x_size * raster_y_size):.1f} complete''') # <<<<<<<<<<<<<< + * for xi in range(1, win_xsize+1): + * flow_dir = flow_dir_block[yi, xi] + */ + __pyx_t_2 = PyFloat_FromDouble(((float)(__pyx_v_raster_x_size * __pyx_v_raster_y_size))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4306, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + + /* "pygeoprocessing/routing/routing.pyx":4306 + * LOGGER.info( + * f'''outlet detection: { + * 100.0 * current_pixel / ( # <<<<<<<<<<<<<< + * raster_x_size * raster_y_size):.1f} complete''') + * for xi in range(1, win_xsize+1): + */ + __pyx_t_14 = __Pyx_PyNumber_Divide(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4306, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4305 + * current_pixel = xoff + yoff * raster_x_size + * LOGGER.info( + * f'''outlet detection: { # <<<<<<<<<<<<<< + * 100.0 * current_pixel / ( + * raster_x_size * raster_y_size):.1f} complete''') + */ + __pyx_t_2 = __Pyx_PyObject_Format(__pyx_t_14, __pyx_kp_u_1f); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4305, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_13 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) > __pyx_t_13) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) : __pyx_t_13; + __pyx_t_22 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_2); + __pyx_t_2 = 0; + __Pyx_INCREF(__pyx_kp_u_complete_2); + __pyx_t_22 += 9; + __Pyx_GIVEREF(__pyx_kp_u_complete_2); + PyTuple_SET_ITEM(__pyx_t_11, 2, __pyx_kp_u_complete_2); + __pyx_t_2 = __Pyx_PyUnicode_Join(__pyx_t_11, 3, __pyx_t_22, __pyx_t_13); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4305, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_7 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_11, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4304, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4301 + * + * for yi in range(1, win_ysize+1): + * if ctime(NULL) - last_log_time > 5.0: # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * current_pixel = xoff + yoff * raster_x_size + */ + } + + /* "pygeoprocessing/routing/routing.pyx":4308 + * 100.0 * current_pixel / ( + * raster_x_size * raster_y_size):.1f} complete''') + * for xi in range(1, win_xsize+1): # <<<<<<<<<<<<<< + * flow_dir = flow_dir_block[yi, xi] + * if flow_dir == flow_dir_nodata: + */ + __pyx_t_23 = (__pyx_v_win_xsize + 1); + __pyx_t_24 = __pyx_t_23; + for (__pyx_t_6 = 1; __pyx_t_6 < __pyx_t_24; __pyx_t_6+=1) { + __pyx_v_xi = __pyx_t_6; + + /* "pygeoprocessing/routing/routing.pyx":4309 + * raster_x_size * raster_y_size):.1f} complete''') + * for xi in range(1, win_xsize+1): + * flow_dir = flow_dir_block[yi, xi] # <<<<<<<<<<<<<< + * if flow_dir == flow_dir_nodata: + * continue + */ + __pyx_t_25 = __pyx_v_yi; + __pyx_t_26 = __pyx_v_xi; + __pyx_t_27 = -1; + if (__pyx_t_25 < 0) { + __pyx_t_25 += __pyx_pybuffernd_flow_dir_block.diminfo[0].shape; + if (unlikely(__pyx_t_25 < 0)) __pyx_t_27 = 0; + } else if (unlikely(__pyx_t_25 >= __pyx_pybuffernd_flow_dir_block.diminfo[0].shape)) __pyx_t_27 = 0; + if (__pyx_t_26 < 0) { + __pyx_t_26 += __pyx_pybuffernd_flow_dir_block.diminfo[1].shape; + if (unlikely(__pyx_t_26 < 0)) __pyx_t_27 = 1; + } else if (unlikely(__pyx_t_26 >= __pyx_pybuffernd_flow_dir_block.diminfo[1].shape)) __pyx_t_27 = 1; + if (unlikely(__pyx_t_27 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_27); + __PYX_ERR(0, 4309, __pyx_L1_error) + } + __pyx_v_flow_dir = (*__Pyx_BufPtrStrided2d(npy_int32 *, __pyx_pybuffernd_flow_dir_block.rcbuffer->pybuffer.buf, __pyx_t_25, __pyx_pybuffernd_flow_dir_block.diminfo[0].strides, __pyx_t_26, __pyx_pybuffernd_flow_dir_block.diminfo[1].strides)); + + /* "pygeoprocessing/routing/routing.pyx":4310 + * for xi in range(1, win_xsize+1): + * flow_dir = flow_dir_block[yi, xi] + * if flow_dir == flow_dir_nodata: # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_5 = ((__pyx_v_flow_dir == __pyx_v_flow_dir_nodata) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":4311 + * flow_dir = flow_dir_block[yi, xi] + * if flow_dir == flow_dir_nodata: + * continue # <<<<<<<<<<<<<< + * + * is_outlet = 1 + */ + goto __pyx_L19_continue; + + /* "pygeoprocessing/routing/routing.pyx":4310 + * for xi in range(1, win_xsize+1): + * flow_dir = flow_dir_block[yi, xi] + * if flow_dir == flow_dir_nodata: # <<<<<<<<<<<<<< + * continue + * + */ + } + + /* "pygeoprocessing/routing/routing.pyx":4313 + * continue + * + * is_outlet = 1 # <<<<<<<<<<<<<< + * if d8_flow_dir_mode: + * # inspect the outflow pixel neighbor + */ + __pyx_v_is_outlet = 1; + + /* "pygeoprocessing/routing/routing.pyx":4314 + * + * is_outlet = 1 + * if d8_flow_dir_mode: # <<<<<<<<<<<<<< + * # inspect the outflow pixel neighbor + * flow_dir_n = flow_dir_block[ + */ + __pyx_t_5 = (__pyx_v_d8_flow_dir_mode != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":4316 + * if d8_flow_dir_mode: + * # inspect the outflow pixel neighbor + * flow_dir_n = flow_dir_block[ # <<<<<<<<<<<<<< + * yi+D8_YOFFSET[flow_dir], + * xi+D8_XOFFSET[flow_dir]] + */ + __pyx_t_26 = (__pyx_v_yi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_flow_dir])); + __pyx_t_25 = (__pyx_v_xi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_flow_dir])); + __pyx_t_27 = -1; + if (__pyx_t_26 < 0) { + __pyx_t_26 += __pyx_pybuffernd_flow_dir_block.diminfo[0].shape; + if (unlikely(__pyx_t_26 < 0)) __pyx_t_27 = 0; + } else if (unlikely(__pyx_t_26 >= __pyx_pybuffernd_flow_dir_block.diminfo[0].shape)) __pyx_t_27 = 0; + if (__pyx_t_25 < 0) { + __pyx_t_25 += __pyx_pybuffernd_flow_dir_block.diminfo[1].shape; + if (unlikely(__pyx_t_25 < 0)) __pyx_t_27 = 1; + } else if (unlikely(__pyx_t_25 >= __pyx_pybuffernd_flow_dir_block.diminfo[1].shape)) __pyx_t_27 = 1; + if (unlikely(__pyx_t_27 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_27); + __PYX_ERR(0, 4316, __pyx_L1_error) + } + __pyx_v_flow_dir_n = (*__Pyx_BufPtrStrided2d(npy_int32 *, __pyx_pybuffernd_flow_dir_block.rcbuffer->pybuffer.buf, __pyx_t_26, __pyx_pybuffernd_flow_dir_block.diminfo[0].strides, __pyx_t_25, __pyx_pybuffernd_flow_dir_block.diminfo[1].strides)); + + /* "pygeoprocessing/routing/routing.pyx":4322 + * # if the outflow pixel is outside the raster boundaries or + * # is a nodata pixel it must mean xi,yi is an outlet + * if flow_dir_n != flow_dir_nodata: # <<<<<<<<<<<<<< + * is_outlet = 0 + * else: + */ + __pyx_t_5 = ((__pyx_v_flow_dir_n != __pyx_v_flow_dir_nodata) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":4323 + * # is a nodata pixel it must mean xi,yi is an outlet + * if flow_dir_n != flow_dir_nodata: + * is_outlet = 0 # <<<<<<<<<<<<<< + * else: + * # inspect all the outflow pixel neighbors in MFD mode + */ + __pyx_v_is_outlet = 0; + + /* "pygeoprocessing/routing/routing.pyx":4322 + * # if the outflow pixel is outside the raster boundaries or + * # is a nodata pixel it must mean xi,yi is an outlet + * if flow_dir_n != flow_dir_nodata: # <<<<<<<<<<<<<< + * is_outlet = 0 + * else: + */ + } + + /* "pygeoprocessing/routing/routing.pyx":4314 + * + * is_outlet = 1 + * if d8_flow_dir_mode: # <<<<<<<<<<<<<< + * # inspect the outflow pixel neighbor + * flow_dir_n = flow_dir_block[ + */ + goto __pyx_L22; + } + + /* "pygeoprocessing/routing/routing.pyx":4326 + * else: + * # inspect all the outflow pixel neighbors in MFD mode + * for n_dir in range(8): # <<<<<<<<<<<<<< + * # shift the 0xF mask to the outflow direction and + * # test if there's any outflow or not. 0 means nothing + */ + /*else*/ { + for (__pyx_t_27 = 0; __pyx_t_27 < 8; __pyx_t_27+=1) { + __pyx_v_n_dir = __pyx_t_27; + + /* "pygeoprocessing/routing/routing.pyx":4338 + * # if it equals 0 it means there was no proportional + * # flow in the `n_dir` direction. + * if flow_dir&(0xF<<(n_dir*4)) == 0: # <<<<<<<<<<<<<< + * continue + * flow_dir_n = flow_dir_block[ + */ + __pyx_t_5 = (((__pyx_v_flow_dir & (0xF << (__pyx_v_n_dir * 4))) == 0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":4339 + * # flow in the `n_dir` direction. + * if flow_dir&(0xF<<(n_dir*4)) == 0: + * continue # <<<<<<<<<<<<<< + * flow_dir_n = flow_dir_block[ + * yi+D8_YOFFSET[n_dir], + */ + goto __pyx_L24_continue; + + /* "pygeoprocessing/routing/routing.pyx":4338 + * # if it equals 0 it means there was no proportional + * # flow in the `n_dir` direction. + * if flow_dir&(0xF<<(n_dir*4)) == 0: # <<<<<<<<<<<<<< + * continue + * flow_dir_n = flow_dir_block[ + */ + } + + /* "pygeoprocessing/routing/routing.pyx":4340 + * if flow_dir&(0xF<<(n_dir*4)) == 0: + * continue + * flow_dir_n = flow_dir_block[ # <<<<<<<<<<<<<< + * yi+D8_YOFFSET[n_dir], + * xi+D8_XOFFSET[n_dir]] + */ + __pyx_t_25 = (__pyx_v_yi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_n_dir])); + __pyx_t_26 = (__pyx_v_xi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_n_dir])); + __pyx_t_28 = -1; + if (__pyx_t_25 < 0) { + __pyx_t_25 += __pyx_pybuffernd_flow_dir_block.diminfo[0].shape; + if (unlikely(__pyx_t_25 < 0)) __pyx_t_28 = 0; + } else if (unlikely(__pyx_t_25 >= __pyx_pybuffernd_flow_dir_block.diminfo[0].shape)) __pyx_t_28 = 0; + if (__pyx_t_26 < 0) { + __pyx_t_26 += __pyx_pybuffernd_flow_dir_block.diminfo[1].shape; + if (unlikely(__pyx_t_26 < 0)) __pyx_t_28 = 1; + } else if (unlikely(__pyx_t_26 >= __pyx_pybuffernd_flow_dir_block.diminfo[1].shape)) __pyx_t_28 = 1; + if (unlikely(__pyx_t_28 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_28); + __PYX_ERR(0, 4340, __pyx_L1_error) + } + __pyx_v_flow_dir_n = (*__Pyx_BufPtrStrided2d(npy_int32 *, __pyx_pybuffernd_flow_dir_block.rcbuffer->pybuffer.buf, __pyx_t_25, __pyx_pybuffernd_flow_dir_block.diminfo[0].strides, __pyx_t_26, __pyx_pybuffernd_flow_dir_block.diminfo[1].strides)); + + /* "pygeoprocessing/routing/routing.pyx":4343 + * yi+D8_YOFFSET[n_dir], + * xi+D8_XOFFSET[n_dir]] + * if flow_dir_n != flow_dir_nodata: # <<<<<<<<<<<<<< + * is_outlet = 0 + * break + */ + __pyx_t_5 = ((__pyx_v_flow_dir_n != __pyx_v_flow_dir_nodata) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":4344 + * xi+D8_XOFFSET[n_dir]] + * if flow_dir_n != flow_dir_nodata: + * is_outlet = 0 # <<<<<<<<<<<<<< + * break + * + */ + __pyx_v_is_outlet = 0; + + /* "pygeoprocessing/routing/routing.pyx":4345 + * if flow_dir_n != flow_dir_nodata: + * is_outlet = 0 + * break # <<<<<<<<<<<<<< + * + * # if the outflow pixel is outside the raster boundaries or + */ + goto __pyx_L25_break; + + /* "pygeoprocessing/routing/routing.pyx":4343 + * yi+D8_YOFFSET[n_dir], + * xi+D8_XOFFSET[n_dir]] + * if flow_dir_n != flow_dir_nodata: # <<<<<<<<<<<<<< + * is_outlet = 0 + * break + */ + } + __pyx_L24_continue:; + } + __pyx_L25_break:; + } + __pyx_L22:; + + /* "pygeoprocessing/routing/routing.pyx":4349 + * # if the outflow pixel is outside the raster boundaries or + * # is a nodata pixel it must mean xi,yi is an outlet + * if is_outlet: # <<<<<<<<<<<<<< + * outlet_point = ogr.Geometry(ogr.wkbPoint) + * # calculate global x/y raster coordinate, the -1 is for + */ + __pyx_t_5 = (__pyx_v_is_outlet != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":4350 + * # is a nodata pixel it must mean xi,yi is an outlet + * if is_outlet: + * outlet_point = ogr.Geometry(ogr.wkbPoint) # <<<<<<<<<<<<<< + * # calculate global x/y raster coordinate, the -1 is for + * # the left/top border of the test array window + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4350, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_Geometry); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4350, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4350, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_wkbPoint); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4350, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_7 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_1, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_11); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4350, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF_SET(__pyx_v_outlet_point, __pyx_t_7); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4353 + * # calculate global x/y raster coordinate, the -1 is for + * # the left/top border of the test array window + * xi_root = xi+xoff-1 # <<<<<<<<<<<<<< + * yi_root = yi+yoff-1 + * # created a projected point in the center of the pixel + */ + __pyx_v_xi_root = ((__pyx_v_xi + __pyx_v_xoff) - 1); + + /* "pygeoprocessing/routing/routing.pyx":4354 + * # the left/top border of the test array window + * xi_root = xi+xoff-1 + * yi_root = yi+yoff-1 # <<<<<<<<<<<<<< + * # created a projected point in the center of the pixel + * # thus the + 0.5 to x and y + */ + __pyx_v_yi_root = ((__pyx_v_yi + __pyx_v_yoff) - 1); + + /* "pygeoprocessing/routing/routing.pyx":4357 + * # created a projected point in the center of the pixel + * # thus the + 0.5 to x and y + * proj_x, proj_y = gdal.ApplyGeoTransform( # <<<<<<<<<<<<<< + * raster_info['geotransform'], + * xi_root+0.5, yi_root+0.5) + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4357, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_ApplyGeoTransform); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4357, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4358 + * # thus the + 0.5 to x and y + * proj_x, proj_y = gdal.ApplyGeoTransform( + * raster_info['geotransform'], # <<<<<<<<<<<<<< + * xi_root+0.5, yi_root+0.5) + * outlet_point.AddPoint(proj_x, proj_y) + */ + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_geotransform); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4358, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + + /* "pygeoprocessing/routing/routing.pyx":4359 + * proj_x, proj_y = gdal.ApplyGeoTransform( + * raster_info['geotransform'], + * xi_root+0.5, yi_root+0.5) # <<<<<<<<<<<<<< + * outlet_point.AddPoint(proj_x, proj_y) + * outlet_feature = ogr.Feature(outlet_layer.GetLayerDefn()) + */ + __pyx_t_1 = PyFloat_FromDouble((__pyx_v_xi_root + 0.5)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4359, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_14 = PyFloat_FromDouble((__pyx_v_yi_root + 0.5)); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4359, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_3 = NULL; + __pyx_t_27 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + __pyx_t_27 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_t_2, __pyx_t_1, __pyx_t_14}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_27, 3+__pyx_t_27); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4357, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_t_2, __pyx_t_1, __pyx_t_14}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_27, 3+__pyx_t_27); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4357, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } else + #endif + { + __pyx_t_29 = PyTuple_New(3+__pyx_t_27); if (unlikely(!__pyx_t_29)) __PYX_ERR(0, 4357, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_29); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_29, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_29, 0+__pyx_t_27, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_29, 1+__pyx_t_27, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_29, 2+__pyx_t_27, __pyx_t_14); + __pyx_t_2 = 0; + __pyx_t_1 = 0; + __pyx_t_14 = 0; + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_29, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4357, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_29); __pyx_t_29 = 0; + } + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) { + PyObject* sequence = __pyx_t_7; + 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, 4357, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_11 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_29 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_11 = PyList_GET_ITEM(sequence, 0); + __pyx_t_29 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(__pyx_t_29); + #else + __pyx_t_11 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4357, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_29 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_29)) __PYX_ERR(0, 4357, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_29); + #endif + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_14 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4357, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_14)->tp_iternext; + index = 0; __pyx_t_11 = __pyx_t_8(__pyx_t_14); if (unlikely(!__pyx_t_11)) goto __pyx_L29_unpacking_failed; + __Pyx_GOTREF(__pyx_t_11); + index = 1; __pyx_t_29 = __pyx_t_8(__pyx_t_14); if (unlikely(!__pyx_t_29)) goto __pyx_L29_unpacking_failed; + __Pyx_GOTREF(__pyx_t_29); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_14), 2) < 0) __PYX_ERR(0, 4357, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + goto __pyx_L30_unpacking_done; + __pyx_L29_unpacking_failed:; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 4357, __pyx_L1_error) + __pyx_L30_unpacking_done:; + } + + /* "pygeoprocessing/routing/routing.pyx":4357 + * # created a projected point in the center of the pixel + * # thus the + 0.5 to x and y + * proj_x, proj_y = gdal.ApplyGeoTransform( # <<<<<<<<<<<<<< + * raster_info['geotransform'], + * xi_root+0.5, yi_root+0.5) + */ + __Pyx_XDECREF_SET(__pyx_v_proj_x, __pyx_t_11); + __pyx_t_11 = 0; + __Pyx_XDECREF_SET(__pyx_v_proj_y, __pyx_t_29); + __pyx_t_29 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4360 + * raster_info['geotransform'], + * xi_root+0.5, yi_root+0.5) + * outlet_point.AddPoint(proj_x, proj_y) # <<<<<<<<<<<<<< + * outlet_feature = ogr.Feature(outlet_layer.GetLayerDefn()) + * outlet_feature.SetGeometry(outlet_point) + */ + __pyx_t_29 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_point, __pyx_n_s_AddPoint); if (unlikely(!__pyx_t_29)) __PYX_ERR(0, 4360, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_29); + __pyx_t_11 = NULL; + __pyx_t_27 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_29))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_29); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_29); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_29, function); + __pyx_t_27 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_29)) { + PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_proj_x, __pyx_v_proj_y}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_29, __pyx_temp+1-__pyx_t_27, 2+__pyx_t_27); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4360, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_29)) { + PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_proj_x, __pyx_v_proj_y}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_29, __pyx_temp+1-__pyx_t_27, 2+__pyx_t_27); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4360, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + { + __pyx_t_14 = PyTuple_New(2+__pyx_t_27); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4360, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + if (__pyx_t_11) { + __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_11); __pyx_t_11 = NULL; + } + __Pyx_INCREF(__pyx_v_proj_x); + __Pyx_GIVEREF(__pyx_v_proj_x); + PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_27, __pyx_v_proj_x); + __Pyx_INCREF(__pyx_v_proj_y); + __Pyx_GIVEREF(__pyx_v_proj_y); + PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_27, __pyx_v_proj_y); + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_29, __pyx_t_14, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4360, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } + __Pyx_DECREF(__pyx_t_29); __pyx_t_29 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4361 + * xi_root+0.5, yi_root+0.5) + * outlet_point.AddPoint(proj_x, proj_y) + * outlet_feature = ogr.Feature(outlet_layer.GetLayerDefn()) # <<<<<<<<<<<<<< + * outlet_feature.SetGeometry(outlet_point) + * # save the raster coordinates of the outlet pixel as i,j + */ + __Pyx_GetModuleGlobalName(__pyx_t_29, __pyx_n_s_ogr); if (unlikely(!__pyx_t_29)) __PYX_ERR(0, 4361, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_29); + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_29, __pyx_n_s_Feature); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4361, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_29); __pyx_t_29 = 0; + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_layer, __pyx_n_s_GetLayerDefn); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4361, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + } + } + __pyx_t_29 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_29)) __PYX_ERR(0, 4361, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_29); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + } + } + __pyx_t_7 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_11, __pyx_t_29) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_t_29); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_29); __pyx_t_29 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4361, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF_SET(__pyx_v_outlet_feature, __pyx_t_7); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4362 + * outlet_point.AddPoint(proj_x, proj_y) + * outlet_feature = ogr.Feature(outlet_layer.GetLayerDefn()) + * outlet_feature.SetGeometry(outlet_point) # <<<<<<<<<<<<<< + * # save the raster coordinates of the outlet pixel as i,j + * outlet_feature.SetField('i', xi_root) + */ + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_feature, __pyx_n_s_SetGeometry); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4362, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_29 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_29 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_29)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_29); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + } + } + __pyx_t_7 = (__pyx_t_29) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_29, __pyx_v_outlet_point) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_v_outlet_point); + __Pyx_XDECREF(__pyx_t_29); __pyx_t_29 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4362, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4364 + * outlet_feature.SetGeometry(outlet_point) + * # save the raster coordinates of the outlet pixel as i,j + * outlet_feature.SetField('i', xi_root) # <<<<<<<<<<<<<< + * outlet_feature.SetField('j', yi_root) + * outlet_feature.SetField('ID', next_id) + */ + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4364, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_29 = __Pyx_PyInt_From_int(__pyx_v_xi_root); if (unlikely(!__pyx_t_29)) __PYX_ERR(0, 4364, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_29); + __pyx_t_11 = NULL; + __pyx_t_27 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + __pyx_t_27 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_n_u_i, __pyx_t_29}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_27, 2+__pyx_t_27); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4364, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_29); __pyx_t_29 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_n_u_i, __pyx_t_29}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_27, 2+__pyx_t_27); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4364, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_29); __pyx_t_29 = 0; + } else + #endif + { + __pyx_t_1 = PyTuple_New(2+__pyx_t_27); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4364, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (__pyx_t_11) { + __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_11); __pyx_t_11 = NULL; + } + __Pyx_INCREF(__pyx_n_u_i); + __Pyx_GIVEREF(__pyx_n_u_i); + PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_27, __pyx_n_u_i); + __Pyx_GIVEREF(__pyx_t_29); + PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_27, __pyx_t_29); + __pyx_t_29 = 0; + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_1, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4364, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4365 + * # save the raster coordinates of the outlet pixel as i,j + * outlet_feature.SetField('i', xi_root) + * outlet_feature.SetField('j', yi_root) # <<<<<<<<<<<<<< + * outlet_feature.SetField('ID', next_id) + * next_id += 1 + */ + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4365, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_yi_root); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4365, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_29 = NULL; + __pyx_t_27 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_29 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_29)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_29); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + __pyx_t_27 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_29, __pyx_n_u_j, __pyx_t_1}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_27, 2+__pyx_t_27); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4365, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_29); __pyx_t_29 = 0; + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_29, __pyx_n_u_j, __pyx_t_1}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_27, 2+__pyx_t_27); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4365, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_29); __pyx_t_29 = 0; + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + { + __pyx_t_11 = PyTuple_New(2+__pyx_t_27); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4365, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + if (__pyx_t_29) { + __Pyx_GIVEREF(__pyx_t_29); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_29); __pyx_t_29 = NULL; + } + __Pyx_INCREF(__pyx_n_u_j); + __Pyx_GIVEREF(__pyx_n_u_j); + PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_27, __pyx_n_u_j); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_27, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_11, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4365, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4366 + * outlet_feature.SetField('i', xi_root) + * outlet_feature.SetField('j', yi_root) + * outlet_feature.SetField('ID', next_id) # <<<<<<<<<<<<<< + * next_id += 1 + * outlet_layer.CreateFeature(outlet_feature) + */ + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4366, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_11 = __Pyx_PyInt_From_int(__pyx_v_next_id); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4366, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_1 = NULL; + __pyx_t_27 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + __pyx_t_27 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_n_u_ID, __pyx_t_11}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_27, 2+__pyx_t_27); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4366, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_n_u_ID, __pyx_t_11}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_27, 2+__pyx_t_27); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4366, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } else + #endif + { + __pyx_t_29 = PyTuple_New(2+__pyx_t_27); if (unlikely(!__pyx_t_29)) __PYX_ERR(0, 4366, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_29); + if (__pyx_t_1) { + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_29, 0, __pyx_t_1); __pyx_t_1 = NULL; + } + __Pyx_INCREF(__pyx_n_u_ID); + __Pyx_GIVEREF(__pyx_n_u_ID); + PyTuple_SET_ITEM(__pyx_t_29, 0+__pyx_t_27, __pyx_n_u_ID); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_29, 1+__pyx_t_27, __pyx_t_11); + __pyx_t_11 = 0; + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_29, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4366, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_29); __pyx_t_29 = 0; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4367 + * outlet_feature.SetField('j', yi_root) + * outlet_feature.SetField('ID', next_id) + * next_id += 1 # <<<<<<<<<<<<<< + * outlet_layer.CreateFeature(outlet_feature) + * outlet_feature = None + */ + __pyx_v_next_id = (__pyx_v_next_id + 1); + + /* "pygeoprocessing/routing/routing.pyx":4368 + * outlet_feature.SetField('ID', next_id) + * next_id += 1 + * outlet_layer.CreateFeature(outlet_feature) # <<<<<<<<<<<<<< + * outlet_feature = None + * outlet_point = None + */ + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_layer, __pyx_n_s_CreateFeature); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4368, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_29 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_29 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_29)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_29); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + } + } + __pyx_t_7 = (__pyx_t_29) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_29, __pyx_v_outlet_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_v_outlet_feature); + __Pyx_XDECREF(__pyx_t_29); __pyx_t_29 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4368, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4369 + * next_id += 1 + * outlet_layer.CreateFeature(outlet_feature) + * outlet_feature = None # <<<<<<<<<<<<<< + * outlet_point = None + * + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_outlet_feature, Py_None); + + /* "pygeoprocessing/routing/routing.pyx":4370 + * outlet_layer.CreateFeature(outlet_feature) + * outlet_feature = None + * outlet_point = None # <<<<<<<<<<<<<< + * + * flow_dir_raster = None + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_outlet_point, Py_None); + + /* "pygeoprocessing/routing/routing.pyx":4349 + * # if the outflow pixel is outside the raster boundaries or + * # is a nodata pixel it must mean xi,yi is an outlet + * if is_outlet: # <<<<<<<<<<<<<< + * outlet_point = ogr.Geometry(ogr.wkbPoint) + * # calculate global x/y raster coordinate, the -1 is for + */ + } + __pyx_L19_continue:; + } + } + + /* "pygeoprocessing/routing/routing.pyx":4247 + * # and writes + * LOGGER.info('outlet detection: 0% complete') + * for block_offsets in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * flow_dir_raster_path_band, offset_only=True): + * xoff = block_offsets['xoff'] + */ + } + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4372 + * outlet_point = None + * + * flow_dir_raster = None # <<<<<<<<<<<<<< + * flow_dir_band = None + * LOGGER.info('outlet detection: 100% complete -- committing transaction') + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_flow_dir_raster, Py_None); + + /* "pygeoprocessing/routing/routing.pyx":4373 + * + * flow_dir_raster = None + * flow_dir_band = None # <<<<<<<<<<<<<< + * LOGGER.info('outlet detection: 100% complete -- committing transaction') + * outlet_layer.CommitTransaction() + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_flow_dir_band, Py_None); + + /* "pygeoprocessing/routing/routing.pyx":4374 + * flow_dir_raster = None + * flow_dir_band = None + * LOGGER.info('outlet detection: 100% complete -- committing transaction') # <<<<<<<<<<<<<< + * outlet_layer.CommitTransaction() + * outlet_layer = None + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4374, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_info); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4374, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + } + } + __pyx_t_10 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_7, __pyx_kp_u_outlet_detection_100_complete_co) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_kp_u_outlet_detection_100_complete_co); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4374, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4375 + * flow_dir_band = None + * LOGGER.info('outlet detection: 100% complete -- committing transaction') + * outlet_layer.CommitTransaction() # <<<<<<<<<<<<<< + * outlet_layer = None + * outlet_vector = None + */ + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_layer, __pyx_n_s_CommitTransaction); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4375, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + } + } + __pyx_t_10 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_14); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4375, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4376 + * LOGGER.info('outlet detection: 100% complete -- committing transaction') + * outlet_layer.CommitTransaction() + * outlet_layer = None # <<<<<<<<<<<<<< + * outlet_vector = None + * LOGGER.info('outlet detection: done') + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_outlet_layer, Py_None); + + /* "pygeoprocessing/routing/routing.pyx":4377 + * outlet_layer.CommitTransaction() + * outlet_layer = None + * outlet_vector = None # <<<<<<<<<<<<<< + * LOGGER.info('outlet detection: done') + * + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_outlet_vector, Py_None); + + /* "pygeoprocessing/routing/routing.pyx":4378 + * outlet_layer = None + * outlet_vector = None + * LOGGER.info('outlet detection: done') # <<<<<<<<<<<<<< + * + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4378, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4378, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_14 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_14)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_10 = (__pyx_t_14) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_14, __pyx_kp_u_outlet_detection_done) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_kp_u_outlet_detection_done); + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4378, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4162 + * + * + * def detect_outlets( # <<<<<<<<<<<<<< + * flow_dir_raster_path_band, flow_dir_type, target_outlet_vector_path): + * """Create point vector indicating flow raster outlets. + */ + + /* 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_7); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_14); + __Pyx_XDECREF(__pyx_t_29); + { 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_block.rcbuffer->pybuffer); + __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} + __Pyx_AddTraceback("pygeoprocessing.routing.routing.detect_outlets", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + goto __pyx_L2; + __pyx_L0:; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_flow_dir_block.rcbuffer->pybuffer); + __pyx_L2:; + __Pyx_XDECREF((PyObject *)__pyx_v_flow_dir_block); + __Pyx_XDECREF(__pyx_v_raster_info); + __Pyx_XDECREF(__pyx_v_flow_dir_raster); + __Pyx_XDECREF(__pyx_v_flow_dir_band); + __Pyx_XDECREF(__pyx_v_raster_srs); + __Pyx_XDECREF(__pyx_v_gpkg_driver); + __Pyx_XDECREF(__pyx_v_outlet_vector); + __Pyx_XDECREF(__pyx_v_outet_basename); + __Pyx_XDECREF(__pyx_v_outlet_layer); + __Pyx_XDECREF(__pyx_v_block_offsets); + __Pyx_XDECREF(__pyx_v_current_pixel); + __Pyx_XDECREF(__pyx_v_outlet_point); + __Pyx_XDECREF(__pyx_v_proj_x); + __Pyx_XDECREF(__pyx_v_proj_y); + __Pyx_XDECREF(__pyx_v_outlet_feature); + __Pyx_XDECREF(__pyx_v_flow_dir_type); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pygeoprocessing/routing/routing.pyx":4381 + * + * + * cdef void _diagonal_fill_step( # <<<<<<<<<<<<<< + * int x_l, int y_l, int edge_dir, + * long discovery, long finish, + */ + +static void __pyx_f_15pygeoprocessing_7routing_7routing__diagonal_fill_step(int __pyx_v_x_l, int __pyx_v_y_l, int __pyx_v_edge_dir, long __pyx_v_discovery, long __pyx_v_finish, struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_discovery_managed_raster, long __pyx_v_discovery_nodata, PyObject *__pyx_v_boundary_list) { + int __pyx_v_xdelta; + int __pyx_v_ydelta; + PyObject *__pyx_v_test_list = NULL; + PyObject *__pyx_v_x_t = NULL; + PyObject *__pyx_v_y_t = NULL; + long __pyx_v_point_discovery; + __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; + Py_ssize_t __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *(*__pyx_t_8)(PyObject *); + int __pyx_t_9; + int __pyx_t_10; + int __pyx_t_11; + int __pyx_t_12; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_diagonal_fill_step", 0); + + /* "pygeoprocessing/routing/routing.pyx":4419 + * """ + * # always add the current pixel + * boundary_list.append((x_l, y_l)) # <<<<<<<<<<<<<< + * + * # this section determines which back diagonal was in the watershed and + */ + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_x_l); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4419, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_y_l); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4419, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4419, __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_2); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_boundary_list, __pyx_t_3); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 4419, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4423 + * # this section determines which back diagonal was in the watershed and + * # fills it. if none are we pick one so there's no degenerate case + * cdef int xdelta = D8_XOFFSET[edge_dir] # <<<<<<<<<<<<<< + * cdef int ydelta = D8_YOFFSET[edge_dir] + * test_list = [ + */ + __pyx_v_xdelta = (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_edge_dir]); + + /* "pygeoprocessing/routing/routing.pyx":4424 + * # fills it. if none are we pick one so there's no degenerate case + * cdef int xdelta = D8_XOFFSET[edge_dir] + * cdef int ydelta = D8_YOFFSET[edge_dir] # <<<<<<<<<<<<<< + * test_list = [ + * (x_l - xdelta, y_l), + */ + __pyx_v_ydelta = (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_edge_dir]); + + /* "pygeoprocessing/routing/routing.pyx":4426 + * cdef int ydelta = D8_YOFFSET[edge_dir] + * test_list = [ + * (x_l - xdelta, y_l), # <<<<<<<<<<<<<< + * (x_l, y_l - ydelta)] + * for x_t, y_t in test_list: + */ + __pyx_t_3 = __Pyx_PyInt_From_int((__pyx_v_x_l - __pyx_v_xdelta)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4426, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_y_l); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4426, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4426, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2); + __pyx_t_3 = 0; + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4427 + * test_list = [ + * (x_l - xdelta, y_l), + * (x_l, y_l - ydelta)] # <<<<<<<<<<<<<< + * for x_t, y_t in test_list: + * point_discovery = discovery_managed_raster.get( + */ + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_x_l); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4427, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyInt_From_int((__pyx_v_y_l - __pyx_v_ydelta)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4427, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4427, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4425 + * cdef int xdelta = D8_XOFFSET[edge_dir] + * cdef int ydelta = D8_YOFFSET[edge_dir] + * test_list = [ # <<<<<<<<<<<<<< + * (x_l - xdelta, y_l), + * (x_l, y_l - ydelta)] + */ + __pyx_t_3 = PyList_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4425, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_1); + PyList_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_5); + PyList_SET_ITEM(__pyx_t_3, 1, __pyx_t_5); + __pyx_t_1 = 0; + __pyx_t_5 = 0; + __pyx_v_test_list = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4428 + * (x_l - xdelta, y_l), + * (x_l, y_l - ydelta)] + * for x_t, y_t in test_list: # <<<<<<<<<<<<<< + * point_discovery = discovery_managed_raster.get( + * x_t, y_t) + */ + __pyx_t_3 = __pyx_v_test_list; __Pyx_INCREF(__pyx_t_3); __pyx_t_6 = 0; + for (;;) { + if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 4428, __pyx_L1_error) + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4428, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + 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, 4428, __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, 4428, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4428, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_7 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4428, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_1)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 1; __pyx_t_2 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_2)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 4428, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L6_unpacking_done; + __pyx_L5_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 4428, __pyx_L1_error) + __pyx_L6_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_x_t, __pyx_t_1); + __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_y_t, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4430 + * for x_t, y_t in test_list: + * point_discovery = discovery_managed_raster.get( + * x_t, y_t) # <<<<<<<<<<<<<< + * if (point_discovery != discovery_nodata and + * point_discovery >= discovery and + */ + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_v_x_t); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4430, __pyx_L1_error) + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_v_y_t); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4430, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":4429 + * (x_l, y_l - ydelta)] + * for x_t, y_t in test_list: + * point_discovery = discovery_managed_raster.get( # <<<<<<<<<<<<<< + * x_t, y_t) + * if (point_discovery != discovery_nodata and + */ + __pyx_v_point_discovery = ((long)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_discovery_managed_raster, __pyx_t_9, __pyx_t_10)); + + /* "pygeoprocessing/routing/routing.pyx":4431 + * point_discovery = discovery_managed_raster.get( + * x_t, y_t) + * if (point_discovery != discovery_nodata and # <<<<<<<<<<<<<< + * point_discovery >= discovery and + * point_discovery <= finish): + */ + __pyx_t_12 = ((__pyx_v_point_discovery != __pyx_v_discovery_nodata) != 0); + if (__pyx_t_12) { + } else { + __pyx_t_11 = __pyx_t_12; + goto __pyx_L8_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":4432 + * x_t, y_t) + * if (point_discovery != discovery_nodata and + * point_discovery >= discovery and # <<<<<<<<<<<<<< + * point_discovery <= finish): + * boundary_list.append((int(x_t), int(y_t))) + */ + __pyx_t_12 = ((__pyx_v_point_discovery >= __pyx_v_discovery) != 0); + if (__pyx_t_12) { + } else { + __pyx_t_11 = __pyx_t_12; + goto __pyx_L8_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":4433 + * if (point_discovery != discovery_nodata and + * point_discovery >= discovery and + * point_discovery <= finish): # <<<<<<<<<<<<<< + * boundary_list.append((int(x_t), int(y_t))) + * # there's only one diagonal to fill in so it's done here + */ + __pyx_t_12 = ((__pyx_v_point_discovery <= __pyx_v_finish) != 0); + __pyx_t_11 = __pyx_t_12; + __pyx_L8_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":4431 + * point_discovery = discovery_managed_raster.get( + * x_t, y_t) + * if (point_discovery != discovery_nodata and # <<<<<<<<<<<<<< + * point_discovery >= discovery and + * point_discovery <= finish): + */ + if (__pyx_t_11) { + + /* "pygeoprocessing/routing/routing.pyx":4434 + * point_discovery >= discovery and + * point_discovery <= finish): + * boundary_list.append((int(x_t), int(y_t))) # <<<<<<<<<<<<<< + * # there's only one diagonal to fill in so it's done here + * return + */ + __pyx_t_5 = __Pyx_PyNumber_Int(__pyx_v_x_t); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4434, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = __Pyx_PyNumber_Int(__pyx_v_y_t); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4434, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4434, __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_2); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2); + __pyx_t_5 = 0; + __pyx_t_2 = 0; + __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_boundary_list, __pyx_t_1); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 4434, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4436 + * boundary_list.append((int(x_t), int(y_t))) + * # there's only one diagonal to fill in so it's done here + * return # <<<<<<<<<<<<<< + * + * # if there's a degenerate case then just add the xdelta, + */ + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L0; + + /* "pygeoprocessing/routing/routing.pyx":4431 + * point_discovery = discovery_managed_raster.get( + * x_t, y_t) + * if (point_discovery != discovery_nodata and # <<<<<<<<<<<<<< + * point_discovery >= discovery and + * point_discovery <= finish): + */ + } + + /* "pygeoprocessing/routing/routing.pyx":4428 + * (x_l - xdelta, y_l), + * (x_l, y_l - ydelta)] + * for x_t, y_t in test_list: # <<<<<<<<<<<<<< + * point_discovery = discovery_managed_raster.get( + * x_t, y_t) + */ + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4440 + * # if there's a degenerate case then just add the xdelta, + * # it doesn't matter + * boundary_list.append(test_list[0]) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_3 = __Pyx_GetItemInt_List(__pyx_v_test_list, 0, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4440, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_boundary_list, __pyx_t_3); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 4440, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4381 + * + * + * cdef void _diagonal_fill_step( # <<<<<<<<<<<<<< + * int x_l, int y_l, int edge_dir, + * long discovery, long finish, + */ + + /* 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_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_WriteUnraisable("pygeoprocessing.routing.routing._diagonal_fill_step", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_test_list); + __Pyx_XDECREF(__pyx_v_x_t); + __Pyx_XDECREF(__pyx_v_y_t); + __Pyx_RefNannyFinishContext(); +} + +/* "pygeoprocessing/routing/routing.pyx":4443 + * + * + * cdef int _in_watershed( # <<<<<<<<<<<<<< + * int x_l, int y_l, int direction_to_test, int discovery, int finish, + * int n_cols, int n_rows, + */ + +static int __pyx_f_15pygeoprocessing_7routing_7routing__in_watershed(int __pyx_v_x_l, int __pyx_v_y_l, int __pyx_v_direction_to_test, int __pyx_v_discovery, int __pyx_v_finish, int __pyx_v_n_cols, int __pyx_v_n_rows, struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_discovery_managed_raster, long __pyx_v_discovery_nodata) { + int __pyx_v_x_n; + int __pyx_v_y_n; + long __pyx_v_point_discovery; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + __Pyx_RefNannySetupContext("_in_watershed", 0); + + /* "pygeoprocessing/routing/routing.pyx":4466 + * 1 if in, 0 if out. + * """ + * cdef int x_n = x_l + D8_XOFFSET[direction_to_test] # <<<<<<<<<<<<<< + * cdef int y_n = y_l + D8_YOFFSET[direction_to_test] + * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: + */ + __pyx_v_x_n = (__pyx_v_x_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_direction_to_test])); + + /* "pygeoprocessing/routing/routing.pyx":4467 + * """ + * cdef int x_n = x_l + D8_XOFFSET[direction_to_test] + * cdef int y_n = y_l + D8_YOFFSET[direction_to_test] # <<<<<<<<<<<<<< + * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: + * return 0 + */ + __pyx_v_y_n = (__pyx_v_y_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_direction_to_test])); + + /* "pygeoprocessing/routing/routing.pyx":4468 + * cdef int x_n = x_l + D8_XOFFSET[direction_to_test] + * cdef int y_n = y_l + D8_YOFFSET[direction_to_test] + * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: # <<<<<<<<<<<<<< + * return 0 + * cdef long point_discovery = discovery_managed_raster.get(x_n, y_n) + */ + __pyx_t_2 = ((__pyx_v_x_n < 0) != 0); + if (!__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_2 = ((__pyx_v_y_n < 0) != 0); + if (!__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_2 = ((__pyx_v_x_n >= __pyx_v_n_cols) != 0); + if (!__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_2 = ((__pyx_v_y_n >= __pyx_v_n_rows) != 0); + __pyx_t_1 = __pyx_t_2; + __pyx_L4_bool_binop_done:; + if (__pyx_t_1) { + + /* "pygeoprocessing/routing/routing.pyx":4469 + * cdef int y_n = y_l + D8_YOFFSET[direction_to_test] + * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: + * return 0 # <<<<<<<<<<<<<< + * cdef long point_discovery = discovery_managed_raster.get(x_n, y_n) + * return (point_discovery != discovery_nodata and + */ + __pyx_r = 0; + goto __pyx_L0; + + /* "pygeoprocessing/routing/routing.pyx":4468 + * cdef int x_n = x_l + D8_XOFFSET[direction_to_test] + * cdef int y_n = y_l + D8_YOFFSET[direction_to_test] + * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: # <<<<<<<<<<<<<< + * return 0 + * cdef long point_discovery = discovery_managed_raster.get(x_n, y_n) + */ + } + + /* "pygeoprocessing/routing/routing.pyx":4470 + * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: + * return 0 + * cdef long point_discovery = discovery_managed_raster.get(x_n, y_n) # <<<<<<<<<<<<<< + * return (point_discovery != discovery_nodata and + * point_discovery >= discovery and + */ + __pyx_v_point_discovery = ((long)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_discovery_managed_raster, __pyx_v_x_n, __pyx_v_y_n)); + + /* "pygeoprocessing/routing/routing.pyx":4471 + * return 0 + * cdef long point_discovery = discovery_managed_raster.get(x_n, y_n) + * return (point_discovery != discovery_nodata and # <<<<<<<<<<<<<< + * point_discovery >= discovery and + * point_discovery <= finish) + */ + __pyx_t_1 = (__pyx_v_point_discovery != __pyx_v_discovery_nodata); + if (__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L8_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":4472 + * cdef long point_discovery = discovery_managed_raster.get(x_n, y_n) + * return (point_discovery != discovery_nodata and + * point_discovery >= discovery and # <<<<<<<<<<<<<< + * point_discovery <= finish) + * + */ + __pyx_t_1 = (__pyx_v_point_discovery >= __pyx_v_discovery); + if (__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L8_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":4473 + * return (point_discovery != discovery_nodata and + * point_discovery >= discovery and + * point_discovery <= finish) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_1 = (__pyx_v_point_discovery <= __pyx_v_finish); + __pyx_t_3 = __pyx_t_1; + __pyx_L8_bool_binop_done:; + __pyx_r = __pyx_t_3; + goto __pyx_L0; + + /* "pygeoprocessing/routing/routing.pyx":4443 + * + * + * cdef int _in_watershed( # <<<<<<<<<<<<<< + * int x_l, int y_l, int direction_to_test, int discovery, int finish, + * int n_cols, int n_rows, + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pygeoprocessing/routing/routing.pyx":4476 + * + * + * cdef _calculate_stream_geometry( # <<<<<<<<<<<<<< + * int x_l, int y_l, int upstream_d8_dir, geotransform, int n_cols, + * int n_rows, _ManagedRaster flow_accum_managed_raster, + */ + +static PyObject *__pyx_f_15pygeoprocessing_7routing_7routing__calculate_stream_geometry(int __pyx_v_x_l, int __pyx_v_y_l, int __pyx_v_upstream_d8_dir, PyObject *__pyx_v_geotransform, int __pyx_v_n_cols, int __pyx_v_n_rows, struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_flow_accum_managed_raster, struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_flow_dir_managed_raster, int __pyx_v_flow_dir_nodata, int __pyx_v_flow_accum_threshold, PyObject *__pyx_v_coord_to_stream_ids) { + int __pyx_v_x_1; + int __pyx_v_y_1; + int __pyx_v_x_n; + int __pyx_v_y_n; + int __pyx_v_d; + int __pyx_v_d_n; + int __pyx_v_stream_end; + int __pyx_v_pixel_length; + PyObject *__pyx_v_upstream_id_list = NULL; + PyObject *__pyx_v_stream_line = NULL; + PyObject *__pyx_v_x_p = NULL; + PyObject *__pyx_v_y_p = NULL; + int __pyx_v_next_dir; + int __pyx_v_last_dir; + 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; + int __pyx_t_7; + PyObject *__pyx_t_8 = NULL; + PyObject *(*__pyx_t_9)(PyObject *); + int __pyx_t_10; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_calculate_stream_geometry", 0); + + /* "pygeoprocessing/routing/routing.pyx":4518 + * + * """ + * cdef int x_1, y_1, x_n, y_n, d, d_n, stream_end=0, pixel_length # <<<<<<<<<<<<<< + * + * if flow_accum_managed_raster.get(x_l, y_l) < flow_accum_threshold: + */ + __pyx_v_stream_end = 0; + + /* "pygeoprocessing/routing/routing.pyx":4520 + * cdef int x_1, y_1, x_n, y_n, d, d_n, stream_end=0, pixel_length + * + * if flow_accum_managed_raster.get(x_l, y_l) < flow_accum_threshold: # <<<<<<<<<<<<<< + * return None + * upstream_id_list = [] + */ + __pyx_t_1 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_accum_managed_raster, __pyx_v_x_l, __pyx_v_y_l) < __pyx_v_flow_accum_threshold) != 0); + if (__pyx_t_1) { + + /* "pygeoprocessing/routing/routing.pyx":4521 + * + * if flow_accum_managed_raster.get(x_l, y_l) < flow_accum_threshold: + * return None # <<<<<<<<<<<<<< + * upstream_id_list = [] + * # anchor the line at the downstream end + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "pygeoprocessing/routing/routing.pyx":4520 + * cdef int x_1, y_1, x_n, y_n, d, d_n, stream_end=0, pixel_length + * + * if flow_accum_managed_raster.get(x_l, y_l) < flow_accum_threshold: # <<<<<<<<<<<<<< + * return None + * upstream_id_list = [] + */ + } + + /* "pygeoprocessing/routing/routing.pyx":4522 + * if flow_accum_managed_raster.get(x_l, y_l) < flow_accum_threshold: + * return None + * upstream_id_list = [] # <<<<<<<<<<<<<< + * # anchor the line at the downstream end + * stream_line = ogr.Geometry(ogr.wkbLineString) + */ + __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4522, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_upstream_id_list = __pyx_t_2; + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4524 + * upstream_id_list = [] + * # anchor the line at the downstream end + * stream_line = ogr.Geometry(ogr.wkbLineString) # <<<<<<<<<<<<<< + * x_p, y_p = gdal.ApplyGeoTransform(geotransform, x_l+0.5, y_l+0.5) + * stream_line.AddPoint(x_p, y_p) + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_ogr); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4524, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_Geometry); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4524, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_ogr); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4524, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_wkbLineString); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4524, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + 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_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4524, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_stream_line = __pyx_t_2; + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4525 + * # anchor the line at the downstream end + * stream_line = ogr.Geometry(ogr.wkbLineString) + * x_p, y_p = gdal.ApplyGeoTransform(geotransform, x_l+0.5, y_l+0.5) # <<<<<<<<<<<<<< + * stream_line.AddPoint(x_p, y_p) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4525, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_ApplyGeoTransform); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4525, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyFloat_FromDouble((__pyx_v_x_l + 0.5)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4525, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyFloat_FromDouble((__pyx_v_y_l + 0.5)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4525, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = NULL; + __pyx_t_7 = 0; + 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); + __pyx_t_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[4] = {__pyx_t_6, __pyx_v_geotransform, __pyx_t_4, __pyx_t_3}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_7, 3+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4525, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_2); + __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_5)) { + PyObject *__pyx_temp[4] = {__pyx_t_6, __pyx_v_geotransform, __pyx_t_4, __pyx_t_3}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_7, 3+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4525, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + { + __pyx_t_8 = PyTuple_New(3+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4525, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + if (__pyx_t_6) { + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL; + } + __Pyx_INCREF(__pyx_v_geotransform); + __Pyx_GIVEREF(__pyx_v_geotransform); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_v_geotransform); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_8, 2+__pyx_t_7, __pyx_t_3); + __pyx_t_4 = 0; + __pyx_t_3 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4525, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + 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 != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 4525, __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_8 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_5 = PyList_GET_ITEM(sequence, 0); + __pyx_t_8 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(__pyx_t_8); + #else + __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4525, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_8 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4525, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + #endif + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4525, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_9 = Py_TYPE(__pyx_t_3)->tp_iternext; + index = 0; __pyx_t_5 = __pyx_t_9(__pyx_t_3); if (unlikely(!__pyx_t_5)) goto __pyx_L4_unpacking_failed; + __Pyx_GOTREF(__pyx_t_5); + index = 1; __pyx_t_8 = __pyx_t_9(__pyx_t_3); if (unlikely(!__pyx_t_8)) goto __pyx_L4_unpacking_failed; + __Pyx_GOTREF(__pyx_t_8); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_3), 2) < 0) __PYX_ERR(0, 4525, __pyx_L1_error) + __pyx_t_9 = NULL; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L5_unpacking_done; + __pyx_L4_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, 4525, __pyx_L1_error) + __pyx_L5_unpacking_done:; + } + __pyx_v_x_p = __pyx_t_5; + __pyx_t_5 = 0; + __pyx_v_y_p = __pyx_t_8; + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4526 + * stream_line = ogr.Geometry(ogr.wkbLineString) + * x_p, y_p = gdal.ApplyGeoTransform(geotransform, x_l+0.5, y_l+0.5) + * stream_line.AddPoint(x_p, y_p) # <<<<<<<<<<<<<< + * + * # initialize next_dir and last_dir so we only drop new points when + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_line, __pyx_n_s_AddPoint); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4526, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_5 = NULL; + __pyx_t_7 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + __pyx_t_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_x_p, __pyx_v_y_p}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4526, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_x_p, __pyx_v_y_p}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4526, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_3 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4526, __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_x_p); + __Pyx_GIVEREF(__pyx_v_x_p); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_7, __pyx_v_x_p); + __Pyx_INCREF(__pyx_v_y_p); + __Pyx_GIVEREF(__pyx_v_y_p); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_7, __pyx_v_y_p); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4526, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4530 + * # initialize next_dir and last_dir so we only drop new points when + * # the line changes direction + * cdef int next_dir = upstream_d8_dir # <<<<<<<<<<<<<< + * cdef int last_dir = next_dir + * + */ + __pyx_v_next_dir = __pyx_v_upstream_d8_dir; + + /* "pygeoprocessing/routing/routing.pyx":4531 + * # the line changes direction + * cdef int next_dir = upstream_d8_dir + * cdef int last_dir = next_dir # <<<<<<<<<<<<<< + * + * stream_end = 0 + */ + __pyx_v_last_dir = __pyx_v_next_dir; + + /* "pygeoprocessing/routing/routing.pyx":4533 + * cdef int last_dir = next_dir + * + * stream_end = 0 # <<<<<<<<<<<<<< + * pixel_length = 0 + * # initialize these for the compiler warniing + */ + __pyx_v_stream_end = 0; + + /* "pygeoprocessing/routing/routing.pyx":4534 + * + * stream_end = 0 + * pixel_length = 0 # <<<<<<<<<<<<<< + * # initialize these for the compiler warniing + * x_1 = -1 + */ + __pyx_v_pixel_length = 0; + + /* "pygeoprocessing/routing/routing.pyx":4536 + * pixel_length = 0 + * # initialize these for the compiler warniing + * x_1 = -1 # <<<<<<<<<<<<<< + * y_1 = -1 + * while not stream_end: + */ + __pyx_v_x_1 = -1; + + /* "pygeoprocessing/routing/routing.pyx":4537 + * # initialize these for the compiler warniing + * x_1 = -1 + * y_1 = -1 # <<<<<<<<<<<<<< + * while not stream_end: + * # walk upstream + */ + __pyx_v_y_1 = -1; + + /* "pygeoprocessing/routing/routing.pyx":4538 + * x_1 = -1 + * y_1 = -1 + * while not stream_end: # <<<<<<<<<<<<<< + * # walk upstream + * x_l += D8_XOFFSET[next_dir] + */ + while (1) { + __pyx_t_1 = ((!(__pyx_v_stream_end != 0)) != 0); + if (!__pyx_t_1) break; + + /* "pygeoprocessing/routing/routing.pyx":4540 + * while not stream_end: + * # walk upstream + * x_l += D8_XOFFSET[next_dir] # <<<<<<<<<<<<<< + * y_l += D8_YOFFSET[next_dir] + * + */ + __pyx_v_x_l = (__pyx_v_x_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_next_dir])); + + /* "pygeoprocessing/routing/routing.pyx":4541 + * # walk upstream + * x_l += D8_XOFFSET[next_dir] + * y_l += D8_YOFFSET[next_dir] # <<<<<<<<<<<<<< + * + * stream_end = 1 + */ + __pyx_v_y_l = (__pyx_v_y_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_next_dir])); + + /* "pygeoprocessing/routing/routing.pyx":4543 + * y_l += D8_YOFFSET[next_dir] + * + * stream_end = 1 # <<<<<<<<<<<<<< + * pixel_length += 1 + * # do <= 1 in case there's a degenerate single point stream + */ + __pyx_v_stream_end = 1; + + /* "pygeoprocessing/routing/routing.pyx":4544 + * + * stream_end = 1 + * pixel_length += 1 # <<<<<<<<<<<<<< + * # do <= 1 in case there's a degenerate single point stream + * if pixel_length <= 1: + */ + __pyx_v_pixel_length = (__pyx_v_pixel_length + 1); + + /* "pygeoprocessing/routing/routing.pyx":4546 + * pixel_length += 1 + * # do <= 1 in case there's a degenerate single point stream + * if pixel_length <= 1: # <<<<<<<<<<<<<< + * x_1 = x_l + * y_1 = y_l + */ + __pyx_t_1 = ((__pyx_v_pixel_length <= 1) != 0); + if (__pyx_t_1) { + + /* "pygeoprocessing/routing/routing.pyx":4547 + * # do <= 1 in case there's a degenerate single point stream + * if pixel_length <= 1: + * x_1 = x_l # <<<<<<<<<<<<<< + * y_1 = y_l + * + */ + __pyx_v_x_1 = __pyx_v_x_l; + + /* "pygeoprocessing/routing/routing.pyx":4548 + * if pixel_length <= 1: + * x_1 = x_l + * y_1 = y_l # <<<<<<<<<<<<<< + * + * # check if we reached an upstream junction + */ + __pyx_v_y_1 = __pyx_v_y_l; + + /* "pygeoprocessing/routing/routing.pyx":4546 + * pixel_length += 1 + * # do <= 1 in case there's a degenerate single point stream + * if pixel_length <= 1: # <<<<<<<<<<<<<< + * x_1 = x_l + * y_1 = y_l + */ + } + + /* "pygeoprocessing/routing/routing.pyx":4551 + * + * # check if we reached an upstream junction + * if (x_l, y_l) in coord_to_stream_ids: # <<<<<<<<<<<<<< + * upstream_id_list = coord_to_stream_ids[(x_l, y_l)] + * del coord_to_stream_ids[(x_l, y_l)] + */ + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_x_l); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4551, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_y_l); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4551, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4551, __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_8); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_8); + __pyx_t_2 = 0; + __pyx_t_8 = 0; + __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_t_3, __pyx_v_coord_to_stream_ids, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 4551, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_10 = (__pyx_t_1 != 0); + if (__pyx_t_10) { + + /* "pygeoprocessing/routing/routing.pyx":4552 + * # check if we reached an upstream junction + * if (x_l, y_l) in coord_to_stream_ids: + * upstream_id_list = coord_to_stream_ids[(x_l, y_l)] # <<<<<<<<<<<<<< + * del coord_to_stream_ids[(x_l, y_l)] + * elif flow_accum_managed_raster.get(x_l, y_l) >= \ + */ + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_x_l); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4552, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_y_l); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4552, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4552, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_8); + __pyx_t_3 = 0; + __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_coord_to_stream_ids, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4552, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF_SET(__pyx_v_upstream_id_list, __pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4553 + * if (x_l, y_l) in coord_to_stream_ids: + * upstream_id_list = coord_to_stream_ids[(x_l, y_l)] + * del coord_to_stream_ids[(x_l, y_l)] # <<<<<<<<<<<<<< + * elif flow_accum_managed_raster.get(x_l, y_l) >= \ + * flow_accum_threshold: + */ + __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_x_l); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4553, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_y_l); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4553, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4553, __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_2); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + __pyx_t_8 = 0; + __pyx_t_2 = 0; + if (unlikely(PyObject_DelItem(__pyx_v_coord_to_stream_ids, __pyx_t_3) < 0)) __PYX_ERR(0, 4553, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4551 + * + * # check if we reached an upstream junction + * if (x_l, y_l) in coord_to_stream_ids: # <<<<<<<<<<<<<< + * upstream_id_list = coord_to_stream_ids[(x_l, y_l)] + * del coord_to_stream_ids[(x_l, y_l)] + */ + goto __pyx_L9; + } + + /* "pygeoprocessing/routing/routing.pyx":4554 + * upstream_id_list = coord_to_stream_ids[(x_l, y_l)] + * del coord_to_stream_ids[(x_l, y_l)] + * elif flow_accum_managed_raster.get(x_l, y_l) >= \ # <<<<<<<<<<<<<< + * flow_accum_threshold: + * # check to see if we can take a step upstream + */ + __pyx_t_10 = ((((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_accum_managed_raster, __pyx_v_x_l, __pyx_v_y_l)) >= __pyx_v_flow_accum_threshold) != 0); + if (__pyx_t_10) { + + /* "pygeoprocessing/routing/routing.pyx":4557 + * flow_accum_threshold: + * # check to see if we can take a step upstream + * for d in range(8): # <<<<<<<<<<<<<< + * x_n = x_l + D8_XOFFSET[d] + * y_n = y_l + D8_YOFFSET[d] + */ + for (__pyx_t_7 = 0; __pyx_t_7 < 8; __pyx_t_7+=1) { + __pyx_v_d = __pyx_t_7; + + /* "pygeoprocessing/routing/routing.pyx":4558 + * # check to see if we can take a step upstream + * for d in range(8): + * x_n = x_l + D8_XOFFSET[d] # <<<<<<<<<<<<<< + * y_n = y_l + D8_YOFFSET[d] + * + */ + __pyx_v_x_n = (__pyx_v_x_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_d])); + + /* "pygeoprocessing/routing/routing.pyx":4559 + * for d in range(8): + * x_n = x_l + D8_XOFFSET[d] + * y_n = y_l + D8_YOFFSET[d] # <<<<<<<<<<<<<< + * + * # check out of bounds + */ + __pyx_v_y_n = (__pyx_v_y_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_d])); + + /* "pygeoprocessing/routing/routing.pyx":4562 + * + * # check out of bounds + * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_1 = ((__pyx_v_x_n < 0) != 0); + if (!__pyx_t_1) { + } else { + __pyx_t_10 = __pyx_t_1; + goto __pyx_L13_bool_binop_done; + } + __pyx_t_1 = ((__pyx_v_y_n < 0) != 0); + if (!__pyx_t_1) { + } else { + __pyx_t_10 = __pyx_t_1; + goto __pyx_L13_bool_binop_done; + } + __pyx_t_1 = ((__pyx_v_x_n >= __pyx_v_n_cols) != 0); + if (!__pyx_t_1) { + } else { + __pyx_t_10 = __pyx_t_1; + goto __pyx_L13_bool_binop_done; + } + __pyx_t_1 = ((__pyx_v_y_n >= __pyx_v_n_rows) != 0); + __pyx_t_10 = __pyx_t_1; + __pyx_L13_bool_binop_done:; + if (__pyx_t_10) { + + /* "pygeoprocessing/routing/routing.pyx":4563 + * # check out of bounds + * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: + * continue # <<<<<<<<<<<<<< + * + * # check for nodata + */ + goto __pyx_L10_continue; + + /* "pygeoprocessing/routing/routing.pyx":4562 + * + * # check out of bounds + * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: # <<<<<<<<<<<<<< + * continue + * + */ + } + + /* "pygeoprocessing/routing/routing.pyx":4566 + * + * # check for nodata + * d_n = flow_dir_managed_raster.get(x_n, y_n) # <<<<<<<<<<<<<< + * if d_n == flow_dir_nodata: + * continue + */ + __pyx_v_d_n = ((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_dir_managed_raster, __pyx_v_x_n, __pyx_v_y_n)); + + /* "pygeoprocessing/routing/routing.pyx":4567 + * # check for nodata + * d_n = flow_dir_managed_raster.get(x_n, y_n) + * if d_n == flow_dir_nodata: # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_10 = ((__pyx_v_d_n == __pyx_v_flow_dir_nodata) != 0); + if (__pyx_t_10) { + + /* "pygeoprocessing/routing/routing.pyx":4568 + * d_n = flow_dir_managed_raster.get(x_n, y_n) + * if d_n == flow_dir_nodata: + * continue # <<<<<<<<<<<<<< + * + * # check if there's an upstream inflow pixel with flow accum + */ + goto __pyx_L10_continue; + + /* "pygeoprocessing/routing/routing.pyx":4567 + * # check for nodata + * d_n = flow_dir_managed_raster.get(x_n, y_n) + * if d_n == flow_dir_nodata: # <<<<<<<<<<<<<< + * continue + * + */ + } + + /* "pygeoprocessing/routing/routing.pyx":4572 + * # check if there's an upstream inflow pixel with flow accum + * # greater than the threshold + * if D8_REVERSE_DIRECTION[d] == d_n and ( # <<<<<<<<<<<<<< + * flow_accum_managed_raster.get( + * x_n, y_n) > flow_accum_threshold): + */ + __pyx_t_1 = (((__pyx_v_15pygeoprocessing_7routing_7routing_D8_REVERSE_DIRECTION[__pyx_v_d]) == __pyx_v_d_n) != 0); + if (__pyx_t_1) { + } else { + __pyx_t_10 = __pyx_t_1; + goto __pyx_L19_bool_binop_done; + } + + /* "pygeoprocessing/routing/routing.pyx":4574 + * if D8_REVERSE_DIRECTION[d] == d_n and ( + * flow_accum_managed_raster.get( + * x_n, y_n) > flow_accum_threshold): # <<<<<<<<<<<<<< + * stream_end = 0 + * next_dir = d + */ + __pyx_t_1 = ((((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_accum_managed_raster, __pyx_v_x_n, __pyx_v_y_n)) > __pyx_v_flow_accum_threshold) != 0); + __pyx_t_10 = __pyx_t_1; + __pyx_L19_bool_binop_done:; + + /* "pygeoprocessing/routing/routing.pyx":4572 + * # check if there's an upstream inflow pixel with flow accum + * # greater than the threshold + * if D8_REVERSE_DIRECTION[d] == d_n and ( # <<<<<<<<<<<<<< + * flow_accum_managed_raster.get( + * x_n, y_n) > flow_accum_threshold): + */ + if (__pyx_t_10) { + + /* "pygeoprocessing/routing/routing.pyx":4575 + * flow_accum_managed_raster.get( + * x_n, y_n) > flow_accum_threshold): + * stream_end = 0 # <<<<<<<<<<<<<< + * next_dir = d + * break + */ + __pyx_v_stream_end = 0; + + /* "pygeoprocessing/routing/routing.pyx":4576 + * x_n, y_n) > flow_accum_threshold): + * stream_end = 0 + * next_dir = d # <<<<<<<<<<<<<< + * break + * else: + */ + __pyx_v_next_dir = __pyx_v_d; + + /* "pygeoprocessing/routing/routing.pyx":4577 + * stream_end = 0 + * next_dir = d + * break # <<<<<<<<<<<<<< + * else: + * # terminated because of flow accumulation too small, so back up + */ + goto __pyx_L11_break; + + /* "pygeoprocessing/routing/routing.pyx":4572 + * # check if there's an upstream inflow pixel with flow accum + * # greater than the threshold + * if D8_REVERSE_DIRECTION[d] == d_n and ( # <<<<<<<<<<<<<< + * flow_accum_managed_raster.get( + * x_n, y_n) > flow_accum_threshold): + */ + } + __pyx_L10_continue:; + } + __pyx_L11_break:; + + /* "pygeoprocessing/routing/routing.pyx":4554 + * upstream_id_list = coord_to_stream_ids[(x_l, y_l)] + * del coord_to_stream_ids[(x_l, y_l)] + * elif flow_accum_managed_raster.get(x_l, y_l) >= \ # <<<<<<<<<<<<<< + * flow_accum_threshold: + * # check to see if we can take a step upstream + */ + goto __pyx_L9; + } + + /* "pygeoprocessing/routing/routing.pyx":4581 + * # terminated because of flow accumulation too small, so back up + * # one pixel + * pixel_length -= 1 # <<<<<<<<<<<<<< + * + * # drop a point on the line if direction changed or last point + */ + /*else*/ { + __pyx_v_pixel_length = (__pyx_v_pixel_length - 1); + } + __pyx_L9:; + + /* "pygeoprocessing/routing/routing.pyx":4584 + * + * # drop a point on the line if direction changed or last point + * if last_dir != next_dir or stream_end: # <<<<<<<<<<<<<< + * x_p, y_p = gdal.ApplyGeoTransform( + * geotransform, x_l+0.5, y_l+0.5) + */ + __pyx_t_1 = ((__pyx_v_last_dir != __pyx_v_next_dir) != 0); + if (!__pyx_t_1) { + } else { + __pyx_t_10 = __pyx_t_1; + goto __pyx_L22_bool_binop_done; + } + __pyx_t_1 = (__pyx_v_stream_end != 0); + __pyx_t_10 = __pyx_t_1; + __pyx_L22_bool_binop_done:; + if (__pyx_t_10) { + + /* "pygeoprocessing/routing/routing.pyx":4585 + * # drop a point on the line if direction changed or last point + * if last_dir != next_dir or stream_end: + * x_p, y_p = gdal.ApplyGeoTransform( # <<<<<<<<<<<<<< + * geotransform, x_l+0.5, y_l+0.5) + * stream_line.AddPoint(x_p, y_p) + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4585, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_ApplyGeoTransform); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4585, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4586 + * if last_dir != next_dir or stream_end: + * x_p, y_p = gdal.ApplyGeoTransform( + * geotransform, x_l+0.5, y_l+0.5) # <<<<<<<<<<<<<< + * stream_line.AddPoint(x_p, y_p) + * last_dir = next_dir + */ + __pyx_t_2 = PyFloat_FromDouble((__pyx_v_x_l + 0.5)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4586, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = PyFloat_FromDouble((__pyx_v_y_l + 0.5)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4586, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = NULL; + __pyx_t_7 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(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); + __pyx_t_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_geotransform, __pyx_t_2, __pyx_t_5}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_7, 3+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4585, __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; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_geotransform, __pyx_t_2, __pyx_t_5}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_7, 3+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4585, __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; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_6 = PyTuple_New(3+__pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4585, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (__pyx_t_4) { + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; + } + __Pyx_INCREF(__pyx_v_geotransform); + __Pyx_GIVEREF(__pyx_v_geotransform); + PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_7, __pyx_v_geotransform); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_7, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_7, __pyx_t_5); + __pyx_t_2 = 0; + __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4585, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 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, 4585, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_8 = PyList_GET_ITEM(sequence, 0); + __pyx_t_6 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(__pyx_t_6); + #else + __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4585, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4585, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + #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, 4585, __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_8 = __pyx_t_9(__pyx_t_5); if (unlikely(!__pyx_t_8)) goto __pyx_L24_unpacking_failed; + __Pyx_GOTREF(__pyx_t_8); + index = 1; __pyx_t_6 = __pyx_t_9(__pyx_t_5); if (unlikely(!__pyx_t_6)) goto __pyx_L24_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_5), 2) < 0) __PYX_ERR(0, 4585, __pyx_L1_error) + __pyx_t_9 = NULL; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L25_unpacking_done; + __pyx_L24_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, 4585, __pyx_L1_error) + __pyx_L25_unpacking_done:; + } + + /* "pygeoprocessing/routing/routing.pyx":4585 + * # drop a point on the line if direction changed or last point + * if last_dir != next_dir or stream_end: + * x_p, y_p = gdal.ApplyGeoTransform( # <<<<<<<<<<<<<< + * geotransform, x_l+0.5, y_l+0.5) + * stream_line.AddPoint(x_p, y_p) + */ + __Pyx_DECREF_SET(__pyx_v_x_p, __pyx_t_8); + __pyx_t_8 = 0; + __Pyx_DECREF_SET(__pyx_v_y_p, __pyx_t_6); + __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4587 + * x_p, y_p = gdal.ApplyGeoTransform( + * geotransform, x_l+0.5, y_l+0.5) + * stream_line.AddPoint(x_p, y_p) # <<<<<<<<<<<<<< + * last_dir = next_dir + * + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_line, __pyx_n_s_AddPoint); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4587, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = NULL; + __pyx_t_7 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_x_p, __pyx_v_y_p}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4587, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_x_p, __pyx_v_y_p}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4587, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_5 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4587, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_8) { + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_8); __pyx_t_8 = NULL; + } + __Pyx_INCREF(__pyx_v_x_p); + __Pyx_GIVEREF(__pyx_v_x_p); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_7, __pyx_v_x_p); + __Pyx_INCREF(__pyx_v_y_p); + __Pyx_GIVEREF(__pyx_v_y_p); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_7, __pyx_v_y_p); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4587, __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(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4588 + * geotransform, x_l+0.5, y_l+0.5) + * stream_line.AddPoint(x_p, y_p) + * last_dir = next_dir # <<<<<<<<<<<<<< + * + * if pixel_length == 0: + */ + __pyx_v_last_dir = __pyx_v_next_dir; + + /* "pygeoprocessing/routing/routing.pyx":4584 + * + * # drop a point on the line if direction changed or last point + * if last_dir != next_dir or stream_end: # <<<<<<<<<<<<<< + * x_p, y_p = gdal.ApplyGeoTransform( + * geotransform, x_l+0.5, y_l+0.5) + */ + } + } + + /* "pygeoprocessing/routing/routing.pyx":4590 + * last_dir = next_dir + * + * if pixel_length == 0: # <<<<<<<<<<<<<< + * return None + * return x_l, y_l, x_1, y_1, upstream_id_list, stream_line + */ + __pyx_t_10 = ((__pyx_v_pixel_length == 0) != 0); + if (__pyx_t_10) { + + /* "pygeoprocessing/routing/routing.pyx":4591 + * + * if pixel_length == 0: + * return None # <<<<<<<<<<<<<< + * return x_l, y_l, x_1, y_1, upstream_id_list, stream_line + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "pygeoprocessing/routing/routing.pyx":4590 + * last_dir = next_dir + * + * if pixel_length == 0: # <<<<<<<<<<<<<< + * return None + * return x_l, y_l, x_1, y_1, upstream_id_list, stream_line + */ + } + + /* "pygeoprocessing/routing/routing.pyx":4592 + * if pixel_length == 0: + * return None + * return x_l, y_l, x_1, y_1, upstream_id_list, stream_line # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_x_l); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4592, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_y_l); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4592, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_x_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4592, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_y_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4592, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_2 = PyTuple_New(6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4592, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_8); + __Pyx_INCREF(__pyx_v_upstream_id_list); + __Pyx_GIVEREF(__pyx_v_upstream_id_list); + PyTuple_SET_ITEM(__pyx_t_2, 4, __pyx_v_upstream_id_list); + __Pyx_INCREF(__pyx_v_stream_line); + __Pyx_GIVEREF(__pyx_v_stream_line); + PyTuple_SET_ITEM(__pyx_t_2, 5, __pyx_v_stream_line); + __pyx_t_3 = 0; + __pyx_t_6 = 0; + __pyx_t_5 = 0; + __pyx_t_8 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "pygeoprocessing/routing/routing.pyx":4476 + * + * + * cdef _calculate_stream_geometry( # <<<<<<<<<<<<<< + * int x_l, int y_l, int upstream_d8_dir, geotransform, int n_cols, + * int n_rows, _ManagedRaster flow_accum_managed_raster, + */ + + /* function exit code */ + __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); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("pygeoprocessing.routing.routing._calculate_stream_geometry", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_upstream_id_list); + __Pyx_XDECREF(__pyx_v_stream_line); + __Pyx_XDECREF(__pyx_v_x_p); + __Pyx_XDECREF(__pyx_v_y_p); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pygeoprocessing/routing/routing.pyx":4595 + * + * + * def _delete_feature( # <<<<<<<<<<<<<< + * stream_feature, stream_layer, upstream_to_downstream_id, + * downstream_to_upstream_ids): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_29_delete_feature(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_15pygeoprocessing_7routing_7routing_28_delete_feature[] = "Helper for Mahler extraction to delete all references to a stream.\n\n Args:\n stream_feature (ogr.Feature): feature to delete\n stream_layer (ogr.Layer): layer to delete the feature\n upstream_to_downstream_id (dict): can be referenced by FID and should\n remove all instances of stream from this dict\n downstream_to_upstream_ids (dict): stream feature contained in\n the values of this dict and should remove all instances of stream\n from this dict\n\n Returns:\n None.\n "; +static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_29_delete_feature = {"_delete_feature", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_7routing_7routing_29_delete_feature, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_7routing_7routing_28_delete_feature}; +static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_29_delete_feature(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_stream_feature = 0; + PyObject *__pyx_v_stream_layer = 0; + PyObject *__pyx_v_upstream_to_downstream_id = 0; + PyObject *__pyx_v_downstream_to_upstream_ids = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_delete_feature (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_stream_feature,&__pyx_n_s_stream_layer,&__pyx_n_s_upstream_to_downstream_id,&__pyx_n_s_downstream_to_upstream_ids,0}; + PyObject* values[4] = {0,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 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_stream_feature)) != 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_stream_layer)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_delete_feature", 1, 4, 4, 1); __PYX_ERR(0, 4595, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_upstream_to_downstream_id)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_delete_feature", 1, 4, 4, 2); __PYX_ERR(0, 4595, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 3: + if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_downstream_to_upstream_ids)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_delete_feature", 1, 4, 4, 3); __PYX_ERR(0, 4595, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_delete_feature") < 0)) __PYX_ERR(0, 4595, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { + 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); + values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + } + __pyx_v_stream_feature = values[0]; + __pyx_v_stream_layer = values[1]; + __pyx_v_upstream_to_downstream_id = values[2]; + __pyx_v_downstream_to_upstream_ids = values[3]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("_delete_feature", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 4595, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pygeoprocessing.routing.routing._delete_feature", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing_28_delete_feature(__pyx_self, __pyx_v_stream_feature, __pyx_v_stream_layer, __pyx_v_upstream_to_downstream_id, __pyx_v_downstream_to_upstream_ids); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_28_delete_feature(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_stream_feature, PyObject *__pyx_v_stream_layer, PyObject *__pyx_v_upstream_to_downstream_id, PyObject *__pyx_v_downstream_to_upstream_ids) { + PyObject *__pyx_v_stream_fid = NULL; + PyObject *__pyx_v_downstream_fid = 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; + int __pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_delete_feature", 0); + + /* "pygeoprocessing/routing/routing.pyx":4612 + * None. + * """ + * stream_fid = stream_feature.GetFID() # <<<<<<<<<<<<<< + * if stream_fid in upstream_to_downstream_id: + * downstream_fid = upstream_to_downstream_id[ + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetFID); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4612, __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); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4612, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_stream_fid = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4613 + * """ + * stream_fid = stream_feature.GetFID() + * if stream_fid in upstream_to_downstream_id: # <<<<<<<<<<<<<< + * downstream_fid = upstream_to_downstream_id[ + * stream_fid] + */ + __pyx_t_4 = (__Pyx_PySequence_ContainsTF(__pyx_v_stream_fid, __pyx_v_upstream_to_downstream_id, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 4613, __pyx_L1_error) + __pyx_t_5 = (__pyx_t_4 != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":4614 + * stream_fid = stream_feature.GetFID() + * if stream_fid in upstream_to_downstream_id: + * downstream_fid = upstream_to_downstream_id[ # <<<<<<<<<<<<<< + * stream_fid] + * del upstream_to_downstream_id[stream_fid] + */ + __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_upstream_to_downstream_id, __pyx_v_stream_fid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4614, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_downstream_fid = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4616 + * downstream_fid = upstream_to_downstream_id[ + * stream_fid] + * del upstream_to_downstream_id[stream_fid] # <<<<<<<<<<<<<< + * if downstream_fid in downstream_to_upstream_ids: + * downstream_to_upstream_ids[ + */ + if (unlikely(PyObject_DelItem(__pyx_v_upstream_to_downstream_id, __pyx_v_stream_fid) < 0)) __PYX_ERR(0, 4616, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":4617 + * stream_fid] + * del upstream_to_downstream_id[stream_fid] + * if downstream_fid in downstream_to_upstream_ids: # <<<<<<<<<<<<<< + * downstream_to_upstream_ids[ + * downstream_fid].remove(stream_fid) + */ + __pyx_t_5 = (__Pyx_PySequence_ContainsTF(__pyx_v_downstream_fid, __pyx_v_downstream_to_upstream_ids, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 4617, __pyx_L1_error) + __pyx_t_4 = (__pyx_t_5 != 0); + if (__pyx_t_4) { + + /* "pygeoprocessing/routing/routing.pyx":4618 + * del upstream_to_downstream_id[stream_fid] + * if downstream_fid in downstream_to_upstream_ids: + * downstream_to_upstream_ids[ # <<<<<<<<<<<<<< + * downstream_fid].remove(stream_fid) + * if stream_fid in downstream_to_upstream_ids: + */ + __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_downstream_to_upstream_ids, __pyx_v_downstream_fid); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4618, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + + /* "pygeoprocessing/routing/routing.pyx":4619 + * if downstream_fid in downstream_to_upstream_ids: + * downstream_to_upstream_ids[ + * downstream_fid].remove(stream_fid) # <<<<<<<<<<<<<< + * if stream_fid in downstream_to_upstream_ids: + * del downstream_to_upstream_ids[ + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_remove); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4619, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_stream_fid) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_stream_fid); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4619, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4617 + * stream_fid] + * del upstream_to_downstream_id[stream_fid] + * if downstream_fid in downstream_to_upstream_ids: # <<<<<<<<<<<<<< + * downstream_to_upstream_ids[ + * downstream_fid].remove(stream_fid) + */ + } + + /* "pygeoprocessing/routing/routing.pyx":4613 + * """ + * stream_fid = stream_feature.GetFID() + * if stream_fid in upstream_to_downstream_id: # <<<<<<<<<<<<<< + * downstream_fid = upstream_to_downstream_id[ + * stream_fid] + */ + } + + /* "pygeoprocessing/routing/routing.pyx":4620 + * downstream_to_upstream_ids[ + * downstream_fid].remove(stream_fid) + * if stream_fid in downstream_to_upstream_ids: # <<<<<<<<<<<<<< + * del downstream_to_upstream_ids[ + * stream_fid] + */ + __pyx_t_4 = (__Pyx_PySequence_ContainsTF(__pyx_v_stream_fid, __pyx_v_downstream_to_upstream_ids, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 4620, __pyx_L1_error) + __pyx_t_5 = (__pyx_t_4 != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/routing.pyx":4622 + * if stream_fid in downstream_to_upstream_ids: + * del downstream_to_upstream_ids[ + * stream_fid] # <<<<<<<<<<<<<< + * stream_layer.DeleteFeature(stream_fid) + */ + if (unlikely(PyObject_DelItem(__pyx_v_downstream_to_upstream_ids, __pyx_v_stream_fid) < 0)) __PYX_ERR(0, 4621, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":4620 + * downstream_to_upstream_ids[ + * downstream_fid].remove(stream_fid) + * if stream_fid in downstream_to_upstream_ids: # <<<<<<<<<<<<<< + * del downstream_to_upstream_ids[ + * stream_fid] + */ + } + + /* "pygeoprocessing/routing/routing.pyx":4623 + * del downstream_to_upstream_ids[ + * stream_fid] + * stream_layer.DeleteFeature(stream_fid) # <<<<<<<<<<<<<< + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_DeleteFeature); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4623, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_stream_fid) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_stream_fid); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4623, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4595 + * + * + * def _delete_feature( # <<<<<<<<<<<<<< + * stream_feature, stream_layer, upstream_to_downstream_id, + * downstream_to_upstream_ids): + */ + + /* 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_AddTraceback("pygeoprocessing.routing.routing._delete_feature", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_stream_fid); + __Pyx_XDECREF(__pyx_v_downstream_fid); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":735 + * ctypedef npy_cdouble complex_t + * + * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(1, 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("PyArray_MultiIterNew1", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":736 + * + * cdef inline object PyArray_MultiIterNew1(a): + * return PyArray_MultiIterNew(1, 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, 736, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":735 + * ctypedef npy_cdouble complex_t + * + * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(1, 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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":738 + * return PyArray_MultiIterNew(1, a) + * + * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(2, a, 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("PyArray_MultiIterNew2", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":739 + * + * cdef inline object PyArray_MultiIterNew2(a, b): + * return PyArray_MultiIterNew(2, a, 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, 739, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":738 + * return PyArray_MultiIterNew(1, a) + * + * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(2, a, 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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":741 + * return PyArray_MultiIterNew(2, a, b) + * + * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(3, a, b, 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("PyArray_MultiIterNew3", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":742 + * + * cdef inline object PyArray_MultiIterNew3(a, b, c): + * return PyArray_MultiIterNew(3, a, b, 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, 742, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":741 + * return PyArray_MultiIterNew(2, a, b) + * + * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(3, a, b, 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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":744 + * return PyArray_MultiIterNew(3, a, b, c) + * + * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(4, a, b, c, 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("PyArray_MultiIterNew4", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":745 + * + * cdef inline object PyArray_MultiIterNew4(a, b, c, d): + * return PyArray_MultiIterNew(4, a, b, c, 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, 745, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":744 + * return PyArray_MultiIterNew(3, a, b, c) + * + * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(4, a, b, c, 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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":747 + * return PyArray_MultiIterNew(4, a, b, c, d) + * + * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(5, a, b, c, d, 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("PyArray_MultiIterNew5", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":748 + * + * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): + * return PyArray_MultiIterNew(5, a, b, c, d, 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, 748, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":747 + * return PyArray_MultiIterNew(4, a, b, c, d) + * + * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(5, a, b, c, d, 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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":750 + * return PyArray_MultiIterNew(5, a, b, c, d, e) + * + * cdef inline tuple PyDataType_SHAPE(dtype d): # <<<<<<<<<<<<<< + * if PyDataType_HASSUBARRAY(d): + * return 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); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":751 + * + * cdef inline tuple PyDataType_SHAPE(dtype d): + * if PyDataType_HASSUBARRAY(d): # <<<<<<<<<<<<<< + * return d.subarray.shape + * else: + */ + __pyx_t_1 = (PyDataType_HASSUBARRAY(__pyx_v_d) != 0); + if (__pyx_t_1) { + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":752 + * cdef inline tuple PyDataType_SHAPE(dtype d): + * if PyDataType_HASSUBARRAY(d): + * return 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; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":751 + * + * cdef inline tuple PyDataType_SHAPE(dtype d): + * if PyDataType_HASSUBARRAY(d): # <<<<<<<<<<<<<< + * return d.subarray.shape + * else: + */ + } + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":754 + * return d.subarray.shape + * else: + * return () # <<<<<<<<<<<<<< + * + * + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_empty_tuple); + __pyx_r = __pyx_empty_tuple; + goto __pyx_L0; + } + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":750 + * return PyArray_MultiIterNew(5, a, b, c, d, e) + * + * cdef inline tuple PyDataType_SHAPE(dtype d): # <<<<<<<<<<<<<< + * if PyDataType_HASSUBARRAY(d): + * return d.subarray.shape + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":931 + * int _import_umath() except -1 + * + * cdef inline void set_array_base(ndarray arr, object base): # <<<<<<<<<<<<<< + * Py_INCREF(base) # important to do this before stealing the reference below! + * PyArray_SetBaseObject(arr, base) + */ + +static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_arr, PyObject *__pyx_v_base) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("set_array_base", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":932 + * + * cdef inline void set_array_base(ndarray arr, object base): + * Py_INCREF(base) # important to do this before stealing the reference below! # <<<<<<<<<<<<<< + * PyArray_SetBaseObject(arr, base) + * + */ + Py_INCREF(__pyx_v_base); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":933 + * cdef inline void set_array_base(ndarray arr, object base): + * Py_INCREF(base) # important to do this before stealing the reference below! + * PyArray_SetBaseObject(arr, base) # <<<<<<<<<<<<<< + * + * cdef inline object get_array_base(ndarray arr): + */ + (void)(PyArray_SetBaseObject(__pyx_v_arr, __pyx_v_base)); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":931 + * int _import_umath() except -1 + * + * cdef inline void set_array_base(ndarray arr, object base): # <<<<<<<<<<<<<< + * Py_INCREF(base) # important to do this before stealing the reference below! + * PyArray_SetBaseObject(arr, base) + */ + + /* function exit code */ + __Pyx_RefNannyFinishContext(); +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":935 + * PyArray_SetBaseObject(arr, base) + * + * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< + * base = PyArray_BASE(arr) + * if base is NULL: + */ + +static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__pyx_v_arr) { + PyObject *__pyx_v_base; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("get_array_base", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":936 + * + * cdef inline object get_array_base(ndarray arr): + * base = PyArray_BASE(arr) # <<<<<<<<<<<<<< + * if base is NULL: + * return None + */ + __pyx_v_base = PyArray_BASE(__pyx_v_arr); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":937 + * cdef inline object get_array_base(ndarray arr): + * base = PyArray_BASE(arr) + * if base is NULL: # <<<<<<<<<<<<<< + * return None + * return base + */ + __pyx_t_1 = ((__pyx_v_base == NULL) != 0); + if (__pyx_t_1) { + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":938 + * base = PyArray_BASE(arr) + * if base is NULL: + * return None # <<<<<<<<<<<<<< + * return base + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":937 + * cdef inline object get_array_base(ndarray arr): + * base = PyArray_BASE(arr) + * if base is NULL: # <<<<<<<<<<<<<< + * return None + * return base + */ + } + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":939 + * if base is NULL: + * return None + * return base # <<<<<<<<<<<<<< + * + * # Versions of the import_* functions which are more suitable for + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_base)); + __pyx_r = ((PyObject *)__pyx_v_base); + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":935 + * PyArray_SetBaseObject(arr, base) + * + * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< + * base = PyArray_BASE(arr) + * if base is NULL: + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":943 + * # Versions of the import_* functions which are more suitable for + * # Cython code. + * cdef inline int import_array() except -1: # <<<<<<<<<<<<<< + * try: + * __pyx_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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("import_array", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":944 + * # Cython code. + * cdef inline int import_array() except -1: + * try: # <<<<<<<<<<<<<< + * __pyx_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:*/ { + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":945 + * cdef inline int import_array() except -1: + * try: + * __pyx_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, 945, __pyx_L3_error) + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":944 + * # Cython code. + * cdef inline int import_array() except -1: + * try: # <<<<<<<<<<<<<< + * __pyx_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:; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":946 + * try: + * __pyx_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, 946, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_7); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":947 + * __pyx_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__24, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 947, __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, 947, __pyx_L5_except_error) + } + goto __pyx_L5_except_error; + __pyx_L5_except_error:; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":944 + * # Cython code. + * cdef inline int import_array() except -1: + * try: # <<<<<<<<<<<<<< + * __pyx_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:; + } + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":943 + * # Versions of the import_* functions which are more suitable for + * # Cython code. + * cdef inline int import_array() except -1: # <<<<<<<<<<<<<< + * try: + * __pyx_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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":949 + * 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("import_umath", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":950 + * + * 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:*/ { + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":951 + * 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, 951, __pyx_L3_error) + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":950 + * + * 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:; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":952 + * 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, 952, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_7); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":953 + * _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__25, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 953, __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, 953, __pyx_L5_except_error) + } + goto __pyx_L5_except_error; + __pyx_L5_except_error:; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":950 + * + * 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:; + } + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":949 + * 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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":955 + * 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("import_ufunc", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":956 + * + * 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:*/ { + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":957 + * 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, 957, __pyx_L3_error) + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":956 + * + * 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:; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":958 + * 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, 958, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_7); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":959 + * _import_umath() + * except Exception: + * raise ImportError("numpy.core.umath failed to import") # <<<<<<<<<<<<<< + * + * cdef extern from *: + */ + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 959, __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, 959, __pyx_L5_except_error) + } + goto __pyx_L5_except_error; + __pyx_L5_except_error:; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":956 + * + * 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:; + } + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":955 + * 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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":969 + * + * + * cdef inline bint is_timedelta64_object(object obj): # <<<<<<<<<<<<<< + * """ + * Cython equivalent of `isinstance(obj, np.timedelta64)` + */ + +static CYTHON_INLINE int __pyx_f_5numpy_is_timedelta64_object(PyObject *__pyx_v_obj) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("is_timedelta64_object", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":981 + * bool + * """ + * return PyObject_TypeCheck(obj, &PyTimedeltaArrType_Type) # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = PyObject_TypeCheck(__pyx_v_obj, (&PyTimedeltaArrType_Type)); + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":969 + * + * + * cdef inline bint is_timedelta64_object(object obj): # <<<<<<<<<<<<<< + * """ + * Cython equivalent of `isinstance(obj, np.timedelta64)` + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":984 + * + * + * cdef inline bint is_datetime64_object(object obj): # <<<<<<<<<<<<<< + * """ + * Cython equivalent of `isinstance(obj, np.datetime64)` + */ + +static CYTHON_INLINE int __pyx_f_5numpy_is_datetime64_object(PyObject *__pyx_v_obj) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("is_datetime64_object", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":996 + * bool + * """ + * return PyObject_TypeCheck(obj, &PyDatetimeArrType_Type) # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = PyObject_TypeCheck(__pyx_v_obj, (&PyDatetimeArrType_Type)); + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":984 + * + * + * cdef inline bint is_datetime64_object(object obj): # <<<<<<<<<<<<<< + * """ + * Cython equivalent of `isinstance(obj, np.datetime64)` + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":999 + * + * + * cdef inline npy_datetime get_datetime64_value(object obj) nogil: # <<<<<<<<<<<<<< + * """ + * returns the int64 value underlying scalar numpy datetime64 object + */ + +static CYTHON_INLINE npy_datetime __pyx_f_5numpy_get_datetime64_value(PyObject *__pyx_v_obj) { + npy_datetime __pyx_r; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1006 + * also needed. That can be found using `get_datetime64_unit`. + * """ + * return (obj).obval # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = ((PyDatetimeScalarObject *)__pyx_v_obj)->obval; + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":999 + * + * + * cdef inline npy_datetime get_datetime64_value(object obj) nogil: # <<<<<<<<<<<<<< + * """ + * returns the int64 value underlying scalar numpy datetime64 object + */ + + /* function exit code */ + __pyx_L0:; + return __pyx_r; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1009 + * + * + * cdef inline npy_timedelta get_timedelta64_value(object obj) nogil: # <<<<<<<<<<<<<< + * """ + * returns the int64 value underlying scalar numpy timedelta64 object + */ + +static CYTHON_INLINE npy_timedelta __pyx_f_5numpy_get_timedelta64_value(PyObject *__pyx_v_obj) { + npy_timedelta __pyx_r; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1013 + * returns the int64 value underlying scalar numpy timedelta64 object + * """ + * return (obj).obval # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = ((PyTimedeltaScalarObject *)__pyx_v_obj)->obval; + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1009 + * + * + * cdef inline npy_timedelta get_timedelta64_value(object obj) nogil: # <<<<<<<<<<<<<< + * """ + * returns the int64 value underlying scalar numpy timedelta64 object + */ + + /* function exit code */ + __pyx_L0:; + return __pyx_r; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1016 + * + * + * cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil: # <<<<<<<<<<<<<< + * """ + * returns the unit part of the dtype for a numpy datetime64 object. + */ + +static CYTHON_INLINE NPY_DATETIMEUNIT __pyx_f_5numpy_get_datetime64_unit(PyObject *__pyx_v_obj) { + NPY_DATETIMEUNIT __pyx_r; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1020 + * returns the unit part of the dtype for a numpy datetime64 object. + * """ + * return (obj).obmeta.base # <<<<<<<<<<<<<< + */ + __pyx_r = ((NPY_DATETIMEUNIT)((PyDatetimeScalarObject *)__pyx_v_obj)->obmeta.base); + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1016 + * + * + * cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil: # <<<<<<<<<<<<<< + * """ + * returns the unit part of the dtype for a numpy datetime64 object. + */ + + /* function exit code */ + __pyx_L0:; + 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 (); + 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); + __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1); + __pyx_pw_15pygeoprocessing_7routing_7routing_14_ManagedRaster_3__dealloc__(o); + __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1); + 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*/ + #if PY_VERSION_HEX < 0x030800b4 + 0, /*tp_print*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 + 0, /*tp_vectorcall_offset*/ + #endif + 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 + #if PY_VERSION_HEX >= 0x030800b1 + 0, /*tp_vectorcall*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000 + 0, /*tp_print*/ + #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 +#ifndef CYTHON_SMALL_CODE +#if defined(__clang__) + #define CYTHON_SMALL_CODE +#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) + #define CYTHON_SMALL_CODE __attribute__((cold)) +#else + #define CYTHON_SMALL_CODE +#endif +#endif + +static __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_kp_u_, __pyx_k_, sizeof(__pyx_k_), 0, 1, 0, 0}, + {&__pyx_kp_u_100_0_complete, __pyx_k_100_0_complete, sizeof(__pyx_k_100_0_complete), 0, 1, 0, 0}, + {&__pyx_kp_u_1f, __pyx_k_1f, sizeof(__pyx_k_1f), 0, 1, 0, 0}, + {&__pyx_kp_u_1f_complete, __pyx_k_1f_complete, sizeof(__pyx_k_1f_complete), 0, 1, 0, 0}, + {&__pyx_n_s_AddGeometry, __pyx_k_AddGeometry, sizeof(__pyx_k_AddGeometry), 0, 0, 1, 1}, + {&__pyx_n_s_AddPoint, __pyx_k_AddPoint, sizeof(__pyx_k_AddPoint), 0, 0, 1, 1}, + {&__pyx_n_s_ApplyGeoTransform, __pyx_k_ApplyGeoTransform, sizeof(__pyx_k_ApplyGeoTransform), 0, 0, 1, 1}, + {&__pyx_kp_u_BIGTIFF_YES, __pyx_k_BIGTIFF_YES, sizeof(__pyx_k_BIGTIFF_YES), 0, 1, 0, 0}, + {&__pyx_kp_u_BLOCKXSIZE_d, __pyx_k_BLOCKXSIZE_d, sizeof(__pyx_k_BLOCKXSIZE_d), 0, 1, 0, 0}, + {&__pyx_kp_u_BLOCKYSIZE_d, __pyx_k_BLOCKYSIZE_d, sizeof(__pyx_k_BLOCKYSIZE_d), 0, 1, 0, 0}, + {&__pyx_kp_u_COMPRESS_LZW, __pyx_k_COMPRESS_LZW, sizeof(__pyx_k_COMPRESS_LZW), 0, 1, 0, 0}, + {&__pyx_n_s_CommitTransaction, __pyx_k_CommitTransaction, sizeof(__pyx_k_CommitTransaction), 0, 0, 1, 1}, + {&__pyx_n_s_Create, __pyx_k_Create, sizeof(__pyx_k_Create), 0, 0, 1, 1}, + {&__pyx_n_s_CreateCopy, __pyx_k_CreateCopy, sizeof(__pyx_k_CreateCopy), 0, 0, 1, 1}, + {&__pyx_n_s_CreateFeature, __pyx_k_CreateFeature, sizeof(__pyx_k_CreateFeature), 0, 0, 1, 1}, + {&__pyx_n_s_CreateField, __pyx_k_CreateField, sizeof(__pyx_k_CreateField), 0, 0, 1, 1}, + {&__pyx_n_s_CreateGeometryFromWkb, __pyx_k_CreateGeometryFromWkb, sizeof(__pyx_k_CreateGeometryFromWkb), 0, 0, 1, 1}, + {&__pyx_n_s_CreateLayer, __pyx_k_CreateLayer, sizeof(__pyx_k_CreateLayer), 0, 0, 1, 1}, + {&__pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT, __pyx_k_DEFAULT_GTIFF_CREATION_TUPLE_OPT, sizeof(__pyx_k_DEFAULT_GTIFF_CREATION_TUPLE_OPT), 0, 0, 1, 1}, + {&__pyx_n_s_DEFAULT_OSR_AXIS_MAPPING_STRATEG, __pyx_k_DEFAULT_OSR_AXIS_MAPPING_STRATEG, sizeof(__pyx_k_DEFAULT_OSR_AXIS_MAPPING_STRATEG), 0, 0, 1, 1}, + {&__pyx_n_s_DeleteFeature, __pyx_k_DeleteFeature, sizeof(__pyx_k_DeleteFeature), 0, 0, 1, 1}, + {&__pyx_n_s_DeleteField, __pyx_k_DeleteField, sizeof(__pyx_k_DeleteField), 0, 0, 1, 1}, + {&__pyx_kp_u_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, 1, 0, 0}, + {&__pyx_kp_u_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, 1, 0, 0}, + {&__pyx_n_s_ExportToWkb, __pyx_k_ExportToWkb, sizeof(__pyx_k_ExportToWkb), 0, 0, 1, 1}, + {&__pyx_n_s_Feature, __pyx_k_Feature, sizeof(__pyx_k_Feature), 0, 0, 1, 1}, + {&__pyx_n_s_FieldDefn, __pyx_k_FieldDefn, sizeof(__pyx_k_FieldDefn), 0, 0, 1, 1}, + {&__pyx_n_s_FindFieldIndex, __pyx_k_FindFieldIndex, sizeof(__pyx_k_FindFieldIndex), 0, 0, 1, 1}, + {&__pyx_n_s_FlushCache, __pyx_k_FlushCache, sizeof(__pyx_k_FlushCache), 0, 0, 1, 1}, + {&__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_GDT_Unknown, __pyx_k_GDT_Unknown, sizeof(__pyx_k_GDT_Unknown), 0, 0, 1, 1}, + {&__pyx_n_u_GPKG, __pyx_k_GPKG, sizeof(__pyx_k_GPKG), 0, 1, 0, 1}, + {&__pyx_n_u_GTiff, __pyx_k_GTiff, sizeof(__pyx_k_GTiff), 0, 1, 0, 1}, + {&__pyx_n_s_Geometry, __pyx_k_Geometry, sizeof(__pyx_k_Geometry), 0, 0, 1, 1}, + {&__pyx_n_s_GetDriverByName, __pyx_k_GetDriverByName, sizeof(__pyx_k_GetDriverByName), 0, 0, 1, 1}, + {&__pyx_n_s_GetFID, __pyx_k_GetFID, sizeof(__pyx_k_GetFID), 0, 0, 1, 1}, + {&__pyx_n_s_GetFeature, __pyx_k_GetFeature, sizeof(__pyx_k_GetFeature), 0, 0, 1, 1}, + {&__pyx_n_s_GetField, __pyx_k_GetField, sizeof(__pyx_k_GetField), 0, 0, 1, 1}, + {&__pyx_n_s_GetGeometryRef, __pyx_k_GetGeometryRef, sizeof(__pyx_k_GetGeometryRef), 0, 0, 1, 1}, + {&__pyx_n_s_GetLayer, __pyx_k_GetLayer, sizeof(__pyx_k_GetLayer), 0, 0, 1, 1}, + {&__pyx_n_s_GetLayerDefn, __pyx_k_GetLayerDefn, sizeof(__pyx_k_GetLayerDefn), 0, 0, 1, 1}, + {&__pyx_n_s_GetRasterBand, __pyx_k_GetRasterBand, sizeof(__pyx_k_GetRasterBand), 0, 0, 1, 1}, + {&__pyx_n_u_ID, __pyx_k_ID, sizeof(__pyx_k_ID), 0, 1, 0, 1}, + {&__pyx_n_s_ImportError, __pyx_k_ImportError, sizeof(__pyx_k_ImportError), 0, 0, 1, 1}, + {&__pyx_n_s_ImportFromWkt, __pyx_k_ImportFromWkt, sizeof(__pyx_k_ImportFromWkt), 0, 0, 1, 1}, + {&__pyx_n_s_LOGGER, __pyx_k_LOGGER, sizeof(__pyx_k_LOGGER), 0, 0, 1, 1}, + {&__pyx_n_s_ManagedRaster, __pyx_k_ManagedRaster, sizeof(__pyx_k_ManagedRaster), 0, 0, 1, 1}, + {&__pyx_n_s_OFTInteger, __pyx_k_OFTInteger, sizeof(__pyx_k_OFTInteger), 0, 0, 1, 1}, + {&__pyx_n_s_OFTInteger64, __pyx_k_OFTInteger64, sizeof(__pyx_k_OFTInteger64), 0, 0, 1, 1}, + {&__pyx_n_s_OFTReal, __pyx_k_OFTReal, sizeof(__pyx_k_OFTReal), 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_OF_VECTOR, __pyx_k_OF_VECTOR, sizeof(__pyx_k_OF_VECTOR), 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_ResetReading, __pyx_k_ResetReading, sizeof(__pyx_k_ResetReading), 0, 0, 1, 1}, + {&__pyx_n_s_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 0, 0, 1, 1}, + {&__pyx_kp_u_SPARSE_OK_TRUE, __pyx_k_SPARSE_OK_TRUE, sizeof(__pyx_k_SPARSE_OK_TRUE), 0, 1, 0, 0}, + {&__pyx_n_s_SetAttributeFilter, __pyx_k_SetAttributeFilter, sizeof(__pyx_k_SetAttributeFilter), 0, 0, 1, 1}, + {&__pyx_n_s_SetAxisMappingStrategy, __pyx_k_SetAxisMappingStrategy, sizeof(__pyx_k_SetAxisMappingStrategy), 0, 0, 1, 1}, + {&__pyx_n_s_SetFeature, __pyx_k_SetFeature, sizeof(__pyx_k_SetFeature), 0, 0, 1, 1}, + {&__pyx_n_s_SetField, __pyx_k_SetField, sizeof(__pyx_k_SetField), 0, 0, 1, 1}, + {&__pyx_n_s_SetGeometry, __pyx_k_SetGeometry, sizeof(__pyx_k_SetGeometry), 0, 0, 1, 1}, + {&__pyx_n_s_SpatialReference, __pyx_k_SpatialReference, sizeof(__pyx_k_SpatialReference), 0, 0, 1, 1}, + {&__pyx_n_s_StartTransaction, __pyx_k_StartTransaction, sizeof(__pyx_k_StartTransaction), 0, 0, 1, 1}, + {&__pyx_kp_u_TILED_YES, __pyx_k_TILED_YES, sizeof(__pyx_k_TILED_YES), 0, 1, 0, 0}, + {&__pyx_kp_u_This_exception_is_happeningin_C, __pyx_k_This_exception_is_happeningin_C, sizeof(__pyx_k_This_exception_is_happeningin_C), 0, 1, 0, 0}, + {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1}, + {&__pyx_n_s_Union, __pyx_k_Union, sizeof(__pyx_k_Union), 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_u_Y_m_d__H__M__S, __pyx_k_Y_m_d__H__M__S, sizeof(__pyx_k_Y_m_d__H__M__S), 0, 1, 0, 0}, + {&__pyx_n_s__34, __pyx_k__34, sizeof(__pyx_k__34), 0, 0, 1, 1}, + {&__pyx_n_s_all_defined, __pyx_k_all_defined, sizeof(__pyx_k_all_defined), 0, 0, 1, 1}, + {&__pyx_n_s_append, __pyx_k_append, sizeof(__pyx_k_append), 0, 0, 1, 1}, + {&__pyx_n_s_astype, __pyx_k_astype, sizeof(__pyx_k_astype), 0, 0, 1, 1}, + {&__pyx_n_s_autotune_flow_accumulation, __pyx_k_autotune_flow_accumulation, sizeof(__pyx_k_autotune_flow_accumulation), 0, 0, 1, 1}, + {&__pyx_n_s_backtrace_set, __pyx_k_backtrace_set, sizeof(__pyx_k_backtrace_set), 0, 0, 1, 1}, + {&__pyx_kp_u_bak_tif, __pyx_k_bak_tif, sizeof(__pyx_k_bak_tif), 0, 1, 0, 0}, + {&__pyx_n_s_band_id, __pyx_k_band_id, sizeof(__pyx_k_band_id), 0, 0, 1, 1}, + {&__pyx_n_s_base_datatype, __pyx_k_base_datatype, sizeof(__pyx_k_base_datatype), 0, 0, 1, 1}, + {&__pyx_n_s_base_feature_count, __pyx_k_base_feature_count, sizeof(__pyx_k_base_feature_count), 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_basename, __pyx_k_basename, sizeof(__pyx_k_basename), 0, 0, 1, 1}, + {&__pyx_n_s_block_array, __pyx_k_block_array, sizeof(__pyx_k_block_array), 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_offsets_list, __pyx_k_block_offsets_list, sizeof(__pyx_k_block_offsets_list), 0, 0, 1, 1}, + {&__pyx_n_u_block_size, __pyx_k_block_size, sizeof(__pyx_k_block_size), 0, 1, 0, 1}, + {&__pyx_n_s_boundary_list, __pyx_k_boundary_list, sizeof(__pyx_k_boundary_list), 0, 0, 1, 1}, + {&__pyx_n_s_boundary_x, __pyx_k_boundary_x, sizeof(__pyx_k_boundary_x), 0, 0, 1, 1}, + {&__pyx_n_s_boundary_y, __pyx_k_boundary_y, sizeof(__pyx_k_boundary_y), 0, 0, 1, 1}, + {&__pyx_n_s_build_discovery_finish_rasters, __pyx_k_build_discovery_finish_rasters, sizeof(__pyx_k_build_discovery_finish_rasters), 0, 0, 1, 1}, + {&__pyx_n_u_calculate_subwatershed_boundary, __pyx_k_calculate_subwatershed_boundary, sizeof(__pyx_k_calculate_subwatershed_boundary), 0, 1, 0, 1}, + {&__pyx_kp_u_calculate_subwatershed_boundary_2, __pyx_k_calculate_subwatershed_boundary_2, sizeof(__pyx_k_calculate_subwatershed_boundary_2), 0, 1, 0, 0}, + {&__pyx_kp_u_calculate_subwatershed_boundary_3, __pyx_k_calculate_subwatershed_boundary_3, sizeof(__pyx_k_calculate_subwatershed_boundary_3), 0, 1, 0, 0}, + {&__pyx_n_s_calculate_subwatershed_boundary_4, __pyx_k_calculate_subwatershed_boundary_4, sizeof(__pyx_k_calculate_subwatershed_boundary_4), 0, 0, 1, 1}, + {&__pyx_n_s_cell_to_test, __pyx_k_cell_to_test, sizeof(__pyx_k_cell_to_test), 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_collections, __pyx_k_collections, sizeof(__pyx_k_collections), 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_u_compatable_dem_tif, __pyx_k_compatable_dem_tif, sizeof(__pyx_k_compatable_dem_tif), 0, 1, 0, 0}, + {&__pyx_kp_u_compatible_dem_complete, __pyx_k_compatible_dem_complete, sizeof(__pyx_k_compatible_dem_complete), 0, 1, 0, 0}, + {&__pyx_kp_u_complete, __pyx_k_complete, sizeof(__pyx_k_complete), 0, 1, 0, 0}, + {&__pyx_kp_u_complete_2, __pyx_k_complete_2, sizeof(__pyx_k_complete_2), 0, 1, 0, 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_connected_fid, __pyx_k_connected_fid, sizeof(__pyx_k_connected_fid), 0, 0, 1, 1}, + {&__pyx_n_s_connected_fids, __pyx_k_connected_fids, sizeof(__pyx_k_connected_fids), 0, 0, 1, 1}, + {&__pyx_n_s_connected_upstream_fids, __pyx_k_connected_upstream_fids, sizeof(__pyx_k_connected_upstream_fids), 0, 0, 1, 1}, + {&__pyx_n_s_coord_to_stream_ids, __pyx_k_coord_to_stream_ids, sizeof(__pyx_k_coord_to_stream_ids), 0, 0, 1, 1}, + {&__pyx_n_s_copy, __pyx_k_copy, sizeof(__pyx_k_copy), 0, 0, 1, 1}, + {&__pyx_n_s_copyfile, __pyx_k_copyfile, sizeof(__pyx_k_copyfile), 0, 0, 1, 1}, + {&__pyx_kp_u_could_not_open, __pyx_k_could_not_open, sizeof(__pyx_k_could_not_open), 0, 1, 0, 0}, + {&__pyx_kp_u_couldn_t_remove_temp_dir, __pyx_k_couldn_t_remove_temp_dir, sizeof(__pyx_k_couldn_t_remove_temp_dir), 0, 1, 0, 0}, + {&__pyx_kp_u_creating_target_flow_accum_raste, __pyx_k_creating_target_flow_accum_raste, sizeof(__pyx_k_creating_target_flow_accum_raste), 0, 1, 0, 0}, + {&__pyx_kp_u_creating_visited_raster_layer, __pyx_k_creating_visited_raster_layer, sizeof(__pyx_k_creating_visited_raster_layer), 0, 1, 0, 0}, + {&__pyx_n_s_current_pixel, __pyx_k_current_pixel, sizeof(__pyx_k_current_pixel), 0, 0, 1, 1}, + {&__pyx_n_s_d, __pyx_k_d, sizeof(__pyx_k_d), 0, 0, 1, 1}, + {&__pyx_n_u_d, __pyx_k_d, sizeof(__pyx_k_d), 0, 1, 0, 1}, + {&__pyx_n_u_d8, __pyx_k_d8, sizeof(__pyx_k_d8), 0, 1, 0, 1}, + {&__pyx_n_s_d8_flow_dir_managed_raster, __pyx_k_d8_flow_dir_managed_raster, sizeof(__pyx_k_d8_flow_dir_managed_raster), 0, 0, 1, 1}, + {&__pyx_n_s_d8_flow_dir_mode, __pyx_k_d8_flow_dir_mode, sizeof(__pyx_k_d8_flow_dir_mode), 0, 0, 1, 1}, + {&__pyx_n_s_d8_flow_dir_raster_path_band, __pyx_k_d8_flow_dir_raster_path_band, sizeof(__pyx_k_d8_flow_dir_raster_path_band), 0, 0, 1, 1}, + {&__pyx_n_s_d_n, __pyx_k_d_n, sizeof(__pyx_k_d_n), 0, 0, 1, 1}, + {&__pyx_n_u_datatype, __pyx_k_datatype, sizeof(__pyx_k_datatype), 0, 1, 0, 1}, + {&__pyx_n_s_debug, __pyx_k_debug, sizeof(__pyx_k_debug), 0, 0, 1, 1}, + {&__pyx_n_s_defaultdict, __pyx_k_defaultdict, sizeof(__pyx_k_defaultdict), 0, 0, 1, 1}, + {&__pyx_n_s_delete_feature, __pyx_k_delete_feature, sizeof(__pyx_k_delete_feature), 0, 0, 1, 1}, + {&__pyx_n_s_deleted_set, __pyx_k_deleted_set, sizeof(__pyx_k_deleted_set), 0, 0, 1, 1}, + {&__pyx_n_s_delta_x, __pyx_k_delta_x, sizeof(__pyx_k_delta_x), 0, 0, 1, 1}, + {&__pyx_n_s_delta_y, __pyx_k_delta_y, sizeof(__pyx_k_delta_y), 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_u_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, 1, 0, 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_detect_outlets, __pyx_k_detect_outlets, sizeof(__pyx_k_detect_outlets), 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_dirname, __pyx_k_dirname, sizeof(__pyx_k_dirname), 0, 0, 1, 1}, + {&__pyx_n_s_discovery, __pyx_k_discovery, sizeof(__pyx_k_discovery), 0, 0, 1, 1}, + {&__pyx_n_s_discovery_count, __pyx_k_discovery_count, sizeof(__pyx_k_discovery_count), 0, 0, 1, 1}, + {&__pyx_n_s_discovery_info, __pyx_k_discovery_info, sizeof(__pyx_k_discovery_info), 0, 0, 1, 1}, + {&__pyx_n_s_discovery_managed_raster, __pyx_k_discovery_managed_raster, sizeof(__pyx_k_discovery_managed_raster), 0, 0, 1, 1}, + {&__pyx_n_s_discovery_nodata, __pyx_k_discovery_nodata, sizeof(__pyx_k_discovery_nodata), 0, 0, 1, 1}, + {&__pyx_n_s_discovery_srs, __pyx_k_discovery_srs, sizeof(__pyx_k_discovery_srs), 0, 0, 1, 1}, + {&__pyx_n_s_discovery_stack, __pyx_k_discovery_stack, sizeof(__pyx_k_discovery_stack), 0, 0, 1, 1}, + {&__pyx_kp_u_discovery_tif, __pyx_k_discovery_tif, sizeof(__pyx_k_discovery_tif), 0, 1, 0, 0}, + {&__pyx_kp_u_discovery_time_processing, __pyx_k_discovery_time_processing, sizeof(__pyx_k_discovery_time_processing), 0, 1, 0, 0}, + {&__pyx_n_s_discovery_time_raster_path, __pyx_k_discovery_time_raster_path, sizeof(__pyx_k_discovery_time_raster_path), 0, 0, 1, 1}, + {&__pyx_n_u_dist_to_channel_mfd_work_dir, __pyx_k_dist_to_channel_mfd_work_dir, sizeof(__pyx_k_dist_to_channel_mfd_work_dir), 0, 1, 0, 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_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_downstream_dem, __pyx_k_downstream_dem, sizeof(__pyx_k_downstream_dem), 0, 0, 1, 1}, + {&__pyx_n_s_downstream_feature, __pyx_k_downstream_feature, sizeof(__pyx_k_downstream_feature), 0, 0, 1, 1}, + {&__pyx_n_s_downstream_fid, __pyx_k_downstream_fid, sizeof(__pyx_k_downstream_fid), 0, 0, 1, 1}, + {&__pyx_n_s_downstream_geom, __pyx_k_downstream_geom, sizeof(__pyx_k_downstream_geom), 0, 0, 1, 1}, + {&__pyx_n_s_downstream_order, __pyx_k_downstream_order, sizeof(__pyx_k_downstream_order), 0, 0, 1, 1}, + {&__pyx_n_s_downstream_to_upstream_ids, __pyx_k_downstream_to_upstream_ids, sizeof(__pyx_k_downstream_to_upstream_ids), 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_drop_distance, __pyx_k_drop_distance, sizeof(__pyx_k_drop_distance), 0, 0, 1, 1}, + {&__pyx_n_u_drop_distance, __pyx_k_drop_distance, sizeof(__pyx_k_drop_distance), 0, 1, 0, 1}, + {&__pyx_n_s_drop_distance_collection, __pyx_k_drop_distance_collection, sizeof(__pyx_k_drop_distance_collection), 0, 0, 1, 1}, + {&__pyx_n_u_ds_fa, __pyx_k_ds_fa, sizeof(__pyx_k_ds_fa), 0, 1, 0, 1}, + {&__pyx_n_s_ds_x, __pyx_k_ds_x, sizeof(__pyx_k_ds_x), 0, 0, 1, 1}, + {&__pyx_n_u_ds_x, __pyx_k_ds_x, sizeof(__pyx_k_ds_x), 0, 1, 0, 1}, + {&__pyx_n_s_ds_x_1, __pyx_k_ds_x_1, sizeof(__pyx_k_ds_x_1), 0, 0, 1, 1}, + {&__pyx_n_u_ds_x_1, __pyx_k_ds_x_1, sizeof(__pyx_k_ds_x_1), 0, 1, 0, 1}, + {&__pyx_n_s_ds_y, __pyx_k_ds_y, sizeof(__pyx_k_ds_y), 0, 0, 1, 1}, + {&__pyx_n_u_ds_y, __pyx_k_ds_y, sizeof(__pyx_k_ds_y), 0, 1, 0, 1}, + {&__pyx_n_s_ds_y_1, __pyx_k_ds_y_1, sizeof(__pyx_k_ds_y_1), 0, 0, 1, 1}, + {&__pyx_n_u_ds_y_1, __pyx_k_ds_y_1, sizeof(__pyx_k_ds_y_1), 0, 1, 0, 1}, + {&__pyx_n_s_dtype, __pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 0, 1, 1}, + {&__pyx_n_s_edge_dir, __pyx_k_edge_dir, sizeof(__pyx_k_edge_dir), 0, 0, 1, 1}, + {&__pyx_n_s_edge_side, __pyx_k_edge_side, sizeof(__pyx_k_edge_side), 0, 0, 1, 1}, + {&__pyx_n_s_empty, __pyx_k_empty, sizeof(__pyx_k_empty), 0, 0, 1, 1}, + {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1}, + {&__pyx_n_s_equal_var, __pyx_k_equal_var, sizeof(__pyx_k_equal_var), 0, 0, 1, 1}, + {&__pyx_n_s_error, __pyx_k_error, sizeof(__pyx_k_error), 0, 0, 1, 1}, + {&__pyx_n_s_exception, __pyx_k_exception, sizeof(__pyx_k_exception), 0, 0, 1, 1}, + {&__pyx_n_s_exists, __pyx_k_exists, sizeof(__pyx_k_exists), 0, 0, 1, 1}, + {&__pyx_kp_u_exists_removing_before_creating, __pyx_k_exists_removing_before_creating, sizeof(__pyx_k_exists_removing_before_creating), 0, 1, 0, 0}, + {&__pyx_kp_u_expected_flow_dir_type_of_either, __pyx_k_expected_flow_dir_type_of_either, sizeof(__pyx_k_expected_flow_dir_type_of_either), 0, 1, 0, 0}, + {&__pyx_n_s_extract_strahler_streams_d8, __pyx_k_extract_strahler_streams_d8, sizeof(__pyx_k_extract_strahler_streams_d8), 0, 0, 1, 1}, + {&__pyx_kp_u_extract_strahler_streams_d8_all, __pyx_k_extract_strahler_streams_d8_all, sizeof(__pyx_k_extract_strahler_streams_d8_all), 0, 1, 0, 0}, + {&__pyx_kp_u_extract_strahler_streams_d8_com, __pyx_k_extract_strahler_streams_d8_com, sizeof(__pyx_k_extract_strahler_streams_d8_com), 0, 1, 0, 0}, + {&__pyx_kp_u_extract_strahler_streams_d8_det, __pyx_k_extract_strahler_streams_d8_det, sizeof(__pyx_k_extract_strahler_streams_d8_det), 0, 1, 0, 0}, + {&__pyx_kp_u_extract_strahler_streams_d8_det_2, __pyx_k_extract_strahler_streams_d8_det_2, sizeof(__pyx_k_extract_strahler_streams_d8_det_2), 0, 1, 0, 0}, + {&__pyx_kp_u_extract_strahler_streams_d8_dra, __pyx_k_extract_strahler_streams_d8_dra, sizeof(__pyx_k_extract_strahler_streams_d8_dra), 0, 1, 0, 0}, + {&__pyx_kp_u_extract_strahler_streams_d8_dra_2, __pyx_k_extract_strahler_streams_d8_dra_2, sizeof(__pyx_k_extract_strahler_streams_d8_dra_2), 0, 1, 0, 0}, + {&__pyx_kp_u_extract_strahler_streams_d8_fin, __pyx_k_extract_strahler_streams_d8_fin, sizeof(__pyx_k_extract_strahler_streams_d8_fin), 0, 1, 0, 0}, + {&__pyx_kp_u_extract_strahler_streams_d8_fin_2, __pyx_k_extract_strahler_streams_d8_fin_2, sizeof(__pyx_k_extract_strahler_streams_d8_fin_2), 0, 1, 0, 0}, + {&__pyx_kp_u_extract_strahler_streams_d8_fin_3, __pyx_k_extract_strahler_streams_d8_fin_3, sizeof(__pyx_k_extract_strahler_streams_d8_fin_3), 0, 1, 0, 0}, + {&__pyx_kp_u_extract_strahler_streams_d8_flo, __pyx_k_extract_strahler_streams_d8_flo, sizeof(__pyx_k_extract_strahler_streams_d8_flo), 0, 1, 0, 0}, + {&__pyx_kp_u_extract_strahler_streams_d8_flo_2, __pyx_k_extract_strahler_streams_d8_flo_2, sizeof(__pyx_k_extract_strahler_streams_d8_flo_2), 0, 1, 0, 0}, + {&__pyx_kp_u_extract_strahler_streams_d8_see, __pyx_k_extract_strahler_streams_d8_see, sizeof(__pyx_k_extract_strahler_streams_d8_see), 0, 1, 0, 0}, + {&__pyx_kp_u_extract_strahler_streams_d8_sta, __pyx_k_extract_strahler_streams_d8_sta, sizeof(__pyx_k_extract_strahler_streams_d8_sta), 0, 1, 0, 0}, + {&__pyx_kp_u_extract_strahler_streams_d8_str, __pyx_k_extract_strahler_streams_d8_str, sizeof(__pyx_k_extract_strahler_streams_d8_str), 0, 1, 0, 0}, + {&__pyx_kp_u_extract_strahler_streams_d8_str_2, __pyx_k_extract_strahler_streams_d8_str_2, sizeof(__pyx_k_extract_strahler_streams_d8_str_2), 0, 1, 0, 0}, + {&__pyx_kp_u_extract_strahler_streams_d8_str_3, __pyx_k_extract_strahler_streams_d8_str_3, sizeof(__pyx_k_extract_strahler_streams_d8_str_3), 0, 1, 0, 0}, + {&__pyx_kp_u_extract_strahler_streams_d8_str_4, __pyx_k_extract_strahler_streams_d8_str_4, sizeof(__pyx_k_extract_strahler_streams_d8_str_4), 0, 1, 0, 0}, + {&__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_fid, __pyx_k_fid, sizeof(__pyx_k_fid), 0, 0, 1, 1}, + {&__pyx_n_s_fid_to_order, __pyx_k_fid_to_order, sizeof(__pyx_k_fid_to_order), 0, 0, 1, 1}, + {&__pyx_n_s_fill_height, __pyx_k_fill_height, sizeof(__pyx_k_fill_height), 0, 0, 1, 1}, + {&__pyx_kp_u_fill_pits, __pyx_k_fill_pits, sizeof(__pyx_k_fill_pits), 0, 1, 0, 0}, + {&__pyx_n_s_fill_pits_2, __pyx_k_fill_pits_2, sizeof(__pyx_k_fill_pits_2), 0, 0, 1, 1}, + {&__pyx_kp_u_fill_pits__s, __pyx_k_fill_pits__s, sizeof(__pyx_k_fill_pits__s), 0, 1, 0, 0}, + {&__pyx_kp_u_fill_pits_complete, __pyx_k_fill_pits_complete, sizeof(__pyx_k_fill_pits_complete), 0, 1, 0, 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_band, __pyx_k_filled_dem_band, sizeof(__pyx_k_filled_dem_band), 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_n_s_filled_dem_raster, __pyx_k_filled_dem_raster, sizeof(__pyx_k_filled_dem_raster), 0, 0, 1, 1}, + {&__pyx_kp_u_filter_out_incomplete_divergent, __pyx_k_filter_out_incomplete_divergent, sizeof(__pyx_k_filter_out_incomplete_divergent), 0, 1, 0, 0}, + {&__pyx_n_s_finish, __pyx_k_finish, sizeof(__pyx_k_finish), 0, 0, 1, 1}, + {&__pyx_n_s_finish_coordinate, __pyx_k_finish_coordinate, sizeof(__pyx_k_finish_coordinate), 0, 0, 1, 1}, + {&__pyx_n_s_finish_managed_raster, __pyx_k_finish_managed_raster, sizeof(__pyx_k_finish_managed_raster), 0, 0, 1, 1}, + {&__pyx_n_s_finish_stack, __pyx_k_finish_stack, sizeof(__pyx_k_finish_stack), 0, 0, 1, 1}, + {&__pyx_kp_u_finish_tif, __pyx_k_finish_tif, sizeof(__pyx_k_finish_tif), 0, 1, 0, 0}, + {&__pyx_n_s_finish_time_raster_path, __pyx_k_finish_time_raster_path, sizeof(__pyx_k_finish_time_raster_path), 0, 0, 1, 1}, + {&__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_u_flat_region_mask_tif, __pyx_k_flat_region_mask_tif, sizeof(__pyx_k_flat_region_mask_tif), 0, 1, 0, 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_block, __pyx_k_flow_dir_block, sizeof(__pyx_k_flow_dir_block), 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_kp_u_flow_dir_d8, __pyx_k_flow_dir_d8, sizeof(__pyx_k_flow_dir_d8), 0, 1, 0, 0}, + {&__pyx_n_s_flow_dir_d8_2, __pyx_k_flow_dir_d8_2, sizeof(__pyx_k_flow_dir_d8_2), 0, 0, 1, 1}, + {&__pyx_kp_u_flow_dir_d8__s, __pyx_k_flow_dir_d8__s, sizeof(__pyx_k_flow_dir_d8__s), 0, 1, 0, 0}, + {&__pyx_kp_u_flow_dir_d8_complete, __pyx_k_flow_dir_d8_complete, sizeof(__pyx_k_flow_dir_d8_complete), 0, 1, 0, 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_info, __pyx_k_flow_dir_info, sizeof(__pyx_k_flow_dir_info), 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_u_flow_dir_multiple_flow_dir__s, __pyx_k_flow_dir_multiple_flow_dir__s, sizeof(__pyx_k_flow_dir_multiple_flow_dir__s), 0, 1, 0, 0}, + {&__pyx_n_s_flow_dir_n, __pyx_k_flow_dir_n, sizeof(__pyx_k_flow_dir_n), 0, 0, 1, 1}, + {&__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_srs, __pyx_k_flow_dir_srs, sizeof(__pyx_k_flow_dir_srs), 0, 0, 1, 1}, + {&__pyx_n_s_flow_dir_type, __pyx_k_flow_dir_type, sizeof(__pyx_k_flow_dir_type), 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_nodata, __pyx_k_flow_nodata, sizeof(__pyx_k_flow_nodata), 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_kp_u_for_writing, __pyx_k_for_writing, sizeof(__pyx_k_for_writing), 0, 1, 0, 0}, + {&__pyx_n_s_g0, __pyx_k_g0, sizeof(__pyx_k_g0), 0, 0, 1, 1}, + {&__pyx_n_s_g1, __pyx_k_g1, sizeof(__pyx_k_g1), 0, 0, 1, 1}, + {&__pyx_n_s_g2, __pyx_k_g2, sizeof(__pyx_k_g2), 0, 0, 1, 1}, + {&__pyx_n_s_g3, __pyx_k_g3, sizeof(__pyx_k_g3), 0, 0, 1, 1}, + {&__pyx_n_s_g4, __pyx_k_g4, sizeof(__pyx_k_g4), 0, 0, 1, 1}, + {&__pyx_n_s_g5, __pyx_k_g5, sizeof(__pyx_k_g5), 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_geoprocessing_core, __pyx_k_geoprocessing_core, sizeof(__pyx_k_geoprocessing_core), 0, 0, 1, 1}, + {&__pyx_n_s_geotransform, __pyx_k_geotransform, sizeof(__pyx_k_geotransform), 0, 0, 1, 1}, + {&__pyx_n_u_geotransform, __pyx_k_geotransform, sizeof(__pyx_k_geotransform), 0, 1, 0, 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_gpkg_driver, __pyx_k_gpkg_driver, sizeof(__pyx_k_gpkg_driver), 0, 0, 1, 1}, + {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1}, + {&__pyx_n_u_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 1, 0, 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_kp_u_in_ManagedRaster_flush, __pyx_k_in_ManagedRaster_flush, sizeof(__pyx_k_in_ManagedRaster_flush), 0, 1, 0, 0}, + {&__pyx_n_s_index, __pyx_k_index, sizeof(__pyx_k_index), 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_int_max_steps_per_watershed, __pyx_k_int_max_steps_per_watershed, sizeof(__pyx_k_int_max_steps_per_watershed), 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_drain, __pyx_k_is_drain, sizeof(__pyx_k_is_drain), 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_isnan, __pyx_k_isnan, sizeof(__pyx_k_isnan), 0, 0, 1, 1}, + {&__pyx_n_s_iterblocks, __pyx_k_iterblocks, sizeof(__pyx_k_iterblocks), 0, 0, 1, 1}, + {&__pyx_n_s_j, __pyx_k_j, sizeof(__pyx_k_j), 0, 0, 1, 1}, + {&__pyx_n_u_j, __pyx_k_j, sizeof(__pyx_k_j), 0, 1, 0, 1}, + {&__pyx_n_s_join, __pyx_k_join, sizeof(__pyx_k_join), 0, 0, 1, 1}, + {&__pyx_n_s_joined_line, __pyx_k_joined_line, sizeof(__pyx_k_joined_line), 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_left, __pyx_k_left, sizeof(__pyx_k_left), 0, 0, 1, 1}, + {&__pyx_n_s_left_in, __pyx_k_left_in, sizeof(__pyx_k_left_in), 0, 0, 1, 1}, + {&__pyx_n_s_linemerge, __pyx_k_linemerge, sizeof(__pyx_k_linemerge), 0, 0, 1, 1}, + {&__pyx_n_s_loads, __pyx_k_loads, sizeof(__pyx_k_loads), 0, 0, 1, 1}, + {&__pyx_n_s_local_flow_accum, __pyx_k_local_flow_accum, sizeof(__pyx_k_local_flow_accum), 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_lower, __pyx_k_lower, sizeof(__pyx_k_lower), 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_max, __pyx_k_max, sizeof(__pyx_k_max), 0, 0, 1, 1}, + {&__pyx_n_s_max_pixel_fill_count, __pyx_k_max_pixel_fill_count, sizeof(__pyx_k_max_pixel_fill_count), 0, 0, 1, 1}, + {&__pyx_n_s_max_steps_per_watershed, __pyx_k_max_steps_per_watershed, sizeof(__pyx_k_max_steps_per_watershed), 0, 0, 1, 1}, + {&__pyx_n_s_max_upstream_flow_accum, __pyx_k_max_upstream_flow_accum, sizeof(__pyx_k_max_upstream_flow_accum), 0, 0, 1, 1}, + {&__pyx_n_u_mfd, __pyx_k_mfd, sizeof(__pyx_k_mfd), 0, 1, 0, 1}, + {&__pyx_kp_u_mfd_flow_accum_1f_complete, __pyx_k_mfd_flow_accum_1f_complete, sizeof(__pyx_k_mfd_flow_accum_1f_complete), 0, 1, 0, 0}, + {&__pyx_n_u_mfd_flow_dir, __pyx_k_mfd_flow_dir, sizeof(__pyx_k_mfd_flow_dir), 0, 1, 0, 1}, + {&__pyx_n_s_min, __pyx_k_min, sizeof(__pyx_k_min), 0, 0, 1, 1}, + {&__pyx_n_s_min_flow_accum_threshold, __pyx_k_min_flow_accum_threshold, sizeof(__pyx_k_min_flow_accum_threshold), 0, 0, 1, 1}, + {&__pyx_n_s_min_p_val, __pyx_k_min_p_val, sizeof(__pyx_k_min_p_val), 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_kp_u_more_times, __pyx_k_more_times, sizeof(__pyx_k_more_times), 0, 1, 0, 0}, + {&__pyx_n_s_multi_line, __pyx_k_multi_line, sizeof(__pyx_k_multi_line), 0, 0, 1, 1}, + {&__pyx_n_u_n_bands, __pyx_k_n_bands, sizeof(__pyx_k_n_bands), 0, 1, 0, 1}, + {&__pyx_n_s_n_cols, __pyx_k_n_cols, sizeof(__pyx_k_n_cols), 0, 0, 1, 1}, + {&__pyx_n_s_n_dir, __pyx_k_n_dir, sizeof(__pyx_k_n_dir), 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_pixels, __pyx_k_n_pixels, sizeof(__pyx_k_n_pixels), 0, 0, 1, 1}, + {&__pyx_n_s_n_points, __pyx_k_n_points, sizeof(__pyx_k_n_points), 0, 0, 1, 1}, + {&__pyx_n_s_n_processed, __pyx_k_n_processed, sizeof(__pyx_k_n_processed), 0, 0, 1, 1}, + {&__pyx_n_s_n_pushed, __pyx_k_n_pushed, sizeof(__pyx_k_n_pushed), 0, 0, 1, 1}, + {&__pyx_n_s_n_rows, __pyx_k_n_rows, sizeof(__pyx_k_n_rows), 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_steps, __pyx_k_n_steps, sizeof(__pyx_k_n_steps), 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_n_s_natural_drain_exists, __pyx_k_natural_drain_exists, sizeof(__pyx_k_natural_drain_exists), 0, 0, 1, 1}, + {&__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_n_s_next_id, __pyx_k_next_id, sizeof(__pyx_k_next_id), 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_u_nodata, __pyx_k_nodata, sizeof(__pyx_k_nodata), 0, 1, 0, 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_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_u_numpy_core_multiarray_failed_to, __pyx_k_numpy_core_multiarray_failed_to, sizeof(__pyx_k_numpy_core_multiarray_failed_to), 0, 1, 0, 0}, + {&__pyx_kp_u_numpy_core_umath_failed_to_impor, __pyx_k_numpy_core_umath_failed_to_impor, sizeof(__pyx_k_numpy_core_umath_failed_to_impor), 0, 1, 0, 0}, + {&__pyx_kp_u_of, __pyx_k_of, sizeof(__pyx_k_of), 0, 1, 0, 0}, + {&__pyx_n_s_offset_dict, __pyx_k_offset_dict, sizeof(__pyx_k_offset_dict), 0, 0, 1, 1}, + {&__pyx_n_s_offset_info, __pyx_k_offset_info, sizeof(__pyx_k_offset_info), 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_ogr, __pyx_k_ogr, sizeof(__pyx_k_ogr), 0, 0, 1, 1}, + {&__pyx_n_s_open_set, __pyx_k_open_set, sizeof(__pyx_k_open_set), 0, 0, 1, 1}, + {&__pyx_kp_u_opening, __pyx_k_opening, sizeof(__pyx_k_opening), 0, 1, 0, 0}, + {&__pyx_n_s_ops, __pyx_k_ops, sizeof(__pyx_k_ops), 0, 0, 1, 1}, + {&__pyx_n_s_options, __pyx_k_options, sizeof(__pyx_k_options), 0, 0, 1, 1}, + {&__pyx_n_s_order, __pyx_k_order, sizeof(__pyx_k_order), 0, 0, 1, 1}, + {&__pyx_n_u_order, __pyx_k_order, sizeof(__pyx_k_order), 0, 1, 0, 1}, + {&__pyx_kp_u_order_1, __pyx_k_order_1, sizeof(__pyx_k_order_1), 0, 1, 0, 0}, + {&__pyx_n_s_order_count, __pyx_k_order_count, sizeof(__pyx_k_order_count), 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_osr, __pyx_k_osr, sizeof(__pyx_k_osr), 0, 0, 1, 1}, + {&__pyx_n_s_osr_axis_mapping_strategy, __pyx_k_osr_axis_mapping_strategy, sizeof(__pyx_k_osr_axis_mapping_strategy), 0, 0, 1, 1}, + {&__pyx_n_s_out_dir, __pyx_k_out_dir, sizeof(__pyx_k_out_dir), 0, 0, 1, 1}, + {&__pyx_n_s_out_dir_increase, __pyx_k_out_dir_increase, sizeof(__pyx_k_out_dir_increase), 0, 0, 1, 1}, + {&__pyx_kp_u_out_of_bounds_for, __pyx_k_out_of_bounds_for, sizeof(__pyx_k_out_of_bounds_for), 0, 1, 0, 0}, + {&__pyx_n_s_outet_basename, __pyx_k_outet_basename, sizeof(__pyx_k_outet_basename), 0, 0, 1, 1}, + {&__pyx_n_s_outflow_dir, __pyx_k_outflow_dir, sizeof(__pyx_k_outflow_dir), 0, 0, 1, 1}, + {&__pyx_n_u_outlet, __pyx_k_outlet, sizeof(__pyx_k_outlet), 0, 1, 0, 1}, + {&__pyx_kp_u_outlet_1, __pyx_k_outlet_1, sizeof(__pyx_k_outlet_1), 0, 1, 0, 0}, + {&__pyx_n_s_outlet_at_confluence, __pyx_k_outlet_at_confluence, sizeof(__pyx_k_outlet_at_confluence), 0, 0, 1, 1}, + {&__pyx_kp_u_outlet_detection, __pyx_k_outlet_detection, sizeof(__pyx_k_outlet_detection), 0, 1, 0, 0}, + {&__pyx_kp_u_outlet_detection_0_complete, __pyx_k_outlet_detection_0_complete, sizeof(__pyx_k_outlet_detection_0_complete), 0, 1, 0, 0}, + {&__pyx_kp_u_outlet_detection_100_complete_co, __pyx_k_outlet_detection_100_complete_co, sizeof(__pyx_k_outlet_detection_100_complete_co), 0, 1, 0, 0}, + {&__pyx_kp_u_outlet_detection_done, __pyx_k_outlet_detection_done, sizeof(__pyx_k_outlet_detection_done), 0, 1, 0, 0}, + {&__pyx_n_s_outlet_feature, __pyx_k_outlet_feature, sizeof(__pyx_k_outlet_feature), 0, 0, 1, 1}, + {&__pyx_n_s_outlet_fid, __pyx_k_outlet_fid, sizeof(__pyx_k_outlet_fid), 0, 0, 1, 1}, + {&__pyx_n_s_outlet_fid_list, __pyx_k_outlet_fid_list, sizeof(__pyx_k_outlet_fid_list), 0, 0, 1, 1}, + {&__pyx_n_s_outlet_index, __pyx_k_outlet_index, sizeof(__pyx_k_outlet_index), 0, 0, 1, 1}, + {&__pyx_n_s_outlet_layer, __pyx_k_outlet_layer, sizeof(__pyx_k_outlet_layer), 0, 0, 1, 1}, + {&__pyx_n_s_outlet_point, __pyx_k_outlet_point, sizeof(__pyx_k_outlet_point), 0, 0, 1, 1}, + {&__pyx_n_s_outlet_vector, __pyx_k_outlet_vector, sizeof(__pyx_k_outlet_vector), 0, 0, 1, 1}, + {&__pyx_n_s_outlet_x, __pyx_k_outlet_x, sizeof(__pyx_k_outlet_x), 0, 0, 1, 1}, + {&__pyx_n_u_outlet_x, __pyx_k_outlet_x, sizeof(__pyx_k_outlet_x), 0, 1, 0, 1}, + {&__pyx_n_s_outlet_y, __pyx_k_outlet_y, sizeof(__pyx_k_outlet_y), 0, 0, 1, 1}, + {&__pyx_n_u_outlet_y, __pyx_k_outlet_y, sizeof(__pyx_k_outlet_y), 0, 1, 0, 1}, + {&__pyx_kp_u_outlets_complete, __pyx_k_outlets_complete, sizeof(__pyx_k_outlets_complete), 0, 1, 0, 0}, + {&__pyx_n_s_p_val, __pyx_k_p_val, sizeof(__pyx_k_p_val), 0, 0, 1, 1}, + {&__pyx_n_s_path, __pyx_k_path, sizeof(__pyx_k_path), 0, 0, 1, 1}, + {&__pyx_n_s_payload, __pyx_k_payload, sizeof(__pyx_k_payload), 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_u_pit_mask_tif, __pyx_k_pit_mask_tif, sizeof(__pyx_k_pit_mask_tif), 0, 1, 0, 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_count, __pyx_k_pixel_count, sizeof(__pyx_k_pixel_count), 0, 0, 1, 1}, + {&__pyx_n_s_pixel_val, __pyx_k_pixel_val, sizeof(__pyx_k_pixel_val), 0, 0, 1, 1}, + {&__pyx_kp_u_pixels_complete, __pyx_k_pixels_complete, sizeof(__pyx_k_pixels_complete), 0, 1, 0, 0}, + {&__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_u_plateau_distance_tif, __pyx_k_plateau_distance_tif, sizeof(__pyx_k_plateau_distance_tif), 0, 1, 0, 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_u_plateu_drain_mask_tif, __pyx_k_plateu_drain_mask_tif, sizeof(__pyx_k_plateu_drain_mask_tif), 0, 1, 0, 0}, + {&__pyx_n_s_pop, __pyx_k_pop, sizeof(__pyx_k_pop), 0, 0, 1, 1}, + {&__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_processed_nodes, __pyx_k_processed_nodes, sizeof(__pyx_k_processed_nodes), 0, 0, 1, 1}, + {&__pyx_n_s_processed_segments, __pyx_k_processed_segments, sizeof(__pyx_k_processed_segments), 0, 0, 1, 1}, + {&__pyx_n_s_proj_x, __pyx_k_proj_x, sizeof(__pyx_k_proj_x), 0, 0, 1, 1}, + {&__pyx_n_s_proj_y, __pyx_k_proj_y, sizeof(__pyx_k_proj_y), 0, 0, 1, 1}, + {&__pyx_n_u_projection_wkt, __pyx_k_projection_wkt, sizeof(__pyx_k_projection_wkt), 0, 1, 0, 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_kp_u_quitting_too_many_steps, __pyx_k_quitting_too_many_steps, sizeof(__pyx_k_quitting_too_many_steps), 0, 1, 0, 0}, + {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1}, + {&__pyx_kp_u_raster, __pyx_k_raster, sizeof(__pyx_k_raster), 0, 1, 0, 0}, + {&__pyx_n_s_raster_coord, __pyx_k_raster_coord, sizeof(__pyx_k_raster_coord), 0, 0, 1, 1}, + {&__pyx_n_s_raster_driver, __pyx_k_raster_driver, sizeof(__pyx_k_raster_driver), 0, 0, 1, 1}, + {&__pyx_n_s_raster_driver_creation_tuple, __pyx_k_raster_driver_creation_tuple, sizeof(__pyx_k_raster_driver_creation_tuple), 0, 0, 1, 1}, + {&__pyx_n_s_raster_info, __pyx_k_raster_info, sizeof(__pyx_k_raster_info), 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_u_raster_size, __pyx_k_raster_size, sizeof(__pyx_k_raster_size), 0, 1, 0, 1}, + {&__pyx_n_s_raster_srs, __pyx_k_raster_srs, sizeof(__pyx_k_raster_srs), 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_remove, __pyx_k_remove, sizeof(__pyx_k_remove), 0, 0, 1, 1}, + {&__pyx_kp_u_resulted_in_null_trying, __pyx_k_resulted_in_null_trying, sizeof(__pyx_k_resulted_in_null_trying), 0, 1, 0, 0}, + {&__pyx_kp_u_retrying, __pyx_k_retrying, sizeof(__pyx_k_retrying), 0, 1, 0, 0}, + {&__pyx_n_s_reverse, __pyx_k_reverse, sizeof(__pyx_k_reverse), 0, 0, 1, 1}, + {&__pyx_n_s_right, __pyx_k_right, sizeof(__pyx_k_right), 0, 0, 1, 1}, + {&__pyx_n_s_right_in, __pyx_k_right_in, sizeof(__pyx_k_right_in), 0, 0, 1, 1}, + {&__pyx_n_u_river_id, __pyx_k_river_id, sizeof(__pyx_k_river_id), 0, 1, 0, 1}, + {&__pyx_n_s_river_order, __pyx_k_river_order, sizeof(__pyx_k_river_order), 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_u_s_is_not_a_file, __pyx_k_s_is_not_a_file, sizeof(__pyx_k_s_is_not_a_file), 0, 1, 0, 0}, + {&__pyx_kp_u_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, 1, 0, 0}, + {&__pyx_n_s_scipy, __pyx_k_scipy, sizeof(__pyx_k_scipy), 0, 0, 1, 1}, + {&__pyx_n_s_scipy_stats, __pyx_k_scipy_stats, sizeof(__pyx_k_scipy_stats), 0, 0, 1, 1}, + {&__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_search_steps, __pyx_k_search_steps, sizeof(__pyx_k_search_steps), 0, 0, 1, 1}, + {&__pyx_kp_u_segments_complete, __pyx_k_segments_complete, sizeof(__pyx_k_segments_complete), 0, 1, 0, 0}, + {&__pyx_n_s_segments_to_process, __pyx_k_segments_to_process, sizeof(__pyx_k_segments_to_process), 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_shapely, __pyx_k_shapely, sizeof(__pyx_k_shapely), 0, 0, 1, 1}, + {&__pyx_n_s_shapely_ops, __pyx_k_shapely_ops, sizeof(__pyx_k_shapely_ops), 0, 0, 1, 1}, + {&__pyx_n_s_shapely_wkb, __pyx_k_shapely_wkb, sizeof(__pyx_k_shapely_wkb), 0, 0, 1, 1}, + {&__pyx_n_s_shutil, __pyx_k_shutil, sizeof(__pyx_k_shutil), 0, 0, 1, 1}, + {&__pyx_n_s_sleep, __pyx_k_sleep, sizeof(__pyx_k_sleep), 0, 0, 1, 1}, + {&__pyx_n_s_sorted, __pyx_k_sorted, sizeof(__pyx_k_sorted), 0, 0, 1, 1}, + {&__pyx_n_s_sorted_stream_order_list, __pyx_k_sorted_stream_order_list, sizeof(__pyx_k_sorted_stream_order_list), 0, 0, 1, 1}, + {&__pyx_n_s_source_id, __pyx_k_source_id, sizeof(__pyx_k_source_id), 0, 0, 1, 1}, + {&__pyx_n_s_source_point_stack, __pyx_k_source_point_stack, sizeof(__pyx_k_source_point_stack), 0, 0, 1, 1}, + {&__pyx_kp_u_source_points_complete, __pyx_k_source_points_complete, sizeof(__pyx_k_source_points_complete), 0, 1, 0, 0}, + {&__pyx_n_s_source_stream_point, __pyx_k_source_stream_point, sizeof(__pyx_k_source_stream_point), 0, 0, 1, 1}, + {&__pyx_n_s_splitext, __pyx_k_splitext, sizeof(__pyx_k_splitext), 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_kp_u_starting_search, __pyx_k_starting_search, sizeof(__pyx_k_starting_search), 0, 1, 0, 0}, + {&__pyx_n_s_stats, __pyx_k_stats, sizeof(__pyx_k_stats), 0, 0, 1, 1}, + {&__pyx_n_s_strahler_stream_vector_path, __pyx_k_strahler_stream_vector_path, sizeof(__pyx_k_strahler_stream_vector_path), 0, 0, 1, 1}, + {&__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_basename, __pyx_k_stream_basename, sizeof(__pyx_k_stream_basename), 0, 0, 1, 1}, + {&__pyx_n_s_stream_feature, __pyx_k_stream_feature, sizeof(__pyx_k_stream_feature), 0, 0, 1, 1}, + {&__pyx_n_s_stream_fid, __pyx_k_stream_fid, sizeof(__pyx_k_stream_fid), 0, 0, 1, 1}, + {&__pyx_n_u_stream_fid, __pyx_k_stream_fid, sizeof(__pyx_k_stream_fid), 0, 1, 0, 1}, + {&__pyx_kp_u_stream_fragments_complete, __pyx_k_stream_fragments_complete, sizeof(__pyx_k_stream_fragments_complete), 0, 1, 0, 0}, + {&__pyx_n_s_stream_layer, __pyx_k_stream_layer, sizeof(__pyx_k_stream_layer), 0, 0, 1, 1}, + {&__pyx_n_s_stream_line, __pyx_k_stream_line, sizeof(__pyx_k_stream_line), 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_order, __pyx_k_stream_order, sizeof(__pyx_k_stream_order), 0, 0, 1, 1}, + {&__pyx_n_s_stream_order_list, __pyx_k_stream_order_list, sizeof(__pyx_k_stream_order_list), 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_stream_vector, __pyx_k_stream_vector, sizeof(__pyx_k_stream_vector), 0, 0, 1, 1}, + {&__pyx_n_s_streams_by_order, __pyx_k_streams_by_order, sizeof(__pyx_k_streams_by_order), 0, 0, 1, 1}, + {&__pyx_n_s_streams_to_process, __pyx_k_streams_to_process, sizeof(__pyx_k_streams_to_process), 0, 0, 1, 1}, + {&__pyx_n_s_streams_to_retest, __pyx_k_streams_to_retest, sizeof(__pyx_k_streams_to_retest), 0, 0, 1, 1}, + {&__pyx_n_s_strftime, __pyx_k_strftime, sizeof(__pyx_k_strftime), 0, 0, 1, 1}, + {&__pyx_n_s_suffix, __pyx_k_suffix, sizeof(__pyx_k_suffix), 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_discovery_raster_path, __pyx_k_target_discovery_raster_path, sizeof(__pyx_k_target_discovery_raster_path), 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_finish_raster_path, __pyx_k_target_finish_raster_path, sizeof(__pyx_k_target_finish_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_outlet_vector_path, __pyx_k_target_outlet_vector_path, sizeof(__pyx_k_target_outlet_vector_path), 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_target_stream_vector_path, __pyx_k_target_stream_vector_path, sizeof(__pyx_k_target_stream_vector_path), 0, 0, 1, 1}, + {&__pyx_n_s_target_watershed_boundary_vector, __pyx_k_target_watershed_boundary_vector, sizeof(__pyx_k_target_watershed_boundary_vector), 0, 0, 1, 1}, + {&__pyx_n_s_tempfile, __pyx_k_tempfile, sizeof(__pyx_k_tempfile), 0, 0, 1, 1}, + {&__pyx_n_s_terminated_early, __pyx_k_terminated_early, sizeof(__pyx_k_terminated_early), 0, 0, 1, 1}, + {&__pyx_n_u_terminated_early, __pyx_k_terminated_early, sizeof(__pyx_k_terminated_early), 0, 1, 0, 1}, + {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, + {&__pyx_n_s_test_dir, __pyx_k_test_dir, sizeof(__pyx_k_test_dir), 0, 0, 1, 1}, + {&__pyx_n_s_test_order, __pyx_k_test_order, sizeof(__pyx_k_test_order), 0, 0, 1, 1}, + {&__pyx_n_u_thresh_fa, __pyx_k_thresh_fa, sizeof(__pyx_k_thresh_fa), 0, 1, 0, 1}, + {&__pyx_n_s_time, __pyx_k_time, sizeof(__pyx_k_time), 0, 0, 1, 1}, + {&__pyx_n_s_tmp_dir, __pyx_k_tmp_dir, sizeof(__pyx_k_tmp_dir), 0, 0, 1, 1}, + {&__pyx_n_s_tmp_dir_root, __pyx_k_tmp_dir_root, sizeof(__pyx_k_tmp_dir_root), 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_tmp_work_dir, __pyx_k_tmp_work_dir, sizeof(__pyx_k_tmp_work_dir), 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_u_trace_threshold_proportion_shoul, __pyx_k_trace_threshold_proportion_shoul, sizeof(__pyx_k_trace_threshold_proportion_shoul), 0, 1, 0, 0}, + {&__pyx_n_s_ttest_ind, __pyx_k_ttest_ind, sizeof(__pyx_k_ttest_ind), 0, 0, 1, 1}, + {&__pyx_n_s_uint8, __pyx_k_uint8, sizeof(__pyx_k_uint8), 0, 0, 1, 1}, + {&__pyx_kp_u_unable_to_open, __pyx_k_unable_to_open, sizeof(__pyx_k_unable_to_open), 0, 1, 0, 0}, + {&__pyx_n_s_upstream_all_defined, __pyx_k_upstream_all_defined, sizeof(__pyx_k_upstream_all_defined), 0, 0, 1, 1}, + {&__pyx_n_s_upstream_coord, __pyx_k_upstream_coord, sizeof(__pyx_k_upstream_coord), 0, 0, 1, 1}, + {&__pyx_n_s_upstream_count, __pyx_k_upstream_count, sizeof(__pyx_k_upstream_count), 0, 0, 1, 1}, + {&__pyx_n_s_upstream_d8_dir, __pyx_k_upstream_d8_dir, sizeof(__pyx_k_upstream_d8_dir), 0, 0, 1, 1}, + {&__pyx_n_u_upstream_d8_dir, __pyx_k_upstream_d8_dir, sizeof(__pyx_k_upstream_d8_dir), 0, 1, 0, 1}, + {&__pyx_n_s_upstream_dem, __pyx_k_upstream_dem, sizeof(__pyx_k_upstream_dem), 0, 0, 1, 1}, + {&__pyx_n_s_upstream_dirs, __pyx_k_upstream_dirs, sizeof(__pyx_k_upstream_dirs), 0, 0, 1, 1}, + {&__pyx_n_s_upstream_feature, __pyx_k_upstream_feature, sizeof(__pyx_k_upstream_feature), 0, 0, 1, 1}, + {&__pyx_n_s_upstream_fid, __pyx_k_upstream_fid, sizeof(__pyx_k_upstream_fid), 0, 0, 1, 1}, + {&__pyx_n_s_upstream_fid_list, __pyx_k_upstream_fid_list, sizeof(__pyx_k_upstream_fid_list), 0, 0, 1, 1}, + {&__pyx_n_s_upstream_fid_map, __pyx_k_upstream_fid_map, sizeof(__pyx_k_upstream_fid_map), 0, 0, 1, 1}, + {&__pyx_n_s_upstream_fids, __pyx_k_upstream_fids, sizeof(__pyx_k_upstream_fids), 0, 0, 1, 1}, + {&__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_upstream_id, __pyx_k_upstream_id, sizeof(__pyx_k_upstream_id), 0, 0, 1, 1}, + {&__pyx_n_s_upstream_id_list, __pyx_k_upstream_id_list, sizeof(__pyx_k_upstream_id_list), 0, 0, 1, 1}, + {&__pyx_n_s_upstream_index, __pyx_k_upstream_index, sizeof(__pyx_k_upstream_index), 0, 0, 1, 1}, + {&__pyx_n_s_upstream_order, __pyx_k_upstream_order, sizeof(__pyx_k_upstream_order), 0, 0, 1, 1}, + {&__pyx_n_s_upstream_stack, __pyx_k_upstream_stack, sizeof(__pyx_k_upstream_stack), 0, 0, 1, 1}, + {&__pyx_n_s_upstream_to_downstream_id, __pyx_k_upstream_to_downstream_id, sizeof(__pyx_k_upstream_to_downstream_id), 0, 0, 1, 1}, + {&__pyx_n_u_us_fa, __pyx_k_us_fa, sizeof(__pyx_k_us_fa), 0, 1, 0, 1}, + {&__pyx_n_s_us_x, __pyx_k_us_x, sizeof(__pyx_k_us_x), 0, 0, 1, 1}, + {&__pyx_n_u_us_x, __pyx_k_us_x, sizeof(__pyx_k_us_x), 0, 1, 0, 1}, + {&__pyx_n_s_us_y, __pyx_k_us_y, sizeof(__pyx_k_us_y), 0, 0, 1, 1}, + {&__pyx_n_u_us_y, __pyx_k_us_y, sizeof(__pyx_k_us_y), 0, 1, 0, 1}, + {&__pyx_n_s_value, __pyx_k_value, sizeof(__pyx_k_value), 0, 0, 1, 1}, + {&__pyx_n_s_visit_count, __pyx_k_visit_count, sizeof(__pyx_k_visit_count), 0, 0, 1, 1}, + {&__pyx_n_s_visit_order_stack, __pyx_k_visit_order_stack, sizeof(__pyx_k_visit_order_stack), 0, 0, 1, 1}, + {&__pyx_n_s_visited_managed_raster, __pyx_k_visited_managed_raster, sizeof(__pyx_k_visited_managed_raster), 0, 0, 1, 1}, + {&__pyx_n_s_visited_raster_path, __pyx_k_visited_raster_path, sizeof(__pyx_k_visited_raster_path), 0, 0, 1, 1}, + {&__pyx_kp_u_visited_tif, __pyx_k_visited_tif, sizeof(__pyx_k_visited_tif), 0, 1, 0, 0}, + {&__pyx_n_s_warning, __pyx_k_warning, sizeof(__pyx_k_warning), 0, 0, 1, 1}, + {&__pyx_n_s_watershed_basename, __pyx_k_watershed_basename, sizeof(__pyx_k_watershed_basename), 0, 0, 1, 1}, + {&__pyx_n_s_watershed_boundary, __pyx_k_watershed_boundary, sizeof(__pyx_k_watershed_boundary), 0, 0, 1, 1}, + {&__pyx_n_s_watershed_feature, __pyx_k_watershed_feature, sizeof(__pyx_k_watershed_feature), 0, 0, 1, 1}, + {&__pyx_n_s_watershed_layer, __pyx_k_watershed_layer, sizeof(__pyx_k_watershed_layer), 0, 0, 1, 1}, + {&__pyx_n_s_watershed_polygon, __pyx_k_watershed_polygon, sizeof(__pyx_k_watershed_polygon), 0, 0, 1, 1}, + {&__pyx_n_s_watershed_vector, __pyx_k_watershed_vector, sizeof(__pyx_k_watershed_vector), 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_u_win_xsize, __pyx_k_win_xsize, sizeof(__pyx_k_win_xsize), 0, 1, 0, 1}, + {&__pyx_n_s_win_xsize_border, __pyx_k_win_xsize_border, sizeof(__pyx_k_win_xsize_border), 0, 0, 1, 1}, + {&__pyx_n_s_win_ysize, __pyx_k_win_ysize, sizeof(__pyx_k_win_ysize), 0, 0, 1, 1}, + {&__pyx_n_u_win_ysize, __pyx_k_win_ysize, sizeof(__pyx_k_win_ysize), 0, 1, 0, 1}, + {&__pyx_n_s_win_ysize_border, __pyx_k_win_ysize_border, sizeof(__pyx_k_win_ysize_border), 0, 0, 1, 1}, + {&__pyx_n_s_wkb, __pyx_k_wkb, sizeof(__pyx_k_wkb), 0, 0, 1, 1}, + {&__pyx_n_s_wkbLineString, __pyx_k_wkbLineString, sizeof(__pyx_k_wkbLineString), 0, 0, 1, 1}, + {&__pyx_n_s_wkbLinearRing, __pyx_k_wkbLinearRing, sizeof(__pyx_k_wkbLinearRing), 0, 0, 1, 1}, + {&__pyx_n_s_wkbPoint, __pyx_k_wkbPoint, sizeof(__pyx_k_wkbPoint), 0, 0, 1, 1}, + {&__pyx_n_s_wkbPolygon, __pyx_k_wkbPolygon, sizeof(__pyx_k_wkbPolygon), 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_working_feature, __pyx_k_working_feature, sizeof(__pyx_k_working_feature), 0, 0, 1, 1}, + {&__pyx_n_s_working_fid, __pyx_k_working_fid, sizeof(__pyx_k_working_fid), 0, 0, 1, 1}, + {&__pyx_n_s_working_flow_accum_threshold, __pyx_k_working_flow_accum_threshold, sizeof(__pyx_k_working_flow_accum_threshold), 0, 0, 1, 1}, + {&__pyx_n_s_working_geom, __pyx_k_working_geom, sizeof(__pyx_k_working_geom), 0, 0, 1, 1}, + {&__pyx_n_s_working_order, __pyx_k_working_order, sizeof(__pyx_k_working_order), 0, 0, 1, 1}, + {&__pyx_n_s_working_river_id, __pyx_k_working_river_id, sizeof(__pyx_k_working_river_id), 0, 0, 1, 1}, + {&__pyx_n_s_working_stack, __pyx_k_working_stack, sizeof(__pyx_k_working_stack), 0, 0, 1, 1}, + {&__pyx_n_s_workspace_dir, __pyx_k_workspace_dir, sizeof(__pyx_k_workspace_dir), 0, 0, 1, 1}, + {&__pyx_n_s_write_mode, __pyx_k_write_mode, sizeof(__pyx_k_write_mode), 0, 0, 1, 1}, + {&__pyx_n_s_x, __pyx_k_x, sizeof(__pyx_k_x), 0, 0, 1, 1}, + {&__pyx_n_u_x, __pyx_k_x, sizeof(__pyx_k_x), 0, 1, 0, 1}, + {&__pyx_n_s_x_f, __pyx_k_x_f, sizeof(__pyx_k_x_f), 0, 0, 1, 1}, + {&__pyx_n_s_x_l, __pyx_k_x_l, sizeof(__pyx_k_x_l), 0, 0, 1, 1}, + {&__pyx_n_s_x_n, __pyx_k_x_n, sizeof(__pyx_k_x_n), 0, 0, 1, 1}, + {&__pyx_n_s_x_off_border, __pyx_k_x_off_border, sizeof(__pyx_k_x_off_border), 0, 0, 1, 1}, + {&__pyx_kp_u_x_out_of_bounds_s, __pyx_k_x_out_of_bounds_s, sizeof(__pyx_k_x_out_of_bounds_s), 0, 1, 0, 0}, + {&__pyx_n_s_x_p, __pyx_k_x_p, sizeof(__pyx_k_x_p), 0, 0, 1, 1}, + {&__pyx_n_s_x_u, __pyx_k_x_u, sizeof(__pyx_k_x_u), 0, 0, 1, 1}, + {&__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_n_u_xoff, __pyx_k_xoff, sizeof(__pyx_k_xoff), 0, 1, 0, 1}, + {&__pyx_n_s_y_f, __pyx_k_y_f, sizeof(__pyx_k_y_f), 0, 0, 1, 1}, + {&__pyx_n_s_y_l, __pyx_k_y_l, sizeof(__pyx_k_y_l), 0, 0, 1, 1}, + {&__pyx_n_s_y_n, __pyx_k_y_n, sizeof(__pyx_k_y_n), 0, 0, 1, 1}, + {&__pyx_n_s_y_off_border, __pyx_k_y_off_border, sizeof(__pyx_k_y_off_border), 0, 0, 1, 1}, + {&__pyx_kp_u_y_out_of_bounds_s, __pyx_k_y_out_of_bounds_s, sizeof(__pyx_k_y_out_of_bounds_s), 0, 1, 0, 0}, + {&__pyx_n_s_y_p, __pyx_k_y_p, sizeof(__pyx_k_y_p), 0, 0, 1, 1}, + {&__pyx_n_s_y_u, __pyx_k_y_u, sizeof(__pyx_k_y_u), 0, 0, 1, 1}, + {&__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}, + {&__pyx_n_u_yoff, __pyx_k_yoff, sizeof(__pyx_k_yoff), 0, 1, 0, 1}, + {0, 0, 0, 0, 0, 0, 0} +}; +static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { + __pyx_builtin_print = __Pyx_GetBuiltinName(__pyx_n_s_print); if (!__pyx_builtin_print) __PYX_ERR(0, 232, __pyx_L1_error) + __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 233, __pyx_L1_error) + __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 340, __pyx_L1_error) + __pyx_builtin_RuntimeError = __Pyx_GetBuiltinName(__pyx_n_s_RuntimeError); if (!__pyx_builtin_RuntimeError) __PYX_ERR(0, 441, __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, 724, __pyx_L1_error) + __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(0, 3398, __pyx_L1_error) + __pyx_builtin_min = __Pyx_GetBuiltinName(__pyx_n_s_min); if (!__pyx_builtin_min) __PYX_ERR(0, 3454, __pyx_L1_error) + __pyx_builtin_max = __Pyx_GetBuiltinName(__pyx_n_s_max); if (!__pyx_builtin_max) __PYX_ERR(0, 3455, __pyx_L1_error) + __pyx_builtin_sorted = __Pyx_GetBuiltinName(__pyx_n_s_sorted); if (!__pyx_builtin_sorted) __PYX_ERR(0, 3959, __pyx_L1_error) + __pyx_builtin_ImportError = __Pyx_GetBuiltinName(__pyx_n_s_ImportError); if (!__pyx_builtin_ImportError) __PYX_ERR(2, 947, __pyx_L1_error) + return 0; + __pyx_L1_error:; + return -1; +} + +static CYTHON_SMALL_CODE 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__2 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__2); + __Pyx_GIVEREF(__pyx_tuple__2); + + /* "(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__3 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__3); + __Pyx_GIVEREF(__pyx_tuple__3); + + /* "pygeoprocessing/routing/routing.pyx":1180 + * (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__7 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__7)) __PYX_ERR(0, 1180, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice__7); + __Pyx_GIVEREF(__pyx_slice__7); + + /* "pygeoprocessing/routing/routing.pyx":1579 + * if weight_raster is not None: + * weight_raster.close() + * LOGGER.info('%.1f%% complete', 100.0) # <<<<<<<<<<<<<< + * + * + */ + __pyx_tuple__9 = PyTuple_Pack(2, __pyx_kp_u_1f_complete, __pyx_float_100_0); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 1579, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__9); + __Pyx_GIVEREF(__pyx_tuple__9); + + /* "pygeoprocessing/routing/routing.pyx":3245 + * stream_feature = ogr.Feature( + * stream_layer.GetLayerDefn()) + * stream_feature.SetField('outlet', 0) # <<<<<<<<<<<<<< + * stream_layer.CreateFeature(stream_feature) + * stream_fid = stream_feature.GetFID() + */ + __pyx_tuple__16 = PyTuple_Pack(2, __pyx_n_u_outlet, __pyx_int_0); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 3245, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__16); + __Pyx_GIVEREF(__pyx_tuple__16); + + /* "pygeoprocessing/routing/routing.pyx":3316 + * # if no upstream it means it is an order 1 source stream + * if not upstream_id_list: + * stream_feature.SetField('order', 1) # <<<<<<<<<<<<<< + * stream_feature.SetGeometry(stream_line) + * + */ + __pyx_tuple__17 = PyTuple_Pack(2, __pyx_n_u_order, __pyx_int_1); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 3316, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__17); + __Pyx_GIVEREF(__pyx_tuple__17); + + /* "pygeoprocessing/routing/routing.pyx":3350 + * if stream_fid not in upstream_to_downstream_id: + * # it's an outlet so no downstream to process + * stream_feature.SetField('outlet', 1) # <<<<<<<<<<<<<< + * stream_layer.SetFeature(stream_feature) + * outlet_fid_list.append(stream_feature.GetFID()) + */ + __pyx_tuple__18 = PyTuple_Pack(2, __pyx_n_u_outlet, __pyx_int_1); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 3350, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__18); + __Pyx_GIVEREF(__pyx_tuple__18); + + /* "pygeoprocessing/routing/routing.pyx":3567 + * + * stream_layer.DeleteField( + * stream_layer.FindFieldIndex('upstream_d8_dir', 1)) # <<<<<<<<<<<<<< + * stream_layer.CommitTransaction() + * stream_layer.StartTransaction() + */ + __pyx_tuple__19 = PyTuple_Pack(2, __pyx_n_u_upstream_d8_dir, __pyx_int_1); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 3567, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__19); + __Pyx_GIVEREF(__pyx_tuple__19); + + /* "pygeoprocessing/routing/routing.pyx":4265 + * x_off_border = 1 + * else: + * flow_dir_block[:, 0] = flow_dir_nodata # <<<<<<<<<<<<<< + * + * # Test for top border and if so stripe nodata on the top margin + */ + __pyx_tuple__20 = PyTuple_Pack(2, __pyx_slice__7, __pyx_int_0); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 4265, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__20); + __Pyx_GIVEREF(__pyx_tuple__20); + + /* "pygeoprocessing/routing/routing.pyx":4272 + * y_off_border = 1 + * else: + * flow_dir_block[0, :] = flow_dir_nodata # <<<<<<<<<<<<<< + * + * # Test for right border and if so stripe nodata on the right margin + */ + __pyx_tuple__21 = PyTuple_Pack(2, __pyx_int_0, __pyx_slice__7); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 4272, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__21); + __Pyx_GIVEREF(__pyx_tuple__21); + + /* "pygeoprocessing/routing/routing.pyx":4279 + * win_xsize_border += 1 + * else: + * flow_dir_block[:, -1] = flow_dir_nodata # <<<<<<<<<<<<<< + * + * # Test for bottom border and if so stripe nodata on the bottom margin + */ + __pyx_tuple__22 = PyTuple_Pack(2, __pyx_slice__7, __pyx_int_neg_1); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 4279, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__22); + __Pyx_GIVEREF(__pyx_tuple__22); + + /* "pygeoprocessing/routing/routing.pyx":4286 + * win_ysize_border += 1 + * else: + * flow_dir_block[-1, :] = flow_dir_nodata # <<<<<<<<<<<<<< + * + * # Read iterblock plus a possible margin on top/bottom/left/right side + */ + __pyx_tuple__23 = PyTuple_Pack(2, __pyx_int_neg_1, __pyx_slice__7); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 4286, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__23); + __Pyx_GIVEREF(__pyx_tuple__23); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":947 + * __pyx_import_array() + * except Exception: + * raise ImportError("numpy.core.multiarray failed to import") # <<<<<<<<<<<<<< + * + * cdef inline int import_umath() except -1: + */ + __pyx_tuple__24 = PyTuple_Pack(1, __pyx_kp_u_numpy_core_multiarray_failed_to); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(2, 947, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__24); + __Pyx_GIVEREF(__pyx_tuple__24); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":953 + * _import_umath() + * except Exception: + * raise ImportError("numpy.core.umath failed to import") # <<<<<<<<<<<<<< + * + * cdef inline int import_ufunc() except -1: + */ + __pyx_tuple__25 = PyTuple_Pack(1, __pyx_kp_u_numpy_core_umath_failed_to_impor); if (unlikely(!__pyx_tuple__25)) __PYX_ERR(2, 953, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__25); + __Pyx_GIVEREF(__pyx_tuple__25); + + /* "pygeoprocessing/routing/routing.pyx":568 + * + * + * 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__26 = 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__26)) __PYX_ERR(0, 568, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__26); + __Pyx_GIVEREF(__pyx_tuple__26); + __pyx_codeobj__27 = (PyObject*)__Pyx_PyCode_New(3, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_generate_read_bounds, 568, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__27)) __PYX_ERR(0, 568, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":612 + * + * + * def fill_pits( # <<<<<<<<<<<<<< + * dem_raster_path_band, target_filled_dem_raster_path, + * working_dir=None, long max_pixel_fill_count=_MAX_PIXEL_FILL_COUNT, + */ + __pyx_tuple__28 = PyTuple_Pack(52, __pyx_n_s_dem_raster_path_band, __pyx_n_s_target_filled_dem_raster_path, __pyx_n_s_working_dir, __pyx_n_s_max_pixel_fill_count, __pyx_n_s_raster_driver_creation_tuple, __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_natural_drain_exists, __pyx_n_s_search_steps, __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_base_datatype, __pyx_n_s_filled_dem_raster, __pyx_n_s_filled_dem_band, __pyx_n_s_offset_info, __pyx_n_s_block_array, __pyx_n_s_filled_dem_managed_raster, __pyx_n_s_offset_dict, __pyx_n_s_current_pixel, __pyx_n_s_n_height, __pyx_n_s_pour_point); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 612, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__28); + __Pyx_GIVEREF(__pyx_tuple__28); + __pyx_codeobj__29 = (PyObject*)__Pyx_PyCode_New(5, 0, 52, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_fill_pits_2, 612, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__29)) __PYX_ERR(0, 612, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":994 + * + * + * def flow_dir_d8( # <<<<<<<<<<<<<< + * dem_raster_path_band, target_flow_dir_path, + * working_dir=None, + */ + __pyx_tuple__30 = 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_raster_driver_creation_tuple, __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_raster_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__30)) __PYX_ERR(0, 994, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__30); + __Pyx_GIVEREF(__pyx_tuple__30); + __pyx_codeobj__31 = (PyObject*)__Pyx_PyCode_New(4, 0, 58, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__30, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_flow_dir_d8_2, 994, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__31)) __PYX_ERR(0, 994, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":1359 + * + * + * def flow_accumulation_d8( # <<<<<<<<<<<<<< + * flow_dir_raster_path_band, target_flow_accum_raster_path, + * weight_raster_path_band=None, + */ + __pyx_tuple__32 = 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_raster_driver_creation_tuple, __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__32)) __PYX_ERR(0, 1359, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__32); + __Pyx_GIVEREF(__pyx_tuple__32); + __pyx_codeobj__33 = (PyObject*)__Pyx_PyCode_New(4, 0, 44, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__32, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_flow_accumulation_d8, 1359, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__33)) __PYX_ERR(0, 1359, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":1582 + * + * + * def flow_dir_mfd( # <<<<<<<<<<<<<< + * dem_raster_path_band, target_flow_dir_path, working_dir=None, + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): + */ + __pyx_tuple__35 = 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_raster_driver_creation_tuple, __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_raster_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__34, __pyx_n_s_n_distance); if (unlikely(!__pyx_tuple__35)) __PYX_ERR(0, 1582, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__35); + __Pyx_GIVEREF(__pyx_tuple__35); + __pyx_codeobj__36 = (PyObject*)__Pyx_PyCode_New(4, 0, 69, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__35, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_flow_dir_mfd, 1582, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__36)) __PYX_ERR(0, 1582, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2073 + * + * + * def flow_accumulation_mfd( # <<<<<<<<<<<<<< + * flow_dir_mfd_raster_path_band, target_flow_accum_raster_path, + * weight_raster_path_band=None, + */ + __pyx_tuple__37 = PyTuple_Pack(51, __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_raster_driver_creation_tuple, __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_visit_count, __pyx_n_s_pixel_count, __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_tmp_dir_root, __pyx_n_s_tmp_dir, __pyx_n_s_visited_raster_path, __pyx_n_s_visited_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__37)) __PYX_ERR(0, 2073, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__37); + __Pyx_GIVEREF(__pyx_tuple__37); + __pyx_codeobj__38 = (PyObject*)__Pyx_PyCode_New(4, 0, 51, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__37, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_flow_accumulation_mfd, 2073, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__38)) __PYX_ERR(0, 2073, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2354 + * + * + * def distance_to_channel_d8( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band, channel_raster_path_band, + * target_distance_to_channel_raster_path, + */ + __pyx_tuple__39 = 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_raster_driver_creation_tuple, __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__39)) __PYX_ERR(0, 2354, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__39); + __Pyx_GIVEREF(__pyx_tuple__39); + __pyx_codeobj__40 = (PyObject*)__Pyx_PyCode_New(5, 0, 41, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__39, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_distance_to_channel_d8, 2354, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__40)) __PYX_ERR(0, 2354, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2544 + * + * + * 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__41 = PyTuple_Pack(53, __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_raster_driver_creation_tuple, __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_tmp_work_dir, __pyx_n_s_visited_raster_path, __pyx_n_s_visited_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__41)) __PYX_ERR(0, 2544, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__41); + __Pyx_GIVEREF(__pyx_tuple__41); + __pyx_codeobj__42 = (PyObject*)__Pyx_PyCode_New(5, 0, 53, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__41, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_distance_to_channel_mfd, 2544, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__42)) __PYX_ERR(0, 2544, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":2811 + * + * + * def extract_streams_mfd( # <<<<<<<<<<<<<< + * flow_accum_raster_path_band, flow_dir_mfd_path_band, + * double flow_threshold, target_stream_raster_path, + */ + __pyx_tuple__43 = PyTuple_Pack(46, __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_raster_driver_creation_tuple, __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_block_offsets_list, __pyx_n_s_stream_raster, __pyx_n_s_stream_band, __pyx_n_s_stream_array); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(0, 2811, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__43); + __Pyx_GIVEREF(__pyx_tuple__43); + __pyx_codeobj__44 = (PyObject*)__Pyx_PyCode_New(6, 0, 46, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__43, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_extract_streams_mfd, 2811, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__44)) __PYX_ERR(0, 2811, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3011 + * + * + * 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__45 = PyTuple_Pack(1, __pyx_n_s_raster_path_band); if (unlikely(!__pyx_tuple__45)) __PYX_ERR(0, 3011, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__45); + __Pyx_GIVEREF(__pyx_tuple__45); + __pyx_codeobj__46 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__45, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_is_raster_path_band_formatted, 3011, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__46)) __PYX_ERR(0, 3011, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3025 + * + * + * def extract_strahler_streams_d8( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band, flow_accum_raster_path_band, + * dem_raster_path_band, + */ + __pyx_tuple__47 = PyTuple_Pack(112, __pyx_n_s_flow_dir_d8_raster_path_band, __pyx_n_s_flow_accum_raster_path_band, __pyx_n_s_dem_raster_path_band, __pyx_n_s_target_stream_vector_path, __pyx_n_s_min_flow_accum_threshold, __pyx_n_s_river_order, __pyx_n_s_min_p_val, __pyx_n_s_autotune_flow_accumulation, __pyx_n_s_osr_axis_mapping_strategy, __pyx_n_s_flow_dir_info, __pyx_n_s_flow_dir_srs, __pyx_n_s_gpkg_driver, __pyx_n_s_stream_vector, __pyx_n_s_stream_basename, __pyx_n_s_stream_layer, __pyx_n_s_flow_dir_managed_raster, __pyx_n_s_flow_accum_managed_raster, __pyx_n_s_dem_managed_raster, __pyx_n_s_flow_nodata, __pyx_n_s_xoff, __pyx_n_s_yoff, __pyx_n_s_i, __pyx_n_s_j, __pyx_n_s_d, __pyx_n_s_d_n, __pyx_n_s_n_cols, __pyx_n_s_n_rows, __pyx_n_s_win_xsize, __pyx_n_s_win_ysize, __pyx_n_s_n_pixels, __pyx_n_s_n_processed, __pyx_n_s_last_log_time, __pyx_n_s_source_point_stack, __pyx_n_s_source_stream_point, __pyx_n_s_x_l, __pyx_n_s_y_l, __pyx_n_s_x_n, __pyx_n_s_y_n, __pyx_n_s_upstream_count, __pyx_n_s_upstream_index, __pyx_n_s_upstream_dirs, __pyx_n_s_local_flow_accum, __pyx_n_s_is_drain, __pyx_n_s_coord_to_stream_ids, __pyx_n_s_offset_dict, __pyx_n_s_stream_feature, __pyx_n_s_stream_fid, __pyx_n_s_n_points, __pyx_n_s_downstream_to_upstream_ids, __pyx_n_s_upstream_to_downstream_id, __pyx_n_s_payload, __pyx_n_s_x_u, __pyx_n_s_y_u, __pyx_n_s_ds_x_1, __pyx_n_s_ds_y_1, __pyx_n_s_upstream_id_list, __pyx_n_s_stream_line, __pyx_n_s_downstream_dem, __pyx_n_s_upstream_id, __pyx_n_s_upstream_dem, __pyx_n_s_drop_distance, __pyx_n_s_streams_to_process, __pyx_n_s_base_feature_count, __pyx_n_s_outlet_fid_list, __pyx_n_s_downstream_fid, __pyx_n_s_downstream_feature, __pyx_n_s_connected_upstream_fids, __pyx_n_s_stream_order_list, __pyx_n_s_all_defined, __pyx_n_s_upstream_fid, __pyx_n_s_upstream_feature, __pyx_n_s_upstream_order, __pyx_n_s_sorted_stream_order_list, __pyx_n_s_downstream_order, __pyx_n_s_working_river_id, __pyx_n_s_outlet_index, __pyx_n_s_outlet_fid, __pyx_n_s_search_stack, __pyx_n_s_feature_id, __pyx_n_s_stream_order, __pyx_n_s_upstream_stack, __pyx_n_s_streams_by_order, __pyx_n_s_drop_distance_collection, __pyx_n_s_max_upstream_flow_accum, __pyx_n_s_order, __pyx_n_s_working_flow_accum_threshold, __pyx_n_s_test_order, __pyx_n_s__34, __pyx_n_s_p_val, __pyx_n_s_streams_to_retest, __pyx_n_s_ds_x, __pyx_n_s_ds_y, __pyx_n_s_upstream_d8_dir, __pyx_n_s_working_stack, __pyx_n_s_fid_to_order, __pyx_n_s_processed_segments, __pyx_n_s_segments_to_process, __pyx_n_s_deleted_set, __pyx_n_s_working_fid, __pyx_n_s_upstream_fid_list, __pyx_n_s_order_count, __pyx_n_s_working_order, __pyx_n_s_working_feature, __pyx_n_s_connected_fids, __pyx_n_s_downstream_geom, __pyx_n_s_working_geom, __pyx_n_s_multi_line, __pyx_n_s_joined_line, __pyx_n_s_upstream_all_defined, __pyx_n_s_connected_fid, __pyx_n_s_stream_feature, __pyx_n_s_fid); if (unlikely(!__pyx_tuple__47)) __PYX_ERR(0, 3025, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__47); + __Pyx_GIVEREF(__pyx_tuple__47); + __pyx_codeobj__48 = (PyObject*)__Pyx_PyCode_New(9, 0, 112, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__47, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_extract_strahler_streams_d8, 3025, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__48)) __PYX_ERR(0, 3025, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3700 + * + * + * def _build_discovery_finish_rasters( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band, target_discovery_raster_path, + * target_finish_raster_path): + */ + __pyx_tuple__49 = PyTuple_Pack(33, __pyx_n_s_flow_dir_d8_raster_path_band, __pyx_n_s_target_discovery_raster_path, __pyx_n_s_target_finish_raster_path, __pyx_n_s_flow_dir_info, __pyx_n_s_n_cols, __pyx_n_s_n_rows, __pyx_n_s_flow_dir_nodata, __pyx_n_s_flow_dir_managed_raster, __pyx_n_s_discovery_managed_raster, __pyx_n_s_finish_managed_raster, __pyx_n_s_discovery_stack, __pyx_n_s_finish_stack, __pyx_n_s_raster_coord, __pyx_n_s_finish_coordinate, __pyx_n_s_discovery_count, __pyx_n_s_n_processed, __pyx_n_s_n_pixels, __pyx_n_s_last_log_time, __pyx_n_s_n_pushed, __pyx_n_s_i, __pyx_n_s_j, __pyx_n_s_xoff, __pyx_n_s_yoff, __pyx_n_s_win_xsize, __pyx_n_s_win_ysize, __pyx_n_s_x_l, __pyx_n_s_y_l, __pyx_n_s_x_n, __pyx_n_s_y_n, __pyx_n_s_n_dir, __pyx_n_s_test_dir, __pyx_n_s_offset_dict, __pyx_n_s_d_n); if (unlikely(!__pyx_tuple__49)) __PYX_ERR(0, 3700, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__49); + __Pyx_GIVEREF(__pyx_tuple__49); + __pyx_codeobj__50 = (PyObject*)__Pyx_PyCode_New(3, 0, 33, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__49, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_build_discovery_finish_rasters, 3700, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__50)) __PYX_ERR(0, 3700, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":3830 + * + * + * def calculate_subwatershed_boundary( # <<<<<<<<<<<<<< + * d8_flow_dir_raster_path_band, + * strahler_stream_vector_path, target_watershed_boundary_vector_path, + */ + __pyx_tuple__51 = PyTuple_Pack(82, __pyx_n_s_d8_flow_dir_raster_path_band, __pyx_n_s_strahler_stream_vector_path, __pyx_n_s_target_watershed_boundary_vector, __pyx_n_s_max_steps_per_watershed, __pyx_n_s_outlet_at_confluence, __pyx_n_s_workspace_dir, __pyx_n_s_discovery_time_raster_path, __pyx_n_s_finish_time_raster_path, __pyx_n_s_discovery_managed_raster, __pyx_n_s_finish_managed_raster, __pyx_n_s_d8_flow_dir_managed_raster, __pyx_n_s_discovery_info, __pyx_n_s_discovery_nodata, __pyx_n_s_n_cols, __pyx_n_s_n_rows, __pyx_n_s_geotransform, __pyx_n_s_g0, __pyx_n_s_g1, __pyx_n_s_g2, __pyx_n_s_g3, __pyx_n_s_g4, __pyx_n_s_g5, __pyx_n_s_discovery_srs, __pyx_n_s_gpkg_driver, __pyx_n_s_watershed_vector, __pyx_n_s_watershed_basename, __pyx_n_s_watershed_layer, __pyx_n_s_x_l, __pyx_n_s_y_l, __pyx_n_s_outflow_dir, __pyx_n_s_x_f, __pyx_n_s_y_f, __pyx_n_s_x_p, __pyx_n_s_y_p, __pyx_n_s_discovery, __pyx_n_s_finish, __pyx_n_s_last_log_time, __pyx_n_s_stream_vector, __pyx_n_s_stream_layer, __pyx_n_s_upstream_fid_map, __pyx_n_s_stream_feature, __pyx_n_s_ds_x, __pyx_n_s_ds_y, __pyx_n_s_visit_order_stack, __pyx_n_s__34, __pyx_n_s_outlet_fid, __pyx_n_s_working_stack, __pyx_n_s_processed_nodes, __pyx_n_s_working_fid, __pyx_n_s_working_feature, __pyx_n_s_us_x, __pyx_n_s_us_y, __pyx_n_s_ds_x_1, __pyx_n_s_ds_y_1, __pyx_n_s_upstream_coord, __pyx_n_s_upstream_fids, __pyx_n_s_edge_side, __pyx_n_s_edge_dir, __pyx_n_s_cell_to_test, __pyx_n_s_out_dir_increase, __pyx_n_s_left, __pyx_n_s_right, __pyx_n_s_n_steps, __pyx_n_s_terminated_early, __pyx_n_s_delta_x, __pyx_n_s_delta_y, __pyx_n_s_int_max_steps_per_watershed, __pyx_n_s_index, __pyx_n_s_stream_fid, __pyx_n_s_boundary_list, __pyx_n_s_outlet_x, __pyx_n_s_outlet_y, __pyx_n_s_watershed_boundary, __pyx_n_s_left_in, __pyx_n_s_right_in, __pyx_n_s_out_dir, __pyx_n_s_watershed_feature, __pyx_n_s_watershed_polygon, __pyx_n_s_boundary_x, __pyx_n_s_boundary_y, __pyx_n_s_x, __pyx_n_s_fid); if (unlikely(!__pyx_tuple__51)) __PYX_ERR(0, 3830, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__51); + __Pyx_GIVEREF(__pyx_tuple__51); + __pyx_codeobj__52 = (PyObject*)__Pyx_PyCode_New(5, 0, 82, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__51, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_calculate_subwatershed_boundary_4, 3830, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__52)) __PYX_ERR(0, 3830, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":4162 + * + * + * def detect_outlets( # <<<<<<<<<<<<<< + * flow_dir_raster_path_band, flow_dir_type, target_outlet_vector_path): + * """Create point vector indicating flow raster outlets. + */ + __pyx_tuple__53 = PyTuple_Pack(40, __pyx_n_s_flow_dir_raster_path_band, __pyx_n_s_flow_dir_type, __pyx_n_s_target_outlet_vector_path, __pyx_n_s_d8_flow_dir_mode, __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_raster_x_size, __pyx_n_s_raster_y_size, __pyx_n_s_flow_dir, __pyx_n_s_flow_dir_n, __pyx_n_s_next_id, __pyx_n_s_n_dir, __pyx_n_s_is_outlet, __pyx_n_s_x_off_border, __pyx_n_s_y_off_border, __pyx_n_s_win_xsize_border, __pyx_n_s_win_ysize_border, __pyx_n_s_flow_dir_block, __pyx_n_s_raster_info, __pyx_n_s_flow_dir_nodata, __pyx_n_s_flow_dir_raster, __pyx_n_s_flow_dir_band, __pyx_n_s_raster_srs, __pyx_n_s_gpkg_driver, __pyx_n_s_outlet_vector, __pyx_n_s_outet_basename, __pyx_n_s_outlet_layer, __pyx_n_s_last_log_time, __pyx_n_s_block_offsets, __pyx_n_s_current_pixel, __pyx_n_s_outlet_point, __pyx_n_s_proj_x, __pyx_n_s_proj_y, __pyx_n_s_outlet_feature); if (unlikely(!__pyx_tuple__53)) __PYX_ERR(0, 4162, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__53); + __Pyx_GIVEREF(__pyx_tuple__53); + __pyx_codeobj__54 = (PyObject*)__Pyx_PyCode_New(3, 0, 40, 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_detect_outlets, 4162, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__54)) __PYX_ERR(0, 4162, __pyx_L1_error) + + /* "pygeoprocessing/routing/routing.pyx":4595 + * + * + * def _delete_feature( # <<<<<<<<<<<<<< + * stream_feature, stream_layer, upstream_to_downstream_id, + * downstream_to_upstream_ids): + */ + __pyx_tuple__55 = PyTuple_Pack(6, __pyx_n_s_stream_feature, __pyx_n_s_stream_layer, __pyx_n_s_upstream_to_downstream_id, __pyx_n_s_downstream_to_upstream_ids, __pyx_n_s_stream_fid, __pyx_n_s_downstream_fid); if (unlikely(!__pyx_tuple__55)) __PYX_ERR(0, 4595, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__55); + __Pyx_GIVEREF(__pyx_tuple__55); + __pyx_codeobj__56 = (PyObject*)__Pyx_PyCode_New(4, 0, 6, 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_delete_feature, 4595, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__56)) __PYX_ERR(0, 4595, __pyx_L1_error) + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} + +static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { + __pyx_umethod_PyList_Type_pop.type = (PyObject*)&PyList_Type; + if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + __pyx_float_0_2 = PyFloat_FromDouble(0.2); if (unlikely(!__pyx_float_0_2)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_float_0_5 = PyFloat_FromDouble(0.5); if (unlikely(!__pyx_float_0_5)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_float_1_25 = PyFloat_FromDouble(1.25); if (unlikely(!__pyx_float_1_25)) __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_5 = PyInt_FromLong(5); if (unlikely(!__pyx_int_5)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_100 = PyInt_FromLong(100); if (unlikely(!__pyx_int_100)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_1000000 = PyInt_FromLong(1000000L); if (unlikely(!__pyx_int_1000000)) __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 CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE 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 + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __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; + __pyx_vtable_15pygeoprocessing_7routing_7routing__ManagedRaster.flush = (void (*)(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *))__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_flush; + if (PyType_Ready(&__pyx_type_15pygeoprocessing_7routing_7routing__ManagedRaster) < 0) __PYX_ERR(0, 184, __pyx_L1_error) + #if PY_VERSION_HEX < 0x030800B1 + __pyx_type_15pygeoprocessing_7routing_7routing__ManagedRaster.tp_print = 0; + #endif + 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, 184, __pyx_L1_error) + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_ManagedRaster, (PyObject *)&__pyx_type_15pygeoprocessing_7routing_7routing__ManagedRaster) < 0) __PYX_ERR(0, 184, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_15pygeoprocessing_7routing_7routing__ManagedRaster) < 0) __PYX_ERR(0, 184, __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 + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); + /*--- Type import code ---*/ + __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", + #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 + sizeof(PyTypeObject), + #else + sizeof(PyHeapTypeObject), + #endif + __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(3, 9, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyImport_ImportModule("numpy"); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 200, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_ptype_5numpy_dtype = __Pyx_ImportType(__pyx_t_1, "numpy", "dtype", sizeof(PyArray_Descr), __Pyx_ImportType_CheckSize_Ignore); + if (!__pyx_ptype_5numpy_dtype) __PYX_ERR(2, 200, __pyx_L1_error) + __pyx_ptype_5numpy_flatiter = __Pyx_ImportType(__pyx_t_1, "numpy", "flatiter", sizeof(PyArrayIterObject), __Pyx_ImportType_CheckSize_Ignore); + if (!__pyx_ptype_5numpy_flatiter) __PYX_ERR(2, 223, __pyx_L1_error) + __pyx_ptype_5numpy_broadcast = __Pyx_ImportType(__pyx_t_1, "numpy", "broadcast", sizeof(PyArrayMultiIterObject), __Pyx_ImportType_CheckSize_Ignore); + if (!__pyx_ptype_5numpy_broadcast) __PYX_ERR(2, 227, __pyx_L1_error) + __pyx_ptype_5numpy_ndarray = __Pyx_ImportType(__pyx_t_1, "numpy", "ndarray", sizeof(PyArrayObject), __Pyx_ImportType_CheckSize_Ignore); + if (!__pyx_ptype_5numpy_ndarray) __PYX_ERR(2, 239, __pyx_L1_error) + __pyx_ptype_5numpy_generic = __Pyx_ImportType(__pyx_t_1, "numpy", "generic", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_generic) __PYX_ERR(2, 771, __pyx_L1_error) + __pyx_ptype_5numpy_number = __Pyx_ImportType(__pyx_t_1, "numpy", "number", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_number) __PYX_ERR(2, 773, __pyx_L1_error) + __pyx_ptype_5numpy_integer = __Pyx_ImportType(__pyx_t_1, "numpy", "integer", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_integer) __PYX_ERR(2, 775, __pyx_L1_error) + __pyx_ptype_5numpy_signedinteger = __Pyx_ImportType(__pyx_t_1, "numpy", "signedinteger", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_signedinteger) __PYX_ERR(2, 777, __pyx_L1_error) + __pyx_ptype_5numpy_unsignedinteger = __Pyx_ImportType(__pyx_t_1, "numpy", "unsignedinteger", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_unsignedinteger) __PYX_ERR(2, 779, __pyx_L1_error) + __pyx_ptype_5numpy_inexact = __Pyx_ImportType(__pyx_t_1, "numpy", "inexact", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_inexact) __PYX_ERR(2, 781, __pyx_L1_error) + __pyx_ptype_5numpy_floating = __Pyx_ImportType(__pyx_t_1, "numpy", "floating", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_floating) __PYX_ERR(2, 783, __pyx_L1_error) + __pyx_ptype_5numpy_complexfloating = __Pyx_ImportType(__pyx_t_1, "numpy", "complexfloating", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_complexfloating) __PYX_ERR(2, 785, __pyx_L1_error) + __pyx_ptype_5numpy_flexible = __Pyx_ImportType(__pyx_t_1, "numpy", "flexible", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_flexible) __PYX_ERR(2, 787, __pyx_L1_error) + __pyx_ptype_5numpy_character = __Pyx_ImportType(__pyx_t_1, "numpy", "character", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_character) __PYX_ERR(2, 789, __pyx_L1_error) + __pyx_ptype_5numpy_ufunc = __Pyx_ImportType(__pyx_t_1, "numpy", "ufunc", sizeof(PyUFuncObject), __Pyx_ImportType_CheckSize_Ignore); + if (!__pyx_ptype_5numpy_ufunc) __PYX_ERR(2, 827, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __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; +} + + +#ifndef CYTHON_NO_PYINIT_EXPORT +#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC +#elif PY_MAJOR_VERSION < 3 +#ifdef __cplusplus +#define __Pyx_PyMODINIT_FUNC extern "C" void +#else +#define __Pyx_PyMODINIT_FUNC void +#endif +#else +#ifdef __cplusplus +#define __Pyx_PyMODINIT_FUNC extern "C" PyObject * +#else +#define __Pyx_PyMODINIT_FUNC PyObject * +#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 CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) { + #if PY_VERSION_HEX >= 0x030700A1 + static PY_INT64_T main_interpreter_id = -1; + PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp); + if (main_interpreter_id == -1) { + main_interpreter_id = current_id; + return (unlikely(current_id == -1)) ? -1 : 0; + } else if (unlikely(main_interpreter_id != current_id)) + #else + static PyInterpreterState *main_interpreter = NULL; + PyInterpreterState *current_interpreter = PyThreadState_Get()->interp; + if (!main_interpreter) { + main_interpreter = current_interpreter; + } else if (unlikely(main_interpreter != current_interpreter)) + #endif + { + PyErr_SetString( + PyExc_ImportError, + "Interpreter change detected - this module can only be loaded into one interpreter per process."); + return -1; + } + return 0; +} +static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) { + PyObject *value = PyObject_GetAttrString(spec, from_name); + int result = 0; + if (likely(value)) { + if (allow_none || value != Py_None) { + result = PyDict_SetItemString(moddict, to_name, value); + } + Py_DECREF(value); + } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Clear(); + } else { + result = -1; + } + return result; +} +static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) { + PyObject *module = NULL, *moddict, *modname; + if (__Pyx_check_single_interpreter()) + return NULL; + 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__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad; + return module; +bad: + Py_XDECREF(module); + return NULL; +} + + +static CYTHON_SMALL_CODE 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[8]; + static int __pyx_t_5[8]; + static int __pyx_t_6[8]; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannyDeclarations + #if CYTHON_PEP489_MULTI_PHASE_INIT + if (__pyx_m) { + if (__pyx_m == __pyx_pyinit_module) return 0; + PyErr_SetString(PyExc_RuntimeError, "Module 'routing' has already been imported. Re-initialisation is not supported."); + return -1; + } + #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) + #ifdef __Pxy_PyFrame_Initialize_Offsets + __Pxy_PyFrame_Initialize_Offsets(); + #endif + __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) + Py_INCREF(__pyx_b); + __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) + Py_INCREF(__pyx_cython_runtime); + 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_SetAttr(__pyx_m, __pyx_n_s_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)) __PYX_ERR(0, 1, __pyx_L1_error) + if (unlikely(__Pyx_modinit_type_import_code() < 0)) __PYX_ERR(0, 1, __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":20 + * 5 6 7 + * """ + * import collections # <<<<<<<<<<<<<< + * import logging + * import os + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_collections, 0, 0); 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_collections, __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 collections + * import logging # <<<<<<<<<<<<<< + * import os + * import shutil + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_logging, 0, 0); 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_logging, __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 collections + * import logging + * import os # <<<<<<<<<<<<<< + * import shutil + * import tempfile + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_os, 0, 0); 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_os, __pyx_t_1) < 0) __PYX_ERR(0, 22, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":23 + * import logging + * import os + * import shutil # <<<<<<<<<<<<<< + * import tempfile + * import time + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_shutil, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 23, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_shutil, __pyx_t_1) < 0) __PYX_ERR(0, 23, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":24 + * import os + * import shutil + * import tempfile # <<<<<<<<<<<<<< + * import time + * + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_tempfile, 0, 0); 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_tempfile, __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 shutil + * import tempfile + * import time # <<<<<<<<<<<<<< + * + * cimport cython + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_time, 0, 0); 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_time, __pyx_t_1) < 0) __PYX_ERR(0, 25, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":41 + * from libcpp.stack cimport stack + * from libcpp.vector cimport vector + * from osgeo import gdal # <<<<<<<<<<<<<< + * from osgeo import ogr + * from osgeo import osr + */ + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 41, __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, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 41, __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, 41, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_gdal, __pyx_t_1) < 0) __PYX_ERR(0, 41, __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.vector cimport vector + * from osgeo import gdal + * from osgeo import ogr # <<<<<<<<<<<<<< + * from osgeo import osr + * import numpy + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 42, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_ogr); + __Pyx_GIVEREF(__pyx_n_s_ogr); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_ogr); + __pyx_t_1 = __Pyx_Import(__pyx_n_s_osgeo, __pyx_t_2, 0); 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_ImportFrom(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 42, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_ogr, __pyx_t_2) < 0) __PYX_ERR(0, 42, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":43 + * from osgeo import gdal + * from osgeo import ogr + * from osgeo import osr # <<<<<<<<<<<<<< + * import numpy + * import shapely.wkb + */ + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_osr); + __Pyx_GIVEREF(__pyx_n_s_osr); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_osr); + __pyx_t_2 = __Pyx_Import(__pyx_n_s_osgeo, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 43, __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_osr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_osr, __pyx_t_1) < 0) __PYX_ERR(0, 43, __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":44 + * from osgeo import ogr + * from osgeo import osr + * import numpy # <<<<<<<<<<<<<< + * import shapely.wkb + * import shapely.ops + */ + __pyx_t_2 = __Pyx_Import(__pyx_n_s_numpy, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 44, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_numpy, __pyx_t_2) < 0) __PYX_ERR(0, 44, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":45 + * from osgeo import osr + * import numpy + * import shapely.wkb # <<<<<<<<<<<<<< + * import shapely.ops + * import scipy.stats + */ + __pyx_t_2 = __Pyx_Import(__pyx_n_s_shapely_wkb, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 45, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_shapely, __pyx_t_2) < 0) __PYX_ERR(0, 45, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":46 + * import numpy + * import shapely.wkb + * import shapely.ops # <<<<<<<<<<<<<< + * import scipy.stats + * + */ + __pyx_t_2 = __Pyx_Import(__pyx_n_s_shapely_ops, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 46, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_shapely, __pyx_t_2) < 0) __PYX_ERR(0, 46, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":47 + * import shapely.wkb + * import shapely.ops + * import scipy.stats # <<<<<<<<<<<<<< + * + * from ..geoprocessing_core import DEFAULT_OSR_AXIS_MAPPING_STRATEGY + */ + __pyx_t_2 = __Pyx_Import(__pyx_n_s_scipy_stats, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 47, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_scipy, __pyx_t_2) < 0) __PYX_ERR(0, 47, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":49 + * import scipy.stats + * + * from ..geoprocessing_core import DEFAULT_OSR_AXIS_MAPPING_STRATEGY # <<<<<<<<<<<<<< + * import pygeoprocessing + * + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 49, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_DEFAULT_OSR_AXIS_MAPPING_STRATEG); + __Pyx_GIVEREF(__pyx_n_s_DEFAULT_OSR_AXIS_MAPPING_STRATEG); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_DEFAULT_OSR_AXIS_MAPPING_STRATEG); + __pyx_t_1 = __Pyx_Import(__pyx_n_s_geoprocessing_core, __pyx_t_2, 2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 49, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_DEFAULT_OSR_AXIS_MAPPING_STRATEG); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 49, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_DEFAULT_OSR_AXIS_MAPPING_STRATEG, __pyx_t_2) < 0) __PYX_ERR(0, 49, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":50 + * + * from ..geoprocessing_core import DEFAULT_OSR_AXIS_MAPPING_STRATEGY + * import pygeoprocessing # <<<<<<<<<<<<<< + * + * LOGGER = logging.getLogger(__name__) + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_pygeoprocessing, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 50, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pygeoprocessing, __pyx_t_1) < 0) __PYX_ERR(0, 50, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/routing.pyx":52 + * import pygeoprocessing + * + * LOGGER = logging.getLogger(__name__) # <<<<<<<<<<<<<< + * + * cdef float _LOGGING_PERIOD = 10.0 + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_logging); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 52, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_getLogger); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 52, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 52, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 52, __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; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_LOGGER, __pyx_t_3) < 0) __PYX_ERR(0, 52, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":54 + * LOGGER = logging.getLogger(__name__) + * + * cdef float _LOGGING_PERIOD = 10.0 # <<<<<<<<<<<<<< + * + * # This module creates rasters with a memory xy block size of 2**BLOCK_BITS + */ + __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD = 10.0; + + /* "pygeoprocessing/routing/routing.pyx":57 + * + * # 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":60 + * + * # 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":65 + * DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS = ('GTiff', ( + * 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', + * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), # <<<<<<<<<<<<<< + * 'BLOCKYSIZE=%d' % (1 << BLOCK_BITS))) + * + */ + __pyx_t_3 = __Pyx_PyInt_From_long((1 << __pyx_v_15pygeoprocessing_7routing_7routing_BLOCK_BITS)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 65, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyUnicode_Format(__pyx_kp_u_BLOCKXSIZE_d, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 65, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":66 + * '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_3 = __Pyx_PyInt_From_long((1 << __pyx_v_15pygeoprocessing_7routing_7routing_BLOCK_BITS)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 66, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyUnicode_Format(__pyx_kp_u_BLOCKYSIZE_d, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 66, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/routing.pyx":64 + * # these are the creation options that'll be used for all the rasters + * DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS = ('GTiff', ( + * 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', # <<<<<<<<<<<<<< + * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), + * 'BLOCKYSIZE=%d' % (1 << BLOCK_BITS))) + */ + __pyx_t_3 = PyTuple_New(5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 64, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_kp_u_TILED_YES); + __Pyx_GIVEREF(__pyx_kp_u_TILED_YES); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_u_TILED_YES); + __Pyx_INCREF(__pyx_kp_u_BIGTIFF_YES); + __Pyx_GIVEREF(__pyx_kp_u_BIGTIFF_YES); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_kp_u_BIGTIFF_YES); + __Pyx_INCREF(__pyx_kp_u_COMPRESS_LZW); + __Pyx_GIVEREF(__pyx_kp_u_COMPRESS_LZW); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_kp_u_COMPRESS_LZW); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_t_2); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":63 + * + * # these are the creation options that'll be used for all the rasters + * DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS = ('GTiff', ( # <<<<<<<<<<<<<< + * 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', + * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), + */ + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 63, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_u_GTiff); + __Pyx_GIVEREF(__pyx_n_u_GTiff); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_n_u_GTiff); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); + __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT, __pyx_t_2) < 0) __PYX_ERR(0, 63, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":70 + * # 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":73 + * + * # 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":74 + * # 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":80 + * # 4x0 + * # 567 + * cdef int *D8_XOFFSET = [1, 1, 0, -1, -1, -1, 0, 1] # <<<<<<<<<<<<<< + * cdef int *D8_YOFFSET = [0, -1, -1, -1, 0, +1, +1, +1] + * + */ + __pyx_t_4[0] = 1; + __pyx_t_4[1] = 1; + __pyx_t_4[2] = 0; + __pyx_t_4[3] = -1; + __pyx_t_4[4] = -1; + __pyx_t_4[5] = -1; + __pyx_t_4[6] = 0; + __pyx_t_4[7] = 1; + __pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET = __pyx_t_4; + + /* "pygeoprocessing/routing/routing.pyx":81 + * # 567 + * cdef int *D8_XOFFSET = [1, 1, 0, -1, -1, -1, 0, 1] + * cdef int *D8_YOFFSET = [0, -1, -1, -1, 0, +1, +1, +1] # <<<<<<<<<<<<<< + * + * # this is used to calculate the opposite D8 direction interpreting the index + */ + __pyx_t_5[0] = 0; + __pyx_t_5[1] = -1; + __pyx_t_5[2] = -1; + __pyx_t_5[3] = -1; + __pyx_t_5[4] = 0; + __pyx_t_5[5] = 1; + __pyx_t_5[6] = 1; + __pyx_t_5[7] = 1; + __pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET = __pyx_t_5; + + /* "pygeoprocessing/routing/routing.pyx":85 + * # 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] # <<<<<<<<<<<<<< + * + * # default of number of pixels to naturally drain. This number was derived off + */ + __pyx_t_6[0] = 4; + __pyx_t_6[1] = 5; + __pyx_t_6[2] = 6; + __pyx_t_6[3] = 7; + __pyx_t_6[4] = 0; + __pyx_t_6[5] = 1; + __pyx_t_6[6] = 2; + __pyx_t_6[7] = 3; + __pyx_v_15pygeoprocessing_7routing_7routing_D8_REVERSE_DIRECTION = __pyx_t_6; + + /* "pygeoprocessing/routing/routing.pyx":89 + * # default of number of pixels to naturally drain. This number was derived off + * # of reasonable expectations from a 30m DEM + * cdef int _MAX_PIXEL_FILL_COUNT = 500 # <<<<<<<<<<<<<< + * + * # exposing stl::priority_queue so we can have all 3 template arguments so + */ + __pyx_v_15pygeoprocessing_7routing_7routing__MAX_PIXEL_FILL_COUNT = 0x1F4; + + /* "pygeoprocessing/routing/routing.pyx":568 + * + * + * 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_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_1_generate_read_bounds, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 568, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_generate_read_bounds, __pyx_t_2) < 0) __PYX_ERR(0, 568, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":614 + * def fill_pits( + * dem_raster_path_band, target_filled_dem_raster_path, + * working_dir=None, long max_pixel_fill_count=_MAX_PIXEL_FILL_COUNT, # <<<<<<<<<<<<<< + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): + * """Fill the pits in a DEM. + */ + __pyx_k__5 = __pyx_v_15pygeoprocessing_7routing_7routing__MAX_PIXEL_FILL_COUNT; + + /* "pygeoprocessing/routing/routing.pyx":615 + * dem_raster_path_band, target_filled_dem_raster_path, + * working_dir=None, long max_pixel_fill_count=_MAX_PIXEL_FILL_COUNT, + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): # <<<<<<<<<<<<<< + * """Fill the pits in a DEM. + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 615, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_k__4 = __pyx_t_2; + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":612 + * + * + * def fill_pits( # <<<<<<<<<<<<<< + * dem_raster_path_band, target_filled_dem_raster_path, + * working_dir=None, long max_pixel_fill_count=_MAX_PIXEL_FILL_COUNT, + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_3fill_pits, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 612, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_fill_pits_2, __pyx_t_2) < 0) __PYX_ERR(0, 612, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":997 + * dem_raster_path_band, target_flow_dir_path, + * working_dir=None, + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): # <<<<<<<<<<<<<< + * """D8 flow direction. + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 997, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_k__6 = __pyx_t_2; + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":994 + * + * + * def flow_dir_d8( # <<<<<<<<<<<<<< + * dem_raster_path_band, target_flow_dir_path, + * working_dir=None, + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_5flow_dir_d8, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 994, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_flow_dir_d8_2, __pyx_t_2) < 0) __PYX_ERR(0, 994, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1362 + * flow_dir_raster_path_band, target_flow_accum_raster_path, + * weight_raster_path_band=None, + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): # <<<<<<<<<<<<<< + * """D8 flow accumulation. + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1362, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_k__8 = __pyx_t_2; + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1359 + * + * + * def flow_accumulation_d8( # <<<<<<<<<<<<<< + * flow_dir_raster_path_band, target_flow_accum_raster_path, + * weight_raster_path_band=None, + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_7flow_accumulation_d8, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1359, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_flow_accumulation_d8, __pyx_t_2) < 0) __PYX_ERR(0, 1359, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1584 + * def flow_dir_mfd( + * dem_raster_path_band, target_flow_dir_path, working_dir=None, + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): # <<<<<<<<<<<<<< + * """Multiple flow direction. + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1584, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_k__10 = __pyx_t_2; + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1582 + * + * + * def flow_dir_mfd( # <<<<<<<<<<<<<< + * dem_raster_path_band, target_flow_dir_path, working_dir=None, + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_9flow_dir_mfd, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1582, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_flow_dir_mfd, __pyx_t_2) < 0) __PYX_ERR(0, 1582, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2076 + * flow_dir_mfd_raster_path_band, target_flow_accum_raster_path, + * weight_raster_path_band=None, + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): # <<<<<<<<<<<<<< + * """Multiple flow direction accumulation. + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2076, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_k__11 = __pyx_t_2; + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2073 + * + * + * def flow_accumulation_mfd( # <<<<<<<<<<<<<< + * flow_dir_mfd_raster_path_band, target_flow_accum_raster_path, + * weight_raster_path_band=None, + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_11flow_accumulation_mfd, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2073, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_flow_accumulation_mfd, __pyx_t_2) < 0) __PYX_ERR(0, 2073, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2358 + * target_distance_to_channel_raster_path, + * weight_raster_path_band=None, + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): # <<<<<<<<<<<<<< + * """Calculate distance to channel with D8 flow. + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2358, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_k__12 = __pyx_t_2; + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2354 + * + * + * def distance_to_channel_d8( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band, channel_raster_path_band, + * target_distance_to_channel_raster_path, + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_13distance_to_channel_d8, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2354, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_distance_to_channel_d8, __pyx_t_2) < 0) __PYX_ERR(0, 2354, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2547 + * flow_dir_mfd_raster_path_band, channel_raster_path_band, + * target_distance_to_channel_raster_path, weight_raster_path_band=None, + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): # <<<<<<<<<<<<<< + * """Calculate distance to channel with multiple flow direction. + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2547, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_k__13 = __pyx_t_2; + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2544 + * + * + * 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_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_15distance_to_channel_mfd, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2544, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_distance_to_channel_mfd, __pyx_t_2) < 0) __PYX_ERR(0, 2544, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2815 + * double flow_threshold, target_stream_raster_path, + * double trace_threshold_proportion=1.0, + * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): # <<<<<<<<<<<<<< + * """Classify a stream raster from MFD flow accumulation. + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2815, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_k__14 = __pyx_t_2; + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":2811 + * + * + * def extract_streams_mfd( # <<<<<<<<<<<<<< + * flow_accum_raster_path_band, flow_dir_mfd_path_band, + * double flow_threshold, target_stream_raster_path, + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_17extract_streams_mfd, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2811, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_extract_streams_mfd, __pyx_t_2) < 0) __PYX_ERR(0, 2811, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3011 + * + * + * 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_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_19_is_raster_path_band_formatted, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3011, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_is_raster_path_band_formatted, __pyx_t_2) < 0) __PYX_ERR(0, 3011, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3033 + * float min_p_val=0.05, + * autotune_flow_accumulation=False, + * osr_axis_mapping_strategy=DEFAULT_OSR_AXIS_MAPPING_STRATEGY): # <<<<<<<<<<<<<< + * """Extract Strahler order stream geometry from flow accumulation. + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_DEFAULT_OSR_AXIS_MAPPING_STRATEG); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3033, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_k__15 = __pyx_t_2; + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3025 + * + * + * def extract_strahler_streams_d8( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band, flow_accum_raster_path_band, + * dem_raster_path_band, + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_21extract_strahler_streams_d8, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3025, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_extract_strahler_streams_d8, __pyx_t_2) < 0) __PYX_ERR(0, 3025, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3700 + * + * + * def _build_discovery_finish_rasters( # <<<<<<<<<<<<<< + * flow_dir_d8_raster_path_band, target_discovery_raster_path, + * target_finish_raster_path): + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_23_build_discovery_finish_rasters, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3700, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_build_discovery_finish_rasters, __pyx_t_2) < 0) __PYX_ERR(0, 3700, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":3830 + * + * + * def calculate_subwatershed_boundary( # <<<<<<<<<<<<<< + * d8_flow_dir_raster_path_band, + * strahler_stream_vector_path, target_watershed_boundary_vector_path, + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_25calculate_subwatershed_boundary, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3830, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_calculate_subwatershed_boundary_4, __pyx_t_2) < 0) __PYX_ERR(0, 3830, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4162 + * + * + * def detect_outlets( # <<<<<<<<<<<<<< + * flow_dir_raster_path_band, flow_dir_type, target_outlet_vector_path): + * """Create point vector indicating flow raster outlets. + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_27detect_outlets, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4162, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_detect_outlets, __pyx_t_2) < 0) __PYX_ERR(0, 4162, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":4595 + * + * + * def _delete_feature( # <<<<<<<<<<<<<< + * stream_feature, stream_layer, upstream_to_downstream_id, + * downstream_to_upstream_ids): + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_29_delete_feature, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4595, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_delete_feature, __pyx_t_2) < 0) __PYX_ERR(0, 4595, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/routing.pyx":1 + * # coding=UTF-8 # <<<<<<<<<<<<<< + * # distutils: language=c++ + * # cython: language_level=3 + */ + __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1016 + * + * + * cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil: # <<<<<<<<<<<<<< + * """ + * returns the unit part of the dtype for a numpy datetime64 object. + */ + + /*--- 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", __pyx_clineno, __pyx_lineno, __pyx_filename); + } + Py_CLEAR(__pyx_m); + } 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(modname); + if (!m) goto end; + p = PyObject_GetAttrString(m, "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_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 + (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(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 + (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(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; +} + +/* PyDictVersioning */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0; +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { + PyObject **dictptr = NULL; + Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; + if (offset) { +#if CYTHON_COMPILING_IN_CPYTHON + dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); +#else + dictptr = _PyObject_GetDictPtr(obj); +#endif + } + return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; +} +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict))) + return 0; + return obj_dict_version == __Pyx_get_object_dict_version(obj); +} +#endif + +/* GetModuleGlobalName */ +#if CYTHON_USE_DICT_VERSIONS +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value) +#else +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name) +#endif +{ + 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); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } else if (unlikely(PyErr_Occurred())) { + return NULL; + } +#else + result = PyDict_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } +#endif +#else + result = PyObject_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } + PyErr_Clear(); +#endif + return __Pyx_GetBuiltinName(name); +} + +/* 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 | METH_STACKLESS))); + 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)(void*)meth)) (self, args, nargs, NULL); + } else { + return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs); + } +} +#endif + +/* PyFunctionFastCall */ +#if CYTHON_FAST_PYCALL +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 = __Pyx_PyFrame_GetLocalsplus(f); + 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, Py_ssize_t 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, (int)nargs, + k, (int)nk, + d, (int)nd, kwdefs, closure); +#else + result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL, + args, (int)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 + +/* PyObjectCall2Args */ +static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) { + PyObject *args, *result = NULL; + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(function)) { + PyObject *args[2] = {arg1, arg2}; + return __Pyx_PyFunction_FastCall(function, args, 2); + } + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(function)) { + PyObject *args[2] = {arg1, arg2}; + return __Pyx_PyCFunction_FastCall(function, args, 2); + } + #endif + args = PyTuple_New(2); + if (unlikely(!args)) goto done; + Py_INCREF(arg1); + PyTuple_SET_ITEM(args, 0, arg1); + Py_INCREF(arg2); + PyTuple_SET_ITEM(args, 1, arg2); + Py_INCREF(function); + result = __Pyx_PyObject_Call(function, args, NULL); + Py_DECREF(args); + Py_DECREF(function); +done: + return result; +} + +/* 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 (__Pyx_PyFastCFunction_Check(func)) { + 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()) { + if (unlikely(PyTuple_Check(key))) { + PyObject* args = PyTuple_Pack(1, key); + if (likely(args)) { + PyErr_SetObject(PyExc_KeyError, args); + Py_DECREF(args); + } + } else { + PyErr_SetObject(PyExc_KeyError, key); + } + } + 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 + +/* CIntToDigits */ +static const char DIGIT_PAIRS_10[2*10*10+1] = { + "00010203040506070809" + "10111213141516171819" + "20212223242526272829" + "30313233343536373839" + "40414243444546474849" + "50515253545556575859" + "60616263646566676869" + "70717273747576777879" + "80818283848586878889" + "90919293949596979899" +}; +static const char DIGIT_PAIRS_8[2*8*8+1] = { + "0001020304050607" + "1011121314151617" + "2021222324252627" + "3031323334353637" + "4041424344454647" + "5051525354555657" + "6061626364656667" + "7071727374757677" +}; +static const char DIGITS_HEX[2*16+1] = { + "0123456789abcdef" + "0123456789ABCDEF" +}; + +/* BuildPyUnicode */ +static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, char* chars, int clength, + int prepend_sign, char padding_char) { + PyObject *uval; + Py_ssize_t uoffset = ulength - clength; +#if CYTHON_USE_UNICODE_INTERNALS + Py_ssize_t i; +#if CYTHON_PEP393_ENABLED + void *udata; + uval = PyUnicode_New(ulength, 127); + if (unlikely(!uval)) return NULL; + udata = PyUnicode_DATA(uval); +#else + Py_UNICODE *udata; + uval = PyUnicode_FromUnicode(NULL, ulength); + if (unlikely(!uval)) return NULL; + udata = PyUnicode_AS_UNICODE(uval); +#endif + if (uoffset > 0) { + i = 0; + if (prepend_sign) { + __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, 0, '-'); + i++; + } + for (; i < uoffset; i++) { + __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, i, padding_char); + } + } + for (i=0; i < clength; i++) { + __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, uoffset+i, chars[i]); + } +#else + { + PyObject *sign = NULL, *padding = NULL; + uval = NULL; + if (uoffset > 0) { + prepend_sign = !!prepend_sign; + if (uoffset > prepend_sign) { + padding = PyUnicode_FromOrdinal(padding_char); + if (likely(padding) && uoffset > prepend_sign + 1) { + PyObject *tmp; + PyObject *repeat = PyInt_FromSize_t(uoffset - prepend_sign); + if (unlikely(!repeat)) goto done_or_error; + tmp = PyNumber_Multiply(padding, repeat); + Py_DECREF(repeat); + Py_DECREF(padding); + padding = tmp; + } + if (unlikely(!padding)) goto done_or_error; + } + if (prepend_sign) { + sign = PyUnicode_FromOrdinal('-'); + if (unlikely(!sign)) goto done_or_error; + } + } + uval = PyUnicode_DecodeASCII(chars, clength, NULL); + if (likely(uval) && padding) { + PyObject *tmp = PyNumber_Add(padding, uval); + Py_DECREF(uval); + uval = tmp; + } + if (likely(uval) && sign) { + PyObject *tmp = PyNumber_Add(sign, uval); + Py_DECREF(uval); + uval = tmp; + } +done_or_error: + Py_XDECREF(padding); + Py_XDECREF(sign); + } +#endif + return uval; +} + +/* CIntToPyUnicode */ +#ifdef _MSC_VER + #ifndef _MSC_STDINT_H_ + #if _MSC_VER < 1300 + typedef unsigned short uint16_t; + #else + typedef unsigned __int16 uint16_t; + #endif + #endif +#else + #include +#endif +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_int(int value, Py_ssize_t width, char padding_char, char format_char) { + char digits[sizeof(int)*3+2]; + char *dpos, *end = digits + sizeof(int)*3+2; + const char *hex_digits = DIGITS_HEX; + Py_ssize_t length, ulength; + int prepend_sign, last_one_off; + int remaining; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const int neg_one = (int) -1, const_zero = (int) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; + if (format_char == 'X') { + hex_digits += 16; + format_char = 'x'; + } + remaining = value; + last_one_off = 0; + dpos = end; + do { + int digit_pos; + switch (format_char) { + case 'o': + digit_pos = abs((int)(remaining % (8*8))); + remaining = (int) (remaining / (8*8)); + dpos -= 2; + *(uint16_t*)dpos = ((const uint16_t*)DIGIT_PAIRS_8)[digit_pos]; + last_one_off = (digit_pos < 8); + break; + case 'd': + digit_pos = abs((int)(remaining % (10*10))); + remaining = (int) (remaining / (10*10)); + dpos -= 2; + *(uint16_t*)dpos = ((const uint16_t*)DIGIT_PAIRS_10)[digit_pos]; + last_one_off = (digit_pos < 10); + break; + case 'x': + *(--dpos) = hex_digits[abs((int)(remaining % 16))]; + remaining = (int) (remaining / 16); + break; + default: + assert(0); + break; + } + } while (unlikely(remaining != 0)); + if (last_one_off) { + assert(*dpos == '0'); + dpos++; + } + length = end - dpos; + ulength = length; + prepend_sign = 0; + if (!is_unsigned && value <= neg_one) { + if (padding_char == ' ' || width <= length + 1) { + *(--dpos) = '-'; + ++length; + } else { + prepend_sign = 1; + } + ++ulength; + } + if (width > ulength) { + ulength = width; + } + if (ulength == 1) { + return PyUnicode_FromOrdinal(*dpos); + } + return __Pyx_PyUnicode_BuildFromAscii(ulength, dpos, (int) length, prepend_sign, padding_char); +} + +/* PyObjectFormatAndDecref */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f) { + if (unlikely(!s)) return NULL; + if (likely(PyUnicode_CheckExact(s))) return s; + #if PY_MAJOR_VERSION < 3 + if (likely(PyString_CheckExact(s))) { + PyObject *result = PyUnicode_FromEncodedObject(s, NULL, "strict"); + Py_DECREF(s); + return result; + } + #endif + return __Pyx_PyObject_FormatAndDecref(s, f); +} +static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f) { + PyObject *result = PyObject_Format(s, f); + Py_DECREF(s); + return result; +} + +/* JoinPyUnicode */ +static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength, + CYTHON_UNUSED Py_UCS4 max_char) { +#if CYTHON_USE_UNICODE_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + PyObject *result_uval; + int result_ukind; + Py_ssize_t i, char_pos; + void *result_udata; +#if CYTHON_PEP393_ENABLED + result_uval = PyUnicode_New(result_ulength, max_char); + if (unlikely(!result_uval)) return NULL; + result_ukind = (max_char <= 255) ? PyUnicode_1BYTE_KIND : (max_char <= 65535) ? PyUnicode_2BYTE_KIND : PyUnicode_4BYTE_KIND; + result_udata = PyUnicode_DATA(result_uval); +#else + result_uval = PyUnicode_FromUnicode(NULL, result_ulength); + if (unlikely(!result_uval)) return NULL; + result_ukind = sizeof(Py_UNICODE); + result_udata = PyUnicode_AS_UNICODE(result_uval); +#endif + char_pos = 0; + for (i=0; i < value_count; i++) { + int ukind; + Py_ssize_t ulength; + void *udata; + PyObject *uval = PyTuple_GET_ITEM(value_tuple, i); + if (unlikely(__Pyx_PyUnicode_READY(uval))) + goto bad; + ulength = __Pyx_PyUnicode_GET_LENGTH(uval); + if (unlikely(!ulength)) + continue; + if (unlikely(char_pos + ulength < 0)) + goto overflow; + ukind = __Pyx_PyUnicode_KIND(uval); + udata = __Pyx_PyUnicode_DATA(uval); + if (!CYTHON_PEP393_ENABLED || ukind == result_ukind) { + memcpy((char *)result_udata + char_pos * result_ukind, udata, (size_t) (ulength * result_ukind)); + } else { + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030300F0 || defined(_PyUnicode_FastCopyCharacters) + _PyUnicode_FastCopyCharacters(result_uval, char_pos, uval, 0, ulength); + #else + Py_ssize_t j; + for (j=0; j < ulength; j++) { + Py_UCS4 uchar = __Pyx_PyUnicode_READ(ukind, udata, j); + __Pyx_PyUnicode_WRITE(result_ukind, result_udata, char_pos+j, uchar); + } + #endif + } + char_pos += ulength; + } + return result_uval; +overflow: + PyErr_SetString(PyExc_OverflowError, "join() result is too long for a Python string"); +bad: + Py_DECREF(result_uval); + return NULL; +#else + result_ulength++; + value_count++; + return PyUnicode_Join(__pyx_empty_unicode, value_tuple); +#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_CyFunction_Check(func))) +#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 '?': return "'bool'"; + 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 '?': 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 '?': 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, 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; + ndim = ctx->head->field->type->ndim; + 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 '?': 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->is_valid_array)) { + 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((size_t)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(__Pyx_is_valid_index(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(__Pyx_is_valid_index(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(__Pyx_is_valid_index(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(__Pyx_is_valid_index(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!"); +} + +/* PyIntCompare */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED long 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))) { + int unequal; + unsigned long uintval; + Py_ssize_t size = Py_SIZE(op1); + const digit* digits = ((PyLongObject*)op1)->ob_digit; + if (intval == 0) { + if (size == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE; + } else if (intval < 0) { + if (size >= 0) + Py_RETURN_FALSE; + intval = -intval; + size = -size; + } else { + if (size <= 0) + Py_RETURN_FALSE; + } + uintval = (unsigned long) intval; +#if PyLong_SHIFT * 4 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 4)) { + unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif +#if PyLong_SHIFT * 3 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 3)) { + unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif +#if PyLong_SHIFT * 2 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 2)) { + unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif +#if PyLong_SHIFT * 1 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 1)) { + unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif + unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK)); + if (unequal == 0) 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)); +} + +/* PyIntBinop */ + #if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) { + (void)inplace; + (void)zerodivision_check; + #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 + +/* None */ + static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) { + PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname); +} + +/* PyIntBinop */ + #if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) { + (void)inplace; + (void)zerodivision_check; + #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 + +/* GetTopmostException */ + #if CYTHON_USE_EXC_INFO_STACK +static _PyErr_StackItem * +__Pyx_PyErr_GetTopmostException(PyThreadState *tstate) +{ + _PyErr_StackItem *exc_info = tstate->exc_info; + while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) && + exc_info->previous_item != NULL) + { + exc_info = exc_info->previous_item; + } + return exc_info; +} +#endif + +/* SaveResetException */ + #if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + #if CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate); + *type = exc_info->exc_type; + *value = exc_info->exc_value; + *tb = exc_info->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 CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = type; + exc_info->exc_value = value; + exc_info->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; icurexc_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 + +/* PyIntCompare */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_NeObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED long inplace) { + if (op1 == op2) { + Py_RETURN_FALSE; + } + #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))) { + int unequal; + unsigned long uintval; + Py_ssize_t size = Py_SIZE(op1); + const digit* digits = ((PyLongObject*)op1)->ob_digit; + if (intval == 0) { + if (size != 0) Py_RETURN_TRUE; else Py_RETURN_FALSE; + } else if (intval < 0) { + if (size >= 0) + Py_RETURN_TRUE; + intval = -intval; + size = -size; + } else { + if (size <= 0) + Py_RETURN_TRUE; + } + uintval = (unsigned long) intval; +#if PyLong_SHIFT * 4 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 4)) { + unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif +#if PyLong_SHIFT * 3 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 3)) { + unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif +#if PyLong_SHIFT * 2 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 2)) { + unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif +#if PyLong_SHIFT * 1 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 1)) { + unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif + unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK)); + if (unequal != 0) 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_NE)); +} + +/* 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 CYTHON_USE_EXC_INFO_STACK + { + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = local_type; + exc_info->exc_value = local_value; + exc_info->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; +} + +/* 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; +} + +/* CIntToPyUnicode */ + #ifdef _MSC_VER + #ifndef _MSC_STDINT_H_ + #if _MSC_VER < 1300 + typedef unsigned short uint16_t; + #else + typedef unsigned __int16 uint16_t; + #endif + #endif +#else + #include +#endif +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_long(long value, Py_ssize_t width, char padding_char, char format_char) { + char digits[sizeof(long)*3+2]; + char *dpos, *end = digits + sizeof(long)*3+2; + const char *hex_digits = DIGITS_HEX; + Py_ssize_t length, ulength; + int prepend_sign, last_one_off; + long remaining; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const long neg_one = (long) -1, const_zero = (long) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; + if (format_char == 'X') { + hex_digits += 16; + format_char = 'x'; + } + remaining = value; + last_one_off = 0; + dpos = end; + do { + int digit_pos; + switch (format_char) { + case 'o': + digit_pos = abs((int)(remaining % (8*8))); + remaining = (long) (remaining / (8*8)); + dpos -= 2; + *(uint16_t*)dpos = ((const uint16_t*)DIGIT_PAIRS_8)[digit_pos]; + last_one_off = (digit_pos < 8); + break; + case 'd': + digit_pos = abs((int)(remaining % (10*10))); + remaining = (long) (remaining / (10*10)); + dpos -= 2; + *(uint16_t*)dpos = ((const uint16_t*)DIGIT_PAIRS_10)[digit_pos]; + last_one_off = (digit_pos < 10); + break; + case 'x': + *(--dpos) = hex_digits[abs((int)(remaining % 16))]; + remaining = (long) (remaining / 16); + break; + default: + assert(0); + break; + } + } while (unlikely(remaining != 0)); + if (last_one_off) { + assert(*dpos == '0'); + dpos++; + } + length = end - dpos; + ulength = length; + prepend_sign = 0; + if (!is_unsigned && value <= neg_one) { + if (padding_char == ' ' || width <= length + 1) { + *(--dpos) = '-'; + ++length; + } else { + prepend_sign = 1; + } + ++ulength; + } + if (width > ulength) { + ulength = width; + } + if (ulength == 1) { + return PyUnicode_FromOrdinal(*dpos); + } + return __Pyx_PyUnicode_BuildFromAscii(ulength, dpos, (int) length, prepend_sign, padding_char); +} + +/* PyObjectGetMethod */ + static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) { + PyObject *attr; +#if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP + PyTypeObject *tp = Py_TYPE(obj); + PyObject *descr; + descrgetfunc f = NULL; + PyObject **dictptr, *dict; + int meth_found = 0; + assert (*method == NULL); + if (unlikely(tp->tp_getattro != PyObject_GenericGetAttr)) { + attr = __Pyx_PyObject_GetAttrStr(obj, name); + goto try_unpack; + } + if (unlikely(tp->tp_dict == NULL) && unlikely(PyType_Ready(tp) < 0)) { + return 0; + } + descr = _PyType_Lookup(tp, name); + if (likely(descr != NULL)) { + Py_INCREF(descr); +#if PY_MAJOR_VERSION >= 3 + #ifdef __Pyx_CyFunction_USED + if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type) || __Pyx_CyFunction_Check(descr))) + #else + if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type))) + #endif +#else + #ifdef __Pyx_CyFunction_USED + if (likely(PyFunction_Check(descr) || __Pyx_CyFunction_Check(descr))) + #else + if (likely(PyFunction_Check(descr))) + #endif +#endif + { + meth_found = 1; + } else { + f = Py_TYPE(descr)->tp_descr_get; + if (f != NULL && PyDescr_IsData(descr)) { + attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); + Py_DECREF(descr); + goto try_unpack; + } + } + } + dictptr = _PyObject_GetDictPtr(obj); + if (dictptr != NULL && (dict = *dictptr) != NULL) { + Py_INCREF(dict); + attr = __Pyx_PyDict_GetItemStr(dict, name); + if (attr != NULL) { + Py_INCREF(attr); + Py_DECREF(dict); + Py_XDECREF(descr); + goto try_unpack; + } + Py_DECREF(dict); + } + if (meth_found) { + *method = descr; + return 1; + } + if (f != NULL) { + attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); + Py_DECREF(descr); + goto try_unpack; + } + if (descr != NULL) { + *method = descr; + return 0; + } + PyErr_Format(PyExc_AttributeError, +#if PY_MAJOR_VERSION >= 3 + "'%.50s' object has no attribute '%U'", + tp->tp_name, name); +#else + "'%.50s' object has no attribute '%.400s'", + tp->tp_name, PyString_AS_STRING(name)); +#endif + return 0; +#else + attr = __Pyx_PyObject_GetAttrStr(obj, name); + goto try_unpack; +#endif +try_unpack: +#if CYTHON_UNPACK_METHODS + if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) { + PyObject *function = PyMethod_GET_FUNCTION(attr); + Py_INCREF(function); + Py_DECREF(attr); + *method = function; + return 1; + } +#endif + *method = attr; + return 0; +} + +/* PyObjectCallMethod1 */ + static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) { + PyObject *result = __Pyx_PyObject_CallOneArg(method, arg); + Py_DECREF(method); + return result; +} +static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) { + PyObject *method = NULL, *result; + int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); + if (likely(is_method)) { + result = __Pyx_PyObject_Call2Args(method, obj, arg); + Py_DECREF(method); + return result; + } + if (unlikely(!method)) return NULL; + return __Pyx__PyObject_CallMethod1(method, arg); +} + +/* append */ + static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x) { + if (likely(PyList_CheckExact(L))) { + if (unlikely(__Pyx_PyList_Append(L, x) < 0)) return -1; + } else { + PyObject* retval = __Pyx_PyObject_CallMethod1(L, __pyx_n_s_append, x); + if (unlikely(!retval)) + return -1; + Py_DECREF(retval); + } + return 0; +} + +/* pop_index */ + static PyObject* __Pyx__PyObject_PopNewIndex(PyObject* L, PyObject* py_ix) { + PyObject *r; + if (unlikely(!py_ix)) return NULL; + r = __Pyx__PyObject_PopIndex(L, py_ix); + Py_DECREF(py_ix); + return r; +} +static PyObject* __Pyx__PyObject_PopIndex(PyObject* L, PyObject* py_ix) { + return __Pyx_PyObject_CallMethod1(L, __pyx_n_s_pop, py_ix); +} +#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS +static PyObject* __Pyx__PyList_PopIndex(PyObject* L, PyObject* py_ix, Py_ssize_t ix) { + Py_ssize_t size = PyList_GET_SIZE(L); + if (likely(size > (((PyListObject*)L)->allocated >> 1))) { + Py_ssize_t cix = ix; + if (cix < 0) { + cix += size; + } + if (likely(__Pyx_is_valid_index(cix, size))) { + PyObject* v = PyList_GET_ITEM(L, cix); + __Pyx_SET_SIZE(L, Py_SIZE(L) - 1); + size -= 1; + memmove(&PyList_GET_ITEM(L, cix), &PyList_GET_ITEM(L, cix+1), (size_t)(size-cix)*sizeof(PyObject*)); + return v; + } + } + if (py_ix == Py_None) { + return __Pyx__PyObject_PopNewIndex(L, PyInt_FromSsize_t(ix)); + } else { + return __Pyx__PyObject_PopIndex(L, py_ix); + } +} +#endif + +/* CIntToPyUnicode */ + #ifdef _MSC_VER + #ifndef _MSC_STDINT_H_ + #if _MSC_VER < 1300 + typedef unsigned short uint16_t; + #else + typedef unsigned __int16 uint16_t; + #endif + #endif +#else + #include +#endif +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_Py_ssize_t(Py_ssize_t value, Py_ssize_t width, char padding_char, char format_char) { + char digits[sizeof(Py_ssize_t)*3+2]; + char *dpos, *end = digits + sizeof(Py_ssize_t)*3+2; + const char *hex_digits = DIGITS_HEX; + Py_ssize_t length, ulength; + int prepend_sign, last_one_off; + Py_ssize_t remaining; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const Py_ssize_t neg_one = (Py_ssize_t) -1, const_zero = (Py_ssize_t) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; + if (format_char == 'X') { + hex_digits += 16; + format_char = 'x'; + } + remaining = value; + last_one_off = 0; + dpos = end; + do { + int digit_pos; + switch (format_char) { + case 'o': + digit_pos = abs((int)(remaining % (8*8))); + remaining = (Py_ssize_t) (remaining / (8*8)); + dpos -= 2; + *(uint16_t*)dpos = ((const uint16_t*)DIGIT_PAIRS_8)[digit_pos]; + last_one_off = (digit_pos < 8); + break; + case 'd': + digit_pos = abs((int)(remaining % (10*10))); + remaining = (Py_ssize_t) (remaining / (10*10)); + dpos -= 2; + *(uint16_t*)dpos = ((const uint16_t*)DIGIT_PAIRS_10)[digit_pos]; + last_one_off = (digit_pos < 10); + break; + case 'x': + *(--dpos) = hex_digits[abs((int)(remaining % 16))]; + remaining = (Py_ssize_t) (remaining / 16); + break; + default: + assert(0); + break; + } + } while (unlikely(remaining != 0)); + if (last_one_off) { + assert(*dpos == '0'); + dpos++; + } + length = end - dpos; + ulength = length; + prepend_sign = 0; + if (!is_unsigned && value <= neg_one) { + if (padding_char == ' ' || width <= length + 1) { + *(--dpos) = '-'; + ++length; + } else { + prepend_sign = 1; + } + ++ulength; + } + if (width > ulength) { + ulength = width; + } + if (ulength == 1) { + return PyUnicode_FromOrdinal(*dpos); + } + return __Pyx_PyUnicode_BuildFromAscii(ulength, dpos, (int) length, prepend_sign, padding_char); +} + +/* PyObjectCallMethod0 */ + static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) { + PyObject *method = NULL, *result = NULL; + int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); + if (likely(is_method)) { + result = __Pyx_PyObject_CallOneArg(method, obj); + Py_DECREF(method); + return result; + } + if (unlikely(!method)) goto bad; + result = __Pyx_PyObject_CallNoArg(method); + Py_DECREF(method); +bad: + return result; +} + +/* UnpackUnboundCMethod */ + static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) { + PyObject *method; + method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name); + if (unlikely(!method)) + return -1; + target->method = method; +#if CYTHON_COMPILING_IN_CPYTHON + #if PY_MAJOR_VERSION >= 3 + if (likely(__Pyx_TypeCheck(method, &PyMethodDescr_Type))) + #endif + { + PyMethodDescrObject *descr = (PyMethodDescrObject*) method; + target->func = descr->d_method->ml_meth; + target->flag = descr->d_method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS); + } +#endif + return 0; +} + +/* CallUnboundCMethod0 */ + static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self) { + PyObject *args, *result = NULL; + if (unlikely(!cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL; +#if CYTHON_ASSUME_SAFE_MACROS + args = PyTuple_New(1); + if (unlikely(!args)) goto bad; + Py_INCREF(self); + PyTuple_SET_ITEM(args, 0, self); +#else + args = PyTuple_Pack(1, self); + if (unlikely(!args)) goto bad; +#endif + result = __Pyx_PyObject_Call(cfunc->method, args, NULL); + Py_DECREF(args); +bad: + return result; +} + +/* pop */ + static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L) { + if (Py_TYPE(L) == &PySet_Type) { + return PySet_Pop(L); + } + return __Pyx_PyObject_CallMethod0(L, __pyx_n_s_pop); +} +#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS +static CYTHON_INLINE PyObject* __Pyx_PyList_Pop(PyObject* L) { + if (likely(PyList_GET_SIZE(L) > (((PyListObject*)L)->allocated >> 1))) { + __Pyx_SET_SIZE(L, Py_SIZE(L) - 1); + return PyList_GET_ITEM(L, PyList_GET_SIZE(L)); + } + return __Pyx_CallUnboundCMethod0(&__pyx_umethod_PyList_Type_pop, L); +} +#endif + +/* RaiseNoneIterError */ + static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); +} + +/* UnpackTupleError */ + static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) { + if (t == Py_None) { + __Pyx_RaiseNoneNotIterableError(); + } else if (PyTuple_GET_SIZE(t) < index) { + __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(t)); + } else { + __Pyx_RaiseTooManyValuesError(index); + } +} + +/* UnpackTuple2 */ + static CYTHON_INLINE int __Pyx_unpack_tuple2_exact( + PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2, int decref_tuple) { + PyObject *value1 = NULL, *value2 = NULL; +#if CYTHON_COMPILING_IN_PYPY + value1 = PySequence_ITEM(tuple, 0); if (unlikely(!value1)) goto bad; + value2 = PySequence_ITEM(tuple, 1); if (unlikely(!value2)) goto bad; +#else + value1 = PyTuple_GET_ITEM(tuple, 0); Py_INCREF(value1); + value2 = PyTuple_GET_ITEM(tuple, 1); Py_INCREF(value2); +#endif + if (decref_tuple) { + Py_DECREF(tuple); + } + *pvalue1 = value1; + *pvalue2 = value2; + return 0; +#if CYTHON_COMPILING_IN_PYPY +bad: + Py_XDECREF(value1); + Py_XDECREF(value2); + if (decref_tuple) { Py_XDECREF(tuple); } + return -1; +#endif +} +static int __Pyx_unpack_tuple2_generic(PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2, + int has_known_size, int decref_tuple) { + Py_ssize_t index; + PyObject *value1 = NULL, *value2 = NULL, *iter = NULL; + iternextfunc iternext; + iter = PyObject_GetIter(tuple); + if (unlikely(!iter)) goto bad; + if (decref_tuple) { Py_DECREF(tuple); tuple = NULL; } + iternext = Py_TYPE(iter)->tp_iternext; + value1 = iternext(iter); if (unlikely(!value1)) { index = 0; goto unpacking_failed; } + value2 = iternext(iter); if (unlikely(!value2)) { index = 1; goto unpacking_failed; } + if (!has_known_size && unlikely(__Pyx_IternextUnpackEndCheck(iternext(iter), 2))) goto bad; + Py_DECREF(iter); + *pvalue1 = value1; + *pvalue2 = value2; + return 0; +unpacking_failed: + if (!has_known_size && __Pyx_IterFinish() == 0) + __Pyx_RaiseNeedMoreValuesError(index); +bad: + Py_XDECREF(iter); + Py_XDECREF(value1); + Py_XDECREF(value2); + if (decref_tuple) { Py_XDECREF(tuple); } + return -1; +} + +/* dict_iter */ + static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_dict, PyObject* method_name, + Py_ssize_t* p_orig_length, int* p_source_is_dict) { + is_dict = is_dict || likely(PyDict_CheckExact(iterable)); + *p_source_is_dict = is_dict; + if (is_dict) { +#if !CYTHON_COMPILING_IN_PYPY + *p_orig_length = PyDict_Size(iterable); + Py_INCREF(iterable); + return iterable; +#elif PY_MAJOR_VERSION >= 3 + static PyObject *py_items = NULL, *py_keys = NULL, *py_values = NULL; + PyObject **pp = NULL; + if (method_name) { + const char *name = PyUnicode_AsUTF8(method_name); + if (strcmp(name, "iteritems") == 0) pp = &py_items; + else if (strcmp(name, "iterkeys") == 0) pp = &py_keys; + else if (strcmp(name, "itervalues") == 0) pp = &py_values; + if (pp) { + if (!*pp) { + *pp = PyUnicode_FromString(name + 4); + if (!*pp) + return NULL; + } + method_name = *pp; + } + } +#endif + } + *p_orig_length = 0; + if (method_name) { + PyObject* iter; + iterable = __Pyx_PyObject_CallMethod0(iterable, method_name); + if (!iterable) + return NULL; +#if !CYTHON_COMPILING_IN_PYPY + if (PyTuple_CheckExact(iterable) || PyList_CheckExact(iterable)) + return iterable; +#endif + iter = PyObject_GetIter(iterable); + Py_DECREF(iterable); + return iter; + } + return PyObject_GetIter(iterable); +} +static CYTHON_INLINE int __Pyx_dict_iter_next( + PyObject* iter_obj, CYTHON_NCP_UNUSED Py_ssize_t orig_length, CYTHON_NCP_UNUSED Py_ssize_t* ppos, + PyObject** pkey, PyObject** pvalue, PyObject** pitem, int source_is_dict) { + PyObject* next_item; +#if !CYTHON_COMPILING_IN_PYPY + if (source_is_dict) { + PyObject *key, *value; + if (unlikely(orig_length != PyDict_Size(iter_obj))) { + PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration"); + return -1; + } + if (unlikely(!PyDict_Next(iter_obj, ppos, &key, &value))) { + return 0; + } + if (pitem) { + PyObject* tuple = PyTuple_New(2); + if (unlikely(!tuple)) { + return -1; + } + Py_INCREF(key); + Py_INCREF(value); + PyTuple_SET_ITEM(tuple, 0, key); + PyTuple_SET_ITEM(tuple, 1, value); + *pitem = tuple; + } else { + if (pkey) { + Py_INCREF(key); + *pkey = key; + } + if (pvalue) { + Py_INCREF(value); + *pvalue = value; + } + } + return 1; + } else if (PyTuple_CheckExact(iter_obj)) { + Py_ssize_t pos = *ppos; + if (unlikely(pos >= PyTuple_GET_SIZE(iter_obj))) return 0; + *ppos = pos + 1; + next_item = PyTuple_GET_ITEM(iter_obj, pos); + Py_INCREF(next_item); + } else if (PyList_CheckExact(iter_obj)) { + Py_ssize_t pos = *ppos; + if (unlikely(pos >= PyList_GET_SIZE(iter_obj))) return 0; + *ppos = pos + 1; + next_item = PyList_GET_ITEM(iter_obj, pos); + Py_INCREF(next_item); + } else +#endif + { + next_item = PyIter_Next(iter_obj); + if (unlikely(!next_item)) { + return __Pyx_IterFinish(); + } + } + if (pitem) { + *pitem = next_item; + } else if (pkey && pvalue) { + if (__Pyx_unpack_tuple2(next_item, pkey, pvalue, source_is_dict, source_is_dict, 1)) + return -1; + } else if (pkey) { + *pkey = next_item; + } else { + *pvalue = next_item; + } + return 1; +} + +/* PyObjectFormat */ + #if CYTHON_USE_UNICODE_WRITER +static PyObject* __Pyx_PyObject_Format(PyObject* obj, PyObject* format_spec) { + int ret; + _PyUnicodeWriter writer; + if (likely(PyFloat_CheckExact(obj))) { +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x03040000 + _PyUnicodeWriter_Init(&writer, 0); +#else + _PyUnicodeWriter_Init(&writer); +#endif + ret = _PyFloat_FormatAdvancedWriter( + &writer, + obj, + format_spec, 0, PyUnicode_GET_LENGTH(format_spec)); + } else if (likely(PyLong_CheckExact(obj))) { +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x03040000 + _PyUnicodeWriter_Init(&writer, 0); +#else + _PyUnicodeWriter_Init(&writer); +#endif + ret = _PyLong_FormatAdvancedWriter( + &writer, + obj, + format_spec, 0, PyUnicode_GET_LENGTH(format_spec)); + } else { + return PyObject_Format(obj, format_spec); + } + if (unlikely(ret == -1)) { + _PyUnicodeWriter_Dealloc(&writer); + return NULL; + } + return _PyUnicodeWriter_Finish(&writer); +} +#endif + +/* pyfrozenset_new */ + static CYTHON_INLINE PyObject* __Pyx_PyFrozenSet_New(PyObject* it) { + if (it) { + PyObject* result; +#if CYTHON_COMPILING_IN_PYPY + PyObject* args; + args = PyTuple_Pack(1, it); + if (unlikely(!args)) + return NULL; + result = PyObject_Call((PyObject*)&PyFrozenSet_Type, args, NULL); + Py_DECREF(args); + return result; +#else + if (PyFrozenSet_CheckExact(it)) { + Py_INCREF(it); + return it; + } + result = PyFrozenSet_New(it); + if (unlikely(!result)) + return NULL; + if ((PY_VERSION_HEX >= 0x031000A1) || likely(PySet_GET_SIZE(result))) + return result; + Py_DECREF(result); +#endif + } +#if CYTHON_USE_TYPE_SLOTS + return PyFrozenSet_Type.tp_new(&PyFrozenSet_Type, __pyx_empty_tuple, NULL); +#else + return PyObject_Call((PyObject*)&PyFrozenSet_Type, __pyx_empty_tuple, NULL); +#endif +} + +/* PySetContains */ + static int __Pyx_PySet_ContainsUnhashable(PyObject *set, PyObject *key) { + int result = -1; + if (PySet_Check(key) && PyErr_ExceptionMatches(PyExc_TypeError)) { + PyObject *tmpkey; + PyErr_Clear(); + tmpkey = __Pyx_PyFrozenSet_New(key); + if (tmpkey != NULL) { + result = PySet_Contains(set, tmpkey); + Py_DECREF(tmpkey); + } + } + return result; +} +static CYTHON_INLINE int __Pyx_PySet_ContainsTF(PyObject* key, PyObject* set, int eq) { + int result = PySet_Contains(set, key); + if (unlikely(result < 0)) { + result = __Pyx_PySet_ContainsUnhashable(set, key); + } + return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); +} + +/* BytesEquals */ + static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY + return PyObject_RichCompareBool(s1, s2, equals); +#else + if (s1 == s2) { + return (equals == Py_EQ); + } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) { + const char *ps1, *ps2; + Py_ssize_t length = PyBytes_GET_SIZE(s1); + if (length != PyBytes_GET_SIZE(s2)) + return (equals == Py_NE); + ps1 = PyBytes_AS_STRING(s1); + ps2 = PyBytes_AS_STRING(s2); + if (ps1[0] != ps2[0]) { + return (equals == Py_NE); + } else if (length == 1) { + return (equals == Py_EQ); + } else { + int result; +#if CYTHON_USE_UNICODE_INTERNALS + Py_hash_t hash1, hash2; + hash1 = ((PyBytesObject*)s1)->ob_shash; + hash2 = ((PyBytesObject*)s2)->ob_shash; + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + return (equals == Py_NE); + } +#endif + result = memcmp(ps1, ps2, (size_t)length); + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) { + return (equals == Py_NE); + } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) { + return (equals == Py_NE); + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +#endif +} + +/* UnicodeEquals */ + static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY + return PyObject_RichCompareBool(s1, s2, equals); +#else +#if PY_MAJOR_VERSION < 3 + PyObject* owned_ref = NULL; +#endif + int s1_is_unicode, s2_is_unicode; + if (s1 == s2) { + goto return_eq; + } + s1_is_unicode = PyUnicode_CheckExact(s1); + s2_is_unicode = PyUnicode_CheckExact(s2); +#if PY_MAJOR_VERSION < 3 + if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) { + owned_ref = PyUnicode_FromObject(s2); + if (unlikely(!owned_ref)) + return -1; + s2 = owned_ref; + s2_is_unicode = 1; + } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) { + owned_ref = PyUnicode_FromObject(s1); + if (unlikely(!owned_ref)) + return -1; + s1 = owned_ref; + s1_is_unicode = 1; + } else if (((!s2_is_unicode) & (!s1_is_unicode))) { + return __Pyx_PyBytes_Equals(s1, s2, equals); + } +#endif + if (s1_is_unicode & s2_is_unicode) { + Py_ssize_t length; + int kind; + void *data1, *data2; + if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0)) + return -1; + length = __Pyx_PyUnicode_GET_LENGTH(s1); + if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) { + goto return_ne; + } +#if CYTHON_USE_UNICODE_INTERNALS + { + Py_hash_t hash1, hash2; + #if CYTHON_PEP393_ENABLED + hash1 = ((PyASCIIObject*)s1)->hash; + hash2 = ((PyASCIIObject*)s2)->hash; + #else + hash1 = ((PyUnicodeObject*)s1)->hash; + hash2 = ((PyUnicodeObject*)s2)->hash; + #endif + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + goto return_ne; + } + } +#endif + kind = __Pyx_PyUnicode_KIND(s1); + if (kind != __Pyx_PyUnicode_KIND(s2)) { + goto return_ne; + } + data1 = __Pyx_PyUnicode_DATA(s1); + data2 = __Pyx_PyUnicode_DATA(s2); + if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) { + goto return_ne; + } else if (length == 1) { + goto return_eq; + } else { + int result = memcmp(data1, data2, (size_t)(length * kind)); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & s2_is_unicode) { + goto return_ne; + } else if ((s2 == Py_None) & s1_is_unicode) { + goto return_ne; + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +return_eq: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ); +return_ne: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_NE); +#endif +} + +/* 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; +} + +/* PyObjectGetAttrStrNoError */ + static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) + __Pyx_PyErr_Clear(); +} +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) { + PyObject *result; +#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1 + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) { + return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1); + } +#endif + result = __Pyx_PyObject_GetAttrStr(obj, attr_name); + if (unlikely(!result)) { + __Pyx_PyObject_GetAttrStr_ClearAttributeError(); + } + return result; +} + +/* 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 __PYX_GOOD; +#else + if (PyObject_HasAttr(type_obj, __pyx_n_s_getstate)) goto __PYX_GOOD; +#endif +#if CYTHON_USE_PYTYPE_LOOKUP + object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; +#else + object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; +#endif + reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto __PYX_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 __PYX_BAD; +#else + object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD; +#endif + reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto __PYX_BAD; + if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) { + reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_reduce_cython); + if (likely(reduce_cython)) { + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + } else if (reduce == object_reduce || PyErr_Occurred()) { + goto __PYX_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_GetAttrStrNoError(type_obj, __pyx_n_s_setstate_cython); + if (likely(setstate_cython)) { + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + } else if (!setstate || PyErr_Occurred()) { + goto __PYX_BAD; + } + } + PyType_Modified((PyTypeObject*)type_obj); + } + } + goto __PYX_GOOD; +__PYX_BAD: + if (!PyErr_Occurred()) + PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name); + ret = -1; +__PYX_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; +} + +/* TypeImport */ + #ifndef __PYX_HAVE_RT_ImportType +#define __PYX_HAVE_RT_ImportType +static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name, + size_t size, enum __Pyx_ImportType_CheckSize check_size) +{ + PyObject *result = 0; + char warning[200]; + Py_ssize_t basicsize; +#ifdef Py_LIMITED_API + PyObject *py_basicsize; +#endif + result = PyObject_GetAttrString(module, class_name); + 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 ((size_t)basicsize < size) { + PyErr_Format(PyExc_ValueError, + "%.200s.%.200s size changed, may indicate binary incompatibility. " + "Expected %zd from C header, got %zd from PyObject", + module_name, class_name, size, basicsize); + goto bad; + } + if (check_size == __Pyx_ImportType_CheckSize_Error && (size_t)basicsize != size) { + PyErr_Format(PyExc_ValueError, + "%.200s.%.200s size changed, may indicate binary incompatibility. " + "Expected %zd from C header, got %zd from PyObject", + module_name, class_name, size, basicsize); + goto bad; + } + else if (check_size == __Pyx_ImportType_CheckSize_Warn && (size_t)basicsize > size) { + PyOS_snprintf(warning, sizeof(warning), + "%s.%s size changed, may indicate binary incompatibility. " + "Expected %zd from C header, got %zd from PyObject", + module_name, class_name, size, basicsize); + if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad; + } + return (PyTypeObject *)result; +bad: + Py_XDECREF(result); + return NULL; +} +#endif + +/* 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 ((1) && (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, (PyObject *)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_NCP_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)) { + __PYX_PY_DICT_LOOKUP_IF_MODIFIED( + use_cline, *cython_runtime_dict, + __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 (use_cline == Py_False || (use_cline != Py_True && 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); + 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)) {} + view->obj = NULL; + Py_DECREF(obj); +} +#endif + + + /* 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;\ + } + +/* 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 = (float)(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 = (float)(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: + 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.0, -1.0); + } + } 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 = (double)(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 = (double)(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: + 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.0, -1.0); + } + } 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_long(long value) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const long neg_one = (long) -1, const_zero = (long) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + 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); + } +} + +/* CIntFromPy */ + static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const long neg_one = (long) -1, const_zero = (long) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + 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; +} + +/* CIntFromPy */ + static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const int neg_one = (int) -1, const_zero = (int) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + 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; +} + +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const int neg_one = (int) -1, const_zero = (int) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + 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); + } +} + +/* CIntFromPy */ + static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const size_t neg_one = (size_t) -1, const_zero = (size_t) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + 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; +} + +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_PY_LONG_LONG(PY_LONG_LONG value) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const PY_LONG_LONG neg_one = (PY_LONG_LONG) -1, const_zero = (PY_LONG_LONG) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(PY_LONG_LONG) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(PY_LONG_LONG) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(PY_LONG_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(PY_LONG_LONG), + little, !is_unsigned); + } +} + +/* 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 int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { + Py_ssize_t i, n; + assert(PyExceptionClass_Check(exc_type)); + n = PyTuple_GET_SIZE(tuple); +#if PY_MAJOR_VERSION >= 3 + for (i=0; ip) { + #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 CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) { + int retval; + if (unlikely(!x)) return -1; + retval = __Pyx_PyObject_IsTrue(x); + Py_DECREF(x); + return retval; +} +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(b); + } +#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 */ diff --git a/src/pygeoprocessing/routing/routing.pyx b/src/pygeoprocessing/routing/routing.pyx index 02d03547..0b992d2f 100644 --- a/src/pygeoprocessing/routing/routing.pyx +++ b/src/pygeoprocessing/routing/routing.pyx @@ -17,27 +17,6 @@ is encoded as:: 4 x 0 5 6 7 """ -import pygeoprocessing -from ..geoprocessing_core import DEFAULT_OSR_AXIS_MAPPING_STRATEGY -import scipy.stats -import shapely.ops -import shapely.wkb -import numpy -from osgeo import osr -from osgeo import ogr -from osgeo import gdal -from libcpp.vector cimport vector -from libcpp.stack cimport stack -from libcpp.set cimport set as cset -from libcpp.queue cimport queue -from libcpp.pair cimport pair -from libcpp.list cimport list as clist -from libcpp.deque cimport deque -from libc.time cimport time_t -from libc.time cimport time as ctime -from cython.operator cimport preincrement as inc -from cython.operator cimport dereference as deref -from cpython.mem cimport PyMem_Malloc, PyMem_Free import collections import logging import os @@ -47,7 +26,28 @@ import time cimport cython cimport numpy +from cpython.mem cimport PyMem_Malloc, PyMem_Free +from cython.operator cimport dereference as deref +from cython.operator cimport preincrement as inc +from libc.time cimport time as ctime +from libc.time cimport time_t +from libcpp.deque cimport deque +from libcpp.list cimport list as clist +from libcpp.pair cimport pair +from libcpp.queue cimport queue +from libcpp.set cimport set as cset +from libcpp.stack cimport stack +from libcpp.vector cimport vector +from osgeo import gdal +from osgeo import ogr +from osgeo import osr +import numpy +import shapely.wkb +import shapely.ops +import scipy.stats +from ..geoprocessing_core import DEFAULT_OSR_AXIS_MAPPING_STRATEGY +import pygeoprocessing LOGGER = logging.getLogger(__name__) @@ -77,41 +77,37 @@ cdef double SQRT2_INV = 1.0 / 1.4142135623730951 # 321 # 4x0 # 567 -cdef int * D8_XOFFSET = [1, 1, 0, -1, -1, -1, 0, 1] -cdef int * D8_YOFFSET = [0, -1, -1, -1, 0, +1, +1, +1] +cdef int *D8_XOFFSET = [1, 1, 0, -1, -1, -1, 0, 1] +cdef int *D8_YOFFSET = [0, -1, -1, -1, 0, +1, +1, +1] # 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] - -# default of number of pixels to naturally drain. This number was derived off -# of reasonable expectations from a 30m DEM -cdef int _MAX_PIXEL_FILL_COUNT = 500 +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 # we can pass a different Compare functor cdef extern from "" namespace "std" nogil: cdef cppclass priority_queue[T, Container, Compare]: priority_queue() except + - priority_queue(priority_queue & ) except + - priority_queue(Container & ) + priority_queue(priority_queue&) except + + priority_queue(Container&) bint empty() void pop() - void push(T & ) + void push(T&) size_t size() - T & top() + T& top() # this is a least recently used cache written in C++ in an external file, # exposing here so _ManagedRaster can use it cdef extern from "LRUCache.h" nogil: cdef cppclass LRUCache[KEY_T, VAL_T]: LRUCache(int) - void put(KEY_T &, VAL_T&, clist[pair[KEY_T, VAL_T]]&) - clist[pair[KEY_T, VAL_T]].iterator begin() - clist[pair[KEY_T, VAL_T]].iterator end() + void put(KEY_T&, VAL_T&, clist[pair[KEY_T,VAL_T]]&) + clist[pair[KEY_T,VAL_T]].iterator begin() + clist[pair[KEY_T,VAL_T]].iterator end() bint exist(KEY_T &) VAL_T get(KEY_T &) - void clean(clist[pair[KEY_T, VAL_T]] &, int n_items) + void clean(clist[pair[KEY_T,VAL_T]]&, int n_items) size_t size() # this is the class type that'll get stored in the priority queue @@ -119,7 +115,7 @@ cdef struct PixelType: double value # pixel value int xi # pixel x coordinate in the raster int yi # pixel y coordinate in the raster - int priority # for breaking ties if two `value`s are equal. + int priority # for breaking ties if two `value`s are equal. # this struct is used to record an intermediate flow pixel's last calculated # direction and the flow accumulation value so far @@ -166,7 +162,7 @@ ctypedef queue[CoordinateType] CoordinateQueueType # functor for priority queue of pixels cdef cppclass GreaterPixel nogil: - bint get "operator()"(PixelType & lhs, PixelType & rhs): + 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 >. if lhs.value > rhs.value: @@ -182,7 +178,7 @@ cdef int _is_close(double x, double y, double abs_delta, double rel_delta): # 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 LRUCache[int, double*]* lru_cache cdef cset[int] dirty_blocks cdef int block_xsize cdef int block_ysize @@ -256,7 +252,7 @@ cdef class _ManagedRaster: 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 = raster_path + self.raster_path = raster_path self.write_mode = write_mode self.closed = 0 @@ -281,9 +277,9 @@ cdef class _ManagedRaster: return self.closed = 1 cdef int xi_copy, yi_copy - cdef numpy.ndarray[double, ndim = 2] block_array = numpy.empty( + cdef numpy.ndarray[double, ndim=2] block_array = numpy.empty( (self.block_ysize, self.block_xsize)) - cdef double * double_buffer + cdef double *double_buffer cdef int block_xi cdef int block_yi # initially the win size is the same as the block size unless @@ -398,8 +394,8 @@ cdef class _ManagedRaster: cdef int yoff = block_yi << self.block_ybits cdef int xi_copy, yi_copy - cdef numpy.ndarray[double, ndim = 2] block_array - cdef double * double_buffer + cdef numpy.ndarray[double, ndim=2] block_array + cdef double *double_buffer cdef clist[BlockBufferPair] removed_value_list # determine the block aligned xoffset for read as array @@ -429,7 +425,7 @@ cdef class _ManagedRaster: 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) + block_index, double_buffer, removed_value_list) if self.write_mode: n_attempts = 5 @@ -494,7 +490,7 @@ cdef class _ManagedRaster: cdef void flush(self) except *: cdef clist[BlockBufferPair] removed_value_list - cdef double * double_buffer + cdef double *double_buffer cdef cset[int].iterator dirty_itr cdef int block_index, block_xi, block_yi cdef int xoff, yoff, win_xsize, win_ysize @@ -611,7 +607,9 @@ def _generate_read_bounds(offset_dict, raster_x_size, raster_y_size): def fill_pits( dem_raster_path_band, target_filled_dem_raster_path, - working_dir=None, long max_pixel_fill_count=_MAX_PIXEL_FILL_COUNT, + working_dir=None, + long long max_pixel_fill_count=-1, + single_outlet_tuple=None, raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): """Fill the pits in a DEM. @@ -637,7 +635,13 @@ def fill_pits( call completes successfully. max_pixel_fill_count (int): maximum number of pixels to fill a pit before leaving as a depression. Useful if there are natural - large depressions. + large depressions. Value of -1 fills the raster with no search + limit. + single_outlet_tuple (tuple): If not None, this is an x/y tuple in + raster coordinates indicating the only pixel that can be + considered a drain. If None then any pixel that would drain to + the edge of the raster or a nodata hole will be considered a + drain. raster_driver_creation_tuple (tuple): a tuple containing a GDAL driver name string as the first element and a GDAL creation options tuple/list as the second. Defaults to a GTiff driver tuple @@ -665,7 +669,7 @@ def fill_pits( # keep track of how many steps searched on the pit to test against # max_pixel_fill_count - cdef int search_steps + cdef long long search_steps # `search_queue` is used to grow a flat region searching for a pour point # to determine if region is plateau or, in the absence of a pour point, @@ -696,6 +700,12 @@ def fill_pits( # have already been processed cdef int feature_id + # used to handle the case for single outlet mode + cdef int single_outlet=0, outlet_x=-1, outlet_y=-1 + if single_outlet_tuple is not None: + single_outlet = 1 + outlet_x, outlet_y = single_outlet_tuple + # used for time-delayed logging cdef time_t last_log_time last_log_time = ctime(NULL) @@ -763,7 +773,7 @@ def fill_pits( target_filled_dem_raster_path, gdal.OF_RASTER | gdal.GA_Update) filled_dem_band = filled_dem_raster.GetRasterBand(1) for offset_info, block_array in pygeoprocessing.iterblocks( - dem_raster_path_band): + dem_raster_path_band): filled_dem_band.WriteArray( block_array, xoff=offset_info['xoff'], yoff=offset_info['yoff']) filled_dem_band.FlushCache() @@ -793,10 +803,10 @@ def fill_pits( 'pixels complete') # search block for locally undrained pixels - for yi in range(1, win_ysize+1): - yi_root = yi-1+yoff - for xi in range(1, win_xsize+1): - xi_root = xi-1+xoff + for yi in range(win_ysize): + yi_root = yi+yoff + for xi in range(win_xsize): + xi_root = xi+xoff # this value is set in case it turns out to be the root of a # pit, we'll start the fill from this pixel in the last phase # of the algorithm @@ -808,22 +818,37 @@ def fill_pits( xi_root, yi_root) != mask_nodata: continue + # a single outlet trivially drains + if (single_outlet and + xi_root == outlet_x and + yi_root == outlet_y): + continue + # search neighbors for downhill or nodata downhill_neighbor = 0 nodata_neighbor = 0 for i_n in range(8): xi_n = xi_root+D8_XOFFSET[i_n] yi_n = yi_root+D8_YOFFSET[i_n] + 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 - break + if not single_outlet: + # it'll drain off the edge of the raster + nodata_neighbor = 1 + break + else: + # continue so we don't access out of bounds + continue n_height = filled_dem_managed_raster.get(xi_n, yi_n) if _is_close(n_height, dem_nodata, 1e-8, 1e-5): - # it'll drain to nodata - nodata_neighbor = 1 - break + if not single_outlet: + # it'll drain to nodata + nodata_neighbor = 1 + break + else: + # skip the rest so it doesn't drain downhill + continue if n_height < center_val: # it'll drain downhill downhill_neighbor = 1 @@ -850,8 +875,12 @@ def fill_pits( xi_q = search_queue.front().xi yi_q = search_queue.front().yi search_queue.pop() - if search_steps > max_pixel_fill_count: + if (max_pixel_fill_count > 0 and + search_steps > max_pixel_fill_count): # clear the search queue and quit + LOGGER.debug( + 'exceeded max pixel fill count when searching ' + 'for plateau drain') while not search_queue.empty(): search_queue.pop() natural_drain_exists = 1 @@ -861,18 +890,23 @@ def fill_pits( for i_n in range(8): xi_n = xi_q+D8_XOFFSET[i_n] yi_n = yi_q+D8_YOFFSET[i_n] + if (xi_n < 0 or xi_n >= raster_x_size or yi_n < 0 or yi_n >= raster_y_size): - natural_drain_exists = 1 + if not single_outlet: + natural_drain_exists = 1 continue + n_height = filled_dem_managed_raster.get( xi_n, yi_n) if _is_close(n_height, dem_nodata, 1e-8, 1e-5): - natural_drain_exists = 1 + if not single_outlet: + natural_drain_exists = 1 continue if n_height < center_val: natural_drain_exists = 1 continue + if flat_region_mask_managed_raster.get( xi_n, yi_n) == 1: # been set before on a previous iteration, skip @@ -909,8 +943,12 @@ def fill_pits( yi_q = pixel.yi # search to see if the fill has gone on too long - if search_steps > max_pixel_fill_count: + if (max_pixel_fill_count > 0 and + search_steps > max_pixel_fill_count): # clear pit_queue and quit + LOGGER.debug( + 'exceeded max pixel fill count when searching ' + 'for pour point') pit_queue = PitPriorityQueueType() natural_drain_exists = 1 break @@ -922,25 +960,42 @@ def fill_pits( for i_n in range(8): xi_n = xi_q+D8_XOFFSET[i_n] yi_n = yi_q+D8_YOFFSET[i_n] + 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 - break + if not single_outlet: + pour_point = 1 + break + else: + continue if pit_mask_managed_raster.get( xi_n, yi_n) == feature_id: # this cell has already been processed continue - # mark as visited in the search for pour point pit_mask_managed_raster.set(xi_n, yi_n, feature_id) n_height = filled_dem_managed_raster.get(xi_n, yi_n) - if _is_close(n_height, dem_nodata, 1e-8, 1e-5) or ( - n_height < fill_height): + if (single_outlet and xi_n == outlet_x + and yi_n == outlet_y): + fill_height = n_height + pour_point = 1 + break + + if _is_close(n_height, dem_nodata, 1e-8, 1e-5): + # we encounter a neighbor not processed that + # is nodata + if not single_outlet: + # it's only a pour point if we aren't in + # single outlet mode + pour_point = 1 + # skip so we don't go negative + continue + if n_height < fill_height: # we encounter a neighbor not processed that is - # lower than the current pixel or nodata + # lower than the current pixel pour_point = 1 break @@ -978,9 +1033,10 @@ def fill_pits( 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( - xi_n, yi_n) < fill_height: + n_height = filled_dem_managed_raster.get(xi_n, yi_n) + if _is_close(n_height, dem_nodata, 1e-8, 1e-5): + continue + if n_height < fill_height: filled_dem_managed_raster.set( xi_n, yi_n, fill_height) fill_queue.push(CoordinateType(xi_n, yi_n)) @@ -1027,7 +1083,7 @@ def flow_dir_d8( # and it's the most complex numerical type and will be compatible without # data loss for any lower type that might be used in # `dem_raster_path_band[0]`. - cdef numpy.ndarray[numpy.float64_t, ndim = 2] dem_buffer_array + cdef numpy.ndarray[numpy.float64_t, ndim=2] dem_buffer_array cdef int win_ysize, win_xsize, xoff, yoff # the _root variables remembers the pixel index where the plateau/pit @@ -1183,7 +1239,7 @@ def flow_dir_d8( (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) + **modified_offset_dict).astype(numpy.float64) # ensure these are set for the complier xi_n = -1 @@ -1397,7 +1453,7 @@ def flow_accumulation_d8( # and it's the most complex numerical type and will be compatible without # data loss for any lower type that might be used in # `dem_raster_path_band[0]`. - cdef numpy.ndarray[numpy.uint8_t, ndim = 2] flow_dir_buffer_array + cdef numpy.ndarray[numpy.uint8_t, ndim=2] flow_dir_buffer_array cdef int win_ysize, win_xsize, xoff, yoff # the _root variables remembers the pixel index where the plateau/pit @@ -1488,7 +1544,7 @@ def flow_accumulation_d8( if ctime(NULL) - last_log_time > _LOGGING_PERIOD: last_log_time = ctime(NULL) current_pixel = xoff + yoff * raster_x_size - LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( raster_x_size * raster_y_size)) # make a buffer big enough to capture block and boundaries around it @@ -1501,7 +1557,7 @@ def flow_accumulation_d8( (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) + **modified_offset_dict).astype(numpy.uint8) # ensure these are set for the complier xi_n = -1 @@ -1522,7 +1578,7 @@ def flow_accumulation_d8( yi_root = yi-1+yoff if weight_raster is not None: - weight_val = weight_raster.get( + weight_val = weight_raster.get( xi_root, yi_root) if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): weight_val = 0.0 @@ -1543,21 +1599,21 @@ def flow_accumulation_d8( yi_n < 0 or yi_n >= raster_y_size): # no upstream here continue - upstream_flow_dir = flow_dir_managed_raster.get( + upstream_flow_dir = 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]): # no upstream here continue - upstream_flow_accum = ( + upstream_flow_accum = ( flow_accum_managed_raster.get(xi_n, yi_n)) if _is_close(upstream_flow_accum, flow_accum_nodata, 1e-8, 1e-5): # 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 = weight_raster.get( + weight_val = weight_raster.get( xi_n, yi_n) if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): weight_val = 0.0 @@ -1619,7 +1675,7 @@ def flow_dir_mfd( # and it's the most complex numerical type and will be compatible without # data loss for any lower type that might be used in # `dem_raster_path_band[0]`. - cdef numpy.ndarray[numpy.float64_t, ndim = 2] dem_buffer_array + cdef numpy.ndarray[numpy.float64_t, ndim=2] dem_buffer_array cdef int win_ysize, win_xsize, xoff, yoff # the _root variables remembers the pixel index where the plateau/pit @@ -1647,7 +1703,7 @@ def flow_dir_mfd( cdef double nodata_downhill_slope_array[8] # a pointer reference to whatever kind of slope we're considering - cdef double * working_downhill_slope_array + cdef double *working_downhill_slope_array # as the neighbor slopes are calculated, this variable gathers them # together to calculate the final contribution of neighbor slopes to @@ -1790,7 +1846,7 @@ def flow_dir_mfd( if ctime(NULL) - last_log_time > _LOGGING_PERIOD: last_log_time = ctime(NULL) current_pixel = xoff + yoff * raster_x_size - LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( raster_x_size * raster_y_size)) # make a buffer big enough to capture block and boundaries around it @@ -1804,7 +1860,7 @@ def flow_dir_mfd( (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) + **modified_offset_dict).astype(numpy.float64) # ensure these are set for the complier xi_n = -1 @@ -1852,7 +1908,7 @@ def flow_dir_mfd( if sum_of_downhill_slopes > 0.0: compressed_integer_slopes = 0 for i_n in range(8): - compressed_integer_slopes |= ( < int > ( + compressed_integer_slopes |= (( 0.5 + downhill_slope_array[i_n] / sum_of_downhill_slopes * 0xF)) << (i_n * 4) @@ -1928,7 +1984,7 @@ def flow_dir_mfd( if working_downhill_slope_sum > 0.0: compressed_integer_slopes = 0 for i_n in range(8): - compressed_integer_slopes |= ( < int > ( + compressed_integer_slopes |= (( 0.5 + working_downhill_slope_array[i_n] / working_downhill_slope_sum * 0xF)) << ( i_n * 4) @@ -2000,7 +2056,7 @@ def flow_dir_mfd( n_drain_distance = drain_distance + ( SQRT2 if i_n & 1 else 1.0) - if ( < double > (dem_managed_raster.get( + if ((dem_managed_raster.get( xi_n, yi_n)) == root_height) and ( plateau_distance_managed_raster.get( xi_n, yi_n) > n_drain_distance): @@ -2053,7 +2109,7 @@ def flow_dir_mfd( continue compressed_integer_slopes = 0 for i_n in range(8): - compressed_integer_slopes |= ( < int > ( + compressed_integer_slopes |= (( 0.5 + downhill_slope_array[i_n] / sum_of_slope_weights * 0xF)) << (i_n * 4) flow_dir_managed_raster.set( @@ -2112,7 +2168,7 @@ def flow_accumulation_mfd( # and it's the most complex numerical type and will be compatible without # data loss for any lower type that might be used in # `dem_raster_path_band[0]`. - cdef numpy.ndarray[numpy.int32_t, ndim = 2] flow_dir_mfd_buffer_array + cdef numpy.ndarray[numpy.int32_t, ndim=2] flow_dir_mfd_buffer_array cdef int win_ysize, win_xsize, xoff, yoff # These are used to estimate % complete @@ -2225,7 +2281,7 @@ def flow_accumulation_mfd( if ctime(NULL) - last_log_time > _LOGGING_PERIOD: last_log_time = ctime(NULL) current_pixel = xoff + yoff * raster_x_size - LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( raster_x_size * raster_y_size)) # make a buffer big enough to capture block and boundaries around it @@ -2239,7 +2295,7 @@ def flow_accumulation_mfd( (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) + **modified_offset_dict).astype(numpy.int32) # ensure these are set for the complier xi_n = -1 @@ -2267,7 +2323,7 @@ def flow_accumulation_mfd( xi_root = xi-1+xoff yi_root = yi-1+yoff if weight_raster is not None: - weight_val = weight_raster.get( + weight_val = weight_raster.get( xi_root, yi_root) if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): weight_val = 0.0 @@ -2298,7 +2354,7 @@ def flow_accumulation_mfd( # no upstream here continue compressed_upstream_flow_dir = ( - < int > flow_dir_managed_raster.get(xi_n, yi_n)) + flow_dir_managed_raster.get(xi_n, yi_n)) upstream_flow_weight = ( compressed_upstream_flow_dir >> ( D8_REVERSE_DIRECTION[i_n] * 4)) & 0xF @@ -2314,7 +2370,7 @@ def flow_accumulation_mfd( flow_pixel.last_flow_dir = i_n search_stack.push(flow_pixel) if weight_raster is not None: - weight_val = weight_raster.get( + weight_val = weight_raster.get( xi_n, yi_n) if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): weight_val = 0.0 @@ -2334,7 +2390,7 @@ def flow_accumulation_mfd( flow_pixel.value += ( upstream_flow_accum * upstream_flow_weight / - upstream_flow_dir_sum) + upstream_flow_dir_sum) if not preempted: flow_accum_managed_raster.set( flow_pixel.xi, flow_pixel.yi, @@ -2391,7 +2447,7 @@ def distance_to_channel_d8( """ # These variables are used to iterate over the DEM using `iterblock` # indexes - cdef numpy.ndarray[numpy.uint8_t, ndim = 2] channel_buffer_array + cdef numpy.ndarray[numpy.uint8_t, ndim=2] channel_buffer_array cdef int win_ysize, win_xsize, xoff, yoff # these variables are used as pixel or neighbor indexes. @@ -2464,7 +2520,7 @@ def distance_to_channel_d8( if ctime(NULL) - last_log_time > _LOGGING_PERIOD: last_log_time = ctime(NULL) current_pixel = xoff + yoff * raster_x_size - LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( raster_x_size * raster_y_size)) # make a buffer big enough to capture block and boundaries around it @@ -2575,8 +2631,8 @@ def distance_to_channel_mfd( """ # These variables are used to iterate over the DEM using `iterblock` # indexes - cdef numpy.ndarray[numpy.uint8_t, ndim = 2] channel_buffer_array - cdef numpy.ndarray[numpy.int32_t, ndim = 2] flow_dir_buffer_array + cdef numpy.ndarray[numpy.uint8_t, ndim=2] channel_buffer_array + cdef numpy.ndarray[numpy.int32_t, ndim=2] flow_dir_buffer_array cdef int win_ysize, win_xsize, xoff, yoff # these variables are used as pixel or neighbor indexes. @@ -2670,7 +2726,7 @@ def distance_to_channel_mfd( if ctime(NULL) - last_log_time > _LOGGING_PERIOD: last_log_time = ctime(NULL) current_pixel = xoff + yoff * raster_x_size - LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( raster_x_size * raster_y_size)) # make a buffer big enough to capture block and boundaries around it @@ -2732,7 +2788,7 @@ def distance_to_channel_mfd( continue compressed_flow_dir = ( - < int > flow_dir_mfd_managed_raster.get( + flow_dir_mfd_managed_raster.get( pixel.xi, pixel.yi)) preempted = 0 @@ -2749,6 +2805,7 @@ def distance_to_channel_mfd( yi_n < 0 or yi_n >= raster_y_size): continue + if visited_managed_raster.get(xi_n, yi_n) == 0: visited_managed_raster.set(xi_n, yi_n, 1) preempted = 1 @@ -2848,7 +2905,7 @@ def extract_streams_mfd( Returns: None. """ - if trace_threshold_proportion < 0. or trace_threshold_proportion > 1.0: + 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) @@ -2889,7 +2946,7 @@ def extract_streams_mfd( # this queue is used to march the front from the stream pixel or the # backwards front for tracing downstream cdef CoordinateQueueType open_set, backtrace_set - cdef int xi_bn, yi_bn # used for backtrace neighbor coordinates + cdef int xi_bn, yi_bn # used for backtrace neighbor coordinates cdef time_t last_log_time = ctime(NULL) @@ -2904,7 +2961,7 @@ def extract_streams_mfd( if ctime(NULL) - last_log_time > _LOGGING_PERIOD: last_log_time = ctime(NULL) current_pixel = xoff + yoff * raster_x_size - LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( + LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( raster_x_size * raster_y_size)) for xi in range(win_xsize): xi_root = xi+xoff @@ -2917,7 +2974,7 @@ def extract_streams_mfd( if flow_accum < flow_threshold: continue - flow_dir_mfd = flow_dir_mfd_mr.get(xi_root, yi_root) + flow_dir_mfd = 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: @@ -2949,13 +3006,13 @@ def extract_streams_mfd( if (xi_sn < 0 or xi_sn >= raster_x_size or yi_sn < 0 or yi_sn >= raster_y_size): continue - flow_dir_mfd = flow_dir_mfd_mr.get(xi_sn, yi_sn) + flow_dir_mfd = 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: # upstream pixel flows into this one - stream_val = stream_mr.get(xi_sn, yi_sn) + stream_val = 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) @@ -2971,7 +3028,7 @@ def extract_streams_mfd( xi_bn = backtrace_set.front().xi yi_bn = backtrace_set.front().yi backtrace_set.pop() - flow_dir_mfd = ( + flow_dir_mfd = ( flow_dir_mfd_mr.get(xi_bn, yi_bn)) for i_sn in range(8): if (flow_dir_mfd >> (i_sn*4)) & 0xF > 0: @@ -2981,8 +3038,7 @@ def extract_streams_mfd( 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) + stream_mr.set(xi_sn, yi_sn, 1) backtrace_set.push( CoordinateType(xi_sn, yi_sn)) elif flow_accum >= trace_flow_threshold: @@ -3156,17 +3212,17 @@ def extract_strahler_streams_d8( cdef stack[StreamConnectivityPoint] source_point_stack cdef StreamConnectivityPoint source_stream_point - cdef int x_l = -1, y_l = -1 # the _l is for "local" aka "current" pixel + cdef int x_l=-1, y_l=-1 # the _l is for "local" aka "current" pixel # D8 backflow directions encoded as # 765 # 0x4 # 123 cdef int x_n, y_n # the _n is for "neighbor" - cdef int upstream_count = 0, upstream_index + cdef int upstream_count=0, upstream_index # this array is filled out as upstream directions are calculated and # indexed by `upstream_count` - cdef int * upstream_dirs = [0, 0, 0, 0, 0, 0, 0, 0] + cdef int *upstream_dirs = [0, 0, 0, 0, 0, 0, 0, 0] cdef long local_flow_accum # used to determine if source is a drain and should be tracked cdef int is_drain @@ -3201,17 +3257,17 @@ def extract_strahler_streams_d8( is_drain = 0 x_l = xoff + i y_l = yoff + j - local_flow_accum = flow_accum_managed_raster.get( + local_flow_accum = flow_accum_managed_raster.get( x_l, y_l) if local_flow_accum < min_flow_accum_threshold: continue # check to see if it's a drain - d_n = flow_dir_managed_raster.get(x_l, y_l) + d_n = flow_dir_managed_raster.get(x_l, y_l) x_n = x_l + D8_XOFFSET[d_n] y_n = y_l + D8_YOFFSET[d_n] if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_cols or - flow_dir_managed_raster.get( + flow_dir_managed_raster.get( x_n, y_n) == flow_nodata): is_drain = 1 @@ -3228,11 +3284,11 @@ def extract_strahler_streams_d8( # check if on border if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: continue - d_n = flow_dir_managed_raster.get(x_n, y_n) + d_n = flow_dir_managed_raster.get(x_n, y_n) if d_n == flow_nodata: continue if (D8_REVERSE_DIRECTION[d] == d_n and - flow_accum_managed_raster.get( + flow_accum_managed_raster.get( x_n, y_n) >= min_flow_accum_threshold): upstream_dirs[upstream_count] = d upstream_count += 1 @@ -3765,7 +3821,7 @@ def _build_discovery_finish_rasters( x_l = xoff + i y_l = yoff + j # check to see if this pixel is a drain - d_n = flow_dir_managed_raster.get(x_l, y_l) + d_n = flow_dir_managed_raster.get(x_l, y_l) if d_n == flow_dir_nodata: continue @@ -3774,7 +3830,7 @@ def _build_discovery_finish_rasters( y_n = y_l + D8_YOFFSET[d_n] if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows or - flow_dir_managed_raster.get( + flow_dir_managed_raster.get( x_n, y_n) == flow_dir_nodata): discovery_stack.push(CoordinateType(x_l, y_l)) finish_stack.push(FinishType(x_l, y_l, 1)) @@ -3797,7 +3853,7 @@ def _build_discovery_finish_rasters( if x_n < 0 or y_n < 0 or \ x_n >= n_cols or y_n >= n_rows: continue - n_dir = flow_dir_managed_raster.get(x_n, y_n) + n_dir = flow_dir_managed_raster.get(x_n, y_n) if n_dir == flow_dir_nodata: continue if D8_REVERSE_DIRECTION[test_dir] == n_dir: @@ -4003,7 +4059,7 @@ def calculate_subwatershed_boundary( visit_order_stack.pop() visit_order_stack.append((working_fid, ds_x, ds_y)) - cdef int edge_side, edge_dir, cell_to_test, out_dir_increase = -1 + cdef int edge_side, edge_dir, cell_to_test, out_dir_increase=-1 cdef int left, right, n_steps, terminated_early cdef int delta_x, delta_y cdef int _int_max_steps_per_watershed = max_steps_per_watershed @@ -4014,16 +4070,16 @@ def calculate_subwatershed_boundary( f'(calculate_subwatershed_boundary): watershed building ' f'{(index/len(visit_order_stack))*100:.1f}% complete') last_log_time = ctime(NULL) - discovery = discovery_managed_raster.get(x_l, y_l) + discovery = discovery_managed_raster.get(x_l, y_l) if discovery == -1: continue boundary_list = [(x_l, y_l)] - finish = finish_managed_raster.get(x_l, y_l) + finish = finish_managed_raster.get(x_l, y_l) outlet_x = x_l outlet_y = y_l watershed_boundary = ogr.Geometry(ogr.wkbLinearRing) - outflow_dir = d8_flow_dir_managed_raster.get(x_l, y_l) + outflow_dir = d8_flow_dir_managed_raster.get(x_l, y_l) # this is the center point of the pixel that will be offset to # make the edge @@ -4159,6 +4215,128 @@ def calculate_subwatershed_boundary( '(calculate_subwatershed_boundary): watershed building 100% complete') +def detect_lowest_drain_and_sink(dem_raster_path_band): + """Find the lowest drain and sink pixel in the DEM. + + This function is used to specify conditions to DEMs that are known to + have one real sink/drain, but may have several numerical sink/drains by + detecting both the lowest pixel that could drain the raster on an edge + and the lowest internal pixel that might sink the whole raster. + + Example: + raster A contains the following + * pixel at (3, 4) at 10m draining to a nodata pixel + * pixel at (15, 19) at 11m draining to a nodata pixel + * pixel at (19, 21) at 10m draining to a nodata pixel + * pit pixel at (10, 15) at 5m surrounded by non-draining pixels + * pit pixel at (25, 15) at 15m surrounded by non-draining pixels + * pit pixel at (2, 125) at 5m surrounded by non-draining pixels + + The result is two pixels indicating the first lowest edge and first + lowest sink seen: + drain_pixel = (3, 4), 10 + sink_pixel = (10, 15), 5 + + Args: + dem_raster_path_band (tuple): a raster/path band tuple to detect + sinks in. + + Return: + (drain_pixel, drain_height, sink_pixel, sink_height) - + two (x, y) tuples with corresponding heights, first + list is for edge drains, the second is for pit sinks. The x/y + coordinate is in raster coordinate space and _height is the + height of the given pixels in edge and pit respectively. + """ + # this outer loop drives the raster block search + cdef double lowest_drain_height = numpy.inf + cdef double lowest_sink_height = numpy.inf + + drain_pixel = None + sink_pixel = None + + dem_raster_info = pygeoprocessing.get_raster_info( + dem_raster_path_band[0]) + cdef double dem_nodata + # guard against undefined nodata by picking a value that's unlikely to + # be a dem value + if dem_raster_info['nodata'][0] is not None: + dem_nodata = dem_raster_info['nodata'][0] + else: + dem_nodata = IMPROBABLE_FLOAT_NODATA + + raster_x_size, raster_y_size = dem_raster_info['raster_size'] + + cdef _ManagedRaster dem_managed_raster = _ManagedRaster( + dem_raster_path_band[0], dem_raster_path_band[1], 0) + + cdef time_t last_log_time = ctime(NULL) + + for offset_dict in pygeoprocessing.iterblocks( + dem_raster_path_band, 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'] + + if ctime(NULL) - last_log_time > _LOGGING_PERIOD: + last_log_time = ctime(NULL) + current_pixel = xoff + yoff * raster_x_size + LOGGER.info( + '(infer_sinks): ' + f'{current_pixel} of {raster_x_size * raster_y_size} ' + 'pixels complete') + + # search block for local sinks + for yi in range(0, win_ysize): + yi_root = yi+yoff + for xi in range(0, win_xsize): + xi_root = xi+xoff + center_val = dem_managed_raster.get(xi_root, yi_root) + if _is_close(center_val, dem_nodata, 1e-8, 1e-5): + continue + + if (center_val > lowest_drain_height and + center_val > lowest_sink_height): + # already found something lower + continue + + # search neighbors for downhill or nodata + pixel_drains = 0 + for i_n in range(8): + xi_n = xi_root+D8_XOFFSET[i_n] + yi_n = yi_root+D8_YOFFSET[i_n] + + 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 center_val < lowest_drain_height: + # found a new lower edge height + lowest_drain_height = center_val + drain_pixel = (xi_root, yi_root) + pixel_drains = 1 + break + n_height = dem_managed_raster.get(xi_n, yi_n) + if _is_close(n_height, dem_nodata, 1e-8, 1e-5): + # it'll drain to nodata + if center_val < lowest_drain_height: + # found a new lower edge height + lowest_drain_height = center_val + drain_pixel = (xi_root, yi_root) + pixel_drains = 1 + break + if n_height < center_val: + # it'll drain downhill + pixel_drains = 1 + break + if not pixel_drains and center_val < lowest_sink_height: + lowest_sink_height = center_val + sink_pixel = (xi_root, yi_root) + return ( + drain_pixel, lowest_drain_height, + sink_pixel, lowest_sink_height) + + def detect_outlets( flow_dir_raster_path_band, flow_dir_type, target_outlet_vector_path): """Create point vector indicating flow raster outlets. @@ -4196,10 +4374,10 @@ def detect_outlets( cdef int xoff, yoff, win_xsize, win_ysize, xi, yi cdef int xi_root, yi_root, raster_x_size, raster_y_size cdef int flow_dir, flow_dir_n - cdef int next_id = 0, n_dir, is_outlet + cdef int next_id=0, n_dir, is_outlet cdef char x_off_border, y_off_border, win_xsize_border, win_ysize_border - cdef numpy.ndarray[numpy.npy_int32, ndim = 2] flow_dir_block + cdef numpy.ndarray[numpy.npy_int32, ndim=2] flow_dir_block raster_info = pygeoprocessing.get_raster_info( flow_dir_raster_path_band[0]) @@ -4335,7 +4513,7 @@ def detect_outlets( # entire MFD direction to the bit shifted 1111 mask, # if it equals 0 it means there was no proportional # flow in the `n_dir` direction. - if flow_dir & (0xF << (n_dir*4)) == 0: + if flow_dir&(0xF<<(n_dir*4)) == 0: continue flow_dir_n = flow_dir_block[ yi+D8_YOFFSET[n_dir], @@ -4426,7 +4604,7 @@ cdef void _diagonal_fill_step( (x_l - xdelta, y_l), (x_l, y_l - ydelta)] for x_t, y_t in test_list: - point_discovery = discovery_managed_raster.get( + point_discovery = discovery_managed_raster.get( x_t, y_t) if (point_discovery != discovery_nodata and point_discovery >= discovery and @@ -4467,7 +4645,7 @@ cdef int _in_watershed( cdef int y_n = y_l + D8_YOFFSET[direction_to_test] if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: return 0 - cdef long point_discovery = discovery_managed_raster.get(x_n, y_n) + cdef long point_discovery = discovery_managed_raster.get(x_n, y_n) return (point_discovery != discovery_nodata and point_discovery >= discovery and point_discovery <= finish) @@ -4515,7 +4693,7 @@ cdef _calculate_stream_geometry( Or ``None` if the point at (x_l, y_l) is below flow accum threshold. """ - cdef int x_1, y_1, x_n, y_n, d, d_n, stream_end = 0, pixel_length + cdef int x_1, y_1, x_n, y_n, d, d_n, stream_end=0, pixel_length if flow_accum_managed_raster.get(x_l, y_l) < flow_accum_threshold: return None @@ -4551,7 +4729,7 @@ cdef _calculate_stream_geometry( if (x_l, y_l) in coord_to_stream_ids: upstream_id_list = coord_to_stream_ids[(x_l, y_l)] del coord_to_stream_ids[(x_l, y_l)] - elif < int > flow_accum_managed_raster.get(x_l, y_l) >= \ + elif flow_accum_managed_raster.get(x_l, y_l) >= \ flow_accum_threshold: # check to see if we can take a step upstream for d in range(8): @@ -4563,15 +4741,15 @@ cdef _calculate_stream_geometry( continue # check for nodata - d_n = flow_dir_managed_raster.get(x_n, y_n) + d_n = flow_dir_managed_raster.get(x_n, y_n) if d_n == flow_dir_nodata: continue # check if there's an upstream inflow pixel with flow accum # greater than the threshold if D8_REVERSE_DIRECTION[d] == d_n and ( - < int > flow_accum_managed_raster.get( - x_n, y_n) > flow_accum_threshold): + flow_accum_managed_raster.get( + x_n, y_n) > flow_accum_threshold): stream_end = 0 next_dir = d break diff --git a/src/pygeoprocessing/routing/watershed.cpp b/src/pygeoprocessing/routing/watershed.cpp new file mode 100644 index 00000000..0cefd5c4 --- /dev/null +++ b/src/pygeoprocessing/routing/watershed.cpp @@ -0,0 +1,21754 @@ +/* Generated by Cython 0.29.23 */ + +#ifndef PY_SSIZE_T_CLEAN +#define PY_SSIZE_T_CLEAN +#endif /* 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_29_23" +#define CYTHON_HEX_VERSION 0x001D17F0 +#define CYTHON_FUTURE_DIVISION 1 +#include +#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 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 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 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 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 (PY_VERSION_HEX >= 0x03050000) + #endif + #ifndef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1) + #endif + #ifndef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1) + #endif + #ifndef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3) + #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 + #ifdef SIZEOF_VOID_P + enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) }; + #endif +#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 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 +#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 +void __Pyx_call_destructor(T& x) { + x.~T(); +} +template +class __Pyx_FakeReference { + public: + __Pyx_FakeReference() : ptr(NULL) { } + __Pyx_FakeReference(const T& ref) : ptr(const_cast(&ref)) { } + T *operator->() { return ptr; } + T *operator&() { return ptr; } + operator T&() { return *ptr; } + template bool operator ==(U other) { return *ptr == other; } + template 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" +#if PY_VERSION_HEX >= 0x030800A4 && PY_VERSION_HEX < 0x030800B2 + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#else + #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) +#endif + #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 +#ifndef METH_STACKLESS + #define METH_STACKLESS 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 | METH_STACKLESS))))) +#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_CPYTHON && PY_VERSION_HEX < 0x030400A1 + #define PyMem_RawMalloc(n) PyMem_Malloc(n) + #define PyMem_RawRealloc(p, n) PyMem_Realloc(p, n) + #define PyMem_RawFree(p) PyMem_Free(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; +} +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 +#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) + #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) + #else + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) + #endif +#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 || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) +#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? 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 +#ifndef PyObject_Unicode + #define PyObject_Unicode PyObject_Str +#endif +#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 PY_VERSION_HEX >= 0x030900A4 + #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt) + #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size) +#else + #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt) + #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size) +#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) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(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 +#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_MARK_ERR_POS(f_index, lineno) \ + { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; } +#define __PYX_ERR(f_index, lineno, Ln_error) \ + { __PYX_MARK_ERR_POS(f_index, lineno) 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__watershed +#define __PYX_HAVE_API__pygeoprocessing__routing__watershed +/* Early includes */ +#include +#include +#include "numpy/arrayobject.h" +#include "numpy/ndarrayobject.h" +#include "numpy/ndarraytypes.h" +#include "numpy/arrayscalars.h" +#include "numpy/ufuncobject.h" + + /* NumPy API declarations from "numpy/__init__.pxd" */ + +#include +#include +#include "ios" +#include "new" +#include "stdexcept" +#include "typeinfo" +#include +#include + + #if __cplusplus > 199711L + #include + + namespace cython_std { + template typename std::remove_reference::type&& move(T& t) noexcept { return std::move(t); } + template typename std::remove_reference::type&& move(T&& t) noexcept { return std::move(t); } + } + + #endif + +#include +#include +#include +#include "LRUCache.h" +#ifdef _OPENMP +#include +#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_UTF8 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8) +#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))) ) +static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) { + return (size_t) i < (size_t) limit; +} +#if defined (__cplusplus) && __cplusplus >= 201103L + #include + #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 int __Pyx_PyObject_IsTrueAndDecref(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) + 1); + 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 + #else + #include + #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/watershed.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; + + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":690 + * # 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":691 + * + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":692 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":693 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":697 + * #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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":698 + * + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":699 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":700 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":704 + * #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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":705 + * + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":714 + * # 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":715 + * # 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":716 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":718 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":719 + * + * ctypedef npy_ulong uint_t + * ctypedef npy_ulonglong ulong_t # <<<<<<<<<<<<<< + * ctypedef npy_ulonglong ulonglong_t + * + */ +typedef npy_ulonglong __pyx_t_5numpy_ulong_t; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":720 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":722 + * ctypedef npy_ulonglong ulonglong_t + * + * ctypedef npy_intp intp_t # <<<<<<<<<<<<<< + * ctypedef npy_uintp uintp_t + * + */ +typedef npy_intp __pyx_t_5numpy_intp_t; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":723 + * + * ctypedef npy_intp intp_t + * ctypedef npy_uintp uintp_t # <<<<<<<<<<<<<< + * + * ctypedef npy_double float_t + */ +typedef npy_uintp __pyx_t_5numpy_uintp_t; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":725 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":726 + * + * ctypedef npy_double float_t + * ctypedef npy_double double_t # <<<<<<<<<<<<<< + * ctypedef npy_longdouble longdouble_t + * + */ +typedef npy_double __pyx_t_5numpy_double_t; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":727 + * 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_9watershed__ManagedRaster; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":729 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":730 + * + * ctypedef npy_cfloat cfloat_t + * ctypedef npy_cdouble cdouble_t # <<<<<<<<<<<<<< + * ctypedef npy_clongdouble clongdouble_t + * + */ +typedef npy_cdouble __pyx_t_5numpy_cdouble_t; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":731 + * 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; + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":733 + * 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_opt_args_15pygeoprocessing_7routing_9watershed__c_split_geometry_into_seeds; + +/* "pygeoprocessing/routing/watershed.pyx":65 + * # this ctype is used to store the block ID and the block buffer as one object + * # inside Managed Raster + * ctypedef pair[int, int*] BlockBufferPair # <<<<<<<<<<<<<< + * + * # a class to allow fast random per-pixel access to a raster for both setting + */ +typedef std::pair __pyx_t_15pygeoprocessing_7routing_9watershed_BlockBufferPair; + +/* "pygeoprocessing/routing/watershed.pyx":385 + * # CoordinatePair().second is the y coordinate. Both are in integer pixel + * # coordinates. + * ctypedef pair[long, long] CoordinatePair # <<<<<<<<<<<<<< + * + * + */ +typedef std::pair __pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair; + +/* "pygeoprocessing/routing/watershed.pyx":402 + * + * + * cdef cset[CoordinatePair] _c_split_geometry_into_seeds( # <<<<<<<<<<<<<< + * source_geom_wkb, tuple flow_dir_geotransform, flow_dir_srs, + * flow_dir_n_cols, flow_dir_n_rows, + */ +struct __pyx_opt_args_15pygeoprocessing_7routing_9watershed__c_split_geometry_into_seeds { + int __pyx_n; + PyObject *diagnostic_vector_path; +}; + +/* "pygeoprocessing/routing/watershed.pyx":69 + * # a class to allow fast random per-pixel access to a raster for both setting + * # and reading pixels. + * cdef class _ManagedRaster: # <<<<<<<<<<<<<< + * cdef LRUCache[int, int*]* lru_cache + * cdef cset[int] dirty_blocks + */ +struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster { + PyObject_HEAD + struct __pyx_vtabstruct_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_vtab; + LRUCache *lru_cache; + std::set 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_9watershed__ManagedRaster { + void (*set)(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *, int, int, int); + int (*get)(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *, int, int); + void (*_load_block)(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *, int); +}; +static struct __pyx_vtabstruct_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_vtabptr_15pygeoprocessing_7routing_9watershed__ManagedRaster; +static CYTHON_INLINE void __pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_set(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *, int, int, int); +static CYTHON_INLINE int __pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_get(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__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); + +/* PyDictVersioning.proto */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +#define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1) +#define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\ + (version_var) = __PYX_GET_DICT_VERSION(dict);\ + (cache_var) = (value); +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\ + (VAR) = __pyx_dict_cached_value;\ + } else {\ + (VAR) = __pyx_dict_cached_value = (LOOKUP);\ + __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\ + }\ +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj); +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj); +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version); +#else +#define __PYX_GET_DICT_VERSION(dict) (0) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP); +#endif + +/* GetModuleGlobalName.proto */ +#if CYTHON_USE_DICT_VERSIONS +#define __Pyx_GetModuleGlobalName(var, name) {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\ + (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\ + __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ +} +#define __Pyx_GetModuleGlobalNameUncached(var, name) {\ + PY_UINT64_T __pyx_dict_version;\ + PyObject *__pyx_dict_cached_value;\ + (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ +} +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); +#else +#define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name) +#define __Pyx_GetModuleGlobalNameUncached(var, name) (var) = __Pyx__GetModuleGlobalName(name) +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name); +#endif + +/* 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, Py_ssize_t nargs, PyObject *kwargs); +#else +#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs) +#endif +#define __Pyx_BUILD_ASSERT_EXPR(cond)\ + (sizeof(char [1 - 2*!(cond)]) - 1) +#ifndef Py_MEMBER_SIZE +#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member) +#endif + static size_t __pyx_pyframe_localsplus_offset = 0; + #include "frameobject.h" + #define __Pxy_PyFrame_Initialize_Offsets()\ + ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\ + (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus))) + #define __Pyx_PyFrame_GetLocalsplus(frame)\ + (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset)) +#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 + +/* PyObjectCall2Args.proto */ +static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2); + +/* 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); + +/* 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); + +/* 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); + +/* PyIntCompare.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_NeObjC(PyObject *op1, PyObject *op2, long intval, long inplace); + +/* PyIntBinop.proto */ +#if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check); +#else +#define __Pyx_PyInt_SubtractObjC(op1, op2, intval, inplace, zerodivision_check)\ + (inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2)) +#endif + +/* PyObjectFormatAndDecref.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f); +static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f); + +/* IncludeStringH.proto */ +#include + +/* JoinPyUnicode.proto */ +static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength, + Py_UCS4 max_char); + +/* 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); + +/* PyIntFromDouble.proto */ +#if PY_MAJOR_VERSION < 3 +static CYTHON_INLINE PyObject* __Pyx_PyInt_FromDouble(double value); +#else +#define __Pyx_PyInt_FromDouble(value) PyLong_FromDouble(value) +#endif + +/* GetTopmostException.proto */ +#if CYTHON_USE_EXC_INFO_STACK +static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate); +#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 + +/* PyObjectGetMethod.proto */ +static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method); + +/* PyObjectCallMethod0.proto */ +static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name); + +/* RaiseNoneIterError.proto */ +static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void); + +/* UnpackTupleError.proto */ +static void __Pyx_UnpackTupleError(PyObject *, Py_ssize_t index); + +/* UnpackTuple2.proto */ +#define __Pyx_unpack_tuple2(tuple, value1, value2, is_tuple, has_known_size, decref_tuple)\ + (likely(is_tuple || PyTuple_Check(tuple)) ?\ + (likely(has_known_size || PyTuple_GET_SIZE(tuple) == 2) ?\ + __Pyx_unpack_tuple2_exact(tuple, value1, value2, decref_tuple) :\ + (__Pyx_UnpackTupleError(tuple, 2), -1)) :\ + __Pyx_unpack_tuple2_generic(tuple, value1, value2, has_known_size, decref_tuple)) +static CYTHON_INLINE int __Pyx_unpack_tuple2_exact( + PyObject* tuple, PyObject** value1, PyObject** value2, int decref_tuple); +static int __Pyx_unpack_tuple2_generic( + PyObject* tuple, PyObject** value1, PyObject** value2, int has_known_size, int decref_tuple); + +/* dict_iter.proto */ +static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* dict, int is_dict, PyObject* method_name, + Py_ssize_t* p_orig_length, int* p_is_dict); +static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* dict_or_iter, Py_ssize_t orig_length, Py_ssize_t* ppos, + PyObject** pkey, PyObject** pvalue, PyObject** pitem, int is_dict); + +/* BytesEquals.proto */ +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); + +/* UnicodeEquals.proto */ +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); + +/* 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); + +/* PyObjectGetAttrStrNoError.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name); + +/* SetupReduce.proto */ +static int __Pyx_setup_reduce(PyObject* type_obj); + +/* TypeImport.proto */ +#ifndef __PYX_HAVE_RT_ImportType_proto +#define __PYX_HAVE_RT_ImportType_proto +enum __Pyx_ImportType_CheckSize { + __Pyx_ImportType_CheckSize_Error = 0, + __Pyx_ImportType_CheckSize_Warn = 1, + __Pyx_ImportType_CheckSize_Ignore = 2 +}; +static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size); +#endif + +/* 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 + +/* 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 + + +/* GCCDiagnostics.proto */ +#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) +#define __Pyx_HAS_GCC_DIAGNOSTIC +#endif + +/* CppExceptionConversion.proto */ +#ifndef __Pyx_CppExn2PyErr +#include +#include +#include +#include +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_long(long value); + +/* CIntFromPy.proto */ +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); + +/* CIntFromPy.proto */ +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_Py_intptr_t(Py_intptr_t value); + +/* 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); + +/* InitStrings.proto */ +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); + +static CYTHON_INLINE void __pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_set(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self, int __pyx_v_xi, int __pyx_v_yi, int __pyx_v_value); /* proto*/ +static CYTHON_INLINE int __pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_get(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self, int __pyx_v_xi, int __pyx_v_yi); /* proto*/ +static void __pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster__load_block(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self, int __pyx_v_block_index); /* proto*/ + +/* Module declarations from 'cython' */ + +/* 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_generic = 0; +static PyTypeObject *__pyx_ptype_5numpy_number = 0; +static PyTypeObject *__pyx_ptype_5numpy_integer = 0; +static PyTypeObject *__pyx_ptype_5numpy_signedinteger = 0; +static PyTypeObject *__pyx_ptype_5numpy_unsignedinteger = 0; +static PyTypeObject *__pyx_ptype_5numpy_inexact = 0; +static PyTypeObject *__pyx_ptype_5numpy_floating = 0; +static PyTypeObject *__pyx_ptype_5numpy_complexfloating = 0; +static PyTypeObject *__pyx_ptype_5numpy_flexible = 0; +static PyTypeObject *__pyx_ptype_5numpy_character = 0; +static PyTypeObject *__pyx_ptype_5numpy_ufunc = 0; + +/* Module declarations from 'libc.stddef' */ + +/* Module declarations from 'libc.time' */ + +/* Module declarations from 'libcpp.list' */ + +/* Module declarations from 'libcpp.utility' */ + +/* Module declarations from 'libcpp.map' */ + +/* Module declarations from 'libcpp.pair' */ + +/* Module declarations from 'libcpp.queue' */ + +/* Module declarations from 'libcpp.set' */ + +/* Module declarations from 'pygeoprocessing.routing.watershed' */ +static PyTypeObject *__pyx_ptype_15pygeoprocessing_7routing_9watershed__ManagedRaster = 0; +static int __pyx_v_15pygeoprocessing_7routing_9watershed_BLOCK_BITS; +static int __pyx_v_15pygeoprocessing_7routing_9watershed_MANAGED_RASTER_N_BLOCKS; +static int *__pyx_v_15pygeoprocessing_7routing_9watershed_D8_REVERSE_DIRECTION; +static int *__pyx_v_15pygeoprocessing_7routing_9watershed_NEIGHBOR_COL; +static int *__pyx_v_15pygeoprocessing_7routing_9watershed_NEIGHBOR_ROW; +static std::set<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> __pyx_f_15pygeoprocessing_7routing_9watershed__c_split_geometry_into_seeds(PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, struct __pyx_opt_args_15pygeoprocessing_7routing_9watershed__c_split_geometry_into_seeds *__pyx_optional_args); /*proto*/ +static PyObject *__pyx_convert_pair_to_py_long____long(std::pair const &); /*proto*/ +static std::pair __pyx_convert_pair_from_py_long__and_long(PyObject *); /*proto*/ +static __Pyx_TypeInfo __Pyx_TypeInfo_int = { "int", NULL, sizeof(int), { 0 }, 0, IS_UNSIGNED(int) ? 'U' : 'I', IS_UNSIGNED(int), 0 }; +static __Pyx_TypeInfo __Pyx_TypeInfo_nn_npy_uint8 = { "npy_uint8", NULL, sizeof(npy_uint8), { 0 }, 0, IS_UNSIGNED(npy_uint8) ? 'U' : 'I', IS_UNSIGNED(npy_uint8), 0 }; +#define __Pyx_MODULE_NAME "pygeoprocessing.routing.watershed" +extern int __pyx_module_is_main_pygeoprocessing__routing__watershed; +int __pyx_module_is_main_pygeoprocessing__routing__watershed = 0; + +/* Implementation of 'pygeoprocessing.routing.watershed' */ +static PyObject *__pyx_builtin_OSError; +static PyObject *__pyx_builtin_ValueError; +static PyObject *__pyx_builtin_xrange; +static PyObject *__pyx_builtin_TypeError; +static PyObject *__pyx_builtin_range; +static PyObject *__pyx_builtin_ImportError; +static const char __pyx_k_[] = ", "; +static const char __pyx_k_d[] = "d"; +static const char __pyx_k_os[] = "os"; +static const char __pyx_k_x1[] = "x1"; +static const char __pyx_k_x2[] = "x2"; +static const char __pyx_k_y1[] = "y1"; +static const char __pyx_k_y2[] = "y2"; +static const char __pyx_k_VRT[] = "VRT"; +static const char __pyx_k__10[] = "_"; +static const char __pyx_k_box[] = "box"; +static const char __pyx_k_dir[] = "dir"; +static const char __pyx_k_fid[] = "fid"; +static const char __pyx_k_mem[] = "mem"; +static const char __pyx_k_ogr[] = "ogr"; +static const char __pyx_k_osr[] = "osr"; +static const char __pyx_k_wkb[] = "wkb"; +static const char __pyx_k_GPKG[] = "GPKG"; +static const char __pyx_k_gdal[] = "gdal"; +static const char __pyx_k_geom[] = "geom"; +static const char __pyx_k_info[] = "info"; +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_prep[] = "prep"; +static const char __pyx_k_seed[] = "seed"; +static const char __pyx_k_test[] = "__test__"; +static const char __pyx_k_time[] = "time"; +static const char __pyx_k_xoff[] = "xoff"; +static const char __pyx_k_yoff[] = "yoff"; +static const char __pyx_k_GTiff[] = "GTiff"; +static const char __pyx_k_Point[] = "Point"; +static const char __pyx_k_close[] = "close"; +static const char __pyx_k_debug[] = "debug"; +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_items[] = "items"; +static const char __pyx_k_loads[] = "loads"; +static const char __pyx_k_numpy[] = "numpy"; +static const char __pyx_k_osgeo[] = "osgeo"; +static const char __pyx_k_range[] = "range"; +static const char __pyx_k_seeds[] = "seeds"; +static const char __pyx_k_ws_id[] = "ws_id"; +static const char __pyx_k_Create[] = "Create"; +static const char __pyx_k_GetFID[] = "GetFID"; +static const char __pyx_k_LOGGER[] = "LOGGER"; +static const char __pyx_k_Memory[] = "Memory"; +static const char __pyx_k_OpenEx[] = "OpenEx"; +static const char __pyx_k_WSID_1[] = "WSID <= 1!"; +static const char __pyx_k_astype[] = "astype"; +static const char __pyx_k_bounds[] = "bounds"; +static const char __pyx_k_driver[] = "driver"; +static const char __pyx_k_exists[] = "exists"; +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_ix_max[] = "ix_max"; +static const char __pyx_k_ix_min[] = "ix_min"; +static const char __pyx_k_iy_max[] = "iy_max"; +static const char __pyx_k_iy_min[] = "iy_min"; +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_remove[] = "remove"; +static const char __pyx_k_rmtree[] = "rmtree"; +static const char __pyx_k_schema[] = "schema"; +static const char __pyx_k_shutil[] = "shutil"; +static const char __pyx_k_xrange[] = "xrange"; +static const char __pyx_k_Feature[] = "Feature"; +static const char __pyx_k_IsEmpty[] = "IsEmpty"; +static const char __pyx_k_OSError[] = "OSError"; +static const char __pyx_k_Polygon[] = "Polygon"; +static const char __pyx_k_band_id[] = "band_id"; +static const char __pyx_k_feature[] = "feature"; +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_options[] = "options"; +static const char __pyx_k_shapely[] = "shapely"; +static const char __pyx_k_BuildVRT[] = "BuildVRT"; +static const char __pyx_k_GDT_Byte[] = "GDT_Byte"; +static const char __pyx_k_Geometry[] = "Geometry"; +static const char __pyx_k_GetField[] = "GetField"; +static const char __pyx_k_GetLayer[] = "GetLayer"; +static const char __pyx_k_SetField[] = "SetField"; +static const char __pyx_k_SetWidth[] = "SetWidth"; +static const char __pyx_k_geom_wkb[] = "geom_wkb"; +static const char __pyx_k_geometry[] = "geometry"; +static const char __pyx_k_getstate[] = "__getstate__"; +static const char __pyx_k_makedirs[] = "makedirs"; +static const char __pyx_k_prepared[] = "prepared"; +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_vrt_band[] = "vrt_band"; +static const char __pyx_k_vrt_path[] = "vrt_path"; +static const char __pyx_k_wkbPoint[] = "wkbPoint"; +static const char __pyx_k_FieldDefn[] = "FieldDefn"; +static const char __pyx_k_GA_Update[] = "GA_Update"; +static const char __pyx_k_OF_RASTER[] = "OF_RASTER"; +static const char __pyx_k_OF_VECTOR[] = "OF_VECTOR"; +static const char __pyx_k_TILED_YES[] = "TILED=YES"; +static const char __pyx_k_TypeError[] = "TypeError"; +static const char __pyx_k_bbox_maxx[] = "bbox_maxx"; +static const char __pyx_k_bbox_maxy[] = "bbox_maxy"; +static const char __pyx_k_bbox_minx[] = "bbox_minx"; +static const char __pyx_k_bbox_miny[] = "bbox_miny"; +static const char __pyx_k_getLogger[] = "getLogger"; +static const char __pyx_k_reduce_ex[] = "__reduce_ex__"; +static const char __pyx_k_s_vrt_vrt[] = "%s_vrt.vrt"; +static const char __pyx_k_source_gt[] = "source_gt"; +static const char __pyx_k_win_xsize[] = "win_xsize"; +static const char __pyx_k_win_ysize[] = "win_ysize"; +static const char __pyx_k_FlushCache[] = "FlushCache"; +static const char __pyx_k_GDT_UInt32[] = "GDT_UInt32"; +static const char __pyx_k_GetFeature[] = "GetFeature"; +static const char __pyx_k_OFTInteger[] = "OFTInteger"; +static const char __pyx_k_Polygonize[] = "Polygonize"; +static const char __pyx_k_ValueError[] = "ValueError"; +static const char __pyx_k_WriteArray[] = "WriteArray"; +static const char __pyx_k_block_size[] = "block_size"; +static const char __pyx_k_field_name[] = "field_name"; +static const char __pyx_k_intersects[] = "intersects"; +static const char __pyx_k_iterblocks[] = "iterblocks"; +static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__"; +static const char __pyx_k_return_set[] = "return_set"; +static const char __pyx_k_vrt_raster[] = "vrt_raster"; +static const char __pyx_k_watersheds[] = "watersheds"; +static const char __pyx_k_wkbPolygon[] = "wkbPolygon"; +static const char __pyx_k_wkbUnknown[] = "wkbUnknown"; +static const char __pyx_k_write_mode[] = "write_mode"; +static const char __pyx_k_AddGeometry[] = "AddGeometry"; +static const char __pyx_k_BIGTIFF_YES[] = "BIGTIFF=YES"; +static const char __pyx_k_CreateField[] = "CreateField"; +static const char __pyx_k_CreateLayer[] = "CreateLayer"; +static const char __pyx_k_DeleteLayer[] = "DeleteLayer"; +static const char __pyx_k_ExportToWkb[] = "ExportToWkb"; +static const char __pyx_k_ExportToWkt[] = "ExportToWkt"; +static const char __pyx_k_GDT_Unknown[] = "GDT_Unknown"; +static const char __pyx_k_ImportError[] = "ImportError"; +static const char __pyx_k_ReadAsArray[] = "ReadAsArray"; +static const char __pyx_k_SetGeometry[] = "SetGeometry"; +static const char __pyx_k_burn_values[] = "burn_values"; +static const char __pyx_k_current_fid[] = "current_fid"; +static const char __pyx_k_field_value[] = "field_value"; +static const char __pyx_k_index_field[] = "index_field"; +static const char __pyx_k_raster_path[] = "raster_path"; +static const char __pyx_k_raster_size[] = "raster_size"; +static const char __pyx_k_shapely_wkb[] = "shapely.wkb"; +static const char __pyx_k_vrt_options[] = "vrt_options"; +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_CreateFields[] = "CreateFields"; +static const char __pyx_k_GetLayerDefn[] = "GetLayerDefn"; +static const char __pyx_k_ResetReading[] = "ResetReading"; +static const char __pyx_k_bounding_box[] = "bounding_box"; +static const char __pyx_k_flow_dir_srs[] = "flow_dir_srs"; +static const char __pyx_k_geotransform[] = "geotransform"; +static const char __pyx_k_gtiff_driver[] = "gtiff_driver"; +static const char __pyx_k_neighbor_col[] = "neighbor_col"; +static const char __pyx_k_neighbor_row[] = "neighbor_row"; +static const char __pyx_k_new_geometry[] = "new_geometry"; +static const char __pyx_k_outputBounds[] = "outputBounds"; +static const char __pyx_k_reverse_flow[] = "reverse_flow"; +static const char __pyx_k_s_seeds_gpkg[] = "%s_seeds.gpkg"; +static const char __pyx_k_shapely_geom[] = "shapely_geom"; +static const char __pyx_k_source_layer[] = "source_layer"; +static const char __pyx_k_CreateFeature[] = "CreateFeature"; +static const char __pyx_k_GetRasterBand[] = "GetRasterBand"; +static const char __pyx_k_ImportFromWkt[] = "ImportFromWkt"; +static const char __pyx_k_ManagedRaster[] = "_ManagedRaster"; +static const char __pyx_k_SetProjection[] = "SetProjection"; +static const char __pyx_k_current_pixel[] = "current_pixel"; +static const char __pyx_k_duplicate_fid[] = "duplicate_fid"; +static const char __pyx_k_flow_dir_bbox[] = "flow_dir_bbox"; +static const char __pyx_k_flow_dir_info[] = "flow_dir_info"; +static const char __pyx_k_last_log_time[] = "last_log_time"; +static const char __pyx_k_outflow_layer[] = "outflow_layer"; +static const char __pyx_k_process_queue[] = "process_queue"; +static const char __pyx_k_reduce_cython[] = "__reduce_cython__"; +static const char __pyx_k_s_scratch_tif[] = "%s_scratch.tif"; +static const char __pyx_k_seed_iterator[] = "seed_iterator"; +static const char __pyx_k_source_vector[] = "source_vector"; +static const char __pyx_k_user_geometry[] = "user_geometry"; +static const char __pyx_k_GetGeometryRef[] = "GetGeometryRef"; +static const char __pyx_k_RasterizeLayer[] = "RasterizeLayer"; +static const char __pyx_k_SPARSE_OK_TRUE[] = "SPARSE_OK=TRUE"; +static const char __pyx_k_Y_m_d__H__M__S[] = "%Y-%m-%d_%H_%M_%S"; +static const char __pyx_k_neighbor_index[] = "neighbor_index"; +static const char __pyx_k_neighbor_pixel[] = "neighbor_pixel"; +static const char __pyx_k_outflow_vector[] = "outflow_vector"; +static const char __pyx_k_projection_wkt[] = "projection_wkt"; +static const char __pyx_k_scratch_raster[] = "scratch_raster"; +static const char __pyx_k_seeds_iterator[] = "seeds_iterator"; +static const char __pyx_k_source_feature[] = "source_feature"; +static const char __pyx_k_watersheds_srs[] = "watersheds_srs"; +static const char __pyx_k_BuildVRTOptions[] = "BuildVRTOptions"; +static const char __pyx_k_GetDriverByName[] = "GetDriverByName"; +static const char __pyx_k_GetFeatureCount[] = "GetFeatureCount"; +static const char __pyx_k_SetGeoTransform[] = "SetGeoTransform"; +static const char __pyx_k_allowed_drivers[] = "allowed_drivers"; +static const char __pyx_k_flow_dir_n_cols[] = "flow_dir_n_cols"; +static const char __pyx_k_flow_dir_n_rows[] = "flow_dir_n_rows"; +static const char __pyx_k_flow_dir_nodata[] = "flow_dir_nodata"; +static const char __pyx_k_get_raster_info[] = "get_raster_info"; +static const char __pyx_k_n_cells_visited[] = "n_cells_visited"; +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_source_geom_wkb[] = "source_geom_wkb"; +static const char __pyx_k_wkbMultiPolygon[] = "wkbMultiPolygon"; +static const char __pyx_k_ALL_TOUCHED_True[] = "ALL_TOUCHED=True"; +static const char __pyx_k_CreateDataSource[] = "CreateDataSource"; +static const char __pyx_k_SpatialReference[] = "SpatialReference"; +static const char __pyx_k_StartTransaction[] = "StartTransaction"; +static const char __pyx_k_raster_path_band[] = "raster_path_band"; +static const char __pyx_k_s_rasterized_tif[] = "%s_rasterized.tif"; +static const char __pyx_k_shapely_geometry[] = "shapely.geometry"; +static const char __pyx_k_shapely_prepared[] = "shapely.prepared"; +static const char __pyx_k_watersheds_layer[] = "watersheds_layer"; +static const char __pyx_k_working_dir_path[] = "working_dir_path"; +static const char __pyx_k_CommitTransaction[] = "CommitTransaction"; +static const char __pyx_k_duplicate_feature[] = "duplicate_feature"; +static const char __pyx_k_duplicate_ids_set[] = "duplicate_ids_set"; +static const char __pyx_k_flow_dir_origin_x[] = "flow_dir_origin_x"; +static const char __pyx_k_flow_dir_origin_y[] = "flow_dir_origin_y"; +static const char __pyx_k_process_queue_set[] = "process_queue_set"; +static const char __pyx_k_remove_temp_files[] = "remove_temp_files"; +static const char __pyx_k_seeds_raster_path[] = "seeds_raster_path"; +static const char __pyx_k_target_layer_name[] = "target_layer_name"; +static const char __pyx_k_watershed_feature[] = "watershed_feature"; +static const char __pyx_k_watersheds_vector[] = "watersheds_vector"; +static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; +static const char __pyx_k_duplicate_geometry[] = "duplicate_geometry"; +static const char __pyx_k_seeds_in_watershed[] = "seeds_in_watershed"; +static const char __pyx_k_target_raster_path[] = "target_raster_path"; +static const char __pyx_k_watersheds_created[] = "watersheds_created"; +static const char __pyx_k_outflow_vector_path[] = "outflow_vector_path"; +static const char __pyx_k_scratch_raster_path[] = "scratch_raster_path"; +static const char __pyx_k_flow_dir_pixelsize_x[] = "flow_dir_pixelsize_x"; +static const char __pyx_k_flow_dir_pixelsize_y[] = "flow_dir_pixelsize_y"; +static const char __pyx_k_CreateGeometryFromWkb[] = "CreateGeometryFromWkb"; +static const char __pyx_k_Testing_geometry_bbox[] = "Testing geometry bbox"; +static const char __pyx_k_outflow_feature_count[] = "outflow_feature_count"; +static const char __pyx_k_Creating_flow_dir_bbox[] = "Creating flow dir bbox"; +static const char __pyx_k_Delineating_watersheds[] = "Delineating watersheds"; +static const char __pyx_k_GTIFF_CREATION_OPTIONS[] = "GTIFF_CREATION_OPTIONS"; +static const char __pyx_k_diagnostic_vector_path[] = "diagnostic_vector_path"; +static const char __pyx_k_polygonized_watersheds[] = "polygonized_watersheds"; +static const char __pyx_k_scratch_managed_raster[] = "scratch_managed_raster"; +static const char __pyx_k_delineate_watersheds_d8[] = "delineate_watersheds_d8"; +static const char __pyx_k_flow_dir_managed_raster[] = "flow_dir_managed_raster"; +static const char __pyx_k_write_diagnostic_vector[] = "write_diagnostic_vector"; +static const char __pyx_k_fragments_with_duplicates[] = "fragments_with_duplicates"; +static const char __pyx_k_split_geometry_into_seeds[] = "_split_geometry_into_seeds"; +static const char __pyx_k_duplicate_ids_set_iterator[] = "duplicate_ids_set_iterator"; +static const char __pyx_k_d8_flow_dir_raster_path_band[] = "d8_flow_dir_raster_path_band"; +static const char __pyx_k_polygonized_watersheds_layer[] = "polygonized_watersheds_layer"; +static const char __pyx_k_Finished_vector_consolidation[] = "Finished vector consolidation"; +static const char __pyx_k_is_raster_path_band_formatted[] = "_is_raster_path_band_formatted"; +static const char __pyx_k_target_watersheds_vector_path[] = "target_watersheds_vector_path"; +static const char __pyx_k_Watershed_delineation_complete[] = "Watershed delineation complete"; +static const char __pyx_k_Could_not_open_outflow_vector_s[] = "Could not open outflow vector %s"; +static const char __pyx_k_Delineating_watershed_s_of_s_ws[] = "Delineating watershed %s of %s (ws_id %s)"; +static const char __pyx_k_Error_Block_size_is_not_a_power[] = "Error: Block size is not a power of two: block_xsize: "; +static const char __pyx_k_This_exception_is_happeningin_C[] = ". 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_numpy_core_multiarray_failed_to[] = "numpy.core.multiarray failed to import"; +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_Consolidating_s_fragments_and_co[] = "Consolidating %s fragments and copying field values to watersheds layer."; +static const char __pyx_k_Creating_flow_dir_managed_raster[] = "Creating flow dir managed raster"; +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_Finished_delineating_s_watershed[] = "Finished delineating %s watersheds"; +static const char __pyx_k_Outflow_feature_s_does_not_inter[] = "Outflow feature %s does not intersect any pixels with valid flow direction. Skipping."; +static const char __pyx_k_Outflow_feature_s_does_not_overl[] = "Outflow feature %s does not overlap with the flow direction raster. Skipping."; +static const char __pyx_k_Outflow_feature_s_has_empty_geom[] = "Outflow feature %s has empty geometry. Skipping."; +static const char __pyx_k_fragments_with_duplicates_iterat[] = "fragments_with_duplicates_iterator"; +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_pygeoprocessing_routing_watershe[] = "pygeoprocessing.routing.watershed"; +static const char __pyx_k_src_pygeoprocessing_routing_wate[] = "src/pygeoprocessing/routing/watershed.pyx"; +static const char __pyx_k_watershed_delineation_trivial__s[] = "watershed_delineation_trivial_%s_"; +static const char __pyx_k_Delineating_watershed_s_of_s_ws_2[] = "Delineating watershed %s of %s (ws_id %s), %s pixels found so far"; +static PyObject *__pyx_kp_u_; +static PyObject *__pyx_kp_u_ALL_TOUCHED_True; +static PyObject *__pyx_n_s_AddGeometry; +static PyObject *__pyx_kp_u_BIGTIFF_YES; +static PyObject *__pyx_kp_u_BLOCKXSIZE_d; +static PyObject *__pyx_kp_u_BLOCKYSIZE_d; +static PyObject *__pyx_n_s_BuildVRT; +static PyObject *__pyx_n_s_BuildVRTOptions; +static PyObject *__pyx_kp_u_COMPRESS_LZW; +static PyObject *__pyx_n_s_CommitTransaction; +static PyObject *__pyx_kp_u_Consolidating_s_fragments_and_co; +static PyObject *__pyx_kp_u_Could_not_open_outflow_vector_s; +static PyObject *__pyx_n_s_Create; +static PyObject *__pyx_n_s_CreateDataSource; +static PyObject *__pyx_n_s_CreateFeature; +static PyObject *__pyx_n_s_CreateField; +static PyObject *__pyx_n_s_CreateFields; +static PyObject *__pyx_n_s_CreateGeometryFromWkb; +static PyObject *__pyx_n_s_CreateLayer; +static PyObject *__pyx_kp_u_Creating_flow_dir_bbox; +static PyObject *__pyx_kp_u_Creating_flow_dir_managed_raster; +static PyObject *__pyx_n_s_DeleteLayer; +static PyObject *__pyx_kp_u_Delineating_watershed_s_of_s_ws; +static PyObject *__pyx_kp_u_Delineating_watershed_s_of_s_ws_2; +static PyObject *__pyx_kp_u_Delineating_watersheds; +static PyObject *__pyx_kp_u_Error_Block_size_is_not_a_power; +static PyObject *__pyx_kp_u_Error_band_ID_s_is_not_a_valid_b; +static PyObject *__pyx_n_s_ExportToWkb; +static PyObject *__pyx_n_s_ExportToWkt; +static PyObject *__pyx_n_s_Feature; +static PyObject *__pyx_n_s_FieldDefn; +static PyObject *__pyx_kp_u_Finished_delineating_s_watershed; +static PyObject *__pyx_kp_u_Finished_vector_consolidation; +static PyObject *__pyx_n_s_FlushCache; +static PyObject *__pyx_n_s_GA_Update; +static PyObject *__pyx_n_s_GDT_Byte; +static PyObject *__pyx_n_s_GDT_UInt32; +static PyObject *__pyx_n_s_GDT_Unknown; +static PyObject *__pyx_n_u_GPKG; +static PyObject *__pyx_n_s_GTIFF_CREATION_OPTIONS; +static PyObject *__pyx_n_u_GTiff; +static PyObject *__pyx_n_s_Geometry; +static PyObject *__pyx_n_s_GetDriverByName; +static PyObject *__pyx_n_s_GetFID; +static PyObject *__pyx_n_s_GetFeature; +static PyObject *__pyx_n_s_GetFeatureCount; +static PyObject *__pyx_n_s_GetField; +static PyObject *__pyx_n_s_GetGeometryRef; +static PyObject *__pyx_n_s_GetLayer; +static PyObject *__pyx_n_s_GetLayerDefn; +static PyObject *__pyx_n_s_GetRasterBand; +static PyObject *__pyx_n_s_ImportError; +static PyObject *__pyx_n_s_ImportFromWkt; +static PyObject *__pyx_n_s_IsEmpty; +static PyObject *__pyx_n_s_LOGGER; +static PyObject *__pyx_n_s_ManagedRaster; +static PyObject *__pyx_n_u_Memory; +static PyObject *__pyx_n_s_OFTInteger; +static PyObject *__pyx_n_s_OF_RASTER; +static PyObject *__pyx_n_s_OF_VECTOR; +static PyObject *__pyx_n_s_OSError; +static PyObject *__pyx_n_s_OpenEx; +static PyObject *__pyx_kp_u_Outflow_feature_s_does_not_inter; +static PyObject *__pyx_kp_u_Outflow_feature_s_does_not_overl; +static PyObject *__pyx_kp_u_Outflow_feature_s_has_empty_geom; +static PyObject *__pyx_n_s_Point; +static PyObject *__pyx_n_s_Polygon; +static PyObject *__pyx_n_s_Polygonize; +static PyObject *__pyx_n_s_RasterizeLayer; +static PyObject *__pyx_n_s_ReadAsArray; +static PyObject *__pyx_n_s_ResetReading; +static PyObject *__pyx_kp_u_SPARSE_OK_TRUE; +static PyObject *__pyx_n_s_SetField; +static PyObject *__pyx_n_s_SetGeoTransform; +static PyObject *__pyx_n_s_SetGeometry; +static PyObject *__pyx_n_s_SetProjection; +static PyObject *__pyx_n_s_SetWidth; +static PyObject *__pyx_n_s_SpatialReference; +static PyObject *__pyx_n_s_StartTransaction; +static PyObject *__pyx_kp_u_TILED_YES; +static PyObject *__pyx_kp_u_Testing_geometry_bbox; +static PyObject *__pyx_kp_u_This_exception_is_happeningin_C; +static PyObject *__pyx_n_s_TypeError; +static PyObject *__pyx_n_u_VRT; +static PyObject *__pyx_n_s_ValueError; +static PyObject *__pyx_kp_u_WSID_1; +static PyObject *__pyx_kp_u_Watershed_delineation_complete; +static PyObject *__pyx_n_s_WriteArray; +static PyObject *__pyx_kp_u_Y_m_d__H__M__S; +static PyObject *__pyx_n_s__10; +static PyObject *__pyx_n_s_allowed_drivers; +static PyObject *__pyx_n_s_astype; +static PyObject *__pyx_n_s_band_id; +static PyObject *__pyx_n_s_bbox_maxx; +static PyObject *__pyx_n_s_bbox_maxy; +static PyObject *__pyx_n_s_bbox_minx; +static PyObject *__pyx_n_s_bbox_miny; +static PyObject *__pyx_n_u_block_size; +static PyObject *__pyx_n_u_bounding_box; +static PyObject *__pyx_n_s_bounds; +static PyObject *__pyx_n_s_box; +static PyObject *__pyx_n_s_burn_values; +static PyObject *__pyx_n_s_cline_in_traceback; +static PyObject *__pyx_n_s_close; +static PyObject *__pyx_n_s_current_fid; +static PyObject *__pyx_n_s_current_pixel; +static PyObject *__pyx_n_u_d; +static PyObject *__pyx_n_s_d8_flow_dir_raster_path_band; +static PyObject *__pyx_n_s_debug; +static PyObject *__pyx_n_s_delineate_watersheds_d8; +static PyObject *__pyx_n_s_diagnostic_vector_path; +static PyObject *__pyx_n_s_dir; +static PyObject *__pyx_n_s_driver; +static PyObject *__pyx_n_s_dtype; +static PyObject *__pyx_n_s_duplicate_feature; +static PyObject *__pyx_n_s_duplicate_fid; +static PyObject *__pyx_n_s_duplicate_geometry; +static PyObject *__pyx_n_s_duplicate_ids_set; +static PyObject *__pyx_n_s_duplicate_ids_set_iterator; +static PyObject *__pyx_n_s_empty; +static PyObject *__pyx_n_s_error; +static PyObject *__pyx_n_s_exists; +static PyObject *__pyx_n_s_feature; +static PyObject *__pyx_n_s_fid; +static PyObject *__pyx_n_s_field_name; +static PyObject *__pyx_n_s_field_value; +static PyObject *__pyx_n_s_flow_dir_bbox; +static PyObject *__pyx_n_s_flow_dir_info; +static PyObject *__pyx_n_s_flow_dir_managed_raster; +static PyObject *__pyx_n_s_flow_dir_n_cols; +static PyObject *__pyx_n_s_flow_dir_n_rows; +static PyObject *__pyx_n_s_flow_dir_nodata; +static PyObject *__pyx_n_s_flow_dir_origin_x; +static PyObject *__pyx_n_s_flow_dir_origin_y; +static PyObject *__pyx_n_s_flow_dir_pixelsize_x; +static PyObject *__pyx_n_s_flow_dir_pixelsize_y; +static PyObject *__pyx_n_s_flow_dir_srs; +static PyObject *__pyx_n_s_fragments_with_duplicates; +static PyObject *__pyx_n_s_fragments_with_duplicates_iterat; +static PyObject *__pyx_n_s_gdal; +static PyObject *__pyx_n_s_geom; +static PyObject *__pyx_n_s_geom_wkb; +static PyObject *__pyx_n_s_geometry; +static PyObject *__pyx_n_s_geotransform; +static PyObject *__pyx_n_u_geotransform; +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_driver; +static PyObject *__pyx_n_s_import; +static PyObject *__pyx_n_s_index_field; +static PyObject *__pyx_n_s_info; +static PyObject *__pyx_n_s_int32; +static PyObject *__pyx_n_s_intersects; +static PyObject *__pyx_n_s_is_raster_path_band_formatted; +static PyObject *__pyx_n_s_isfile; +static PyObject *__pyx_n_s_items; +static PyObject *__pyx_n_s_iterblocks; +static PyObject *__pyx_n_s_ix_max; +static PyObject *__pyx_n_s_ix_min; +static PyObject *__pyx_n_s_iy_max; +static PyObject *__pyx_n_s_iy_min; +static PyObject *__pyx_n_s_join; +static PyObject *__pyx_n_s_last_log_time; +static PyObject *__pyx_n_s_loads; +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_u_mem; +static PyObject *__pyx_n_s_mkdtemp; +static PyObject *__pyx_n_u_n_bands; +static PyObject *__pyx_n_s_n_cells_visited; +static PyObject *__pyx_n_s_name; +static PyObject *__pyx_n_s_neighbor_col; +static PyObject *__pyx_n_s_neighbor_index; +static PyObject *__pyx_n_s_neighbor_pixel; +static PyObject *__pyx_n_s_neighbor_row; +static PyObject *__pyx_n_s_new_geometry; +static PyObject *__pyx_kp_s_no_default___reduce___due_to_non; +static PyObject *__pyx_n_u_nodata; +static PyObject *__pyx_n_s_numpy; +static PyObject *__pyx_kp_u_numpy_core_multiarray_failed_to; +static PyObject *__pyx_kp_u_numpy_core_umath_failed_to_impor; +static PyObject *__pyx_n_s_ogr; +static PyObject *__pyx_n_s_options; +static PyObject *__pyx_n_s_os; +static PyObject *__pyx_n_s_osgeo; +static PyObject *__pyx_n_s_osr; +static PyObject *__pyx_n_s_outflow_feature_count; +static PyObject *__pyx_n_s_outflow_layer; +static PyObject *__pyx_n_s_outflow_vector; +static PyObject *__pyx_n_s_outflow_vector_path; +static PyObject *__pyx_n_s_outputBounds; +static PyObject *__pyx_n_s_path; +static PyObject *__pyx_n_u_polygonized_watersheds; +static PyObject *__pyx_n_s_polygonized_watersheds_layer; +static PyObject *__pyx_n_s_prefix; +static PyObject *__pyx_n_s_prep; +static PyObject *__pyx_n_s_prepared; +static PyObject *__pyx_n_s_process_queue; +static PyObject *__pyx_n_s_process_queue_set; +static PyObject *__pyx_n_u_projection_wkt; +static PyObject *__pyx_n_s_pygeoprocessing; +static PyObject *__pyx_n_s_pygeoprocessing_routing_watershe; +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_u_raster_size; +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_remove; +static PyObject *__pyx_n_s_remove_temp_files; +static PyObject *__pyx_n_s_return_set; +static PyObject *__pyx_n_s_reverse_flow; +static PyObject *__pyx_n_s_rmtree; +static PyObject *__pyx_kp_u_s_is_not_a_file; +static PyObject *__pyx_kp_u_s_is_supposed_to_be_a_raster_ba; +static PyObject *__pyx_kp_u_s_rasterized_tif; +static PyObject *__pyx_kp_u_s_scratch_tif; +static PyObject *__pyx_kp_u_s_seeds_gpkg; +static PyObject *__pyx_kp_u_s_vrt_vrt; +static PyObject *__pyx_n_s_schema; +static PyObject *__pyx_n_s_scratch_managed_raster; +static PyObject *__pyx_n_s_scratch_raster; +static PyObject *__pyx_n_s_scratch_raster_path; +static PyObject *__pyx_n_s_seed; +static PyObject *__pyx_n_s_seed_iterator; +static PyObject *__pyx_n_s_seeds; +static PyObject *__pyx_n_u_seeds; +static PyObject *__pyx_n_s_seeds_in_watershed; +static PyObject *__pyx_n_s_seeds_iterator; +static PyObject *__pyx_n_s_seeds_raster_path; +static PyObject *__pyx_n_s_setstate; +static PyObject *__pyx_n_s_setstate_cython; +static PyObject *__pyx_n_s_shapely; +static PyObject *__pyx_n_s_shapely_geom; +static PyObject *__pyx_n_s_shapely_geometry; +static PyObject *__pyx_n_s_shapely_prepared; +static PyObject *__pyx_n_s_shapely_wkb; +static PyObject *__pyx_n_s_shutil; +static PyObject *__pyx_n_s_source_feature; +static PyObject *__pyx_n_s_source_geom_wkb; +static PyObject *__pyx_n_s_source_gt; +static PyObject *__pyx_n_s_source_layer; +static PyObject *__pyx_n_s_source_vector; +static PyObject *__pyx_n_s_split_geometry_into_seeds; +static PyObject *__pyx_kp_s_src_pygeoprocessing_routing_wate; +static PyObject *__pyx_n_s_strftime; +static PyObject *__pyx_n_s_target_layer_name; +static PyObject *__pyx_n_s_target_raster_path; +static PyObject *__pyx_n_s_target_watersheds_vector_path; +static PyObject *__pyx_n_s_tempfile; +static PyObject *__pyx_n_s_test; +static PyObject *__pyx_n_s_time; +static PyObject *__pyx_n_u_user_geometry; +static PyObject *__pyx_n_s_vrt_band; +static PyObject *__pyx_n_s_vrt_options; +static PyObject *__pyx_n_s_vrt_path; +static PyObject *__pyx_n_s_vrt_raster; +static PyObject *__pyx_kp_u_watershed_delineation_trivial__s; +static PyObject *__pyx_n_s_watershed_feature; +static PyObject *__pyx_n_u_watersheds; +static PyObject *__pyx_n_s_watersheds_created; +static PyObject *__pyx_n_s_watersheds_layer; +static PyObject *__pyx_n_s_watersheds_srs; +static PyObject *__pyx_n_s_watersheds_vector; +static PyObject *__pyx_n_s_win_xsize; +static PyObject *__pyx_n_s_win_ysize; +static PyObject *__pyx_n_s_wkb; +static PyObject *__pyx_n_s_wkbMultiPolygon; +static PyObject *__pyx_n_s_wkbPoint; +static PyObject *__pyx_n_s_wkbPolygon; +static PyObject *__pyx_n_s_wkbUnknown; +static PyObject *__pyx_n_s_working_dir; +static PyObject *__pyx_n_s_working_dir_path; +static PyObject *__pyx_n_s_write_diagnostic_vector; +static PyObject *__pyx_n_s_write_mode; +static PyObject *__pyx_n_s_ws_id; +static PyObject *__pyx_n_u_ws_id; +static PyObject *__pyx_n_s_x1; +static PyObject *__pyx_n_s_x2; +static PyObject *__pyx_n_s_xoff; +static PyObject *__pyx_n_u_xoff; +static PyObject *__pyx_n_s_xrange; +static PyObject *__pyx_n_s_y1; +static PyObject *__pyx_n_s_y2; +static PyObject *__pyx_n_s_yoff; +static PyObject *__pyx_n_u_yoff; +static int __pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster___init__(CYTHON_UNUSED struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self, PyObject *__pyx_v_raster_path, PyObject *__pyx_v_band_id, CYTHON_UNUSED PyObject *__pyx_v_write_mode); /* proto */ +static int __pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_2__cinit__(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__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_9watershed_14_ManagedRaster_4__dealloc__(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_6close(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_15pygeoprocessing_7routing_9watershed__is_raster_path_band_formatted(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_raster_path_band); /* proto */ +static PyObject *__pyx_pf_15pygeoprocessing_7routing_9watershed_2_split_geometry_into_seeds(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_source_geom_wkb, PyObject *__pyx_v_geotransform, PyObject *__pyx_v_flow_dir_srs, PyObject *__pyx_v_flow_dir_n_cols, PyObject *__pyx_v_flow_dir_n_rows, PyObject *__pyx_v_target_raster_path, PyObject *__pyx_v_diagnostic_vector_path); /* proto */ +static PyObject *__pyx_pf_15pygeoprocessing_7routing_9watershed_4delineate_watersheds_d8(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_d8_flow_dir_raster_path_band, PyObject *__pyx_v_outflow_vector_path, PyObject *__pyx_v_target_watersheds_vector_path, PyObject *__pyx_v_working_dir, PyObject *__pyx_v_write_diagnostic_vector, PyObject *__pyx_v_remove_temp_files, PyObject *__pyx_v_target_layer_name); /* proto */ +static PyObject *__pyx_tp_new_15pygeoprocessing_7routing_9watershed__ManagedRaster(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_int_0; +static PyObject *__pyx_int_1; +static PyObject *__pyx_int_24; +static PyObject *__pyx_tuple__2; +static PyObject *__pyx_tuple__3; +static PyObject *__pyx_tuple__4; +static PyObject *__pyx_tuple__5; +static PyObject *__pyx_tuple__6; +static PyObject *__pyx_tuple__8; +static PyObject *__pyx_tuple__11; +static PyObject *__pyx_codeobj__7; +static PyObject *__pyx_codeobj__9; +static PyObject *__pyx_codeobj__12; +/* Late includes */ + +/* "pygeoprocessing/routing/watershed.pyx":87 + * cdef int closed + * + * def __init__(self, raster_path, band_id, write_mode): # <<<<<<<<<<<<<< + * """Create new instance of Managed Raster. + * + */ + +/* Python wrapper */ +static int __pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_15pygeoprocessing_7routing_9watershed_14_ManagedRaster___init__[] = "Create new instance of Managed Raster.\n\n Parameters:\n raster_path (char*): path to raster that has block sizes that are\n powers of 2. If not, an exception is raised.\n band_id (int): which band in `raster_path` to index. Uses GDAL\n notation that starts at 1.\n write_mode (boolean): if true, this raster is writable and dirty\n memory blocks will be written back to the raster as blocks\n are swapped out of the cache or when the object deconstructs.\n\n Returns:\n None.\n "; +#if CYTHON_COMPILING_IN_CPYTHON +struct wrapperbase __pyx_wrapperbase_15pygeoprocessing_7routing_9watershed_14_ManagedRaster___init__; +#endif +static int __pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_raster_path = 0; + PyObject *__pyx_v_band_id = 0; + CYTHON_UNUSED PyObject *__pyx_v_write_mode = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (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("__init__", 1, 3, 3, 1); __PYX_ERR(0, 87, __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("__init__", 1, 3, 3, 2); __PYX_ERR(0, 87, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 87, __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("__init__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 87, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pygeoprocessing.routing.watershed._ManagedRaster.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster___init__(((struct __pyx_obj_15pygeoprocessing_7routing_9watershed__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_9watershed_14_ManagedRaster___init__(CYTHON_UNUSED struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self, PyObject *__pyx_v_raster_path, PyObject *__pyx_v_band_id, CYTHON_UNUSED PyObject *__pyx_v_write_mode) { + PyObject *__pyx_v_raster_info = NULL; + PyObject *__pyx_v_err_msg = NULL; + PyObject *__pyx_v_block_xsize = NULL; + PyObject *__pyx_v_block_ysize = NULL; + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *(*__pyx_t_8)(PyObject *); + Py_ssize_t __pyx_t_9; + Py_UCS4 __pyx_t_10; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__init__", 0); + + /* "pygeoprocessing/routing/watershed.pyx":102 + * None. + * """ + * if not os.path.isfile(raster_path): # <<<<<<<<<<<<<< + * LOGGER.error("%s is not a file.", raster_path) + * raise OSError('%s is not a file.' % raster_path) + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 102, __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, 102, __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, 102, __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); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_raster_path); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 102, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __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, 102, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_5 = ((!__pyx_t_4) != 0); + if (unlikely(__pyx_t_5)) { + + /* "pygeoprocessing/routing/watershed.pyx":103 + * """ + * if not os.path.isfile(raster_path): + * LOGGER.error("%s is not a file.", raster_path) # <<<<<<<<<<<<<< + * raise OSError('%s is not a file.' % raster_path) + * raster_info = pygeoprocessing.get_raster_info(raster_path) + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 103, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_error); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 103, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + __pyx_t_6 = 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_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_kp_u_s_is_not_a_file, __pyx_v_raster_path}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 103, __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_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_kp_u_s_is_not_a_file, __pyx_v_raster_path}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 103, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 103, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_2) { + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2); __pyx_t_2 = NULL; + } + __Pyx_INCREF(__pyx_kp_u_s_is_not_a_file); + __Pyx_GIVEREF(__pyx_kp_u_s_is_not_a_file); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_kp_u_s_is_not_a_file); + __Pyx_INCREF(__pyx_v_raster_path); + __Pyx_GIVEREF(__pyx_v_raster_path); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_raster_path); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 103, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":104 + * if not os.path.isfile(raster_path): + * LOGGER.error("%s is not a file.", raster_path) + * raise OSError('%s is not a file.' % raster_path) # <<<<<<<<<<<<<< + * raster_info = pygeoprocessing.get_raster_info(raster_path) + * + */ + __pyx_t_1 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_s_is_not_a_file, __pyx_v_raster_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 104, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_OSError, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 104, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 104, __pyx_L1_error) + + /* "pygeoprocessing/routing/watershed.pyx":102 + * None. + * """ + * if not os.path.isfile(raster_path): # <<<<<<<<<<<<<< + * LOGGER.error("%s is not a file.", raster_path) + * raise OSError('%s is not a file.' % raster_path) + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":105 + * LOGGER.error("%s is not a file.", raster_path) + * raise OSError('%s is not a file.' % raster_path) + * raster_info = pygeoprocessing.get_raster_info(raster_path) # <<<<<<<<<<<<<< + * + * if not (1 <= band_id <= raster_info['n_bands']): + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 105, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 105, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_3 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_1, __pyx_v_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_raster_path); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 105, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_raster_info = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":107 + * raster_info = pygeoprocessing.get_raster_info(raster_path) + * + * if not (1 <= band_id <= raster_info['n_bands']): # <<<<<<<<<<<<<< + * err_msg = ( + * "Error: band ID (%s) is not a valid band number. " + */ + __pyx_t_3 = PyObject_RichCompare(__pyx_int_1, __pyx_v_band_id, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 107, __pyx_L1_error) + if (__Pyx_PyObject_IsTrue(__pyx_t_3)) { + __Pyx_DECREF(__pyx_t_3); + __pyx_t_7 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_n_bands); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 107, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_band_id, __pyx_t_7, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 107, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 107, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_4 = ((!__pyx_t_5) != 0); + if (unlikely(__pyx_t_4)) { + + /* "pygeoprocessing/routing/watershed.pyx":112 + * "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)) # <<<<<<<<<<<<<< + * LOGGER.error(err_msg) + * raise ValueError(err_msg) + */ + __pyx_t_3 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_Error_band_ID_s_is_not_a_valid_b, __pyx_v_band_id); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 112, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_err_msg = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":113 + * "hard seg-fault, but it's otherwise meant to be a " + * "ValueError." % (band_id)) + * LOGGER.error(err_msg) # <<<<<<<<<<<<<< + * raise ValueError(err_msg) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 113, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_error); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 113, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __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); + } + } + __pyx_t_3 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_7, __pyx_v_err_msg) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_err_msg); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 113, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":114 + * "ValueError." % (band_id)) + * LOGGER.error(err_msg) + * raise ValueError(err_msg) # <<<<<<<<<<<<<< + * + * block_xsize, block_ysize = raster_info['block_size'] + */ + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_v_err_msg); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 114, __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, 114, __pyx_L1_error) + + /* "pygeoprocessing/routing/watershed.pyx":107 + * raster_info = pygeoprocessing.get_raster_info(raster_path) + * + * if not (1 <= band_id <= raster_info['n_bands']): # <<<<<<<<<<<<<< + * err_msg = ( + * "Error: band ID (%s) is not a valid band number. " + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":116 + * raise ValueError(err_msg) + * + * block_xsize, block_ysize = raster_info['block_size'] # <<<<<<<<<<<<<< + * if (block_xsize & (block_xsize - 1) != 0) or ( + * block_ysize & (block_ysize - 1) != 0): + */ + __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_block_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 116, __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, 116, __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, 116, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 116, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 116, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_2)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_8(__pyx_t_2); if (unlikely(!__pyx_t_1)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 1; __pyx_t_7 = __pyx_t_8(__pyx_t_2); if (unlikely(!__pyx_t_7)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_2), 2) < 0) __PYX_ERR(0, 116, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L6_unpacking_done; + __pyx_L5_unpacking_failed:; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 116, __pyx_L1_error) + __pyx_L6_unpacking_done:; + } + __pyx_v_block_xsize = __pyx_t_1; + __pyx_t_1 = 0; + __pyx_v_block_ysize = __pyx_t_7; + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":117 + * + * block_xsize, block_ysize = raster_info['block_size'] + * if (block_xsize & (block_xsize - 1) != 0) or ( # <<<<<<<<<<<<<< + * block_ysize & (block_ysize - 1) != 0): + * # If inputs are not a power of two, this will at least print + */ + __pyx_t_3 = __Pyx_PyInt_SubtractObjC(__pyx_v_block_xsize, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 117, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = PyNumber_And(__pyx_v_block_xsize, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 117, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyInt_NeObjC(__pyx_t_7, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 117, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 117, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (!__pyx_t_5) { + } else { + __pyx_t_4 = __pyx_t_5; + goto __pyx_L8_bool_binop_done; + } + + /* "pygeoprocessing/routing/watershed.pyx":118 + * block_xsize, block_ysize = raster_info['block_size'] + * if (block_xsize & (block_xsize - 1) != 0) or ( + * block_ysize & (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_3 = __Pyx_PyInt_SubtractObjC(__pyx_v_block_ysize, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 118, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = PyNumber_And(__pyx_v_block_ysize, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 118, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyInt_NeObjC(__pyx_t_7, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 118, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 118, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_4 = __pyx_t_5; + __pyx_L8_bool_binop_done:; + + /* "pygeoprocessing/routing/watershed.pyx":117 + * + * block_xsize, block_ysize = raster_info['block_size'] + * if (block_xsize & (block_xsize - 1) != 0) or ( # <<<<<<<<<<<<<< + * block_ysize & (block_ysize - 1) != 0): + * # If inputs are not a power of two, this will at least print + */ + if (unlikely(__pyx_t_4)) { + + /* "pygeoprocessing/routing/watershed.pyx":124 + * # ValueError in here at least for readability. + * err_msg = ( + * "Error: Block size is not a power of two: " # <<<<<<<<<<<<<< + * "block_xsize: %d, %d, %s. This exception is happening" + * "in Cython, so it will cause a hard seg-fault, but it's" + */ + __pyx_t_3 = PyTuple_New(7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 124, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_9 = 0; + __pyx_t_10 = 127; + __Pyx_INCREF(__pyx_kp_u_Error_Block_size_is_not_a_power); + __pyx_t_9 += 54; + __Pyx_GIVEREF(__pyx_kp_u_Error_Block_size_is_not_a_power); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_u_Error_Block_size_is_not_a_power); + + /* "pygeoprocessing/routing/watershed.pyx":128 + * "in Cython, so it will cause a hard seg-fault, but it's" + * "otherwise meant to be a ValueError." % ( + * block_xsize, block_ysize, raster_path)) # <<<<<<<<<<<<<< + * LOGGER.error(err_msg) + * raise ValueError(err_msg) + */ + __pyx_t_7 = __Pyx_PyObject_FormatAndDecref(__Pyx_PyNumber_IntOrLong(__pyx_v_block_xsize), __pyx_n_u_d); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 128, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_10 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_10) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_10; + __pyx_t_9 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_INCREF(__pyx_kp_u_); + __pyx_t_9 += 2; + __Pyx_GIVEREF(__pyx_kp_u_); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_kp_u_); + __pyx_t_7 = __Pyx_PyObject_FormatAndDecref(__Pyx_PyNumber_IntOrLong(__pyx_v_block_ysize), __pyx_n_u_d); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 128, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_10 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_10) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_10; + __pyx_t_9 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_INCREF(__pyx_kp_u_); + __pyx_t_9 += 2; + __Pyx_GIVEREF(__pyx_kp_u_); + PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_kp_u_); + __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_raster_path), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 128, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_10 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_10) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_10; + __pyx_t_9 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_3, 5, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_INCREF(__pyx_kp_u_This_exception_is_happeningin_C); + __pyx_t_9 += 118; + __Pyx_GIVEREF(__pyx_kp_u_This_exception_is_happeningin_C); + PyTuple_SET_ITEM(__pyx_t_3, 6, __pyx_kp_u_This_exception_is_happeningin_C); + + /* "pygeoprocessing/routing/watershed.pyx":124 + * # ValueError in here at least for readability. + * err_msg = ( + * "Error: Block size is not a power of two: " # <<<<<<<<<<<<<< + * "block_xsize: %d, %d, %s. This exception is happening" + * "in Cython, so it will cause a hard seg-fault, but it's" + */ + __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_3, 7, __pyx_t_9, __pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 124, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_err_msg = ((PyObject*)__pyx_t_7); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":129 + * "otherwise meant to be a ValueError." % ( + * block_xsize, block_ysize, raster_path)) + * LOGGER.error(err_msg) # <<<<<<<<<<<<<< + * raise ValueError(err_msg) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 129, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_error); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 129, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __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); + } + } + __pyx_t_7 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_3, __pyx_v_err_msg) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_err_msg); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 129, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":130 + * block_xsize, block_ysize, raster_path)) + * LOGGER.error(err_msg) + * raise ValueError(err_msg) # <<<<<<<<<<<<<< + * + * def __cinit__(self, raster_path, band_id, write_mode): + */ + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_v_err_msg); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 130, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_Raise(__pyx_t_7, 0, 0, 0); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __PYX_ERR(0, 130, __pyx_L1_error) + + /* "pygeoprocessing/routing/watershed.pyx":117 + * + * block_xsize, block_ysize = raster_info['block_size'] + * if (block_xsize & (block_xsize - 1) != 0) or ( # <<<<<<<<<<<<<< + * block_ysize & (block_ysize - 1) != 0): + * # If inputs are not a power of two, this will at least print + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":87 + * cdef int closed + * + * def __init__(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_7); + __Pyx_AddTraceback("pygeoprocessing.routing.watershed._ManagedRaster.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_raster_info); + __Pyx_XDECREF(__pyx_v_err_msg); + __Pyx_XDECREF(__pyx_v_block_xsize); + __Pyx_XDECREF(__pyx_v_block_ysize); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pygeoprocessing/routing/watershed.pyx":132 + * raise ValueError(err_msg) + * + * def __cinit__(self, raster_path, band_id, write_mode): # <<<<<<<<<<<<<< + * """Create new instance of Managed Raster. + * + */ + +/* Python wrapper */ +static int __pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_3__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_3__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_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 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, 132, __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, 132, __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, 132, __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, 132, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pygeoprocessing.routing.watershed._ManagedRaster.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_2__cinit__(((struct __pyx_obj_15pygeoprocessing_7routing_9watershed__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_9watershed_14_ManagedRaster_2__cinit__(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__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; + 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; + PyObject *(*__pyx_t_5)(PyObject *); + int __pyx_t_6; + int __pyx_t_7; + long __pyx_t_8; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "pygeoprocessing/routing/watershed.pyx":147 + * None. + * """ + * 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 147, __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, 147, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + 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_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_raster_path); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 147, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_raster_info = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":148 + * """ + * 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_u_raster_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 148, __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, 148, __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, 148, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 148, __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, 148, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext; + index = 0; __pyx_t_3 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L3_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + index = 1; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L3_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) __PYX_ERR(0, 148, __pyx_L1_error) + __pyx_t_5 = NULL; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L4_unpacking_done; + __pyx_L3_unpacking_failed:; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 148, __pyx_L1_error) + __pyx_L4_unpacking_done:; + } + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 148, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 148, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_self->raster_x_size = __pyx_t_6; + __pyx_v_self->raster_y_size = __pyx_t_7; + + /* "pygeoprocessing/routing/watershed.pyx":149 + * 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_u_block_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 149, __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, 149, __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, 149, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 149, __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, 149, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext; + index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + index = 1; __pyx_t_3 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) __PYX_ERR(0, 149, __pyx_L1_error) + __pyx_t_5 = NULL; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L6_unpacking_done; + __pyx_L5_unpacking_failed:; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 149, __pyx_L1_error) + __pyx_L6_unpacking_done:; + } + __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 149, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 149, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_self->block_xsize = __pyx_t_7; + __pyx_v_self->block_ysize = __pyx_t_6; + + /* "pygeoprocessing/routing/watershed.pyx":150 + * 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/watershed.pyx":151 + * self.block_xsize, self.block_ysize = raster_info['block_size'] + * self.block_xmod = self.block_xsize-1 + * self.block_ymod = self.block_ysize-1 # <<<<<<<<<<<<<< + * + * self.band_id = band_id + */ + __pyx_v_self->block_ymod = (__pyx_v_self->block_ysize - 1); + + /* "pygeoprocessing/routing/watershed.pyx":153 + * self.block_ymod = self.block_ysize-1 + * + * self.band_id = band_id # <<<<<<<<<<<<<< + * + * self.block_xbits = numpy.log2(self.block_xsize) + */ + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_v_band_id); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 153, __pyx_L1_error) + __pyx_v_self->band_id = __pyx_t_6; + + /* "pygeoprocessing/routing/watershed.pyx":155 + * self.band_id = band_id + * + * self.block_xbits = numpy.log2(self.block_xsize) # <<<<<<<<<<<<<< + * self.block_ybits = numpy.log2(self.block_ysize) + * self.block_nx = ( + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 155, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_log2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 155, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->block_xsize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 155, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 155, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 155, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_self->block_xbits = __pyx_t_6; + + /* "pygeoprocessing/routing/watershed.pyx":156 + * + * 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 156, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_log2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 156, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->block_ysize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 156, __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); + } + } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 156, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 156, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_self->block_ybits = __pyx_t_6; + + /* "pygeoprocessing/routing/watershed.pyx":158 + * 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_8 = ((__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, 158, __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_8))) { + PyErr_SetString(PyExc_OverflowError, "value too large to perform division"); + __PYX_ERR(0, 158, __pyx_L1_error) + } + + /* "pygeoprocessing/routing/watershed.pyx":157 + * 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_8, __pyx_v_self->block_xsize); + + /* "pygeoprocessing/routing/watershed.pyx":160 + * 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, int*](MANAGED_RASTER_N_BLOCKS) + */ + __pyx_t_8 = ((__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, 160, __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_8))) { + PyErr_SetString(PyExc_OverflowError, "value too large to perform division"); + __PYX_ERR(0, 160, __pyx_L1_error) + } + + /* "pygeoprocessing/routing/watershed.pyx":159 + * 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_8, __pyx_v_self->block_ysize); + + /* "pygeoprocessing/routing/watershed.pyx":162 + * self.raster_y_size + (self.block_ysize) - 1) // self.block_ysize + * + * self.lru_cache = new LRUCache[int, int*](MANAGED_RASTER_N_BLOCKS) # <<<<<<<<<<<<<< + * self.raster_path = raster_path + * self.write_mode = write_mode + */ + __pyx_v_self->lru_cache = new LRUCache (__pyx_v_15pygeoprocessing_7routing_9watershed_MANAGED_RASTER_N_BLOCKS); + + /* "pygeoprocessing/routing/watershed.pyx":163 + * + * self.lru_cache = new LRUCache[int, int*](MANAGED_RASTER_N_BLOCKS) + * self.raster_path = raster_path # <<<<<<<<<<<<<< + * self.write_mode = write_mode + * self.closed = 0 + */ + __pyx_t_1 = __pyx_v_raster_path; + __Pyx_INCREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->raster_path); + __Pyx_DECREF(__pyx_v_self->raster_path); + __pyx_v_self->raster_path = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":164 + * self.lru_cache = new LRUCache[int, int*](MANAGED_RASTER_N_BLOCKS) + * self.raster_path = raster_path + * self.write_mode = write_mode # <<<<<<<<<<<<<< + * self.closed = 0 + * + */ + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_v_write_mode); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 164, __pyx_L1_error) + __pyx_v_self->write_mode = __pyx_t_6; + + /* "pygeoprocessing/routing/watershed.pyx":165 + * self.raster_path = raster_path + * self.write_mode = write_mode + * self.closed = 0 # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->closed = 0; + + /* "pygeoprocessing/routing/watershed.pyx":132 + * raise ValueError(err_msg) + * + * 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_AddTraceback("pygeoprocessing.routing.watershed._ManagedRaster.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_raster_info); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pygeoprocessing/routing/watershed.pyx":167 + * self.closed = 0 + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * """Deallocate _ManagedRaster. + * + */ + +/* Python wrapper */ +static void __pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_5__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_5__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_4__dealloc__(((struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); +} + +static void __pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_4__dealloc__(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self) { + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "pygeoprocessing/routing/watershed.pyx":173 + * 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, 173, __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); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 173, __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/watershed.pyx":167 + * 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.watershed._ManagedRaster.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_L0:; + __Pyx_RefNannyFinishContext(); +} + +/* "pygeoprocessing/routing/watershed.pyx":175 + * self.close() + * + * def close(self): # <<<<<<<<<<<<<< + * """Close the _ManagedRaster and free up resources. + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_7close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_6close[] = "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_9watershed_14_ManagedRaster_7close(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_9watershed_14_ManagedRaster_6close(((struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_6close(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self) { + int __pyx_v_xi_copy; + int __pyx_v_yi_copy; + PyArrayObject *__pyx_v_block_array = 0; + int *__pyx_v_int_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_9watershed_BlockBufferPair> ::iterator __pyx_v_it; + std::list<__pyx_t_15pygeoprocessing_7routing_9watershed_BlockBufferPair> ::iterator __pyx_v_end; + PyObject *__pyx_v_raster = NULL; + PyObject *__pyx_v_raster_band = NULL; + std::set ::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; + int *__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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __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/watershed.pyx":184 + * have undefined behavior. + * """ + * if self.closed: # <<<<<<<<<<<<<< + * return + * self.closed = 1 + */ + __pyx_t_1 = (__pyx_v_self->closed != 0); + if (__pyx_t_1) { + + /* "pygeoprocessing/routing/watershed.pyx":185 + * """ + * 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/watershed.pyx":184 + * have undefined behavior. + * """ + * if self.closed: # <<<<<<<<<<<<<< + * return + * self.closed = 1 + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":186 + * if self.closed: + * return + * self.closed = 1 # <<<<<<<<<<<<<< + * cdef int xi_copy, yi_copy + * cdef numpy.ndarray[int, ndim=2] block_array = numpy.empty( + */ + __pyx_v_self->closed = 1; + + /* "pygeoprocessing/routing/watershed.pyx":188 + * self.closed = 1 + * cdef int xi_copy, yi_copy + * cdef numpy.ndarray[int, ndim=2] block_array = numpy.empty( # <<<<<<<<<<<<<< + * (self.block_ysize, self.block_xsize), dtype=numpy.int32) + * cdef int *int_buffer + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 188, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 188, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":189 + * cdef int xi_copy, yi_copy + * cdef numpy.ndarray[int, ndim=2] block_array = numpy.empty( + * (self.block_ysize, self.block_xsize), dtype=numpy.int32) # <<<<<<<<<<<<<< + * cdef int *int_buffer + * cdef int block_xi + */ + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->block_ysize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_self->block_xsize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4); + __pyx_t_2 = 0; + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":188 + * self.closed = 1 + * cdef int xi_copy, yi_copy + * cdef numpy.ndarray[int, ndim=2] block_array = numpy.empty( # <<<<<<<<<<<<<< + * (self.block_ysize, self.block_xsize), dtype=numpy.int32) + * cdef int *int_buffer + */ + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 188, __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 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":189 + * cdef int xi_copy, yi_copy + * cdef numpy.ndarray[int, ndim=2] block_array = numpy.empty( + * (self.block_ysize, self.block_xsize), dtype=numpy.int32) # <<<<<<<<<<<<<< + * cdef int *int_buffer + * cdef int block_xi + */ + __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int32); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 189, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":188 + * self.closed = 1 + * cdef int xi_copy, yi_copy + * cdef numpy.ndarray[int, ndim=2] block_array = numpy.empty( # <<<<<<<<<<<<<< + * (self.block_ysize, self.block_xsize), dtype=numpy.int32) + * cdef int *int_buffer + */ + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 188, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 188, __pyx_L1_error) + __pyx_t_7 = ((PyArrayObject *)__pyx_t_6); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_block_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_int, 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, 188, __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_6); + __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":202 + * 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/watershed.pyx":203 + * + * 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/watershed.pyx":204 + * 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/watershed.pyx":205 + * 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/watershed.pyx":207 + * 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/watershed.pyx":208 + * # write the changed value back if desired + * PyMem_Free(deref(it).second) + * inc(it) # <<<<<<<<<<<<<< + * return + * + */ + (void)((++__pyx_v_it)); + } + + /* "pygeoprocessing/routing/watershed.pyx":209 + * 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/watershed.pyx":204 + * 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/watershed.pyx":211 + * return + * + * raster = gdal.OpenEx( # <<<<<<<<<<<<<< + * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) + * raster_band = raster.GetRasterBand(self.band_id) + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_gdal); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 211, __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, 211, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":212 + * + * raster = gdal.OpenEx( + * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) # <<<<<<<<<<<<<< + * raster_band = raster.GetRasterBand(self.band_id) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_gdal); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 212, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_GA_Update); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 212, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_gdal); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 212, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 212, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyNumber_Or(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 212, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + __pyx_t_8 = 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_8 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_self->raster_path, __pyx_t_5}; + __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 211, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 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_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_self->raster_path, __pyx_t_5}; + __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 211, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_3 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 211, __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_v_self->raster_path); + __Pyx_GIVEREF(__pyx_v_self->raster_path); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_8, __pyx_v_self->raster_path); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_8, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 211, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_raster = __pyx_t_6; + __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":213 + * 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_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 213, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->band_id); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 213, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = NULL; + 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_6 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 213, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_raster_band = __pyx_t_6; + __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":217 + * # if we get here, we're in write_mode + * cdef cset[int].iterator dirty_itr + * while it != end: # <<<<<<<<<<<<<< + * int_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/watershed.pyx":218 + * cdef cset[int].iterator dirty_itr + * while it != end: + * int_buffer = deref(it).second # <<<<<<<<<<<<<< + * block_index = deref(it).first + * + */ + __pyx_t_9 = (*__pyx_v_it).second; + __pyx_v_int_buffer = __pyx_t_9; + + /* "pygeoprocessing/routing/watershed.pyx":219 + * while it != end: + * int_buffer = deref(it).second + * block_index = deref(it).first # <<<<<<<<<<<<<< + * + * # write to disk if block is dirty + */ + __pyx_t_6 = __Pyx_PyInt_From_int((*__pyx_v_it).first); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 219, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_XDECREF_SET(__pyx_v_block_index, __pyx_t_6); + __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":222 + * + * # 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, 222, __pyx_L1_error) + __pyx_v_dirty_itr = __pyx_v_self->dirty_blocks.find(__pyx_t_8); + + /* "pygeoprocessing/routing/watershed.pyx":223 + * # 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/watershed.pyx":224 + * 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 + */ + (void)(__pyx_v_self->dirty_blocks.erase(__pyx_v_dirty_itr)); + + /* "pygeoprocessing/routing/watershed.pyx":225 + * 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_6 = __Pyx_PyInt_From_int(__pyx_v_self->block_nx); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 225, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = PyNumber_Remainder(__pyx_v_block_index, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 225, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 225, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_block_xi = __pyx_t_8; + + /* "pygeoprocessing/routing/watershed.pyx":226 + * 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_4 = __Pyx_PyInt_From_int(__pyx_v_self->block_nx); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 226, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = __Pyx_PyNumber_Divide(__pyx_v_block_index, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 226, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 226, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_block_yi = __pyx_t_8; + + /* "pygeoprocessing/routing/watershed.pyx":230 + * # 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/watershed.pyx":231 + * # 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/watershed.pyx":233 + * 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/watershed.pyx":234 + * + * 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/watershed.pyx":237 + * + * # 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/watershed.pyx":238 + * # 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/watershed.pyx":237 + * + * # 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/watershed.pyx":240 + * 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/watershed.pyx":241 + * 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/watershed.pyx":240 + * 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/watershed.pyx":244 + * yoff+win_ysize - self.raster_y_size) + * + * for xi_copy in xrange(win_xsize): # <<<<<<<<<<<<<< + * for yi_copy in xrange(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/watershed.pyx":245 + * + * for xi_copy in xrange(win_xsize): + * for yi_copy in xrange(win_ysize): # <<<<<<<<<<<<<< + * block_array[yi_copy, xi_copy] = ( + * int_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/watershed.pyx":246 + * for xi_copy in xrange(win_xsize): + * for yi_copy in xrange(win_ysize): + * block_array[yi_copy, xi_copy] = ( # <<<<<<<<<<<<<< + * int_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, 246, __pyx_L1_error) + } + *__Pyx_BufPtrStrided2d(int *, __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_int_buffer[((__pyx_v_yi_copy << __pyx_v_self->block_xbits) + __pyx_v_xi_copy)]); + } + } + + /* "pygeoprocessing/routing/watershed.pyx":249 + * int_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_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster_band, __pyx_n_s_WriteArray); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 249, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + + /* "pygeoprocessing/routing/watershed.pyx":250 + * (yi_copy << self.block_xbits) + xi_copy]) + * raster_band.WriteArray( + * block_array[0:win_ysize, 0:win_xsize], # <<<<<<<<<<<<<< + * xoff=xoff, yoff=yoff) + * PyMem_Free(int_buffer) + */ + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 250, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PySlice_New(__pyx_int_0, __pyx_t_4, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 250, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 250, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PySlice_New(__pyx_int_0, __pyx_t_4, Py_None); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 250, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 250, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5); + __pyx_t_3 = 0; + __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_block_array), __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 250, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":249 + * int_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 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 249, __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 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":251 + * raster_band.WriteArray( + * block_array[0:win_ysize, 0:win_xsize], + * xoff=xoff, yoff=yoff) # <<<<<<<<<<<<<< + * PyMem_Free(int_buffer) + * inc(it) + */ + __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 251, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_xoff); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 251, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_xoff, __pyx_t_3) < 0) __PYX_ERR(0, 251, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_yoff); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 251, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_yoff, __pyx_t_3) < 0) __PYX_ERR(0, 251, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":249 + * int_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 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 249, __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; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":223 + * # 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/watershed.pyx":252 + * block_array[0:win_ysize, 0:win_xsize], + * xoff=xoff, yoff=yoff) + * PyMem_Free(int_buffer) # <<<<<<<<<<<<<< + * inc(it) + * raster_band.FlushCache() + */ + PyMem_Free(__pyx_v_int_buffer); + + /* "pygeoprocessing/routing/watershed.pyx":253 + * xoff=xoff, yoff=yoff) + * PyMem_Free(int_buffer) + * inc(it) # <<<<<<<<<<<<<< + * raster_band.FlushCache() + * raster_band = None + */ + (void)((++__pyx_v_it)); + } + + /* "pygeoprocessing/routing/watershed.pyx":254 + * PyMem_Free(int_buffer) + * inc(it) + * raster_band.FlushCache() # <<<<<<<<<<<<<< + * raster_band = None + * raster = None + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster_band, __pyx_n_s_FlushCache); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 254, __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); + } + } + __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 254, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":255 + * 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/watershed.pyx":256 + * raster_band.FlushCache() + * raster_band = None + * raster = None # <<<<<<<<<<<<<< + * + * cdef inline void set(self, int xi, int yi, int value): + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_raster, Py_None); + + /* "pygeoprocessing/routing/watershed.pyx":175 + * 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.watershed._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/watershed.pyx":258 + * raster = None + * + * cdef inline void set(self, int xi, int yi, int value): # <<<<<<<<<<<<<< + * """Set the pixel at `xi,yi` to `value`.""" + * cdef int block_xi = xi >> self.block_xbits + */ + +static CYTHON_INLINE void __pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_set(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self, int __pyx_v_xi, int __pyx_v_yi, int __pyx_v_value) { + int __pyx_v_block_xi; + int __pyx_v_block_yi; + int __pyx_v_block_index; + std::set ::iterator __pyx_v_dirty_itr; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("set", 0); + + /* "pygeoprocessing/routing/watershed.pyx":260 + * cdef inline void set(self, int xi, int yi, int value): + * """Set the pixel at `xi,yi` to `value`.""" + * 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/watershed.pyx":261 + * """Set the pixel at `xi,yi` to `value`.""" + * 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/watershed.pyx":263 + * 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/watershed.pyx":264 + * # 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/watershed.pyx":265 + * 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_9watershed__ManagedRaster *)__pyx_v_self->__pyx_vtab)->_load_block(__pyx_v_self, __pyx_v_block_index); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 265, __pyx_L1_error) + + /* "pygeoprocessing/routing/watershed.pyx":264 + * # 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/watershed.pyx":268 + * self.lru_cache.get( + * block_index)[ + * ((yi & (self.block_ymod))<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/watershed.pyx":270 + * ((yi & (self.block_ymod))<write_mode != 0); + if (__pyx_t_1) { + + /* "pygeoprocessing/routing/watershed.pyx":271 + * (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/watershed.pyx":272 + * 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/watershed.pyx":273 + * dirty_itr = self.dirty_blocks.find(block_index) + * if dirty_itr == self.dirty_blocks.end(): + * self.dirty_blocks.insert(block_index) # <<<<<<<<<<<<<< + * + * cdef inline int get(self, int xi, int yi): + */ + try { + __pyx_v_self->dirty_blocks.insert(__pyx_v_block_index); + } catch(...) { + __Pyx_CppExn2PyErr(); + __PYX_ERR(0, 273, __pyx_L1_error) + } + + /* "pygeoprocessing/routing/watershed.pyx":272 + * 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/watershed.pyx":270 + * ((yi & (self.block_ymod))<> self.block_xbits + */ + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_WriteUnraisable("pygeoprocessing.routing.watershed._ManagedRaster.set", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_L0:; + __Pyx_RefNannyFinishContext(); +} + +/* "pygeoprocessing/routing/watershed.pyx":275 + * self.dirty_blocks.insert(block_index) + * + * cdef inline int get(self, int xi, int yi): # <<<<<<<<<<<<<< + * """Return the value of the pixel at `xi,yi`.""" + * cdef int block_xi = xi >> self.block_xbits + */ + +static CYTHON_INLINE int __pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_get(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__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; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("get", 0); + + /* "pygeoprocessing/routing/watershed.pyx":277 + * cdef inline int get(self, int xi, int yi): + * """Return the value of the pixel at `xi,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/watershed.pyx":278 + * """Return the value of the pixel at `xi,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/watershed.pyx":280 + * 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/watershed.pyx":281 + * # 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/watershed.pyx":282 + * 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_9watershed__ManagedRaster *)__pyx_v_self->__pyx_vtab)->_load_block(__pyx_v_self, __pyx_v_block_index); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 282, __pyx_L1_error) + + /* "pygeoprocessing/routing/watershed.pyx":281 + * # 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/watershed.pyx":284 + * self._load_block(block_index) + * return self.lru_cache.get( + * block_index)[ # <<<<<<<<<<<<<< + * ((yi & (self.block_ymod))<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/watershed.pyx":275 + * self.dirty_blocks.insert(block_index) + * + * cdef inline int get(self, int xi, int yi): # <<<<<<<<<<<<<< + * """Return the value of the pixel at `xi,yi`.""" + * cdef int block_xi = xi >> self.block_xbits + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_WriteUnraisable("pygeoprocessing.routing.watershed._ManagedRaster.get", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pygeoprocessing/routing/watershed.pyx":288 + * (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_9watershed_14_ManagedRaster__load_block(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__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; + int *__pyx_v_int_buffer; + std::list<__pyx_t_15pygeoprocessing_7routing_9watershed_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 ::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; + int *__pyx_t_20; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __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/watershed.pyx":289 + * + * 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, 289, __pyx_L1_error) + } + __pyx_v_block_xi = __Pyx_mod_int(__pyx_v_block_index, __pyx_v_self->block_nx); + + /* "pygeoprocessing/routing/watershed.pyx":290 + * 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, 290, __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, 290, __pyx_L1_error) + } + __pyx_v_block_yi = __Pyx_div_int(__pyx_v_block_index, __pyx_v_self->block_nx); + + /* "pygeoprocessing/routing/watershed.pyx":293 + * + * # 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/watershed.pyx":294 + * # 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/watershed.pyx":305 + * # 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/watershed.pyx":306 + * # 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/watershed.pyx":309 + * + * # 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/watershed.pyx":310 + * # 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/watershed.pyx":309 + * + * # 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/watershed.pyx":311 + * 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/watershed.pyx":312 + * 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/watershed.pyx":311 + * 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/watershed.pyx":314 + * 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_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 314, __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, 314, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 314, __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, 314, __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, 314, __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, 314, __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, 314, __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, 314, __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/watershed.pyx":315 + * + * 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, 315, __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, 315, __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); + } + } + __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_7); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 315, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_raster_band = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":316 + * 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( + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 316, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + + /* "pygeoprocessing/routing/watershed.pyx":317 + * 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.int32) + */ + __pyx_t_7 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 317, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_xoff); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 317, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_xoff, __pyx_t_6) < 0) __PYX_ERR(0, 317, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_yoff); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 317, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_yoff, __pyx_t_6) < 0) __PYX_ERR(0, 317, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 317, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_win_xsize, __pyx_t_6) < 0) __PYX_ERR(0, 317, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":318 + * block_array = raster_band.ReadAsArray( + * xoff=xoff, yoff=yoff, win_xsize=win_xsize, + * win_ysize=win_ysize).astype( # <<<<<<<<<<<<<< + * numpy.int32) + * raster_band = None + */ + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 318, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_win_ysize, __pyx_t_6) < 0) __PYX_ERR(0, 317, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":316 + * 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( + */ + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_empty_tuple, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 316, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":318 + * block_array = raster_band.ReadAsArray( + * xoff=xoff, yoff=yoff, win_xsize=win_xsize, + * win_ysize=win_ysize).astype( # <<<<<<<<<<<<<< + * numpy.int32) + * raster_band = None + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_astype); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 318, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":319 + * xoff=xoff, yoff=yoff, win_xsize=win_xsize, + * win_ysize=win_ysize).astype( + * numpy.int32) # <<<<<<<<<<<<<< + * raster_band = None + * raster = None + */ + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_numpy); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 319, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int32); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 319, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 318, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":318 + * block_array = raster_band.ReadAsArray( + * xoff=xoff, yoff=yoff, win_xsize=win_xsize, + * win_ysize=win_ysize).astype( # <<<<<<<<<<<<<< + * numpy.int32) + * raster_band = None + */ + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 318, __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_int, 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_int, 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, 316, __pyx_L1_error) + } + __pyx_t_8 = 0; + __pyx_v_block_array = ((PyArrayObject *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":320 + * win_ysize=win_ysize).astype( + * numpy.int32) + * raster_band = None # <<<<<<<<<<<<<< + * raster = None + * int_buffer = PyMem_Malloc( + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_raster_band, Py_None); + + /* "pygeoprocessing/routing/watershed.pyx":321 + * numpy.int32) + * raster_band = None + * raster = None # <<<<<<<<<<<<<< + * int_buffer = PyMem_Malloc( + * (sizeof(int) << self.block_xbits) * win_ysize) + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_raster, Py_None); + + /* "pygeoprocessing/routing/watershed.pyx":322 + * raster_band = None + * raster = None + * int_buffer = PyMem_Malloc( # <<<<<<<<<<<<<< + * (sizeof(int) << self.block_xbits) * win_ysize) + * for xi_copy in xrange(win_xsize): + */ + __pyx_v_int_buffer = ((int *)PyMem_Malloc((((sizeof(int)) << __pyx_v_self->block_xbits) * __pyx_v_win_ysize))); + + /* "pygeoprocessing/routing/watershed.pyx":324 + * int_buffer = PyMem_Malloc( + * (sizeof(int) << self.block_xbits) * win_ysize) + * for xi_copy in xrange(win_xsize): # <<<<<<<<<<<<<< + * for yi_copy in xrange(win_ysize): + * int_buffer[(yi_copy<block_index, int_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, 327, __pyx_L1_error) + } + + /* "pygeoprocessing/routing/watershed.pyx":326 + * for xi_copy in xrange(win_xsize): + * for yi_copy in xrange(win_ysize): + * int_buffer[(yi_copy<block_xbits) + __pyx_v_xi_copy)]) = (*__Pyx_BufPtrStrided2d(int *, __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/watershed.pyx":328 + * int_buffer[(yi_copy<block_index, int_buffer, removed_value_list) + * + */ + __pyx_v_self->lru_cache->put(((int)__pyx_v_block_index), ((int *)__pyx_v_int_buffer), __pyx_v_removed_value_list); + + /* "pygeoprocessing/routing/watershed.pyx":331 + * block_index, int_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/watershed.pyx":332 + * + * if self.write_mode: + * raster = gdal.OpenEx( # <<<<<<<<<<<<<< + * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) + * raster_band = raster.GetRasterBand(self.band_id) + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 332, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 332, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":333 + * if self.write_mode: + * raster = gdal.OpenEx( + * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) # <<<<<<<<<<<<<< + * raster_band = raster.GetRasterBand(self.band_id) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 333, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_GA_Update); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 333, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 333, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 333, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = PyNumber_Or(__pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 333, __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_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_7}; + __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, 332, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 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[3] = {__pyx_t_4, __pyx_v_self->raster_path, __pyx_t_7}; + __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, 332, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_6 = PyTuple_New(2+__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 332, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (__pyx_t_4) { + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 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_6, 0+__pyx_t_1, __pyx_v_self->raster_path); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_1, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 332, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF_SET(__pyx_v_raster, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":334 + * 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_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 334, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_self->band_id); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 334, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + __pyx_t_3 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 334, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF_SET(__pyx_v_raster_band, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":331 + * block_index, int_buffer, removed_value_list) + * + * if self.write_mode: # <<<<<<<<<<<<<< + * raster = gdal.OpenEx( + * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":336 + * raster_band = raster.GetRasterBand(self.band_id) + * + * block_array = numpy.empty( # <<<<<<<<<<<<<< + * (self.block_ysize, self.block_xsize), dtype=numpy.int32) + * while not removed_value_list.empty(): + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 336, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 336, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":337 + * + * block_array = numpy.empty( + * (self.block_ysize, self.block_xsize), dtype=numpy.int32) # <<<<<<<<<<<<<< + * 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, 337, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_self->block_xsize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 337, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 337, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6); + __pyx_t_3 = 0; + __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":336 + * raster_band = raster.GetRasterBand(self.band_id) + * + * block_array = numpy.empty( # <<<<<<<<<<<<<< + * (self.block_ysize, self.block_xsize), dtype=numpy.int32) + * while not removed_value_list.empty(): + */ + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 336, __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 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":337 + * + * block_array = numpy.empty( + * (self.block_ysize, self.block_xsize), dtype=numpy.int32) # <<<<<<<<<<<<<< + * while not removed_value_list.empty(): + * # write the changed value back if desired + */ + __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 337, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 337, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int32); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 337, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 337, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":336 + * raster_band = raster.GetRasterBand(self.band_id) + * + * block_array = numpy.empty( # <<<<<<<<<<<<<< + * (self.block_ysize, self.block_xsize), dtype=numpy.int32) + * while not removed_value_list.empty(): + */ + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 336, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __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; + if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 336, __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_int, 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_int, 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, 336, __pyx_L1_error) + } + __pyx_t_8 = 0; + __Pyx_DECREF_SET(__pyx_v_block_array, ((PyArrayObject *)__pyx_t_4)); + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":338 + * block_array = numpy.empty( + * (self.block_ysize, self.block_xsize), dtype=numpy.int32) + * while not removed_value_list.empty(): # <<<<<<<<<<<<<< + * # write the changed value back if desired + * int_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/watershed.pyx":340 + * while not removed_value_list.empty(): + * # write the changed value back if desired + * int_buffer = removed_value_list.front().second # <<<<<<<<<<<<<< + * + * if self.write_mode: + */ + __pyx_t_20 = __pyx_v_removed_value_list.front().second; + __pyx_v_int_buffer = __pyx_t_20; + + /* "pygeoprocessing/routing/watershed.pyx":342 + * int_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/watershed.pyx":343 + * + * 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/watershed.pyx":346 + * + * # 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/watershed.pyx":347 + * # 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/watershed.pyx":348 + * 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 + */ + (void)(__pyx_v_self->dirty_blocks.erase(__pyx_v_dirty_itr)); + + /* "pygeoprocessing/routing/watershed.pyx":350 + * 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, 350, __pyx_L1_error) + } + __pyx_v_block_xi = __Pyx_mod_int(__pyx_v_block_index, __pyx_v_self->block_nx); + + /* "pygeoprocessing/routing/watershed.pyx":351 + * + * 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, 351, __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, 351, __pyx_L1_error) + } + __pyx_v_block_yi = __Pyx_div_int(__pyx_v_block_index, __pyx_v_self->block_nx); + + /* "pygeoprocessing/routing/watershed.pyx":353 + * 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/watershed.pyx":354 + * + * 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/watershed.pyx":356 + * 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/watershed.pyx":357 + * + * 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/watershed.pyx":359 + * 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/watershed.pyx":360 + * + * 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/watershed.pyx":359 + * 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/watershed.pyx":362 + * 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/watershed.pyx":363 + * 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/watershed.pyx":362 + * 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/watershed.pyx":366 + * yoff+win_ysize - self.raster_y_size) + * + * for xi_copy in xrange(win_xsize): # <<<<<<<<<<<<<< + * for yi_copy in xrange(win_ysize): + * block_array[yi_copy, xi_copy] = int_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/watershed.pyx":367 + * + * for xi_copy in xrange(win_xsize): + * for yi_copy in xrange(win_ysize): # <<<<<<<<<<<<<< + * block_array[yi_copy, xi_copy] = int_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/watershed.pyx":368 + * for xi_copy in xrange(win_xsize): + * for yi_copy in xrange(win_ysize): + * block_array[yi_copy, xi_copy] = int_buffer[ # <<<<<<<<<<<<<< + * (yi_copy << self.block_xbits) + xi_copy] + * raster_band.WriteArray( + */ + __pyx_t_18 = __pyx_v_yi_copy; + __pyx_t_17 = __pyx_v_xi_copy; + __pyx_t_19 = -1; + if (__pyx_t_18 < 0) { + __pyx_t_18 += __pyx_pybuffernd_block_array.diminfo[0].shape; + if (unlikely(__pyx_t_18 < 0)) __pyx_t_19 = 0; + } else if (unlikely(__pyx_t_18 >= __pyx_pybuffernd_block_array.diminfo[0].shape)) __pyx_t_19 = 0; + if (__pyx_t_17 < 0) { + __pyx_t_17 += __pyx_pybuffernd_block_array.diminfo[1].shape; + if (unlikely(__pyx_t_17 < 0)) __pyx_t_19 = 1; + } else if (unlikely(__pyx_t_17 >= __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, 368, __pyx_L1_error) + } + *__Pyx_BufPtrStrided2d(int *, __pyx_pybuffernd_block_array.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_block_array.diminfo[0].strides, __pyx_t_17, __pyx_pybuffernd_block_array.diminfo[1].strides) = (__pyx_v_int_buffer[((__pyx_v_yi_copy << __pyx_v_self->block_xbits) + __pyx_v_xi_copy)]); + } + } + + /* "pygeoprocessing/routing/watershed.pyx":370 + * block_array[yi_copy, xi_copy] = int_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, 370, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "pygeoprocessing/routing/watershed.pyx":371 + * (yi_copy << self.block_xbits) + xi_copy] + * raster_band.WriteArray( + * block_array[0:win_ysize, 0:win_xsize], # <<<<<<<<<<<<<< + * xoff=xoff, yoff=yoff) + * PyMem_Free(int_buffer) + */ + __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 371, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = PySlice_New(__pyx_int_0, __pyx_t_7, Py_None); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 371, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __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, 371, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_5 = PySlice_New(__pyx_int_0, __pyx_t_7, Py_None); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 371, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 371, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_5); + __pyx_t_6 = 0; + __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_block_array), __pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 371, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":370 + * block_array[yi_copy, xi_copy] = int_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 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 370, __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/watershed.pyx":372 + * raster_band.WriteArray( + * block_array[0:win_ysize, 0:win_xsize], + * xoff=xoff, yoff=yoff) # <<<<<<<<<<<<<< + * PyMem_Free(int_buffer) + * removed_value_list.pop_front() + */ + __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 372, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_xoff); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 372, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_xoff, __pyx_t_6) < 0) __PYX_ERR(0, 372, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_yoff); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 372, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_yoff, __pyx_t_6) < 0) __PYX_ERR(0, 372, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":370 + * block_array[yi_copy, xi_copy] = int_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_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 370, __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_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":347 + * # 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/watershed.pyx":342 + * int_buffer = removed_value_list.front().second + * + * if self.write_mode: # <<<<<<<<<<<<<< + * block_index = removed_value_list.front().first + * + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":373 + * block_array[0:win_ysize, 0:win_xsize], + * xoff=xoff, yoff=yoff) + * PyMem_Free(int_buffer) # <<<<<<<<<<<<<< + * removed_value_list.pop_front() + * + */ + PyMem_Free(__pyx_v_int_buffer); + + /* "pygeoprocessing/routing/watershed.pyx":374 + * xoff=xoff, yoff=yoff) + * PyMem_Free(int_buffer) + * removed_value_list.pop_front() # <<<<<<<<<<<<<< + * + * if self.write_mode: + */ + __pyx_v_removed_value_list.pop_front(); + } + + /* "pygeoprocessing/routing/watershed.pyx":376 + * 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/watershed.pyx":377 + * + * if self.write_mode: + * raster_band = None # <<<<<<<<<<<<<< + * raster = None + * + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_raster_band, Py_None); + + /* "pygeoprocessing/routing/watershed.pyx":378 + * if self.write_mode: + * raster_band = None + * raster = None # <<<<<<<<<<<<<< + * + * + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_raster, Py_None); + + /* "pygeoprocessing/routing/watershed.pyx":376 + * removed_value_list.pop_front() + * + * if self.write_mode: # <<<<<<<<<<<<<< + * raster_band = None + * raster = None + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":288 + * (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.watershed._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_9watershed_14_ManagedRaster_9__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_9__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_9watershed_14_ManagedRaster_8__reduce_cython__(((struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __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__2, 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.watershed._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_9watershed_14_ManagedRaster_11__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_11__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_9watershed_14_ManagedRaster_10__setstate_cython__(((struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __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__3, 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.watershed._ManagedRaster.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pygeoprocessing/routing/watershed.pyx":388 + * + * + * 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_9watershed_1_is_raster_path_band_formatted(PyObject *__pyx_self, PyObject *__pyx_v_raster_path_band); /*proto*/ +static char __pyx_doc_15pygeoprocessing_7routing_9watershed__is_raster_path_band_formatted[] = "Return true if raster path band is a (str, int) tuple/list."; +static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_9watershed_1_is_raster_path_band_formatted = {"_is_raster_path_band_formatted", (PyCFunction)__pyx_pw_15pygeoprocessing_7routing_9watershed_1_is_raster_path_band_formatted, METH_O, __pyx_doc_15pygeoprocessing_7routing_9watershed__is_raster_path_band_formatted}; +static PyObject *__pyx_pw_15pygeoprocessing_7routing_9watershed_1_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_9watershed__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_9watershed__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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_is_raster_path_band_formatted", 0); + + /* "pygeoprocessing/routing/watershed.pyx":390 + * 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/watershed.pyx":391 + * """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/watershed.pyx":390 + * 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/watershed.pyx":392 + * 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, 392, __pyx_L1_error) + __pyx_t_2 = ((__pyx_t_4 != 2) != 0); + if (__pyx_t_2) { + + /* "pygeoprocessing/routing/watershed.pyx":393 + * 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/watershed.pyx":392 + * 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/watershed.pyx":394 + * 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, 394, __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/watershed.pyx":395 + * 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/watershed.pyx":394 + * 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/watershed.pyx":396 + * 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, 396, __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/watershed.pyx":397 + * 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/watershed.pyx":396 + * elif not isinstance(raster_path_band[0], basestring): + * return False + * elif not isinstance(raster_path_band[1], int): # <<<<<<<<<<<<<< + * return False + * else: + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":399 + * return False + * else: + * return True # <<<<<<<<<<<<<< + * + * + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(Py_True); + __pyx_r = Py_True; + goto __pyx_L0; + } + + /* "pygeoprocessing/routing/watershed.pyx":388 + * + * + * 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.watershed._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; +} + +/* "pygeoprocessing/routing/watershed.pyx":402 + * + * + * cdef cset[CoordinatePair] _c_split_geometry_into_seeds( # <<<<<<<<<<<<<< + * source_geom_wkb, tuple flow_dir_geotransform, flow_dir_srs, + * flow_dir_n_cols, flow_dir_n_rows, + */ + +static std::set<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> __pyx_f_15pygeoprocessing_7routing_9watershed__c_split_geometry_into_seeds(PyObject *__pyx_v_source_geom_wkb, PyObject *__pyx_v_flow_dir_geotransform, PyObject *__pyx_v_flow_dir_srs, PyObject *__pyx_v_flow_dir_n_cols, PyObject *__pyx_v_flow_dir_n_rows, PyObject *__pyx_v_target_raster_path, struct __pyx_opt_args_15pygeoprocessing_7routing_9watershed__c_split_geometry_into_seeds *__pyx_optional_args) { + + /* "pygeoprocessing/routing/watershed.pyx":405 + * source_geom_wkb, tuple flow_dir_geotransform, flow_dir_srs, + * flow_dir_n_cols, flow_dir_n_rows, + * target_raster_path, diagnostic_vector_path=None): # <<<<<<<<<<<<<< + * """Split a geometry into 'seeds' of (x, y) coordinate pairs. + * + */ + PyObject *__pyx_v_diagnostic_vector_path = ((PyObject *)Py_None); + float __pyx_v_minx; + float __pyx_v_miny; + float __pyx_v_maxx; + float __pyx_v_maxy; + double __pyx_v_x_origin; + double __pyx_v_y_origin; + double __pyx_v_x_pixelwidth; + double __pyx_v_y_pixelwidth; + double __pyx_v_flow_dir_maxx; + double __pyx_v_flow_dir_miny; + std::set<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> __pyx_v_seed_set; + PyObject *__pyx_v_geometry = NULL; + int __pyx_v_minx_pixelcoord; + int __pyx_v_miny_pixelcoord; + int __pyx_v_maxx_pixelcoord; + int __pyx_v_maxy_pixelcoord; + PyObject *__pyx_v_seed = NULL; + double __pyx_v_minx_aligned; + double __pyx_v_miny_aligned; + double __pyx_v_maxx_aligned; + double __pyx_v_maxy_aligned; + double __pyx_v_local_n_cols; + double __pyx_v_local_n_rows; + PyObject *__pyx_v_memory_driver = NULL; + PyObject *__pyx_v_new_vector = NULL; + PyObject *__pyx_v_new_layer = NULL; + PyObject *__pyx_v_new_feature = NULL; + double __pyx_v_local_origin_x; + double __pyx_v_local_origin_y; + PyObject *__pyx_v_local_geotransform = NULL; + PyObject *__pyx_v_gtiff_driver = NULL; + PyObject *__pyx_v_raster = NULL; + int __pyx_v_write_diagnostic_vector; + PyObject *__pyx_v_diagnostic_vector = NULL; + PyObject *__pyx_v_diagnostic_layer = NULL; + PyObject *__pyx_v_gpkg_driver = NULL; + PyObject *__pyx_v_user_geometry_layer = NULL; + PyObject *__pyx_v_user_feature = NULL; + int __pyx_v_row; + int __pyx_v_col; + int __pyx_v_global_row; + int __pyx_v_global_col; + int __pyx_v_seed_raster_origin_col; + int __pyx_v_seed_raster_origin_row; + PyObject *__pyx_v_block_info = 0; + int __pyx_v_block_xoff; + int __pyx_v_block_yoff; + PyArrayObject *__pyx_v_seed_array = 0; + npy_intp __pyx_v_n_rows; + npy_intp __pyx_v_n_cols; + __Pyx_LocalBuf_ND __pyx_pybuffernd_seed_array; + __Pyx_Buffer __pyx_pybuffer_seed_array; + std::set<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + double __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; + PyObject *(*__pyx_t_8)(PyObject *); + float __pyx_t_9; + float __pyx_t_10; + float __pyx_t_11; + float __pyx_t_12; + int __pyx_t_13; + int __pyx_t_14; + __pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair __pyx_t_15; + double __pyx_t_16; + double __pyx_t_17; + long __pyx_t_18; + int __pyx_t_19; + PyObject *__pyx_t_20 = NULL; + Py_ssize_t __pyx_t_21; + PyObject *(*__pyx_t_22)(PyObject *); + PyArrayObject *__pyx_t_23 = NULL; + PyObject *__pyx_t_24 = NULL; + PyObject *__pyx_t_25 = NULL; + PyObject *__pyx_t_26 = NULL; + npy_intp __pyx_t_27; + npy_intp __pyx_t_28; + npy_intp __pyx_t_29; + npy_intp __pyx_t_30; + int __pyx_t_31; + Py_ssize_t __pyx_t_32; + Py_ssize_t __pyx_t_33; + PyObject *__pyx_t_34 = NULL; + PyObject *__pyx_t_35 = NULL; + PyObject *__pyx_t_36 = NULL; + int __pyx_t_37; + PyObject *__pyx_t_38 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_c_split_geometry_into_seeds", 0); + if (__pyx_optional_args) { + if (__pyx_optional_args->__pyx_n > 0) { + __pyx_v_diagnostic_vector_path = __pyx_optional_args->diagnostic_vector_path; + } + } + __pyx_pybuffer_seed_array.pybuffer.buf = NULL; + __pyx_pybuffer_seed_array.refcount = 0; + __pyx_pybuffernd_seed_array.data = NULL; + __pyx_pybuffernd_seed_array.rcbuffer = &__pyx_pybuffer_seed_array; + + /* "pygeoprocessing/routing/watershed.pyx":435 + * """ + * cdef float minx, miny, maxx, maxy + * cdef double x_origin = flow_dir_geotransform[0] # <<<<<<<<<<<<<< + * cdef double y_origin = flow_dir_geotransform[3] + * cdef double x_pixelwidth = flow_dir_geotransform[1] + */ + if (unlikely(__pyx_v_flow_dir_geotransform == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 435, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_flow_dir_geotransform, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 435, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 435, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_x_origin = __pyx_t_2; + + /* "pygeoprocessing/routing/watershed.pyx":436 + * cdef float minx, miny, maxx, maxy + * cdef double x_origin = flow_dir_geotransform[0] + * cdef double y_origin = flow_dir_geotransform[3] # <<<<<<<<<<<<<< + * cdef double x_pixelwidth = flow_dir_geotransform[1] + * cdef double y_pixelwidth = flow_dir_geotransform[5] + */ + if (unlikely(__pyx_v_flow_dir_geotransform == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 436, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_flow_dir_geotransform, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 436, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 436, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_y_origin = __pyx_t_2; + + /* "pygeoprocessing/routing/watershed.pyx":437 + * cdef double x_origin = flow_dir_geotransform[0] + * cdef double y_origin = flow_dir_geotransform[3] + * cdef double x_pixelwidth = flow_dir_geotransform[1] # <<<<<<<<<<<<<< + * cdef double y_pixelwidth = flow_dir_geotransform[5] + * cdef double flow_dir_maxx = x_origin + (flow_dir_n_cols * x_pixelwidth) + */ + if (unlikely(__pyx_v_flow_dir_geotransform == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 437, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_flow_dir_geotransform, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 437, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 437, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_x_pixelwidth = __pyx_t_2; + + /* "pygeoprocessing/routing/watershed.pyx":438 + * cdef double y_origin = flow_dir_geotransform[3] + * cdef double x_pixelwidth = flow_dir_geotransform[1] + * cdef double y_pixelwidth = flow_dir_geotransform[5] # <<<<<<<<<<<<<< + * cdef double flow_dir_maxx = x_origin + (flow_dir_n_cols * x_pixelwidth) + * cdef double flow_dir_miny = y_origin + (flow_dir_n_rows * y_pixelwidth) + */ + if (unlikely(__pyx_v_flow_dir_geotransform == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 438, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_flow_dir_geotransform, 5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 438, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 438, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_y_pixelwidth = __pyx_t_2; + + /* "pygeoprocessing/routing/watershed.pyx":439 + * cdef double x_pixelwidth = flow_dir_geotransform[1] + * cdef double y_pixelwidth = flow_dir_geotransform[5] + * cdef double flow_dir_maxx = x_origin + (flow_dir_n_cols * x_pixelwidth) # <<<<<<<<<<<<<< + * cdef double flow_dir_miny = y_origin + (flow_dir_n_rows * y_pixelwidth) + * cdef cset[CoordinatePair] seed_set + */ + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_x_origin); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 439, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyFloat_FromDouble(__pyx_v_x_pixelwidth); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 439, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyNumber_Multiply(__pyx_v_flow_dir_n_cols, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 439, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyNumber_Add(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 439, __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; + __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 439, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_flow_dir_maxx = __pyx_t_2; + + /* "pygeoprocessing/routing/watershed.pyx":440 + * cdef double y_pixelwidth = flow_dir_geotransform[5] + * cdef double flow_dir_maxx = x_origin + (flow_dir_n_cols * x_pixelwidth) + * cdef double flow_dir_miny = y_origin + (flow_dir_n_rows * y_pixelwidth) # <<<<<<<<<<<<<< + * cdef cset[CoordinatePair] seed_set + * + */ + __pyx_t_3 = PyFloat_FromDouble(__pyx_v_y_origin); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 440, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyFloat_FromDouble(__pyx_v_y_pixelwidth); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 440, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PyNumber_Multiply(__pyx_v_flow_dir_n_rows, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 440, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyNumber_Add(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 440, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 440, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_flow_dir_miny = __pyx_t_2; + + /* "pygeoprocessing/routing/watershed.pyx":443 + * cdef cset[CoordinatePair] seed_set + * + * geometry = shapely.wkb.loads(source_geom_wkb) # <<<<<<<<<<<<<< + * + * minx, miny, maxx, maxy = geometry.bounds + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_shapely); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 443, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_wkb); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 443, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_loads); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 443, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_4 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_3, __pyx_v_source_geom_wkb) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_source_geom_wkb); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 443, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_geometry = __pyx_t_4; + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":445 + * geometry = shapely.wkb.loads(source_geom_wkb) + * + * minx, miny, maxx, maxy = geometry.bounds # <<<<<<<<<<<<<< + * cdef int minx_pixelcoord = ((minx - x_origin) // x_pixelwidth) + * cdef int miny_pixelcoord = ((miny - y_origin) // y_pixelwidth) + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_geometry, __pyx_n_s_bounds); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 445, __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 != 4)) { + if (size > 4) __Pyx_RaiseTooManyValuesError(4); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 445, __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); + __pyx_t_5 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 3); + } else { + __pyx_t_1 = PyList_GET_ITEM(sequence, 0); + __pyx_t_3 = PyList_GET_ITEM(sequence, 1); + __pyx_t_5 = PyList_GET_ITEM(sequence, 2); + __pyx_t_6 = PyList_GET_ITEM(sequence, 3); + } + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(__pyx_t_6); + #else + { + Py_ssize_t i; + PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_3,&__pyx_t_5,&__pyx_t_6}; + for (i=0; i < 4; i++) { + PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 445, __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_3,&__pyx_t_5,&__pyx_t_6}; + __pyx_t_7 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 445, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; + for (index=0; index < 4; index++) { + PyObject* item = __pyx_t_8(__pyx_t_7); if (unlikely(!item)) goto __pyx_L3_unpacking_failed; + __Pyx_GOTREF(item); + *(temps[index]) = item; + } + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 4) < 0) __PYX_ERR(0, 445, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L4_unpacking_done; + __pyx_L3_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 445, __pyx_L1_error) + __pyx_L4_unpacking_done:; + } + __pyx_t_9 = __pyx_PyFloat_AsFloat(__pyx_t_1); if (unlikely((__pyx_t_9 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 445, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_10 = __pyx_PyFloat_AsFloat(__pyx_t_3); if (unlikely((__pyx_t_10 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 445, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_11 = __pyx_PyFloat_AsFloat(__pyx_t_5); if (unlikely((__pyx_t_11 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 445, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_12 = __pyx_PyFloat_AsFloat(__pyx_t_6); if (unlikely((__pyx_t_12 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 445, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_minx = __pyx_t_9; + __pyx_v_miny = __pyx_t_10; + __pyx_v_maxx = __pyx_t_11; + __pyx_v_maxy = __pyx_t_12; + + /* "pygeoprocessing/routing/watershed.pyx":446 + * + * minx, miny, maxx, maxy = geometry.bounds + * cdef int minx_pixelcoord = ((minx - x_origin) // x_pixelwidth) # <<<<<<<<<<<<<< + * cdef int miny_pixelcoord = ((miny - y_origin) // y_pixelwidth) + * cdef int maxx_pixelcoord = ((maxx - x_origin) // x_pixelwidth) + */ + __pyx_t_2 = (__pyx_v_minx - __pyx_v_x_origin); + if (unlikely(__pyx_v_x_pixelwidth == 0)) { + PyErr_SetString(PyExc_ZeroDivisionError, "float division"); + __PYX_ERR(0, 446, __pyx_L1_error) + } + __pyx_v_minx_pixelcoord = ((int)floor(__pyx_t_2 / __pyx_v_x_pixelwidth)); + + /* "pygeoprocessing/routing/watershed.pyx":447 + * minx, miny, maxx, maxy = geometry.bounds + * cdef int minx_pixelcoord = ((minx - x_origin) // x_pixelwidth) + * cdef int miny_pixelcoord = ((miny - y_origin) // y_pixelwidth) # <<<<<<<<<<<<<< + * cdef int maxx_pixelcoord = ((maxx - x_origin) // x_pixelwidth) + * cdef int maxy_pixelcoord = ((maxy - y_origin) // y_pixelwidth) + */ + __pyx_t_2 = (__pyx_v_miny - __pyx_v_y_origin); + if (unlikely(__pyx_v_y_pixelwidth == 0)) { + PyErr_SetString(PyExc_ZeroDivisionError, "float division"); + __PYX_ERR(0, 447, __pyx_L1_error) + } + __pyx_v_miny_pixelcoord = ((int)floor(__pyx_t_2 / __pyx_v_y_pixelwidth)); + + /* "pygeoprocessing/routing/watershed.pyx":448 + * cdef int minx_pixelcoord = ((minx - x_origin) // x_pixelwidth) + * cdef int miny_pixelcoord = ((miny - y_origin) // y_pixelwidth) + * cdef int maxx_pixelcoord = ((maxx - x_origin) // x_pixelwidth) # <<<<<<<<<<<<<< + * cdef int maxy_pixelcoord = ((maxy - y_origin) // y_pixelwidth) + * + */ + __pyx_t_2 = (__pyx_v_maxx - __pyx_v_x_origin); + if (unlikely(__pyx_v_x_pixelwidth == 0)) { + PyErr_SetString(PyExc_ZeroDivisionError, "float division"); + __PYX_ERR(0, 448, __pyx_L1_error) + } + __pyx_v_maxx_pixelcoord = ((int)floor(__pyx_t_2 / __pyx_v_x_pixelwidth)); + + /* "pygeoprocessing/routing/watershed.pyx":449 + * cdef int miny_pixelcoord = ((miny - y_origin) // y_pixelwidth) + * cdef int maxx_pixelcoord = ((maxx - x_origin) // x_pixelwidth) + * cdef int maxy_pixelcoord = ((maxy - y_origin) // y_pixelwidth) # <<<<<<<<<<<<<< + * + * # If the geometry only intersects a single pixel, we can treat it + */ + __pyx_t_2 = (__pyx_v_maxy - __pyx_v_y_origin); + if (unlikely(__pyx_v_y_pixelwidth == 0)) { + PyErr_SetString(PyExc_ZeroDivisionError, "float division"); + __PYX_ERR(0, 449, __pyx_L1_error) + } + __pyx_v_maxy_pixelcoord = ((int)floor(__pyx_t_2 / __pyx_v_y_pixelwidth)); + + /* "pygeoprocessing/routing/watershed.pyx":455 + * # seeds data structure and not have to include it in the disjoint set + * # determination. + * if minx_pixelcoord == maxx_pixelcoord and miny_pixelcoord == maxy_pixelcoord: # <<<<<<<<<<<<<< + * # If the point is over nodata, skip it. + * seed = CoordinatePair(minx_pixelcoord, miny_pixelcoord) + */ + __pyx_t_14 = ((__pyx_v_minx_pixelcoord == __pyx_v_maxx_pixelcoord) != 0); + if (__pyx_t_14) { + } else { + __pyx_t_13 = __pyx_t_14; + goto __pyx_L6_bool_binop_done; + } + __pyx_t_14 = ((__pyx_v_miny_pixelcoord == __pyx_v_maxy_pixelcoord) != 0); + __pyx_t_13 = __pyx_t_14; + __pyx_L6_bool_binop_done:; + if (__pyx_t_13) { + + /* "pygeoprocessing/routing/watershed.pyx":457 + * if minx_pixelcoord == maxx_pixelcoord and miny_pixelcoord == maxy_pixelcoord: + * # If the point is over nodata, skip it. + * seed = CoordinatePair(minx_pixelcoord, miny_pixelcoord) # <<<<<<<<<<<<<< + * seed_set.insert(seed) + * return seed_set + */ + try { + __pyx_t_15 = __pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair(__pyx_v_minx_pixelcoord, __pyx_v_miny_pixelcoord); + } catch(...) { + __Pyx_CppExn2PyErr(); + __PYX_ERR(0, 457, __pyx_L1_error) + } + __pyx_t_4 = __pyx_convert_pair_to_py_long____long(__pyx_t_15); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 457, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_v_seed = __pyx_t_4; + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":458 + * # If the point is over nodata, skip it. + * seed = CoordinatePair(minx_pixelcoord, miny_pixelcoord) + * seed_set.insert(seed) # <<<<<<<<<<<<<< + * return seed_set + * + */ + __pyx_t_15 = __pyx_convert_pair_from_py_long__and_long(__pyx_v_seed); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 458, __pyx_L1_error) + try { + __pyx_v_seed_set.insert(__pyx_t_15); + } catch(...) { + __Pyx_CppExn2PyErr(); + __PYX_ERR(0, 458, __pyx_L1_error) + } + + /* "pygeoprocessing/routing/watershed.pyx":459 + * seed = CoordinatePair(minx_pixelcoord, miny_pixelcoord) + * seed_set.insert(seed) + * return seed_set # <<<<<<<<<<<<<< + * + * # If the geometry's bounding box covers more than one pixel, we need to + */ + __pyx_r = __pyx_v_seed_set; + goto __pyx_L0; + + /* "pygeoprocessing/routing/watershed.pyx":455 + * # seeds data structure and not have to include it in the disjoint set + * # determination. + * if minx_pixelcoord == maxx_pixelcoord and miny_pixelcoord == maxy_pixelcoord: # <<<<<<<<<<<<<< + * # If the point is over nodata, skip it. + * seed = CoordinatePair(minx_pixelcoord, miny_pixelcoord) + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":465 + * cdef double minx_aligned = max( + * x_origin + (minx_pixelcoord * x_pixelwidth), + * x_origin) # <<<<<<<<<<<<<< + * cdef double miny_aligned = max( + * y_origin + ((miny_pixelcoord+1) * y_pixelwidth), + */ + __pyx_t_2 = __pyx_v_x_origin; + + /* "pygeoprocessing/routing/watershed.pyx":464 + * # rasterize it to determine which pixels it intersects. + * cdef double minx_aligned = max( + * x_origin + (minx_pixelcoord * x_pixelwidth), # <<<<<<<<<<<<<< + * x_origin) + * cdef double miny_aligned = max( + */ + __pyx_t_16 = (__pyx_v_x_origin + (__pyx_v_minx_pixelcoord * __pyx_v_x_pixelwidth)); + + /* "pygeoprocessing/routing/watershed.pyx":465 + * cdef double minx_aligned = max( + * x_origin + (minx_pixelcoord * x_pixelwidth), + * x_origin) # <<<<<<<<<<<<<< + * cdef double miny_aligned = max( + * y_origin + ((miny_pixelcoord+1) * y_pixelwidth), + */ + if (((__pyx_t_2 > __pyx_t_16) != 0)) { + __pyx_t_17 = __pyx_t_2; + } else { + __pyx_t_17 = __pyx_t_16; + } + __pyx_v_minx_aligned = __pyx_t_17; + + /* "pygeoprocessing/routing/watershed.pyx":468 + * cdef double miny_aligned = max( + * y_origin + ((miny_pixelcoord+1) * y_pixelwidth), + * flow_dir_miny) # <<<<<<<<<<<<<< + * cdef double maxx_aligned = min( + * x_origin + ((maxx_pixelcoord+1) * x_pixelwidth), + */ + __pyx_t_17 = __pyx_v_flow_dir_miny; + + /* "pygeoprocessing/routing/watershed.pyx":467 + * x_origin) + * cdef double miny_aligned = max( + * y_origin + ((miny_pixelcoord+1) * y_pixelwidth), # <<<<<<<<<<<<<< + * flow_dir_miny) + * cdef double maxx_aligned = min( + */ + __pyx_t_2 = (__pyx_v_y_origin + ((__pyx_v_miny_pixelcoord + 1) * __pyx_v_y_pixelwidth)); + + /* "pygeoprocessing/routing/watershed.pyx":468 + * cdef double miny_aligned = max( + * y_origin + ((miny_pixelcoord+1) * y_pixelwidth), + * flow_dir_miny) # <<<<<<<<<<<<<< + * cdef double maxx_aligned = min( + * x_origin + ((maxx_pixelcoord+1) * x_pixelwidth), + */ + if (((__pyx_t_17 > __pyx_t_2) != 0)) { + __pyx_t_16 = __pyx_t_17; + } else { + __pyx_t_16 = __pyx_t_2; + } + __pyx_v_miny_aligned = __pyx_t_16; + + /* "pygeoprocessing/routing/watershed.pyx":471 + * cdef double maxx_aligned = min( + * x_origin + ((maxx_pixelcoord+1) * x_pixelwidth), + * flow_dir_maxx) # <<<<<<<<<<<<<< + * cdef double maxy_aligned = min( + * y_origin + (maxy_pixelcoord * y_pixelwidth), + */ + __pyx_t_16 = __pyx_v_flow_dir_maxx; + + /* "pygeoprocessing/routing/watershed.pyx":470 + * flow_dir_miny) + * cdef double maxx_aligned = min( + * x_origin + ((maxx_pixelcoord+1) * x_pixelwidth), # <<<<<<<<<<<<<< + * flow_dir_maxx) + * cdef double maxy_aligned = min( + */ + __pyx_t_17 = (__pyx_v_x_origin + ((__pyx_v_maxx_pixelcoord + 1) * __pyx_v_x_pixelwidth)); + + /* "pygeoprocessing/routing/watershed.pyx":471 + * cdef double maxx_aligned = min( + * x_origin + ((maxx_pixelcoord+1) * x_pixelwidth), + * flow_dir_maxx) # <<<<<<<<<<<<<< + * cdef double maxy_aligned = min( + * y_origin + (maxy_pixelcoord * y_pixelwidth), + */ + if (((__pyx_t_16 < __pyx_t_17) != 0)) { + __pyx_t_2 = __pyx_t_16; + } else { + __pyx_t_2 = __pyx_t_17; + } + __pyx_v_maxx_aligned = __pyx_t_2; + + /* "pygeoprocessing/routing/watershed.pyx":474 + * cdef double maxy_aligned = min( + * y_origin + (maxy_pixelcoord * y_pixelwidth), + * y_origin) # <<<<<<<<<<<<<< + * + * # It's possible for a perfectly vertical or horizontal line to cover 0 rows + */ + __pyx_t_2 = __pyx_v_y_origin; + + /* "pygeoprocessing/routing/watershed.pyx":473 + * flow_dir_maxx) + * cdef double maxy_aligned = min( + * y_origin + (maxy_pixelcoord * y_pixelwidth), # <<<<<<<<<<<<<< + * y_origin) + * + */ + __pyx_t_16 = (__pyx_v_y_origin + (__pyx_v_maxy_pixelcoord * __pyx_v_y_pixelwidth)); + + /* "pygeoprocessing/routing/watershed.pyx":474 + * cdef double maxy_aligned = min( + * y_origin + (maxy_pixelcoord * y_pixelwidth), + * y_origin) # <<<<<<<<<<<<<< + * + * # It's possible for a perfectly vertical or horizontal line to cover 0 rows + */ + if (((__pyx_t_2 < __pyx_t_16) != 0)) { + __pyx_t_17 = __pyx_t_2; + } else { + __pyx_t_17 = __pyx_t_16; + } + __pyx_v_maxy_aligned = __pyx_t_17; + + /* "pygeoprocessing/routing/watershed.pyx":478 + * # It's possible for a perfectly vertical or horizontal line to cover 0 rows + * # or columns, so defaulting to row/col count of 1 in these cases. + * local_n_cols = max(abs(maxx_aligned - minx_aligned) // abs(x_pixelwidth), 1) # <<<<<<<<<<<<<< + * local_n_rows = max(abs(maxy_aligned - miny_aligned) // abs(y_pixelwidth), 1) + * + */ + __pyx_t_18 = 1; + __pyx_t_17 = fabs((__pyx_v_maxx_aligned - __pyx_v_minx_aligned)); + __pyx_t_2 = fabs(__pyx_v_x_pixelwidth); + if (unlikely(__pyx_t_2 == 0)) { + PyErr_SetString(PyExc_ZeroDivisionError, "float division"); + __PYX_ERR(0, 478, __pyx_L1_error) + } + __pyx_t_16 = floor(__pyx_t_17 / __pyx_t_2); + if (((__pyx_t_18 > __pyx_t_16) != 0)) { + __pyx_t_2 = __pyx_t_18; + } else { + __pyx_t_2 = __pyx_t_16; + } + __pyx_v_local_n_cols = __pyx_t_2; + + /* "pygeoprocessing/routing/watershed.pyx":479 + * # or columns, so defaulting to row/col count of 1 in these cases. + * local_n_cols = max(abs(maxx_aligned - minx_aligned) // abs(x_pixelwidth), 1) + * local_n_rows = max(abs(maxy_aligned - miny_aligned) // abs(y_pixelwidth), 1) # <<<<<<<<<<<<<< + * + * # The geometry does not fit into a single pixel, so let's create a new + */ + __pyx_t_18 = 1; + __pyx_t_2 = fabs((__pyx_v_maxy_aligned - __pyx_v_miny_aligned)); + __pyx_t_16 = fabs(__pyx_v_y_pixelwidth); + if (unlikely(__pyx_t_16 == 0)) { + PyErr_SetString(PyExc_ZeroDivisionError, "float division"); + __PYX_ERR(0, 479, __pyx_L1_error) + } + __pyx_t_17 = floor(__pyx_t_2 / __pyx_t_16); + if (((__pyx_t_18 > __pyx_t_17) != 0)) { + __pyx_t_16 = __pyx_t_18; + } else { + __pyx_t_16 = __pyx_t_17; + } + __pyx_v_local_n_rows = __pyx_t_16; + + /* "pygeoprocessing/routing/watershed.pyx":483 + * # The geometry does not fit into a single pixel, so let's create a new + * # raster onto which to rasterize it. + * memory_driver = gdal.GetDriverByName('Memory') # <<<<<<<<<<<<<< + * new_vector = memory_driver.Create('mem', 0, 0, 0, gdal.GDT_Unknown) + * new_layer = new_vector.CreateLayer('user_geometry', flow_dir_srs, ogr.wkbUnknown) + */ + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_gdal); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 483, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_GetDriverByName); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 483, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __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); + } + } + __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_n_u_Memory) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_n_u_Memory); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 483, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_memory_driver = __pyx_t_4; + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":484 + * # raster onto which to rasterize it. + * memory_driver = gdal.GetDriverByName('Memory') + * new_vector = memory_driver.Create('mem', 0, 0, 0, gdal.GDT_Unknown) # <<<<<<<<<<<<<< + * new_layer = new_vector.CreateLayer('user_geometry', flow_dir_srs, ogr.wkbUnknown) + * new_layer.StartTransaction() + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_memory_driver, __pyx_n_s_Create); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 484, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_gdal); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 484, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_GDT_Unknown); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 484, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = NULL; + __pyx_t_19 = 0; + 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); + __pyx_t_19 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[6] = {__pyx_t_6, __pyx_n_u_mem, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_t_3}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_19, 5+__pyx_t_19); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 484, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_4); + __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[6] = {__pyx_t_6, __pyx_n_u_mem, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_t_3}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_19, 5+__pyx_t_19); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 484, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + { + __pyx_t_1 = PyTuple_New(5+__pyx_t_19); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 484, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (__pyx_t_6) { + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_6); __pyx_t_6 = NULL; + } + __Pyx_INCREF(__pyx_n_u_mem); + __Pyx_GIVEREF(__pyx_n_u_mem); + PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_19, __pyx_n_u_mem); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_19, __pyx_int_0); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_1, 2+__pyx_t_19, __pyx_int_0); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_1, 3+__pyx_t_19, __pyx_int_0); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_1, 4+__pyx_t_19, __pyx_t_3); + __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, 484, __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_v_new_vector = __pyx_t_4; + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":485 + * memory_driver = gdal.GetDriverByName('Memory') + * new_vector = memory_driver.Create('mem', 0, 0, 0, gdal.GDT_Unknown) + * new_layer = new_vector.CreateLayer('user_geometry', flow_dir_srs, ogr.wkbUnknown) # <<<<<<<<<<<<<< + * new_layer.StartTransaction() + * new_feature = ogr.Feature(new_layer.GetLayerDefn()) + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_new_vector, __pyx_n_s_CreateLayer); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 485, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 485, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_wkbUnknown); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 485, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + __pyx_t_19 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_19 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_n_u_user_geometry, __pyx_v_flow_dir_srs, __pyx_t_3}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_19, 3+__pyx_t_19); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 485, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_4); + __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[4] = {__pyx_t_1, __pyx_n_u_user_geometry, __pyx_v_flow_dir_srs, __pyx_t_3}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_19, 3+__pyx_t_19); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 485, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + { + __pyx_t_6 = PyTuple_New(3+__pyx_t_19); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 485, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (__pyx_t_1) { + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); __pyx_t_1 = NULL; + } + __Pyx_INCREF(__pyx_n_u_user_geometry); + __Pyx_GIVEREF(__pyx_n_u_user_geometry); + PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_19, __pyx_n_u_user_geometry); + __Pyx_INCREF(__pyx_v_flow_dir_srs); + __Pyx_GIVEREF(__pyx_v_flow_dir_srs); + PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_19, __pyx_v_flow_dir_srs); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_19, __pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 485, __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_v_new_layer = __pyx_t_4; + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":486 + * new_vector = memory_driver.Create('mem', 0, 0, 0, gdal.GDT_Unknown) + * new_layer = new_vector.CreateLayer('user_geometry', flow_dir_srs, ogr.wkbUnknown) + * new_layer.StartTransaction() # <<<<<<<<<<<<<< + * new_feature = ogr.Feature(new_layer.GetLayerDefn()) + * new_feature.SetGeometry(ogr.CreateGeometryFromWkb(source_geom_wkb)) + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_new_layer, __pyx_n_s_StartTransaction); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 486, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __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); + } + } + __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 486, __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/watershed.pyx":487 + * new_layer = new_vector.CreateLayer('user_geometry', flow_dir_srs, ogr.wkbUnknown) + * new_layer.StartTransaction() + * new_feature = ogr.Feature(new_layer.GetLayerDefn()) # <<<<<<<<<<<<<< + * new_feature.SetGeometry(ogr.CreateGeometryFromWkb(source_geom_wkb)) + * new_layer.CreateFeature(new_feature) + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_ogr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 487, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_Feature); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 487, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_new_layer, __pyx_n_s_GetLayerDefn); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 487, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __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); + } + } + __pyx_t_5 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 487, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(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); + } + } + __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_3, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 487, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_new_feature = __pyx_t_4; + __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":488 + * new_layer.StartTransaction() + * new_feature = ogr.Feature(new_layer.GetLayerDefn()) + * new_feature.SetGeometry(ogr.CreateGeometryFromWkb(source_geom_wkb)) # <<<<<<<<<<<<<< + * new_layer.CreateFeature(new_feature) + * new_layer.CommitTransaction() + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_new_feature, __pyx_n_s_SetGeometry); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 488, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_ogr); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 488, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_CreateGeometryFromWkb); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 488, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __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); + } + } + __pyx_t_5 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_3, __pyx_v_source_geom_wkb) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_source_geom_wkb); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 488, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + __pyx_t_4 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_1, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 488, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":489 + * new_feature = ogr.Feature(new_layer.GetLayerDefn()) + * new_feature.SetGeometry(ogr.CreateGeometryFromWkb(source_geom_wkb)) + * new_layer.CreateFeature(new_feature) # <<<<<<<<<<<<<< + * new_layer.CommitTransaction() + * + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_new_layer, __pyx_n_s_CreateFeature); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 489, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_v_new_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_new_feature); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 489, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":490 + * new_feature.SetGeometry(ogr.CreateGeometryFromWkb(source_geom_wkb)) + * new_layer.CreateFeature(new_feature) + * new_layer.CommitTransaction() # <<<<<<<<<<<<<< + * + * local_origin_x = max(minx_aligned, x_origin) + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_new_layer, __pyx_n_s_CommitTransaction); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 490, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 490, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":492 + * new_layer.CommitTransaction() + * + * local_origin_x = max(minx_aligned, x_origin) # <<<<<<<<<<<<<< + * local_origin_y = min(maxy_aligned, y_origin) + * + */ + __pyx_t_16 = __pyx_v_x_origin; + __pyx_t_17 = __pyx_v_minx_aligned; + if (((__pyx_t_16 > __pyx_t_17) != 0)) { + __pyx_t_2 = __pyx_t_16; + } else { + __pyx_t_2 = __pyx_t_17; + } + __pyx_v_local_origin_x = __pyx_t_2; + + /* "pygeoprocessing/routing/watershed.pyx":493 + * + * local_origin_x = max(minx_aligned, x_origin) + * local_origin_y = min(maxy_aligned, y_origin) # <<<<<<<<<<<<<< + * + * local_geotransform = [ + */ + __pyx_t_2 = __pyx_v_y_origin; + __pyx_t_16 = __pyx_v_maxy_aligned; + if (((__pyx_t_2 < __pyx_t_16) != 0)) { + __pyx_t_17 = __pyx_t_2; + } else { + __pyx_t_17 = __pyx_t_16; + } + __pyx_v_local_origin_y = __pyx_t_17; + + /* "pygeoprocessing/routing/watershed.pyx":496 + * + * local_geotransform = [ + * local_origin_x, flow_dir_geotransform[1], flow_dir_geotransform[2], # <<<<<<<<<<<<<< + * local_origin_y, flow_dir_geotransform[4], flow_dir_geotransform[5]] + * gtiff_driver = gdal.GetDriverByName('GTiff') + */ + __pyx_t_4 = PyFloat_FromDouble(__pyx_v_local_origin_x); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 496, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (unlikely(__pyx_v_flow_dir_geotransform == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 496, __pyx_L1_error) + } + __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v_flow_dir_geotransform, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 496, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (unlikely(__pyx_v_flow_dir_geotransform == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 496, __pyx_L1_error) + } + __pyx_t_5 = __Pyx_GetItemInt_Tuple(__pyx_v_flow_dir_geotransform, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 496, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + + /* "pygeoprocessing/routing/watershed.pyx":497 + * local_geotransform = [ + * local_origin_x, flow_dir_geotransform[1], flow_dir_geotransform[2], + * local_origin_y, flow_dir_geotransform[4], flow_dir_geotransform[5]] # <<<<<<<<<<<<<< + * gtiff_driver = gdal.GetDriverByName('GTiff') + * # Raster is sparse, no need to fill. + */ + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_local_origin_y); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 497, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (unlikely(__pyx_v_flow_dir_geotransform == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 497, __pyx_L1_error) + } + __pyx_t_3 = __Pyx_GetItemInt_Tuple(__pyx_v_flow_dir_geotransform, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 497, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (unlikely(__pyx_v_flow_dir_geotransform == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 497, __pyx_L1_error) + } + __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v_flow_dir_geotransform, 5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 497, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + + /* "pygeoprocessing/routing/watershed.pyx":495 + * local_origin_y = min(maxy_aligned, y_origin) + * + * local_geotransform = [ # <<<<<<<<<<<<<< + * local_origin_x, flow_dir_geotransform[1], flow_dir_geotransform[2], + * local_origin_y, flow_dir_geotransform[4], flow_dir_geotransform[5]] + */ + __pyx_t_20 = PyList_New(6); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 495, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_GIVEREF(__pyx_t_4); + PyList_SET_ITEM(__pyx_t_20, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_6); + PyList_SET_ITEM(__pyx_t_20, 1, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_5); + PyList_SET_ITEM(__pyx_t_20, 2, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_1); + PyList_SET_ITEM(__pyx_t_20, 3, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_3); + PyList_SET_ITEM(__pyx_t_20, 4, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_7); + PyList_SET_ITEM(__pyx_t_20, 5, __pyx_t_7); + __pyx_t_4 = 0; + __pyx_t_6 = 0; + __pyx_t_5 = 0; + __pyx_t_1 = 0; + __pyx_t_3 = 0; + __pyx_t_7 = 0; + __pyx_v_local_geotransform = ((PyObject*)__pyx_t_20); + __pyx_t_20 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":498 + * local_origin_x, flow_dir_geotransform[1], flow_dir_geotransform[2], + * local_origin_y, flow_dir_geotransform[4], flow_dir_geotransform[5]] + * gtiff_driver = gdal.GetDriverByName('GTiff') # <<<<<<<<<<<<<< + * # Raster is sparse, no need to fill. + * raster = gtiff_driver.Create( + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 498, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_GetDriverByName); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 498, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_20 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_7, __pyx_n_u_GTiff) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_n_u_GTiff); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 498, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_gtiff_driver = __pyx_t_20; + __pyx_t_20 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":500 + * gtiff_driver = gdal.GetDriverByName('GTiff') + * # Raster is sparse, no need to fill. + * raster = gtiff_driver.Create( # <<<<<<<<<<<<<< + * target_raster_path, int(local_n_cols), int(local_n_rows), 1, + * gdal.GDT_Byte, options=GTIFF_CREATION_OPTIONS) + */ + __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_v_gtiff_driver, __pyx_n_s_Create); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 500, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + + /* "pygeoprocessing/routing/watershed.pyx":501 + * # Raster is sparse, no need to fill. + * raster = gtiff_driver.Create( + * target_raster_path, int(local_n_cols), int(local_n_rows), 1, # <<<<<<<<<<<<<< + * gdal.GDT_Byte, options=GTIFF_CREATION_OPTIONS) + * raster.SetProjection(flow_dir_srs.ExportToWkt()) + */ + __pyx_t_3 = __Pyx_PyInt_FromDouble(__pyx_v_local_n_cols); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 501, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = __Pyx_PyInt_FromDouble(__pyx_v_local_n_rows); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 501, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + + /* "pygeoprocessing/routing/watershed.pyx":502 + * raster = gtiff_driver.Create( + * target_raster_path, int(local_n_cols), int(local_n_rows), 1, + * gdal.GDT_Byte, options=GTIFF_CREATION_OPTIONS) # <<<<<<<<<<<<<< + * raster.SetProjection(flow_dir_srs.ExportToWkt()) + * raster.SetGeoTransform(local_geotransform) + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 502, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 502, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":500 + * gtiff_driver = gdal.GetDriverByName('GTiff') + * # Raster is sparse, no need to fill. + * raster = gtiff_driver.Create( # <<<<<<<<<<<<<< + * target_raster_path, int(local_n_cols), int(local_n_rows), 1, + * gdal.GDT_Byte, options=GTIFF_CREATION_OPTIONS) + */ + __pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 500, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_target_raster_path); + __Pyx_GIVEREF(__pyx_v_target_raster_path); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_target_raster_path); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_7); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_int_1); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_t_5); + __pyx_t_3 = 0; + __pyx_t_7 = 0; + __pyx_t_5 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":502 + * raster = gtiff_driver.Create( + * target_raster_path, int(local_n_cols), int(local_n_rows), 1, + * gdal.GDT_Byte, options=GTIFF_CREATION_OPTIONS) # <<<<<<<<<<<<<< + * raster.SetProjection(flow_dir_srs.ExportToWkt()) + * raster.SetGeoTransform(local_geotransform) + */ + __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 502, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_GTIFF_CREATION_OPTIONS); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 502, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_options, __pyx_t_7) < 0) __PYX_ERR(0, 502, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":500 + * gtiff_driver = gdal.GetDriverByName('GTiff') + * # Raster is sparse, no need to fill. + * raster = gtiff_driver.Create( # <<<<<<<<<<<<<< + * target_raster_path, int(local_n_cols), int(local_n_rows), 1, + * gdal.GDT_Byte, options=GTIFF_CREATION_OPTIONS) + */ + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_20, __pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 500, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_raster = __pyx_t_7; + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":503 + * target_raster_path, int(local_n_cols), int(local_n_rows), 1, + * gdal.GDT_Byte, options=GTIFF_CREATION_OPTIONS) + * raster.SetProjection(flow_dir_srs.ExportToWkt()) # <<<<<<<<<<<<<< + * raster.SetGeoTransform(local_geotransform) + * + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster, __pyx_n_s_SetProjection); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 503, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_srs, __pyx_n_s_ExportToWkt); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 503, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_20))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_20); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_20); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_20, function); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_20, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_20); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 503, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + __pyx_t_20 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_20)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_20); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + __pyx_t_7 = (__pyx_t_20) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_20, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_1); + __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 503, __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/watershed.pyx":504 + * gdal.GDT_Byte, options=GTIFF_CREATION_OPTIONS) + * raster.SetProjection(flow_dir_srs.ExportToWkt()) + * raster.SetGeoTransform(local_geotransform) # <<<<<<<<<<<<<< + * + * gdal.RasterizeLayer( + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster, __pyx_n_s_SetGeoTransform); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 504, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + __pyx_t_7 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_1, __pyx_v_local_geotransform) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_local_geotransform); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 504, __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/watershed.pyx":506 + * raster.SetGeoTransform(local_geotransform) + * + * gdal.RasterizeLayer( # <<<<<<<<<<<<<< + * raster, [1], new_layer, burn_values=[1], options=['ALL_TOUCHED=True']) + * raster = None + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 506, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_RasterizeLayer); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 506, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":507 + * + * gdal.RasterizeLayer( + * raster, [1], new_layer, burn_values=[1], options=['ALL_TOUCHED=True']) # <<<<<<<<<<<<<< + * raster = None + * + */ + __pyx_t_7 = PyList_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 507, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyList_SET_ITEM(__pyx_t_7, 0, __pyx_int_1); + + /* "pygeoprocessing/routing/watershed.pyx":506 + * raster.SetGeoTransform(local_geotransform) + * + * gdal.RasterizeLayer( # <<<<<<<<<<<<<< + * raster, [1], new_layer, burn_values=[1], options=['ALL_TOUCHED=True']) + * raster = None + */ + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 506, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_raster); + __Pyx_GIVEREF(__pyx_v_raster); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_raster); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_7); + __Pyx_INCREF(__pyx_v_new_layer); + __Pyx_GIVEREF(__pyx_v_new_layer); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_new_layer); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":507 + * + * gdal.RasterizeLayer( + * raster, [1], new_layer, burn_values=[1], options=['ALL_TOUCHED=True']) # <<<<<<<<<<<<<< + * raster = None + * + */ + __pyx_t_7 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 507, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_20 = PyList_New(1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 507, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyList_SET_ITEM(__pyx_t_20, 0, __pyx_int_1); + if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_burn_values, __pyx_t_20) < 0) __PYX_ERR(0, 507, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + __pyx_t_20 = PyList_New(1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 507, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_INCREF(__pyx_kp_u_ALL_TOUCHED_True); + __Pyx_GIVEREF(__pyx_kp_u_ALL_TOUCHED_True); + PyList_SET_ITEM(__pyx_t_20, 0, __pyx_kp_u_ALL_TOUCHED_True); + if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_options, __pyx_t_20) < 0) __PYX_ERR(0, 507, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":506 + * raster.SetGeoTransform(local_geotransform) + * + * gdal.RasterizeLayer( # <<<<<<<<<<<<<< + * raster, [1], new_layer, burn_values=[1], options=['ALL_TOUCHED=True']) + * raster = None + */ + __pyx_t_20 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_1, __pyx_t_7); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 506, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":508 + * gdal.RasterizeLayer( + * raster, [1], new_layer, burn_values=[1], options=['ALL_TOUCHED=True']) + * raster = None # <<<<<<<<<<<<<< + * + * cdef int write_diagnostic_vector = 0 + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_raster, Py_None); + + /* "pygeoprocessing/routing/watershed.pyx":510 + * raster = None + * + * cdef int write_diagnostic_vector = 0 # <<<<<<<<<<<<<< + * diagnostic_vector = None + * diagnostic_layer = None + */ + __pyx_v_write_diagnostic_vector = 0; + + /* "pygeoprocessing/routing/watershed.pyx":511 + * + * cdef int write_diagnostic_vector = 0 + * diagnostic_vector = None # <<<<<<<<<<<<<< + * diagnostic_layer = None + * if diagnostic_vector_path is not None: + */ + __Pyx_INCREF(Py_None); + __pyx_v_diagnostic_vector = Py_None; + + /* "pygeoprocessing/routing/watershed.pyx":512 + * cdef int write_diagnostic_vector = 0 + * diagnostic_vector = None + * diagnostic_layer = None # <<<<<<<<<<<<<< + * if diagnostic_vector_path is not None: + * write_diagnostic_vector = 1 + */ + __Pyx_INCREF(Py_None); + __pyx_v_diagnostic_layer = Py_None; + + /* "pygeoprocessing/routing/watershed.pyx":513 + * diagnostic_vector = None + * diagnostic_layer = None + * if diagnostic_vector_path is not None: # <<<<<<<<<<<<<< + * write_diagnostic_vector = 1 + * + */ + __pyx_t_13 = (__pyx_v_diagnostic_vector_path != Py_None); + __pyx_t_14 = (__pyx_t_13 != 0); + if (__pyx_t_14) { + + /* "pygeoprocessing/routing/watershed.pyx":514 + * diagnostic_layer = None + * if diagnostic_vector_path is not None: + * write_diagnostic_vector = 1 # <<<<<<<<<<<<<< + * + * gpkg_driver = gdal.GetDriverByName('GPKG') + */ + __pyx_v_write_diagnostic_vector = 1; + + /* "pygeoprocessing/routing/watershed.pyx":516 + * write_diagnostic_vector = 1 + * + * gpkg_driver = gdal.GetDriverByName('GPKG') # <<<<<<<<<<<<<< + * diagnostic_vector = gpkg_driver.Create( + * diagnostic_vector_path, 0, 0, 0, gdal.GDT_Unknown) + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 516, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_GetDriverByName); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 516, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __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); + } + } + __pyx_t_20 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_7, __pyx_n_u_GPKG) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_n_u_GPKG); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 516, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_gpkg_driver = __pyx_t_20; + __pyx_t_20 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":517 + * + * gpkg_driver = gdal.GetDriverByName('GPKG') + * diagnostic_vector = gpkg_driver.Create( # <<<<<<<<<<<<<< + * diagnostic_vector_path, 0, 0, 0, gdal.GDT_Unknown) + * diagnostic_layer = diagnostic_vector.CreateLayer( + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_gpkg_driver, __pyx_n_s_Create); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 517, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/watershed.pyx":518 + * gpkg_driver = gdal.GetDriverByName('GPKG') + * diagnostic_vector = gpkg_driver.Create( + * diagnostic_vector_path, 0, 0, 0, gdal.GDT_Unknown) # <<<<<<<<<<<<<< + * diagnostic_layer = diagnostic_vector.CreateLayer( + * 'seeds', flow_dir_srs, ogr.wkbPoint) + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 518, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_GDT_Unknown); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 518, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + __pyx_t_19 = 0; + if (CYTHON_UNPACK_METHODS && likely(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); + __pyx_t_19 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[6] = {__pyx_t_7, __pyx_v_diagnostic_vector_path, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_t_5}; + __pyx_t_20 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_19, 5+__pyx_t_19); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 517, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_20); + __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[6] = {__pyx_t_7, __pyx_v_diagnostic_vector_path, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_t_5}; + __pyx_t_20 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_19, 5+__pyx_t_19); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 517, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_3 = PyTuple_New(5+__pyx_t_19); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 517, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_v_diagnostic_vector_path); + __Pyx_GIVEREF(__pyx_v_diagnostic_vector_path); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_19, __pyx_v_diagnostic_vector_path); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_19, __pyx_int_0); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_3, 2+__pyx_t_19, __pyx_int_0); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_3, 3+__pyx_t_19, __pyx_int_0); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_3, 4+__pyx_t_19, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_20 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 517, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF_SET(__pyx_v_diagnostic_vector, __pyx_t_20); + __pyx_t_20 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":519 + * diagnostic_vector = gpkg_driver.Create( + * diagnostic_vector_path, 0, 0, 0, gdal.GDT_Unknown) + * diagnostic_layer = diagnostic_vector.CreateLayer( # <<<<<<<<<<<<<< + * 'seeds', flow_dir_srs, ogr.wkbPoint) + * user_geometry_layer = diagnostic_vector.CreateLayer( + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_diagnostic_vector, __pyx_n_s_CreateLayer); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 519, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/watershed.pyx":520 + * diagnostic_vector_path, 0, 0, 0, gdal.GDT_Unknown) + * diagnostic_layer = diagnostic_vector.CreateLayer( + * 'seeds', flow_dir_srs, ogr.wkbPoint) # <<<<<<<<<<<<<< + * user_geometry_layer = diagnostic_vector.CreateLayer( + * 'user_geometry', flow_dir_srs, ogr.wkbUnknown) + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_ogr); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 520, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_wkbPoint); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 520, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + __pyx_t_19 = 0; + if (CYTHON_UNPACK_METHODS && likely(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_19 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_n_u_seeds, __pyx_v_flow_dir_srs, __pyx_t_5}; + __pyx_t_20 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_19, 3+__pyx_t_19); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 519, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_20); + __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_3, __pyx_n_u_seeds, __pyx_v_flow_dir_srs, __pyx_t_5}; + __pyx_t_20 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_19, 3+__pyx_t_19); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 519, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(3+__pyx_t_19); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 519, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_INCREF(__pyx_n_u_seeds); + __Pyx_GIVEREF(__pyx_n_u_seeds); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_19, __pyx_n_u_seeds); + __Pyx_INCREF(__pyx_v_flow_dir_srs); + __Pyx_GIVEREF(__pyx_v_flow_dir_srs); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_19, __pyx_v_flow_dir_srs); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_19, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_20 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 519, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF_SET(__pyx_v_diagnostic_layer, __pyx_t_20); + __pyx_t_20 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":521 + * diagnostic_layer = diagnostic_vector.CreateLayer( + * 'seeds', flow_dir_srs, ogr.wkbPoint) + * user_geometry_layer = diagnostic_vector.CreateLayer( # <<<<<<<<<<<<<< + * 'user_geometry', flow_dir_srs, ogr.wkbUnknown) + * user_geometry_layer.StartTransaction() + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_diagnostic_vector, __pyx_n_s_CreateLayer); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 521, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pygeoprocessing/routing/watershed.pyx":522 + * 'seeds', flow_dir_srs, ogr.wkbPoint) + * user_geometry_layer = diagnostic_vector.CreateLayer( + * 'user_geometry', flow_dir_srs, ogr.wkbUnknown) # <<<<<<<<<<<<<< + * user_geometry_layer.StartTransaction() + * user_feature = ogr.Feature(user_geometry_layer.GetLayerDefn()) + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 522, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_wkbUnknown); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 522, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + __pyx_t_19 = 0; + if (CYTHON_UNPACK_METHODS && likely(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); + __pyx_t_19 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_n_u_user_geometry, __pyx_v_flow_dir_srs, __pyx_t_5}; + __pyx_t_20 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_19, 3+__pyx_t_19); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 521, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_20); + __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_7, __pyx_n_u_user_geometry, __pyx_v_flow_dir_srs, __pyx_t_5}; + __pyx_t_20 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_19, 3+__pyx_t_19); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 521, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_3 = PyTuple_New(3+__pyx_t_19); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 521, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_n_u_user_geometry); + __Pyx_GIVEREF(__pyx_n_u_user_geometry); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_19, __pyx_n_u_user_geometry); + __Pyx_INCREF(__pyx_v_flow_dir_srs); + __Pyx_GIVEREF(__pyx_v_flow_dir_srs); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_19, __pyx_v_flow_dir_srs); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_3, 2+__pyx_t_19, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_20 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 521, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_user_geometry_layer = __pyx_t_20; + __pyx_t_20 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":523 + * user_geometry_layer = diagnostic_vector.CreateLayer( + * 'user_geometry', flow_dir_srs, ogr.wkbUnknown) + * user_geometry_layer.StartTransaction() # <<<<<<<<<<<<<< + * user_feature = ogr.Feature(user_geometry_layer.GetLayerDefn()) + * user_feature.SetGeometry(ogr.CreateGeometryFromWkb(source_geom_wkb)) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_user_geometry_layer, __pyx_n_s_StartTransaction); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 523, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_20 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 523, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":524 + * 'user_geometry', flow_dir_srs, ogr.wkbUnknown) + * user_geometry_layer.StartTransaction() + * user_feature = ogr.Feature(user_geometry_layer.GetLayerDefn()) # <<<<<<<<<<<<<< + * user_feature.SetGeometry(ogr.CreateGeometryFromWkb(source_geom_wkb)) + * user_geometry_layer.CreateFeature(user_feature) + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 524, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_Feature); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 524, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_user_geometry_layer, __pyx_n_s_GetLayerDefn); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 524, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 524, __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_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_20 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 524, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_user_feature = __pyx_t_20; + __pyx_t_20 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":525 + * user_geometry_layer.StartTransaction() + * user_feature = ogr.Feature(user_geometry_layer.GetLayerDefn()) + * user_feature.SetGeometry(ogr.CreateGeometryFromWkb(source_geom_wkb)) # <<<<<<<<<<<<<< + * user_geometry_layer.CreateFeature(user_feature) + * user_geometry_layer.CommitTransaction() + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_user_feature, __pyx_n_s_SetGeometry); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 525, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_ogr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 525, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_CreateGeometryFromWkb); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 525, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __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); + } + } + __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_5, __pyx_v_source_geom_wkb) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_source_geom_wkb); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 525, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_20 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_7, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 525, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":526 + * user_feature = ogr.Feature(user_geometry_layer.GetLayerDefn()) + * user_feature.SetGeometry(ogr.CreateGeometryFromWkb(source_geom_wkb)) + * user_geometry_layer.CreateFeature(user_feature) # <<<<<<<<<<<<<< + * user_geometry_layer.CommitTransaction() + * + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_user_geometry_layer, __pyx_n_s_CreateFeature); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 526, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __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); + } + } + __pyx_t_20 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_1, __pyx_v_user_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_user_feature); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 526, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":527 + * user_feature.SetGeometry(ogr.CreateGeometryFromWkb(source_geom_wkb)) + * user_geometry_layer.CreateFeature(user_feature) + * user_geometry_layer.CommitTransaction() # <<<<<<<<<<<<<< + * + * cdef int row, col + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_user_geometry_layer, __pyx_n_s_CommitTransaction); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 527, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __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); + } + } + __pyx_t_20 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 527, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":513 + * diagnostic_vector = None + * diagnostic_layer = None + * if diagnostic_vector_path is not None: # <<<<<<<<<<<<<< + * write_diagnostic_vector = 1 + * + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":531 + * cdef int row, col + * cdef int global_row, global_col + * cdef int seed_raster_origin_col = ((local_origin_x - x_origin) // x_pixelwidth) # <<<<<<<<<<<<<< + * cdef int seed_raster_origin_row = ((local_origin_y - y_origin) // y_pixelwidth) + * cdef dict block_info + */ + __pyx_t_17 = (__pyx_v_local_origin_x - __pyx_v_x_origin); + if (unlikely(__pyx_v_x_pixelwidth == 0)) { + PyErr_SetString(PyExc_ZeroDivisionError, "float division"); + __PYX_ERR(0, 531, __pyx_L1_error) + } + __pyx_v_seed_raster_origin_col = ((int)floor(__pyx_t_17 / __pyx_v_x_pixelwidth)); + + /* "pygeoprocessing/routing/watershed.pyx":532 + * cdef int global_row, global_col + * cdef int seed_raster_origin_col = ((local_origin_x - x_origin) // x_pixelwidth) + * cdef int seed_raster_origin_row = ((local_origin_y - y_origin) // y_pixelwidth) # <<<<<<<<<<<<<< + * cdef dict block_info + * cdef int block_xoff + */ + __pyx_t_17 = (__pyx_v_local_origin_y - __pyx_v_y_origin); + if (unlikely(__pyx_v_y_pixelwidth == 0)) { + PyErr_SetString(PyExc_ZeroDivisionError, "float division"); + __PYX_ERR(0, 532, __pyx_L1_error) + } + __pyx_v_seed_raster_origin_row = ((int)floor(__pyx_t_17 / __pyx_v_y_pixelwidth)); + + /* "pygeoprocessing/routing/watershed.pyx":537 + * cdef int block_yoff + * cdef numpy.ndarray[numpy.npy_uint8, ndim=2] seed_array + * for block_info, seed_array in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * (target_raster_path, 1)): + * block_xoff = block_info['xoff'] + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 537, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 537, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":538 + * cdef numpy.ndarray[numpy.npy_uint8, ndim=2] seed_array + * for block_info, seed_array in pygeoprocessing.iterblocks( + * (target_raster_path, 1)): # <<<<<<<<<<<<<< + * block_xoff = block_info['xoff'] + * block_yoff = block_info['yoff'] + */ + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 538, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_target_raster_path); + __Pyx_GIVEREF(__pyx_v_target_raster_path); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_target_raster_path); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_1); + __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); + } + } + __pyx_t_20 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_7, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 537, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":537 + * cdef int block_yoff + * cdef numpy.ndarray[numpy.npy_uint8, ndim=2] seed_array + * for block_info, seed_array in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * (target_raster_path, 1)): + * block_xoff = block_info['xoff'] + */ + if (likely(PyList_CheckExact(__pyx_t_20)) || PyTuple_CheckExact(__pyx_t_20)) { + __pyx_t_1 = __pyx_t_20; __Pyx_INCREF(__pyx_t_1); __pyx_t_21 = 0; + __pyx_t_22 = NULL; + } else { + __pyx_t_21 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_20); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 537, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_22 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 537, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + for (;;) { + if (likely(!__pyx_t_22)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_21 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_20 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_21); __Pyx_INCREF(__pyx_t_20); __pyx_t_21++; if (unlikely(0 < 0)) __PYX_ERR(0, 537, __pyx_L1_error) + #else + __pyx_t_20 = PySequence_ITEM(__pyx_t_1, __pyx_t_21); __pyx_t_21++; if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 537, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + #endif + } else { + if (__pyx_t_21 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_20 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_21); __Pyx_INCREF(__pyx_t_20); __pyx_t_21++; if (unlikely(0 < 0)) __PYX_ERR(0, 537, __pyx_L1_error) + #else + __pyx_t_20 = PySequence_ITEM(__pyx_t_1, __pyx_t_21); __pyx_t_21++; if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 537, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + #endif + } + } else { + __pyx_t_20 = __pyx_t_22(__pyx_t_1); + if (unlikely(!__pyx_t_20)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 537, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_20); + } + if ((likely(PyTuple_CheckExact(__pyx_t_20))) || (PyList_CheckExact(__pyx_t_20))) { + PyObject* sequence = __pyx_t_20; + 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, 537, __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_7 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_3 = PyList_GET_ITEM(sequence, 0); + __pyx_t_7 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_7); + #else + __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 537, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 537, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_5 = PyObject_GetIter(__pyx_t_20); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 537, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_5)->tp_iternext; + index = 0; __pyx_t_3 = __pyx_t_8(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + index = 1; __pyx_t_7 = __pyx_t_8(__pyx_t_5); if (unlikely(!__pyx_t_7)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_5), 2) < 0) __PYX_ERR(0, 537, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L12_unpacking_done; + __pyx_L11_unpacking_failed:; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 537, __pyx_L1_error) + __pyx_L12_unpacking_done:; + } + if (!(likely(PyDict_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 537, __pyx_L1_error) + if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 537, __pyx_L1_error) + __Pyx_XDECREF_SET(__pyx_v_block_info, ((PyObject*)__pyx_t_3)); + __pyx_t_3 = 0; + __pyx_t_23 = ((PyArrayObject *)__pyx_t_7); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_seed_array.rcbuffer->pybuffer); + __pyx_t_19 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_seed_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_23, &__Pyx_TypeInfo_nn_npy_uint8, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); + if (unlikely(__pyx_t_19 < 0)) { + PyErr_Fetch(&__pyx_t_24, &__pyx_t_25, &__pyx_t_26); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_seed_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_seed_array, &__Pyx_TypeInfo_nn_npy_uint8, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_24); Py_XDECREF(__pyx_t_25); Py_XDECREF(__pyx_t_26); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_24, __pyx_t_25, __pyx_t_26); + } + __pyx_t_24 = __pyx_t_25 = __pyx_t_26 = 0; + } + __pyx_pybuffernd_seed_array.diminfo[0].strides = __pyx_pybuffernd_seed_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_seed_array.diminfo[0].shape = __pyx_pybuffernd_seed_array.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_seed_array.diminfo[1].strides = __pyx_pybuffernd_seed_array.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_seed_array.diminfo[1].shape = __pyx_pybuffernd_seed_array.rcbuffer->pybuffer.shape[1]; + if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 537, __pyx_L1_error) + } + __pyx_t_23 = 0; + __Pyx_XDECREF_SET(__pyx_v_seed_array, ((PyArrayObject *)__pyx_t_7)); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":539 + * for block_info, seed_array in pygeoprocessing.iterblocks( + * (target_raster_path, 1)): + * block_xoff = block_info['xoff'] # <<<<<<<<<<<<<< + * block_yoff = block_info['yoff'] + * n_rows = seed_array.shape[0] + */ + if (unlikely(__pyx_v_block_info == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 539, __pyx_L1_error) + } + __pyx_t_20 = __Pyx_PyDict_GetItem(__pyx_v_block_info, __pyx_n_u_xoff); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 539, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __pyx_t_19 = __Pyx_PyInt_As_int(__pyx_t_20); if (unlikely((__pyx_t_19 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 539, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + __pyx_v_block_xoff = __pyx_t_19; + + /* "pygeoprocessing/routing/watershed.pyx":540 + * (target_raster_path, 1)): + * block_xoff = block_info['xoff'] + * block_yoff = block_info['yoff'] # <<<<<<<<<<<<<< + * n_rows = seed_array.shape[0] + * n_cols = seed_array.shape[1] + */ + if (unlikely(__pyx_v_block_info == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 540, __pyx_L1_error) + } + __pyx_t_20 = __Pyx_PyDict_GetItem(__pyx_v_block_info, __pyx_n_u_yoff); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 540, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __pyx_t_19 = __Pyx_PyInt_As_int(__pyx_t_20); if (unlikely((__pyx_t_19 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 540, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + __pyx_v_block_yoff = __pyx_t_19; + + /* "pygeoprocessing/routing/watershed.pyx":541 + * block_xoff = block_info['xoff'] + * block_yoff = block_info['yoff'] + * n_rows = seed_array.shape[0] # <<<<<<<<<<<<<< + * n_cols = seed_array.shape[1] + * + */ + __pyx_v_n_rows = (__pyx_v_seed_array->dimensions[0]); + + /* "pygeoprocessing/routing/watershed.pyx":542 + * block_yoff = block_info['yoff'] + * n_rows = seed_array.shape[0] + * n_cols = seed_array.shape[1] # <<<<<<<<<<<<<< + * + * for row in range(n_rows): + */ + __pyx_v_n_cols = (__pyx_v_seed_array->dimensions[1]); + + /* "pygeoprocessing/routing/watershed.pyx":544 + * n_cols = seed_array.shape[1] + * + * for row in range(n_rows): # <<<<<<<<<<<<<< + * for col in range(n_cols): + * with cython.boundscheck(False): + */ + __pyx_t_27 = __pyx_v_n_rows; + __pyx_t_28 = __pyx_t_27; + for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_28; __pyx_t_19+=1) { + __pyx_v_row = __pyx_t_19; + + /* "pygeoprocessing/routing/watershed.pyx":545 + * + * for row in range(n_rows): + * for col in range(n_cols): # <<<<<<<<<<<<<< + * with cython.boundscheck(False): + * # Check if the pixel does not overlap the geometry. + */ + __pyx_t_29 = __pyx_v_n_cols; + __pyx_t_30 = __pyx_t_29; + for (__pyx_t_31 = 0; __pyx_t_31 < __pyx_t_30; __pyx_t_31+=1) { + __pyx_v_col = __pyx_t_31; + + /* "pygeoprocessing/routing/watershed.pyx":548 + * with cython.boundscheck(False): + * # Check if the pixel does not overlap the geometry. + * if seed_array[row, col] == 0: # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_32 = __pyx_v_row; + __pyx_t_33 = __pyx_v_col; + if (__pyx_t_32 < 0) __pyx_t_32 += __pyx_pybuffernd_seed_array.diminfo[0].shape; + if (__pyx_t_33 < 0) __pyx_t_33 += __pyx_pybuffernd_seed_array.diminfo[1].shape; + __pyx_t_14 = (((*__Pyx_BufPtrStrided2d(npy_uint8 *, __pyx_pybuffernd_seed_array.rcbuffer->pybuffer.buf, __pyx_t_32, __pyx_pybuffernd_seed_array.diminfo[0].strides, __pyx_t_33, __pyx_pybuffernd_seed_array.diminfo[1].strides)) == 0) != 0); + if (__pyx_t_14) { + + /* "pygeoprocessing/routing/watershed.pyx":549 + * # Check if the pixel does not overlap the geometry. + * if seed_array[row, col] == 0: + * continue # <<<<<<<<<<<<<< + * + * global_row = seed_raster_origin_row + block_yoff + row + */ + goto __pyx_L15_continue; + + /* "pygeoprocessing/routing/watershed.pyx":548 + * with cython.boundscheck(False): + * # Check if the pixel does not overlap the geometry. + * if seed_array[row, col] == 0: # <<<<<<<<<<<<<< + * continue + * + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":551 + * continue + * + * global_row = seed_raster_origin_row + block_yoff + row # <<<<<<<<<<<<<< + * global_col = seed_raster_origin_col + block_xoff + col + * + */ + __pyx_v_global_row = ((__pyx_v_seed_raster_origin_row + __pyx_v_block_yoff) + __pyx_v_row); + + /* "pygeoprocessing/routing/watershed.pyx":552 + * + * global_row = seed_raster_origin_row + block_yoff + row + * global_col = seed_raster_origin_col + block_xoff + col # <<<<<<<<<<<<<< + * + * if write_diagnostic_vector == 1: + */ + __pyx_v_global_col = ((__pyx_v_seed_raster_origin_col + __pyx_v_block_xoff) + __pyx_v_col); + + /* "pygeoprocessing/routing/watershed.pyx":554 + * global_col = seed_raster_origin_col + block_xoff + col + * + * if write_diagnostic_vector == 1: # <<<<<<<<<<<<<< + * diagnostic_layer.StartTransaction() + * new_feature = ogr.Feature(diagnostic_layer.GetLayerDefn()) + */ + __pyx_t_14 = ((__pyx_v_write_diagnostic_vector == 1) != 0); + if (__pyx_t_14) { + + /* "pygeoprocessing/routing/watershed.pyx":555 + * + * if write_diagnostic_vector == 1: + * diagnostic_layer.StartTransaction() # <<<<<<<<<<<<<< + * new_feature = ogr.Feature(diagnostic_layer.GetLayerDefn()) + * new_feature.SetGeometry(ogr.CreateGeometryFromWkb( + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_diagnostic_layer, __pyx_n_s_StartTransaction); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 555, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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); + } + } + __pyx_t_20 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 555, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":556 + * if write_diagnostic_vector == 1: + * diagnostic_layer.StartTransaction() + * new_feature = ogr.Feature(diagnostic_layer.GetLayerDefn()) # <<<<<<<<<<<<<< + * new_feature.SetGeometry(ogr.CreateGeometryFromWkb( + * shapely.geometry.Point( + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 556, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_Feature); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 556, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_diagnostic_layer, __pyx_n_s_GetLayerDefn); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 556, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __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); + } + } + __pyx_t_7 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 556, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + 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_20 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_7); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 556, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF_SET(__pyx_v_new_feature, __pyx_t_20); + __pyx_t_20 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":557 + * diagnostic_layer.StartTransaction() + * new_feature = ogr.Feature(diagnostic_layer.GetLayerDefn()) + * new_feature.SetGeometry(ogr.CreateGeometryFromWkb( # <<<<<<<<<<<<<< + * shapely.geometry.Point( + * x_origin + ((global_col*x_pixelwidth) + + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_new_feature, __pyx_n_s_SetGeometry); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 557, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_ogr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 557, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_CreateGeometryFromWkb); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 557, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":558 + * new_feature = ogr.Feature(diagnostic_layer.GetLayerDefn()) + * new_feature.SetGeometry(ogr.CreateGeometryFromWkb( + * shapely.geometry.Point( # <<<<<<<<<<<<<< + * x_origin + ((global_col*x_pixelwidth) + + * (x_pixelwidth / 2.)), + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_shapely); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 558, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_34 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_geometry); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 558, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_34); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_34, __pyx_n_s_Point); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 558, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_34); __pyx_t_34 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":559 + * new_feature.SetGeometry(ogr.CreateGeometryFromWkb( + * shapely.geometry.Point( + * x_origin + ((global_col*x_pixelwidth) + # <<<<<<<<<<<<<< + * (x_pixelwidth / 2.)), + * y_origin + ((global_row*y_pixelwidth) + + */ + __pyx_t_34 = PyFloat_FromDouble((__pyx_v_x_origin + ((__pyx_v_global_col * __pyx_v_x_pixelwidth) + (__pyx_v_x_pixelwidth / 2.)))); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 559, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_34); + + /* "pygeoprocessing/routing/watershed.pyx":561 + * x_origin + ((global_col*x_pixelwidth) + + * (x_pixelwidth / 2.)), + * y_origin + ((global_row*y_pixelwidth) + # <<<<<<<<<<<<<< + * (y_pixelwidth / 2.))).wkb)) + * diagnostic_layer.CreateFeature(new_feature) + */ + __pyx_t_35 = PyFloat_FromDouble((__pyx_v_y_origin + ((__pyx_v_global_row * __pyx_v_y_pixelwidth) + (__pyx_v_y_pixelwidth / 2.)))); if (unlikely(!__pyx_t_35)) __PYX_ERR(0, 561, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_35); + __pyx_t_36 = NULL; + __pyx_t_37 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_36 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_36)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_36); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_37 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_36, __pyx_t_34, __pyx_t_35}; + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_37, 2+__pyx_t_37); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 558, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_36); __pyx_t_36 = 0; + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_34); __pyx_t_34 = 0; + __Pyx_DECREF(__pyx_t_35); __pyx_t_35 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_36, __pyx_t_34, __pyx_t_35}; + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_37, 2+__pyx_t_37); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 558, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_36); __pyx_t_36 = 0; + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_34); __pyx_t_34 = 0; + __Pyx_DECREF(__pyx_t_35); __pyx_t_35 = 0; + } else + #endif + { + __pyx_t_38 = PyTuple_New(2+__pyx_t_37); if (unlikely(!__pyx_t_38)) __PYX_ERR(0, 558, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_38); + if (__pyx_t_36) { + __Pyx_GIVEREF(__pyx_t_36); PyTuple_SET_ITEM(__pyx_t_38, 0, __pyx_t_36); __pyx_t_36 = NULL; + } + __Pyx_GIVEREF(__pyx_t_34); + PyTuple_SET_ITEM(__pyx_t_38, 0+__pyx_t_37, __pyx_t_34); + __Pyx_GIVEREF(__pyx_t_35); + PyTuple_SET_ITEM(__pyx_t_38, 1+__pyx_t_37, __pyx_t_35); + __pyx_t_34 = 0; + __pyx_t_35 = 0; + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_38, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 558, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_38); __pyx_t_38 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":562 + * (x_pixelwidth / 2.)), + * y_origin + ((global_row*y_pixelwidth) + + * (y_pixelwidth / 2.))).wkb)) # <<<<<<<<<<<<<< + * diagnostic_layer.CreateFeature(new_feature) + * diagnostic_layer.CommitTransaction() + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_wkb); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + __pyx_t_7 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 557, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_20 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_7); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 557, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":563 + * y_origin + ((global_row*y_pixelwidth) + + * (y_pixelwidth / 2.))).wkb)) + * diagnostic_layer.CreateFeature(new_feature) # <<<<<<<<<<<<<< + * diagnostic_layer.CommitTransaction() + * + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_diagnostic_layer, __pyx_n_s_CreateFeature); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 563, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_20 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_7, __pyx_v_new_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_new_feature); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 563, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":564 + * (y_pixelwidth / 2.))).wkb)) + * diagnostic_layer.CreateFeature(new_feature) + * diagnostic_layer.CommitTransaction() # <<<<<<<<<<<<<< + * + * seed_set.insert(CoordinatePair(global_col, global_row)) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_diagnostic_layer, __pyx_n_s_CommitTransaction); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 564, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_20 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 564, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":554 + * global_col = seed_raster_origin_col + block_xoff + col + * + * if write_diagnostic_vector == 1: # <<<<<<<<<<<<<< + * diagnostic_layer.StartTransaction() + * new_feature = ogr.Feature(diagnostic_layer.GetLayerDefn()) + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":566 + * diagnostic_layer.CommitTransaction() + * + * seed_set.insert(CoordinatePair(global_col, global_row)) # <<<<<<<<<<<<<< + * + * return seed_set + */ + try { + __pyx_t_15 = __pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair(__pyx_v_global_col, __pyx_v_global_row); + } catch(...) { + __Pyx_CppExn2PyErr(); + __PYX_ERR(0, 566, __pyx_L1_error) + } + try { + __pyx_v_seed_set.insert(__pyx_t_15); + } catch(...) { + __Pyx_CppExn2PyErr(); + __PYX_ERR(0, 566, __pyx_L1_error) + } + __pyx_L15_continue:; + } + } + + /* "pygeoprocessing/routing/watershed.pyx":537 + * cdef int block_yoff + * cdef numpy.ndarray[numpy.npy_uint8, ndim=2] seed_array + * for block_info, seed_array in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< + * (target_raster_path, 1)): + * block_xoff = block_info['xoff'] + */ + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":568 + * seed_set.insert(CoordinatePair(global_col, global_row)) + * + * return seed_set # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_seed_set; + goto __pyx_L0; + + /* "pygeoprocessing/routing/watershed.pyx":402 + * + * + * cdef cset[CoordinatePair] _c_split_geometry_into_seeds( # <<<<<<<<<<<<<< + * source_geom_wkb, tuple flow_dir_geotransform, flow_dir_srs, + * flow_dir_n_cols, flow_dir_n_rows, + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __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_20); + __Pyx_XDECREF(__pyx_t_34); + __Pyx_XDECREF(__pyx_t_35); + __Pyx_XDECREF(__pyx_t_36); + __Pyx_XDECREF(__pyx_t_38); + { 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_seed_array.rcbuffer->pybuffer); + __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} + __Pyx_WriteUnraisable("pygeoprocessing.routing.watershed._c_split_geometry_into_seeds", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __Pyx_pretend_to_initialize(&__pyx_r); + goto __pyx_L2; + __pyx_L0:; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_seed_array.rcbuffer->pybuffer); + __pyx_L2:; + __Pyx_XDECREF(__pyx_v_geometry); + __Pyx_XDECREF(__pyx_v_seed); + __Pyx_XDECREF(__pyx_v_memory_driver); + __Pyx_XDECREF(__pyx_v_new_vector); + __Pyx_XDECREF(__pyx_v_new_layer); + __Pyx_XDECREF(__pyx_v_new_feature); + __Pyx_XDECREF(__pyx_v_local_geotransform); + __Pyx_XDECREF(__pyx_v_gtiff_driver); + __Pyx_XDECREF(__pyx_v_raster); + __Pyx_XDECREF(__pyx_v_diagnostic_vector); + __Pyx_XDECREF(__pyx_v_diagnostic_layer); + __Pyx_XDECREF(__pyx_v_gpkg_driver); + __Pyx_XDECREF(__pyx_v_user_geometry_layer); + __Pyx_XDECREF(__pyx_v_user_feature); + __Pyx_XDECREF(__pyx_v_block_info); + __Pyx_XDECREF((PyObject *)__pyx_v_seed_array); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pygeoprocessing/routing/watershed.pyx":571 + * + * + * def _split_geometry_into_seeds( # <<<<<<<<<<<<<< + * source_geom_wkb, geotransform, flow_dir_srs, + * flow_dir_n_cols, flow_dir_n_rows, target_raster_path, + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15pygeoprocessing_7routing_9watershed_3_split_geometry_into_seeds(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_15pygeoprocessing_7routing_9watershed_2_split_geometry_into_seeds[] = "Split a geometry into 'seeds' of (x, y) coordinate pairs.\n\n This function is a python wrapper around ``_c_split_geometry_into_seeds``\n that is useful for testing.\n\n Parameters:\n source_geom_wkb (str): A string of bytes in WKB representing\n a geometry. Must be in the same projected coordinate system\n as the flow direction raster from which\n ``flow_dir_geotransform`` and ``flow_dir_srs`` are derived.\n flow_dir_geotransform (list): A 6-element array representing\n the GDAL affine geotransform from the flow direction raster.\n flow_dir_srs (osr.SpatialReference): The OSR SpatialReference\n object from the flow direction raster.\n flow_dir_n_cols (int): the number of columns in the flow\n direction raster.\n flow_dir_n_rows (int): the number of rows in the flow\n direction raster.\n target_raster_path (str): The path to a raster onto which\n the geometry might be rasterized. If the geometry is small\n enough to be completely contained within a single pixel, no\n raster will be written to this location.\n diagnostic_vector_path (string or None): If a string, a GeoPackage\n vector will be written to this path containing georeferenced\n points representing the 'seeds' determined by this function.\n If ``None``, no vector is created.\n\n Returns:\n A python ``set`` of (x-index, y-index) tuples.\n\n "; +static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_9watershed_3_split_geometry_into_seeds = {"_split_geometry_into_seeds", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_7routing_9watershed_3_split_geometry_into_seeds, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_7routing_9watershed_2_split_geometry_into_seeds}; +static PyObject *__pyx_pw_15pygeoprocessing_7routing_9watershed_3_split_geometry_into_seeds(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_source_geom_wkb = 0; + PyObject *__pyx_v_geotransform = 0; + PyObject *__pyx_v_flow_dir_srs = 0; + PyObject *__pyx_v_flow_dir_n_cols = 0; + PyObject *__pyx_v_flow_dir_n_rows = 0; + PyObject *__pyx_v_target_raster_path = 0; + PyObject *__pyx_v_diagnostic_vector_path = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_split_geometry_into_seeds (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_source_geom_wkb,&__pyx_n_s_geotransform,&__pyx_n_s_flow_dir_srs,&__pyx_n_s_flow_dir_n_cols,&__pyx_n_s_flow_dir_n_rows,&__pyx_n_s_target_raster_path,&__pyx_n_s_diagnostic_vector_path,0}; + PyObject* values[7] = {0,0,0,0,0,0,0}; + + /* "pygeoprocessing/routing/watershed.pyx":574 + * source_geom_wkb, geotransform, flow_dir_srs, + * flow_dir_n_cols, flow_dir_n_rows, target_raster_path, + * diagnostic_vector_path=None): # <<<<<<<<<<<<<< + * """Split a geometry into 'seeds' of (x, y) coordinate pairs. + * + */ + values[6] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + CYTHON_FALLTHROUGH; + 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_source_geom_wkb)) != 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_geotransform)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_split_geometry_into_seeds", 0, 6, 7, 1); __PYX_ERR(0, 571, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_flow_dir_srs)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_split_geometry_into_seeds", 0, 6, 7, 2); __PYX_ERR(0, 571, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 3: + if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_flow_dir_n_cols)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_split_geometry_into_seeds", 0, 6, 7, 3); __PYX_ERR(0, 571, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 4: + if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_flow_dir_n_rows)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_split_geometry_into_seeds", 0, 6, 7, 4); __PYX_ERR(0, 571, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 5: + if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_raster_path)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_split_geometry_into_seeds", 0, 6, 7, 5); __PYX_ERR(0, 571, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 6: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_diagnostic_vector_path); + if (value) { values[6] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_split_geometry_into_seeds") < 0)) __PYX_ERR(0, 571, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + CYTHON_FALLTHROUGH; + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + values[4] = PyTuple_GET_ITEM(__pyx_args, 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_source_geom_wkb = values[0]; + __pyx_v_geotransform = values[1]; + __pyx_v_flow_dir_srs = values[2]; + __pyx_v_flow_dir_n_cols = values[3]; + __pyx_v_flow_dir_n_rows = values[4]; + __pyx_v_target_raster_path = values[5]; + __pyx_v_diagnostic_vector_path = values[6]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("_split_geometry_into_seeds", 0, 6, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 571, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pygeoprocessing.routing.watershed._split_geometry_into_seeds", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_15pygeoprocessing_7routing_9watershed_2_split_geometry_into_seeds(__pyx_self, __pyx_v_source_geom_wkb, __pyx_v_geotransform, __pyx_v_flow_dir_srs, __pyx_v_flow_dir_n_cols, __pyx_v_flow_dir_n_rows, __pyx_v_target_raster_path, __pyx_v_diagnostic_vector_path); + + /* "pygeoprocessing/routing/watershed.pyx":571 + * + * + * def _split_geometry_into_seeds( # <<<<<<<<<<<<<< + * source_geom_wkb, geotransform, flow_dir_srs, + * flow_dir_n_cols, flow_dir_n_rows, target_raster_path, + */ + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15pygeoprocessing_7routing_9watershed_2_split_geometry_into_seeds(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_source_geom_wkb, PyObject *__pyx_v_geotransform, PyObject *__pyx_v_flow_dir_srs, PyObject *__pyx_v_flow_dir_n_cols, PyObject *__pyx_v_flow_dir_n_rows, PyObject *__pyx_v_target_raster_path, PyObject *__pyx_v_diagnostic_vector_path) { + PyObject *__pyx_v_return_set = NULL; + std::set<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> __pyx_v_seeds; + __pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair __pyx_v_seed; + std::set<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> ::iterator __pyx_v_seeds_iterator; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + std::set<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> __pyx_t_2; + struct __pyx_opt_args_15pygeoprocessing_7routing_9watershed__c_split_geometry_into_seeds __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_split_geometry_into_seeds", 0); + + /* "pygeoprocessing/routing/watershed.pyx":607 + * """ + * + * return_set = set() # <<<<<<<<<<<<<< + * cdef cset[CoordinatePair] seeds = _c_split_geometry_into_seeds( + * source_geom_wkb, geotransform, flow_dir_srs, flow_dir_n_cols, + */ + __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 607, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_return_set = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":609 + * return_set = set() + * cdef cset[CoordinatePair] seeds = _c_split_geometry_into_seeds( + * source_geom_wkb, geotransform, flow_dir_srs, flow_dir_n_cols, # <<<<<<<<<<<<<< + * flow_dir_n_rows, target_raster_path, diagnostic_vector_path) + * + */ + if (!(likely(PyTuple_CheckExact(__pyx_v_geotransform))||((__pyx_v_geotransform) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v_geotransform)->tp_name), 0))) __PYX_ERR(0, 609, __pyx_L1_error) + + /* "pygeoprocessing/routing/watershed.pyx":608 + * + * return_set = set() + * cdef cset[CoordinatePair] seeds = _c_split_geometry_into_seeds( # <<<<<<<<<<<<<< + * source_geom_wkb, geotransform, flow_dir_srs, flow_dir_n_cols, + * flow_dir_n_rows, target_raster_path, diagnostic_vector_path) + */ + __pyx_t_3.__pyx_n = 1; + __pyx_t_3.diagnostic_vector_path = __pyx_v_diagnostic_vector_path; + __pyx_t_2 = __pyx_f_15pygeoprocessing_7routing_9watershed__c_split_geometry_into_seeds(__pyx_v_source_geom_wkb, ((PyObject*)__pyx_v_geotransform), __pyx_v_flow_dir_srs, __pyx_v_flow_dir_n_cols, __pyx_v_flow_dir_n_rows, __pyx_v_target_raster_path, &__pyx_t_3); + __pyx_v_seeds = __pyx_t_2; + + /* "pygeoprocessing/routing/watershed.pyx":613 + * + * cdef CoordinatePair seed + * cdef cset[CoordinatePair].iterator seeds_iterator = seeds.begin() # <<<<<<<<<<<<<< + * while seeds_iterator != seeds.end(): + * seed = deref(seeds_iterator) + */ + __pyx_v_seeds_iterator = __pyx_v_seeds.begin(); + + /* "pygeoprocessing/routing/watershed.pyx":614 + * cdef CoordinatePair seed + * cdef cset[CoordinatePair].iterator seeds_iterator = seeds.begin() + * while seeds_iterator != seeds.end(): # <<<<<<<<<<<<<< + * seed = deref(seeds_iterator) + * inc(seeds_iterator) + */ + while (1) { + __pyx_t_4 = ((__pyx_v_seeds_iterator != __pyx_v_seeds.end()) != 0); + if (!__pyx_t_4) break; + + /* "pygeoprocessing/routing/watershed.pyx":615 + * cdef cset[CoordinatePair].iterator seeds_iterator = seeds.begin() + * while seeds_iterator != seeds.end(): + * seed = deref(seeds_iterator) # <<<<<<<<<<<<<< + * inc(seeds_iterator) + * + */ + __pyx_v_seed = (*__pyx_v_seeds_iterator); + + /* "pygeoprocessing/routing/watershed.pyx":616 + * while seeds_iterator != seeds.end(): + * seed = deref(seeds_iterator) + * inc(seeds_iterator) # <<<<<<<<<<<<<< + * + * return_set.add((seed.first, seed.second)) + */ + (void)((++__pyx_v_seeds_iterator)); + + /* "pygeoprocessing/routing/watershed.pyx":618 + * inc(seeds_iterator) + * + * return_set.add((seed.first, seed.second)) # <<<<<<<<<<<<<< + * + * return return_set + */ + __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_seed.first); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 618, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyInt_From_long(__pyx_v_seed.second); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 618, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 618, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); + __pyx_t_1 = 0; + __pyx_t_5 = 0; + __pyx_t_7 = PySet_Add(__pyx_v_return_set, __pyx_t_6); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 618, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + + /* "pygeoprocessing/routing/watershed.pyx":620 + * return_set.add((seed.first, seed.second)) + * + * return return_set # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_return_set); + __pyx_r = __pyx_v_return_set; + goto __pyx_L0; + + /* "pygeoprocessing/routing/watershed.pyx":571 + * + * + * def _split_geometry_into_seeds( # <<<<<<<<<<<<<< + * source_geom_wkb, geotransform, flow_dir_srs, + * flow_dir_n_cols, flow_dir_n_rows, target_raster_path, + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("pygeoprocessing.routing.watershed._split_geometry_into_seeds", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_return_set); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pygeoprocessing/routing/watershed.pyx":624 + * + * @cython.boundscheck(False) + * def delineate_watersheds_d8( # <<<<<<<<<<<<<< + * d8_flow_dir_raster_path_band, outflow_vector_path, + * target_watersheds_vector_path, working_dir=None, + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15pygeoprocessing_7routing_9watershed_5delineate_watersheds_d8(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_15pygeoprocessing_7routing_9watershed_4delineate_watersheds_d8[] = "Delineate watersheds for a vector of geometries using D8 flow dir.\n\n Args:\n d8_flow_dir_raster_path_band (tuple): A (path, band_id) tuple\n to a D8 flow direction raster. This raster must be a tiled raster\n with block sizes being a power of 2.\n outflow_vector_path (str): The path to a vector on disk containing\n features with valid geometries from which watersheds will be\n delineated. Only those parts of the geometry that overlap valid\n flow direction pixels will be included in the output watersheds\n vector.\n target_watersheds_vector_path (str): The path to a vector on disk\n where the target watersheds will be stored. Must have the\n extension ``.gpkg``.\n working_dir=None (str or None): The path to a directory on disk\n within which various intermediate files will be stored. If None,\n a folder will be created within the system's temp directory.\n write_diagnostic_vector=False (bool): If ``True``, a set of vectors will\n be written to ``working_dir``, one per watershed. Each vector\n includes geometries for the watershed being represented and\n for the watershed seed pixels the geometry overlaps. Useful in\n debugging issues with feature overlap of the DEM. Setting this\n parameter to ``True`` will dramatically increase runtime when\n outflow geometries cover many pixels.\n remove_temp_files=True (bool): Whether to remove the created temp\n directory at the end of the watershed delineation run.\n target_layer_name='watersheds' (str): The string name to use for\n the watersheds layer. This layer name may be named anything\n except for \"polygonized_watersheds\".\n\n Returns:\n ``None``\n\n "; +static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_9watershed_5delineate_watersheds_d8 = {"delineate_watersheds_d8", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_7routing_9watershed_5delineate_watersheds_d8, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_7routing_9watershed_4delineate_watersheds_d8}; +static PyObject *__pyx_pw_15pygeoprocessing_7routing_9watershed_5delineate_watersheds_d8(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_d8_flow_dir_raster_path_band = 0; + PyObject *__pyx_v_outflow_vector_path = 0; + PyObject *__pyx_v_target_watersheds_vector_path = 0; + PyObject *__pyx_v_working_dir = 0; + PyObject *__pyx_v_write_diagnostic_vector = 0; + PyObject *__pyx_v_remove_temp_files = 0; + PyObject *__pyx_v_target_layer_name = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("delineate_watersheds_d8 (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_d8_flow_dir_raster_path_band,&__pyx_n_s_outflow_vector_path,&__pyx_n_s_target_watersheds_vector_path,&__pyx_n_s_working_dir,&__pyx_n_s_write_diagnostic_vector,&__pyx_n_s_remove_temp_files,&__pyx_n_s_target_layer_name,0}; + PyObject* values[7] = {0,0,0,0,0,0,0}; + + /* "pygeoprocessing/routing/watershed.pyx":626 + * def delineate_watersheds_d8( + * d8_flow_dir_raster_path_band, outflow_vector_path, + * target_watersheds_vector_path, working_dir=None, # <<<<<<<<<<<<<< + * write_diagnostic_vector=False, remove_temp_files=True, + * target_layer_name='watersheds'): + */ + values[3] = ((PyObject *)Py_None); + + /* "pygeoprocessing/routing/watershed.pyx":627 + * d8_flow_dir_raster_path_band, outflow_vector_path, + * target_watersheds_vector_path, working_dir=None, + * write_diagnostic_vector=False, remove_temp_files=True, # <<<<<<<<<<<<<< + * target_layer_name='watersheds'): + * """Delineate watersheds for a vector of geometries using D8 flow dir. + */ + values[4] = ((PyObject *)Py_False); + values[5] = ((PyObject *)Py_True); + values[6] = ((PyObject *)__pyx_n_u_watersheds); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + CYTHON_FALLTHROUGH; + 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_d8_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_outflow_vector_path)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("delineate_watersheds_d8", 0, 3, 7, 1); __PYX_ERR(0, 624, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_watersheds_vector_path)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("delineate_watersheds_d8", 0, 3, 7, 2); __PYX_ERR(0, 624, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 3: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_working_dir); + 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_write_diagnostic_vector); + 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_remove_temp_files); + if (value) { values[5] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 6: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_layer_name); + if (value) { values[6] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "delineate_watersheds_d8") < 0)) __PYX_ERR(0, 624, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + CYTHON_FALLTHROUGH; + 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); + 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_d8_flow_dir_raster_path_band = values[0]; + __pyx_v_outflow_vector_path = values[1]; + __pyx_v_target_watersheds_vector_path = values[2]; + __pyx_v_working_dir = values[3]; + __pyx_v_write_diagnostic_vector = values[4]; + __pyx_v_remove_temp_files = values[5]; + __pyx_v_target_layer_name = values[6]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("delineate_watersheds_d8", 0, 3, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 624, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pygeoprocessing.routing.watershed.delineate_watersheds_d8", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_15pygeoprocessing_7routing_9watershed_4delineate_watersheds_d8(__pyx_self, __pyx_v_d8_flow_dir_raster_path_band, __pyx_v_outflow_vector_path, __pyx_v_target_watersheds_vector_path, __pyx_v_working_dir, __pyx_v_write_diagnostic_vector, __pyx_v_remove_temp_files, __pyx_v_target_layer_name); + + /* "pygeoprocessing/routing/watershed.pyx":624 + * + * @cython.boundscheck(False) + * def delineate_watersheds_d8( # <<<<<<<<<<<<<< + * d8_flow_dir_raster_path_band, outflow_vector_path, + * target_watersheds_vector_path, working_dir=None, + */ + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15pygeoprocessing_7routing_9watershed_4delineate_watersheds_d8(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_d8_flow_dir_raster_path_band, PyObject *__pyx_v_outflow_vector_path, PyObject *__pyx_v_target_watersheds_vector_path, PyObject *__pyx_v_working_dir, PyObject *__pyx_v_write_diagnostic_vector, PyObject *__pyx_v_remove_temp_files, PyObject *__pyx_v_target_layer_name) { + PyObject *__pyx_v_working_dir_path = NULL; + PyObject *__pyx_v_flow_dir_info = NULL; + int __pyx_v_flow_dir_nodata; + PyObject *__pyx_v_source_gt = NULL; + double __pyx_v_flow_dir_origin_x; + double __pyx_v_flow_dir_origin_y; + double __pyx_v_flow_dir_pixelsize_x; + double __pyx_v_flow_dir_pixelsize_y; + int __pyx_v_flow_dir_n_cols; + int __pyx_v_flow_dir_n_rows; + int __pyx_v_ws_id; + PyObject *__pyx_v_bbox_minx = NULL; + PyObject *__pyx_v_bbox_miny = NULL; + PyObject *__pyx_v_bbox_maxx = NULL; + PyObject *__pyx_v_bbox_maxy = NULL; + PyObject *__pyx_v_flow_dir_bbox = NULL; + struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_flow_dir_managed_raster = NULL; + PyObject *__pyx_v_gtiff_driver = NULL; + PyObject *__pyx_v_flow_dir_srs = NULL; + PyObject *__pyx_v_outflow_vector = NULL; + PyObject *__pyx_v_driver = NULL; + PyObject *__pyx_v_watersheds_srs = NULL; + PyObject *__pyx_v_watersheds_vector = NULL; + PyObject *__pyx_v_polygonized_watersheds_layer = NULL; + PyObject *__pyx_v_watersheds_layer = NULL; + PyObject *__pyx_v_index_field = NULL; + int *__pyx_v_reverse_flow; + int *__pyx_v_neighbor_col; + int *__pyx_v_neighbor_row; + std::queue<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> __pyx_v_process_queue; + std::set<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> __pyx_v_process_queue_set; + __pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair __pyx_v_neighbor_pixel; + int __pyx_v_ix_min; + int __pyx_v_iy_min; + int __pyx_v_ix_max; + int __pyx_v_iy_max; + struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_scratch_managed_raster = 0; + int __pyx_v_watersheds_created; + int __pyx_v_current_fid; + int __pyx_v_outflow_feature_count; + std::set<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> ::iterator __pyx_v_seed_iterator; + std::set<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> __pyx_v_seeds_in_watershed; + time_t __pyx_v_last_log_time; + int __pyx_v_n_cells_visited; + PyObject *__pyx_v_outflow_layer = NULL; + PyObject *__pyx_v_feature = NULL; + PyObject *__pyx_v_geom = NULL; + PyObject *__pyx_v_geom_wkb = NULL; + PyObject *__pyx_v_shapely_geom = NULL; + PyObject *__pyx_v_seeds_raster_path = NULL; + PyObject *__pyx_v_diagnostic_vector_path = NULL; + __pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair __pyx_v_seed; + PyObject *__pyx_v_scratch_raster_path = NULL; + PyObject *__pyx_v_scratch_raster = NULL; + __pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair __pyx_v_current_pixel; + long __pyx_v_neighbor_index; + double __pyx_v_x1; + double __pyx_v_y1; + double __pyx_v_x2; + double __pyx_v_y2; + PyObject *__pyx_v_vrt_options = NULL; + PyObject *__pyx_v_vrt_path = NULL; + PyObject *__pyx_v_vrt_raster = NULL; + PyObject *__pyx_v_vrt_band = NULL; + CYTHON_UNUSED PyObject *__pyx_v__ = NULL; + std::map > __pyx_v_fragments_with_duplicates; + int __pyx_v_fid; + PyObject *__pyx_v_source_vector = NULL; + PyObject *__pyx_v_source_layer = NULL; + int __pyx_v_duplicate_fid; + std::set __pyx_v_duplicate_ids_set; + std::set ::iterator __pyx_v_duplicate_ids_set_iterator; + std::map > ::iterator __pyx_v_fragments_with_duplicates_iterator; + PyObject *__pyx_v_source_feature = NULL; + PyObject *__pyx_v_new_geometry = NULL; + PyObject *__pyx_v_duplicate_feature = NULL; + PyObject *__pyx_v_duplicate_geometry = NULL; + PyObject *__pyx_v_watershed_feature = NULL; + PyObject *__pyx_v_field_name = NULL; + PyObject *__pyx_v_field_value = 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; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + int __pyx_t_14; + double __pyx_t_15; + PyObject *(*__pyx_t_16)(PyObject *); + PyObject *__pyx_t_17 = NULL; + PyObject *__pyx_t_18 = NULL; + PyObject *__pyx_t_19 = NULL; + int __pyx_t_20[8]; + int __pyx_t_21[8]; + int __pyx_t_22[8]; + Py_ssize_t __pyx_t_23; + PyObject *(*__pyx_t_24)(PyObject *); + std::set<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> __pyx_t_25; + struct __pyx_opt_args_15pygeoprocessing_7routing_9watershed__c_split_geometry_into_seeds __pyx_t_26; + long __pyx_t_27; + long __pyx_t_28; + __pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair __pyx_t_29; + long __pyx_t_30; + double __pyx_t_31; + double __pyx_t_32; + std::set __pyx_t_33; + Py_ssize_t __pyx_t_34; + int __pyx_t_35; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("delineate_watersheds_d8", 0); + + /* "pygeoprocessing/routing/watershed.pyx":663 + * + * """ + * try: # <<<<<<<<<<<<<< + * if working_dir is not None: + * os.makedirs(working_dir) + */ + { + __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:*/ { + + /* "pygeoprocessing/routing/watershed.pyx":664 + * """ + * try: + * if working_dir is not None: # <<<<<<<<<<<<<< + * os.makedirs(working_dir) + * except OSError: + */ + __pyx_t_4 = (__pyx_v_working_dir != Py_None); + __pyx_t_5 = (__pyx_t_4 != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/watershed.pyx":665 + * try: + * if working_dir is not None: + * os.makedirs(working_dir) # <<<<<<<<<<<<<< + * except OSError: + * pass + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_os); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 665, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_makedirs); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 665, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __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); + } + } + __pyx_t_6 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_7, __pyx_v_working_dir) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_working_dir); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 665, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":664 + * """ + * try: + * if working_dir is not None: # <<<<<<<<<<<<<< + * os.makedirs(working_dir) + * except OSError: + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":663 + * + * """ + * try: # <<<<<<<<<<<<<< + * if working_dir is not None: + * os.makedirs(working_dir) + */ + } + __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:; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":666 + * if working_dir is not None: + * os.makedirs(working_dir) + * except OSError: # <<<<<<<<<<<<<< + * pass + * working_dir_path = tempfile.mkdtemp( + */ + __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OSError); + if (__pyx_t_9) { + __Pyx_ErrRestore(0,0,0); + goto __pyx_L4_exception_handled; + } + goto __pyx_L5_except_error; + __pyx_L5_except_error:; + + /* "pygeoprocessing/routing/watershed.pyx":663 + * + * """ + * try: # <<<<<<<<<<<<<< + * if working_dir is not None: + * os.makedirs(working_dir) + */ + __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_L4_exception_handled:; + __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); + __pyx_L8_try_end:; + } + + /* "pygeoprocessing/routing/watershed.pyx":668 + * except OSError: + * pass + * working_dir_path = tempfile.mkdtemp( # <<<<<<<<<<<<<< + * dir=working_dir, prefix='watershed_delineation_trivial_%s_' % time.strftime( + * '%Y-%m-%d_%H_%M_%S', time.gmtime())) + */ + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_tempfile); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 668, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_mkdtemp); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 668, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":669 + * pass + * working_dir_path = tempfile.mkdtemp( + * dir=working_dir, prefix='watershed_delineation_trivial_%s_' % time.strftime( # <<<<<<<<<<<<<< + * '%Y-%m-%d_%H_%M_%S', time.gmtime())) + * + */ + __pyx_t_6 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 669, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dir, __pyx_v_working_dir) < 0) __PYX_ERR(0, 669, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_time); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 669, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_strftime); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 669, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":670 + * working_dir_path = tempfile.mkdtemp( + * dir=working_dir, prefix='watershed_delineation_trivial_%s_' % time.strftime( + * '%Y-%m-%d_%H_%M_%S', time.gmtime())) # <<<<<<<<<<<<<< + * + * if (d8_flow_dir_raster_path_band is not None and not + */ + __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_time); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 670, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_gmtime); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 670, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_13))) { + __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_13); + if (likely(__pyx_t_12)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_13, function); + } + } + __pyx_t_10 = (__pyx_t_12) ? __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_12) : __Pyx_PyObject_CallNoArg(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 670, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_13 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_kp_u_Y_m_d__H__M__S, __pyx_t_10}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 669, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_kp_u_Y_m_d__H__M__S, __pyx_t_10}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 669, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } else + #endif + { + __pyx_t_12 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 669, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + if (__pyx_t_13) { + __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_13); __pyx_t_13 = NULL; + } + __Pyx_INCREF(__pyx_kp_u_Y_m_d__H__M__S); + __Pyx_GIVEREF(__pyx_kp_u_Y_m_d__H__M__S); + PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_9, __pyx_kp_u_Y_m_d__H__M__S); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_9, __pyx_t_10); + __pyx_t_10 = 0; + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_12, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 669, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":669 + * pass + * working_dir_path = tempfile.mkdtemp( + * dir=working_dir, prefix='watershed_delineation_trivial_%s_' % time.strftime( # <<<<<<<<<<<<<< + * '%Y-%m-%d_%H_%M_%S', time.gmtime())) + * + */ + __pyx_t_11 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_watershed_delineation_trivial__s, __pyx_t_7); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 669, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_prefix, __pyx_t_11) < 0) __PYX_ERR(0, 669, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":668 + * except OSError: + * pass + * working_dir_path = tempfile.mkdtemp( # <<<<<<<<<<<<<< + * dir=working_dir, prefix='watershed_delineation_trivial_%s_' % time.strftime( + * '%Y-%m-%d_%H_%M_%S', time.gmtime())) + */ + __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_empty_tuple, __pyx_t_6); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 668, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_working_dir_path = __pyx_t_11; + __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":672 + * '%Y-%m-%d_%H_%M_%S', time.gmtime())) + * + * if (d8_flow_dir_raster_path_band is not None and not # <<<<<<<<<<<<<< + * _is_raster_path_band_formatted(d8_flow_dir_raster_path_band)): + * raise ValueError( + */ + __pyx_t_4 = (__pyx_v_d8_flow_dir_raster_path_band != Py_None); + __pyx_t_14 = (__pyx_t_4 != 0); + if (__pyx_t_14) { + } else { + __pyx_t_5 = __pyx_t_14; + goto __pyx_L11_bool_binop_done; + } + + /* "pygeoprocessing/routing/watershed.pyx":673 + * + * if (d8_flow_dir_raster_path_band is not None and not + * _is_raster_path_band_formatted(d8_flow_dir_raster_path_band)): # <<<<<<<<<<<<<< + * raise ValueError( + * "%s is supposed to be a raster band tuple but it's not." % ( + */ + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_is_raster_path_band_formatted); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 673, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + __pyx_t_11 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_8, __pyx_v_d8_flow_dir_raster_path_band) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_d8_flow_dir_raster_path_band); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 673, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 673, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":672 + * '%Y-%m-%d_%H_%M_%S', time.gmtime())) + * + * if (d8_flow_dir_raster_path_band is not None and not # <<<<<<<<<<<<<< + * _is_raster_path_band_formatted(d8_flow_dir_raster_path_band)): + * raise ValueError( + */ + __pyx_t_4 = ((!__pyx_t_14) != 0); + __pyx_t_5 = __pyx_t_4; + __pyx_L11_bool_binop_done:; + if (unlikely(__pyx_t_5)) { + + /* "pygeoprocessing/routing/watershed.pyx":675 + * _is_raster_path_band_formatted(d8_flow_dir_raster_path_band)): + * raise ValueError( + * "%s is supposed to be a raster band tuple but it's not." % ( # <<<<<<<<<<<<<< + * d8_flow_dir_raster_path_band)) + * + */ + __pyx_t_11 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_s_is_supposed_to_be_a_raster_ba, __pyx_v_d8_flow_dir_raster_path_band); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 675, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + + /* "pygeoprocessing/routing/watershed.pyx":674 + * if (d8_flow_dir_raster_path_band is not None and not + * _is_raster_path_band_formatted(d8_flow_dir_raster_path_band)): + * raise ValueError( # <<<<<<<<<<<<<< + * "%s is supposed to be a raster band tuple but it's not." % ( + * d8_flow_dir_raster_path_band)) + */ + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 674, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __PYX_ERR(0, 674, __pyx_L1_error) + + /* "pygeoprocessing/routing/watershed.pyx":672 + * '%Y-%m-%d_%H_%M_%S', time.gmtime())) + * + * if (d8_flow_dir_raster_path_band is not None and not # <<<<<<<<<<<<<< + * _is_raster_path_band_formatted(d8_flow_dir_raster_path_band)): + * raise ValueError( + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":678 + * d8_flow_dir_raster_path_band)) + * + * flow_dir_info = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< + * d8_flow_dir_raster_path_band[0]) + * cdef int flow_dir_nodata = flow_dir_info['nodata'][0] + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 678, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 678, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":679 + * + * flow_dir_info = pygeoprocessing.get_raster_info( + * d8_flow_dir_raster_path_band[0]) # <<<<<<<<<<<<<< + * cdef int flow_dir_nodata = flow_dir_info['nodata'][0] + * source_gt = flow_dir_info['geotransform'] + */ + __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_d8_flow_dir_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 679, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __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); + } + } + __pyx_t_6 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_7, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_11); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 678, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_flow_dir_info = __pyx_t_6; + __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":680 + * flow_dir_info = pygeoprocessing.get_raster_info( + * d8_flow_dir_raster_path_band[0]) + * cdef int flow_dir_nodata = flow_dir_info['nodata'][0] # <<<<<<<<<<<<<< + * source_gt = flow_dir_info['geotransform'] + * cdef double flow_dir_origin_x = source_gt[0] + */ + __pyx_t_6 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_nodata); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 680, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = __Pyx_GetItemInt(__pyx_t_6, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 680, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_8); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 680, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_flow_dir_nodata = __pyx_t_9; + + /* "pygeoprocessing/routing/watershed.pyx":681 + * d8_flow_dir_raster_path_band[0]) + * cdef int flow_dir_nodata = flow_dir_info['nodata'][0] + * source_gt = flow_dir_info['geotransform'] # <<<<<<<<<<<<<< + * cdef double flow_dir_origin_x = source_gt[0] + * cdef double flow_dir_origin_y = source_gt[3] + */ + __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_geotransform); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 681, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_v_source_gt = __pyx_t_8; + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":682 + * cdef int flow_dir_nodata = flow_dir_info['nodata'][0] + * source_gt = flow_dir_info['geotransform'] + * cdef double flow_dir_origin_x = source_gt[0] # <<<<<<<<<<<<<< + * cdef double flow_dir_origin_y = source_gt[3] + * cdef double flow_dir_pixelsize_x = source_gt[1] + */ + __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_source_gt, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 682, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_15 = __pyx_PyFloat_AsDouble(__pyx_t_8); if (unlikely((__pyx_t_15 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 682, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_flow_dir_origin_x = __pyx_t_15; + + /* "pygeoprocessing/routing/watershed.pyx":683 + * source_gt = flow_dir_info['geotransform'] + * cdef double flow_dir_origin_x = source_gt[0] + * cdef double flow_dir_origin_y = source_gt[3] # <<<<<<<<<<<<<< + * cdef double flow_dir_pixelsize_x = source_gt[1] + * cdef double flow_dir_pixelsize_y = source_gt[5] + */ + __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_source_gt, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 683, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_15 = __pyx_PyFloat_AsDouble(__pyx_t_8); if (unlikely((__pyx_t_15 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 683, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_flow_dir_origin_y = __pyx_t_15; + + /* "pygeoprocessing/routing/watershed.pyx":684 + * cdef double flow_dir_origin_x = source_gt[0] + * cdef double flow_dir_origin_y = source_gt[3] + * cdef double flow_dir_pixelsize_x = source_gt[1] # <<<<<<<<<<<<<< + * cdef double flow_dir_pixelsize_y = source_gt[5] + * cdef int flow_dir_n_cols = flow_dir_info['raster_size'][0] + */ + __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_source_gt, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 684, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_15 = __pyx_PyFloat_AsDouble(__pyx_t_8); if (unlikely((__pyx_t_15 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 684, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_flow_dir_pixelsize_x = __pyx_t_15; + + /* "pygeoprocessing/routing/watershed.pyx":685 + * cdef double flow_dir_origin_y = source_gt[3] + * cdef double flow_dir_pixelsize_x = source_gt[1] + * cdef double flow_dir_pixelsize_y = source_gt[5] # <<<<<<<<<<<<<< + * cdef int flow_dir_n_cols = flow_dir_info['raster_size'][0] + * cdef int flow_dir_n_rows = flow_dir_info['raster_size'][1] + */ + __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_source_gt, 5, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 685, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_15 = __pyx_PyFloat_AsDouble(__pyx_t_8); if (unlikely((__pyx_t_15 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 685, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_flow_dir_pixelsize_y = __pyx_t_15; + + /* "pygeoprocessing/routing/watershed.pyx":686 + * cdef double flow_dir_pixelsize_x = source_gt[1] + * cdef double flow_dir_pixelsize_y = source_gt[5] + * cdef int flow_dir_n_cols = flow_dir_info['raster_size'][0] # <<<<<<<<<<<<<< + * cdef int flow_dir_n_rows = flow_dir_info['raster_size'][1] + * cdef int ws_id + */ + __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 686, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_8, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 686, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 686, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_flow_dir_n_cols = __pyx_t_9; + + /* "pygeoprocessing/routing/watershed.pyx":687 + * cdef double flow_dir_pixelsize_y = source_gt[5] + * cdef int flow_dir_n_cols = flow_dir_info['raster_size'][0] + * cdef int flow_dir_n_rows = flow_dir_info['raster_size'][1] # <<<<<<<<<<<<<< + * cdef int ws_id + * bbox_minx, bbox_miny, bbox_maxx, bbox_maxy = flow_dir_info['bounding_box'] + */ + __pyx_t_6 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 687, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = __Pyx_GetItemInt(__pyx_t_6, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 687, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_8); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 687, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_flow_dir_n_rows = __pyx_t_9; + + /* "pygeoprocessing/routing/watershed.pyx":689 + * cdef int flow_dir_n_rows = flow_dir_info['raster_size'][1] + * cdef int ws_id + * bbox_minx, bbox_miny, bbox_maxx, bbox_maxy = flow_dir_info['bounding_box'] # <<<<<<<<<<<<<< + * LOGGER.debug('Creating flow dir bbox') + * flow_dir_bbox = shapely.prepared.prep( + */ + __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_bounding_box); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 689, __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 != 4)) { + if (size > 4) __Pyx_RaiseTooManyValuesError(4); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 689, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_11 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_12 = PyTuple_GET_ITEM(sequence, 3); + } else { + __pyx_t_6 = PyList_GET_ITEM(sequence, 0); + __pyx_t_11 = PyList_GET_ITEM(sequence, 1); + __pyx_t_7 = PyList_GET_ITEM(sequence, 2); + __pyx_t_12 = PyList_GET_ITEM(sequence, 3); + } + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_12); + #else + { + Py_ssize_t i; + PyObject** temps[4] = {&__pyx_t_6,&__pyx_t_11,&__pyx_t_7,&__pyx_t_12}; + for (i=0; i < 4; i++) { + PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 689, __pyx_L1_error) + __Pyx_GOTREF(item); + *(temps[i]) = item; + } + } + #endif + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else { + Py_ssize_t index = -1; + PyObject** temps[4] = {&__pyx_t_6,&__pyx_t_11,&__pyx_t_7,&__pyx_t_12}; + __pyx_t_10 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 689, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_16 = Py_TYPE(__pyx_t_10)->tp_iternext; + for (index=0; index < 4; index++) { + PyObject* item = __pyx_t_16(__pyx_t_10); if (unlikely(!item)) goto __pyx_L13_unpacking_failed; + __Pyx_GOTREF(item); + *(temps[index]) = item; + } + if (__Pyx_IternextUnpackEndCheck(__pyx_t_16(__pyx_t_10), 4) < 0) __PYX_ERR(0, 689, __pyx_L1_error) + __pyx_t_16 = NULL; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + goto __pyx_L14_unpacking_done; + __pyx_L13_unpacking_failed:; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_16 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 689, __pyx_L1_error) + __pyx_L14_unpacking_done:; + } + __pyx_v_bbox_minx = __pyx_t_6; + __pyx_t_6 = 0; + __pyx_v_bbox_miny = __pyx_t_11; + __pyx_t_11 = 0; + __pyx_v_bbox_maxx = __pyx_t_7; + __pyx_t_7 = 0; + __pyx_v_bbox_maxy = __pyx_t_12; + __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":690 + * cdef int ws_id + * bbox_minx, bbox_miny, bbox_maxx, bbox_maxy = flow_dir_info['bounding_box'] + * LOGGER.debug('Creating flow dir bbox') # <<<<<<<<<<<<<< + * flow_dir_bbox = shapely.prepared.prep( + * shapely.geometry.Polygon([ + */ + __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 690, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_debug); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 690, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = NULL; + 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_8 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_12, __pyx_kp_u_Creating_flow_dir_bbox) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_kp_u_Creating_flow_dir_bbox); + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 690, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":691 + * bbox_minx, bbox_miny, bbox_maxx, bbox_maxy = flow_dir_info['bounding_box'] + * LOGGER.debug('Creating flow dir bbox') + * flow_dir_bbox = shapely.prepared.prep( # <<<<<<<<<<<<<< + * shapely.geometry.Polygon([ + * (bbox_minx, bbox_maxy), + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_shapely); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 691, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_prepared); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 691, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_prep); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 691, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":692 + * LOGGER.debug('Creating flow dir bbox') + * flow_dir_bbox = shapely.prepared.prep( + * shapely.geometry.Polygon([ # <<<<<<<<<<<<<< + * (bbox_minx, bbox_maxy), + * (bbox_minx, bbox_miny), + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_shapely); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 692, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_geometry); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 692, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_Polygon); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 692, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":693 + * flow_dir_bbox = shapely.prepared.prep( + * shapely.geometry.Polygon([ + * (bbox_minx, bbox_maxy), # <<<<<<<<<<<<<< + * (bbox_minx, bbox_miny), + * (bbox_maxx, bbox_miny), + */ + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 693, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(__pyx_v_bbox_minx); + __Pyx_GIVEREF(__pyx_v_bbox_minx); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_bbox_minx); + __Pyx_INCREF(__pyx_v_bbox_maxy); + __Pyx_GIVEREF(__pyx_v_bbox_maxy); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_bbox_maxy); + + /* "pygeoprocessing/routing/watershed.pyx":694 + * shapely.geometry.Polygon([ + * (bbox_minx, bbox_maxy), + * (bbox_minx, bbox_miny), # <<<<<<<<<<<<<< + * (bbox_maxx, bbox_miny), + * (bbox_maxx, bbox_maxy), + */ + __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 694, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_v_bbox_minx); + __Pyx_GIVEREF(__pyx_v_bbox_minx); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_bbox_minx); + __Pyx_INCREF(__pyx_v_bbox_miny); + __Pyx_GIVEREF(__pyx_v_bbox_miny); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_v_bbox_miny); + + /* "pygeoprocessing/routing/watershed.pyx":695 + * (bbox_minx, bbox_maxy), + * (bbox_minx, bbox_miny), + * (bbox_maxx, bbox_miny), # <<<<<<<<<<<<<< + * (bbox_maxx, bbox_maxy), + * (bbox_minx, bbox_maxy)])) + */ + __pyx_t_13 = PyTuple_New(2); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 695, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_INCREF(__pyx_v_bbox_maxx); + __Pyx_GIVEREF(__pyx_v_bbox_maxx); + PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_v_bbox_maxx); + __Pyx_INCREF(__pyx_v_bbox_miny); + __Pyx_GIVEREF(__pyx_v_bbox_miny); + PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_v_bbox_miny); + + /* "pygeoprocessing/routing/watershed.pyx":696 + * (bbox_minx, bbox_miny), + * (bbox_maxx, bbox_miny), + * (bbox_maxx, bbox_maxy), # <<<<<<<<<<<<<< + * (bbox_minx, bbox_maxy)])) + * LOGGER.debug('Creating flow dir managed raster') + */ + __pyx_t_17 = PyTuple_New(2); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 696, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_17); + __Pyx_INCREF(__pyx_v_bbox_maxx); + __Pyx_GIVEREF(__pyx_v_bbox_maxx); + PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_v_bbox_maxx); + __Pyx_INCREF(__pyx_v_bbox_maxy); + __Pyx_GIVEREF(__pyx_v_bbox_maxy); + PyTuple_SET_ITEM(__pyx_t_17, 1, __pyx_v_bbox_maxy); + + /* "pygeoprocessing/routing/watershed.pyx":697 + * (bbox_maxx, bbox_miny), + * (bbox_maxx, bbox_maxy), + * (bbox_minx, bbox_maxy)])) # <<<<<<<<<<<<<< + * LOGGER.debug('Creating flow dir managed raster') + * flow_dir_managed_raster = _ManagedRaster(d8_flow_dir_raster_path_band[0], + */ + __pyx_t_18 = PyTuple_New(2); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 697, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_INCREF(__pyx_v_bbox_minx); + __Pyx_GIVEREF(__pyx_v_bbox_minx); + PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_v_bbox_minx); + __Pyx_INCREF(__pyx_v_bbox_maxy); + __Pyx_GIVEREF(__pyx_v_bbox_maxy); + PyTuple_SET_ITEM(__pyx_t_18, 1, __pyx_v_bbox_maxy); + + /* "pygeoprocessing/routing/watershed.pyx":692 + * LOGGER.debug('Creating flow dir bbox') + * flow_dir_bbox = shapely.prepared.prep( + * shapely.geometry.Polygon([ # <<<<<<<<<<<<<< + * (bbox_minx, bbox_maxy), + * (bbox_minx, bbox_miny), + */ + __pyx_t_19 = PyList_New(5); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 692, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_GIVEREF(__pyx_t_6); + PyList_SET_ITEM(__pyx_t_19, 0, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_10); + PyList_SET_ITEM(__pyx_t_19, 1, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_13); + PyList_SET_ITEM(__pyx_t_19, 2, __pyx_t_13); + __Pyx_GIVEREF(__pyx_t_17); + PyList_SET_ITEM(__pyx_t_19, 3, __pyx_t_17); + __Pyx_GIVEREF(__pyx_t_18); + PyList_SET_ITEM(__pyx_t_19, 4, __pyx_t_18); + __pyx_t_6 = 0; + __pyx_t_10 = 0; + __pyx_t_13 = 0; + __pyx_t_17 = 0; + __pyx_t_18 = 0; + __pyx_t_18 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_18 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_18)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_18); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + } + } + __pyx_t_12 = (__pyx_t_18) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_18, __pyx_t_19) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_19); + __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 692, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_8 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_11, __pyx_t_12) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_12); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 691, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_flow_dir_bbox = __pyx_t_8; + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":698 + * (bbox_maxx, bbox_maxy), + * (bbox_minx, bbox_maxy)])) + * LOGGER.debug('Creating flow dir managed raster') # <<<<<<<<<<<<<< + * flow_dir_managed_raster = _ManagedRaster(d8_flow_dir_raster_path_band[0], + * d8_flow_dir_raster_path_band[1], 0) + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 698, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_debug); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 698, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + } + } + __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_7, __pyx_kp_u_Creating_flow_dir_managed_raster) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_kp_u_Creating_flow_dir_managed_raster); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 698, __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/watershed.pyx":699 + * (bbox_minx, bbox_maxy)])) + * LOGGER.debug('Creating flow dir managed raster') + * flow_dir_managed_raster = _ManagedRaster(d8_flow_dir_raster_path_band[0], # <<<<<<<<<<<<<< + * d8_flow_dir_raster_path_band[1], 0) + * + */ + __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_d8_flow_dir_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 699, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + + /* "pygeoprocessing/routing/watershed.pyx":700 + * LOGGER.debug('Creating flow dir managed raster') + * flow_dir_managed_raster = _ManagedRaster(d8_flow_dir_raster_path_band[0], + * d8_flow_dir_raster_path_band[1], 0) # <<<<<<<<<<<<<< + * + * gtiff_driver = gdal.GetDriverByName('GTiff') + */ + __pyx_t_12 = __Pyx_GetItemInt(__pyx_v_d8_flow_dir_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 700, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + + /* "pygeoprocessing/routing/watershed.pyx":699 + * (bbox_minx, bbox_maxy)])) + * LOGGER.debug('Creating flow dir managed raster') + * flow_dir_managed_raster = _ManagedRaster(d8_flow_dir_raster_path_band[0], # <<<<<<<<<<<<<< + * d8_flow_dir_raster_path_band[1], 0) + * + */ + __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 699, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_12); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_int_0); + __pyx_t_8 = 0; + __pyx_t_12 = 0; + __pyx_t_12 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_9watershed__ManagedRaster), __pyx_t_7, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 699, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_flow_dir_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *)__pyx_t_12); + __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":702 + * d8_flow_dir_raster_path_band[1], 0) + * + * gtiff_driver = gdal.GetDriverByName('GTiff') # <<<<<<<<<<<<<< + * flow_dir_srs = osr.SpatialReference() + * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 702, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_GetDriverByName); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 702, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __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); + } + } + __pyx_t_12 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_7, __pyx_n_u_GTiff) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_n_u_GTiff); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 702, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_gtiff_driver = __pyx_t_12; + __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":703 + * + * gtiff_driver = gdal.GetDriverByName('GTiff') + * flow_dir_srs = osr.SpatialReference() # <<<<<<<<<<<<<< + * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_osr); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 703, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_SpatialReference); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 703, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __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); + } + } + __pyx_t_12 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 703, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_flow_dir_srs = __pyx_t_12; + __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":704 + * gtiff_driver = gdal.GetDriverByName('GTiff') + * flow_dir_srs = osr.SpatialReference() + * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) # <<<<<<<<<<<<<< + * + * outflow_vector = gdal.OpenEx(outflow_vector_path, gdal.OF_VECTOR) + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_srs, __pyx_n_s_ImportFromWkt); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 704, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_projection_wkt); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 704, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_12 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_11, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 704, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":706 + * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) + * + * outflow_vector = gdal.OpenEx(outflow_vector_path, gdal.OF_VECTOR) # <<<<<<<<<<<<<< + * if outflow_vector is None: + * raise ValueError(u'Could not open outflow vector %s' % outflow_vector_path) + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OF_VECTOR); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + __pyx_t_9 = 0; + 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); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_outflow_vector_path, __pyx_t_11}; + __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_outflow_vector_path, __pyx_t_11}; + __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } else + #endif + { + __pyx_t_19 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_v_outflow_vector_path); + __Pyx_GIVEREF(__pyx_v_outflow_vector_path); + PyTuple_SET_ITEM(__pyx_t_19, 0+__pyx_t_9, __pyx_v_outflow_vector_path); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_19, 1+__pyx_t_9, __pyx_t_11); + __pyx_t_11 = 0; + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_19, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_outflow_vector = __pyx_t_12; + __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":707 + * + * outflow_vector = gdal.OpenEx(outflow_vector_path, gdal.OF_VECTOR) + * if outflow_vector is None: # <<<<<<<<<<<<<< + * raise ValueError(u'Could not open outflow vector %s' % outflow_vector_path) + * + */ + __pyx_t_5 = (__pyx_v_outflow_vector == Py_None); + __pyx_t_4 = (__pyx_t_5 != 0); + if (unlikely(__pyx_t_4)) { + + /* "pygeoprocessing/routing/watershed.pyx":708 + * outflow_vector = gdal.OpenEx(outflow_vector_path, gdal.OF_VECTOR) + * if outflow_vector is None: + * raise ValueError(u'Could not open outflow vector %s' % outflow_vector_path) # <<<<<<<<<<<<<< + * + * driver = ogr.GetDriverByName('GPKG') + */ + __pyx_t_12 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_Could_not_open_outflow_vector_s, __pyx_v_outflow_vector_path); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 708, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_12); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 708, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_Raise(__pyx_t_8, 0, 0, 0); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __PYX_ERR(0, 708, __pyx_L1_error) + + /* "pygeoprocessing/routing/watershed.pyx":707 + * + * outflow_vector = gdal.OpenEx(outflow_vector_path, gdal.OF_VECTOR) + * if outflow_vector is None: # <<<<<<<<<<<<<< + * raise ValueError(u'Could not open outflow vector %s' % outflow_vector_path) + * + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":710 + * raise ValueError(u'Could not open outflow vector %s' % outflow_vector_path) + * + * driver = ogr.GetDriverByName('GPKG') # <<<<<<<<<<<<<< + * watersheds_srs = osr.SpatialReference() + * watersheds_srs.ImportFromWkt(flow_dir_info['projection_wkt']) + */ + __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_ogr); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 710, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_GetDriverByName); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 710, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_19))) { + __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_19); + if (likely(__pyx_t_12)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19); + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_19, function); + } + } + __pyx_t_8 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_19, __pyx_t_12, __pyx_n_u_GPKG) : __Pyx_PyObject_CallOneArg(__pyx_t_19, __pyx_n_u_GPKG); + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 710, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __pyx_v_driver = __pyx_t_8; + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":711 + * + * driver = ogr.GetDriverByName('GPKG') + * watersheds_srs = osr.SpatialReference() # <<<<<<<<<<<<<< + * watersheds_srs.ImportFromWkt(flow_dir_info['projection_wkt']) + * watersheds_vector = driver.CreateDataSource(target_watersheds_vector_path) + */ + __Pyx_GetModuleGlobalName(__pyx_t_19, __pyx_n_s_osr); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 711, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_n_s_SpatialReference); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 711, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __pyx_t_19 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_19)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_19); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + } + } + __pyx_t_8 = (__pyx_t_19) ? __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_19) : __Pyx_PyObject_CallNoArg(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 711, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_v_watersheds_srs = __pyx_t_8; + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":712 + * driver = ogr.GetDriverByName('GPKG') + * watersheds_srs = osr.SpatialReference() + * watersheds_srs.ImportFromWkt(flow_dir_info['projection_wkt']) # <<<<<<<<<<<<<< + * watersheds_vector = driver.CreateDataSource(target_watersheds_vector_path) + * polygonized_watersheds_layer = watersheds_vector.CreateLayer( + */ + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_watersheds_srs, __pyx_n_s_ImportFromWkt); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 712, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_19 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_projection_wkt); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 712, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + } + } + __pyx_t_8 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_11, __pyx_t_19) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_19); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 712, __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/watershed.pyx":713 + * watersheds_srs = osr.SpatialReference() + * watersheds_srs.ImportFromWkt(flow_dir_info['projection_wkt']) + * watersheds_vector = driver.CreateDataSource(target_watersheds_vector_path) # <<<<<<<<<<<<<< + * polygonized_watersheds_layer = watersheds_vector.CreateLayer( + * 'polygonized_watersheds', watersheds_srs, ogr.wkbPolygon) + */ + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_driver, __pyx_n_s_CreateDataSource); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 713, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_19 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_19)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_19); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + } + } + __pyx_t_8 = (__pyx_t_19) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_19, __pyx_v_target_watersheds_vector_path) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_v_target_watersheds_vector_path); + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 713, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_v_watersheds_vector = __pyx_t_8; + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":714 + * watersheds_srs.ImportFromWkt(flow_dir_info['projection_wkt']) + * watersheds_vector = driver.CreateDataSource(target_watersheds_vector_path) + * polygonized_watersheds_layer = watersheds_vector.CreateLayer( # <<<<<<<<<<<<<< + * 'polygonized_watersheds', watersheds_srs, ogr.wkbPolygon) + * + */ + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_watersheds_vector, __pyx_n_s_CreateLayer); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 714, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + + /* "pygeoprocessing/routing/watershed.pyx":715 + * watersheds_vector = driver.CreateDataSource(target_watersheds_vector_path) + * polygonized_watersheds_layer = watersheds_vector.CreateLayer( + * 'polygonized_watersheds', watersheds_srs, ogr.wkbPolygon) # <<<<<<<<<<<<<< + * + * # Using wkbUnknown layer data type because it's possible for a single + */ + __Pyx_GetModuleGlobalName(__pyx_t_19, __pyx_n_s_ogr); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 715, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_n_s_wkbPolygon); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 715, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __pyx_t_19 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_19)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_19); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_12)) { + PyObject *__pyx_temp[4] = {__pyx_t_19, __pyx_n_u_polygonized_watersheds, __pyx_v_watersheds_srs, __pyx_t_11}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 714, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) { + PyObject *__pyx_temp[4] = {__pyx_t_19, __pyx_n_u_polygonized_watersheds, __pyx_v_watersheds_srs, __pyx_t_11}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 714, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(3+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 714, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_19) { + __Pyx_GIVEREF(__pyx_t_19); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_19); __pyx_t_19 = NULL; + } + __Pyx_INCREF(__pyx_n_u_polygonized_watersheds); + __Pyx_GIVEREF(__pyx_n_u_polygonized_watersheds); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_9, __pyx_n_u_polygonized_watersheds); + __Pyx_INCREF(__pyx_v_watersheds_srs); + __Pyx_GIVEREF(__pyx_v_watersheds_srs); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_9, __pyx_v_watersheds_srs); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_9, __pyx_t_11); + __pyx_t_11 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 714, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_v_polygonized_watersheds_layer = __pyx_t_8; + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":722 + * # technically not supported by the GPKG standard although GDAL + * # allows it for the time being. + * watersheds_layer = watersheds_vector.CreateLayer( # <<<<<<<<<<<<<< + * target_layer_name, watersheds_srs, ogr.wkbUnknown) + * index_field = ogr.FieldDefn('ws_id', ogr.OFTInteger) + */ + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_watersheds_vector, __pyx_n_s_CreateLayer); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 722, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + + /* "pygeoprocessing/routing/watershed.pyx":723 + * # allows it for the time being. + * watersheds_layer = watersheds_vector.CreateLayer( + * target_layer_name, watersheds_srs, ogr.wkbUnknown) # <<<<<<<<<<<<<< + * index_field = ogr.FieldDefn('ws_id', ogr.OFTInteger) + * index_field.SetWidth(24) + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 723, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_wkbUnknown); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 723, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_12)) { + PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_v_target_layer_name, __pyx_v_watersheds_srs, __pyx_t_11}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 722, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) { + PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_v_target_layer_name, __pyx_v_watersheds_srs, __pyx_t_11}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 722, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } else + #endif + { + __pyx_t_19 = PyTuple_New(3+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 722, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_v_target_layer_name); + __Pyx_GIVEREF(__pyx_v_target_layer_name); + PyTuple_SET_ITEM(__pyx_t_19, 0+__pyx_t_9, __pyx_v_target_layer_name); + __Pyx_INCREF(__pyx_v_watersheds_srs); + __Pyx_GIVEREF(__pyx_v_watersheds_srs); + PyTuple_SET_ITEM(__pyx_t_19, 1+__pyx_t_9, __pyx_v_watersheds_srs); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_19, 2+__pyx_t_9, __pyx_t_11); + __pyx_t_11 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_19, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 722, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + } + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_v_watersheds_layer = __pyx_t_8; + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":724 + * watersheds_layer = watersheds_vector.CreateLayer( + * target_layer_name, watersheds_srs, ogr.wkbUnknown) + * index_field = ogr.FieldDefn('ws_id', ogr.OFTInteger) # <<<<<<<<<<<<<< + * index_field.SetWidth(24) + * polygonized_watersheds_layer.CreateField(index_field) + */ + __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_ogr); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 724, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 724, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_ogr); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 724, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 724, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_19))) { + __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_19); + if (likely(__pyx_t_12)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19); + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_19, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_19)) { + PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_n_u_ws_id, __pyx_t_11}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_19, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 724, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_19)) { + PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_n_u_ws_id, __pyx_t_11}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_19, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 724, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 724, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_12) { + __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_12); __pyx_t_12 = NULL; + } + __Pyx_INCREF(__pyx_n_u_ws_id); + __Pyx_GIVEREF(__pyx_n_u_ws_id); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_9, __pyx_n_u_ws_id); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_9, __pyx_t_11); + __pyx_t_11 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_19, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 724, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __pyx_v_index_field = __pyx_t_8; + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":725 + * target_layer_name, watersheds_srs, ogr.wkbUnknown) + * index_field = ogr.FieldDefn('ws_id', ogr.OFTInteger) + * index_field.SetWidth(24) # <<<<<<<<<<<<<< + * polygonized_watersheds_layer.CreateField(index_field) + * + */ + __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_v_index_field, __pyx_n_s_SetWidth); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 725, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_19))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_19); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_19, function); + } + } + __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_19, __pyx_t_7, __pyx_int_24) : __Pyx_PyObject_CallOneArg(__pyx_t_19, __pyx_int_24); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 725, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":726 + * index_field = ogr.FieldDefn('ws_id', ogr.OFTInteger) + * index_field.SetWidth(24) + * polygonized_watersheds_layer.CreateField(index_field) # <<<<<<<<<<<<<< + * + * cdef int* reverse_flow = [4, 5, 6, 7, 0, 1, 2, 3] + */ + __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_v_polygonized_watersheds_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 726, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_19))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_19); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_19, function); + } + } + __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_19, __pyx_t_7, __pyx_v_index_field) : __Pyx_PyObject_CallOneArg(__pyx_t_19, __pyx_v_index_field); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 726, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":728 + * polygonized_watersheds_layer.CreateField(index_field) + * + * cdef int* reverse_flow = [4, 5, 6, 7, 0, 1, 2, 3] # <<<<<<<<<<<<<< + * cdef int* neighbor_col = [1, 1, 0, -1, -1, -1, 0, 1] + * cdef int* neighbor_row = [0, -1, -1, -1, 0, 1, 1, 1] + */ + __pyx_t_20[0] = 4; + __pyx_t_20[1] = 5; + __pyx_t_20[2] = 6; + __pyx_t_20[3] = 7; + __pyx_t_20[4] = 0; + __pyx_t_20[5] = 1; + __pyx_t_20[6] = 2; + __pyx_t_20[7] = 3; + __pyx_v_reverse_flow = __pyx_t_20; + + /* "pygeoprocessing/routing/watershed.pyx":729 + * + * cdef int* reverse_flow = [4, 5, 6, 7, 0, 1, 2, 3] + * cdef int* neighbor_col = [1, 1, 0, -1, -1, -1, 0, 1] # <<<<<<<<<<<<<< + * cdef int* neighbor_row = [0, -1, -1, -1, 0, 1, 1, 1] + * cdef queue[CoordinatePair] process_queue + */ + __pyx_t_21[0] = 1; + __pyx_t_21[1] = 1; + __pyx_t_21[2] = 0; + __pyx_t_21[3] = -1; + __pyx_t_21[4] = -1; + __pyx_t_21[5] = -1; + __pyx_t_21[6] = 0; + __pyx_t_21[7] = 1; + __pyx_v_neighbor_col = __pyx_t_21; + + /* "pygeoprocessing/routing/watershed.pyx":730 + * cdef int* reverse_flow = [4, 5, 6, 7, 0, 1, 2, 3] + * cdef int* neighbor_col = [1, 1, 0, -1, -1, -1, 0, 1] + * cdef int* neighbor_row = [0, -1, -1, -1, 0, 1, 1, 1] # <<<<<<<<<<<<<< + * cdef queue[CoordinatePair] process_queue + * cdef cset[CoordinatePair] process_queue_set + */ + __pyx_t_22[0] = 0; + __pyx_t_22[1] = -1; + __pyx_t_22[2] = -1; + __pyx_t_22[3] = -1; + __pyx_t_22[4] = 0; + __pyx_t_22[5] = 1; + __pyx_t_22[6] = 1; + __pyx_t_22[7] = 1; + __pyx_v_neighbor_row = __pyx_t_22; + + /* "pygeoprocessing/routing/watershed.pyx":736 + * cdef int ix_min, iy_min, ix_max, iy_max + * cdef _ManagedRaster scratch_managed_raster + * cdef int watersheds_created = 0 # <<<<<<<<<<<<<< + * cdef int current_fid, outflow_feature_count + * cdef cset[CoordinatePair].iterator seed_iterator + */ + __pyx_v_watersheds_created = 0; + + /* "pygeoprocessing/routing/watershed.pyx":741 + * cdef cset[CoordinatePair] seeds_in_watershed + * cdef time_t last_log_time + * cdef int n_cells_visited = 0 # <<<<<<<<<<<<<< + * + * LOGGER.info('Delineating watersheds') + */ + __pyx_v_n_cells_visited = 0; + + /* "pygeoprocessing/routing/watershed.pyx":743 + * cdef int n_cells_visited = 0 + * + * LOGGER.info('Delineating watersheds') # <<<<<<<<<<<<<< + * outflow_layer = outflow_vector.GetLayer() + * outflow_feature_count = outflow_layer.GetFeatureCount() + */ + __Pyx_GetModuleGlobalName(__pyx_t_19, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 743, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_n_s_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 743, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __pyx_t_19 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_19)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_19); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_8 = (__pyx_t_19) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_19, __pyx_kp_u_Delineating_watersheds) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_kp_u_Delineating_watersheds); + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 743, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":744 + * + * LOGGER.info('Delineating watersheds') + * outflow_layer = outflow_vector.GetLayer() # <<<<<<<<<<<<<< + * outflow_feature_count = outflow_layer.GetFeatureCount() + * flow_dir_srs = osr.SpatialReference() + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_outflow_vector, __pyx_n_s_GetLayer); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 744, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_19 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_19)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_19); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_8 = (__pyx_t_19) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_19) : __Pyx_PyObject_CallNoArg(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 744, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_outflow_layer = __pyx_t_8; + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":745 + * LOGGER.info('Delineating watersheds') + * outflow_layer = outflow_vector.GetLayer() + * outflow_feature_count = outflow_layer.GetFeatureCount() # <<<<<<<<<<<<<< + * flow_dir_srs = osr.SpatialReference() + * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_outflow_layer, __pyx_n_s_GetFeatureCount); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 745, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_19 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_19)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_19); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_8 = (__pyx_t_19) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_19) : __Pyx_PyObject_CallNoArg(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 745, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_8); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 745, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_outflow_feature_count = __pyx_t_9; + + /* "pygeoprocessing/routing/watershed.pyx":746 + * outflow_layer = outflow_vector.GetLayer() + * outflow_feature_count = outflow_layer.GetFeatureCount() + * flow_dir_srs = osr.SpatialReference() # <<<<<<<<<<<<<< + * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) + * for feature in outflow_layer: + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_osr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 746, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_SpatialReference); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 746, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_19))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_19); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_19, function); + } + } + __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_19, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_19); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 746, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_DECREF_SET(__pyx_v_flow_dir_srs, __pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":747 + * outflow_feature_count = outflow_layer.GetFeatureCount() + * flow_dir_srs = osr.SpatialReference() + * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) # <<<<<<<<<<<<<< + * for feature in outflow_layer: + * # Some vectors start indexing their FIDs at 0. + */ + __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_srs, __pyx_n_s_ImportFromWkt); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 747, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_7 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_projection_wkt); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 747, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_19))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_19); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_19, function); + } + } + __pyx_t_8 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_19, __pyx_t_11, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_19, __pyx_t_7); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 747, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":748 + * flow_dir_srs = osr.SpatialReference() + * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) + * for feature in outflow_layer: # <<<<<<<<<<<<<< + * # Some vectors start indexing their FIDs at 0. + * # The mask raster input to polygonization, however, only regards pixels + */ + if (likely(PyList_CheckExact(__pyx_v_outflow_layer)) || PyTuple_CheckExact(__pyx_v_outflow_layer)) { + __pyx_t_8 = __pyx_v_outflow_layer; __Pyx_INCREF(__pyx_t_8); __pyx_t_23 = 0; + __pyx_t_24 = NULL; + } else { + __pyx_t_23 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_outflow_layer); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 748, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_24 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 748, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_24)) { + if (likely(PyList_CheckExact(__pyx_t_8))) { + if (__pyx_t_23 >= PyList_GET_SIZE(__pyx_t_8)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_19 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_23); __Pyx_INCREF(__pyx_t_19); __pyx_t_23++; if (unlikely(0 < 0)) __PYX_ERR(0, 748, __pyx_L1_error) + #else + __pyx_t_19 = PySequence_ITEM(__pyx_t_8, __pyx_t_23); __pyx_t_23++; if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 748, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + #endif + } else { + if (__pyx_t_23 >= PyTuple_GET_SIZE(__pyx_t_8)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_19 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_23); __Pyx_INCREF(__pyx_t_19); __pyx_t_23++; if (unlikely(0 < 0)) __PYX_ERR(0, 748, __pyx_L1_error) + #else + __pyx_t_19 = PySequence_ITEM(__pyx_t_8, __pyx_t_23); __pyx_t_23++; if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 748, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + #endif + } + } else { + __pyx_t_19 = __pyx_t_24(__pyx_t_8); + if (unlikely(!__pyx_t_19)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 748, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_19); + } + __Pyx_XDECREF_SET(__pyx_v_feature, __pyx_t_19); + __pyx_t_19 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":753 + * # as zero or nonzero. Therefore, to make sure we can use the ws_id as + * # the FID and not maintain a separate mask raster, we'll just add 1. + * current_fid = feature.GetFID() # <<<<<<<<<<<<<< + * ws_id = current_fid + 1 + * assert ws_id >= 1, 'WSID <= 1!' + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_feature, __pyx_n_s_GetFID); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 753, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_19 = (__pyx_t_11) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_11) : __Pyx_PyObject_CallNoArg(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 753, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_19); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 753, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __pyx_v_current_fid = __pyx_t_9; + + /* "pygeoprocessing/routing/watershed.pyx":754 + * # the FID and not maintain a separate mask raster, we'll just add 1. + * current_fid = feature.GetFID() + * ws_id = current_fid + 1 # <<<<<<<<<<<<<< + * assert ws_id >= 1, 'WSID <= 1!' + * + */ + __pyx_v_ws_id = (__pyx_v_current_fid + 1); + + /* "pygeoprocessing/routing/watershed.pyx":755 + * current_fid = feature.GetFID() + * ws_id = current_fid + 1 + * assert ws_id >= 1, 'WSID <= 1!' # <<<<<<<<<<<<<< + * + * geom = feature.GetGeometryRef() + */ + #ifndef CYTHON_WITHOUT_ASSERTIONS + if (unlikely(!Py_OptimizeFlag)) { + if (unlikely(!((__pyx_v_ws_id >= 1) != 0))) { + PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_WSID_1); + __PYX_ERR(0, 755, __pyx_L1_error) + } + } + #endif + + /* "pygeoprocessing/routing/watershed.pyx":757 + * assert ws_id >= 1, 'WSID <= 1!' + * + * geom = feature.GetGeometryRef() # <<<<<<<<<<<<<< + * if geom.IsEmpty(): + * LOGGER.debug( + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_feature, __pyx_n_s_GetGeometryRef); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 757, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_19 = (__pyx_t_11) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_11) : __Pyx_PyObject_CallNoArg(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 757, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF_SET(__pyx_v_geom, __pyx_t_19); + __pyx_t_19 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":758 + * + * geom = feature.GetGeometryRef() + * if geom.IsEmpty(): # <<<<<<<<<<<<<< + * LOGGER.debug( + * 'Outflow feature %s has empty geometry. Skipping.', + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_geom, __pyx_n_s_IsEmpty); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 758, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_19 = (__pyx_t_11) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_11) : __Pyx_PyObject_CallNoArg(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 758, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_19); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 758, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + if (__pyx_t_4) { + + /* "pygeoprocessing/routing/watershed.pyx":759 + * geom = feature.GetGeometryRef() + * if geom.IsEmpty(): + * LOGGER.debug( # <<<<<<<<<<<<<< + * 'Outflow feature %s has empty geometry. Skipping.', + * current_fid) + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 759, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_debug); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 759, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":761 + * LOGGER.debug( + * 'Outflow feature %s has empty geometry. Skipping.', + * current_fid) # <<<<<<<<<<<<<< + * continue + * geom_wkb = geom.ExportToWkb() + */ + __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_current_fid); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 761, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_12 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_12)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_kp_u_Outflow_feature_s_has_empty_geom, __pyx_t_7}; + __pyx_t_19 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 759, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_kp_u_Outflow_feature_s_has_empty_geom, __pyx_t_7}; + __pyx_t_19 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 759, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_18 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 759, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + if (__pyx_t_12) { + __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_12); __pyx_t_12 = NULL; + } + __Pyx_INCREF(__pyx_kp_u_Outflow_feature_s_has_empty_geom); + __Pyx_GIVEREF(__pyx_kp_u_Outflow_feature_s_has_empty_geom); + PyTuple_SET_ITEM(__pyx_t_18, 0+__pyx_t_9, __pyx_kp_u_Outflow_feature_s_has_empty_geom); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_18, 1+__pyx_t_9, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_18, NULL); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 759, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + } + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":762 + * 'Outflow feature %s has empty geometry. Skipping.', + * current_fid) + * continue # <<<<<<<<<<<<<< + * geom_wkb = geom.ExportToWkb() + * shapely_geom = shapely.wkb.loads(geom_wkb) + */ + goto __pyx_L16_continue; + + /* "pygeoprocessing/routing/watershed.pyx":758 + * + * geom = feature.GetGeometryRef() + * if geom.IsEmpty(): # <<<<<<<<<<<<<< + * LOGGER.debug( + * 'Outflow feature %s has empty geometry. Skipping.', + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":763 + * current_fid) + * continue + * geom_wkb = geom.ExportToWkb() # <<<<<<<<<<<<<< + * shapely_geom = shapely.wkb.loads(geom_wkb) + * + */ + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_geom, __pyx_n_s_ExportToWkb); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 763, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_18 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_18 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_18)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_18); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + } + } + __pyx_t_19 = (__pyx_t_18) ? __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_18) : __Pyx_PyObject_CallNoArg(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; + if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 763, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF_SET(__pyx_v_geom_wkb, __pyx_t_19); + __pyx_t_19 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":764 + * continue + * geom_wkb = geom.ExportToWkb() + * shapely_geom = shapely.wkb.loads(geom_wkb) # <<<<<<<<<<<<<< + * + * LOGGER.debug('Testing geometry bbox') + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_shapely); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 764, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_18 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_wkb); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 764, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_18, __pyx_n_s_loads); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 764, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __pyx_t_18 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_18 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_18)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_18); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + } + } + __pyx_t_19 = (__pyx_t_18) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_18, __pyx_v_geom_wkb) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_v_geom_wkb); + __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; + if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 764, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF_SET(__pyx_v_shapely_geom, __pyx_t_19); + __pyx_t_19 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":766 + * shapely_geom = shapely.wkb.loads(geom_wkb) + * + * LOGGER.debug('Testing geometry bbox') # <<<<<<<<<<<<<< + * if not flow_dir_bbox.intersects(shapely.geometry.box(*shapely_geom.bounds)): + * LOGGER.debug( + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 766, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_18 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_debug); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 766, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_18))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_18); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_18); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_18, function); + } + } + __pyx_t_19 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_18, __pyx_t_11, __pyx_kp_u_Testing_geometry_bbox) : __Pyx_PyObject_CallOneArg(__pyx_t_18, __pyx_kp_u_Testing_geometry_bbox); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 766, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":767 + * + * LOGGER.debug('Testing geometry bbox') + * if not flow_dir_bbox.intersects(shapely.geometry.box(*shapely_geom.bounds)): # <<<<<<<<<<<<<< + * LOGGER.debug( + * 'Outflow feature %s does not overlap with the flow ' + */ + __pyx_t_18 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_bbox, __pyx_n_s_intersects); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 767, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_shapely); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 767, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_geometry); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 767, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_box); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 767, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_shapely_geom, __pyx_n_s_bounds); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 767, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_12 = __Pyx_PySequence_Tuple(__pyx_t_7); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 767, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_12, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 767, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_18))) { + __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_18); + if (likely(__pyx_t_12)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_18); + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_18, function); + } + } + __pyx_t_19 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_18, __pyx_t_12, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_18, __pyx_t_7); + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 767, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_19); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 767, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __pyx_t_5 = ((!__pyx_t_4) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/watershed.pyx":768 + * LOGGER.debug('Testing geometry bbox') + * if not flow_dir_bbox.intersects(shapely.geometry.box(*shapely_geom.bounds)): + * LOGGER.debug( # <<<<<<<<<<<<<< + * 'Outflow feature %s does not overlap with the flow ' + * 'direction raster. Skipping.', current_fid) + */ + __Pyx_GetModuleGlobalName(__pyx_t_18, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 768, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_18, __pyx_n_s_debug); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 768, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":770 + * LOGGER.debug( + * 'Outflow feature %s does not overlap with the flow ' + * 'direction raster. Skipping.', current_fid) # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_18 = __Pyx_PyInt_From_int(__pyx_v_current_fid); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 770, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __pyx_t_12 = NULL; + __pyx_t_9 = 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_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_kp_u_Outflow_feature_s_does_not_overl, __pyx_t_18}; + __pyx_t_19 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 768, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_kp_u_Outflow_feature_s_does_not_overl, __pyx_t_18}; + __pyx_t_19 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 768, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + } else + #endif + { + __pyx_t_11 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 768, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + if (__pyx_t_12) { + __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_12); __pyx_t_12 = NULL; + } + __Pyx_INCREF(__pyx_kp_u_Outflow_feature_s_does_not_overl); + __Pyx_GIVEREF(__pyx_kp_u_Outflow_feature_s_does_not_overl); + PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_9, __pyx_kp_u_Outflow_feature_s_does_not_overl); + __Pyx_GIVEREF(__pyx_t_18); + PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_9, __pyx_t_18); + __pyx_t_18 = 0; + __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_11, NULL); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 768, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":771 + * 'Outflow feature %s does not overlap with the flow ' + * 'direction raster. Skipping.', current_fid) + * continue # <<<<<<<<<<<<<< + * + * seeds_raster_path = os.path.join(working_dir_path, '%s_rasterized.tif' % ws_id) + */ + goto __pyx_L16_continue; + + /* "pygeoprocessing/routing/watershed.pyx":767 + * + * LOGGER.debug('Testing geometry bbox') + * if not flow_dir_bbox.intersects(shapely.geometry.box(*shapely_geom.bounds)): # <<<<<<<<<<<<<< + * LOGGER.debug( + * 'Outflow feature %s does not overlap with the flow ' + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":773 + * continue + * + * seeds_raster_path = os.path.join(working_dir_path, '%s_rasterized.tif' % ws_id) # <<<<<<<<<<<<<< + * if write_diagnostic_vector: + * diagnostic_vector_path = os.path.join(working_dir_path, '%s_seeds.gpkg' % ws_id) + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_os); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 773, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_path); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 773, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_join); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 773, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = __Pyx_PyInt_From_int(__pyx_v_ws_id); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 773, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_18 = PyUnicode_Format(__pyx_kp_u_s_rasterized_tif, __pyx_t_11); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 773, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_working_dir_path, __pyx_t_18}; + __pyx_t_19 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 773, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_working_dir_path, __pyx_t_18}; + __pyx_t_19 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 773, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + } else + #endif + { + __pyx_t_12 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 773, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + if (__pyx_t_11) { + __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11); __pyx_t_11 = NULL; + } + __Pyx_INCREF(__pyx_v_working_dir_path); + __Pyx_GIVEREF(__pyx_v_working_dir_path); + PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_9, __pyx_v_working_dir_path); + __Pyx_GIVEREF(__pyx_t_18); + PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_9, __pyx_t_18); + __pyx_t_18 = 0; + __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_12, NULL); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 773, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF_SET(__pyx_v_seeds_raster_path, __pyx_t_19); + __pyx_t_19 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":774 + * + * seeds_raster_path = os.path.join(working_dir_path, '%s_rasterized.tif' % ws_id) + * if write_diagnostic_vector: # <<<<<<<<<<<<<< + * diagnostic_vector_path = os.path.join(working_dir_path, '%s_seeds.gpkg' % ws_id) + * else: + */ + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_write_diagnostic_vector); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 774, __pyx_L1_error) + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/watershed.pyx":775 + * seeds_raster_path = os.path.join(working_dir_path, '%s_rasterized.tif' % ws_id) + * if write_diagnostic_vector: + * diagnostic_vector_path = os.path.join(working_dir_path, '%s_seeds.gpkg' % ws_id) # <<<<<<<<<<<<<< + * else: + * diagnostic_vector_path = None + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_os); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 775, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_path); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 775, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_join); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 775, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = __Pyx_PyInt_From_int(__pyx_v_ws_id); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 775, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_18 = PyUnicode_Format(__pyx_kp_u_s_seeds_gpkg, __pyx_t_12); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 775, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && likely(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_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_v_working_dir_path, __pyx_t_18}; + __pyx_t_19 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 775, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_v_working_dir_path, __pyx_t_18}; + __pyx_t_19 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 775, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + } else + #endif + { + __pyx_t_11 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 775, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + if (__pyx_t_12) { + __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_12); __pyx_t_12 = NULL; + } + __Pyx_INCREF(__pyx_v_working_dir_path); + __Pyx_GIVEREF(__pyx_v_working_dir_path); + PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_9, __pyx_v_working_dir_path); + __Pyx_GIVEREF(__pyx_t_18); + PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_9, __pyx_t_18); + __pyx_t_18 = 0; + __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_11, NULL); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 775, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF_SET(__pyx_v_diagnostic_vector_path, __pyx_t_19); + __pyx_t_19 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":774 + * + * seeds_raster_path = os.path.join(working_dir_path, '%s_rasterized.tif' % ws_id) + * if write_diagnostic_vector: # <<<<<<<<<<<<<< + * diagnostic_vector_path = os.path.join(working_dir_path, '%s_seeds.gpkg' % ws_id) + * else: + */ + goto __pyx_L20; + } + + /* "pygeoprocessing/routing/watershed.pyx":777 + * diagnostic_vector_path = os.path.join(working_dir_path, '%s_seeds.gpkg' % ws_id) + * else: + * diagnostic_vector_path = None # <<<<<<<<<<<<<< + * seeds_in_watershed = _c_split_geometry_into_seeds( + * geom_wkb, + */ + /*else*/ { + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_diagnostic_vector_path, Py_None); + } + __pyx_L20:; + + /* "pygeoprocessing/routing/watershed.pyx":780 + * seeds_in_watershed = _c_split_geometry_into_seeds( + * geom_wkb, + * source_gt, # <<<<<<<<<<<<<< + * flow_dir_srs=flow_dir_srs, + * flow_dir_n_cols=flow_dir_n_cols, + */ + if (!(likely(PyTuple_CheckExact(__pyx_v_source_gt))||((__pyx_v_source_gt) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v_source_gt)->tp_name), 0))) __PYX_ERR(0, 780, __pyx_L1_error) + + /* "pygeoprocessing/routing/watershed.pyx":782 + * source_gt, + * flow_dir_srs=flow_dir_srs, + * flow_dir_n_cols=flow_dir_n_cols, # <<<<<<<<<<<<<< + * flow_dir_n_rows=flow_dir_n_rows, + * target_raster_path=seeds_raster_path, + */ + __pyx_t_19 = __Pyx_PyInt_From_int(__pyx_v_flow_dir_n_cols); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 782, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + + /* "pygeoprocessing/routing/watershed.pyx":783 + * flow_dir_srs=flow_dir_srs, + * flow_dir_n_cols=flow_dir_n_cols, + * flow_dir_n_rows=flow_dir_n_rows, # <<<<<<<<<<<<<< + * target_raster_path=seeds_raster_path, + * diagnostic_vector_path=diagnostic_vector_path + */ + __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_flow_dir_n_rows); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 783, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + + /* "pygeoprocessing/routing/watershed.pyx":778 + * else: + * diagnostic_vector_path = None + * seeds_in_watershed = _c_split_geometry_into_seeds( # <<<<<<<<<<<<<< + * geom_wkb, + * source_gt, + */ + __pyx_t_26.__pyx_n = 1; + __pyx_t_26.diagnostic_vector_path = __pyx_v_diagnostic_vector_path; + __pyx_t_25 = __pyx_f_15pygeoprocessing_7routing_9watershed__c_split_geometry_into_seeds(__pyx_v_geom_wkb, ((PyObject*)__pyx_v_source_gt), __pyx_v_flow_dir_srs, __pyx_t_19, __pyx_t_7, __pyx_v_seeds_raster_path, &__pyx_t_26); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_seeds_in_watershed = __pyx_t_25; + + /* "pygeoprocessing/routing/watershed.pyx":788 + * ) + * + * seed_iterator = seeds_in_watershed.begin() # <<<<<<<<<<<<<< + * while seed_iterator != seeds_in_watershed.end(): + * seed = deref(seed_iterator) + */ + __pyx_v_seed_iterator = __pyx_v_seeds_in_watershed.begin(); + + /* "pygeoprocessing/routing/watershed.pyx":789 + * + * seed_iterator = seeds_in_watershed.begin() + * while seed_iterator != seeds_in_watershed.end(): # <<<<<<<<<<<<<< + * seed = deref(seed_iterator) + * inc(seed_iterator) + */ + while (1) { + __pyx_t_5 = ((__pyx_v_seed_iterator != __pyx_v_seeds_in_watershed.end()) != 0); + if (!__pyx_t_5) break; + + /* "pygeoprocessing/routing/watershed.pyx":790 + * seed_iterator = seeds_in_watershed.begin() + * while seed_iterator != seeds_in_watershed.end(): + * seed = deref(seed_iterator) # <<<<<<<<<<<<<< + * inc(seed_iterator) + * + */ + __pyx_v_seed = (*__pyx_v_seed_iterator); + + /* "pygeoprocessing/routing/watershed.pyx":791 + * while seed_iterator != seeds_in_watershed.end(): + * seed = deref(seed_iterator) + * inc(seed_iterator) # <<<<<<<<<<<<<< + * + * if not 0 <= seed.first < flow_dir_n_cols: + */ + (void)((++__pyx_v_seed_iterator)); + + /* "pygeoprocessing/routing/watershed.pyx":793 + * inc(seed_iterator) + * + * if not 0 <= seed.first < flow_dir_n_cols: # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_5 = (0 <= __pyx_v_seed.first); + if (__pyx_t_5) { + __pyx_t_5 = (__pyx_v_seed.first < __pyx_v_flow_dir_n_cols); + } + __pyx_t_4 = ((!(__pyx_t_5 != 0)) != 0); + if (__pyx_t_4) { + + /* "pygeoprocessing/routing/watershed.pyx":794 + * + * if not 0 <= seed.first < flow_dir_n_cols: + * continue # <<<<<<<<<<<<<< + * + * if not 0 <= seed.second < flow_dir_n_rows: + */ + goto __pyx_L21_continue; + + /* "pygeoprocessing/routing/watershed.pyx":793 + * inc(seed_iterator) + * + * if not 0 <= seed.first < flow_dir_n_cols: # <<<<<<<<<<<<<< + * continue + * + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":796 + * continue + * + * if not 0 <= seed.second < flow_dir_n_rows: # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_4 = (0 <= __pyx_v_seed.second); + if (__pyx_t_4) { + __pyx_t_4 = (__pyx_v_seed.second < __pyx_v_flow_dir_n_rows); + } + __pyx_t_5 = ((!(__pyx_t_4 != 0)) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/watershed.pyx":797 + * + * if not 0 <= seed.second < flow_dir_n_rows: + * continue # <<<<<<<<<<<<<< + * + * if flow_dir_managed_raster.get(seed.first, seed.second) == flow_dir_nodata: + */ + goto __pyx_L21_continue; + + /* "pygeoprocessing/routing/watershed.pyx":796 + * continue + * + * if not 0 <= seed.second < flow_dir_n_rows: # <<<<<<<<<<<<<< + * continue + * + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":799 + * continue + * + * if flow_dir_managed_raster.get(seed.first, seed.second) == flow_dir_nodata: # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_5 = ((__pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_get(__pyx_v_flow_dir_managed_raster, __pyx_v_seed.first, __pyx_v_seed.second) == __pyx_v_flow_dir_nodata) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/watershed.pyx":800 + * + * if flow_dir_managed_raster.get(seed.first, seed.second) == flow_dir_nodata: + * continue # <<<<<<<<<<<<<< + * + * process_queue.push(seed) + */ + goto __pyx_L21_continue; + + /* "pygeoprocessing/routing/watershed.pyx":799 + * continue + * + * if flow_dir_managed_raster.get(seed.first, seed.second) == flow_dir_nodata: # <<<<<<<<<<<<<< + * continue + * + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":802 + * continue + * + * process_queue.push(seed) # <<<<<<<<<<<<<< + * process_queue_set.insert(seed) + * + */ + __pyx_v_process_queue.push(__pyx_v_seed); + + /* "pygeoprocessing/routing/watershed.pyx":803 + * + * process_queue.push(seed) + * process_queue_set.insert(seed) # <<<<<<<<<<<<<< + * + * if process_queue_set.size() == 0: + */ + try { + __pyx_v_process_queue_set.insert(__pyx_v_seed); + } catch(...) { + __Pyx_CppExn2PyErr(); + __PYX_ERR(0, 803, __pyx_L1_error) + } + __pyx_L21_continue:; + } + + /* "pygeoprocessing/routing/watershed.pyx":805 + * process_queue_set.insert(seed) + * + * if process_queue_set.size() == 0: # <<<<<<<<<<<<<< + * LOGGER.debug( + * 'Outflow feature %s does not intersect any pixels with ' + */ + __pyx_t_5 = ((__pyx_v_process_queue_set.size() == 0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/watershed.pyx":806 + * + * if process_queue_set.size() == 0: + * LOGGER.debug( # <<<<<<<<<<<<<< + * 'Outflow feature %s does not intersect any pixels with ' + * 'valid flow direction. Skipping.', current_fid) + */ + __Pyx_GetModuleGlobalName(__pyx_t_19, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 806, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_n_s_debug); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 806, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":808 + * LOGGER.debug( + * 'Outflow feature %s does not intersect any pixels with ' + * 'valid flow direction. Skipping.', current_fid) # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_19 = __Pyx_PyInt_From_int(__pyx_v_current_fid); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 808, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_18 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_18 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_18)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_18); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[3] = {__pyx_t_18, __pyx_kp_u_Outflow_feature_s_does_not_inter, __pyx_t_19}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 806, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[3] = {__pyx_t_18, __pyx_kp_u_Outflow_feature_s_does_not_inter, __pyx_t_19}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 806, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + } else + #endif + { + __pyx_t_12 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 806, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + if (__pyx_t_18) { + __Pyx_GIVEREF(__pyx_t_18); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_18); __pyx_t_18 = NULL; + } + __Pyx_INCREF(__pyx_kp_u_Outflow_feature_s_does_not_inter); + __Pyx_GIVEREF(__pyx_kp_u_Outflow_feature_s_does_not_inter); + PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_9, __pyx_kp_u_Outflow_feature_s_does_not_inter); + __Pyx_GIVEREF(__pyx_t_19); + PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_9, __pyx_t_19); + __pyx_t_19 = 0; + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_12, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 806, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":809 + * 'Outflow feature %s does not intersect any pixels with ' + * 'valid flow direction. Skipping.', current_fid) + * continue # <<<<<<<<<<<<<< + * + * scratch_raster_path = os.path.join(working_dir_path, + */ + goto __pyx_L16_continue; + + /* "pygeoprocessing/routing/watershed.pyx":805 + * process_queue_set.insert(seed) + * + * if process_queue_set.size() == 0: # <<<<<<<<<<<<<< + * LOGGER.debug( + * 'Outflow feature %s does not intersect any pixels with ' + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":811 + * continue + * + * scratch_raster_path = os.path.join(working_dir_path, # <<<<<<<<<<<<<< + * '%s_scratch.tif' % ws_id) + * scratch_raster = gtiff_driver.Create( + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_os); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 811, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_path); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 811, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_join); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 811, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":812 + * + * scratch_raster_path = os.path.join(working_dir_path, + * '%s_scratch.tif' % ws_id) # <<<<<<<<<<<<<< + * scratch_raster = gtiff_driver.Create( + * scratch_raster_path, + */ + __pyx_t_12 = __Pyx_PyInt_From_int(__pyx_v_ws_id); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 812, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_19 = PyUnicode_Format(__pyx_kp_u_s_scratch_tif, __pyx_t_12); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 812, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_12)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_v_working_dir_path, __pyx_t_19}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 811, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_v_working_dir_path, __pyx_t_19}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 811, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + } else + #endif + { + __pyx_t_18 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 811, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + if (__pyx_t_12) { + __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_12); __pyx_t_12 = NULL; + } + __Pyx_INCREF(__pyx_v_working_dir_path); + __Pyx_GIVEREF(__pyx_v_working_dir_path); + PyTuple_SET_ITEM(__pyx_t_18, 0+__pyx_t_9, __pyx_v_working_dir_path); + __Pyx_GIVEREF(__pyx_t_19); + PyTuple_SET_ITEM(__pyx_t_18, 1+__pyx_t_9, __pyx_t_19); + __pyx_t_19 = 0; + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_18, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 811, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + } + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF_SET(__pyx_v_scratch_raster_path, __pyx_t_7); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":813 + * scratch_raster_path = os.path.join(working_dir_path, + * '%s_scratch.tif' % ws_id) + * scratch_raster = gtiff_driver.Create( # <<<<<<<<<<<<<< + * scratch_raster_path, + * flow_dir_n_cols, + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_gtiff_driver, __pyx_n_s_Create); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 813, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + + /* "pygeoprocessing/routing/watershed.pyx":815 + * scratch_raster = gtiff_driver.Create( + * scratch_raster_path, + * flow_dir_n_cols, # <<<<<<<<<<<<<< + * flow_dir_n_rows, + * 1, # n bands + */ + __pyx_t_11 = __Pyx_PyInt_From_int(__pyx_v_flow_dir_n_cols); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 815, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + + /* "pygeoprocessing/routing/watershed.pyx":816 + * scratch_raster_path, + * flow_dir_n_cols, + * flow_dir_n_rows, # <<<<<<<<<<<<<< + * 1, # n bands + * gdal.GDT_UInt32, + */ + __pyx_t_18 = __Pyx_PyInt_From_int(__pyx_v_flow_dir_n_rows); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 816, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + + /* "pygeoprocessing/routing/watershed.pyx":818 + * flow_dir_n_rows, + * 1, # n bands + * gdal.GDT_UInt32, # <<<<<<<<<<<<<< + * options=GTIFF_CREATION_OPTIONS) + * scratch_raster.SetGeoTransform(source_gt) + */ + __Pyx_GetModuleGlobalName(__pyx_t_19, __pyx_n_s_gdal); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 818, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_n_s_GDT_UInt32); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 818, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":813 + * scratch_raster_path = os.path.join(working_dir_path, + * '%s_scratch.tif' % ws_id) + * scratch_raster = gtiff_driver.Create( # <<<<<<<<<<<<<< + * scratch_raster_path, + * flow_dir_n_cols, + */ + __pyx_t_19 = PyTuple_New(5); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 813, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_INCREF(__pyx_v_scratch_raster_path); + __Pyx_GIVEREF(__pyx_v_scratch_raster_path); + PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_v_scratch_raster_path); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_19, 1, __pyx_t_11); + __Pyx_GIVEREF(__pyx_t_18); + PyTuple_SET_ITEM(__pyx_t_19, 2, __pyx_t_18); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_19, 3, __pyx_int_1); + __Pyx_GIVEREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_19, 4, __pyx_t_12); + __pyx_t_11 = 0; + __pyx_t_18 = 0; + __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":819 + * 1, # n bands + * gdal.GDT_UInt32, + * options=GTIFF_CREATION_OPTIONS) # <<<<<<<<<<<<<< + * scratch_raster.SetGeoTransform(source_gt) + * scratch_raster.SetProjection(flow_dir_info['projection_wkt']) + */ + __pyx_t_12 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 819, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_GetModuleGlobalName(__pyx_t_18, __pyx_n_s_GTIFF_CREATION_OPTIONS); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 819, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_options, __pyx_t_18) < 0) __PYX_ERR(0, 819, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":813 + * scratch_raster_path = os.path.join(working_dir_path, + * '%s_scratch.tif' % ws_id) + * scratch_raster = gtiff_driver.Create( # <<<<<<<<<<<<<< + * scratch_raster_path, + * flow_dir_n_cols, + */ + __pyx_t_18 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_19, __pyx_t_12); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 813, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF_SET(__pyx_v_scratch_raster, __pyx_t_18); + __pyx_t_18 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":820 + * gdal.GDT_UInt32, + * options=GTIFF_CREATION_OPTIONS) + * scratch_raster.SetGeoTransform(source_gt) # <<<<<<<<<<<<<< + * scratch_raster.SetProjection(flow_dir_info['projection_wkt']) + * # strictly speaking, there's no need to set the nodata value on the band. + */ + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_scratch_raster, __pyx_n_s_SetGeoTransform); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 820, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_19 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_19)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_19); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + } + } + __pyx_t_18 = (__pyx_t_19) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_19, __pyx_v_source_gt) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_v_source_gt); + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 820, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":821 + * options=GTIFF_CREATION_OPTIONS) + * scratch_raster.SetGeoTransform(source_gt) + * scratch_raster.SetProjection(flow_dir_info['projection_wkt']) # <<<<<<<<<<<<<< + * # strictly speaking, there's no need to set the nodata value on the band. + * scratch_raster = None + */ + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_scratch_raster, __pyx_n_s_SetProjection); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 821, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_19 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_projection_wkt); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 821, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + } + } + __pyx_t_18 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_7, __pyx_t_19) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_19); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 821, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":823 + * scratch_raster.SetProjection(flow_dir_info['projection_wkt']) + * # strictly speaking, there's no need to set the nodata value on the band. + * scratch_raster = None # <<<<<<<<<<<<<< + * + * scratch_managed_raster = _ManagedRaster(scratch_raster_path, 1, 1) + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_scratch_raster, Py_None); + + /* "pygeoprocessing/routing/watershed.pyx":825 + * scratch_raster = None + * + * scratch_managed_raster = _ManagedRaster(scratch_raster_path, 1, 1) # <<<<<<<<<<<<<< + * ix_min = flow_dir_n_cols + * iy_min = flow_dir_n_rows + */ + __pyx_t_18 = PyTuple_New(3); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 825, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_INCREF(__pyx_v_scratch_raster_path); + __Pyx_GIVEREF(__pyx_v_scratch_raster_path); + PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_v_scratch_raster_path); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_18, 1, __pyx_int_1); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_18, 2, __pyx_int_1); + __pyx_t_12 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_9watershed__ManagedRaster), __pyx_t_18, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 825, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __Pyx_XDECREF_SET(__pyx_v_scratch_managed_raster, ((struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *)__pyx_t_12)); + __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":826 + * + * scratch_managed_raster = _ManagedRaster(scratch_raster_path, 1, 1) + * ix_min = flow_dir_n_cols # <<<<<<<<<<<<<< + * iy_min = flow_dir_n_rows + * ix_max = 0 + */ + __pyx_v_ix_min = __pyx_v_flow_dir_n_cols; + + /* "pygeoprocessing/routing/watershed.pyx":827 + * scratch_managed_raster = _ManagedRaster(scratch_raster_path, 1, 1) + * ix_min = flow_dir_n_cols + * iy_min = flow_dir_n_rows # <<<<<<<<<<<<<< + * ix_max = 0 + * iy_max = 0 + */ + __pyx_v_iy_min = __pyx_v_flow_dir_n_rows; + + /* "pygeoprocessing/routing/watershed.pyx":828 + * ix_min = flow_dir_n_cols + * iy_min = flow_dir_n_rows + * ix_max = 0 # <<<<<<<<<<<<<< + * iy_max = 0 + * n_cells_visited = 0 + */ + __pyx_v_ix_max = 0; + + /* "pygeoprocessing/routing/watershed.pyx":829 + * iy_min = flow_dir_n_rows + * ix_max = 0 + * iy_max = 0 # <<<<<<<<<<<<<< + * n_cells_visited = 0 + * LOGGER.info( + */ + __pyx_v_iy_max = 0; + + /* "pygeoprocessing/routing/watershed.pyx":830 + * ix_max = 0 + * iy_max = 0 + * n_cells_visited = 0 # <<<<<<<<<<<<<< + * LOGGER.info( + * 'Delineating watershed %s of %s (ws_id %s)', + */ + __pyx_v_n_cells_visited = 0; + + /* "pygeoprocessing/routing/watershed.pyx":831 + * iy_max = 0 + * n_cells_visited = 0 + * LOGGER.info( # <<<<<<<<<<<<<< + * 'Delineating watershed %s of %s (ws_id %s)', + * current_fid, outflow_feature_count, ws_id) + */ + __Pyx_GetModuleGlobalName(__pyx_t_18, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 831, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_t_18, __pyx_n_s_info); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 831, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":833 + * LOGGER.info( + * 'Delineating watershed %s of %s (ws_id %s)', + * current_fid, outflow_feature_count, ws_id) # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * while not process_queue.empty(): + */ + __pyx_t_18 = __Pyx_PyInt_From_int(__pyx_v_current_fid); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 833, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_outflow_feature_count); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 833, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_11 = __Pyx_PyInt_From_int(__pyx_v_ws_id); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 833, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_17 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_19))) { + __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_19); + if (likely(__pyx_t_17)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19); + __Pyx_INCREF(__pyx_t_17); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_19, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_19)) { + PyObject *__pyx_temp[5] = {__pyx_t_17, __pyx_kp_u_Delineating_watershed_s_of_s_ws, __pyx_t_18, __pyx_t_7, __pyx_t_11}; + __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_19, __pyx_temp+1-__pyx_t_9, 4+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 831, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_19)) { + PyObject *__pyx_temp[5] = {__pyx_t_17, __pyx_kp_u_Delineating_watershed_s_of_s_ws, __pyx_t_18, __pyx_t_7, __pyx_t_11}; + __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_19, __pyx_temp+1-__pyx_t_9, 4+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 831, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } else + #endif + { + __pyx_t_13 = PyTuple_New(4+__pyx_t_9); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 831, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + if (__pyx_t_17) { + __Pyx_GIVEREF(__pyx_t_17); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_17); __pyx_t_17 = NULL; + } + __Pyx_INCREF(__pyx_kp_u_Delineating_watershed_s_of_s_ws); + __Pyx_GIVEREF(__pyx_kp_u_Delineating_watershed_s_of_s_ws); + PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_9, __pyx_kp_u_Delineating_watershed_s_of_s_ws); + __Pyx_GIVEREF(__pyx_t_18); + PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_9, __pyx_t_18); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_13, 2+__pyx_t_9, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_13, 3+__pyx_t_9, __pyx_t_11); + __pyx_t_18 = 0; + __pyx_t_7 = 0; + __pyx_t_11 = 0; + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_19, __pyx_t_13, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 831, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + } + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":834 + * 'Delineating watershed %s of %s (ws_id %s)', + * current_fid, outflow_feature_count, ws_id) + * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< + * while not process_queue.empty(): + * if ctime(NULL) - last_log_time > 5.0: + */ + __pyx_v_last_log_time = time(NULL); + + /* "pygeoprocessing/routing/watershed.pyx":835 + * current_fid, outflow_feature_count, ws_id) + * last_log_time = ctime(NULL) + * while not process_queue.empty(): # <<<<<<<<<<<<<< + * if ctime(NULL) - last_log_time > 5.0: + * last_log_time = ctime(NULL) + */ + while (1) { + __pyx_t_5 = ((!(__pyx_v_process_queue.empty() != 0)) != 0); + if (!__pyx_t_5) break; + + /* "pygeoprocessing/routing/watershed.pyx":836 + * last_log_time = ctime(NULL) + * while not process_queue.empty(): + * if ctime(NULL) - last_log_time > 5.0: # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * LOGGER.info( + */ + __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > 5.0) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/watershed.pyx":837 + * while not process_queue.empty(): + * if ctime(NULL) - last_log_time > 5.0: + * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< + * LOGGER.info( + * 'Delineating watershed %s of %s (ws_id %s), %s pixels ' + */ + __pyx_v_last_log_time = time(NULL); + + /* "pygeoprocessing/routing/watershed.pyx":838 + * if ctime(NULL) - last_log_time > 5.0: + * last_log_time = ctime(NULL) + * LOGGER.info( # <<<<<<<<<<<<<< + * 'Delineating watershed %s of %s (ws_id %s), %s pixels ' + * 'found so far', current_fid, outflow_feature_count, + */ + __Pyx_GetModuleGlobalName(__pyx_t_19, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 838, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_n_s_info); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 838, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":840 + * LOGGER.info( + * 'Delineating watershed %s of %s (ws_id %s), %s pixels ' + * 'found so far', current_fid, outflow_feature_count, # <<<<<<<<<<<<<< + * ws_id, n_cells_visited) + * + */ + __pyx_t_19 = __Pyx_PyInt_From_int(__pyx_v_current_fid); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 840, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_11 = __Pyx_PyInt_From_int(__pyx_v_outflow_feature_count); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 840, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + + /* "pygeoprocessing/routing/watershed.pyx":841 + * 'Delineating watershed %s of %s (ws_id %s), %s pixels ' + * 'found so far', current_fid, outflow_feature_count, + * ws_id, n_cells_visited) # <<<<<<<<<<<<<< + * + * current_pixel = process_queue.front() + */ + __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_ws_id); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 841, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_18 = __Pyx_PyInt_From_int(__pyx_v_n_cells_visited); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 841, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + __pyx_t_17 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_13))) { + __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_13); + if (likely(__pyx_t_17)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); + __Pyx_INCREF(__pyx_t_17); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_13, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_13)) { + PyObject *__pyx_temp[6] = {__pyx_t_17, __pyx_kp_u_Delineating_watershed_s_of_s_ws_2, __pyx_t_19, __pyx_t_11, __pyx_t_7, __pyx_t_18}; + __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_9, 5+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 838, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_13)) { + PyObject *__pyx_temp[6] = {__pyx_t_17, __pyx_kp_u_Delineating_watershed_s_of_s_ws_2, __pyx_t_19, __pyx_t_11, __pyx_t_7, __pyx_t_18}; + __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_9, 5+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 838, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + } else + #endif + { + __pyx_t_10 = PyTuple_New(5+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 838, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + if (__pyx_t_17) { + __Pyx_GIVEREF(__pyx_t_17); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_17); __pyx_t_17 = NULL; + } + __Pyx_INCREF(__pyx_kp_u_Delineating_watershed_s_of_s_ws_2); + __Pyx_GIVEREF(__pyx_kp_u_Delineating_watershed_s_of_s_ws_2); + PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_kp_u_Delineating_watershed_s_of_s_ws_2); + __Pyx_GIVEREF(__pyx_t_19); + PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_t_19); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_10, 2+__pyx_t_9, __pyx_t_11); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_10, 3+__pyx_t_9, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_18); + PyTuple_SET_ITEM(__pyx_t_10, 4+__pyx_t_9, __pyx_t_18); + __pyx_t_19 = 0; + __pyx_t_11 = 0; + __pyx_t_7 = 0; + __pyx_t_18 = 0; + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_10, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 838, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":836 + * last_log_time = ctime(NULL) + * while not process_queue.empty(): + * if ctime(NULL) - last_log_time > 5.0: # <<<<<<<<<<<<<< + * last_log_time = ctime(NULL) + * LOGGER.info( + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":843 + * ws_id, n_cells_visited) + * + * current_pixel = process_queue.front() # <<<<<<<<<<<<<< + * process_queue_set.erase(current_pixel) + * process_queue.pop() + */ + __pyx_v_current_pixel = __pyx_v_process_queue.front(); + + /* "pygeoprocessing/routing/watershed.pyx":844 + * + * current_pixel = process_queue.front() + * process_queue_set.erase(current_pixel) # <<<<<<<<<<<<<< + * process_queue.pop() + * + */ + (void)(__pyx_v_process_queue_set.erase(__pyx_v_current_pixel)); + + /* "pygeoprocessing/routing/watershed.pyx":845 + * current_pixel = process_queue.front() + * process_queue_set.erase(current_pixel) + * process_queue.pop() # <<<<<<<<<<<<<< + * + * scratch_managed_raster.set(current_pixel.first, + */ + __pyx_v_process_queue.pop(); + + /* "pygeoprocessing/routing/watershed.pyx":847 + * process_queue.pop() + * + * scratch_managed_raster.set(current_pixel.first, # <<<<<<<<<<<<<< + * current_pixel.second, ws_id) + * n_cells_visited += 1 + */ + __pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_set(__pyx_v_scratch_managed_raster, __pyx_v_current_pixel.first, __pyx_v_current_pixel.second, __pyx_v_ws_id); + + /* "pygeoprocessing/routing/watershed.pyx":849 + * scratch_managed_raster.set(current_pixel.first, + * current_pixel.second, ws_id) + * n_cells_visited += 1 # <<<<<<<<<<<<<< + * + * # These are for tracking the extents of the raster so we can build + */ + __pyx_v_n_cells_visited = (__pyx_v_n_cells_visited + 1); + + /* "pygeoprocessing/routing/watershed.pyx":853 + * # These are for tracking the extents of the raster so we can build + * # a VRT and only polygonize the pixels we need to. + * ix_min = min(ix_min, current_pixel.first) # <<<<<<<<<<<<<< + * iy_min = min(iy_min, current_pixel.second) + * ix_max = max(ix_max, current_pixel.first) + */ + __pyx_t_27 = __pyx_v_current_pixel.first; + __pyx_t_9 = __pyx_v_ix_min; + if (((__pyx_t_27 < __pyx_t_9) != 0)) { + __pyx_t_28 = __pyx_t_27; + } else { + __pyx_t_28 = __pyx_t_9; + } + __pyx_v_ix_min = __pyx_t_28; + + /* "pygeoprocessing/routing/watershed.pyx":854 + * # a VRT and only polygonize the pixels we need to. + * ix_min = min(ix_min, current_pixel.first) + * iy_min = min(iy_min, current_pixel.second) # <<<<<<<<<<<<<< + * ix_max = max(ix_max, current_pixel.first) + * iy_max = max(iy_max, current_pixel.second) + */ + __pyx_t_28 = __pyx_v_current_pixel.second; + __pyx_t_9 = __pyx_v_iy_min; + if (((__pyx_t_28 < __pyx_t_9) != 0)) { + __pyx_t_27 = __pyx_t_28; + } else { + __pyx_t_27 = __pyx_t_9; + } + __pyx_v_iy_min = __pyx_t_27; + + /* "pygeoprocessing/routing/watershed.pyx":855 + * ix_min = min(ix_min, current_pixel.first) + * iy_min = min(iy_min, current_pixel.second) + * ix_max = max(ix_max, current_pixel.first) # <<<<<<<<<<<<<< + * iy_max = max(iy_max, current_pixel.second) + * + */ + __pyx_t_27 = __pyx_v_current_pixel.first; + __pyx_t_9 = __pyx_v_ix_max; + if (((__pyx_t_27 > __pyx_t_9) != 0)) { + __pyx_t_28 = __pyx_t_27; + } else { + __pyx_t_28 = __pyx_t_9; + } + __pyx_v_ix_max = __pyx_t_28; + + /* "pygeoprocessing/routing/watershed.pyx":856 + * iy_min = min(iy_min, current_pixel.second) + * ix_max = max(ix_max, current_pixel.first) + * iy_max = max(iy_max, current_pixel.second) # <<<<<<<<<<<<<< + * + * for neighbor_index in range(8): + */ + __pyx_t_28 = __pyx_v_current_pixel.second; + __pyx_t_9 = __pyx_v_iy_max; + if (((__pyx_t_28 > __pyx_t_9) != 0)) { + __pyx_t_27 = __pyx_t_28; + } else { + __pyx_t_27 = __pyx_t_9; + } + __pyx_v_iy_max = __pyx_t_27; + + /* "pygeoprocessing/routing/watershed.pyx":858 + * iy_max = max(iy_max, current_pixel.second) + * + * for neighbor_index in range(8): # <<<<<<<<<<<<<< + * neighbor_pixel = CoordinatePair( + * current_pixel.first + neighbor_col[neighbor_index], + */ + for (__pyx_t_27 = 0; __pyx_t_27 < 8; __pyx_t_27+=1) { + __pyx_v_neighbor_index = __pyx_t_27; + + /* "pygeoprocessing/routing/watershed.pyx":859 + * + * for neighbor_index in range(8): + * neighbor_pixel = CoordinatePair( # <<<<<<<<<<<<<< + * current_pixel.first + neighbor_col[neighbor_index], + * current_pixel.second + neighbor_row[neighbor_index]) + */ + try { + __pyx_t_29 = __pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair((__pyx_v_current_pixel.first + (__pyx_v_neighbor_col[__pyx_v_neighbor_index])), (__pyx_v_current_pixel.second + (__pyx_v_neighbor_row[__pyx_v_neighbor_index]))); + } catch(...) { + __Pyx_CppExn2PyErr(); + __PYX_ERR(0, 859, __pyx_L1_error) + } + __pyx_v_neighbor_pixel = __pyx_t_29; + + /* "pygeoprocessing/routing/watershed.pyx":863 + * current_pixel.second + neighbor_row[neighbor_index]) + * + * if not 0 <= neighbor_pixel.first < flow_dir_n_cols: # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_5 = (0 <= __pyx_v_neighbor_pixel.first); + if (__pyx_t_5) { + __pyx_t_5 = (__pyx_v_neighbor_pixel.first < __pyx_v_flow_dir_n_cols); + } + __pyx_t_4 = ((!(__pyx_t_5 != 0)) != 0); + if (__pyx_t_4) { + + /* "pygeoprocessing/routing/watershed.pyx":864 + * + * if not 0 <= neighbor_pixel.first < flow_dir_n_cols: + * continue # <<<<<<<<<<<<<< + * + * if not 0 <= neighbor_pixel.second < flow_dir_n_rows: + */ + goto __pyx_L30_continue; + + /* "pygeoprocessing/routing/watershed.pyx":863 + * current_pixel.second + neighbor_row[neighbor_index]) + * + * if not 0 <= neighbor_pixel.first < flow_dir_n_cols: # <<<<<<<<<<<<<< + * continue + * + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":866 + * continue + * + * if not 0 <= neighbor_pixel.second < flow_dir_n_rows: # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_4 = (0 <= __pyx_v_neighbor_pixel.second); + if (__pyx_t_4) { + __pyx_t_4 = (__pyx_v_neighbor_pixel.second < __pyx_v_flow_dir_n_rows); + } + __pyx_t_5 = ((!(__pyx_t_4 != 0)) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/watershed.pyx":867 + * + * if not 0 <= neighbor_pixel.second < flow_dir_n_rows: + * continue # <<<<<<<<<<<<<< + * + * # If we've already enqueued the neighbor (either it's + */ + goto __pyx_L30_continue; + + /* "pygeoprocessing/routing/watershed.pyx":866 + * continue + * + * if not 0 <= neighbor_pixel.second < flow_dir_n_rows: # <<<<<<<<<<<<<< + * continue + * + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":872 + * # upstream of another pixel or it's a watershed seed), we + * # don't need to re-enqueue it. + * if (process_queue_set.find(neighbor_pixel) != # <<<<<<<<<<<<<< + * process_queue_set.end()): + * continue + */ + __pyx_t_5 = ((__pyx_v_process_queue_set.find(__pyx_v_neighbor_pixel) != __pyx_v_process_queue_set.end()) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/watershed.pyx":874 + * if (process_queue_set.find(neighbor_pixel) != + * process_queue_set.end()): + * continue # <<<<<<<<<<<<<< + * + * # If the neighbor is known to be a seed, we don't need to + */ + goto __pyx_L30_continue; + + /* "pygeoprocessing/routing/watershed.pyx":872 + * # upstream of another pixel or it's a watershed seed), we + * # don't need to re-enqueue it. + * if (process_queue_set.find(neighbor_pixel) != # <<<<<<<<<<<<<< + * process_queue_set.end()): + * continue + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":879 + * # re-enqueue it either. Either it's been visited already (and + * # may have upstream pixels) or it's going to be. + * if (seeds_in_watershed.find(neighbor_pixel) != # <<<<<<<<<<<<<< + * seeds_in_watershed.end()): + * continue + */ + __pyx_t_5 = ((__pyx_v_seeds_in_watershed.find(__pyx_v_neighbor_pixel) != __pyx_v_seeds_in_watershed.end()) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/watershed.pyx":881 + * if (seeds_in_watershed.find(neighbor_pixel) != + * seeds_in_watershed.end()): + * continue # <<<<<<<<<<<<<< + * + * # Does the neighbor flow into this pixel? + */ + goto __pyx_L30_continue; + + /* "pygeoprocessing/routing/watershed.pyx":879 + * # re-enqueue it either. Either it's been visited already (and + * # may have upstream pixels) or it's going to be. + * if (seeds_in_watershed.find(neighbor_pixel) != # <<<<<<<<<<<<<< + * seeds_in_watershed.end()): + * continue + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":885 + * # Does the neighbor flow into this pixel? + * # If yes, enqueue it. + * if (reverse_flow[neighbor_index] == # <<<<<<<<<<<<<< + * flow_dir_managed_raster.get( + * neighbor_pixel.first, neighbor_pixel.second)): + */ + __pyx_t_5 = (((__pyx_v_reverse_flow[__pyx_v_neighbor_index]) == __pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_get(__pyx_v_flow_dir_managed_raster, __pyx_v_neighbor_pixel.first, __pyx_v_neighbor_pixel.second)) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/watershed.pyx":888 + * flow_dir_managed_raster.get( + * neighbor_pixel.first, neighbor_pixel.second)): + * process_queue.push(neighbor_pixel) # <<<<<<<<<<<<<< + * process_queue_set.insert(neighbor_pixel) + * + */ + __pyx_v_process_queue.push(__pyx_v_neighbor_pixel); + + /* "pygeoprocessing/routing/watershed.pyx":889 + * neighbor_pixel.first, neighbor_pixel.second)): + * process_queue.push(neighbor_pixel) + * process_queue_set.insert(neighbor_pixel) # <<<<<<<<<<<<<< + * + * watersheds_created += 1 + */ + try { + __pyx_v_process_queue_set.insert(__pyx_v_neighbor_pixel); + } catch(...) { + __Pyx_CppExn2PyErr(); + __PYX_ERR(0, 889, __pyx_L1_error) + } + + /* "pygeoprocessing/routing/watershed.pyx":885 + * # Does the neighbor flow into this pixel? + * # If yes, enqueue it. + * if (reverse_flow[neighbor_index] == # <<<<<<<<<<<<<< + * flow_dir_managed_raster.get( + * neighbor_pixel.first, neighbor_pixel.second)): + */ + } + __pyx_L30_continue:; + } + } + + /* "pygeoprocessing/routing/watershed.pyx":891 + * process_queue_set.insert(neighbor_pixel) + * + * watersheds_created += 1 # <<<<<<<<<<<<<< + * scratch_managed_raster.close() + * + */ + __pyx_v_watersheds_created = (__pyx_v_watersheds_created + 1); + + /* "pygeoprocessing/routing/watershed.pyx":892 + * + * watersheds_created += 1 + * scratch_managed_raster.close() # <<<<<<<<<<<<<< + * + * # Build a VRT from the bounds of the affected pixels before + */ + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_scratch_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 892, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_10 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_13); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_13, function); + } + } + __pyx_t_12 = (__pyx_t_10) ? __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_10) : __Pyx_PyObject_CallNoArg(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 892, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":898 + * # raster, this yields a large speedup because we don't have to read in + * # the whole scratch raster in order to polygonize. + * x1 = (flow_dir_origin_x + (max(ix_min-1, 0)*flow_dir_pixelsize_x)) # minx # <<<<<<<<<<<<<< + * y1 = (flow_dir_origin_y + (max(iy_min-1, 0)*flow_dir_pixelsize_y)) # miny + * x2 = (flow_dir_origin_x + (min(ix_max+1, flow_dir_n_cols)*flow_dir_pixelsize_x)) # maxx + */ + __pyx_t_27 = 0; + __pyx_t_28 = (__pyx_v_ix_min - 1); + if (((__pyx_t_27 > __pyx_t_28) != 0)) { + __pyx_t_30 = __pyx_t_27; + } else { + __pyx_t_30 = __pyx_t_28; + } + __pyx_v_x1 = (__pyx_v_flow_dir_origin_x + (__pyx_t_30 * __pyx_v_flow_dir_pixelsize_x)); + + /* "pygeoprocessing/routing/watershed.pyx":899 + * # the whole scratch raster in order to polygonize. + * x1 = (flow_dir_origin_x + (max(ix_min-1, 0)*flow_dir_pixelsize_x)) # minx + * y1 = (flow_dir_origin_y + (max(iy_min-1, 0)*flow_dir_pixelsize_y)) # miny # <<<<<<<<<<<<<< + * x2 = (flow_dir_origin_x + (min(ix_max+1, flow_dir_n_cols)*flow_dir_pixelsize_x)) # maxx + * y2 = (flow_dir_origin_y + (min(iy_max+1, flow_dir_n_rows)*flow_dir_pixelsize_y)) # maxy + */ + __pyx_t_30 = 0; + __pyx_t_27 = (__pyx_v_iy_min - 1); + if (((__pyx_t_30 > __pyx_t_27) != 0)) { + __pyx_t_28 = __pyx_t_30; + } else { + __pyx_t_28 = __pyx_t_27; + } + __pyx_v_y1 = (__pyx_v_flow_dir_origin_y + (__pyx_t_28 * __pyx_v_flow_dir_pixelsize_y)); + + /* "pygeoprocessing/routing/watershed.pyx":900 + * x1 = (flow_dir_origin_x + (max(ix_min-1, 0)*flow_dir_pixelsize_x)) # minx + * y1 = (flow_dir_origin_y + (max(iy_min-1, 0)*flow_dir_pixelsize_y)) # miny + * x2 = (flow_dir_origin_x + (min(ix_max+1, flow_dir_n_cols)*flow_dir_pixelsize_x)) # maxx # <<<<<<<<<<<<<< + * y2 = (flow_dir_origin_y + (min(iy_max+1, flow_dir_n_rows)*flow_dir_pixelsize_y)) # maxy + * + */ + __pyx_t_9 = __pyx_v_flow_dir_n_cols; + __pyx_t_28 = (__pyx_v_ix_max + 1); + if (((__pyx_t_9 < __pyx_t_28) != 0)) { + __pyx_t_30 = __pyx_t_9; + } else { + __pyx_t_30 = __pyx_t_28; + } + __pyx_v_x2 = (__pyx_v_flow_dir_origin_x + (__pyx_t_30 * __pyx_v_flow_dir_pixelsize_x)); + + /* "pygeoprocessing/routing/watershed.pyx":901 + * y1 = (flow_dir_origin_y + (max(iy_min-1, 0)*flow_dir_pixelsize_y)) # miny + * x2 = (flow_dir_origin_x + (min(ix_max+1, flow_dir_n_cols)*flow_dir_pixelsize_x)) # maxx + * y2 = (flow_dir_origin_y + (min(iy_max+1, flow_dir_n_rows)*flow_dir_pixelsize_y)) # maxy # <<<<<<<<<<<<<< + * + * vrt_options = gdal.BuildVRTOptions( + */ + __pyx_t_9 = __pyx_v_flow_dir_n_rows; + __pyx_t_30 = (__pyx_v_iy_max + 1); + if (((__pyx_t_9 < __pyx_t_30) != 0)) { + __pyx_t_28 = __pyx_t_9; + } else { + __pyx_t_28 = __pyx_t_30; + } + __pyx_v_y2 = (__pyx_v_flow_dir_origin_y + (__pyx_t_28 * __pyx_v_flow_dir_pixelsize_y)); + + /* "pygeoprocessing/routing/watershed.pyx":903 + * y2 = (flow_dir_origin_y + (min(iy_max+1, flow_dir_n_rows)*flow_dir_pixelsize_y)) # maxy + * + * vrt_options = gdal.BuildVRTOptions( # <<<<<<<<<<<<<< + * outputBounds=( + * min(x1, x2), + */ + __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_gdal); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 903, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_BuildVRTOptions); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 903, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":904 + * + * vrt_options = gdal.BuildVRTOptions( + * outputBounds=( # <<<<<<<<<<<<<< + * min(x1, x2), + * min(y1, y2), + */ + __pyx_t_12 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 904, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + + /* "pygeoprocessing/routing/watershed.pyx":905 + * vrt_options = gdal.BuildVRTOptions( + * outputBounds=( + * min(x1, x2), # <<<<<<<<<<<<<< + * min(y1, y2), + * max(x1, x2), + */ + __pyx_t_15 = __pyx_v_x2; + __pyx_t_31 = __pyx_v_x1; + if (((__pyx_t_15 < __pyx_t_31) != 0)) { + __pyx_t_32 = __pyx_t_15; + } else { + __pyx_t_32 = __pyx_t_31; + } + __pyx_t_10 = PyFloat_FromDouble(__pyx_t_32); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 905, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + + /* "pygeoprocessing/routing/watershed.pyx":906 + * outputBounds=( + * min(x1, x2), + * min(y1, y2), # <<<<<<<<<<<<<< + * max(x1, x2), + * max(y1, y2)) + */ + __pyx_t_32 = __pyx_v_y2; + __pyx_t_15 = __pyx_v_y1; + if (((__pyx_t_32 < __pyx_t_15) != 0)) { + __pyx_t_31 = __pyx_t_32; + } else { + __pyx_t_31 = __pyx_t_15; + } + __pyx_t_18 = PyFloat_FromDouble(__pyx_t_31); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 906, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_18); + + /* "pygeoprocessing/routing/watershed.pyx":907 + * min(x1, x2), + * min(y1, y2), + * max(x1, x2), # <<<<<<<<<<<<<< + * max(y1, y2)) + * ) + */ + __pyx_t_31 = __pyx_v_x2; + __pyx_t_32 = __pyx_v_x1; + if (((__pyx_t_31 > __pyx_t_32) != 0)) { + __pyx_t_15 = __pyx_t_31; + } else { + __pyx_t_15 = __pyx_t_32; + } + __pyx_t_7 = PyFloat_FromDouble(__pyx_t_15); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 907, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + + /* "pygeoprocessing/routing/watershed.pyx":908 + * min(y1, y2), + * max(x1, x2), + * max(y1, y2)) # <<<<<<<<<<<<<< + * ) + * vrt_path = os.path.join(working_dir_path, '%s_vrt.vrt' % ws_id) + */ + __pyx_t_15 = __pyx_v_y2; + __pyx_t_31 = __pyx_v_y1; + if (((__pyx_t_15 > __pyx_t_31) != 0)) { + __pyx_t_32 = __pyx_t_15; + } else { + __pyx_t_32 = __pyx_t_31; + } + __pyx_t_11 = PyFloat_FromDouble(__pyx_t_32); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 908, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + + /* "pygeoprocessing/routing/watershed.pyx":905 + * vrt_options = gdal.BuildVRTOptions( + * outputBounds=( + * min(x1, x2), # <<<<<<<<<<<<<< + * min(y1, y2), + * max(x1, x2), + */ + __pyx_t_19 = PyTuple_New(4); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 905, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_18); + PyTuple_SET_ITEM(__pyx_t_19, 1, __pyx_t_18); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_19, 2, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_19, 3, __pyx_t_11); + __pyx_t_10 = 0; + __pyx_t_18 = 0; + __pyx_t_7 = 0; + __pyx_t_11 = 0; + if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_outputBounds, __pyx_t_19) < 0) __PYX_ERR(0, 904, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":903 + * y2 = (flow_dir_origin_y + (min(iy_max+1, flow_dir_n_rows)*flow_dir_pixelsize_y)) # maxy + * + * vrt_options = gdal.BuildVRTOptions( # <<<<<<<<<<<<<< + * outputBounds=( + * min(x1, x2), + */ + __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_empty_tuple, __pyx_t_12); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 903, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF_SET(__pyx_v_vrt_options, __pyx_t_19); + __pyx_t_19 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":910 + * max(y1, y2)) + * ) + * vrt_path = os.path.join(working_dir_path, '%s_vrt.vrt' % ws_id) # <<<<<<<<<<<<<< + * gdal.BuildVRT(vrt_path, [scratch_raster_path], options=vrt_options) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_os); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 910, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_path); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 910, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_join); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 910, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_13 = __Pyx_PyInt_From_int(__pyx_v_ws_id); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 910, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_11 = PyUnicode_Format(__pyx_kp_u_s_vrt_vrt, __pyx_t_13); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 910, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_13 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_12)) { + PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_v_working_dir_path, __pyx_t_11}; + __pyx_t_19 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 910, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) { + PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_v_working_dir_path, __pyx_t_11}; + __pyx_t_19 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 910, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 910, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_13) { + __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_13); __pyx_t_13 = NULL; + } + __Pyx_INCREF(__pyx_v_working_dir_path); + __Pyx_GIVEREF(__pyx_v_working_dir_path); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_9, __pyx_v_working_dir_path); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_9, __pyx_t_11); + __pyx_t_11 = 0; + __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_7, NULL); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 910, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF_SET(__pyx_v_vrt_path, __pyx_t_19); + __pyx_t_19 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":911 + * ) + * vrt_path = os.path.join(working_dir_path, '%s_vrt.vrt' % ws_id) + * gdal.BuildVRT(vrt_path, [scratch_raster_path], options=vrt_options) # <<<<<<<<<<<<<< + * + * # Polygonize this new watershed from the VRT. + */ + __Pyx_GetModuleGlobalName(__pyx_t_19, __pyx_n_s_gdal); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 911, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_n_s_BuildVRT); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 911, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __pyx_t_19 = PyList_New(1); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 911, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_INCREF(__pyx_v_scratch_raster_path); + __Pyx_GIVEREF(__pyx_v_scratch_raster_path); + PyList_SET_ITEM(__pyx_t_19, 0, __pyx_v_scratch_raster_path); + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 911, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_v_vrt_path); + __Pyx_GIVEREF(__pyx_v_vrt_path); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_vrt_path); + __Pyx_GIVEREF(__pyx_t_19); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_19); + __pyx_t_19 = 0; + __pyx_t_19 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 911, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + if (PyDict_SetItem(__pyx_t_19, __pyx_n_s_options, __pyx_v_vrt_options) < 0) __PYX_ERR(0, 911, __pyx_L1_error) + __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_7, __pyx_t_19); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 911, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":914 + * + * # Polygonize this new watershed from the VRT. + * vrt_raster = gdal.OpenEx(vrt_path, gdal.OF_RASTER, allowed_drivers=['VRT']) # <<<<<<<<<<<<<< + * vrt_band = vrt_raster.GetRasterBand(1) + * _ = gdal.Polygonize( + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_gdal); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 914, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 914, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_gdal); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 914, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 914, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 914, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_INCREF(__pyx_v_vrt_path); + __Pyx_GIVEREF(__pyx_v_vrt_path); + PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_vrt_path); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 914, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_12 = PyList_New(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 914, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_INCREF(__pyx_n_u_VRT); + __Pyx_GIVEREF(__pyx_n_u_VRT); + PyList_SET_ITEM(__pyx_t_12, 0, __pyx_n_u_VRT); + if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_allowed_drivers, __pyx_t_12) < 0) __PYX_ERR(0, 914, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_19, __pyx_t_11, __pyx_t_7); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 914, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF_SET(__pyx_v_vrt_raster, __pyx_t_12); + __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":915 + * # Polygonize this new watershed from the VRT. + * vrt_raster = gdal.OpenEx(vrt_path, gdal.OF_RASTER, allowed_drivers=['VRT']) + * vrt_band = vrt_raster.GetRasterBand(1) # <<<<<<<<<<<<<< + * _ = gdal.Polygonize( + * vrt_band, # The source band + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_vrt_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 915, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_12 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_11, __pyx_int_1) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_int_1); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 915, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF_SET(__pyx_v_vrt_band, __pyx_t_12); + __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":916 + * vrt_raster = gdal.OpenEx(vrt_path, gdal.OF_RASTER, allowed_drivers=['VRT']) + * vrt_band = vrt_raster.GetRasterBand(1) + * _ = gdal.Polygonize( # <<<<<<<<<<<<<< + * vrt_band, # The source band + * vrt_band, # The mask. Pixels with 0 are invalid, nonzero are valid + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 916, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_Polygonize); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 916, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":921 + * polygonized_watersheds_layer, + * 0, # ws_id field index + * []) # 8connectedness does not always produce valid geometries. # <<<<<<<<<<<<<< + * _ = None + * vrt_band = None + */ + __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 921, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_19 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_19)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_19); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[6] = {__pyx_t_19, __pyx_v_vrt_band, __pyx_v_vrt_band, __pyx_v_polygonized_watersheds_layer, __pyx_int_0, __pyx_t_7}; + __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 5+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 916, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[6] = {__pyx_t_19, __pyx_v_vrt_band, __pyx_v_vrt_band, __pyx_v_polygonized_watersheds_layer, __pyx_int_0, __pyx_t_7}; + __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 5+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 916, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_13 = PyTuple_New(5+__pyx_t_9); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 916, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + if (__pyx_t_19) { + __Pyx_GIVEREF(__pyx_t_19); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_19); __pyx_t_19 = NULL; + } + __Pyx_INCREF(__pyx_v_vrt_band); + __Pyx_GIVEREF(__pyx_v_vrt_band); + PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_9, __pyx_v_vrt_band); + __Pyx_INCREF(__pyx_v_vrt_band); + __Pyx_GIVEREF(__pyx_v_vrt_band); + PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_9, __pyx_v_vrt_band); + __Pyx_INCREF(__pyx_v_polygonized_watersheds_layer); + __Pyx_GIVEREF(__pyx_v_polygonized_watersheds_layer); + PyTuple_SET_ITEM(__pyx_t_13, 2+__pyx_t_9, __pyx_v_polygonized_watersheds_layer); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_13, 3+__pyx_t_9, __pyx_int_0); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_13, 4+__pyx_t_9, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_13, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 916, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + } + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_12); + __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":922 + * 0, # ws_id field index + * []) # 8connectedness does not always produce valid geometries. + * _ = None # <<<<<<<<<<<<<< + * vrt_band = None + * vrt_raster = None + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v__, Py_None); + + /* "pygeoprocessing/routing/watershed.pyx":923 + * []) # 8connectedness does not always produce valid geometries. + * _ = None + * vrt_band = None # <<<<<<<<<<<<<< + * vrt_raster = None + * + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_vrt_band, Py_None); + + /* "pygeoprocessing/routing/watershed.pyx":924 + * _ = None + * vrt_band = None + * vrt_raster = None # <<<<<<<<<<<<<< + * + * # Removing files as we go to help manage disk space. + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_vrt_raster, Py_None); + + /* "pygeoprocessing/routing/watershed.pyx":927 + * + * # Removing files as we go to help manage disk space. + * if remove_temp_files: # <<<<<<<<<<<<<< + * os.remove(scratch_raster_path) + * if os.path.exists(seeds_raster_path): + */ + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_remove_temp_files); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 927, __pyx_L1_error) + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/watershed.pyx":928 + * # Removing files as we go to help manage disk space. + * if remove_temp_files: + * os.remove(scratch_raster_path) # <<<<<<<<<<<<<< + * if os.path.exists(seeds_raster_path): + * os.remove(seeds_raster_path) + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_os); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 928, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_remove); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 928, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_13))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_13); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_13, function); + } + } + __pyx_t_12 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_13, __pyx_t_11, __pyx_v_scratch_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_v_scratch_raster_path); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 928, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":929 + * if remove_temp_files: + * os.remove(scratch_raster_path) + * if os.path.exists(seeds_raster_path): # <<<<<<<<<<<<<< + * os.remove(seeds_raster_path) + * os.remove(vrt_path) + */ + __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_os); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 929, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_path); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 929, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_exists); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 929, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_13); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_13, function); + } + } + __pyx_t_12 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_13, __pyx_t_11, __pyx_v_seeds_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_v_seeds_raster_path); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 929, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_12); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 929, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/watershed.pyx":930 + * os.remove(scratch_raster_path) + * if os.path.exists(seeds_raster_path): + * os.remove(seeds_raster_path) # <<<<<<<<<<<<<< + * os.remove(vrt_path) + * if (diagnostic_vector_path + */ + __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_os); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 930, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_remove); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 930, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_13 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + } + } + __pyx_t_12 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_13, __pyx_v_seeds_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_v_seeds_raster_path); + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 930, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":929 + * if remove_temp_files: + * os.remove(scratch_raster_path) + * if os.path.exists(seeds_raster_path): # <<<<<<<<<<<<<< + * os.remove(seeds_raster_path) + * os.remove(vrt_path) + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":931 + * if os.path.exists(seeds_raster_path): + * os.remove(seeds_raster_path) + * os.remove(vrt_path) # <<<<<<<<<<<<<< + * if (diagnostic_vector_path + * and os.path.exists(diagnostic_vector_path)): + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_os); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 931, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_remove); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 931, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_13))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_13); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_13, function); + } + } + __pyx_t_12 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_13, __pyx_t_11, __pyx_v_vrt_path) : __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_v_vrt_path); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 931, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":932 + * os.remove(seeds_raster_path) + * os.remove(vrt_path) + * if (diagnostic_vector_path # <<<<<<<<<<<<<< + * and os.path.exists(diagnostic_vector_path)): + * os.remove(diagnostic_vector_path) + */ + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_diagnostic_vector_path); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 932, __pyx_L1_error) + if (__pyx_t_4) { + } else { + __pyx_t_5 = __pyx_t_4; + goto __pyx_L40_bool_binop_done; + } + + /* "pygeoprocessing/routing/watershed.pyx":933 + * os.remove(vrt_path) + * if (diagnostic_vector_path + * and os.path.exists(diagnostic_vector_path)): # <<<<<<<<<<<<<< + * os.remove(diagnostic_vector_path) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_os); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 933, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_path); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 933, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_exists); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 933, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_13); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_13, function); + } + } + __pyx_t_12 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_13, __pyx_t_11, __pyx_v_diagnostic_vector_path) : __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_v_diagnostic_vector_path); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 933, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_12); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 933, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_5 = __pyx_t_4; + __pyx_L40_bool_binop_done:; + + /* "pygeoprocessing/routing/watershed.pyx":932 + * os.remove(seeds_raster_path) + * os.remove(vrt_path) + * if (diagnostic_vector_path # <<<<<<<<<<<<<< + * and os.path.exists(diagnostic_vector_path)): + * os.remove(diagnostic_vector_path) + */ + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/watershed.pyx":934 + * if (diagnostic_vector_path + * and os.path.exists(diagnostic_vector_path)): + * os.remove(diagnostic_vector_path) # <<<<<<<<<<<<<< + * + * LOGGER.info('Finished delineating %s watersheds', watersheds_created) + */ + __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_os); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 934, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_remove); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 934, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_13 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + } + } + __pyx_t_12 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_13, __pyx_v_diagnostic_vector_path) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_v_diagnostic_vector_path); + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 934, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":932 + * os.remove(seeds_raster_path) + * os.remove(vrt_path) + * if (diagnostic_vector_path # <<<<<<<<<<<<<< + * and os.path.exists(diagnostic_vector_path)): + * os.remove(diagnostic_vector_path) + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":927 + * + * # Removing files as we go to help manage disk space. + * if remove_temp_files: # <<<<<<<<<<<<<< + * os.remove(scratch_raster_path) + * if os.path.exists(seeds_raster_path): + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":748 + * flow_dir_srs = osr.SpatialReference() + * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) + * for feature in outflow_layer: # <<<<<<<<<<<<<< + * # Some vectors start indexing their FIDs at 0. + * # The mask raster input to polygonization, however, only regards pixels + */ + __pyx_L16_continue:; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":936 + * os.remove(diagnostic_vector_path) + * + * LOGGER.info('Finished delineating %s watersheds', watersheds_created) # <<<<<<<<<<<<<< + * + * # The Polygonization algorithm will sometimes identify regions that + */ + __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 936, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_info); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 936, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = __Pyx_PyInt_From_int(__pyx_v_watersheds_created); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 936, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_kp_u_Finished_delineating_s_watershed, __pyx_t_12}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 936, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 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_11)) { + PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_kp_u_Finished_delineating_s_watershed, __pyx_t_12}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 936, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 936, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_13) { + __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_13); __pyx_t_13 = NULL; + } + __Pyx_INCREF(__pyx_kp_u_Finished_delineating_s_watershed); + __Pyx_GIVEREF(__pyx_kp_u_Finished_delineating_s_watershed); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_9, __pyx_kp_u_Finished_delineating_s_watershed); + __Pyx_GIVEREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_9, __pyx_t_12); + __pyx_t_12 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 936, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":944 + * cdef cmap[int, cset[int]] fragments_with_duplicates + * cdef int fid + * for feature in polygonized_watersheds_layer: # <<<<<<<<<<<<<< + * fid = feature.GetFID() + * # ws_id is tracked as 1 more than the FID. See previous note about why. + */ + if (likely(PyList_CheckExact(__pyx_v_polygonized_watersheds_layer)) || PyTuple_CheckExact(__pyx_v_polygonized_watersheds_layer)) { + __pyx_t_8 = __pyx_v_polygonized_watersheds_layer; __Pyx_INCREF(__pyx_t_8); __pyx_t_23 = 0; + __pyx_t_24 = NULL; + } else { + __pyx_t_23 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_polygonized_watersheds_layer); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 944, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_24 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 944, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_24)) { + if (likely(PyList_CheckExact(__pyx_t_8))) { + if (__pyx_t_23 >= PyList_GET_SIZE(__pyx_t_8)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_11 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_23); __Pyx_INCREF(__pyx_t_11); __pyx_t_23++; if (unlikely(0 < 0)) __PYX_ERR(0, 944, __pyx_L1_error) + #else + __pyx_t_11 = PySequence_ITEM(__pyx_t_8, __pyx_t_23); __pyx_t_23++; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 944, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + #endif + } else { + if (__pyx_t_23 >= PyTuple_GET_SIZE(__pyx_t_8)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_11 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_23); __Pyx_INCREF(__pyx_t_11); __pyx_t_23++; if (unlikely(0 < 0)) __PYX_ERR(0, 944, __pyx_L1_error) + #else + __pyx_t_11 = PySequence_ITEM(__pyx_t_8, __pyx_t_23); __pyx_t_23++; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 944, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + #endif + } + } else { + __pyx_t_11 = __pyx_t_24(__pyx_t_8); + if (unlikely(!__pyx_t_11)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 944, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_11); + } + __Pyx_XDECREF_SET(__pyx_v_feature, __pyx_t_11); + __pyx_t_11 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":945 + * cdef int fid + * for feature in polygonized_watersheds_layer: + * fid = feature.GetFID() # <<<<<<<<<<<<<< + * # ws_id is tracked as 1 more than the FID. See previous note about why. + * ws_id = feature.GetField('ws_id') - 1 + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_feature, __pyx_n_s_GetFID); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 945, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_12 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_11 = (__pyx_t_12) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_12) : __Pyx_PyObject_CallNoArg(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 945, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_11); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 945, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_v_fid = __pyx_t_9; + + /* "pygeoprocessing/routing/watershed.pyx":947 + * fid = feature.GetFID() + * # ws_id is tracked as 1 more than the FID. See previous note about why. + * ws_id = feature.GetField('ws_id') - 1 # <<<<<<<<<<<<<< + * if (fragments_with_duplicates.find(ws_id) + * == fragments_with_duplicates.end()): + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 947, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_12 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_11 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_12, __pyx_n_u_ws_id) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_n_u_ws_id); + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 947, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyInt_SubtractObjC(__pyx_t_11, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 947, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 947, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_ws_id = __pyx_t_9; + + /* "pygeoprocessing/routing/watershed.pyx":949 + * ws_id = feature.GetField('ws_id') - 1 + * if (fragments_with_duplicates.find(ws_id) + * == fragments_with_duplicates.end()): # <<<<<<<<<<<<<< + * fragments_with_duplicates[ws_id] = cset[int]() + * fragments_with_duplicates[ws_id].insert(fid) + */ + __pyx_t_5 = ((__pyx_v_fragments_with_duplicates.find(__pyx_v_ws_id) == __pyx_v_fragments_with_duplicates.end()) != 0); + + /* "pygeoprocessing/routing/watershed.pyx":948 + * # ws_id is tracked as 1 more than the FID. See previous note about why. + * ws_id = feature.GetField('ws_id') - 1 + * if (fragments_with_duplicates.find(ws_id) # <<<<<<<<<<<<<< + * == fragments_with_duplicates.end()): + * fragments_with_duplicates[ws_id] = cset[int]() + */ + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/watershed.pyx":950 + * if (fragments_with_duplicates.find(ws_id) + * == fragments_with_duplicates.end()): + * fragments_with_duplicates[ws_id] = cset[int]() # <<<<<<<<<<<<<< + * fragments_with_duplicates[ws_id].insert(fid) + * polygonized_watersheds_layer.ResetReading() + */ + try { + __pyx_t_33 = std::set (); + } catch(...) { + __Pyx_CppExn2PyErr(); + __PYX_ERR(0, 950, __pyx_L1_error) + } + (__pyx_v_fragments_with_duplicates[__pyx_v_ws_id]) = __pyx_t_33; + + /* "pygeoprocessing/routing/watershed.pyx":948 + * # ws_id is tracked as 1 more than the FID. See previous note about why. + * ws_id = feature.GetField('ws_id') - 1 + * if (fragments_with_duplicates.find(ws_id) # <<<<<<<<<<<<<< + * == fragments_with_duplicates.end()): + * fragments_with_duplicates[ws_id] = cset[int]() + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":951 + * == fragments_with_duplicates.end()): + * fragments_with_duplicates[ws_id] = cset[int]() + * fragments_with_duplicates[ws_id].insert(fid) # <<<<<<<<<<<<<< + * polygonized_watersheds_layer.ResetReading() + * + */ + try { + (__pyx_v_fragments_with_duplicates[__pyx_v_ws_id]).insert(__pyx_v_fid); + } catch(...) { + __Pyx_CppExn2PyErr(); + __PYX_ERR(0, 951, __pyx_L1_error) + } + + /* "pygeoprocessing/routing/watershed.pyx":944 + * cdef cmap[int, cset[int]] fragments_with_duplicates + * cdef int fid + * for feature in polygonized_watersheds_layer: # <<<<<<<<<<<<<< + * fid = feature.GetFID() + * # ws_id is tracked as 1 more than the FID. See previous note about why. + */ + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":952 + * fragments_with_duplicates[ws_id] = cset[int]() + * fragments_with_duplicates[ws_id].insert(fid) + * polygonized_watersheds_layer.ResetReading() # <<<<<<<<<<<<<< + * + * LOGGER.info( + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_polygonized_watersheds_layer, __pyx_n_s_ResetReading); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 952, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_8 = (__pyx_t_11) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_11) : __Pyx_PyObject_CallNoArg(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 952, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":954 + * polygonized_watersheds_layer.ResetReading() + * + * LOGGER.info( # <<<<<<<<<<<<<< + * 'Consolidating %s fragments and copying field values to ' + * 'watersheds layer.', polygonized_watersheds_layer.GetFeatureCount()) + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 954, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_info); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 954, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":956 + * LOGGER.info( + * 'Consolidating %s fragments and copying field values to ' + * 'watersheds layer.', polygonized_watersheds_layer.GetFeatureCount()) # <<<<<<<<<<<<<< + * source_vector = gdal.OpenEx(outflow_vector_path, gdal.OF_VECTOR) + * source_layer = source_vector.GetLayer() + */ + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_polygonized_watersheds_layer, __pyx_n_s_GetFeatureCount); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 956, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + } + } + __pyx_t_7 = (__pyx_t_13) ? __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_13) : __Pyx_PyObject_CallNoArg(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 956, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_12)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_kp_u_Consolidating_s_fragments_and_co, __pyx_t_7}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 954, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_kp_u_Consolidating_s_fragments_and_co, __pyx_t_7}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 954, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_13 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 954, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + if (__pyx_t_12) { + __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_12); __pyx_t_12 = NULL; + } + __Pyx_INCREF(__pyx_kp_u_Consolidating_s_fragments_and_co); + __Pyx_GIVEREF(__pyx_kp_u_Consolidating_s_fragments_and_co); + PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_9, __pyx_kp_u_Consolidating_s_fragments_and_co); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_9, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_13, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 954, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + } + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":957 + * 'Consolidating %s fragments and copying field values to ' + * 'watersheds layer.', polygonized_watersheds_layer.GetFeatureCount()) + * source_vector = gdal.OpenEx(outflow_vector_path, gdal.OF_VECTOR) # <<<<<<<<<<<<<< + * source_layer = source_vector.GetLayer() + * watersheds_layer.CreateFields(source_layer.schema) + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_gdal); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 957, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 957, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_gdal); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 957, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_OF_VECTOR); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 957, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_13))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_13); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_13, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_13)) { + PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_outflow_vector_path, __pyx_t_7}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 957, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_13)) { + PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_outflow_vector_path, __pyx_t_7}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 957, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_12 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 957, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + if (__pyx_t_11) { + __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11); __pyx_t_11 = NULL; + } + __Pyx_INCREF(__pyx_v_outflow_vector_path); + __Pyx_GIVEREF(__pyx_v_outflow_vector_path); + PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_9, __pyx_v_outflow_vector_path); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_9, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_12, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 957, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_v_source_vector = __pyx_t_8; + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":958 + * 'watersheds layer.', polygonized_watersheds_layer.GetFeatureCount()) + * source_vector = gdal.OpenEx(outflow_vector_path, gdal.OF_VECTOR) + * source_layer = source_vector.GetLayer() # <<<<<<<<<<<<<< + * watersheds_layer.CreateFields(source_layer.schema) + * + */ + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_source_vector, __pyx_n_s_GetLayer); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 958, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_12 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) { + __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_13); + if (likely(__pyx_t_12)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_13, function); + } + } + __pyx_t_8 = (__pyx_t_12) ? __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_12) : __Pyx_PyObject_CallNoArg(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 958, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_v_source_layer = __pyx_t_8; + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":959 + * source_vector = gdal.OpenEx(outflow_vector_path, gdal.OF_VECTOR) + * source_layer = source_vector.GetLayer() + * watersheds_layer.CreateFields(source_layer.schema) # <<<<<<<<<<<<<< + * + * watersheds_layer.StartTransaction() + */ + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_watersheds_layer, __pyx_n_s_CreateFields); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 959, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_source_layer, __pyx_n_s_schema); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 959, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_13); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_13, function); + } + } + __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_13, __pyx_t_7, __pyx_t_12) : __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_12); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 959, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":961 + * watersheds_layer.CreateFields(source_layer.schema) + * + * watersheds_layer.StartTransaction() # <<<<<<<<<<<<<< + * cdef int duplicate_fid + * cdef cset[int] duplicate_ids_set + */ + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_watersheds_layer, __pyx_n_s_StartTransaction); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 961, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_12 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) { + __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_13); + if (likely(__pyx_t_12)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_13, function); + } + } + __pyx_t_8 = (__pyx_t_12) ? __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_12) : __Pyx_PyObject_CallNoArg(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 961, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":966 + * cdef cset[int].iterator duplicate_ids_set_iterator + * cdef cmap[int, cset[int]].iterator fragments_with_duplicates_iterator + * fragments_with_duplicates_iterator = fragments_with_duplicates.begin() # <<<<<<<<<<<<<< + * while fragments_with_duplicates_iterator != fragments_with_duplicates.end(): + * ws_id = deref(fragments_with_duplicates_iterator).first + */ + __pyx_v_fragments_with_duplicates_iterator = __pyx_v_fragments_with_duplicates.begin(); + + /* "pygeoprocessing/routing/watershed.pyx":967 + * cdef cmap[int, cset[int]].iterator fragments_with_duplicates_iterator + * fragments_with_duplicates_iterator = fragments_with_duplicates.begin() + * while fragments_with_duplicates_iterator != fragments_with_duplicates.end(): # <<<<<<<<<<<<<< + * ws_id = deref(fragments_with_duplicates_iterator).first + * duplicate_ids_set = deref(fragments_with_duplicates_iterator).second + */ + while (1) { + __pyx_t_5 = ((__pyx_v_fragments_with_duplicates_iterator != __pyx_v_fragments_with_duplicates.end()) != 0); + if (!__pyx_t_5) break; + + /* "pygeoprocessing/routing/watershed.pyx":968 + * fragments_with_duplicates_iterator = fragments_with_duplicates.begin() + * while fragments_with_duplicates_iterator != fragments_with_duplicates.end(): + * ws_id = deref(fragments_with_duplicates_iterator).first # <<<<<<<<<<<<<< + * duplicate_ids_set = deref(fragments_with_duplicates_iterator).second + * inc(fragments_with_duplicates_iterator) + */ + __pyx_t_9 = (*__pyx_v_fragments_with_duplicates_iterator).first; + __pyx_v_ws_id = __pyx_t_9; + + /* "pygeoprocessing/routing/watershed.pyx":969 + * while fragments_with_duplicates_iterator != fragments_with_duplicates.end(): + * ws_id = deref(fragments_with_duplicates_iterator).first + * duplicate_ids_set = deref(fragments_with_duplicates_iterator).second # <<<<<<<<<<<<<< + * inc(fragments_with_duplicates_iterator) + * + */ + __pyx_t_33 = (*__pyx_v_fragments_with_duplicates_iterator).second; + __pyx_v_duplicate_ids_set = __pyx_t_33; + + /* "pygeoprocessing/routing/watershed.pyx":970 + * ws_id = deref(fragments_with_duplicates_iterator).first + * duplicate_ids_set = deref(fragments_with_duplicates_iterator).second + * inc(fragments_with_duplicates_iterator) # <<<<<<<<<<<<<< + * + * duplicate_ids_set_iterator = duplicate_ids_set.begin() + */ + (void)((++__pyx_v_fragments_with_duplicates_iterator)); + + /* "pygeoprocessing/routing/watershed.pyx":972 + * inc(fragments_with_duplicates_iterator) + * + * duplicate_ids_set_iterator = duplicate_ids_set.begin() # <<<<<<<<<<<<<< + * + * if duplicate_ids_set.size() == 1: + */ + __pyx_v_duplicate_ids_set_iterator = __pyx_v_duplicate_ids_set.begin(); + + /* "pygeoprocessing/routing/watershed.pyx":974 + * duplicate_ids_set_iterator = duplicate_ids_set.begin() + * + * if duplicate_ids_set.size() == 1: # <<<<<<<<<<<<<< + * duplicate_fid = deref(duplicate_ids_set_iterator) + * source_feature = polygonized_watersheds_layer.GetFeature(duplicate_fid) + */ + __pyx_t_5 = ((__pyx_v_duplicate_ids_set.size() == 1) != 0); + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/watershed.pyx":975 + * + * if duplicate_ids_set.size() == 1: + * duplicate_fid = deref(duplicate_ids_set_iterator) # <<<<<<<<<<<<<< + * source_feature = polygonized_watersheds_layer.GetFeature(duplicate_fid) + * new_geometry = source_feature.GetGeometryRef() + */ + __pyx_v_duplicate_fid = (*__pyx_v_duplicate_ids_set_iterator); + + /* "pygeoprocessing/routing/watershed.pyx":976 + * if duplicate_ids_set.size() == 1: + * duplicate_fid = deref(duplicate_ids_set_iterator) + * source_feature = polygonized_watersheds_layer.GetFeature(duplicate_fid) # <<<<<<<<<<<<<< + * new_geometry = source_feature.GetGeometryRef() + * else: + */ + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_polygonized_watersheds_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 976, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_12 = __Pyx_PyInt_From_int(__pyx_v_duplicate_fid); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 976, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_13); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_13, function); + } + } + __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_13, __pyx_t_7, __pyx_t_12) : __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_12); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 976, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF_SET(__pyx_v_source_feature, __pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":977 + * duplicate_fid = deref(duplicate_ids_set_iterator) + * source_feature = polygonized_watersheds_layer.GetFeature(duplicate_fid) + * new_geometry = source_feature.GetGeometryRef() # <<<<<<<<<<<<<< + * else: + * new_geometry = ogr.Geometry(ogr.wkbMultiPolygon) + */ + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_source_feature, __pyx_n_s_GetGeometryRef); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 977, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_12 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) { + __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_13); + if (likely(__pyx_t_12)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_13, function); + } + } + __pyx_t_8 = (__pyx_t_12) ? __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_12) : __Pyx_PyObject_CallNoArg(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 977, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF_SET(__pyx_v_new_geometry, __pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":974 + * duplicate_ids_set_iterator = duplicate_ids_set.begin() + * + * if duplicate_ids_set.size() == 1: # <<<<<<<<<<<<<< + * duplicate_fid = deref(duplicate_ids_set_iterator) + * source_feature = polygonized_watersheds_layer.GetFeature(duplicate_fid) + */ + goto __pyx_L47; + } + + /* "pygeoprocessing/routing/watershed.pyx":979 + * new_geometry = source_feature.GetGeometryRef() + * else: + * new_geometry = ogr.Geometry(ogr.wkbMultiPolygon) # <<<<<<<<<<<<<< + * while duplicate_ids_set_iterator != duplicate_ids_set.end(): + * duplicate_fid = deref(duplicate_ids_set_iterator) + */ + /*else*/ { + __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_ogr); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 979, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_Geometry); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 979, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_ogr); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 979, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_wkbMultiPolygon); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 979, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_13 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + } + } + __pyx_t_8 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_13, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_7); + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 979, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF_SET(__pyx_v_new_geometry, __pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":980 + * else: + * new_geometry = ogr.Geometry(ogr.wkbMultiPolygon) + * while duplicate_ids_set_iterator != duplicate_ids_set.end(): # <<<<<<<<<<<<<< + * duplicate_fid = deref(duplicate_ids_set_iterator) + * inc(duplicate_ids_set_iterator) + */ + while (1) { + __pyx_t_5 = ((__pyx_v_duplicate_ids_set_iterator != __pyx_v_duplicate_ids_set.end()) != 0); + if (!__pyx_t_5) break; + + /* "pygeoprocessing/routing/watershed.pyx":981 + * new_geometry = ogr.Geometry(ogr.wkbMultiPolygon) + * while duplicate_ids_set_iterator != duplicate_ids_set.end(): + * duplicate_fid = deref(duplicate_ids_set_iterator) # <<<<<<<<<<<<<< + * inc(duplicate_ids_set_iterator) + * + */ + __pyx_v_duplicate_fid = (*__pyx_v_duplicate_ids_set_iterator); + + /* "pygeoprocessing/routing/watershed.pyx":982 + * while duplicate_ids_set_iterator != duplicate_ids_set.end(): + * duplicate_fid = deref(duplicate_ids_set_iterator) + * inc(duplicate_ids_set_iterator) # <<<<<<<<<<<<<< + * + * duplicate_feature = polygonized_watersheds_layer.GetFeature(duplicate_fid) + */ + (void)((++__pyx_v_duplicate_ids_set_iterator)); + + /* "pygeoprocessing/routing/watershed.pyx":984 + * inc(duplicate_ids_set_iterator) + * + * duplicate_feature = polygonized_watersheds_layer.GetFeature(duplicate_fid) # <<<<<<<<<<<<<< + * duplicate_geometry = duplicate_feature.GetGeometryRef() + * new_geometry.AddGeometry(duplicate_geometry) + */ + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_polygonized_watersheds_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 984, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_duplicate_fid); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 984, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_13 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + } + } + __pyx_t_8 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_13, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_7); + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 984, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF_SET(__pyx_v_duplicate_feature, __pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":985 + * + * duplicate_feature = polygonized_watersheds_layer.GetFeature(duplicate_fid) + * duplicate_geometry = duplicate_feature.GetGeometryRef() # <<<<<<<<<<<<<< + * new_geometry.AddGeometry(duplicate_geometry) + * + */ + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_duplicate_feature, __pyx_n_s_GetGeometryRef); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 985, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + } + } + __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 985, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF_SET(__pyx_v_duplicate_geometry, __pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":986 + * duplicate_feature = polygonized_watersheds_layer.GetFeature(duplicate_fid) + * duplicate_geometry = duplicate_feature.GetGeometryRef() + * new_geometry.AddGeometry(duplicate_geometry) # <<<<<<<<<<<<<< + * + * watershed_feature = ogr.Feature(watersheds_layer.GetLayerDefn()) + */ + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_new_geometry, __pyx_n_s_AddGeometry); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 986, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + } + } + __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_7, __pyx_v_duplicate_geometry) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_v_duplicate_geometry); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 986, __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; + } + } + __pyx_L47:; + + /* "pygeoprocessing/routing/watershed.pyx":988 + * new_geometry.AddGeometry(duplicate_geometry) + * + * watershed_feature = ogr.Feature(watersheds_layer.GetLayerDefn()) # <<<<<<<<<<<<<< + * watershed_feature.SetGeometry(new_geometry) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_ogr); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 988, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_Feature); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 988, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_watersheds_layer, __pyx_n_s_GetLayerDefn); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 988, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_13); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_13, function); + } + } + __pyx_t_12 = (__pyx_t_11) ? __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_11) : __Pyx_PyObject_CallNoArg(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 988, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_13 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_8 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_13, __pyx_t_12) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 988, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF_SET(__pyx_v_watershed_feature, __pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":989 + * + * watershed_feature = ogr.Feature(watersheds_layer.GetLayerDefn()) + * watershed_feature.SetGeometry(new_geometry) # <<<<<<<<<<<<<< + * + * source_feature = source_layer.GetFeature(ws_id) + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_feature, __pyx_n_s_SetGeometry); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 989, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_12 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_8 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_12, __pyx_v_new_geometry) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_new_geometry); + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 989, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":991 + * watershed_feature.SetGeometry(new_geometry) + * + * source_feature = source_layer.GetFeature(ws_id) # <<<<<<<<<<<<<< + * for field_name, field_value in source_feature.items().items(): + * watershed_feature.SetField(field_name, field_value) + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_source_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 991, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_12 = __Pyx_PyInt_From_int(__pyx_v_ws_id); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 991, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_8 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_13, __pyx_t_12) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 991, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF_SET(__pyx_v_source_feature, __pyx_t_8); + __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":992 + * + * source_feature = source_layer.GetFeature(ws_id) + * for field_name, field_value in source_feature.items().items(): # <<<<<<<<<<<<<< + * watershed_feature.SetField(field_name, field_value) + * if field_name == 'ws_id': + */ + __pyx_t_23 = 0; + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_source_feature, __pyx_n_s_items); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 992, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + } + } + __pyx_t_7 = (__pyx_t_13) ? __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_13) : __Pyx_PyObject_CallNoArg(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 992, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(__pyx_t_7 == Py_None)) { + PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "items"); + __PYX_ERR(0, 992, __pyx_L1_error) + } + __pyx_t_12 = __Pyx_dict_iterator(__pyx_t_7, 0, __pyx_n_s_items, (&__pyx_t_34), (&__pyx_t_9)); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 992, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); + __pyx_t_8 = __pyx_t_12; + __pyx_t_12 = 0; + while (1) { + __pyx_t_35 = __Pyx_dict_iter_next(__pyx_t_8, __pyx_t_34, &__pyx_t_23, &__pyx_t_12, &__pyx_t_7, NULL, __pyx_t_9); + if (unlikely(__pyx_t_35 == 0)) break; + if (unlikely(__pyx_t_35 == -1)) __PYX_ERR(0, 992, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_GOTREF(__pyx_t_7); + __Pyx_XDECREF_SET(__pyx_v_field_name, __pyx_t_12); + __pyx_t_12 = 0; + __Pyx_XDECREF_SET(__pyx_v_field_value, __pyx_t_7); + __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":993 + * source_feature = source_layer.GetFeature(ws_id) + * for field_name, field_value in source_feature.items().items(): + * watershed_feature.SetField(field_name, field_value) # <<<<<<<<<<<<<< + * if field_name == 'ws_id': + * continue + */ + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 993, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = NULL; + __pyx_t_35 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + __pyx_t_35 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_12)) { + PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_v_field_name, __pyx_v_field_value}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_35, 2+__pyx_t_35); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 993, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) { + PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_v_field_name, __pyx_v_field_value}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_35, 2+__pyx_t_35); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 993, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + { + __pyx_t_11 = PyTuple_New(2+__pyx_t_35); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 993, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + if (__pyx_t_13) { + __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_13); __pyx_t_13 = NULL; + } + __Pyx_INCREF(__pyx_v_field_name); + __Pyx_GIVEREF(__pyx_v_field_name); + PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_35, __pyx_v_field_name); + __Pyx_INCREF(__pyx_v_field_value); + __Pyx_GIVEREF(__pyx_v_field_value); + PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_35, __pyx_v_field_value); + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_11, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 993, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":994 + * for field_name, field_value in source_feature.items().items(): + * watershed_feature.SetField(field_name, field_value) + * if field_name == 'ws_id': # <<<<<<<<<<<<<< + * continue + * watersheds_layer.CreateFeature(watershed_feature) + */ + __pyx_t_5 = (__Pyx_PyUnicode_Equals(__pyx_v_field_name, __pyx_n_u_ws_id, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 994, __pyx_L1_error) + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/watershed.pyx":995 + * watershed_feature.SetField(field_name, field_value) + * if field_name == 'ws_id': + * continue # <<<<<<<<<<<<<< + * watersheds_layer.CreateFeature(watershed_feature) + * watersheds_layer.CommitTransaction() + */ + goto __pyx_L50_continue; + + /* "pygeoprocessing/routing/watershed.pyx":994 + * for field_name, field_value in source_feature.items().items(): + * watershed_feature.SetField(field_name, field_value) + * if field_name == 'ws_id': # <<<<<<<<<<<<<< + * continue + * watersheds_layer.CreateFeature(watershed_feature) + */ + } + __pyx_L50_continue:; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":996 + * if field_name == 'ws_id': + * continue + * watersheds_layer.CreateFeature(watershed_feature) # <<<<<<<<<<<<<< + * watersheds_layer.CommitTransaction() + * + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_watersheds_layer, __pyx_n_s_CreateFeature); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 996, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_12 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_8 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_12, __pyx_v_watershed_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_watershed_feature); + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 996, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + + /* "pygeoprocessing/routing/watershed.pyx":997 + * continue + * watersheds_layer.CreateFeature(watershed_feature) + * watersheds_layer.CommitTransaction() # <<<<<<<<<<<<<< + * + * polygonized_watersheds_layer = None + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_watersheds_layer, __pyx_n_s_CommitTransaction); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 997, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_12 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_8 = (__pyx_t_12) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_12) : __Pyx_PyObject_CallNoArg(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 997, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":999 + * watersheds_layer.CommitTransaction() + * + * polygonized_watersheds_layer = None # <<<<<<<<<<<<<< + * if remove_temp_files: + * watersheds_vector.DeleteLayer('polygonized_watersheds') + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_polygonized_watersheds_layer, Py_None); + + /* "pygeoprocessing/routing/watershed.pyx":1000 + * + * polygonized_watersheds_layer = None + * if remove_temp_files: # <<<<<<<<<<<<<< + * watersheds_vector.DeleteLayer('polygonized_watersheds') + * LOGGER.info('Finished vector consolidation') + */ + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_remove_temp_files); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1000, __pyx_L1_error) + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/watershed.pyx":1001 + * polygonized_watersheds_layer = None + * if remove_temp_files: + * watersheds_vector.DeleteLayer('polygonized_watersheds') # <<<<<<<<<<<<<< + * LOGGER.info('Finished vector consolidation') + * + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_watersheds_vector, __pyx_n_s_DeleteLayer); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1001, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_12 = NULL; + if (CYTHON_UNPACK_METHODS && likely(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_8 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_12, __pyx_n_u_polygonized_watersheds) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_n_u_polygonized_watersheds); + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1001, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":1000 + * + * polygonized_watersheds_layer = None + * if remove_temp_files: # <<<<<<<<<<<<<< + * watersheds_vector.DeleteLayer('polygonized_watersheds') + * LOGGER.info('Finished vector consolidation') + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":1002 + * if remove_temp_files: + * watersheds_vector.DeleteLayer('polygonized_watersheds') + * LOGGER.info('Finished vector consolidation') # <<<<<<<<<<<<<< + * + * watersheds_layer = None + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1002, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_info); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1002, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + } + } + __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_7, __pyx_kp_u_Finished_vector_consolidation) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_kp_u_Finished_vector_consolidation); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1002, __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/watershed.pyx":1004 + * LOGGER.info('Finished vector consolidation') + * + * watersheds_layer = None # <<<<<<<<<<<<<< + * watersheds_vector = None + * source_layer = None + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_watersheds_layer, Py_None); + + /* "pygeoprocessing/routing/watershed.pyx":1005 + * + * watersheds_layer = None + * watersheds_vector = None # <<<<<<<<<<<<<< + * source_layer = None + * source_vector = None + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_watersheds_vector, Py_None); + + /* "pygeoprocessing/routing/watershed.pyx":1006 + * watersheds_layer = None + * watersheds_vector = None + * source_layer = None # <<<<<<<<<<<<<< + * source_vector = None + * + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_source_layer, Py_None); + + /* "pygeoprocessing/routing/watershed.pyx":1007 + * watersheds_vector = None + * source_layer = None + * source_vector = None # <<<<<<<<<<<<<< + * + * if remove_temp_files: + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_source_vector, Py_None); + + /* "pygeoprocessing/routing/watershed.pyx":1009 + * source_vector = None + * + * if remove_temp_files: # <<<<<<<<<<<<<< + * shutil.rmtree(working_dir_path) + * LOGGER.info('Watershed delineation complete') + */ + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_remove_temp_files); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1009, __pyx_L1_error) + if (__pyx_t_5) { + + /* "pygeoprocessing/routing/watershed.pyx":1010 + * + * if remove_temp_files: + * shutil.rmtree(working_dir_path) # <<<<<<<<<<<<<< + * LOGGER.info('Watershed delineation complete') + */ + __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_shutil); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1010, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_rmtree); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1010, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = NULL; + 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_8 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_12, __pyx_v_working_dir_path) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_working_dir_path); + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1010, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":1009 + * source_vector = None + * + * if remove_temp_files: # <<<<<<<<<<<<<< + * shutil.rmtree(working_dir_path) + * LOGGER.info('Watershed delineation complete') + */ + } + + /* "pygeoprocessing/routing/watershed.pyx":1011 + * if remove_temp_files: + * shutil.rmtree(working_dir_path) + * LOGGER.info('Watershed delineation complete') # <<<<<<<<<<<<<< + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1011, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_info); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1011, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + } + } + __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_7, __pyx_kp_u_Watershed_delineation_complete) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_kp_u_Watershed_delineation_complete); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1011, __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/watershed.pyx":624 + * + * @cython.boundscheck(False) + * def delineate_watersheds_d8( # <<<<<<<<<<<<<< + * d8_flow_dir_raster_path_band, outflow_vector_path, + * target_watersheds_vector_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_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_17); + __Pyx_XDECREF(__pyx_t_18); + __Pyx_XDECREF(__pyx_t_19); + __Pyx_AddTraceback("pygeoprocessing.routing.watershed.delineate_watersheds_d8", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_working_dir_path); + __Pyx_XDECREF(__pyx_v_flow_dir_info); + __Pyx_XDECREF(__pyx_v_source_gt); + __Pyx_XDECREF(__pyx_v_bbox_minx); + __Pyx_XDECREF(__pyx_v_bbox_miny); + __Pyx_XDECREF(__pyx_v_bbox_maxx); + __Pyx_XDECREF(__pyx_v_bbox_maxy); + __Pyx_XDECREF(__pyx_v_flow_dir_bbox); + __Pyx_XDECREF((PyObject *)__pyx_v_flow_dir_managed_raster); + __Pyx_XDECREF(__pyx_v_gtiff_driver); + __Pyx_XDECREF(__pyx_v_flow_dir_srs); + __Pyx_XDECREF(__pyx_v_outflow_vector); + __Pyx_XDECREF(__pyx_v_driver); + __Pyx_XDECREF(__pyx_v_watersheds_srs); + __Pyx_XDECREF(__pyx_v_watersheds_vector); + __Pyx_XDECREF(__pyx_v_polygonized_watersheds_layer); + __Pyx_XDECREF(__pyx_v_watersheds_layer); + __Pyx_XDECREF(__pyx_v_index_field); + __Pyx_XDECREF((PyObject *)__pyx_v_scratch_managed_raster); + __Pyx_XDECREF(__pyx_v_outflow_layer); + __Pyx_XDECREF(__pyx_v_feature); + __Pyx_XDECREF(__pyx_v_geom); + __Pyx_XDECREF(__pyx_v_geom_wkb); + __Pyx_XDECREF(__pyx_v_shapely_geom); + __Pyx_XDECREF(__pyx_v_seeds_raster_path); + __Pyx_XDECREF(__pyx_v_diagnostic_vector_path); + __Pyx_XDECREF(__pyx_v_scratch_raster_path); + __Pyx_XDECREF(__pyx_v_scratch_raster); + __Pyx_XDECREF(__pyx_v_vrt_options); + __Pyx_XDECREF(__pyx_v_vrt_path); + __Pyx_XDECREF(__pyx_v_vrt_raster); + __Pyx_XDECREF(__pyx_v_vrt_band); + __Pyx_XDECREF(__pyx_v__); + __Pyx_XDECREF(__pyx_v_source_vector); + __Pyx_XDECREF(__pyx_v_source_layer); + __Pyx_XDECREF(__pyx_v_source_feature); + __Pyx_XDECREF(__pyx_v_new_geometry); + __Pyx_XDECREF(__pyx_v_duplicate_feature); + __Pyx_XDECREF(__pyx_v_duplicate_geometry); + __Pyx_XDECREF(__pyx_v_watershed_feature); + __Pyx_XDECREF(__pyx_v_field_name); + __Pyx_XDECREF(__pyx_v_field_value); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":735 + * ctypedef npy_cdouble complex_t + * + * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(1, 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("PyArray_MultiIterNew1", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":736 + * + * cdef inline object PyArray_MultiIterNew1(a): + * return PyArray_MultiIterNew(1, 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, 736, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":735 + * ctypedef npy_cdouble complex_t + * + * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(1, 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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":738 + * return PyArray_MultiIterNew(1, a) + * + * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(2, a, 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("PyArray_MultiIterNew2", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":739 + * + * cdef inline object PyArray_MultiIterNew2(a, b): + * return PyArray_MultiIterNew(2, a, 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, 739, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":738 + * return PyArray_MultiIterNew(1, a) + * + * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(2, a, 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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":741 + * return PyArray_MultiIterNew(2, a, b) + * + * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(3, a, b, 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("PyArray_MultiIterNew3", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":742 + * + * cdef inline object PyArray_MultiIterNew3(a, b, c): + * return PyArray_MultiIterNew(3, a, b, 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, 742, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":741 + * return PyArray_MultiIterNew(2, a, b) + * + * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(3, a, b, 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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":744 + * return PyArray_MultiIterNew(3, a, b, c) + * + * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(4, a, b, c, 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("PyArray_MultiIterNew4", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":745 + * + * cdef inline object PyArray_MultiIterNew4(a, b, c, d): + * return PyArray_MultiIterNew(4, a, b, c, 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, 745, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":744 + * return PyArray_MultiIterNew(3, a, b, c) + * + * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(4, a, b, c, 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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":747 + * return PyArray_MultiIterNew(4, a, b, c, d) + * + * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(5, a, b, c, d, 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("PyArray_MultiIterNew5", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":748 + * + * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): + * return PyArray_MultiIterNew(5, a, b, c, d, 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, 748, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":747 + * return PyArray_MultiIterNew(4, a, b, c, d) + * + * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(5, a, b, c, d, 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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":750 + * return PyArray_MultiIterNew(5, a, b, c, d, e) + * + * cdef inline tuple PyDataType_SHAPE(dtype d): # <<<<<<<<<<<<<< + * if PyDataType_HASSUBARRAY(d): + * return 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); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":751 + * + * cdef inline tuple PyDataType_SHAPE(dtype d): + * if PyDataType_HASSUBARRAY(d): # <<<<<<<<<<<<<< + * return d.subarray.shape + * else: + */ + __pyx_t_1 = (PyDataType_HASSUBARRAY(__pyx_v_d) != 0); + if (__pyx_t_1) { + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":752 + * cdef inline tuple PyDataType_SHAPE(dtype d): + * if PyDataType_HASSUBARRAY(d): + * return 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; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":751 + * + * cdef inline tuple PyDataType_SHAPE(dtype d): + * if PyDataType_HASSUBARRAY(d): # <<<<<<<<<<<<<< + * return d.subarray.shape + * else: + */ + } + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":754 + * return d.subarray.shape + * else: + * return () # <<<<<<<<<<<<<< + * + * + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_empty_tuple); + __pyx_r = __pyx_empty_tuple; + goto __pyx_L0; + } + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":750 + * return PyArray_MultiIterNew(5, a, b, c, d, e) + * + * cdef inline tuple PyDataType_SHAPE(dtype d): # <<<<<<<<<<<<<< + * if PyDataType_HASSUBARRAY(d): + * return d.subarray.shape + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":931 + * int _import_umath() except -1 + * + * cdef inline void set_array_base(ndarray arr, object base): # <<<<<<<<<<<<<< + * Py_INCREF(base) # important to do this before stealing the reference below! + * PyArray_SetBaseObject(arr, base) + */ + +static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_arr, PyObject *__pyx_v_base) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("set_array_base", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":932 + * + * cdef inline void set_array_base(ndarray arr, object base): + * Py_INCREF(base) # important to do this before stealing the reference below! # <<<<<<<<<<<<<< + * PyArray_SetBaseObject(arr, base) + * + */ + Py_INCREF(__pyx_v_base); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":933 + * cdef inline void set_array_base(ndarray arr, object base): + * Py_INCREF(base) # important to do this before stealing the reference below! + * PyArray_SetBaseObject(arr, base) # <<<<<<<<<<<<<< + * + * cdef inline object get_array_base(ndarray arr): + */ + (void)(PyArray_SetBaseObject(__pyx_v_arr, __pyx_v_base)); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":931 + * int _import_umath() except -1 + * + * cdef inline void set_array_base(ndarray arr, object base): # <<<<<<<<<<<<<< + * Py_INCREF(base) # important to do this before stealing the reference below! + * PyArray_SetBaseObject(arr, base) + */ + + /* function exit code */ + __Pyx_RefNannyFinishContext(); +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":935 + * PyArray_SetBaseObject(arr, base) + * + * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< + * base = PyArray_BASE(arr) + * if base is NULL: + */ + +static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__pyx_v_arr) { + PyObject *__pyx_v_base; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("get_array_base", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":936 + * + * cdef inline object get_array_base(ndarray arr): + * base = PyArray_BASE(arr) # <<<<<<<<<<<<<< + * if base is NULL: + * return None + */ + __pyx_v_base = PyArray_BASE(__pyx_v_arr); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":937 + * cdef inline object get_array_base(ndarray arr): + * base = PyArray_BASE(arr) + * if base is NULL: # <<<<<<<<<<<<<< + * return None + * return base + */ + __pyx_t_1 = ((__pyx_v_base == NULL) != 0); + if (__pyx_t_1) { + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":938 + * base = PyArray_BASE(arr) + * if base is NULL: + * return None # <<<<<<<<<<<<<< + * return base + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":937 + * cdef inline object get_array_base(ndarray arr): + * base = PyArray_BASE(arr) + * if base is NULL: # <<<<<<<<<<<<<< + * return None + * return base + */ + } + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":939 + * if base is NULL: + * return None + * return base # <<<<<<<<<<<<<< + * + * # Versions of the import_* functions which are more suitable for + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_base)); + __pyx_r = ((PyObject *)__pyx_v_base); + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":935 + * PyArray_SetBaseObject(arr, base) + * + * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< + * base = PyArray_BASE(arr) + * if base is NULL: + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":943 + * # Versions of the import_* functions which are more suitable for + * # Cython code. + * cdef inline int import_array() except -1: # <<<<<<<<<<<<<< + * try: + * __pyx_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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("import_array", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":944 + * # Cython code. + * cdef inline int import_array() except -1: + * try: # <<<<<<<<<<<<<< + * __pyx_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:*/ { + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":945 + * cdef inline int import_array() except -1: + * try: + * __pyx_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, 945, __pyx_L3_error) + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":944 + * # Cython code. + * cdef inline int import_array() except -1: + * try: # <<<<<<<<<<<<<< + * __pyx_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:; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":946 + * try: + * __pyx_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, 946, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_7); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":947 + * __pyx_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__4, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 947, __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, 947, __pyx_L5_except_error) + } + goto __pyx_L5_except_error; + __pyx_L5_except_error:; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":944 + * # Cython code. + * cdef inline int import_array() except -1: + * try: # <<<<<<<<<<<<<< + * __pyx_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:; + } + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":943 + * # Versions of the import_* functions which are more suitable for + * # Cython code. + * cdef inline int import_array() except -1: # <<<<<<<<<<<<<< + * try: + * __pyx_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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":949 + * 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("import_umath", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":950 + * + * 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:*/ { + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":951 + * 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, 951, __pyx_L3_error) + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":950 + * + * 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:; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":952 + * 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, 952, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_7); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":953 + * _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__5, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 953, __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, 953, __pyx_L5_except_error) + } + goto __pyx_L5_except_error; + __pyx_L5_except_error:; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":950 + * + * 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:; + } + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":949 + * 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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":955 + * 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; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("import_ufunc", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":956 + * + * 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:*/ { + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":957 + * 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, 957, __pyx_L3_error) + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":956 + * + * 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:; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":958 + * 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, 958, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_7); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":959 + * _import_umath() + * except Exception: + * raise ImportError("numpy.core.umath failed to import") # <<<<<<<<<<<<<< + * + * cdef extern from *: + */ + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 959, __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, 959, __pyx_L5_except_error) + } + goto __pyx_L5_except_error; + __pyx_L5_except_error:; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":956 + * + * 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:; + } + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":955 + * 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; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":969 + * + * + * cdef inline bint is_timedelta64_object(object obj): # <<<<<<<<<<<<<< + * """ + * Cython equivalent of `isinstance(obj, np.timedelta64)` + */ + +static CYTHON_INLINE int __pyx_f_5numpy_is_timedelta64_object(PyObject *__pyx_v_obj) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("is_timedelta64_object", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":981 + * bool + * """ + * return PyObject_TypeCheck(obj, &PyTimedeltaArrType_Type) # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = PyObject_TypeCheck(__pyx_v_obj, (&PyTimedeltaArrType_Type)); + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":969 + * + * + * cdef inline bint is_timedelta64_object(object obj): # <<<<<<<<<<<<<< + * """ + * Cython equivalent of `isinstance(obj, np.timedelta64)` + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":984 + * + * + * cdef inline bint is_datetime64_object(object obj): # <<<<<<<<<<<<<< + * """ + * Cython equivalent of `isinstance(obj, np.datetime64)` + */ + +static CYTHON_INLINE int __pyx_f_5numpy_is_datetime64_object(PyObject *__pyx_v_obj) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("is_datetime64_object", 0); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":996 + * bool + * """ + * return PyObject_TypeCheck(obj, &PyDatetimeArrType_Type) # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = PyObject_TypeCheck(__pyx_v_obj, (&PyDatetimeArrType_Type)); + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":984 + * + * + * cdef inline bint is_datetime64_object(object obj): # <<<<<<<<<<<<<< + * """ + * Cython equivalent of `isinstance(obj, np.datetime64)` + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":999 + * + * + * cdef inline npy_datetime get_datetime64_value(object obj) nogil: # <<<<<<<<<<<<<< + * """ + * returns the int64 value underlying scalar numpy datetime64 object + */ + +static CYTHON_INLINE npy_datetime __pyx_f_5numpy_get_datetime64_value(PyObject *__pyx_v_obj) { + npy_datetime __pyx_r; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1006 + * also needed. That can be found using `get_datetime64_unit`. + * """ + * return (obj).obval # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = ((PyDatetimeScalarObject *)__pyx_v_obj)->obval; + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":999 + * + * + * cdef inline npy_datetime get_datetime64_value(object obj) nogil: # <<<<<<<<<<<<<< + * """ + * returns the int64 value underlying scalar numpy datetime64 object + */ + + /* function exit code */ + __pyx_L0:; + return __pyx_r; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1009 + * + * + * cdef inline npy_timedelta get_timedelta64_value(object obj) nogil: # <<<<<<<<<<<<<< + * """ + * returns the int64 value underlying scalar numpy timedelta64 object + */ + +static CYTHON_INLINE npy_timedelta __pyx_f_5numpy_get_timedelta64_value(PyObject *__pyx_v_obj) { + npy_timedelta __pyx_r; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1013 + * returns the int64 value underlying scalar numpy timedelta64 object + * """ + * return (obj).obval # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = ((PyTimedeltaScalarObject *)__pyx_v_obj)->obval; + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1009 + * + * + * cdef inline npy_timedelta get_timedelta64_value(object obj) nogil: # <<<<<<<<<<<<<< + * """ + * returns the int64 value underlying scalar numpy timedelta64 object + */ + + /* function exit code */ + __pyx_L0:; + return __pyx_r; +} + +/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1016 + * + * + * cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil: # <<<<<<<<<<<<<< + * """ + * returns the unit part of the dtype for a numpy datetime64 object. + */ + +static CYTHON_INLINE NPY_DATETIMEUNIT __pyx_f_5numpy_get_datetime64_unit(PyObject *__pyx_v_obj) { + NPY_DATETIMEUNIT __pyx_r; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1020 + * returns the unit part of the dtype for a numpy datetime64 object. + * """ + * return (obj).obmeta.base # <<<<<<<<<<<<<< + */ + __pyx_r = ((NPY_DATETIMEUNIT)((PyDatetimeScalarObject *)__pyx_v_obj)->obmeta.base); + goto __pyx_L0; + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1016 + * + * + * cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil: # <<<<<<<<<<<<<< + * """ + * returns the unit part of the dtype for a numpy datetime64 object. + */ + + /* function exit code */ + __pyx_L0:; + return __pyx_r; +} + +/* "pair.to_py":158 + * + * @cname("__pyx_convert_pair_to_py_long____long") + * cdef object __pyx_convert_pair_to_py_long____long(const pair[X,Y]& p): # <<<<<<<<<<<<<< + * return p.first, p.second + * + */ + +static PyObject *__pyx_convert_pair_to_py_long____long(std::pair const &__pyx_v_p) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__pyx_convert_pair_to_py_long____long", 0); + + /* "pair.to_py":159 + * @cname("__pyx_convert_pair_to_py_long____long") + * cdef object __pyx_convert_pair_to_py_long____long(const pair[X,Y]& p): + * return p.first, p.second # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_p.first); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 159, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_p.second); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 159, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 159, __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_2); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + /* "pair.to_py":158 + * + * @cname("__pyx_convert_pair_to_py_long____long") + * cdef object __pyx_convert_pair_to_py_long____long(const pair[X,Y]& p): # <<<<<<<<<<<<<< + * return p.first, p.second + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pair.to_py.__pyx_convert_pair_to_py_long____long", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pair.from_py":145 + * + * @cname("__pyx_convert_pair_from_py_long__and_long") + * cdef pair[X,Y] __pyx_convert_pair_from_py_long__and_long(object o) except *: # <<<<<<<<<<<<<< + * x, y = o + * return pair[X,Y](x, y) + */ + +static std::pair __pyx_convert_pair_from_py_long__and_long(PyObject *__pyx_v_o) { + PyObject *__pyx_v_x = NULL; + PyObject *__pyx_v_y = NULL; + std::pair __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *(*__pyx_t_4)(PyObject *); + long __pyx_t_5; + long __pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__pyx_convert_pair_from_py_long__and_long", 0); + + /* "pair.from_py":146 + * @cname("__pyx_convert_pair_from_py_long__and_long") + * cdef pair[X,Y] __pyx_convert_pair_from_py_long__and_long(object o) except *: + * x, y = o # <<<<<<<<<<<<<< + * return pair[X,Y](x, y) + * + */ + if ((likely(PyTuple_CheckExact(__pyx_v_o))) || (PyList_CheckExact(__pyx_v_o))) { + PyObject* sequence = __pyx_v_o; + 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(1, 146, __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(1, 146, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 146, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } else { + Py_ssize_t index = -1; + __pyx_t_3 = PyObject_GetIter(__pyx_v_o); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 146, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_4(__pyx_t_3); if (unlikely(!__pyx_t_1)) goto __pyx_L3_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 1; __pyx_t_2 = __pyx_t_4(__pyx_t_3); if (unlikely(!__pyx_t_2)) goto __pyx_L3_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_4(__pyx_t_3), 2) < 0) __PYX_ERR(1, 146, __pyx_L1_error) + __pyx_t_4 = NULL; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L4_unpacking_done; + __pyx_L3_unpacking_failed:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_4 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(1, 146, __pyx_L1_error) + __pyx_L4_unpacking_done:; + } + __pyx_v_x = __pyx_t_1; + __pyx_t_1 = 0; + __pyx_v_y = __pyx_t_2; + __pyx_t_2 = 0; + + /* "pair.from_py":147 + * cdef pair[X,Y] __pyx_convert_pair_from_py_long__and_long(object o) except *: + * x, y = o + * return pair[X,Y](x, y) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_5 = __Pyx_PyInt_As_long(__pyx_v_x); if (unlikely((__pyx_t_5 == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 147, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyInt_As_long(__pyx_v_y); if (unlikely((__pyx_t_6 == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 147, __pyx_L1_error) + __pyx_r = std::pair (((long)__pyx_t_5), ((long)__pyx_t_6)); + goto __pyx_L0; + + /* "pair.from_py":145 + * + * @cname("__pyx_convert_pair_from_py_long__and_long") + * cdef pair[X,Y] __pyx_convert_pair_from_py_long__and_long(object o) except *: # <<<<<<<<<<<<<< + * x, y = o + * return pair[X,Y](x, y) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pair.from_py.__pyx_convert_pair_from_py_long__and_long", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_pretend_to_initialize(&__pyx_r); + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_x); + __Pyx_XDECREF(__pyx_v_y); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static struct __pyx_vtabstruct_15pygeoprocessing_7routing_9watershed__ManagedRaster __pyx_vtable_15pygeoprocessing_7routing_9watershed__ManagedRaster; + +static PyObject *__pyx_tp_new_15pygeoprocessing_7routing_9watershed__ManagedRaster(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_15pygeoprocessing_7routing_9watershed__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_9watershed__ManagedRaster *)o); + p->__pyx_vtab = __pyx_vtabptr_15pygeoprocessing_7routing_9watershed__ManagedRaster; + new((void*)&(p->dirty_blocks)) std::set (); + p->raster_path = ((PyObject*)Py_None); Py_INCREF(Py_None); + if (unlikely(__pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_3__cinit__(o, a, k) < 0)) goto bad; + return o; + bad: + Py_DECREF(o); o = 0; + return NULL; +} + +static void __pyx_tp_dealloc_15pygeoprocessing_7routing_9watershed__ManagedRaster(PyObject *o) { + struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *p = (struct __pyx_obj_15pygeoprocessing_7routing_9watershed__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); + __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1); + __pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_5__dealloc__(o); + __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1); + 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_9watershed__ManagedRaster[] = { + {"close", (PyCFunction)__pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_7close, METH_NOARGS, __pyx_doc_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_6close}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_9__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_11__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type_15pygeoprocessing_7routing_9watershed__ManagedRaster = { + PyVarObject_HEAD_INIT(0, 0) + "pygeoprocessing.routing.watershed._ManagedRaster", /*tp_name*/ + sizeof(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_15pygeoprocessing_7routing_9watershed__ManagedRaster, /*tp_dealloc*/ + #if PY_VERSION_HEX < 0x030800b4 + 0, /*tp_print*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 + 0, /*tp_vectorcall_offset*/ + #endif + 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_9watershed__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*/ + __pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_1__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_15pygeoprocessing_7routing_9watershed__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 + #if PY_VERSION_HEX >= 0x030800b1 + 0, /*tp_vectorcall*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000 + 0, /*tp_print*/ + #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_watershed(PyObject* module); /*proto*/ +static PyModuleDef_Slot __pyx_moduledef_slots[] = { + {Py_mod_create, (void*)__pyx_pymod_create}, + {Py_mod_exec, (void*)__pyx_pymod_exec_watershed}, + {0, NULL} +}; +#endif + +static struct PyModuleDef __pyx_moduledef = { + PyModuleDef_HEAD_INIT, + "watershed", + 0, /* 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 +#ifndef CYTHON_SMALL_CODE +#if defined(__clang__) + #define CYTHON_SMALL_CODE +#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) + #define CYTHON_SMALL_CODE __attribute__((cold)) +#else + #define CYTHON_SMALL_CODE +#endif +#endif + +static __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_kp_u_, __pyx_k_, sizeof(__pyx_k_), 0, 1, 0, 0}, + {&__pyx_kp_u_ALL_TOUCHED_True, __pyx_k_ALL_TOUCHED_True, sizeof(__pyx_k_ALL_TOUCHED_True), 0, 1, 0, 0}, + {&__pyx_n_s_AddGeometry, __pyx_k_AddGeometry, sizeof(__pyx_k_AddGeometry), 0, 0, 1, 1}, + {&__pyx_kp_u_BIGTIFF_YES, __pyx_k_BIGTIFF_YES, sizeof(__pyx_k_BIGTIFF_YES), 0, 1, 0, 0}, + {&__pyx_kp_u_BLOCKXSIZE_d, __pyx_k_BLOCKXSIZE_d, sizeof(__pyx_k_BLOCKXSIZE_d), 0, 1, 0, 0}, + {&__pyx_kp_u_BLOCKYSIZE_d, __pyx_k_BLOCKYSIZE_d, sizeof(__pyx_k_BLOCKYSIZE_d), 0, 1, 0, 0}, + {&__pyx_n_s_BuildVRT, __pyx_k_BuildVRT, sizeof(__pyx_k_BuildVRT), 0, 0, 1, 1}, + {&__pyx_n_s_BuildVRTOptions, __pyx_k_BuildVRTOptions, sizeof(__pyx_k_BuildVRTOptions), 0, 0, 1, 1}, + {&__pyx_kp_u_COMPRESS_LZW, __pyx_k_COMPRESS_LZW, sizeof(__pyx_k_COMPRESS_LZW), 0, 1, 0, 0}, + {&__pyx_n_s_CommitTransaction, __pyx_k_CommitTransaction, sizeof(__pyx_k_CommitTransaction), 0, 0, 1, 1}, + {&__pyx_kp_u_Consolidating_s_fragments_and_co, __pyx_k_Consolidating_s_fragments_and_co, sizeof(__pyx_k_Consolidating_s_fragments_and_co), 0, 1, 0, 0}, + {&__pyx_kp_u_Could_not_open_outflow_vector_s, __pyx_k_Could_not_open_outflow_vector_s, sizeof(__pyx_k_Could_not_open_outflow_vector_s), 0, 1, 0, 0}, + {&__pyx_n_s_Create, __pyx_k_Create, sizeof(__pyx_k_Create), 0, 0, 1, 1}, + {&__pyx_n_s_CreateDataSource, __pyx_k_CreateDataSource, sizeof(__pyx_k_CreateDataSource), 0, 0, 1, 1}, + {&__pyx_n_s_CreateFeature, __pyx_k_CreateFeature, sizeof(__pyx_k_CreateFeature), 0, 0, 1, 1}, + {&__pyx_n_s_CreateField, __pyx_k_CreateField, sizeof(__pyx_k_CreateField), 0, 0, 1, 1}, + {&__pyx_n_s_CreateFields, __pyx_k_CreateFields, sizeof(__pyx_k_CreateFields), 0, 0, 1, 1}, + {&__pyx_n_s_CreateGeometryFromWkb, __pyx_k_CreateGeometryFromWkb, sizeof(__pyx_k_CreateGeometryFromWkb), 0, 0, 1, 1}, + {&__pyx_n_s_CreateLayer, __pyx_k_CreateLayer, sizeof(__pyx_k_CreateLayer), 0, 0, 1, 1}, + {&__pyx_kp_u_Creating_flow_dir_bbox, __pyx_k_Creating_flow_dir_bbox, sizeof(__pyx_k_Creating_flow_dir_bbox), 0, 1, 0, 0}, + {&__pyx_kp_u_Creating_flow_dir_managed_raster, __pyx_k_Creating_flow_dir_managed_raster, sizeof(__pyx_k_Creating_flow_dir_managed_raster), 0, 1, 0, 0}, + {&__pyx_n_s_DeleteLayer, __pyx_k_DeleteLayer, sizeof(__pyx_k_DeleteLayer), 0, 0, 1, 1}, + {&__pyx_kp_u_Delineating_watershed_s_of_s_ws, __pyx_k_Delineating_watershed_s_of_s_ws, sizeof(__pyx_k_Delineating_watershed_s_of_s_ws), 0, 1, 0, 0}, + {&__pyx_kp_u_Delineating_watershed_s_of_s_ws_2, __pyx_k_Delineating_watershed_s_of_s_ws_2, sizeof(__pyx_k_Delineating_watershed_s_of_s_ws_2), 0, 1, 0, 0}, + {&__pyx_kp_u_Delineating_watersheds, __pyx_k_Delineating_watersheds, sizeof(__pyx_k_Delineating_watersheds), 0, 1, 0, 0}, + {&__pyx_kp_u_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, 1, 0, 0}, + {&__pyx_kp_u_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, 1, 0, 0}, + {&__pyx_n_s_ExportToWkb, __pyx_k_ExportToWkb, sizeof(__pyx_k_ExportToWkb), 0, 0, 1, 1}, + {&__pyx_n_s_ExportToWkt, __pyx_k_ExportToWkt, sizeof(__pyx_k_ExportToWkt), 0, 0, 1, 1}, + {&__pyx_n_s_Feature, __pyx_k_Feature, sizeof(__pyx_k_Feature), 0, 0, 1, 1}, + {&__pyx_n_s_FieldDefn, __pyx_k_FieldDefn, sizeof(__pyx_k_FieldDefn), 0, 0, 1, 1}, + {&__pyx_kp_u_Finished_delineating_s_watershed, __pyx_k_Finished_delineating_s_watershed, sizeof(__pyx_k_Finished_delineating_s_watershed), 0, 1, 0, 0}, + {&__pyx_kp_u_Finished_vector_consolidation, __pyx_k_Finished_vector_consolidation, sizeof(__pyx_k_Finished_vector_consolidation), 0, 1, 0, 0}, + {&__pyx_n_s_FlushCache, __pyx_k_FlushCache, sizeof(__pyx_k_FlushCache), 0, 0, 1, 1}, + {&__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_UInt32, __pyx_k_GDT_UInt32, sizeof(__pyx_k_GDT_UInt32), 0, 0, 1, 1}, + {&__pyx_n_s_GDT_Unknown, __pyx_k_GDT_Unknown, sizeof(__pyx_k_GDT_Unknown), 0, 0, 1, 1}, + {&__pyx_n_u_GPKG, __pyx_k_GPKG, sizeof(__pyx_k_GPKG), 0, 1, 0, 1}, + {&__pyx_n_s_GTIFF_CREATION_OPTIONS, __pyx_k_GTIFF_CREATION_OPTIONS, sizeof(__pyx_k_GTIFF_CREATION_OPTIONS), 0, 0, 1, 1}, + {&__pyx_n_u_GTiff, __pyx_k_GTiff, sizeof(__pyx_k_GTiff), 0, 1, 0, 1}, + {&__pyx_n_s_Geometry, __pyx_k_Geometry, sizeof(__pyx_k_Geometry), 0, 0, 1, 1}, + {&__pyx_n_s_GetDriverByName, __pyx_k_GetDriverByName, sizeof(__pyx_k_GetDriverByName), 0, 0, 1, 1}, + {&__pyx_n_s_GetFID, __pyx_k_GetFID, sizeof(__pyx_k_GetFID), 0, 0, 1, 1}, + {&__pyx_n_s_GetFeature, __pyx_k_GetFeature, sizeof(__pyx_k_GetFeature), 0, 0, 1, 1}, + {&__pyx_n_s_GetFeatureCount, __pyx_k_GetFeatureCount, sizeof(__pyx_k_GetFeatureCount), 0, 0, 1, 1}, + {&__pyx_n_s_GetField, __pyx_k_GetField, sizeof(__pyx_k_GetField), 0, 0, 1, 1}, + {&__pyx_n_s_GetGeometryRef, __pyx_k_GetGeometryRef, sizeof(__pyx_k_GetGeometryRef), 0, 0, 1, 1}, + {&__pyx_n_s_GetLayer, __pyx_k_GetLayer, sizeof(__pyx_k_GetLayer), 0, 0, 1, 1}, + {&__pyx_n_s_GetLayerDefn, __pyx_k_GetLayerDefn, sizeof(__pyx_k_GetLayerDefn), 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_ImportFromWkt, __pyx_k_ImportFromWkt, sizeof(__pyx_k_ImportFromWkt), 0, 0, 1, 1}, + {&__pyx_n_s_IsEmpty, __pyx_k_IsEmpty, sizeof(__pyx_k_IsEmpty), 0, 0, 1, 1}, + {&__pyx_n_s_LOGGER, __pyx_k_LOGGER, sizeof(__pyx_k_LOGGER), 0, 0, 1, 1}, + {&__pyx_n_s_ManagedRaster, __pyx_k_ManagedRaster, sizeof(__pyx_k_ManagedRaster), 0, 0, 1, 1}, + {&__pyx_n_u_Memory, __pyx_k_Memory, sizeof(__pyx_k_Memory), 0, 1, 0, 1}, + {&__pyx_n_s_OFTInteger, __pyx_k_OFTInteger, sizeof(__pyx_k_OFTInteger), 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_OF_VECTOR, __pyx_k_OF_VECTOR, sizeof(__pyx_k_OF_VECTOR), 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_kp_u_Outflow_feature_s_does_not_inter, __pyx_k_Outflow_feature_s_does_not_inter, sizeof(__pyx_k_Outflow_feature_s_does_not_inter), 0, 1, 0, 0}, + {&__pyx_kp_u_Outflow_feature_s_does_not_overl, __pyx_k_Outflow_feature_s_does_not_overl, sizeof(__pyx_k_Outflow_feature_s_does_not_overl), 0, 1, 0, 0}, + {&__pyx_kp_u_Outflow_feature_s_has_empty_geom, __pyx_k_Outflow_feature_s_has_empty_geom, sizeof(__pyx_k_Outflow_feature_s_has_empty_geom), 0, 1, 0, 0}, + {&__pyx_n_s_Point, __pyx_k_Point, sizeof(__pyx_k_Point), 0, 0, 1, 1}, + {&__pyx_n_s_Polygon, __pyx_k_Polygon, sizeof(__pyx_k_Polygon), 0, 0, 1, 1}, + {&__pyx_n_s_Polygonize, __pyx_k_Polygonize, sizeof(__pyx_k_Polygonize), 0, 0, 1, 1}, + {&__pyx_n_s_RasterizeLayer, __pyx_k_RasterizeLayer, sizeof(__pyx_k_RasterizeLayer), 0, 0, 1, 1}, + {&__pyx_n_s_ReadAsArray, __pyx_k_ReadAsArray, sizeof(__pyx_k_ReadAsArray), 0, 0, 1, 1}, + {&__pyx_n_s_ResetReading, __pyx_k_ResetReading, sizeof(__pyx_k_ResetReading), 0, 0, 1, 1}, + {&__pyx_kp_u_SPARSE_OK_TRUE, __pyx_k_SPARSE_OK_TRUE, sizeof(__pyx_k_SPARSE_OK_TRUE), 0, 1, 0, 0}, + {&__pyx_n_s_SetField, __pyx_k_SetField, sizeof(__pyx_k_SetField), 0, 0, 1, 1}, + {&__pyx_n_s_SetGeoTransform, __pyx_k_SetGeoTransform, sizeof(__pyx_k_SetGeoTransform), 0, 0, 1, 1}, + {&__pyx_n_s_SetGeometry, __pyx_k_SetGeometry, sizeof(__pyx_k_SetGeometry), 0, 0, 1, 1}, + {&__pyx_n_s_SetProjection, __pyx_k_SetProjection, sizeof(__pyx_k_SetProjection), 0, 0, 1, 1}, + {&__pyx_n_s_SetWidth, __pyx_k_SetWidth, sizeof(__pyx_k_SetWidth), 0, 0, 1, 1}, + {&__pyx_n_s_SpatialReference, __pyx_k_SpatialReference, sizeof(__pyx_k_SpatialReference), 0, 0, 1, 1}, + {&__pyx_n_s_StartTransaction, __pyx_k_StartTransaction, sizeof(__pyx_k_StartTransaction), 0, 0, 1, 1}, + {&__pyx_kp_u_TILED_YES, __pyx_k_TILED_YES, sizeof(__pyx_k_TILED_YES), 0, 1, 0, 0}, + {&__pyx_kp_u_Testing_geometry_bbox, __pyx_k_Testing_geometry_bbox, sizeof(__pyx_k_Testing_geometry_bbox), 0, 1, 0, 0}, + {&__pyx_kp_u_This_exception_is_happeningin_C, __pyx_k_This_exception_is_happeningin_C, sizeof(__pyx_k_This_exception_is_happeningin_C), 0, 1, 0, 0}, + {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1}, + {&__pyx_n_u_VRT, __pyx_k_VRT, sizeof(__pyx_k_VRT), 0, 1, 0, 1}, + {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1}, + {&__pyx_kp_u_WSID_1, __pyx_k_WSID_1, sizeof(__pyx_k_WSID_1), 0, 1, 0, 0}, + {&__pyx_kp_u_Watershed_delineation_complete, __pyx_k_Watershed_delineation_complete, sizeof(__pyx_k_Watershed_delineation_complete), 0, 1, 0, 0}, + {&__pyx_n_s_WriteArray, __pyx_k_WriteArray, sizeof(__pyx_k_WriteArray), 0, 0, 1, 1}, + {&__pyx_kp_u_Y_m_d__H__M__S, __pyx_k_Y_m_d__H__M__S, sizeof(__pyx_k_Y_m_d__H__M__S), 0, 1, 0, 0}, + {&__pyx_n_s__10, __pyx_k__10, sizeof(__pyx_k__10), 0, 0, 1, 1}, + {&__pyx_n_s_allowed_drivers, __pyx_k_allowed_drivers, sizeof(__pyx_k_allowed_drivers), 0, 0, 1, 1}, + {&__pyx_n_s_astype, __pyx_k_astype, sizeof(__pyx_k_astype), 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_bbox_maxx, __pyx_k_bbox_maxx, sizeof(__pyx_k_bbox_maxx), 0, 0, 1, 1}, + {&__pyx_n_s_bbox_maxy, __pyx_k_bbox_maxy, sizeof(__pyx_k_bbox_maxy), 0, 0, 1, 1}, + {&__pyx_n_s_bbox_minx, __pyx_k_bbox_minx, sizeof(__pyx_k_bbox_minx), 0, 0, 1, 1}, + {&__pyx_n_s_bbox_miny, __pyx_k_bbox_miny, sizeof(__pyx_k_bbox_miny), 0, 0, 1, 1}, + {&__pyx_n_u_block_size, __pyx_k_block_size, sizeof(__pyx_k_block_size), 0, 1, 0, 1}, + {&__pyx_n_u_bounding_box, __pyx_k_bounding_box, sizeof(__pyx_k_bounding_box), 0, 1, 0, 1}, + {&__pyx_n_s_bounds, __pyx_k_bounds, sizeof(__pyx_k_bounds), 0, 0, 1, 1}, + {&__pyx_n_s_box, __pyx_k_box, sizeof(__pyx_k_box), 0, 0, 1, 1}, + {&__pyx_n_s_burn_values, __pyx_k_burn_values, sizeof(__pyx_k_burn_values), 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_current_fid, __pyx_k_current_fid, sizeof(__pyx_k_current_fid), 0, 0, 1, 1}, + {&__pyx_n_s_current_pixel, __pyx_k_current_pixel, sizeof(__pyx_k_current_pixel), 0, 0, 1, 1}, + {&__pyx_n_u_d, __pyx_k_d, sizeof(__pyx_k_d), 0, 1, 0, 1}, + {&__pyx_n_s_d8_flow_dir_raster_path_band, __pyx_k_d8_flow_dir_raster_path_band, sizeof(__pyx_k_d8_flow_dir_raster_path_band), 0, 0, 1, 1}, + {&__pyx_n_s_debug, __pyx_k_debug, sizeof(__pyx_k_debug), 0, 0, 1, 1}, + {&__pyx_n_s_delineate_watersheds_d8, __pyx_k_delineate_watersheds_d8, sizeof(__pyx_k_delineate_watersheds_d8), 0, 0, 1, 1}, + {&__pyx_n_s_diagnostic_vector_path, __pyx_k_diagnostic_vector_path, sizeof(__pyx_k_diagnostic_vector_path), 0, 0, 1, 1}, + {&__pyx_n_s_dir, __pyx_k_dir, sizeof(__pyx_k_dir), 0, 0, 1, 1}, + {&__pyx_n_s_driver, __pyx_k_driver, sizeof(__pyx_k_driver), 0, 0, 1, 1}, + {&__pyx_n_s_dtype, __pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 0, 1, 1}, + {&__pyx_n_s_duplicate_feature, __pyx_k_duplicate_feature, sizeof(__pyx_k_duplicate_feature), 0, 0, 1, 1}, + {&__pyx_n_s_duplicate_fid, __pyx_k_duplicate_fid, sizeof(__pyx_k_duplicate_fid), 0, 0, 1, 1}, + {&__pyx_n_s_duplicate_geometry, __pyx_k_duplicate_geometry, sizeof(__pyx_k_duplicate_geometry), 0, 0, 1, 1}, + {&__pyx_n_s_duplicate_ids_set, __pyx_k_duplicate_ids_set, sizeof(__pyx_k_duplicate_ids_set), 0, 0, 1, 1}, + {&__pyx_n_s_duplicate_ids_set_iterator, __pyx_k_duplicate_ids_set_iterator, sizeof(__pyx_k_duplicate_ids_set_iterator), 0, 0, 1, 1}, + {&__pyx_n_s_empty, __pyx_k_empty, sizeof(__pyx_k_empty), 0, 0, 1, 1}, + {&__pyx_n_s_error, __pyx_k_error, sizeof(__pyx_k_error), 0, 0, 1, 1}, + {&__pyx_n_s_exists, __pyx_k_exists, sizeof(__pyx_k_exists), 0, 0, 1, 1}, + {&__pyx_n_s_feature, __pyx_k_feature, sizeof(__pyx_k_feature), 0, 0, 1, 1}, + {&__pyx_n_s_fid, __pyx_k_fid, sizeof(__pyx_k_fid), 0, 0, 1, 1}, + {&__pyx_n_s_field_name, __pyx_k_field_name, sizeof(__pyx_k_field_name), 0, 0, 1, 1}, + {&__pyx_n_s_field_value, __pyx_k_field_value, sizeof(__pyx_k_field_value), 0, 0, 1, 1}, + {&__pyx_n_s_flow_dir_bbox, __pyx_k_flow_dir_bbox, sizeof(__pyx_k_flow_dir_bbox), 0, 0, 1, 1}, + {&__pyx_n_s_flow_dir_info, __pyx_k_flow_dir_info, sizeof(__pyx_k_flow_dir_info), 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_n_cols, __pyx_k_flow_dir_n_cols, sizeof(__pyx_k_flow_dir_n_cols), 0, 0, 1, 1}, + {&__pyx_n_s_flow_dir_n_rows, __pyx_k_flow_dir_n_rows, sizeof(__pyx_k_flow_dir_n_rows), 0, 0, 1, 1}, + {&__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_origin_x, __pyx_k_flow_dir_origin_x, sizeof(__pyx_k_flow_dir_origin_x), 0, 0, 1, 1}, + {&__pyx_n_s_flow_dir_origin_y, __pyx_k_flow_dir_origin_y, sizeof(__pyx_k_flow_dir_origin_y), 0, 0, 1, 1}, + {&__pyx_n_s_flow_dir_pixelsize_x, __pyx_k_flow_dir_pixelsize_x, sizeof(__pyx_k_flow_dir_pixelsize_x), 0, 0, 1, 1}, + {&__pyx_n_s_flow_dir_pixelsize_y, __pyx_k_flow_dir_pixelsize_y, sizeof(__pyx_k_flow_dir_pixelsize_y), 0, 0, 1, 1}, + {&__pyx_n_s_flow_dir_srs, __pyx_k_flow_dir_srs, sizeof(__pyx_k_flow_dir_srs), 0, 0, 1, 1}, + {&__pyx_n_s_fragments_with_duplicates, __pyx_k_fragments_with_duplicates, sizeof(__pyx_k_fragments_with_duplicates), 0, 0, 1, 1}, + {&__pyx_n_s_fragments_with_duplicates_iterat, __pyx_k_fragments_with_duplicates_iterat, sizeof(__pyx_k_fragments_with_duplicates_iterat), 0, 0, 1, 1}, + {&__pyx_n_s_gdal, __pyx_k_gdal, sizeof(__pyx_k_gdal), 0, 0, 1, 1}, + {&__pyx_n_s_geom, __pyx_k_geom, sizeof(__pyx_k_geom), 0, 0, 1, 1}, + {&__pyx_n_s_geom_wkb, __pyx_k_geom_wkb, sizeof(__pyx_k_geom_wkb), 0, 0, 1, 1}, + {&__pyx_n_s_geometry, __pyx_k_geometry, sizeof(__pyx_k_geometry), 0, 0, 1, 1}, + {&__pyx_n_s_geotransform, __pyx_k_geotransform, sizeof(__pyx_k_geotransform), 0, 0, 1, 1}, + {&__pyx_n_u_geotransform, __pyx_k_geotransform, sizeof(__pyx_k_geotransform), 0, 1, 0, 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_driver, __pyx_k_gtiff_driver, sizeof(__pyx_k_gtiff_driver), 0, 0, 1, 1}, + {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, + {&__pyx_n_s_index_field, __pyx_k_index_field, sizeof(__pyx_k_index_field), 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_intersects, __pyx_k_intersects, sizeof(__pyx_k_intersects), 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_items, __pyx_k_items, sizeof(__pyx_k_items), 0, 0, 1, 1}, + {&__pyx_n_s_iterblocks, __pyx_k_iterblocks, sizeof(__pyx_k_iterblocks), 0, 0, 1, 1}, + {&__pyx_n_s_ix_max, __pyx_k_ix_max, sizeof(__pyx_k_ix_max), 0, 0, 1, 1}, + {&__pyx_n_s_ix_min, __pyx_k_ix_min, sizeof(__pyx_k_ix_min), 0, 0, 1, 1}, + {&__pyx_n_s_iy_max, __pyx_k_iy_max, sizeof(__pyx_k_iy_max), 0, 0, 1, 1}, + {&__pyx_n_s_iy_min, __pyx_k_iy_min, sizeof(__pyx_k_iy_min), 0, 0, 1, 1}, + {&__pyx_n_s_join, __pyx_k_join, sizeof(__pyx_k_join), 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_loads, __pyx_k_loads, sizeof(__pyx_k_loads), 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_u_mem, __pyx_k_mem, sizeof(__pyx_k_mem), 0, 1, 0, 1}, + {&__pyx_n_s_mkdtemp, __pyx_k_mkdtemp, sizeof(__pyx_k_mkdtemp), 0, 0, 1, 1}, + {&__pyx_n_u_n_bands, __pyx_k_n_bands, sizeof(__pyx_k_n_bands), 0, 1, 0, 1}, + {&__pyx_n_s_n_cells_visited, __pyx_k_n_cells_visited, sizeof(__pyx_k_n_cells_visited), 0, 0, 1, 1}, + {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, + {&__pyx_n_s_neighbor_col, __pyx_k_neighbor_col, sizeof(__pyx_k_neighbor_col), 0, 0, 1, 1}, + {&__pyx_n_s_neighbor_index, __pyx_k_neighbor_index, sizeof(__pyx_k_neighbor_index), 0, 0, 1, 1}, + {&__pyx_n_s_neighbor_pixel, __pyx_k_neighbor_pixel, sizeof(__pyx_k_neighbor_pixel), 0, 0, 1, 1}, + {&__pyx_n_s_neighbor_row, __pyx_k_neighbor_row, sizeof(__pyx_k_neighbor_row), 0, 0, 1, 1}, + {&__pyx_n_s_new_geometry, __pyx_k_new_geometry, sizeof(__pyx_k_new_geometry), 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_u_nodata, __pyx_k_nodata, sizeof(__pyx_k_nodata), 0, 1, 0, 1}, + {&__pyx_n_s_numpy, __pyx_k_numpy, sizeof(__pyx_k_numpy), 0, 0, 1, 1}, + {&__pyx_kp_u_numpy_core_multiarray_failed_to, __pyx_k_numpy_core_multiarray_failed_to, sizeof(__pyx_k_numpy_core_multiarray_failed_to), 0, 1, 0, 0}, + {&__pyx_kp_u_numpy_core_umath_failed_to_impor, __pyx_k_numpy_core_umath_failed_to_impor, sizeof(__pyx_k_numpy_core_umath_failed_to_impor), 0, 1, 0, 0}, + {&__pyx_n_s_ogr, __pyx_k_ogr, sizeof(__pyx_k_ogr), 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_osr, __pyx_k_osr, sizeof(__pyx_k_osr), 0, 0, 1, 1}, + {&__pyx_n_s_outflow_feature_count, __pyx_k_outflow_feature_count, sizeof(__pyx_k_outflow_feature_count), 0, 0, 1, 1}, + {&__pyx_n_s_outflow_layer, __pyx_k_outflow_layer, sizeof(__pyx_k_outflow_layer), 0, 0, 1, 1}, + {&__pyx_n_s_outflow_vector, __pyx_k_outflow_vector, sizeof(__pyx_k_outflow_vector), 0, 0, 1, 1}, + {&__pyx_n_s_outflow_vector_path, __pyx_k_outflow_vector_path, sizeof(__pyx_k_outflow_vector_path), 0, 0, 1, 1}, + {&__pyx_n_s_outputBounds, __pyx_k_outputBounds, sizeof(__pyx_k_outputBounds), 0, 0, 1, 1}, + {&__pyx_n_s_path, __pyx_k_path, sizeof(__pyx_k_path), 0, 0, 1, 1}, + {&__pyx_n_u_polygonized_watersheds, __pyx_k_polygonized_watersheds, sizeof(__pyx_k_polygonized_watersheds), 0, 1, 0, 1}, + {&__pyx_n_s_polygonized_watersheds_layer, __pyx_k_polygonized_watersheds_layer, sizeof(__pyx_k_polygonized_watersheds_layer), 0, 0, 1, 1}, + {&__pyx_n_s_prefix, __pyx_k_prefix, sizeof(__pyx_k_prefix), 0, 0, 1, 1}, + {&__pyx_n_s_prep, __pyx_k_prep, sizeof(__pyx_k_prep), 0, 0, 1, 1}, + {&__pyx_n_s_prepared, __pyx_k_prepared, sizeof(__pyx_k_prepared), 0, 0, 1, 1}, + {&__pyx_n_s_process_queue, __pyx_k_process_queue, sizeof(__pyx_k_process_queue), 0, 0, 1, 1}, + {&__pyx_n_s_process_queue_set, __pyx_k_process_queue_set, sizeof(__pyx_k_process_queue_set), 0, 0, 1, 1}, + {&__pyx_n_u_projection_wkt, __pyx_k_projection_wkt, sizeof(__pyx_k_projection_wkt), 0, 1, 0, 1}, + {&__pyx_n_s_pygeoprocessing, __pyx_k_pygeoprocessing, sizeof(__pyx_k_pygeoprocessing), 0, 0, 1, 1}, + {&__pyx_n_s_pygeoprocessing_routing_watershe, __pyx_k_pygeoprocessing_routing_watershe, sizeof(__pyx_k_pygeoprocessing_routing_watershe), 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_u_raster_size, __pyx_k_raster_size, sizeof(__pyx_k_raster_size), 0, 1, 0, 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_remove, __pyx_k_remove, sizeof(__pyx_k_remove), 0, 0, 1, 1}, + {&__pyx_n_s_remove_temp_files, __pyx_k_remove_temp_files, sizeof(__pyx_k_remove_temp_files), 0, 0, 1, 1}, + {&__pyx_n_s_return_set, __pyx_k_return_set, sizeof(__pyx_k_return_set), 0, 0, 1, 1}, + {&__pyx_n_s_reverse_flow, __pyx_k_reverse_flow, sizeof(__pyx_k_reverse_flow), 0, 0, 1, 1}, + {&__pyx_n_s_rmtree, __pyx_k_rmtree, sizeof(__pyx_k_rmtree), 0, 0, 1, 1}, + {&__pyx_kp_u_s_is_not_a_file, __pyx_k_s_is_not_a_file, sizeof(__pyx_k_s_is_not_a_file), 0, 1, 0, 0}, + {&__pyx_kp_u_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, 1, 0, 0}, + {&__pyx_kp_u_s_rasterized_tif, __pyx_k_s_rasterized_tif, sizeof(__pyx_k_s_rasterized_tif), 0, 1, 0, 0}, + {&__pyx_kp_u_s_scratch_tif, __pyx_k_s_scratch_tif, sizeof(__pyx_k_s_scratch_tif), 0, 1, 0, 0}, + {&__pyx_kp_u_s_seeds_gpkg, __pyx_k_s_seeds_gpkg, sizeof(__pyx_k_s_seeds_gpkg), 0, 1, 0, 0}, + {&__pyx_kp_u_s_vrt_vrt, __pyx_k_s_vrt_vrt, sizeof(__pyx_k_s_vrt_vrt), 0, 1, 0, 0}, + {&__pyx_n_s_schema, __pyx_k_schema, sizeof(__pyx_k_schema), 0, 0, 1, 1}, + {&__pyx_n_s_scratch_managed_raster, __pyx_k_scratch_managed_raster, sizeof(__pyx_k_scratch_managed_raster), 0, 0, 1, 1}, + {&__pyx_n_s_scratch_raster, __pyx_k_scratch_raster, sizeof(__pyx_k_scratch_raster), 0, 0, 1, 1}, + {&__pyx_n_s_scratch_raster_path, __pyx_k_scratch_raster_path, sizeof(__pyx_k_scratch_raster_path), 0, 0, 1, 1}, + {&__pyx_n_s_seed, __pyx_k_seed, sizeof(__pyx_k_seed), 0, 0, 1, 1}, + {&__pyx_n_s_seed_iterator, __pyx_k_seed_iterator, sizeof(__pyx_k_seed_iterator), 0, 0, 1, 1}, + {&__pyx_n_s_seeds, __pyx_k_seeds, sizeof(__pyx_k_seeds), 0, 0, 1, 1}, + {&__pyx_n_u_seeds, __pyx_k_seeds, sizeof(__pyx_k_seeds), 0, 1, 0, 1}, + {&__pyx_n_s_seeds_in_watershed, __pyx_k_seeds_in_watershed, sizeof(__pyx_k_seeds_in_watershed), 0, 0, 1, 1}, + {&__pyx_n_s_seeds_iterator, __pyx_k_seeds_iterator, sizeof(__pyx_k_seeds_iterator), 0, 0, 1, 1}, + {&__pyx_n_s_seeds_raster_path, __pyx_k_seeds_raster_path, sizeof(__pyx_k_seeds_raster_path), 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_shapely, __pyx_k_shapely, sizeof(__pyx_k_shapely), 0, 0, 1, 1}, + {&__pyx_n_s_shapely_geom, __pyx_k_shapely_geom, sizeof(__pyx_k_shapely_geom), 0, 0, 1, 1}, + {&__pyx_n_s_shapely_geometry, __pyx_k_shapely_geometry, sizeof(__pyx_k_shapely_geometry), 0, 0, 1, 1}, + {&__pyx_n_s_shapely_prepared, __pyx_k_shapely_prepared, sizeof(__pyx_k_shapely_prepared), 0, 0, 1, 1}, + {&__pyx_n_s_shapely_wkb, __pyx_k_shapely_wkb, sizeof(__pyx_k_shapely_wkb), 0, 0, 1, 1}, + {&__pyx_n_s_shutil, __pyx_k_shutil, sizeof(__pyx_k_shutil), 0, 0, 1, 1}, + {&__pyx_n_s_source_feature, __pyx_k_source_feature, sizeof(__pyx_k_source_feature), 0, 0, 1, 1}, + {&__pyx_n_s_source_geom_wkb, __pyx_k_source_geom_wkb, sizeof(__pyx_k_source_geom_wkb), 0, 0, 1, 1}, + {&__pyx_n_s_source_gt, __pyx_k_source_gt, sizeof(__pyx_k_source_gt), 0, 0, 1, 1}, + {&__pyx_n_s_source_layer, __pyx_k_source_layer, sizeof(__pyx_k_source_layer), 0, 0, 1, 1}, + {&__pyx_n_s_source_vector, __pyx_k_source_vector, sizeof(__pyx_k_source_vector), 0, 0, 1, 1}, + {&__pyx_n_s_split_geometry_into_seeds, __pyx_k_split_geometry_into_seeds, sizeof(__pyx_k_split_geometry_into_seeds), 0, 0, 1, 1}, + {&__pyx_kp_s_src_pygeoprocessing_routing_wate, __pyx_k_src_pygeoprocessing_routing_wate, sizeof(__pyx_k_src_pygeoprocessing_routing_wate), 0, 0, 1, 0}, + {&__pyx_n_s_strftime, __pyx_k_strftime, sizeof(__pyx_k_strftime), 0, 0, 1, 1}, + {&__pyx_n_s_target_layer_name, __pyx_k_target_layer_name, sizeof(__pyx_k_target_layer_name), 0, 0, 1, 1}, + {&__pyx_n_s_target_raster_path, __pyx_k_target_raster_path, sizeof(__pyx_k_target_raster_path), 0, 0, 1, 1}, + {&__pyx_n_s_target_watersheds_vector_path, __pyx_k_target_watersheds_vector_path, sizeof(__pyx_k_target_watersheds_vector_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_u_user_geometry, __pyx_k_user_geometry, sizeof(__pyx_k_user_geometry), 0, 1, 0, 1}, + {&__pyx_n_s_vrt_band, __pyx_k_vrt_band, sizeof(__pyx_k_vrt_band), 0, 0, 1, 1}, + {&__pyx_n_s_vrt_options, __pyx_k_vrt_options, sizeof(__pyx_k_vrt_options), 0, 0, 1, 1}, + {&__pyx_n_s_vrt_path, __pyx_k_vrt_path, sizeof(__pyx_k_vrt_path), 0, 0, 1, 1}, + {&__pyx_n_s_vrt_raster, __pyx_k_vrt_raster, sizeof(__pyx_k_vrt_raster), 0, 0, 1, 1}, + {&__pyx_kp_u_watershed_delineation_trivial__s, __pyx_k_watershed_delineation_trivial__s, sizeof(__pyx_k_watershed_delineation_trivial__s), 0, 1, 0, 0}, + {&__pyx_n_s_watershed_feature, __pyx_k_watershed_feature, sizeof(__pyx_k_watershed_feature), 0, 0, 1, 1}, + {&__pyx_n_u_watersheds, __pyx_k_watersheds, sizeof(__pyx_k_watersheds), 0, 1, 0, 1}, + {&__pyx_n_s_watersheds_created, __pyx_k_watersheds_created, sizeof(__pyx_k_watersheds_created), 0, 0, 1, 1}, + {&__pyx_n_s_watersheds_layer, __pyx_k_watersheds_layer, sizeof(__pyx_k_watersheds_layer), 0, 0, 1, 1}, + {&__pyx_n_s_watersheds_srs, __pyx_k_watersheds_srs, sizeof(__pyx_k_watersheds_srs), 0, 0, 1, 1}, + {&__pyx_n_s_watersheds_vector, __pyx_k_watersheds_vector, sizeof(__pyx_k_watersheds_vector), 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_wkb, __pyx_k_wkb, sizeof(__pyx_k_wkb), 0, 0, 1, 1}, + {&__pyx_n_s_wkbMultiPolygon, __pyx_k_wkbMultiPolygon, sizeof(__pyx_k_wkbMultiPolygon), 0, 0, 1, 1}, + {&__pyx_n_s_wkbPoint, __pyx_k_wkbPoint, sizeof(__pyx_k_wkbPoint), 0, 0, 1, 1}, + {&__pyx_n_s_wkbPolygon, __pyx_k_wkbPolygon, sizeof(__pyx_k_wkbPolygon), 0, 0, 1, 1}, + {&__pyx_n_s_wkbUnknown, __pyx_k_wkbUnknown, sizeof(__pyx_k_wkbUnknown), 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_write_diagnostic_vector, __pyx_k_write_diagnostic_vector, sizeof(__pyx_k_write_diagnostic_vector), 0, 0, 1, 1}, + {&__pyx_n_s_write_mode, __pyx_k_write_mode, sizeof(__pyx_k_write_mode), 0, 0, 1, 1}, + {&__pyx_n_s_ws_id, __pyx_k_ws_id, sizeof(__pyx_k_ws_id), 0, 0, 1, 1}, + {&__pyx_n_u_ws_id, __pyx_k_ws_id, sizeof(__pyx_k_ws_id), 0, 1, 0, 1}, + {&__pyx_n_s_x1, __pyx_k_x1, sizeof(__pyx_k_x1), 0, 0, 1, 1}, + {&__pyx_n_s_x2, __pyx_k_x2, sizeof(__pyx_k_x2), 0, 0, 1, 1}, + {&__pyx_n_s_xoff, __pyx_k_xoff, sizeof(__pyx_k_xoff), 0, 0, 1, 1}, + {&__pyx_n_u_xoff, __pyx_k_xoff, sizeof(__pyx_k_xoff), 0, 1, 0, 1}, + {&__pyx_n_s_xrange, __pyx_k_xrange, sizeof(__pyx_k_xrange), 0, 0, 1, 1}, + {&__pyx_n_s_y1, __pyx_k_y1, sizeof(__pyx_k_y1), 0, 0, 1, 1}, + {&__pyx_n_s_y2, __pyx_k_y2, sizeof(__pyx_k_y2), 0, 0, 1, 1}, + {&__pyx_n_s_yoff, __pyx_k_yoff, sizeof(__pyx_k_yoff), 0, 0, 1, 1}, + {&__pyx_n_u_yoff, __pyx_k_yoff, sizeof(__pyx_k_yoff), 0, 1, 0, 1}, + {0, 0, 0, 0, 0, 0, 0} +}; +static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { + __pyx_builtin_OSError = __Pyx_GetBuiltinName(__pyx_n_s_OSError); if (!__pyx_builtin_OSError) __PYX_ERR(0, 104, __pyx_L1_error) + __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 114, __pyx_L1_error) + #if PY_MAJOR_VERSION >= 3 + __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_xrange) __PYX_ERR(0, 244, __pyx_L1_error) + #else + __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s_xrange); if (!__pyx_builtin_xrange) __PYX_ERR(0, 244, __pyx_L1_error) + #endif + __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 544, __pyx_L1_error) + __pyx_builtin_ImportError = __Pyx_GetBuiltinName(__pyx_n_s_ImportError); if (!__pyx_builtin_ImportError) __PYX_ERR(2, 947, __pyx_L1_error) + return 0; + __pyx_L1_error:; + return -1; +} + +static CYTHON_SMALL_CODE 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__2 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__2); + __Pyx_GIVEREF(__pyx_tuple__2); + + /* "(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__3 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__3); + __Pyx_GIVEREF(__pyx_tuple__3); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":947 + * __pyx_import_array() + * except Exception: + * raise ImportError("numpy.core.multiarray failed to import") # <<<<<<<<<<<<<< + * + * cdef inline int import_umath() except -1: + */ + __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_u_numpy_core_multiarray_failed_to); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(2, 947, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__4); + __Pyx_GIVEREF(__pyx_tuple__4); + + /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":953 + * _import_umath() + * except Exception: + * raise ImportError("numpy.core.umath failed to import") # <<<<<<<<<<<<<< + * + * cdef inline int import_ufunc() except -1: + */ + __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_u_numpy_core_umath_failed_to_impor); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(2, 953, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__5); + __Pyx_GIVEREF(__pyx_tuple__5); + + /* "pygeoprocessing/routing/watershed.pyx":388 + * + * + * 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__6 = PyTuple_Pack(1, __pyx_n_s_raster_path_band); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 388, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__6); + __Pyx_GIVEREF(__pyx_tuple__6); + __pyx_codeobj__7 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__6, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_wate, __pyx_n_s_is_raster_path_band_formatted, 388, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__7)) __PYX_ERR(0, 388, __pyx_L1_error) + + /* "pygeoprocessing/routing/watershed.pyx":571 + * + * + * def _split_geometry_into_seeds( # <<<<<<<<<<<<<< + * source_geom_wkb, geotransform, flow_dir_srs, + * flow_dir_n_cols, flow_dir_n_rows, target_raster_path, + */ + __pyx_tuple__8 = PyTuple_Pack(11, __pyx_n_s_source_geom_wkb, __pyx_n_s_geotransform, __pyx_n_s_flow_dir_srs, __pyx_n_s_flow_dir_n_cols, __pyx_n_s_flow_dir_n_rows, __pyx_n_s_target_raster_path, __pyx_n_s_diagnostic_vector_path, __pyx_n_s_return_set, __pyx_n_s_seeds, __pyx_n_s_seed, __pyx_n_s_seeds_iterator); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 571, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__8); + __Pyx_GIVEREF(__pyx_tuple__8); + __pyx_codeobj__9 = (PyObject*)__Pyx_PyCode_New(7, 0, 11, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__8, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_wate, __pyx_n_s_split_geometry_into_seeds, 571, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__9)) __PYX_ERR(0, 571, __pyx_L1_error) + + /* "pygeoprocessing/routing/watershed.pyx":624 + * + * @cython.boundscheck(False) + * def delineate_watersheds_d8( # <<<<<<<<<<<<<< + * d8_flow_dir_raster_path_band, outflow_vector_path, + * target_watersheds_vector_path, working_dir=None, + */ + __pyx_tuple__11 = PyTuple_Pack(87, __pyx_n_s_d8_flow_dir_raster_path_band, __pyx_n_s_outflow_vector_path, __pyx_n_s_target_watersheds_vector_path, __pyx_n_s_working_dir, __pyx_n_s_write_diagnostic_vector, __pyx_n_s_remove_temp_files, __pyx_n_s_target_layer_name, __pyx_n_s_working_dir_path, __pyx_n_s_flow_dir_info, __pyx_n_s_flow_dir_nodata, __pyx_n_s_source_gt, __pyx_n_s_flow_dir_origin_x, __pyx_n_s_flow_dir_origin_y, __pyx_n_s_flow_dir_pixelsize_x, __pyx_n_s_flow_dir_pixelsize_y, __pyx_n_s_flow_dir_n_cols, __pyx_n_s_flow_dir_n_rows, __pyx_n_s_ws_id, __pyx_n_s_bbox_minx, __pyx_n_s_bbox_miny, __pyx_n_s_bbox_maxx, __pyx_n_s_bbox_maxy, __pyx_n_s_flow_dir_bbox, __pyx_n_s_flow_dir_managed_raster, __pyx_n_s_gtiff_driver, __pyx_n_s_flow_dir_srs, __pyx_n_s_outflow_vector, __pyx_n_s_driver, __pyx_n_s_watersheds_srs, __pyx_n_s_watersheds_vector, __pyx_n_s_polygonized_watersheds_layer, __pyx_n_s_watersheds_layer, __pyx_n_s_index_field, __pyx_n_s_reverse_flow, __pyx_n_s_neighbor_col, __pyx_n_s_neighbor_row, __pyx_n_s_process_queue, __pyx_n_s_process_queue_set, __pyx_n_s_neighbor_pixel, __pyx_n_s_ix_min, __pyx_n_s_iy_min, __pyx_n_s_ix_max, __pyx_n_s_iy_max, __pyx_n_s_scratch_managed_raster, __pyx_n_s_watersheds_created, __pyx_n_s_current_fid, __pyx_n_s_outflow_feature_count, __pyx_n_s_seed_iterator, __pyx_n_s_seeds_in_watershed, __pyx_n_s_last_log_time, __pyx_n_s_n_cells_visited, __pyx_n_s_outflow_layer, __pyx_n_s_feature, __pyx_n_s_geom, __pyx_n_s_geom_wkb, __pyx_n_s_shapely_geom, __pyx_n_s_seeds_raster_path, __pyx_n_s_diagnostic_vector_path, __pyx_n_s_seed, __pyx_n_s_scratch_raster_path, __pyx_n_s_scratch_raster, __pyx_n_s_current_pixel, __pyx_n_s_neighbor_index, __pyx_n_s_x1, __pyx_n_s_y1, __pyx_n_s_x2, __pyx_n_s_y2, __pyx_n_s_vrt_options, __pyx_n_s_vrt_path, __pyx_n_s_vrt_raster, __pyx_n_s_vrt_band, __pyx_n_s__10, __pyx_n_s_fragments_with_duplicates, __pyx_n_s_fid, __pyx_n_s_source_vector, __pyx_n_s_source_layer, __pyx_n_s_duplicate_fid, __pyx_n_s_duplicate_ids_set, __pyx_n_s_duplicate_ids_set_iterator, __pyx_n_s_fragments_with_duplicates_iterat, __pyx_n_s_source_feature, __pyx_n_s_new_geometry, __pyx_n_s_duplicate_feature, __pyx_n_s_duplicate_geometry, __pyx_n_s_watershed_feature, __pyx_n_s_field_name, __pyx_n_s_field_value); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 624, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__11); + __Pyx_GIVEREF(__pyx_tuple__11); + __pyx_codeobj__12 = (PyObject*)__Pyx_PyCode_New(7, 0, 87, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__11, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_wate, __pyx_n_s_delineate_watersheds_d8, 624, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__12)) __PYX_ERR(0, 624, __pyx_L1_error) + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} + +static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { + if (__Pyx_InitStrings(__pyx_string_tab) < 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_24 = PyInt_FromLong(24); if (unlikely(!__pyx_int_24)) __PYX_ERR(0, 1, __pyx_L1_error) + return 0; + __pyx_L1_error:; + return -1; +} + +static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE 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 + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); + /*--- Type init code ---*/ + __pyx_vtabptr_15pygeoprocessing_7routing_9watershed__ManagedRaster = &__pyx_vtable_15pygeoprocessing_7routing_9watershed__ManagedRaster; + __pyx_vtable_15pygeoprocessing_7routing_9watershed__ManagedRaster.set = (void (*)(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *, int, int, int))__pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_set; + __pyx_vtable_15pygeoprocessing_7routing_9watershed__ManagedRaster.get = (int (*)(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *, int, int))__pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_get; + __pyx_vtable_15pygeoprocessing_7routing_9watershed__ManagedRaster._load_block = (void (*)(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *, int))__pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster__load_block; + if (PyType_Ready(&__pyx_type_15pygeoprocessing_7routing_9watershed__ManagedRaster) < 0) __PYX_ERR(0, 69, __pyx_L1_error) + #if PY_VERSION_HEX < 0x030800B1 + __pyx_type_15pygeoprocessing_7routing_9watershed__ManagedRaster.tp_print = 0; + #endif + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_15pygeoprocessing_7routing_9watershed__ManagedRaster.tp_dictoffset && __pyx_type_15pygeoprocessing_7routing_9watershed__ManagedRaster.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_15pygeoprocessing_7routing_9watershed__ManagedRaster.tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + #if CYTHON_COMPILING_IN_CPYTHON + { + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_15pygeoprocessing_7routing_9watershed__ManagedRaster, "__init__"); if (unlikely(!wrapper)) __PYX_ERR(0, 69, __pyx_L1_error) + if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { + __pyx_wrapperbase_15pygeoprocessing_7routing_9watershed_14_ManagedRaster___init__ = *((PyWrapperDescrObject *)wrapper)->d_base; + __pyx_wrapperbase_15pygeoprocessing_7routing_9watershed_14_ManagedRaster___init__.doc = __pyx_doc_15pygeoprocessing_7routing_9watershed_14_ManagedRaster___init__; + ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_15pygeoprocessing_7routing_9watershed_14_ManagedRaster___init__; + } + } + #endif + if (__Pyx_SetVtable(__pyx_type_15pygeoprocessing_7routing_9watershed__ManagedRaster.tp_dict, __pyx_vtabptr_15pygeoprocessing_7routing_9watershed__ManagedRaster) < 0) __PYX_ERR(0, 69, __pyx_L1_error) + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_ManagedRaster, (PyObject *)&__pyx_type_15pygeoprocessing_7routing_9watershed__ManagedRaster) < 0) __PYX_ERR(0, 69, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_15pygeoprocessing_7routing_9watershed__ManagedRaster) < 0) __PYX_ERR(0, 69, __pyx_L1_error) + __pyx_ptype_15pygeoprocessing_7routing_9watershed__ManagedRaster = &__pyx_type_15pygeoprocessing_7routing_9watershed__ManagedRaster; + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} + +static int __Pyx_modinit_type_import_code(void) { + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); + /*--- Type import code ---*/ + __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", + #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 + sizeof(PyTypeObject), + #else + sizeof(PyHeapTypeObject), + #endif + __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(3, 9, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyImport_ImportModule("numpy"); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 200, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_ptype_5numpy_dtype = __Pyx_ImportType(__pyx_t_1, "numpy", "dtype", sizeof(PyArray_Descr), __Pyx_ImportType_CheckSize_Ignore); + if (!__pyx_ptype_5numpy_dtype) __PYX_ERR(2, 200, __pyx_L1_error) + __pyx_ptype_5numpy_flatiter = __Pyx_ImportType(__pyx_t_1, "numpy", "flatiter", sizeof(PyArrayIterObject), __Pyx_ImportType_CheckSize_Ignore); + if (!__pyx_ptype_5numpy_flatiter) __PYX_ERR(2, 223, __pyx_L1_error) + __pyx_ptype_5numpy_broadcast = __Pyx_ImportType(__pyx_t_1, "numpy", "broadcast", sizeof(PyArrayMultiIterObject), __Pyx_ImportType_CheckSize_Ignore); + if (!__pyx_ptype_5numpy_broadcast) __PYX_ERR(2, 227, __pyx_L1_error) + __pyx_ptype_5numpy_ndarray = __Pyx_ImportType(__pyx_t_1, "numpy", "ndarray", sizeof(PyArrayObject), __Pyx_ImportType_CheckSize_Ignore); + if (!__pyx_ptype_5numpy_ndarray) __PYX_ERR(2, 239, __pyx_L1_error) + __pyx_ptype_5numpy_generic = __Pyx_ImportType(__pyx_t_1, "numpy", "generic", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_generic) __PYX_ERR(2, 771, __pyx_L1_error) + __pyx_ptype_5numpy_number = __Pyx_ImportType(__pyx_t_1, "numpy", "number", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_number) __PYX_ERR(2, 773, __pyx_L1_error) + __pyx_ptype_5numpy_integer = __Pyx_ImportType(__pyx_t_1, "numpy", "integer", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_integer) __PYX_ERR(2, 775, __pyx_L1_error) + __pyx_ptype_5numpy_signedinteger = __Pyx_ImportType(__pyx_t_1, "numpy", "signedinteger", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_signedinteger) __PYX_ERR(2, 777, __pyx_L1_error) + __pyx_ptype_5numpy_unsignedinteger = __Pyx_ImportType(__pyx_t_1, "numpy", "unsignedinteger", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_unsignedinteger) __PYX_ERR(2, 779, __pyx_L1_error) + __pyx_ptype_5numpy_inexact = __Pyx_ImportType(__pyx_t_1, "numpy", "inexact", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_inexact) __PYX_ERR(2, 781, __pyx_L1_error) + __pyx_ptype_5numpy_floating = __Pyx_ImportType(__pyx_t_1, "numpy", "floating", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_floating) __PYX_ERR(2, 783, __pyx_L1_error) + __pyx_ptype_5numpy_complexfloating = __Pyx_ImportType(__pyx_t_1, "numpy", "complexfloating", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_complexfloating) __PYX_ERR(2, 785, __pyx_L1_error) + __pyx_ptype_5numpy_flexible = __Pyx_ImportType(__pyx_t_1, "numpy", "flexible", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_flexible) __PYX_ERR(2, 787, __pyx_L1_error) + __pyx_ptype_5numpy_character = __Pyx_ImportType(__pyx_t_1, "numpy", "character", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_5numpy_character) __PYX_ERR(2, 789, __pyx_L1_error) + __pyx_ptype_5numpy_ufunc = __Pyx_ImportType(__pyx_t_1, "numpy", "ufunc", sizeof(PyUFuncObject), __Pyx_ImportType_CheckSize_Ignore); + if (!__pyx_ptype_5numpy_ufunc) __PYX_ERR(2, 827, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __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; +} + + +#ifndef CYTHON_NO_PYINIT_EXPORT +#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC +#elif PY_MAJOR_VERSION < 3 +#ifdef __cplusplus +#define __Pyx_PyMODINIT_FUNC extern "C" void +#else +#define __Pyx_PyMODINIT_FUNC void +#endif +#else +#ifdef __cplusplus +#define __Pyx_PyMODINIT_FUNC extern "C" PyObject * +#else +#define __Pyx_PyMODINIT_FUNC PyObject * +#endif +#endif + + +#if PY_MAJOR_VERSION < 3 +__Pyx_PyMODINIT_FUNC initwatershed(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC initwatershed(void) +#else +__Pyx_PyMODINIT_FUNC PyInit_watershed(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC PyInit_watershed(void) +#if CYTHON_PEP489_MULTI_PHASE_INIT +{ + return PyModuleDef_Init(&__pyx_moduledef); +} +static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) { + #if PY_VERSION_HEX >= 0x030700A1 + static PY_INT64_T main_interpreter_id = -1; + PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp); + if (main_interpreter_id == -1) { + main_interpreter_id = current_id; + return (unlikely(current_id == -1)) ? -1 : 0; + } else if (unlikely(main_interpreter_id != current_id)) + #else + static PyInterpreterState *main_interpreter = NULL; + PyInterpreterState *current_interpreter = PyThreadState_Get()->interp; + if (!main_interpreter) { + main_interpreter = current_interpreter; + } else if (unlikely(main_interpreter != current_interpreter)) + #endif + { + PyErr_SetString( + PyExc_ImportError, + "Interpreter change detected - this module can only be loaded into one interpreter per process."); + return -1; + } + return 0; +} +static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) { + PyObject *value = PyObject_GetAttrString(spec, from_name); + int result = 0; + if (likely(value)) { + if (allow_none || value != Py_None) { + result = PyDict_SetItemString(moddict, to_name, value); + } + Py_DECREF(value); + } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Clear(); + } else { + result = -1; + } + return result; +} +static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) { + PyObject *module = NULL, *moddict, *modname; + if (__Pyx_check_single_interpreter()) + return NULL; + 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__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad; + return module; +bad: + Py_XDECREF(module); + return NULL; +} + + +static CYTHON_SMALL_CODE int __pyx_pymod_exec_watershed(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[8]; + static int __pyx_t_5[8]; + static int __pyx_t_6[8]; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannyDeclarations + #if CYTHON_PEP489_MULTI_PHASE_INIT + if (__pyx_m) { + if (__pyx_m == __pyx_pyinit_module) return 0; + PyErr_SetString(PyExc_RuntimeError, "Module 'watershed' has already been imported. Re-initialisation is not supported."); + return -1; + } + #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_watershed(void)", 0); + if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pxy_PyFrame_Initialize_Offsets + __Pxy_PyFrame_Initialize_Offsets(); + #endif + __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("watershed", __pyx_methods, 0, 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) + Py_INCREF(__pyx_b); + __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) + Py_INCREF(__pyx_cython_runtime); + 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__watershed) { + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_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.watershed")) { + if (unlikely(PyDict_SetItemString(modules, "pygeoprocessing.routing.watershed", __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)) __PYX_ERR(0, 1, __pyx_L1_error) + if (unlikely(__Pyx_modinit_type_import_code() < 0)) __PYX_ERR(0, 1, __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/watershed.pyx":3 + * # coding=UTF-8 + * # cython: language_level=3 + * import logging # <<<<<<<<<<<<<< + * import os + * import shutil + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_logging, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_logging, __pyx_t_1) < 0) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":4 + * # cython: language_level=3 + * import logging + * import os # <<<<<<<<<<<<<< + * import shutil + * import tempfile + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_os, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_1) < 0) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":5 + * import logging + * import os + * import shutil # <<<<<<<<<<<<<< + * import tempfile + * import time + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_shutil, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_shutil, __pyx_t_1) < 0) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":6 + * import os + * import shutil + * import tempfile # <<<<<<<<<<<<<< + * import time + * + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_tempfile, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_tempfile, __pyx_t_1) < 0) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":7 + * import shutil + * import tempfile + * import time # <<<<<<<<<<<<<< + * + * cimport cython + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_time, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_time, __pyx_t_1) < 0) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":21 + * from libcpp.queue cimport queue + * from libcpp.set cimport set as cset + * from osgeo import gdal # <<<<<<<<<<<<<< + * from osgeo import ogr + * from osgeo import osr + */ + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 21, __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, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 21, __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, 21, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_gdal, __pyx_t_1) < 0) __PYX_ERR(0, 21, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":22 + * from libcpp.set cimport set as cset + * from osgeo import gdal + * from osgeo import ogr # <<<<<<<<<<<<<< + * from osgeo import osr + * import numpy + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 22, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_ogr); + __Pyx_GIVEREF(__pyx_n_s_ogr); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_ogr); + __pyx_t_1 = __Pyx_Import(__pyx_n_s_osgeo, __pyx_t_2, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 22, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 22, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_ogr, __pyx_t_2) < 0) __PYX_ERR(0, 22, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":23 + * from osgeo import gdal + * from osgeo import ogr + * from osgeo import osr # <<<<<<<<<<<<<< + * import numpy + * import shapely.geometry + */ + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 23, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_osr); + __Pyx_GIVEREF(__pyx_n_s_osr); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_osr); + __pyx_t_2 = __Pyx_Import(__pyx_n_s_osgeo, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 23, __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_osr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 23, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_osr, __pyx_t_1) < 0) __PYX_ERR(0, 23, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":24 + * from osgeo import ogr + * from osgeo import osr + * import numpy # <<<<<<<<<<<<<< + * import shapely.geometry + * import shapely.prepared + */ + __pyx_t_2 = __Pyx_Import(__pyx_n_s_numpy, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 24, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_numpy, __pyx_t_2) < 0) __PYX_ERR(0, 24, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":25 + * from osgeo import osr + * import numpy + * import shapely.geometry # <<<<<<<<<<<<<< + * import shapely.prepared + * import shapely.wkb + */ + __pyx_t_2 = __Pyx_Import(__pyx_n_s_shapely_geometry, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 25, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_shapely, __pyx_t_2) < 0) __PYX_ERR(0, 25, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":26 + * import numpy + * import shapely.geometry + * import shapely.prepared # <<<<<<<<<<<<<< + * import shapely.wkb + * + */ + __pyx_t_2 = __Pyx_Import(__pyx_n_s_shapely_prepared, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 26, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_shapely, __pyx_t_2) < 0) __PYX_ERR(0, 26, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":27 + * import shapely.geometry + * import shapely.prepared + * import shapely.wkb # <<<<<<<<<<<<<< + * + * import pygeoprocessing + */ + __pyx_t_2 = __Pyx_Import(__pyx_n_s_shapely_wkb, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 27, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_shapely, __pyx_t_2) < 0) __PYX_ERR(0, 27, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":29 + * import shapely.wkb + * + * import pygeoprocessing # <<<<<<<<<<<<<< + * + * LOGGER = logging.getLogger(__name__) + */ + __pyx_t_2 = __Pyx_Import(__pyx_n_s_pygeoprocessing, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 29, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pygeoprocessing, __pyx_t_2) < 0) __PYX_ERR(0, 29, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":31 + * import pygeoprocessing + * + * LOGGER = logging.getLogger(__name__) # <<<<<<<<<<<<<< + * + * # This module creates rasters with a memory xy block size of 2**BLOCK_BITS + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_logging); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 31, __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, 31, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 31, __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, 31, __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, 31, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":34 + * + * # 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_9watershed_BLOCK_BITS = 8; + + /* "pygeoprocessing/routing/watershed.pyx":37 + * + * # Number of raster blocks to hold in memory at once per Managed Raster + * cdef int MANAGED_RASTER_N_BLOCKS = 2**7 # <<<<<<<<<<<<<< + * + * # these are the creation options that'll be used for all the rasters + */ + __pyx_v_15pygeoprocessing_7routing_9watershed_MANAGED_RASTER_N_BLOCKS = 0x80; + + /* "pygeoprocessing/routing/watershed.pyx":43 + * 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', + * 'SPARSE_OK=TRUE', + * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), # <<<<<<<<<<<<<< + * 'BLOCKYSIZE=%d' % (1 << BLOCK_BITS)) + * + */ + __pyx_t_3 = __Pyx_PyInt_From_long((1 << __pyx_v_15pygeoprocessing_7routing_9watershed_BLOCK_BITS)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 43, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyUnicode_Format(__pyx_kp_u_BLOCKXSIZE_d, __pyx_t_3); 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; + + /* "pygeoprocessing/routing/watershed.pyx":44 + * 'SPARSE_OK=TRUE', + * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), + * 'BLOCKYSIZE=%d' % (1 << BLOCK_BITS)) # <<<<<<<<<<<<<< + * + * # this is used to calculate the opposite D8 direction interpreting the index + */ + __pyx_t_3 = __Pyx_PyInt_From_long((1 << __pyx_v_15pygeoprocessing_7routing_9watershed_BLOCK_BITS)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 44, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyUnicode_Format(__pyx_kp_u_BLOCKYSIZE_d, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 44, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":41 + * # these are the creation options that'll be used for all the rasters + * GTIFF_CREATION_OPTIONS = ( + * 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', # <<<<<<<<<<<<<< + * 'SPARSE_OK=TRUE', + * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), + */ + __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 41, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_kp_u_TILED_YES); + __Pyx_GIVEREF(__pyx_kp_u_TILED_YES); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_u_TILED_YES); + __Pyx_INCREF(__pyx_kp_u_BIGTIFF_YES); + __Pyx_GIVEREF(__pyx_kp_u_BIGTIFF_YES); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_kp_u_BIGTIFF_YES); + __Pyx_INCREF(__pyx_kp_u_COMPRESS_LZW); + __Pyx_GIVEREF(__pyx_kp_u_COMPRESS_LZW); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_kp_u_COMPRESS_LZW); + __Pyx_INCREF(__pyx_kp_u_SPARSE_OK_TRUE); + __Pyx_GIVEREF(__pyx_kp_u_SPARSE_OK_TRUE); + PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_kp_u_SPARSE_OK_TRUE); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_3, 5, __pyx_t_1); + __pyx_t_2 = 0; + __pyx_t_1 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_GTIFF_CREATION_OPTIONS, __pyx_t_3) < 0) __PYX_ERR(0, 40, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":48 + * # 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] # <<<<<<<<<<<<<< + * cdef int* NEIGHBOR_COL = [1, 1, 0, -1, -1, -1, 0, 1] + * cdef int* NEIGHBOR_ROW = [0, -1, -1, -1, 0, 1, 1, 1] + */ + __pyx_t_4[0] = 4; + __pyx_t_4[1] = 5; + __pyx_t_4[2] = 6; + __pyx_t_4[3] = 7; + __pyx_t_4[4] = 0; + __pyx_t_4[5] = 1; + __pyx_t_4[6] = 2; + __pyx_t_4[7] = 3; + __pyx_v_15pygeoprocessing_7routing_9watershed_D8_REVERSE_DIRECTION = __pyx_t_4; + + /* "pygeoprocessing/routing/watershed.pyx":49 + * # as a D8 direction + * cdef int* D8_REVERSE_DIRECTION = [4, 5, 6, 7, 0, 1, 2, 3] + * cdef int* NEIGHBOR_COL = [1, 1, 0, -1, -1, -1, 0, 1] # <<<<<<<<<<<<<< + * cdef int* NEIGHBOR_ROW = [0, -1, -1, -1, 0, 1, 1, 1] + * + */ + __pyx_t_5[0] = 1; + __pyx_t_5[1] = 1; + __pyx_t_5[2] = 0; + __pyx_t_5[3] = -1; + __pyx_t_5[4] = -1; + __pyx_t_5[5] = -1; + __pyx_t_5[6] = 0; + __pyx_t_5[7] = 1; + __pyx_v_15pygeoprocessing_7routing_9watershed_NEIGHBOR_COL = __pyx_t_5; + + /* "pygeoprocessing/routing/watershed.pyx":50 + * cdef int* D8_REVERSE_DIRECTION = [4, 5, 6, 7, 0, 1, 2, 3] + * cdef int* NEIGHBOR_COL = [1, 1, 0, -1, -1, -1, 0, 1] + * cdef int* NEIGHBOR_ROW = [0, -1, -1, -1, 0, 1, 1, 1] # <<<<<<<<<<<<<< + * + * # this is a least recently used cache written in C++ in an external file, + */ + __pyx_t_6[0] = 0; + __pyx_t_6[1] = -1; + __pyx_t_6[2] = -1; + __pyx_t_6[3] = -1; + __pyx_t_6[4] = 0; + __pyx_t_6[5] = 1; + __pyx_t_6[6] = 1; + __pyx_t_6[7] = 1; + __pyx_v_15pygeoprocessing_7routing_9watershed_NEIGHBOR_ROW = __pyx_t_6; + + /* "pygeoprocessing/routing/watershed.pyx":388 + * + * + * 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_3 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_9watershed_1_is_raster_path_band_formatted, NULL, __pyx_n_s_pygeoprocessing_routing_watershe); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 388, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_is_raster_path_band_formatted, __pyx_t_3) < 0) __PYX_ERR(0, 388, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":571 + * + * + * def _split_geometry_into_seeds( # <<<<<<<<<<<<<< + * source_geom_wkb, geotransform, flow_dir_srs, + * flow_dir_n_cols, flow_dir_n_rows, target_raster_path, + */ + __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_9watershed_3_split_geometry_into_seeds, NULL, __pyx_n_s_pygeoprocessing_routing_watershe); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 571, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_split_geometry_into_seeds, __pyx_t_3) < 0) __PYX_ERR(0, 571, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":624 + * + * @cython.boundscheck(False) + * def delineate_watersheds_d8( # <<<<<<<<<<<<<< + * d8_flow_dir_raster_path_band, outflow_vector_path, + * target_watersheds_vector_path, working_dir=None, + */ + __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_9watershed_5delineate_watersheds_d8, NULL, __pyx_n_s_pygeoprocessing_routing_watershe); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 624, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_delineate_watersheds_d8, __pyx_t_3) < 0) __PYX_ERR(0, 624, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pygeoprocessing/routing/watershed.pyx":1 + * # coding=UTF-8 # <<<<<<<<<<<<<< + * # cython: language_level=3 + * import logging + */ + __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_3) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pair.from_py":145 + * + * @cname("__pyx_convert_pair_from_py_long__and_long") + * cdef pair[X,Y] __pyx_convert_pair_from_py_long__and_long(object o) except *: # <<<<<<<<<<<<<< + * x, y = o + * return pair[X,Y](x, y) + */ + + /*--- 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.watershed", __pyx_clineno, __pyx_lineno, __pyx_filename); + } + Py_CLEAR(__pyx_m); + } else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_ImportError, "init pygeoprocessing.routing.watershed"); + } + __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(modname); + if (!m) goto end; + p = PyObject_GetAttrString(m, "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_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 + (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(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 + (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(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; +} + +/* PyDictVersioning */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0; +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { + PyObject **dictptr = NULL; + Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; + if (offset) { +#if CYTHON_COMPILING_IN_CPYTHON + dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); +#else + dictptr = _PyObject_GetDictPtr(obj); +#endif + } + return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; +} +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict))) + return 0; + return obj_dict_version == __Pyx_get_object_dict_version(obj); +} +#endif + +/* GetModuleGlobalName */ +#if CYTHON_USE_DICT_VERSIONS +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value) +#else +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name) +#endif +{ + 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); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } else if (unlikely(PyErr_Occurred())) { + return NULL; + } +#else + result = PyDict_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } +#endif +#else + result = PyObject_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } + PyErr_Clear(); +#endif + return __Pyx_GetBuiltinName(name); +} + +/* 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 | METH_STACKLESS))); + 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)(void*)meth)) (self, args, nargs, NULL); + } else { + return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs); + } +} +#endif + +/* PyFunctionFastCall */ +#if CYTHON_FAST_PYCALL +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 = __Pyx_PyFrame_GetLocalsplus(f); + 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, Py_ssize_t 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, (int)nargs, + k, (int)nk, + d, (int)nd, kwdefs, closure); +#else + result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL, + args, (int)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 + +/* PyObjectCall2Args */ +static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) { + PyObject *args, *result = NULL; + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(function)) { + PyObject *args[2] = {arg1, arg2}; + return __Pyx_PyFunction_FastCall(function, args, 2); + } + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(function)) { + PyObject *args[2] = {arg1, arg2}; + return __Pyx_PyCFunction_FastCall(function, args, 2); + } + #endif + args = PyTuple_New(2); + if (unlikely(!args)) goto done; + Py_INCREF(arg1); + PyTuple_SET_ITEM(args, 0, arg1); + Py_INCREF(arg2); + PyTuple_SET_ITEM(args, 1, arg2); + Py_INCREF(function); + result = __Pyx_PyObject_Call(function, args, NULL); + Py_DECREF(args); + Py_DECREF(function); +done: + return result; +} + +/* 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 (__Pyx_PyFastCFunction_Check(func)) { + 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 + +/* 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 + +/* 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()) { + if (unlikely(PyTuple_Check(key))) { + PyObject* args = PyTuple_Pack(1, key); + if (likely(args)) { + PyErr_SetObject(PyExc_KeyError, args); + Py_DECREF(args); + } + } else { + PyErr_SetObject(PyExc_KeyError, key); + } + } + 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; +} + +/* PyIntCompare */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_NeObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED long inplace) { + if (op1 == op2) { + Py_RETURN_FALSE; + } + #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))) { + int unequal; + unsigned long uintval; + Py_ssize_t size = Py_SIZE(op1); + const digit* digits = ((PyLongObject*)op1)->ob_digit; + if (intval == 0) { + if (size != 0) Py_RETURN_TRUE; else Py_RETURN_FALSE; + } else if (intval < 0) { + if (size >= 0) + Py_RETURN_TRUE; + intval = -intval; + size = -size; + } else { + if (size <= 0) + Py_RETURN_TRUE; + } + uintval = (unsigned long) intval; +#if PyLong_SHIFT * 4 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 4)) { + unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif +#if PyLong_SHIFT * 3 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 3)) { + unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif +#if PyLong_SHIFT * 2 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 2)) { + unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif +#if PyLong_SHIFT * 1 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 1)) { + unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif + unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK)); + if (unequal != 0) 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_NE)); +} + +/* PyIntBinop */ +#if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) { + (void)inplace; + (void)zerodivision_check; + #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 + +/* PyObjectFormatAndDecref */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f) { + if (unlikely(!s)) return NULL; + if (likely(PyUnicode_CheckExact(s))) return s; + #if PY_MAJOR_VERSION < 3 + if (likely(PyString_CheckExact(s))) { + PyObject *result = PyUnicode_FromEncodedObject(s, NULL, "strict"); + Py_DECREF(s); + return result; + } + #endif + return __Pyx_PyObject_FormatAndDecref(s, f); +} +static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f) { + PyObject *result = PyObject_Format(s, f); + Py_DECREF(s); + return result; +} + +/* JoinPyUnicode */ +static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength, + CYTHON_UNUSED Py_UCS4 max_char) { +#if CYTHON_USE_UNICODE_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + PyObject *result_uval; + int result_ukind; + Py_ssize_t i, char_pos; + void *result_udata; +#if CYTHON_PEP393_ENABLED + result_uval = PyUnicode_New(result_ulength, max_char); + if (unlikely(!result_uval)) return NULL; + result_ukind = (max_char <= 255) ? PyUnicode_1BYTE_KIND : (max_char <= 65535) ? PyUnicode_2BYTE_KIND : PyUnicode_4BYTE_KIND; + result_udata = PyUnicode_DATA(result_uval); +#else + result_uval = PyUnicode_FromUnicode(NULL, result_ulength); + if (unlikely(!result_uval)) return NULL; + result_ukind = sizeof(Py_UNICODE); + result_udata = PyUnicode_AS_UNICODE(result_uval); +#endif + char_pos = 0; + for (i=0; i < value_count; i++) { + int ukind; + Py_ssize_t ulength; + void *udata; + PyObject *uval = PyTuple_GET_ITEM(value_tuple, i); + if (unlikely(__Pyx_PyUnicode_READY(uval))) + goto bad; + ulength = __Pyx_PyUnicode_GET_LENGTH(uval); + if (unlikely(!ulength)) + continue; + if (unlikely(char_pos + ulength < 0)) + goto overflow; + ukind = __Pyx_PyUnicode_KIND(uval); + udata = __Pyx_PyUnicode_DATA(uval); + if (!CYTHON_PEP393_ENABLED || ukind == result_ukind) { + memcpy((char *)result_udata + char_pos * result_ukind, udata, (size_t) (ulength * result_ukind)); + } else { + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030300F0 || defined(_PyUnicode_FastCopyCharacters) + _PyUnicode_FastCopyCharacters(result_uval, char_pos, uval, 0, ulength); + #else + Py_ssize_t j; + for (j=0; j < ulength; j++) { + Py_UCS4 uchar = __Pyx_PyUnicode_READ(ukind, udata, j); + __Pyx_PyUnicode_WRITE(result_ukind, result_udata, char_pos+j, uchar); + } + #endif + } + char_pos += ulength; + } + return result_uval; +overflow: + PyErr_SetString(PyExc_OverflowError, "join() result is too long for a Python string"); +bad: + Py_DECREF(result_uval); + return NULL; +#else + result_ulength++; + value_count++; + return PyUnicode_Join(__pyx_empty_unicode, value_tuple); +#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_CyFunction_Check(func))) +#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 '?': return "'bool'"; + 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 '?': 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 '?': 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, 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; + ndim = ctx->head->field->type->ndim; + 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 '?': 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->is_valid_array)) { + 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((size_t)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(__Pyx_is_valid_index(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(__Pyx_is_valid_index(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(__Pyx_is_valid_index(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(__Pyx_is_valid_index(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!"); +} + +/* PyIntFromDouble */ + #if PY_MAJOR_VERSION < 3 +static CYTHON_INLINE PyObject* __Pyx_PyInt_FromDouble(double value) { + if (value >= (double)LONG_MIN && value <= (double)LONG_MAX) { + return PyInt_FromLong((long)value); + } + return PyLong_FromDouble(value); +} +#endif + +/* GetTopmostException */ + #if CYTHON_USE_EXC_INFO_STACK +static _PyErr_StackItem * +__Pyx_PyErr_GetTopmostException(PyThreadState *tstate) +{ + _PyErr_StackItem *exc_info = tstate->exc_info; + while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) && + exc_info->previous_item != NULL) + { + exc_info = exc_info->previous_item; + } + return exc_info; +} +#endif + +/* SaveResetException */ + #if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + #if CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate); + *type = exc_info->exc_type; + *value = exc_info->exc_value; + *tb = exc_info->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 CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = type; + exc_info->exc_value = value; + exc_info->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; icurexc_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 + +/* PyObjectGetMethod */ + static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) { + PyObject *attr; +#if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP + PyTypeObject *tp = Py_TYPE(obj); + PyObject *descr; + descrgetfunc f = NULL; + PyObject **dictptr, *dict; + int meth_found = 0; + assert (*method == NULL); + if (unlikely(tp->tp_getattro != PyObject_GenericGetAttr)) { + attr = __Pyx_PyObject_GetAttrStr(obj, name); + goto try_unpack; + } + if (unlikely(tp->tp_dict == NULL) && unlikely(PyType_Ready(tp) < 0)) { + return 0; + } + descr = _PyType_Lookup(tp, name); + if (likely(descr != NULL)) { + Py_INCREF(descr); +#if PY_MAJOR_VERSION >= 3 + #ifdef __Pyx_CyFunction_USED + if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type) || __Pyx_CyFunction_Check(descr))) + #else + if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type))) + #endif +#else + #ifdef __Pyx_CyFunction_USED + if (likely(PyFunction_Check(descr) || __Pyx_CyFunction_Check(descr))) + #else + if (likely(PyFunction_Check(descr))) + #endif +#endif + { + meth_found = 1; + } else { + f = Py_TYPE(descr)->tp_descr_get; + if (f != NULL && PyDescr_IsData(descr)) { + attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); + Py_DECREF(descr); + goto try_unpack; + } + } + } + dictptr = _PyObject_GetDictPtr(obj); + if (dictptr != NULL && (dict = *dictptr) != NULL) { + Py_INCREF(dict); + attr = __Pyx_PyDict_GetItemStr(dict, name); + if (attr != NULL) { + Py_INCREF(attr); + Py_DECREF(dict); + Py_XDECREF(descr); + goto try_unpack; + } + Py_DECREF(dict); + } + if (meth_found) { + *method = descr; + return 1; + } + if (f != NULL) { + attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); + Py_DECREF(descr); + goto try_unpack; + } + if (descr != NULL) { + *method = descr; + return 0; + } + PyErr_Format(PyExc_AttributeError, +#if PY_MAJOR_VERSION >= 3 + "'%.50s' object has no attribute '%U'", + tp->tp_name, name); +#else + "'%.50s' object has no attribute '%.400s'", + tp->tp_name, PyString_AS_STRING(name)); +#endif + return 0; +#else + attr = __Pyx_PyObject_GetAttrStr(obj, name); + goto try_unpack; +#endif +try_unpack: +#if CYTHON_UNPACK_METHODS + if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) { + PyObject *function = PyMethod_GET_FUNCTION(attr); + Py_INCREF(function); + Py_DECREF(attr); + *method = function; + return 1; + } +#endif + *method = attr; + return 0; +} + +/* PyObjectCallMethod0 */ + static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) { + PyObject *method = NULL, *result = NULL; + int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); + if (likely(is_method)) { + result = __Pyx_PyObject_CallOneArg(method, obj); + Py_DECREF(method); + return result; + } + if (unlikely(!method)) goto bad; + result = __Pyx_PyObject_CallNoArg(method); + Py_DECREF(method); +bad: + return result; +} + +/* RaiseNoneIterError */ + static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); +} + +/* UnpackTupleError */ + static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) { + if (t == Py_None) { + __Pyx_RaiseNoneNotIterableError(); + } else if (PyTuple_GET_SIZE(t) < index) { + __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(t)); + } else { + __Pyx_RaiseTooManyValuesError(index); + } +} + +/* UnpackTuple2 */ + static CYTHON_INLINE int __Pyx_unpack_tuple2_exact( + PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2, int decref_tuple) { + PyObject *value1 = NULL, *value2 = NULL; +#if CYTHON_COMPILING_IN_PYPY + value1 = PySequence_ITEM(tuple, 0); if (unlikely(!value1)) goto bad; + value2 = PySequence_ITEM(tuple, 1); if (unlikely(!value2)) goto bad; +#else + value1 = PyTuple_GET_ITEM(tuple, 0); Py_INCREF(value1); + value2 = PyTuple_GET_ITEM(tuple, 1); Py_INCREF(value2); +#endif + if (decref_tuple) { + Py_DECREF(tuple); + } + *pvalue1 = value1; + *pvalue2 = value2; + return 0; +#if CYTHON_COMPILING_IN_PYPY +bad: + Py_XDECREF(value1); + Py_XDECREF(value2); + if (decref_tuple) { Py_XDECREF(tuple); } + return -1; +#endif +} +static int __Pyx_unpack_tuple2_generic(PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2, + int has_known_size, int decref_tuple) { + Py_ssize_t index; + PyObject *value1 = NULL, *value2 = NULL, *iter = NULL; + iternextfunc iternext; + iter = PyObject_GetIter(tuple); + if (unlikely(!iter)) goto bad; + if (decref_tuple) { Py_DECREF(tuple); tuple = NULL; } + iternext = Py_TYPE(iter)->tp_iternext; + value1 = iternext(iter); if (unlikely(!value1)) { index = 0; goto unpacking_failed; } + value2 = iternext(iter); if (unlikely(!value2)) { index = 1; goto unpacking_failed; } + if (!has_known_size && unlikely(__Pyx_IternextUnpackEndCheck(iternext(iter), 2))) goto bad; + Py_DECREF(iter); + *pvalue1 = value1; + *pvalue2 = value2; + return 0; +unpacking_failed: + if (!has_known_size && __Pyx_IterFinish() == 0) + __Pyx_RaiseNeedMoreValuesError(index); +bad: + Py_XDECREF(iter); + Py_XDECREF(value1); + Py_XDECREF(value2); + if (decref_tuple) { Py_XDECREF(tuple); } + return -1; +} + +/* dict_iter */ + static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_dict, PyObject* method_name, + Py_ssize_t* p_orig_length, int* p_source_is_dict) { + is_dict = is_dict || likely(PyDict_CheckExact(iterable)); + *p_source_is_dict = is_dict; + if (is_dict) { +#if !CYTHON_COMPILING_IN_PYPY + *p_orig_length = PyDict_Size(iterable); + Py_INCREF(iterable); + return iterable; +#elif PY_MAJOR_VERSION >= 3 + static PyObject *py_items = NULL, *py_keys = NULL, *py_values = NULL; + PyObject **pp = NULL; + if (method_name) { + const char *name = PyUnicode_AsUTF8(method_name); + if (strcmp(name, "iteritems") == 0) pp = &py_items; + else if (strcmp(name, "iterkeys") == 0) pp = &py_keys; + else if (strcmp(name, "itervalues") == 0) pp = &py_values; + if (pp) { + if (!*pp) { + *pp = PyUnicode_FromString(name + 4); + if (!*pp) + return NULL; + } + method_name = *pp; + } + } +#endif + } + *p_orig_length = 0; + if (method_name) { + PyObject* iter; + iterable = __Pyx_PyObject_CallMethod0(iterable, method_name); + if (!iterable) + return NULL; +#if !CYTHON_COMPILING_IN_PYPY + if (PyTuple_CheckExact(iterable) || PyList_CheckExact(iterable)) + return iterable; +#endif + iter = PyObject_GetIter(iterable); + Py_DECREF(iterable); + return iter; + } + return PyObject_GetIter(iterable); +} +static CYTHON_INLINE int __Pyx_dict_iter_next( + PyObject* iter_obj, CYTHON_NCP_UNUSED Py_ssize_t orig_length, CYTHON_NCP_UNUSED Py_ssize_t* ppos, + PyObject** pkey, PyObject** pvalue, PyObject** pitem, int source_is_dict) { + PyObject* next_item; +#if !CYTHON_COMPILING_IN_PYPY + if (source_is_dict) { + PyObject *key, *value; + if (unlikely(orig_length != PyDict_Size(iter_obj))) { + PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration"); + return -1; + } + if (unlikely(!PyDict_Next(iter_obj, ppos, &key, &value))) { + return 0; + } + if (pitem) { + PyObject* tuple = PyTuple_New(2); + if (unlikely(!tuple)) { + return -1; + } + Py_INCREF(key); + Py_INCREF(value); + PyTuple_SET_ITEM(tuple, 0, key); + PyTuple_SET_ITEM(tuple, 1, value); + *pitem = tuple; + } else { + if (pkey) { + Py_INCREF(key); + *pkey = key; + } + if (pvalue) { + Py_INCREF(value); + *pvalue = value; + } + } + return 1; + } else if (PyTuple_CheckExact(iter_obj)) { + Py_ssize_t pos = *ppos; + if (unlikely(pos >= PyTuple_GET_SIZE(iter_obj))) return 0; + *ppos = pos + 1; + next_item = PyTuple_GET_ITEM(iter_obj, pos); + Py_INCREF(next_item); + } else if (PyList_CheckExact(iter_obj)) { + Py_ssize_t pos = *ppos; + if (unlikely(pos >= PyList_GET_SIZE(iter_obj))) return 0; + *ppos = pos + 1; + next_item = PyList_GET_ITEM(iter_obj, pos); + Py_INCREF(next_item); + } else +#endif + { + next_item = PyIter_Next(iter_obj); + if (unlikely(!next_item)) { + return __Pyx_IterFinish(); + } + } + if (pitem) { + *pitem = next_item; + } else if (pkey && pvalue) { + if (__Pyx_unpack_tuple2(next_item, pkey, pvalue, source_is_dict, source_is_dict, 1)) + return -1; + } else if (pkey) { + *pkey = next_item; + } else { + *pvalue = next_item; + } + return 1; +} + +/* BytesEquals */ + static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY + return PyObject_RichCompareBool(s1, s2, equals); +#else + if (s1 == s2) { + return (equals == Py_EQ); + } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) { + const char *ps1, *ps2; + Py_ssize_t length = PyBytes_GET_SIZE(s1); + if (length != PyBytes_GET_SIZE(s2)) + return (equals == Py_NE); + ps1 = PyBytes_AS_STRING(s1); + ps2 = PyBytes_AS_STRING(s2); + if (ps1[0] != ps2[0]) { + return (equals == Py_NE); + } else if (length == 1) { + return (equals == Py_EQ); + } else { + int result; +#if CYTHON_USE_UNICODE_INTERNALS + Py_hash_t hash1, hash2; + hash1 = ((PyBytesObject*)s1)->ob_shash; + hash2 = ((PyBytesObject*)s2)->ob_shash; + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + return (equals == Py_NE); + } +#endif + result = memcmp(ps1, ps2, (size_t)length); + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) { + return (equals == Py_NE); + } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) { + return (equals == Py_NE); + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +#endif +} + +/* UnicodeEquals */ + static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY + return PyObject_RichCompareBool(s1, s2, equals); +#else +#if PY_MAJOR_VERSION < 3 + PyObject* owned_ref = NULL; +#endif + int s1_is_unicode, s2_is_unicode; + if (s1 == s2) { + goto return_eq; + } + s1_is_unicode = PyUnicode_CheckExact(s1); + s2_is_unicode = PyUnicode_CheckExact(s2); +#if PY_MAJOR_VERSION < 3 + if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) { + owned_ref = PyUnicode_FromObject(s2); + if (unlikely(!owned_ref)) + return -1; + s2 = owned_ref; + s2_is_unicode = 1; + } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) { + owned_ref = PyUnicode_FromObject(s1); + if (unlikely(!owned_ref)) + return -1; + s1 = owned_ref; + s1_is_unicode = 1; + } else if (((!s2_is_unicode) & (!s1_is_unicode))) { + return __Pyx_PyBytes_Equals(s1, s2, equals); + } +#endif + if (s1_is_unicode & s2_is_unicode) { + Py_ssize_t length; + int kind; + void *data1, *data2; + if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0)) + return -1; + length = __Pyx_PyUnicode_GET_LENGTH(s1); + if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) { + goto return_ne; + } +#if CYTHON_USE_UNICODE_INTERNALS + { + Py_hash_t hash1, hash2; + #if CYTHON_PEP393_ENABLED + hash1 = ((PyASCIIObject*)s1)->hash; + hash2 = ((PyASCIIObject*)s2)->hash; + #else + hash1 = ((PyUnicodeObject*)s1)->hash; + hash2 = ((PyUnicodeObject*)s2)->hash; + #endif + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + goto return_ne; + } + } +#endif + kind = __Pyx_PyUnicode_KIND(s1); + if (kind != __Pyx_PyUnicode_KIND(s2)) { + goto return_ne; + } + data1 = __Pyx_PyUnicode_DATA(s1); + data2 = __Pyx_PyUnicode_DATA(s2); + if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) { + goto return_ne; + } else if (length == 1) { + goto return_eq; + } else { + int result = memcmp(data1, data2, (size_t)(length * kind)); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & s2_is_unicode) { + goto return_ne; + } else if ((s2 == Py_None) & s1_is_unicode) { + goto return_ne; + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +return_eq: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ); +return_ne: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_NE); +#endif +} + +/* 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 CYTHON_USE_EXC_INFO_STACK + { + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = local_type; + exc_info->exc_value = local_value; + exc_info->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; +} + +/* PyObjectGetAttrStrNoError */ + static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) + __Pyx_PyErr_Clear(); +} +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) { + PyObject *result; +#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1 + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) { + return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1); + } +#endif + result = __Pyx_PyObject_GetAttrStr(obj, attr_name); + if (unlikely(!result)) { + __Pyx_PyObject_GetAttrStr_ClearAttributeError(); + } + return result; +} + +/* 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 __PYX_GOOD; +#else + if (PyObject_HasAttr(type_obj, __pyx_n_s_getstate)) goto __PYX_GOOD; +#endif +#if CYTHON_USE_PYTYPE_LOOKUP + object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; +#else + object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; +#endif + reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto __PYX_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 __PYX_BAD; +#else + object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD; +#endif + reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto __PYX_BAD; + if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) { + reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_reduce_cython); + if (likely(reduce_cython)) { + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + } else if (reduce == object_reduce || PyErr_Occurred()) { + goto __PYX_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_GetAttrStrNoError(type_obj, __pyx_n_s_setstate_cython); + if (likely(setstate_cython)) { + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + } else if (!setstate || PyErr_Occurred()) { + goto __PYX_BAD; + } + } + PyType_Modified((PyTypeObject*)type_obj); + } + } + goto __PYX_GOOD; +__PYX_BAD: + if (!PyErr_Occurred()) + PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name); + ret = -1; +__PYX_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; +} + +/* TypeImport */ + #ifndef __PYX_HAVE_RT_ImportType +#define __PYX_HAVE_RT_ImportType +static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name, + size_t size, enum __Pyx_ImportType_CheckSize check_size) +{ + PyObject *result = 0; + char warning[200]; + Py_ssize_t basicsize; +#ifdef Py_LIMITED_API + PyObject *py_basicsize; +#endif + result = PyObject_GetAttrString(module, class_name); + 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 ((size_t)basicsize < size) { + PyErr_Format(PyExc_ValueError, + "%.200s.%.200s size changed, may indicate binary incompatibility. " + "Expected %zd from C header, got %zd from PyObject", + module_name, class_name, size, basicsize); + goto bad; + } + if (check_size == __Pyx_ImportType_CheckSize_Error && (size_t)basicsize != size) { + PyErr_Format(PyExc_ValueError, + "%.200s.%.200s size changed, may indicate binary incompatibility. " + "Expected %zd from C header, got %zd from PyObject", + module_name, class_name, size, basicsize); + goto bad; + } + else if (check_size == __Pyx_ImportType_CheckSize_Warn && (size_t)basicsize > size) { + PyOS_snprintf(warning, sizeof(warning), + "%s.%s size changed, may indicate binary incompatibility. " + "Expected %zd from C header, got %zd from PyObject", + module_name, class_name, size, basicsize); + if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad; + } + return (PyTypeObject *)result; +bad: + Py_XDECREF(result); + return NULL; +} +#endif + +/* 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 ((1) && (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, (PyObject *)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_NCP_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)) { + __PYX_PY_DICT_LOOKUP_IF_MODIFIED( + use_cline, *cython_runtime_dict, + __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 (use_cline == Py_False || (use_cline != Py_True && 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); + 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)) {} + view->obj = NULL; + Py_DECREF(obj); +} +#endif + + + /* 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;\ + } + +/* 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 = (float)(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 = (float)(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: + 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.0, -1.0); + } + } 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 = (double)(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 = (double)(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: + 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.0, -1.0); + } + } 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_long(long value) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const long neg_one = (long) -1, const_zero = (long) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + 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); + } +} + +/* CIntFromPy */ + static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const int neg_one = (int) -1, const_zero = (int) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + 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; +} + +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const int neg_one = (int) -1, const_zero = (int) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + 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); + } +} + +/* CIntFromPy */ + static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const long neg_one = (long) -1, const_zero = (long) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + 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; +} + +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_Py_intptr_t(Py_intptr_t value) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const Py_intptr_t neg_one = (Py_intptr_t) -1, const_zero = (Py_intptr_t) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(Py_intptr_t) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(Py_intptr_t) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(Py_intptr_t) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(Py_intptr_t) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(Py_intptr_t) <= 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(Py_intptr_t), + little, !is_unsigned); + } +} + +/* 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 int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { + Py_ssize_t i, n; + assert(PyExceptionClass_Check(exc_type)); + n = PyTuple_GET_SIZE(tuple); +#if PY_MAJOR_VERSION >= 3 + for (i=0; ip) { + #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 CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) { + int retval; + if (unlikely(!x)) return -1; + retval = __Pyx_PyObject_IsTrue(x); + Py_DECREF(x); + return retval; +} +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(b); + } +#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 */ diff --git a/src/pygeoprocessing/routing/watershed.pyx b/src/pygeoprocessing/routing/watershed.pyx index 88d27d8a..1dd1510f 100644 --- a/src/pygeoprocessing/routing/watershed.pyx +++ b/src/pygeoprocessing/routing/watershed.pyx @@ -1,23 +1,5 @@ # coding=UTF-8 # cython: language_level=3 -import pygeoprocessing -import shapely.wkb -import shapely.prepared -import shapely.geometry -import numpy -from osgeo import osr -from osgeo import ogr -from osgeo import gdal -from libcpp.set cimport set as cset -from libcpp.queue cimport queue -from libcpp.pair cimport pair -from libcpp.map cimport map as cmap -from libcpp.list cimport list as clist -from libc.time cimport time_t -from libc.time cimport time as ctime -from cython.operator cimport preincrement as inc -from cython.operator cimport dereference as deref -from cpython.mem cimport PyMem_Malloc, PyMem_Free import logging import os import shutil @@ -26,7 +8,25 @@ import time cimport cython cimport numpy +from cpython.mem cimport PyMem_Malloc, PyMem_Free +from cython.operator cimport dereference as deref +from cython.operator cimport preincrement as inc +from libc.time cimport time as ctime +from libc.time cimport time_t +from libcpp.list cimport list as clist +from libcpp.map cimport map as cmap +from libcpp.pair cimport pair +from libcpp.queue cimport queue +from libcpp.set cimport set as cset +from osgeo import gdal +from osgeo import ogr +from osgeo import osr +import numpy +import shapely.geometry +import shapely.prepared +import shapely.wkb +import pygeoprocessing LOGGER = logging.getLogger(__name__) @@ -45,18 +45,18 @@ GTIFF_CREATION_OPTIONS = ( # 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] -cdef int * NEIGHBOR_COL = [1, 1, 0, -1, -1, -1, 0, 1] -cdef int * NEIGHBOR_ROW = [0, -1, -1, -1, 0, 1, 1, 1] +cdef int* D8_REVERSE_DIRECTION = [4, 5, 6, 7, 0, 1, 2, 3] +cdef int* NEIGHBOR_COL = [1, 1, 0, -1, -1, -1, 0, 1] +cdef int* NEIGHBOR_ROW = [0, -1, -1, -1, 0, 1, 1, 1] # this is a least recently used cache written in C++ in an external file, # exposing here so _ManagedRaster can use it cdef extern from "LRUCache.h" nogil: cdef cppclass LRUCache[KEY_T, VAL_T]: LRUCache(int) - void put(KEY_T &, VAL_T&, clist[pair[KEY_T, VAL_T]]&) - clist[pair[KEY_T, VAL_T]].iterator begin() - clist[pair[KEY_T, VAL_T]].iterator end() + void put(KEY_T&, VAL_T&, clist[pair[KEY_T,VAL_T]]&) + clist[pair[KEY_T,VAL_T]].iterator begin() + clist[pair[KEY_T,VAL_T]].iterator end() bint exist(KEY_T &) VAL_T get(KEY_T &) @@ -67,7 +67,7 @@ ctypedef pair[int, int*] BlockBufferPair # a class to allow fast random per-pixel access to a raster for both setting # and reading pixels. cdef class _ManagedRaster: - cdef LRUCache[int, int*] * lru_cache + cdef LRUCache[int, int*]* lru_cache cdef cset[int] dirty_blocks cdef int block_xsize cdef int block_ysize @@ -160,7 +160,7 @@ cdef class _ManagedRaster: self.raster_y_size + (self.block_ysize) - 1) // self.block_ysize self.lru_cache = new LRUCache[int, int*](MANAGED_RASTER_N_BLOCKS) - self.raster_path = raster_path + self.raster_path = raster_path self.write_mode = write_mode self.closed = 0 @@ -185,9 +185,9 @@ cdef class _ManagedRaster: return self.closed = 1 cdef int xi_copy, yi_copy - cdef numpy.ndarray[int, ndim = 2] block_array = numpy.empty( + cdef numpy.ndarray[int, ndim=2] block_array = numpy.empty( (self.block_ysize, self.block_xsize), dtype=numpy.int32) - cdef int * int_buffer + cdef int *int_buffer cdef int block_xi cdef int block_yi # initially the win size is the same as the block size unless @@ -265,7 +265,7 @@ cdef class _ManagedRaster: self._load_block(block_index) self.lru_cache.get( block_index)[ - ((yi & (self.block_ymod)) << self.block_xbits) + + ((yi & (self.block_ymod))< block_index, < int*>int_buffer, removed_value_list) + block_index, int_buffer, removed_value_list) if self.write_mode: raster = gdal.OpenEx( @@ -443,10 +443,10 @@ cdef cset[CoordinatePair] _c_split_geometry_into_seeds( geometry = shapely.wkb.loads(source_geom_wkb) minx, miny, maxx, maxy = geometry.bounds - cdef int minx_pixelcoord = ((minx - x_origin) // x_pixelwidth) - cdef int miny_pixelcoord = ((miny - y_origin) // y_pixelwidth) - cdef int maxx_pixelcoord = ((maxx - x_origin) // x_pixelwidth) - cdef int maxy_pixelcoord = ((maxy - y_origin) // y_pixelwidth) + cdef int minx_pixelcoord = ((minx - x_origin) // x_pixelwidth) + cdef int miny_pixelcoord = ((miny - y_origin) // y_pixelwidth) + cdef int maxx_pixelcoord = ((maxx - x_origin) // x_pixelwidth) + cdef int maxy_pixelcoord = ((maxy - y_origin) // y_pixelwidth) # If the geometry only intersects a single pixel, we can treat it # as a single point, which means that we can track it directly in our @@ -475,17 +475,14 @@ cdef cset[CoordinatePair] _c_split_geometry_into_seeds( # It's possible for a perfectly vertical or horizontal line to cover 0 rows # or columns, so defaulting to row/col count of 1 in these cases. - local_n_cols = max(abs(maxx_aligned - minx_aligned) // - abs(x_pixelwidth), 1) - local_n_rows = max(abs(maxy_aligned - miny_aligned) // - abs(y_pixelwidth), 1) + local_n_cols = max(abs(maxx_aligned - minx_aligned) // abs(x_pixelwidth), 1) + local_n_rows = max(abs(maxy_aligned - miny_aligned) // abs(y_pixelwidth), 1) # The geometry does not fit into a single pixel, so let's create a new # raster onto which to rasterize it. memory_driver = gdal.GetDriverByName('Memory') new_vector = memory_driver.Create('mem', 0, 0, 0, gdal.GDT_Unknown) - new_layer = new_vector.CreateLayer( - 'user_geometry', flow_dir_srs, ogr.wkbUnknown) + new_layer = new_vector.CreateLayer('user_geometry', flow_dir_srs, ogr.wkbUnknown) new_layer.StartTransaction() new_feature = ogr.Feature(new_layer.GetLayerDefn()) new_feature.SetGeometry(ogr.CreateGeometryFromWkb(source_geom_wkb)) @@ -531,12 +528,12 @@ cdef cset[CoordinatePair] _c_split_geometry_into_seeds( cdef int row, col cdef int global_row, global_col - cdef int seed_raster_origin_col = ((local_origin_x - x_origin) // x_pixelwidth) - cdef int seed_raster_origin_row = ((local_origin_y - y_origin) // y_pixelwidth) + cdef int seed_raster_origin_col = ((local_origin_x - x_origin) // x_pixelwidth) + cdef int seed_raster_origin_row = ((local_origin_y - y_origin) // y_pixelwidth) cdef dict block_info cdef int block_xoff cdef int block_yoff - cdef numpy.ndarray[numpy.npy_uint8, ndim = 2] seed_array + cdef numpy.ndarray[numpy.npy_uint8, ndim=2] seed_array for block_info, seed_array in pygeoprocessing.iterblocks( (target_raster_path, 1)): block_xoff = block_info['xoff'] @@ -708,8 +705,7 @@ def delineate_watersheds_d8( outflow_vector = gdal.OpenEx(outflow_vector_path, gdal.OF_VECTOR) if outflow_vector is None: - raise ValueError(u'Could not open outflow vector %s' % - outflow_vector_path) + raise ValueError(u'Could not open outflow vector %s' % outflow_vector_path) driver = ogr.GetDriverByName('GPKG') watersheds_srs = osr.SpatialReference() @@ -729,9 +725,9 @@ def delineate_watersheds_d8( index_field.SetWidth(24) polygonized_watersheds_layer.CreateField(index_field) - cdef int * reverse_flow = [4, 5, 6, 7, 0, 1, 2, 3] - cdef int * neighbor_col = [1, 1, 0, -1, -1, -1, 0, 1] - cdef int * neighbor_row = [0, -1, -1, -1, 0, 1, 1, 1] + cdef int* reverse_flow = [4, 5, 6, 7, 0, 1, 2, 3] + cdef int* neighbor_col = [1, 1, 0, -1, -1, -1, 0, 1] + cdef int* neighbor_row = [0, -1, -1, -1, 0, 1, 1, 1] cdef queue[CoordinatePair] process_queue cdef cset[CoordinatePair] process_queue_set cdef CoordinatePair neighbor_pixel @@ -764,7 +760,6 @@ def delineate_watersheds_d8( 'Outflow feature %s has empty geometry. Skipping.', current_fid) continue - # with GDAL>=3.3.0 ExportToWkb returns a bytearray instead of bytes geom_wkb = bytes(geom.ExportToWkb()) shapely_geom = shapely.wkb.loads(geom_wkb) @@ -775,11 +770,9 @@ def delineate_watersheds_d8( 'direction raster. Skipping.', current_fid) continue - seeds_raster_path = os.path.join( - working_dir_path, '%s_rasterized.tif' % ws_id) + seeds_raster_path = os.path.join(working_dir_path, '%s_rasterized.tif' % ws_id) if write_diagnostic_vector: - diagnostic_vector_path = os.path.join( - working_dir_path, '%s_seeds.gpkg' % ws_id) + diagnostic_vector_path = os.path.join(working_dir_path, '%s_seeds.gpkg' % ws_id) else: diagnostic_vector_path = None seeds_in_watershed = _c_split_geometry_into_seeds( @@ -904,10 +897,8 @@ def delineate_watersheds_d8( # the whole scratch raster in order to polygonize. x1 = (flow_dir_origin_x + (max(ix_min-1, 0)*flow_dir_pixelsize_x)) # minx y1 = (flow_dir_origin_y + (max(iy_min-1, 0)*flow_dir_pixelsize_y)) # miny - x2 = (flow_dir_origin_x + (min(ix_max+1, flow_dir_n_cols) - * flow_dir_pixelsize_x)) # maxx - y2 = (flow_dir_origin_y + (min(iy_max+1, flow_dir_n_rows) - * flow_dir_pixelsize_y)) # maxy + x2 = (flow_dir_origin_x + (min(ix_max+1, flow_dir_n_cols)*flow_dir_pixelsize_x)) # maxx + y2 = (flow_dir_origin_y + (min(iy_max+1, flow_dir_n_rows)*flow_dir_pixelsize_y)) # maxy vrt_options = gdal.BuildVRTOptions( outputBounds=( @@ -920,8 +911,7 @@ def delineate_watersheds_d8( gdal.BuildVRT(vrt_path, [scratch_raster_path], options=vrt_options) # Polygonize this new watershed from the VRT. - vrt_raster = gdal.OpenEx( - vrt_path, gdal.OF_RASTER, allowed_drivers=['VRT']) + vrt_raster = gdal.OpenEx(vrt_path, gdal.OF_RASTER, allowed_drivers=['VRT']) vrt_band = vrt_raster.GetRasterBand(1) _ = gdal.Polygonize( vrt_band, # The source band @@ -983,8 +973,7 @@ def delineate_watersheds_d8( if duplicate_ids_set.size() == 1: duplicate_fid = deref(duplicate_ids_set_iterator) - source_feature = polygonized_watersheds_layer.GetFeature( - duplicate_fid) + source_feature = polygonized_watersheds_layer.GetFeature(duplicate_fid) new_geometry = source_feature.GetGeometryRef() else: new_geometry = ogr.Geometry(ogr.wkbMultiPolygon) @@ -992,8 +981,7 @@ def delineate_watersheds_d8( duplicate_fid = deref(duplicate_ids_set_iterator) inc(duplicate_ids_set_iterator) - duplicate_feature = polygonized_watersheds_layer.GetFeature( - duplicate_fid) + duplicate_feature = polygonized_watersheds_layer.GetFeature(duplicate_fid) duplicate_geometry = duplicate_feature.GetGeometryRef() new_geometry.AddGeometry(duplicate_geometry) From 93bbad3af790a5f93c21b8834b6f3141a414aea4 Mon Sep 17 00:00:00 2001 From: emlys Date: Tue, 8 Jun 2021 10:25:18 -0400 Subject: [PATCH 08/10] remove extra files --- src/pygeoprocessing/geoprocessing_core.cpp | 38436 ----------- src/pygeoprocessing/routing/routing.cpp | 65695 ------------------- src/pygeoprocessing/routing/watershed.cpp | 21754 ------ 3 files changed, 125885 deletions(-) delete mode 100644 src/pygeoprocessing/geoprocessing_core.cpp delete mode 100644 src/pygeoprocessing/routing/routing.cpp delete mode 100644 src/pygeoprocessing/routing/watershed.cpp diff --git a/src/pygeoprocessing/geoprocessing_core.cpp b/src/pygeoprocessing/geoprocessing_core.cpp deleted file mode 100644 index 5e5fc643..00000000 --- a/src/pygeoprocessing/geoprocessing_core.cpp +++ /dev/null @@ -1,38436 +0,0 @@ -/* Generated by Cython 0.29.23 */ - -#ifndef PY_SSIZE_T_CLEAN -#define PY_SSIZE_T_CLEAN -#endif /* 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_29_23" -#define CYTHON_HEX_VERSION 0x001D17F0 -#define CYTHON_FUTURE_DIVISION 1 -#include -#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 - #undef CYTHON_USE_DICT_VERSIONS - #define CYTHON_USE_DICT_VERSIONS 0 - #undef CYTHON_USE_EXC_INFO_STACK - #define CYTHON_USE_EXC_INFO_STACK 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 - #undef CYTHON_USE_DICT_VERSIONS - #define CYTHON_USE_DICT_VERSIONS 0 - #undef CYTHON_USE_EXC_INFO_STACK - #define CYTHON_USE_EXC_INFO_STACK 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 (PY_VERSION_HEX >= 0x03050000) - #endif - #ifndef CYTHON_USE_TP_FINALIZE - #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1) - #endif - #ifndef CYTHON_USE_DICT_VERSIONS - #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1) - #endif - #ifndef CYTHON_USE_EXC_INFO_STACK - #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3) - #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 - #ifdef SIZEOF_VOID_P - enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) }; - #endif -#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 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 -#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 -void __Pyx_call_destructor(T& x) { - x.~T(); -} -template -class __Pyx_FakeReference { - public: - __Pyx_FakeReference() : ptr(NULL) { } - __Pyx_FakeReference(const T& ref) : ptr(const_cast(&ref)) { } - T *operator->() { return ptr; } - T *operator&() { return ptr; } - operator T&() { return *ptr; } - template bool operator ==(U other) { return *ptr == other; } - template 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" -#if PY_VERSION_HEX >= 0x030800A4 && PY_VERSION_HEX < 0x030800B2 - #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ - PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) -#else - #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) -#endif - #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 -#ifndef METH_STACKLESS - #define METH_STACKLESS 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 | METH_STACKLESS))))) -#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_CPYTHON && PY_VERSION_HEX < 0x030400A1 - #define PyMem_RawMalloc(n) PyMem_Malloc(n) - #define PyMem_RawRealloc(p, n) PyMem_Realloc(p, n) - #define PyMem_RawFree(p) PyMem_Free(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; -} -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 -#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) - #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE) - #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) - #else - #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) - #endif -#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 || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) -#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? 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 -#ifndef PyObject_Unicode - #define PyObject_Unicode PyObject_Str -#endif -#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 PY_VERSION_HEX >= 0x030900A4 - #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt) - #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size) -#else - #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt) - #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size) -#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) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(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 -#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_MARK_ERR_POS(f_index, lineno) \ - { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; } -#define __PYX_ERR(f_index, lineno, Ln_error) \ - { __PYX_MARK_ERR_POS(f_index, lineno) 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__geoprocessing_core -#define __PYX_HAVE_API__pygeoprocessing__geoprocessing_core -/* Early includes */ -#include -#include -#include -#include "numpy/arrayobject.h" -#include "numpy/ndarrayobject.h" -#include "numpy/ndarraytypes.h" -#include "numpy/arrayscalars.h" -#include "numpy/ufuncobject.h" - - /* NumPy API declarations from "numpy/__init__.pxd" */ - -#include "ios" -#include "new" -#include "stdexcept" -#include "typeinfo" -#include -#include "FastFileIterator.h" -#include "pythread.h" -#include -#include "pystate.h" -#ifdef _OPENMP -#include -#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_UTF8 0 -#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8) -#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))) ) -static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) { - return (size_t) i < (size_t) limit; -} -#if defined (__cplusplus) && __cplusplus >= 201103L - #include - #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 int __Pyx_PyObject_IsTrueAndDecref(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) + 1); - 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 - #else - #include - #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/geoprocessing_core.pyx", - "__init__.pxd", - "stringsource", - "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; - -/* NoFastGil.proto */ -#define __Pyx_PyGILState_Ensure PyGILState_Ensure -#define __Pyx_PyGILState_Release PyGILState_Release -#define __Pyx_FastGIL_Remember() -#define __Pyx_FastGIL_Forget() -#define __Pyx_FastGilFuncInit() - -/* ForceInitThreads.proto */ -#ifndef __PYX_FORCE_INIT_THREADS - #define __PYX_FORCE_INIT_THREADS 0 -#endif - -/* MemviewSliceStruct.proto */ -struct __pyx_memoryview_obj; -typedef struct { - struct __pyx_memoryview_obj *memview; - char *data; - Py_ssize_t shape[8]; - Py_ssize_t strides[8]; - Py_ssize_t suboffsets[8]; -} __Pyx_memviewslice; -#define __Pyx_MemoryView_Len(m) (m.shape[0]) - -/* Atomics.proto */ -#include -#ifndef CYTHON_ATOMICS - #define CYTHON_ATOMICS 1 -#endif -#define __pyx_atomic_int_type int -#if CYTHON_ATOMICS && __GNUC__ >= 4 && (__GNUC_MINOR__ > 1 ||\ - (__GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL >= 2)) &&\ - !defined(__i386__) - #define __pyx_atomic_incr_aligned(value, lock) __sync_fetch_and_add(value, 1) - #define __pyx_atomic_decr_aligned(value, lock) __sync_fetch_and_sub(value, 1) - #ifdef __PYX_DEBUG_ATOMICS - #warning "Using GNU atomics" - #endif -#elif CYTHON_ATOMICS && defined(_MSC_VER) && 0 - #include - #undef __pyx_atomic_int_type - #define __pyx_atomic_int_type LONG - #define __pyx_atomic_incr_aligned(value, lock) InterlockedIncrement(value) - #define __pyx_atomic_decr_aligned(value, lock) InterlockedDecrement(value) - #ifdef __PYX_DEBUG_ATOMICS - #pragma message ("Using MSVC atomics") - #endif -#elif CYTHON_ATOMICS && (defined(__ICC) || defined(__INTEL_COMPILER)) && 0 - #define __pyx_atomic_incr_aligned(value, lock) _InterlockedIncrement(value) - #define __pyx_atomic_decr_aligned(value, lock) _InterlockedDecrement(value) - #ifdef __PYX_DEBUG_ATOMICS - #warning "Using Intel atomics" - #endif -#else - #undef CYTHON_ATOMICS - #define CYTHON_ATOMICS 0 - #ifdef __PYX_DEBUG_ATOMICS - #warning "Not using atomics" - #endif -#endif -typedef volatile __pyx_atomic_int_type __pyx_atomic_int; -#if CYTHON_ATOMICS - #define __pyx_add_acquisition_count(memview)\ - __pyx_atomic_incr_aligned(__pyx_get_slice_count_pointer(memview), memview->lock) - #define __pyx_sub_acquisition_count(memview)\ - __pyx_atomic_decr_aligned(__pyx_get_slice_count_pointer(memview), memview->lock) -#else - #define __pyx_add_acquisition_count(memview)\ - __pyx_add_acquisition_count_locked(__pyx_get_slice_count_pointer(memview), memview->lock) - #define __pyx_sub_acquisition_count(memview)\ - __pyx_sub_acquisition_count_locked(__pyx_get_slice_count_pointer(memview), memview->lock) -#endif - - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":690 - * # 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":691 - * - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":692 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":693 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":697 - * #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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":698 - * - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":699 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":700 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":704 - * #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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":705 - * - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":714 - * # 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":715 - * # 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":716 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":718 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":719 - * - * ctypedef npy_ulong uint_t - * ctypedef npy_ulonglong ulong_t # <<<<<<<<<<<<<< - * ctypedef npy_ulonglong ulonglong_t - * - */ -typedef npy_ulonglong __pyx_t_5numpy_ulong_t; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":720 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":722 - * ctypedef npy_ulonglong ulonglong_t - * - * ctypedef npy_intp intp_t # <<<<<<<<<<<<<< - * ctypedef npy_uintp uintp_t - * - */ -typedef npy_intp __pyx_t_5numpy_intp_t; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":723 - * - * ctypedef npy_intp intp_t - * ctypedef npy_uintp uintp_t # <<<<<<<<<<<<<< - * - * ctypedef npy_double float_t - */ -typedef npy_uintp __pyx_t_5numpy_uintp_t; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":725 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":726 - * - * ctypedef npy_double float_t - * ctypedef npy_double double_t # <<<<<<<<<<<<<< - * ctypedef npy_longdouble longdouble_t - * - */ -typedef npy_double __pyx_t_5numpy_double_t; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":727 - * 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; - -/* "pygeoprocessing/geoprocessing_core.pyx":621 - * - * - * ctypedef long long int64t # <<<<<<<<<<<<<< - * ctypedef FastFileIterator[long long]* FastFileIteratorLongLongIntPtr - * ctypedef FastFileIterator[double]* FastFileIteratorDoublePtr - */ -typedef PY_LONG_LONG __pyx_t_15pygeoprocessing_18geoprocessing_core_int64t; -/* 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_array_obj; -struct __pyx_MemviewEnum_obj; -struct __pyx_memoryview_obj; -struct __pyx_memoryviewslice_obj; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":729 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":730 - * - * ctypedef npy_cfloat cfloat_t - * ctypedef npy_cdouble cdouble_t # <<<<<<<<<<<<<< - * ctypedef npy_clongdouble clongdouble_t - * - */ -typedef npy_cdouble __pyx_t_5numpy_cdouble_t; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":731 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":733 - * ctypedef npy_clongdouble clongdouble_t - * - * ctypedef npy_cdouble complex_t # <<<<<<<<<<<<<< - * - * cdef inline object PyArray_MultiIterNew1(a): - */ -typedef npy_cdouble __pyx_t_5numpy_complex_t; - -/* "pygeoprocessing/geoprocessing_core.pyx":622 - * - * ctypedef long long int64t - * ctypedef FastFileIterator[long long]* FastFileIteratorLongLongIntPtr # <<<<<<<<<<<<<< - * ctypedef FastFileIterator[double]* FastFileIteratorDoublePtr - * - */ -typedef FastFileIterator *__pyx_t_15pygeoprocessing_18geoprocessing_core_FastFileIteratorLongLongIntPtr; - -/* "pygeoprocessing/geoprocessing_core.pyx":623 - * ctypedef long long int64t - * ctypedef FastFileIterator[long long]* FastFileIteratorLongLongIntPtr - * ctypedef FastFileIterator[double]* FastFileIteratorDoublePtr # <<<<<<<<<<<<<< - * - * - */ -typedef FastFileIterator *__pyx_t_15pygeoprocessing_18geoprocessing_core_FastFileIteratorDoublePtr; - -/* "View.MemoryView":105 - * - * @cname("__pyx_array") - * cdef class array: # <<<<<<<<<<<<<< - * - * cdef: - */ -struct __pyx_array_obj { - PyObject_HEAD - struct __pyx_vtabstruct_array *__pyx_vtab; - char *data; - Py_ssize_t len; - char *format; - int ndim; - Py_ssize_t *_shape; - Py_ssize_t *_strides; - Py_ssize_t itemsize; - PyObject *mode; - PyObject *_format; - void (*callback_free_data)(void *); - int free_data; - int dtype_is_object; -}; - - -/* "View.MemoryView":279 - * - * @cname('__pyx_MemviewEnum') - * cdef class Enum(object): # <<<<<<<<<<<<<< - * cdef object name - * def __init__(self, name): - */ -struct __pyx_MemviewEnum_obj { - PyObject_HEAD - PyObject *name; -}; - - -/* "View.MemoryView":330 - * - * @cname('__pyx_memoryview') - * cdef class memoryview(object): # <<<<<<<<<<<<<< - * - * cdef object obj - */ -struct __pyx_memoryview_obj { - PyObject_HEAD - struct __pyx_vtabstruct_memoryview *__pyx_vtab; - PyObject *obj; - PyObject *_size; - PyObject *_array_interface; - PyThread_type_lock lock; - __pyx_atomic_int acquisition_count[2]; - __pyx_atomic_int *acquisition_count_aligned_p; - Py_buffer view; - int flags; - int dtype_is_object; - __Pyx_TypeInfo *typeinfo; -}; - - -/* "View.MemoryView":965 - * - * @cname('__pyx_memoryviewslice') - * cdef class _memoryviewslice(memoryview): # <<<<<<<<<<<<<< - * "Internal class for passing memoryview slices to Python" - * - */ -struct __pyx_memoryviewslice_obj { - struct __pyx_memoryview_obj __pyx_base; - __Pyx_memviewslice from_slice; - PyObject *from_object; - PyObject *(*to_object_func)(char *); - int (*to_dtype_func)(char *, PyObject *); -}; - - - -/* "View.MemoryView":105 - * - * @cname("__pyx_array") - * cdef class array: # <<<<<<<<<<<<<< - * - * cdef: - */ - -struct __pyx_vtabstruct_array { - PyObject *(*get_memview)(struct __pyx_array_obj *); -}; -static struct __pyx_vtabstruct_array *__pyx_vtabptr_array; - - -/* "View.MemoryView":330 - * - * @cname('__pyx_memoryview') - * cdef class memoryview(object): # <<<<<<<<<<<<<< - * - * cdef object obj - */ - -struct __pyx_vtabstruct_memoryview { - char *(*get_item_pointer)(struct __pyx_memoryview_obj *, PyObject *); - PyObject *(*is_slice)(struct __pyx_memoryview_obj *, PyObject *); - PyObject *(*setitem_slice_assignment)(struct __pyx_memoryview_obj *, PyObject *, PyObject *); - PyObject *(*setitem_slice_assign_scalar)(struct __pyx_memoryview_obj *, struct __pyx_memoryview_obj *, PyObject *); - PyObject *(*setitem_indexed)(struct __pyx_memoryview_obj *, PyObject *, PyObject *); - PyObject *(*convert_item_to_object)(struct __pyx_memoryview_obj *, char *); - PyObject *(*assign_item_from_object)(struct __pyx_memoryview_obj *, char *, PyObject *); -}; -static struct __pyx_vtabstruct_memoryview *__pyx_vtabptr_memoryview; - - -/* "View.MemoryView":965 - * - * @cname('__pyx_memoryviewslice') - * cdef class _memoryviewslice(memoryview): # <<<<<<<<<<<<<< - * "Internal class for passing memoryview slices to Python" - * - */ - -struct __pyx_vtabstruct__memoryviewslice { - struct __pyx_vtabstruct_memoryview __pyx_base; -}; -static struct __pyx_vtabstruct__memoryviewslice *__pyx_vtabptr__memoryviewslice; - -/* --- 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); - -/* PyDictVersioning.proto */ -#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS -#define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1) -#define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag) -#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\ - (version_var) = __PYX_GET_DICT_VERSION(dict);\ - (cache_var) = (value); -#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\ - static PY_UINT64_T __pyx_dict_version = 0;\ - static PyObject *__pyx_dict_cached_value = NULL;\ - if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\ - (VAR) = __pyx_dict_cached_value;\ - } else {\ - (VAR) = __pyx_dict_cached_value = (LOOKUP);\ - __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\ - }\ -} -static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj); -static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj); -static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version); -#else -#define __PYX_GET_DICT_VERSION(dict) (0) -#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) -#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP); -#endif - -/* GetModuleGlobalName.proto */ -#if CYTHON_USE_DICT_VERSIONS -#define __Pyx_GetModuleGlobalName(var, name) {\ - static PY_UINT64_T __pyx_dict_version = 0;\ - static PyObject *__pyx_dict_cached_value = NULL;\ - (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\ - (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\ - __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ -} -#define __Pyx_GetModuleGlobalNameUncached(var, name) {\ - PY_UINT64_T __pyx_dict_version;\ - PyObject *__pyx_dict_cached_value;\ - (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ -} -static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); -#else -#define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name) -#define __Pyx_GetModuleGlobalNameUncached(var, name) (var) = __Pyx__GetModuleGlobalName(name) -static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name); -#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, Py_ssize_t nargs, PyObject *kwargs); -#else -#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs) -#endif -#define __Pyx_BUILD_ASSERT_EXPR(cond)\ - (sizeof(char [1 - 2*!(cond)]) - 1) -#ifndef Py_MEMBER_SIZE -#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member) -#endif - static size_t __pyx_pyframe_localsplus_offset = 0; - #include "frameobject.h" - #define __Pxy_PyFrame_Initialize_Offsets()\ - ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\ - (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus))) - #define __Pyx_PyFrame_GetLocalsplus(frame)\ - (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset)) -#endif - -/* 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 - -/* 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 - -/* PyObjectCall2Args.proto */ -static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2); - -/* 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); - -/* 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 - -/* 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 - -/* 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); - -/* 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 }; - -/* BufferFallbackError.proto */ -static void __Pyx_RaiseBufferFallbackError(void); - -/* PyIntCompare.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, long intval, long inplace); - -/* 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 - -#define __Pyx_BufPtrStrided2d(type, buf, i0, s0, i1, s1) (type)((char*)buf + i0 * s0 + i1 * s1) -#define __Pyx_BufPtrStrided1d(type, buf, i0, s0) (type)((char*)buf + i0 * s0) -/* 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 - -/* 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); - -/* PyIntBinop.proto */ -#if !CYTHON_COMPILING_IN_PYPY -static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check); -#else -#define __Pyx_PyInt_SubtractObjC(op1, op2, intval, inplace, zerodivision_check)\ - (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, int zerodivision_check); -#else -#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace, zerodivision_check)\ - (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2)) -#endif - -/* PyObjectGetMethod.proto */ -static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method); - -/* PyObjectCallMethod0.proto */ -static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name); - -/* RaiseNoneIterError.proto */ -static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void); - -/* UnpackTupleError.proto */ -static void __Pyx_UnpackTupleError(PyObject *, Py_ssize_t index); - -/* UnpackTuple2.proto */ -#define __Pyx_unpack_tuple2(tuple, value1, value2, is_tuple, has_known_size, decref_tuple)\ - (likely(is_tuple || PyTuple_Check(tuple)) ?\ - (likely(has_known_size || PyTuple_GET_SIZE(tuple) == 2) ?\ - __Pyx_unpack_tuple2_exact(tuple, value1, value2, decref_tuple) :\ - (__Pyx_UnpackTupleError(tuple, 2), -1)) :\ - __Pyx_unpack_tuple2_generic(tuple, value1, value2, has_known_size, decref_tuple)) -static CYTHON_INLINE int __Pyx_unpack_tuple2_exact( - PyObject* tuple, PyObject** value1, PyObject** value2, int decref_tuple); -static int __Pyx_unpack_tuple2_generic( - PyObject* tuple, PyObject** value1, PyObject** value2, int has_known_size, int decref_tuple); - -/* dict_iter.proto */ -static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* dict, int is_dict, PyObject* method_name, - Py_ssize_t* p_orig_length, int* p_is_dict); -static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* dict_or_iter, Py_ssize_t orig_length, Py_ssize_t* ppos, - PyObject** pkey, PyObject** pvalue, PyObject** pitem, int is_dict); - -/* MergeKeywords.proto */ -static int __Pyx_MergeKeywords(PyObject *kwdict, PyObject *source_mapping); - -/* PyObjectFormatSimple.proto */ -#if CYTHON_COMPILING_IN_PYPY - #define __Pyx_PyObject_FormatSimple(s, f) (\ - likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ - PyObject_Format(s, f)) -#elif PY_MAJOR_VERSION < 3 - #define __Pyx_PyObject_FormatSimple(s, f) (\ - likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ - likely(PyString_CheckExact(s)) ? PyUnicode_FromEncodedObject(s, NULL, "strict") :\ - PyObject_Format(s, f)) -#elif CYTHON_USE_TYPE_SLOTS - #define __Pyx_PyObject_FormatSimple(s, f) (\ - likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ - likely(PyLong_CheckExact(s)) ? PyLong_Type.tp_str(s) :\ - likely(PyFloat_CheckExact(s)) ? PyFloat_Type.tp_str(s) :\ - PyObject_Format(s, f)) -#else - #define __Pyx_PyObject_FormatSimple(s, f) (\ - likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ - PyObject_Format(s, f)) -#endif - -/* GetTopmostException.proto */ -#if CYTHON_USE_EXC_INFO_STACK -static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate); -#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 - -/* 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 - -/* SwapException.proto */ -#if CYTHON_FAST_THREAD_STATE -#define __Pyx_ExceptionSwap(type, value, tb) __Pyx__ExceptionSwap(__pyx_tstate, type, value, tb) -static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); -#else -static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb); -#endif - -/* RaiseException.proto */ -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); - -/* PyObjectFormat.proto */ -#if CYTHON_USE_UNICODE_WRITER -static PyObject* __Pyx_PyObject_Format(PyObject* s, PyObject* f); -#else -#define __Pyx_PyObject_Format(s, f) PyObject_Format(s, f) -#endif - -/* GCCDiagnostics.proto */ -#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) -#define __Pyx_HAS_GCC_DIAGNOSTIC -#endif - -/* BuildPyUnicode.proto */ -static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, char* chars, int clength, - int prepend_sign, char padding_char); - -/* CIntToPyUnicode.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_PY_LONG_LONG(PY_LONG_LONG value, Py_ssize_t width, char padding_char, char format_char); - -/* IncludeStringH.proto */ -#include - -/* JoinPyUnicode.proto */ -static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength, - Py_UCS4 max_char); - -/* MemviewSliceInit.proto */ -#define __Pyx_BUF_MAX_NDIMS %(BUF_MAX_NDIMS)d -#define __Pyx_MEMVIEW_DIRECT 1 -#define __Pyx_MEMVIEW_PTR 2 -#define __Pyx_MEMVIEW_FULL 4 -#define __Pyx_MEMVIEW_CONTIG 8 -#define __Pyx_MEMVIEW_STRIDED 16 -#define __Pyx_MEMVIEW_FOLLOW 32 -#define __Pyx_IS_C_CONTIG 1 -#define __Pyx_IS_F_CONTIG 2 -static int __Pyx_init_memviewslice( - struct __pyx_memoryview_obj *memview, - int ndim, - __Pyx_memviewslice *memviewslice, - int memview_is_new_reference); -static CYTHON_INLINE int __pyx_add_acquisition_count_locked( - __pyx_atomic_int *acquisition_count, PyThread_type_lock lock); -static CYTHON_INLINE int __pyx_sub_acquisition_count_locked( - __pyx_atomic_int *acquisition_count, PyThread_type_lock lock); -#define __pyx_get_slice_count_pointer(memview) (memview->acquisition_count_aligned_p) -#define __pyx_get_slice_count(memview) (*__pyx_get_slice_count_pointer(memview)) -#define __PYX_INC_MEMVIEW(slice, have_gil) __Pyx_INC_MEMVIEW(slice, have_gil, __LINE__) -#define __PYX_XDEC_MEMVIEW(slice, have_gil) __Pyx_XDEC_MEMVIEW(slice, have_gil, __LINE__) -static CYTHON_INLINE void __Pyx_INC_MEMVIEW(__Pyx_memviewslice *, int, int); -static CYTHON_INLINE void __Pyx_XDEC_MEMVIEW(__Pyx_memviewslice *, int, int); - -/* ListAppend.proto */ -#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS -static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) { - PyListObject* L = (PyListObject*) list; - Py_ssize_t len = Py_SIZE(list); - if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) { - Py_INCREF(x); - PyList_SET_ITEM(list, len, x); - __Pyx_SET_SIZE(list, len + 1); - return 0; - } - return PyList_Append(list, x); -} -#else -#define __Pyx_PyList_Append(L,x) PyList_Append(L,x) -#endif - -/* BufferIndexError.proto */ -static void __Pyx_RaiseBufferIndexError(int axis); - -/* ArgTypeTest.proto */ -#define __Pyx_ArgTypeTest(obj, type, none_allowed, name, exact)\ - ((likely((Py_TYPE(obj) == type) | (none_allowed && (obj == Py_None)))) ? 1 :\ - __Pyx__ArgTypeTest(obj, type, name, exact)) -static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact); - -/* BytesEquals.proto */ -static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); - -/* UnicodeEquals.proto */ -static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); - -/* StrEquals.proto */ -#if PY_MAJOR_VERSION >= 3 -#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals -#else -#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals -#endif - -/* None.proto */ -static CYTHON_INLINE Py_ssize_t __Pyx_div_Py_ssize_t(Py_ssize_t, Py_ssize_t); - -/* UnaryNegOverflows.proto */ -#define UNARY_NEG_WOULD_OVERFLOW(x)\ - (((x) < 0) & ((unsigned long)(x) == 0-(unsigned long)(x))) - -static CYTHON_UNUSED int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ -static PyObject *__pyx_array_get_memview(struct __pyx_array_obj *); /*proto*/ -/* GetAttr.proto */ -static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *); - -/* decode_c_string_utf16.proto */ -static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16(const char *s, Py_ssize_t size, const char *errors) { - int byteorder = 0; - return PyUnicode_DecodeUTF16(s, size, errors, &byteorder); -} -static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16LE(const char *s, Py_ssize_t size, const char *errors) { - int byteorder = -1; - return PyUnicode_DecodeUTF16(s, size, errors, &byteorder); -} -static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16BE(const char *s, Py_ssize_t size, const char *errors) { - int byteorder = 1; - return PyUnicode_DecodeUTF16(s, size, errors, &byteorder); -} - -/* decode_c_string.proto */ -static CYTHON_INLINE PyObject* __Pyx_decode_c_string( - const char* cstring, Py_ssize_t start, Py_ssize_t stop, - const char* encoding, const char* errors, - PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)); - -/* GetAttr3.proto */ -static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *); - -/* Import.proto */ -static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); - -/* 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) - -static CYTHON_UNUSED int __pyx_memoryview_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ -/* ListCompAppend.proto */ -#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS -static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) { - PyListObject* L = (PyListObject*) list; - Py_ssize_t len = Py_SIZE(list); - if (likely(L->allocated > len)) { - Py_INCREF(x); - PyList_SET_ITEM(list, len, x); - __Pyx_SET_SIZE(list, len + 1); - return 0; - } - return PyList_Append(list, x); -} -#else -#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x) -#endif - -/* ListExtend.proto */ -static CYTHON_INLINE int __Pyx_PyList_Extend(PyObject* L, PyObject* v) { -#if CYTHON_COMPILING_IN_CPYTHON - PyObject* none = _PyList_Extend((PyListObject*)L, v); - if (unlikely(!none)) - return -1; - Py_DECREF(none); - return 0; -#else - return PyList_SetSlice(L, PY_SSIZE_T_MAX, PY_SSIZE_T_MAX, v); -#endif -} - -/* None.proto */ -static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname); - -/* None.proto */ -static CYTHON_INLINE long __Pyx_div_long(long, long); - -/* ImportFrom.proto */ -static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name); - -/* HasAttr.proto */ -static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *); - -/* 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); - -/* PyObjectGetAttrStrNoError.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name); - -/* SetupReduce.proto */ -static int __Pyx_setup_reduce(PyObject* type_obj); - -/* TypeImport.proto */ -#ifndef __PYX_HAVE_RT_ImportType_proto -#define __PYX_HAVE_RT_ImportType_proto -enum __Pyx_ImportType_CheckSize { - __Pyx_ImportType_CheckSize_Error = 0, - __Pyx_ImportType_CheckSize_Warn = 1, - __Pyx_ImportType_CheckSize_Ignore = 2 -}; -static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size); -#endif - -/* 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); - -#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 - - -/* 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; - -/* MemviewSliceIsContig.proto */ -static int __pyx_memviewslice_is_contig(const __Pyx_memviewslice mvs, char order, int ndim); - -/* OverlappingSlices.proto */ -static int __pyx_slices_overlap(__Pyx_memviewslice *slice1, - __Pyx_memviewslice *slice2, - int ndim, size_t itemsize); - -/* Capsule.proto */ -static CYTHON_INLINE PyObject *__pyx_capsule_create(void *p, const char *sig); - -/* MemviewDtypeToObject.proto */ -static CYTHON_INLINE PyObject *__pyx_memview_get_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t(const char *itemp); -static CYTHON_INLINE int __pyx_memview_set_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t(const char *itemp, PyObject *obj); - -/* CppExceptionConversion.proto */ -#ifndef __Pyx_CppExn2PyErr -#include -#include -#include -#include -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 - -/* MemviewDtypeToObject.proto */ -static CYTHON_INLINE PyObject *__pyx_memview_get_double(const char *itemp); -static CYTHON_INLINE int __pyx_memview_set_double(const char *itemp, PyObject *obj); - -/* 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 - -/* MemviewSliceCopyTemplate.proto */ -static __Pyx_memviewslice -__pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, - const char *mode, int ndim, - size_t sizeof_dtype, int contig_flag, - int dtype_is_object); - -/* CIntFromPy.proto */ -static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); - -/* CIntToPy.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); - -/* CIntToPy.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); - -/* CIntToPy.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyInt_From_PY_LONG_LONG(PY_LONG_LONG value); - -/* CIntFromPy.proto */ -static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_As_PY_LONG_LONG(PyObject *); - -/* CIntFromPy.proto */ -static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *); - -/* CIntFromPy.proto */ -static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); - -/* CIntFromPy.proto */ -static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *); - -/* TypeInfoCompare.proto */ -static int __pyx_typeinfo_cmp(__Pyx_TypeInfo *a, __Pyx_TypeInfo *b); - -/* MemviewSliceValidateAndInit.proto */ -static int __Pyx_ValidateAndInit_memviewslice( - int *axes_specs, - int c_or_f_flag, - int buf_flags, - int ndim, - __Pyx_TypeInfo *dtype, - __Pyx_BufFmt_StackElem stack[], - __Pyx_memviewslice *memviewslice, - PyObject *original_obj); - -/* ObjectToMemviewSlice.proto */ -static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t(PyObject *, int writable_flag); - -/* ObjectToMemviewSlice.proto */ -static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_double(PyObject *, int writable_flag); - -/* CheckBinaryVersion.proto */ -static int __Pyx_check_binary_version(void); - -/* InitStrings.proto */ -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); - -static PyObject *__pyx_array_get_memview(struct __pyx_array_obj *__pyx_v_self); /* proto*/ -static char *__pyx_memoryview_get_item_pointer(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index); /* proto*/ -static PyObject *__pyx_memoryview_is_slice(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj); /* proto*/ -static PyObject *__pyx_memoryview_setitem_slice_assignment(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_dst, PyObject *__pyx_v_src); /* proto*/ -static PyObject *__pyx_memoryview_setitem_slice_assign_scalar(struct __pyx_memoryview_obj *__pyx_v_self, struct __pyx_memoryview_obj *__pyx_v_dst, PyObject *__pyx_v_value); /* proto*/ -static PyObject *__pyx_memoryview_setitem_indexed(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value); /* proto*/ -static PyObject *__pyx_memoryview_convert_item_to_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp); /* proto*/ -static PyObject *__pyx_memoryview_assign_item_from_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp, PyObject *__pyx_v_value); /* proto*/ -static PyObject *__pyx_memoryviewslice_convert_item_to_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp); /* proto*/ -static PyObject *__pyx_memoryviewslice_assign_item_from_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp, PyObject *__pyx_v_value); /* proto*/ - -/* Module declarations from 'cython.view' */ - -/* Module declarations from 'cython' */ - -/* Module declarations from 'libcpp' */ - -/* Module declarations from 'libcpp.algorithm' */ - -/* 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_generic = 0; -static PyTypeObject *__pyx_ptype_5numpy_number = 0; -static PyTypeObject *__pyx_ptype_5numpy_integer = 0; -static PyTypeObject *__pyx_ptype_5numpy_signedinteger = 0; -static PyTypeObject *__pyx_ptype_5numpy_unsignedinteger = 0; -static PyTypeObject *__pyx_ptype_5numpy_inexact = 0; -static PyTypeObject *__pyx_ptype_5numpy_floating = 0; -static PyTypeObject *__pyx_ptype_5numpy_complexfloating = 0; -static PyTypeObject *__pyx_ptype_5numpy_flexible = 0; -static PyTypeObject *__pyx_ptype_5numpy_character = 0; -static PyTypeObject *__pyx_ptype_5numpy_ufunc = 0; - -/* Module declarations from 'libcpp.vector' */ - -/* Module declarations from 'pygeoprocessing.geoprocessing_core' */ -static PyTypeObject *__pyx_array_type = 0; -static PyTypeObject *__pyx_MemviewEnum_type = 0; -static PyTypeObject *__pyx_memoryview_type = 0; -static PyTypeObject *__pyx_memoryviewslice_type = 0; -static float __pyx_v_15pygeoprocessing_18geoprocessing_core__NODATA; -static PyObject *generic = 0; -static PyObject *strided = 0; -static PyObject *indirect = 0; -static PyObject *contiguous = 0; -static PyObject *indirect_contiguous = 0; -static int __pyx_memoryview_thread_locks_used; -static PyThread_type_lock __pyx_memoryview_thread_locks[8]; -static struct __pyx_array_obj *__pyx_array_new(PyObject *, Py_ssize_t, char *, char *, char *); /*proto*/ -static void *__pyx_align_pointer(void *, size_t); /*proto*/ -static PyObject *__pyx_memoryview_new(PyObject *, int, int, __Pyx_TypeInfo *); /*proto*/ -static CYTHON_INLINE int __pyx_memoryview_check(PyObject *); /*proto*/ -static PyObject *_unellipsify(PyObject *, int); /*proto*/ -static PyObject *assert_direct_dimensions(Py_ssize_t *, int); /*proto*/ -static struct __pyx_memoryview_obj *__pyx_memview_slice(struct __pyx_memoryview_obj *, PyObject *); /*proto*/ -static int __pyx_memoryview_slice_memviewslice(__Pyx_memviewslice *, Py_ssize_t, Py_ssize_t, Py_ssize_t, int, int, int *, Py_ssize_t, Py_ssize_t, Py_ssize_t, int, int, int, int); /*proto*/ -static char *__pyx_pybuffer_index(Py_buffer *, char *, Py_ssize_t, Py_ssize_t); /*proto*/ -static int __pyx_memslice_transpose(__Pyx_memviewslice *); /*proto*/ -static PyObject *__pyx_memoryview_fromslice(__Pyx_memviewslice, int, PyObject *(*)(char *), int (*)(char *, PyObject *), int); /*proto*/ -static __Pyx_memviewslice *__pyx_memoryview_get_slice_from_memoryview(struct __pyx_memoryview_obj *, __Pyx_memviewslice *); /*proto*/ -static void __pyx_memoryview_slice_copy(struct __pyx_memoryview_obj *, __Pyx_memviewslice *); /*proto*/ -static PyObject *__pyx_memoryview_copy_object(struct __pyx_memoryview_obj *); /*proto*/ -static PyObject *__pyx_memoryview_copy_object_from_slice(struct __pyx_memoryview_obj *, __Pyx_memviewslice *); /*proto*/ -static Py_ssize_t abs_py_ssize_t(Py_ssize_t); /*proto*/ -static char __pyx_get_best_slice_order(__Pyx_memviewslice *, int); /*proto*/ -static void _copy_strided_to_strided(char *, Py_ssize_t *, char *, Py_ssize_t *, Py_ssize_t *, Py_ssize_t *, int, size_t); /*proto*/ -static void copy_strided_to_strided(__Pyx_memviewslice *, __Pyx_memviewslice *, int, size_t); /*proto*/ -static Py_ssize_t __pyx_memoryview_slice_get_size(__Pyx_memviewslice *, int); /*proto*/ -static Py_ssize_t __pyx_fill_contig_strides_array(Py_ssize_t *, Py_ssize_t *, Py_ssize_t, int, char); /*proto*/ -static void *__pyx_memoryview_copy_data_to_temp(__Pyx_memviewslice *, __Pyx_memviewslice *, char, int); /*proto*/ -static int __pyx_memoryview_err_extents(int, Py_ssize_t, Py_ssize_t); /*proto*/ -static int __pyx_memoryview_err_dim(PyObject *, char *, int); /*proto*/ -static int __pyx_memoryview_err(PyObject *, char *); /*proto*/ -static int __pyx_memoryview_copy_contents(__Pyx_memviewslice, __Pyx_memviewslice, int, int, int); /*proto*/ -static void __pyx_memoryview_broadcast_leading(__Pyx_memviewslice *, int, int); /*proto*/ -static void __pyx_memoryview_refcount_copying(__Pyx_memviewslice *, int, int, int); /*proto*/ -static void __pyx_memoryview_refcount_objects_in_slice_with_gil(char *, Py_ssize_t *, Py_ssize_t *, int, int); /*proto*/ -static void __pyx_memoryview_refcount_objects_in_slice(char *, Py_ssize_t *, Py_ssize_t *, int, int); /*proto*/ -static void __pyx_memoryview_slice_assign_scalar(__Pyx_memviewslice *, int, size_t, void *, int); /*proto*/ -static void __pyx_memoryview__slice_assign_scalar(char *, Py_ssize_t *, Py_ssize_t *, int, size_t, void *); /*proto*/ -static PyObject *__pyx_unpickle_Enum__set_state(struct __pyx_MemviewEnum_obj *, PyObject *); /*proto*/ -static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_int8_t = { "int8_t", NULL, sizeof(__pyx_t_5numpy_int8_t), { 0 }, 0, IS_UNSIGNED(__pyx_t_5numpy_int8_t) ? 'U' : 'I', IS_UNSIGNED(__pyx_t_5numpy_int8_t), 0 }; -static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t = { "float32_t", NULL, sizeof(__pyx_t_5numpy_float32_t), { 0 }, 0, 'R', 0, 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 }; -static __Pyx_TypeInfo __Pyx_TypeInfo_nn_npy_float64 = { "npy_float64", NULL, sizeof(npy_float64), { 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_15pygeoprocessing_18geoprocessing_core_int64t = { "int64t", NULL, sizeof(__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t), { 0 }, 0, IS_UNSIGNED(__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t) ? 'U' : 'I', IS_UNSIGNED(__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t), 0 }; -static __Pyx_TypeInfo __Pyx_TypeInfo_double = { "double", NULL, sizeof(double), { 0 }, 0, 'R', 0, 0 }; -#define __Pyx_MODULE_NAME "pygeoprocessing.geoprocessing_core" -extern int __pyx_module_is_main_pygeoprocessing__geoprocessing_core; -int __pyx_module_is_main_pygeoprocessing__geoprocessing_core = 0; - -/* Implementation of 'pygeoprocessing.geoprocessing_core' */ -static PyObject *__pyx_builtin_range; -static PyObject *__pyx_builtin_ValueError; -static PyObject *__pyx_builtin_OSError; -static PyObject *__pyx_builtin_ImportError; -static PyObject *__pyx_builtin_MemoryError; -static PyObject *__pyx_builtin_enumerate; -static PyObject *__pyx_builtin_TypeError; -static PyObject *__pyx_builtin_Ellipsis; -static PyObject *__pyx_builtin_id; -static PyObject *__pyx_builtin_IndexError; -static const char __pyx_k_O[] = "O"; -static const char __pyx_k_a[] = "a"; -static const char __pyx_k_b[] = "b"; -static const char __pyx_k_c[] = "c"; -static const char __pyx_k_d[] = "d"; -static const char __pyx_k_e[] = "e"; -static const char __pyx_k_f[] = "f"; -static const char __pyx_k_g[] = "g"; -static const char __pyx_k_h[] = "h"; -static const char __pyx_k_i[] = "i"; -static const char __pyx_k_n[] = "n"; -static const char __pyx_k_w[] = "w"; -static const char __pyx_k_x[] = "x"; -static const char __pyx_k_1f[] = ".1f"; -static const char __pyx_k_dt[] = "dt"; -static const char __pyx_k_gu[] = "gu"; -static const char __pyx_k_id[] = "id"; -static const char __pyx_k_os[] = "os"; -static const char __pyx_k_sq[] = "sq"; -static const char __pyx_k_tq[] = "tq"; -static const char __pyx_k__34[] = "_"; -static const char __pyx_k_buf[] = "buf"; -static const char __pyx_k_get[] = "get"; -static const char __pyx_k_gsq[] = "gsq"; -static const char __pyx_k_min[] = "min"; -static const char __pyx_k_new[] = "__new__"; -static const char __pyx_k_obj[] = "obj"; -static const char __pyx_k_osr[] = "osr"; -static const char __pyx_k_put[] = "put"; -static const char __pyx_k_sys[] = "sys"; -static const char __pyx_k_base[] = "base"; -static const char __pyx_k_copy[] = "copy"; -static const char __pyx_k_dict[] = "__dict__"; -static const char __pyx_k_done[] = "done"; -static const char __pyx_k_fptr[] = "fptr"; -static const char __pyx_k_gdal[] = "gdal"; -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_main[] = "__main__"; -static const char __pyx_k_mode[] = "mode"; -static const char __pyx_k_name[] = "name"; -static const char __pyx_k_ndim[] = "ndim"; -static const char __pyx_k_pack[] = "pack"; -static const char __pyx_k_path[] = "path"; -static const char __pyx_k_size[] = "size"; -static const char __pyx_k_sort[] = "sort"; -static const char __pyx_k_sqrt[] = "sqrt"; -static const char __pyx_k_step[] = "step"; -static const char __pyx_k_stop[] = "stop"; -static const char __pyx_k_test[] = "__test__"; -static const char __pyx_k_time[] = "time"; -static const char __pyx_k_xoff[] = "xoff"; -static const char __pyx_k_yoff[] = "yoff"; -static const char __pyx_k_zlib[] = "zlib"; -static const char __pyx_k_ASCII[] = "ASCII"; -static const char __pyx_k_GTIFF[] = "GTIFF"; -static const char __pyx_k_block[] = "block"; -static const char __pyx_k_class[] = "__class__"; -static const char __pyx_k_d_dat[] = "%d.dat"; -static const char __pyx_k_debug[] = "debug"; -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_finfo[] = "finfo"; -static const char __pyx_k_flags[] = "flags"; -static const char __pyx_k_index[] = "index"; -static const char __pyx_k_int32[] = "int32"; -static const char __pyx_k_int64[] = "int64"; -static const char __pyx_k_items[] = "items"; -static const char __pyx_k_numpy[] = "numpy"; -static const char __pyx_k_osgeo[] = "osgeo"; -static const char __pyx_k_range[] = "range"; -static const char __pyx_k_shape[] = "shape"; -static const char __pyx_k_start[] = "start"; -static const char __pyx_k_utf_8[] = "utf-8"; -static const char __pyx_k_x_end[] = "x_end"; -static const char __pyx_k_y_end[] = "y_end"; -static const char __pyx_k_LOGGER[] = "LOGGER"; -static const char __pyx_k_M_last[] = "M_last"; -static const char __pyx_k_OpenEx[] = "OpenEx"; -static const char __pyx_k_arange[] = "arange"; -static const char __pyx_k_astype[] = "astype"; -static const char __pyx_k_buffer[] = "buffer"; -static const char __pyx_k_double[] = "double"; -static const char __pyx_k_encode[] = "encode"; -static const char __pyx_k_format[] = "format"; -static const char __pyx_k_g_band[] = "g_band"; -static const char __pyx_k_getpid[] = "getpid"; -static const char __pyx_k_import[] = "__import__"; -static const char __pyx_k_n_cols[] = "n_cols"; -static const char __pyx_k_n_rows[] = "n_rows"; -static const char __pyx_k_name_2[] = "__name__"; -static const char __pyx_k_nodata[] = "nodata"; -static const char __pyx_k_out_of[] = " out of "; -static const char __pyx_k_pickle[] = "pickle"; -static const char __pyx_k_reduce[] = "__reduce__"; -static const char __pyx_k_remove[] = "remove"; -static const char __pyx_k_rmtree[] = "rmtree"; -static const char __pyx_k_shutil[] = "shutil"; -static const char __pyx_k_struct[] = "struct"; -static const char __pyx_k_unpack[] = "unpack"; -static const char __pyx_k_update[] = "update"; -static const char __pyx_k_M_local[] = "M_local"; -static const char __pyx_k_OSError[] = "OSError"; -static const char __pyx_k_S_local[] = "S_local"; -static const char __pyx_k_buf_obj[] = "buf_obj"; -static const char __pyx_k_float32[] = "float32"; -static const char __pyx_k_float64[] = "float64"; -static const char __pyx_k_fortran[] = "fortran"; -static const char __pyx_k_g_block[] = "g_block"; -static const char __pyx_k_isclose[] = "isclose"; -static const char __pyx_k_logging[] = "logging"; -static const char __pyx_k_memview[] = "memview"; -static const char __pyx_k_payload[] = "payload"; -static const char __pyx_k_q_index[] = "q_index"; -static const char __pyx_k_s_array[] = "s_array"; -static const char __pyx_k_t_array[] = "t_array"; -static const char __pyx_k_u_index[] = "u_index"; -static const char __pyx_k_warning[] = "warning"; -static const char __pyx_k_x_start[] = "x_start"; -static const char __pyx_k_y_start[] = "y_start"; -static const char __pyx_k_Ellipsis[] = "Ellipsis"; -static const char __pyx_k_GDT_Byte[] = "GDT_Byte"; -static const char __pyx_k_complete[] = "% complete, "; -static const char __pyx_k_datatype[] = "datatype"; -static const char __pyx_k_dem_band[] = "dem_band"; -static const char __pyx_k_dem_info[] = "dem_info"; -static const char __pyx_k_g_raster[] = "g_raster"; -static const char __pyx_k_getstate[] = "__getstate__"; -static const char __pyx_k_itemsize[] = "itemsize"; -static const char __pyx_k_makedirs[] = "makedirs"; -static const char __pyx_k_n_pixels[] = "n_pixels"; -static const char __pyx_k_next_val[] = "next_val"; -static const char __pyx_k_pyx_type[] = "__pyx_type"; -static const char __pyx_k_setstate[] = "__setstate__"; -static const char __pyx_k_tempfile[] = "tempfile"; -static const char __pyx_k_GA_Update[] = "GA_Update"; -static const char __pyx_k_GDT_Int16[] = "GDT_Int16"; -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_col_index[] = "col_index"; -static const char __pyx_k_dem_array[] = "dem_array"; -static const char __pyx_k_enumerate[] = "enumerate"; -static const char __pyx_k_exception[] = "exception"; -static const char __pyx_k_ffiv_iter[] = "ffiv_iter"; -static const char __pyx_k_file_path[] = "file_path"; -static const char __pyx_k_getLogger[] = "getLogger"; -static const char __pyx_k_mask_band[] = "mask_band"; -static const char __pyx_k_max_value[] = "max_value"; -static const char __pyx_k_min_value[] = "min_value"; -static const char __pyx_k_pyx_state[] = "__pyx_state"; -static const char __pyx_k_reduce_ex[] = "__reduce_ex__"; -static const char __pyx_k_row_index[] = "row_index"; -static const char __pyx_k_step_size[] = "step_size"; -static const char __pyx_k_traceback[] = "traceback"; -static const char __pyx_k_win_xsize[] = "win_xsize"; -static const char __pyx_k_win_ysize[] = "win_ysize"; -static const char __pyx_k_FlushCache[] = "FlushCache"; -static const char __pyx_k_GDT_UInt16[] = "GDT_UInt16"; -static const char __pyx_k_GDT_UInt32[] = "GDT_UInt32"; -static const char __pyx_k_IndexError[] = "IndexError"; -static const char __pyx_k_ValueError[] = "ValueError"; -static const char __pyx_k_WriteArray[] = "WriteArray"; -static const char __pyx_k_block_data[] = "block_data"; -static const char __pyx_k_block_size[] = "block_size"; -static const char __pyx_k_dem_nodata[] = "dem_nodata"; -static const char __pyx_k_dem_raster[] = "dem_raster"; -static const char __pyx_k_dzdx_array[] = "dzdx_array"; -static const char __pyx_k_dzdy_array[] = "dzdy_array"; -static const char __pyx_k_file_index[] = "file_index"; -static const char __pyx_k_iterblocks[] = "iterblocks"; -static const char __pyx_k_mask_block[] = "mask_block"; -static const char __pyx_k_max_sample[] = "max_sample"; -static const char __pyx_k_n_elements[] = "n_elements"; -static const char __pyx_k_pixel_size[] = "pixel_size"; -static const char __pyx_k_pyx_result[] = "__pyx_result"; -static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__"; -static const char __pyx_k_raw_nodata[] = "raw_nodata"; -static const char __pyx_k_sample_d_x[] = "sample_d_x"; -static const char __pyx_k_sample_d_y[] = "sample_d_y"; -static const char __pyx_k_valid_mask[] = "valid_mask"; -static const char __pyx_k_BIGTIFF_YES[] = "BIGTIFF=YES"; -static const char __pyx_k_GDT_Float32[] = "GDT_Float32"; -static const char __pyx_k_GDT_Float64[] = "GDT_Float64"; -static const char __pyx_k_ImportError[] = "ImportError"; -static const char __pyx_k_MemoryError[] = "MemoryError"; -static const char __pyx_k_PickleError[] = "PickleError"; -static const char __pyx_k_RasterXSize[] = "RasterXSize"; -static const char __pyx_k_RasterYSize[] = "RasterYSize"; -static const char __pyx_k_ReadAsArray[] = "ReadAsArray"; -static const char __pyx_k_block_xsize[] = "block_xsize"; -static const char __pyx_k_block_ysize[] = "block_ysize"; -static const char __pyx_k_buffer_data[] = "buffer_data"; -static const char __pyx_k_last_update[] = "last_update"; -static const char __pyx_k_mask_raster[] = "mask_raster"; -static const char __pyx_k_offset_only[] = "offset_only"; -static const char __pyx_k_raster_info[] = "raster_info"; -static const char __pyx_k_raster_size[] = "raster_size"; -static const char __pyx_k_raster_type[] = "raster_type"; -static const char __pyx_k_result_list[] = "result_list"; -static const char __pyx_k_slope_array[] = "slope_array"; -static const char __pyx_k_x_cell_size[] = "x_cell_size"; -static const char __pyx_k_y_cell_size[] = "y_cell_size"; -static const char __pyx_k_COMPRESS_LZW[] = "COMPRESS=LZW"; -static const char __pyx_k_GetBlockSize[] = "GetBlockSize"; -static const char __pyx_k_block_offset[] = "block_offset"; -static const char __pyx_k_current_step[] = "current_step"; -static const char __pyx_k_existing_shm[] = "existing_shm"; -static const char __pyx_k_pyx_checksum[] = "__pyx_checksum"; -static const char __pyx_k_slope_nodata[] = "slope_nodata"; -static const char __pyx_k_stats_worker[] = "stats_worker"; -static const char __pyx_k_stringsource[] = "stringsource"; -static const char __pyx_k_GetRasterBand[] = "GetRasterBand"; -static const char __pyx_k_g_raster_path[] = "g_raster_path"; -static const char __pyx_k_heapfile_list[] = "heapfile_list"; -static const char __pyx_k_largest_block[] = "largest_block"; -static const char __pyx_k_local_x_index[] = "local_x_index"; -static const char __pyx_k_local_y_index[] = "local_y_index"; -static const char __pyx_k_numerical_inf[] = "numerical_inf"; -static const char __pyx_k_pyx_getbuffer[] = "__pyx_getbuffer"; -static const char __pyx_k_reduce_cython[] = "__reduce_cython__"; -static const char __pyx_k_BLOCKXSIZE_256[] = "BLOCKXSIZE=256"; -static const char __pyx_k_BLOCKYSIZE_256[] = "BLOCKYSIZE=256"; -static const char __pyx_k_x_denom_factor[] = "x_denom_factor"; -static const char __pyx_k_y_denom_factor[] = "y_denom_factor"; -static const char __pyx_k_View_MemoryView[] = "View.MemoryView"; -static const char __pyx_k_allocate_buffer[] = "allocate_buffer"; -static const char __pyx_k_calculate_slope[] = "calculate_slope"; -static const char __pyx_k_distance_nodata[] = "distance_nodata"; -static const char __pyx_k_dtype_is_object[] = "dtype_is_object"; -static const char __pyx_k_expected_blocks[] = "expected_blocks"; -static const char __pyx_k_ffi_buffer_size[] = "ffi_buffer_size"; -static const char __pyx_k_get_raster_info[] = "get_raster_info"; -static const char __pyx_k_multiprocessing[] = "multiprocessing"; -static const char __pyx_k_percentile_list[] = "percentile_list"; -static const char __pyx_k_pygeoprocessing[] = "pygeoprocessing"; -static const char __pyx_k_pyx_PickleError[] = "__pyx_PickleError"; -static const char __pyx_k_setstate_cython[] = "__setstate_cython__"; -static const char __pyx_k_dzdx_accumulator[] = "dzdx_accumulator"; -static const char __pyx_k_dzdy_accumulator[] = "dzdy_accumulator"; -static const char __pyx_k_g_band_blocksize[] = "g_band_blocksize"; -static const char __pyx_k_heap_buffer_size[] = "heap_buffer_size"; -static const char __pyx_k_percentile_index[] = "percentile_index"; -static const char __pyx_k_pixels_processed[] = "pixels_processed"; -static const char __pyx_k_rm_dir_when_done[] = "rm_dir_when_done"; -static const char __pyx_k_stats_work_queue[] = "stats_work_queue"; -static const char __pyx_k_stats_worker_PID[] = "stats worker PID: "; -static const char __pyx_k_ComputeStatistics[] = "ComputeStatistics"; -static const char __pyx_k_block_offset_copy[] = "block_offset_copy"; -static const char __pyx_k_data_sort_to_heap[] = "data sort to heap "; -static const char __pyx_k_pyx_unpickle_Enum[] = "__pyx_unpickle_Enum"; -static const char __pyx_k_target_slope_band[] = "target_slope_band"; -static const char __pyx_k_target_slope_path[] = "target_slope_path"; -static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; -static const char __pyx_k_current_percentile[] = "current_percentile"; -static const char __pyx_k_fast_file_iterator[] = "fast_file_iterator"; -static const char __pyx_k_region_raster_path[] = "region_raster_path"; -static const char __pyx_k_strided_and_direct[] = ""; -static const char __pyx_k_unable_to_remove_s[] = "unable to remove %s"; -static const char __pyx_k_exception_s_s_s_s_s[] = "exception %s %s %s %s %s"; -static const char __pyx_k_target_slope_raster[] = "target_slope_raster"; -static const char __pyx_k_new_raster_from_base[] = "new_raster_from_base"; -static const char __pyx_k_sorting_data_to_heap[] = "sorting data to heap"; -static const char __pyx_k_strided_and_indirect[] = ""; -static const char __pyx_k_target_distance_band[] = "target_distance_band"; -static const char __pyx_k_base_raster_path_band[] = "base_raster_path_band"; -static const char __pyx_k_contiguous_and_direct[] = ""; -static const char __pyx_k_invalid_value_for_n_s[] = "invalid value for n %s"; -static const char __pyx_k_MemoryView_of_r_object[] = ""; -static const char __pyx_k_distance_transform_edt[] = "_distance_transform_edt"; -static const char __pyx_k_raster_band_percentile[] = "raster_band_percentile"; -static const char __pyx_k_target_distance_raster[] = "target_distance_raster"; -static const char __pyx_k_working_sort_directory[] = "working_sort_directory"; -static const char __pyx_k_MemoryView_of_r_at_0x_x[] = ""; -static const char __pyx_k_calculating_percentiles[] = "calculating percentiles"; -static const char __pyx_k_contiguous_and_indirect[] = ""; -static const char __pyx_k_Cannot_index_with_type_s[] = "Cannot index with type '%s'"; -static const char __pyx_k_Invalid_shape_in_axis_d_d[] = "Invalid shape in axis %d: %d."; -static const char __pyx_k_fast_file_iterator_vector[] = "fast_file_iterator_vector"; -static const char __pyx_k_here_is_percentile_list_s[] = "here is percentile_list: %s"; -static const char __pyx_k_Distance_Transform_Phase_2[] = "Distance Transform Phase 2"; -static const char __pyx_k_OAMS_TRADITIONAL_GIS_ORDER[] = "OAMS_TRADITIONAL_GIS_ORDER"; -static const char __pyx_k_raster_band_percentile_int[] = "_raster_band_percentile_int"; -static const char __pyx_k_total_number_of_pixels_s_s[] = "total number of pixels %s (%s)"; -static const char __pyx_k_itemsize_0_for_cython_array[] = "itemsize <= 0 for cython.array"; -static const char __pyx_k_target_distance_raster_path[] = "target_distance_raster_path"; -static const char __pyx_k_raster_driver_creation_tuple[] = "raster_driver_creation_tuple"; -static const char __pyx_k_raster_band_percentile_double[] = "_raster_band_percentile_double"; -static const char __pyx_k_unable_to_allocate_array_data[] = "unable to allocate array data."; -static const char __pyx_k_strided_and_direct_or_indirect[] = ""; -static const char __pyx_k_base_elevation_raster_path_band[] = "base_elevation_raster_path_band"; -static const char __pyx_k_numpy_core_multiarray_failed_to[] = "numpy.core.multiarray failed to import"; -static const char __pyx_k_Buffer_view_does_not_expose_stri[] = "Buffer view does not expose strides"; -static const char __pyx_k_Can_only_create_a_buffer_that_is[] = "Can only create a buffer that is contiguous in memory."; -static const char __pyx_k_Cannot_assign_to_read_only_memor[] = "Cannot assign to read-only memoryview"; -static const char __pyx_k_Cannot_create_writable_memory_vi[] = "Cannot create writable memory view from read-only memoryview"; -static const char __pyx_k_Cannot_process_raster_type_s_not[] = "Cannot process raster type %s (not a known integer nor float type)"; -static const char __pyx_k_DEFAULT_GTIFF_CREATION_TUPLE_OPT[] = "DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS"; -static const char __pyx_k_DEFAULT_OSR_AXIS_MAPPING_STRATEG[] = "DEFAULT_OSR_AXIS_MAPPING_STRATEGY"; -static const char __pyx_k_Empty_shape_tuple_for_cython_arr[] = "Empty shape tuple for cython.array"; -static const char __pyx_k_Incompatible_checksums_s_vs_0xb0[] = "Incompatible checksums (%s vs 0xb068931 = (name))"; -static const char __pyx_k_Indirect_dimensions_not_supporte[] = "Indirect dimensions not supported"; -static const char __pyx_k_Invalid_mode_expected_c_or_fortr[] = "Invalid mode, expected 'c' or 'fortran', got %s"; -static const char __pyx_k_No_valid_pixels_were_received_se[] = "No valid pixels were received, sending None."; -static const char __pyx_k_Out_of_bounds_on_buffer_access_a[] = "Out of bounds on buffer access (axis %d)"; -static const char __pyx_k_Unable_to_convert_item_to_object[] = "Unable to convert item to object"; -static const char __pyx_k_calculating_percentiles_2f_compl[] = "calculating percentiles %.2f%% complete"; -static const char __pyx_k_couldn_t_make_working_sort_direc[] = "couldn't make working_sort_directory: %s"; -static const char __pyx_k_got_differing_extents_in_dimensi[] = "got differing extents in dimension %d (got %d and %d)"; -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_pygeoprocessing_geoprocessing_co[] = "pygeoprocessing.geoprocessing_core"; -static const char __pyx_k_src_pygeoprocessing_geoprocessin[] = "src/pygeoprocessing/geoprocessing_core.pyx"; -static const char __pyx_k_unable_to_allocate_shape_and_str[] = "unable to allocate shape and strides."; -static PyObject *__pyx_kp_u_1f; -static PyObject *__pyx_n_s_ASCII; -static PyObject *__pyx_kp_u_BIGTIFF_YES; -static PyObject *__pyx_kp_u_BLOCKXSIZE_256; -static PyObject *__pyx_kp_u_BLOCKYSIZE_256; -static PyObject *__pyx_kp_s_Buffer_view_does_not_expose_stri; -static PyObject *__pyx_kp_u_COMPRESS_LZW; -static PyObject *__pyx_kp_s_Can_only_create_a_buffer_that_is; -static PyObject *__pyx_kp_s_Cannot_assign_to_read_only_memor; -static PyObject *__pyx_kp_s_Cannot_create_writable_memory_vi; -static PyObject *__pyx_kp_s_Cannot_index_with_type_s; -static PyObject *__pyx_kp_u_Cannot_process_raster_type_s_not; -static PyObject *__pyx_n_s_ComputeStatistics; -static PyObject *__pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT; -static PyObject *__pyx_n_s_DEFAULT_OSR_AXIS_MAPPING_STRATEG; -static PyObject *__pyx_kp_u_Distance_Transform_Phase_2; -static PyObject *__pyx_n_s_Ellipsis; -static PyObject *__pyx_kp_s_Empty_shape_tuple_for_cython_arr; -static PyObject *__pyx_n_s_FlushCache; -static PyObject *__pyx_n_s_GA_Update; -static PyObject *__pyx_n_s_GDT_Byte; -static PyObject *__pyx_n_s_GDT_Float32; -static PyObject *__pyx_n_s_GDT_Float64; -static PyObject *__pyx_n_s_GDT_Int16; -static PyObject *__pyx_n_s_GDT_Int32; -static PyObject *__pyx_n_s_GDT_UInt16; -static PyObject *__pyx_n_s_GDT_UInt32; -static PyObject *__pyx_n_u_GTIFF; -static PyObject *__pyx_n_s_GetBlockSize; -static PyObject *__pyx_n_s_GetRasterBand; -static PyObject *__pyx_n_s_ImportError; -static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0xb0; -static PyObject *__pyx_n_s_IndexError; -static PyObject *__pyx_kp_s_Indirect_dimensions_not_supporte; -static PyObject *__pyx_kp_s_Invalid_mode_expected_c_or_fortr; -static PyObject *__pyx_kp_s_Invalid_shape_in_axis_d_d; -static PyObject *__pyx_n_s_LOGGER; -static PyObject *__pyx_n_s_M_last; -static PyObject *__pyx_n_s_M_local; -static PyObject *__pyx_n_s_MemoryError; -static PyObject *__pyx_kp_s_MemoryView_of_r_at_0x_x; -static PyObject *__pyx_kp_s_MemoryView_of_r_object; -static PyObject *__pyx_kp_u_No_valid_pixels_were_received_se; -static PyObject *__pyx_n_b_O; -static PyObject *__pyx_n_s_OAMS_TRADITIONAL_GIS_ORDER; -static PyObject *__pyx_n_s_OF_RASTER; -static PyObject *__pyx_n_s_OSError; -static PyObject *__pyx_n_s_OpenEx; -static PyObject *__pyx_kp_s_Out_of_bounds_on_buffer_access_a; -static PyObject *__pyx_n_s_PickleError; -static PyObject *__pyx_n_s_RasterXSize; -static PyObject *__pyx_n_s_RasterYSize; -static PyObject *__pyx_n_s_ReadAsArray; -static PyObject *__pyx_n_s_S_local; -static PyObject *__pyx_kp_u_TILED_YES; -static PyObject *__pyx_n_s_TypeError; -static PyObject *__pyx_kp_s_Unable_to_convert_item_to_object; -static PyObject *__pyx_n_s_ValueError; -static PyObject *__pyx_n_s_View_MemoryView; -static PyObject *__pyx_n_s_WriteArray; -static PyObject *__pyx_n_s__34; -static PyObject *__pyx_n_s_a; -static PyObject *__pyx_n_s_allocate_buffer; -static PyObject *__pyx_n_s_arange; -static PyObject *__pyx_n_s_astype; -static PyObject *__pyx_n_s_b; -static PyObject *__pyx_n_s_base; -static PyObject *__pyx_n_s_base_elevation_raster_path_band; -static PyObject *__pyx_n_s_base_raster_path_band; -static PyObject *__pyx_n_s_block; -static PyObject *__pyx_n_s_block_data; -static PyObject *__pyx_n_s_block_offset; -static PyObject *__pyx_n_s_block_offset_copy; -static PyObject *__pyx_n_u_block_size; -static PyObject *__pyx_n_s_block_xsize; -static PyObject *__pyx_n_s_block_ysize; -static PyObject *__pyx_n_s_buf; -static PyObject *__pyx_n_s_buf_obj; -static PyObject *__pyx_n_s_buffer; -static PyObject *__pyx_n_s_buffer_data; -static PyObject *__pyx_n_s_c; -static PyObject *__pyx_n_u_c; -static PyObject *__pyx_n_s_calculate_slope; -static PyObject *__pyx_kp_u_calculating_percentiles; -static PyObject *__pyx_kp_u_calculating_percentiles_2f_compl; -static PyObject *__pyx_n_s_class; -static PyObject *__pyx_n_s_cline_in_traceback; -static PyObject *__pyx_n_s_col_index; -static PyObject *__pyx_kp_u_complete; -static PyObject *__pyx_kp_s_contiguous_and_direct; -static PyObject *__pyx_kp_s_contiguous_and_indirect; -static PyObject *__pyx_n_s_copy; -static PyObject *__pyx_kp_u_couldn_t_make_working_sort_direc; -static PyObject *__pyx_n_s_current_percentile; -static PyObject *__pyx_n_s_current_step; -static PyObject *__pyx_n_s_d; -static PyObject *__pyx_kp_u_d_dat; -static PyObject *__pyx_kp_u_data_sort_to_heap; -static PyObject *__pyx_n_u_datatype; -static PyObject *__pyx_n_s_debug; -static PyObject *__pyx_n_s_dem_array; -static PyObject *__pyx_n_s_dem_band; -static PyObject *__pyx_n_s_dem_info; -static PyObject *__pyx_n_s_dem_nodata; -static PyObject *__pyx_n_s_dem_raster; -static PyObject *__pyx_n_s_dict; -static PyObject *__pyx_n_s_distance_nodata; -static PyObject *__pyx_n_s_distance_transform_edt; -static PyObject *__pyx_n_s_done; -static PyObject *__pyx_n_s_double; -static PyObject *__pyx_n_s_dt; -static PyObject *__pyx_n_s_dtype; -static PyObject *__pyx_n_s_dtype_is_object; -static PyObject *__pyx_n_s_dzdx_accumulator; -static PyObject *__pyx_n_s_dzdx_array; -static PyObject *__pyx_n_s_dzdy_accumulator; -static PyObject *__pyx_n_s_dzdy_array; -static PyObject *__pyx_n_s_e; -static PyObject *__pyx_n_s_empty; -static PyObject *__pyx_n_s_encode; -static PyObject *__pyx_n_s_enumerate; -static PyObject *__pyx_n_s_error; -static PyObject *__pyx_n_s_exception; -static PyObject *__pyx_kp_u_exception_s_s_s_s_s; -static PyObject *__pyx_n_s_existing_shm; -static PyObject *__pyx_n_s_expected_blocks; -static PyObject *__pyx_n_s_f; -static PyObject *__pyx_n_s_fast_file_iterator; -static PyObject *__pyx_n_s_fast_file_iterator_vector; -static PyObject *__pyx_n_s_ffi_buffer_size; -static PyObject *__pyx_n_s_ffiv_iter; -static PyObject *__pyx_n_s_file_index; -static PyObject *__pyx_n_s_file_path; -static PyObject *__pyx_n_s_finfo; -static PyObject *__pyx_n_s_flags; -static PyObject *__pyx_n_s_float32; -static PyObject *__pyx_n_s_float64; -static PyObject *__pyx_n_s_format; -static PyObject *__pyx_n_s_fortran; -static PyObject *__pyx_n_u_fortran; -static PyObject *__pyx_n_s_fptr; -static PyObject *__pyx_n_s_g; -static PyObject *__pyx_n_s_g_band; -static PyObject *__pyx_n_s_g_band_blocksize; -static PyObject *__pyx_n_s_g_block; -static PyObject *__pyx_n_s_g_raster; -static PyObject *__pyx_n_s_g_raster_path; -static PyObject *__pyx_n_s_gdal; -static PyObject *__pyx_n_s_get; -static PyObject *__pyx_n_s_getLogger; -static PyObject *__pyx_n_s_get_raster_info; -static PyObject *__pyx_n_s_getpid; -static PyObject *__pyx_n_s_getstate; -static PyObject *__pyx_kp_s_got_differing_extents_in_dimensi; -static PyObject *__pyx_n_s_gsq; -static PyObject *__pyx_n_s_gu; -static PyObject *__pyx_n_s_h; -static PyObject *__pyx_n_s_heap_buffer_size; -static PyObject *__pyx_n_s_heapfile_list; -static PyObject *__pyx_kp_u_here_is_percentile_list_s; -static PyObject *__pyx_n_s_i; -static PyObject *__pyx_n_s_id; -static PyObject *__pyx_n_s_import; -static PyObject *__pyx_n_s_index; -static PyObject *__pyx_n_s_info; -static PyObject *__pyx_n_s_int32; -static PyObject *__pyx_n_s_int64; -static PyObject *__pyx_n_s_int8; -static PyObject *__pyx_kp_u_invalid_value_for_n_s; -static PyObject *__pyx_n_s_isclose; -static PyObject *__pyx_n_s_items; -static PyObject *__pyx_n_s_itemsize; -static PyObject *__pyx_kp_s_itemsize_0_for_cython_array; -static PyObject *__pyx_n_s_iterblocks; -static PyObject *__pyx_n_s_join; -static PyObject *__pyx_n_s_largest_block; -static PyObject *__pyx_n_s_last_update; -static PyObject *__pyx_n_s_local_x_index; -static PyObject *__pyx_n_s_local_y_index; -static PyObject *__pyx_n_s_logging; -static PyObject *__pyx_n_s_main; -static PyObject *__pyx_n_s_makedirs; -static PyObject *__pyx_n_s_mask_band; -static PyObject *__pyx_n_s_mask_block; -static PyObject *__pyx_n_s_mask_raster; -static PyObject *__pyx_n_s_max_sample; -static PyObject *__pyx_n_s_max_value; -static PyObject *__pyx_n_s_memview; -static PyObject *__pyx_n_s_min; -static PyObject *__pyx_n_s_min_value; -static PyObject *__pyx_n_s_mode; -static PyObject *__pyx_n_s_multiprocessing; -static PyObject *__pyx_n_s_n; -static PyObject *__pyx_n_s_n_cols; -static PyObject *__pyx_n_s_n_elements; -static PyObject *__pyx_n_s_n_pixels; -static PyObject *__pyx_n_s_n_rows; -static PyObject *__pyx_n_s_name; -static PyObject *__pyx_n_s_name_2; -static PyObject *__pyx_n_s_ndim; -static PyObject *__pyx_n_s_new; -static PyObject *__pyx_n_s_new_raster_from_base; -static PyObject *__pyx_n_s_next_val; -static PyObject *__pyx_kp_s_no_default___reduce___due_to_non; -static PyObject *__pyx_n_s_nodata; -static PyObject *__pyx_n_u_nodata; -static PyObject *__pyx_n_s_numerical_inf; -static PyObject *__pyx_n_s_numpy; -static PyObject *__pyx_kp_u_numpy_core_multiarray_failed_to; -static PyObject *__pyx_kp_u_numpy_core_umath_failed_to_impor; -static PyObject *__pyx_n_s_obj; -static PyObject *__pyx_n_s_offset_only; -static PyObject *__pyx_n_s_os; -static PyObject *__pyx_n_s_osgeo; -static PyObject *__pyx_n_s_osr; -static PyObject *__pyx_kp_u_out_of; -static PyObject *__pyx_n_s_pack; -static PyObject *__pyx_n_s_path; -static PyObject *__pyx_n_s_payload; -static PyObject *__pyx_n_s_percentile_index; -static PyObject *__pyx_n_s_percentile_list; -static PyObject *__pyx_n_s_pickle; -static PyObject *__pyx_n_u_pixel_size; -static PyObject *__pyx_n_s_pixels_processed; -static PyObject *__pyx_n_s_put; -static PyObject *__pyx_n_s_pygeoprocessing; -static PyObject *__pyx_n_s_pygeoprocessing_geoprocessing_co; -static PyObject *__pyx_kp_u_pygeoprocessing_geoprocessing_co; -static PyObject *__pyx_n_s_pyx_PickleError; -static PyObject *__pyx_n_s_pyx_checksum; -static PyObject *__pyx_n_s_pyx_getbuffer; -static PyObject *__pyx_n_s_pyx_result; -static PyObject *__pyx_n_s_pyx_state; -static PyObject *__pyx_n_s_pyx_type; -static PyObject *__pyx_n_s_pyx_unpickle_Enum; -static PyObject *__pyx_n_s_pyx_vtable; -static PyObject *__pyx_n_s_q_index; -static PyObject *__pyx_n_s_range; -static PyObject *__pyx_n_s_raster_band_percentile; -static PyObject *__pyx_n_s_raster_band_percentile_double; -static PyObject *__pyx_n_s_raster_band_percentile_int; -static PyObject *__pyx_n_s_raster_driver_creation_tuple; -static PyObject *__pyx_n_s_raster_info; -static PyObject *__pyx_n_u_raster_size; -static PyObject *__pyx_n_s_raster_type; -static PyObject *__pyx_n_s_raw_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_region_raster_path; -static PyObject *__pyx_n_s_remove; -static PyObject *__pyx_n_s_result_list; -static PyObject *__pyx_n_s_rm_dir_when_done; -static PyObject *__pyx_n_s_rmtree; -static PyObject *__pyx_n_s_row_index; -static PyObject *__pyx_n_s_s_array; -static PyObject *__pyx_n_s_sample_d_x; -static PyObject *__pyx_n_s_sample_d_y; -static PyObject *__pyx_n_s_setstate; -static PyObject *__pyx_n_s_setstate_cython; -static PyObject *__pyx_n_s_shape; -static PyObject *__pyx_n_s_shutil; -static PyObject *__pyx_n_s_size; -static PyObject *__pyx_n_s_slope_array; -static PyObject *__pyx_n_s_slope_nodata; -static PyObject *__pyx_n_s_sort; -static PyObject *__pyx_kp_u_sorting_data_to_heap; -static PyObject *__pyx_n_s_sq; -static PyObject *__pyx_n_s_sqrt; -static PyObject *__pyx_kp_s_src_pygeoprocessing_geoprocessin; -static PyObject *__pyx_n_s_start; -static PyObject *__pyx_n_s_stats_work_queue; -static PyObject *__pyx_n_s_stats_worker; -static PyObject *__pyx_kp_u_stats_worker_PID; -static PyObject *__pyx_n_s_step; -static PyObject *__pyx_n_s_step_size; -static PyObject *__pyx_n_s_stop; -static PyObject *__pyx_kp_s_strided_and_direct; -static PyObject *__pyx_kp_s_strided_and_direct_or_indirect; -static PyObject *__pyx_kp_s_strided_and_indirect; -static PyObject *__pyx_kp_s_stringsource; -static PyObject *__pyx_n_s_struct; -static PyObject *__pyx_n_s_sys; -static PyObject *__pyx_n_s_t_array; -static PyObject *__pyx_n_s_target_distance_band; -static PyObject *__pyx_n_s_target_distance_raster; -static PyObject *__pyx_n_s_target_distance_raster_path; -static PyObject *__pyx_n_s_target_slope_band; -static PyObject *__pyx_n_s_target_slope_path; -static PyObject *__pyx_n_s_target_slope_raster; -static PyObject *__pyx_n_s_tempfile; -static PyObject *__pyx_n_s_test; -static PyObject *__pyx_n_s_time; -static PyObject *__pyx_kp_u_total_number_of_pixels_s_s; -static PyObject *__pyx_n_s_tq; -static PyObject *__pyx_n_s_traceback; -static PyObject *__pyx_n_s_u_index; -static PyObject *__pyx_kp_s_unable_to_allocate_array_data; -static PyObject *__pyx_kp_s_unable_to_allocate_shape_and_str; -static PyObject *__pyx_kp_u_unable_to_remove_s; -static PyObject *__pyx_n_s_unpack; -static PyObject *__pyx_n_s_update; -static PyObject *__pyx_kp_u_utf_8; -static PyObject *__pyx_n_s_valid_mask; -static PyObject *__pyx_n_s_w; -static PyObject *__pyx_n_s_warning; -static PyObject *__pyx_n_s_win_xsize; -static PyObject *__pyx_n_u_win_xsize; -static PyObject *__pyx_n_s_win_ysize; -static PyObject *__pyx_n_u_win_ysize; -static PyObject *__pyx_n_s_working_sort_directory; -static PyObject *__pyx_n_s_x; -static PyObject *__pyx_n_s_x_cell_size; -static PyObject *__pyx_n_s_x_denom_factor; -static PyObject *__pyx_n_s_x_end; -static PyObject *__pyx_n_s_x_start; -static PyObject *__pyx_n_s_xoff; -static PyObject *__pyx_n_u_xoff; -static PyObject *__pyx_n_s_y_cell_size; -static PyObject *__pyx_n_s_y_denom_factor; -static PyObject *__pyx_n_s_y_end; -static PyObject *__pyx_n_s_y_start; -static PyObject *__pyx_n_s_yoff; -static PyObject *__pyx_n_u_yoff; -static PyObject *__pyx_n_s_zlib; -static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core__distance_transform_edt(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_region_raster_path, PyObject *__pyx_v_g_raster_path, float __pyx_v_sample_d_x, float __pyx_v_sample_d_y, PyObject *__pyx_v_target_distance_raster_path, PyObject *__pyx_v_raster_driver_creation_tuple); /* proto */ -static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core_2calculate_slope(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_base_elevation_raster_path_band, PyObject *__pyx_v_target_slope_path, PyObject *__pyx_v_raster_driver_creation_tuple); /* proto */ -static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core_4stats_worker(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_stats_work_queue, PyObject *__pyx_v_expected_blocks); /* proto */ -static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core_6raster_band_percentile(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_base_raster_path_band, PyObject *__pyx_v_working_sort_directory, PyObject *__pyx_v_percentile_list, PyObject *__pyx_v_heap_buffer_size, PyObject *__pyx_v_ffi_buffer_size); /* proto */ -static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core_8_raster_band_percentile_int(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_base_raster_path_band, PyObject *__pyx_v_working_sort_directory, PyObject *__pyx_v_percentile_list, PyObject *__pyx_v_heap_buffer_size, PyObject *__pyx_v_ffi_buffer_size); /* proto */ -static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core_10_raster_band_percentile_double(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_base_raster_path_band, PyObject *__pyx_v_working_sort_directory, PyObject *__pyx_v_percentile_list, PyObject *__pyx_v_heap_buffer_size, PyObject *__pyx_v_ffi_buffer_size); /* proto */ -static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, PyObject *__pyx_v_format, PyObject *__pyx_v_mode, int __pyx_v_allocate_buffer); /* proto */ -static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_2__getbuffer__(struct __pyx_array_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */ -static void __pyx_array___pyx_pf_15View_dot_MemoryView_5array_4__dealloc__(struct __pyx_array_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_15View_dot_MemoryView_5array_7memview___get__(struct __pyx_array_obj *__pyx_v_self); /* proto */ -static Py_ssize_t __pyx_array___pyx_pf_15View_dot_MemoryView_5array_6__len__(struct __pyx_array_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_8__getattr__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_attr); /* proto */ -static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_10__getitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item); /* proto */ -static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_12__setitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value); /* proto */ -static PyObject *__pyx_pf___pyx_array___reduce_cython__(CYTHON_UNUSED struct __pyx_array_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf___pyx_array_2__setstate_cython__(CYTHON_UNUSED struct __pyx_array_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ -static int __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum___init__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v_name); /* proto */ -static PyObject *__pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum_2__repr__(struct __pyx_MemviewEnum_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf___pyx_MemviewEnum___reduce_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf___pyx_MemviewEnum_2__setstate_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ -static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview___cinit__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj, int __pyx_v_flags, int __pyx_v_dtype_is_object); /* proto */ -static void __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_2__dealloc__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_4__getitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index); /* proto */ -static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_6__setitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value); /* proto */ -static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_8__getbuffer__(struct __pyx_memoryview_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */ -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_1T___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4base___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_5shape___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_7strides___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_10suboffsets___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4ndim___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_8itemsize___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_6nbytes___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4size___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ -static Py_ssize_t __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_10__len__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_12__repr__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_14__str__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_16is_c_contig(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_18is_f_contig(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_20copy(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_22copy_fortran(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf___pyx_memoryview___reduce_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf___pyx_memoryview_2__setstate_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ -static void __pyx_memoryviewslice___pyx_pf_15View_dot_MemoryView_16_memoryviewslice___dealloc__(struct __pyx_memoryviewslice_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_15View_dot_MemoryView_16_memoryviewslice_4base___get__(struct __pyx_memoryviewslice_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf___pyx_memoryviewslice___reduce_cython__(CYTHON_UNUSED struct __pyx_memoryviewslice_obj *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf___pyx_memoryviewslice_2__setstate_cython__(CYTHON_UNUSED struct __pyx_memoryviewslice_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ -static PyObject *__pyx_pf_15View_dot_MemoryView___pyx_unpickle_Enum(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ -static PyObject *__pyx_tp_new_array(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ -static PyObject *__pyx_tp_new_Enum(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ -static PyObject *__pyx_tp_new_memoryview(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ -static PyObject *__pyx_tp_new__memoryviewslice(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ -static PyObject *__pyx_float_5_0; -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_1024; -static PyObject *__pyx_int_184977713; -static PyObject *__pyx_int_268435456; -static PyObject *__pyx_int_neg_1; -static PyObject *__pyx_k__3; -static PyObject *__pyx_slice_; -static PyObject *__pyx_tuple__2; -static PyObject *__pyx_tuple__4; -static PyObject *__pyx_tuple__5; -static PyObject *__pyx_tuple__6; -static PyObject *__pyx_tuple__7; -static PyObject *__pyx_tuple__8; -static PyObject *__pyx_tuple__9; -static PyObject *__pyx_tuple__10; -static PyObject *__pyx_tuple__11; -static PyObject *__pyx_tuple__12; -static PyObject *__pyx_tuple__13; -static PyObject *__pyx_tuple__14; -static PyObject *__pyx_tuple__15; -static PyObject *__pyx_tuple__16; -static PyObject *__pyx_tuple__17; -static PyObject *__pyx_tuple__18; -static PyObject *__pyx_tuple__19; -static PyObject *__pyx_tuple__20; -static PyObject *__pyx_tuple__21; -static PyObject *__pyx_tuple__22; -static PyObject *__pyx_tuple__23; -static PyObject *__pyx_tuple__24; -static PyObject *__pyx_tuple__25; -static PyObject *__pyx_tuple__26; -static PyObject *__pyx_tuple__28; -static PyObject *__pyx_tuple__30; -static PyObject *__pyx_tuple__32; -static PyObject *__pyx_tuple__35; -static PyObject *__pyx_tuple__37; -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_codeobj__27; -static PyObject *__pyx_codeobj__29; -static PyObject *__pyx_codeobj__31; -static PyObject *__pyx_codeobj__33; -static PyObject *__pyx_codeobj__36; -static PyObject *__pyx_codeobj__38; -static PyObject *__pyx_codeobj__45; -/* Late includes */ - -/* "pygeoprocessing/geoprocessing_core.pyx":71 - * @cython.wraparound(False) - * @cython.cdivision(True) - * def _distance_transform_edt( # <<<<<<<<<<<<<< - * region_raster_path, g_raster_path, float sample_d_x, - * float sample_d_y, target_distance_raster_path, - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_1_distance_transform_edt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_15pygeoprocessing_18geoprocessing_core__distance_transform_edt[] = "Calculate the euclidean distance transform on base raster.\n\n Calculates the euclidean distance transform on the base raster in units of\n pixels multiplied by an optional scalar constant. The implementation is\n based off the algorithm described in: Meijster, Arnold, Jos BTM Roerdink,\n and Wim H. Hesselink. \"A general algorithm for computing distance\n transforms in linear time.\" Mathematical Morphology and its applications\n to image and signal processing. Springer, Boston, MA, 2002. 331-340.\n\n The base mask raster represents the area to distance transform from as\n any pixel that is not 0 or nodata. It is computationally convenient to\n calculate the distance transform on the entire raster irrespective of\n nodata placement and thus produces a raster that will have distance\n transform values even in pixels that are nodata in the base.\n\n Parameters:\n region_raster_path (string): path to a byte raster where region pixels\n are indicated by a 1 and 0 otherwise.\n g_raster_path (string): path to a raster created by this call that\n is used as the intermediate \"g\" variable described in Meijster\n et. al.\n sample_d_x (float):\n sample_d_y (float):\n These parameters scale the pixel distances when calculating the\n distance transform. ``d_x`` is the x direction when changing a\n column index, and ``d_y`` when changing a row index. Both values\n must be > 0.\n target_distance_raster_path (string): path to the target raster\n created by this call that is the exact euclidean distance\n transform from any pixel in the base raster that is not nodata and\n not 0. The units are in (pixel distance * sampling_distance).\n raster_driver_creation_tuple (tuple): a tuple containing a GDAL driver\n name string as the first element and a GDAL creation options\n tup""le/list as the second. Defaults to a GTiff driver tuple\n defined at geoprocessing.DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS.\n\n Returns:\n None\n\n "; -static PyMethodDef __pyx_mdef_15pygeoprocessing_18geoprocessing_core_1_distance_transform_edt = {"_distance_transform_edt", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_18geoprocessing_core_1_distance_transform_edt, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_18geoprocessing_core__distance_transform_edt}; -static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_1_distance_transform_edt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_region_raster_path = 0; - PyObject *__pyx_v_g_raster_path = 0; - float __pyx_v_sample_d_x; - float __pyx_v_sample_d_y; - PyObject *__pyx_v_target_distance_raster_path = 0; - PyObject *__pyx_v_raster_driver_creation_tuple = 0; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_distance_transform_edt (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_region_raster_path,&__pyx_n_s_g_raster_path,&__pyx_n_s_sample_d_x,&__pyx_n_s_sample_d_y,&__pyx_n_s_target_distance_raster_path,&__pyx_n_s_raster_driver_creation_tuple,0}; - PyObject* values[6] = {0,0,0,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 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_region_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_g_raster_path)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_distance_transform_edt", 1, 6, 6, 1); __PYX_ERR(0, 71, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_sample_d_x)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_distance_transform_edt", 1, 6, 6, 2); __PYX_ERR(0, 71, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_sample_d_y)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_distance_transform_edt", 1, 6, 6, 3); __PYX_ERR(0, 71, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 4: - if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_distance_raster_path)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_distance_transform_edt", 1, 6, 6, 4); __PYX_ERR(0, 71, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 5: - if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_raster_driver_creation_tuple)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_distance_transform_edt", 1, 6, 6, 5); __PYX_ERR(0, 71, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_distance_transform_edt") < 0)) __PYX_ERR(0, 71, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 6) { - 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); - values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - } - __pyx_v_region_raster_path = values[0]; - __pyx_v_g_raster_path = values[1]; - __pyx_v_sample_d_x = __pyx_PyFloat_AsFloat(values[2]); if (unlikely((__pyx_v_sample_d_x == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 72, __pyx_L3_error) - __pyx_v_sample_d_y = __pyx_PyFloat_AsFloat(values[3]); if (unlikely((__pyx_v_sample_d_y == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 73, __pyx_L3_error) - __pyx_v_target_distance_raster_path = values[4]; - __pyx_v_raster_driver_creation_tuple = values[5]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_distance_transform_edt", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 71, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core._distance_transform_edt", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_15pygeoprocessing_18geoprocessing_core__distance_transform_edt(__pyx_self, __pyx_v_region_raster_path, __pyx_v_g_raster_path, __pyx_v_sample_d_x, __pyx_v_sample_d_y, __pyx_v_target_distance_raster_path, __pyx_v_raster_driver_creation_tuple); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core__distance_transform_edt(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_region_raster_path, PyObject *__pyx_v_g_raster_path, float __pyx_v_sample_d_x, float __pyx_v_sample_d_y, PyObject *__pyx_v_target_distance_raster_path, PyObject *__pyx_v_raster_driver_creation_tuple) { - int __pyx_v_yoff; - int __pyx_v_row_index; - int __pyx_v_block_ysize; - int __pyx_v_win_ysize; - int __pyx_v_n_rows; - int __pyx_v_xoff; - int __pyx_v_block_xsize; - int __pyx_v_win_xsize; - int __pyx_v_n_cols; - int __pyx_v_q_index; - int __pyx_v_local_x_index; - int __pyx_v_local_y_index; - int __pyx_v_u_index; - int __pyx_v_tq; - int __pyx_v_sq; - float __pyx_v_gu; - float __pyx_v_gsq; - float __pyx_v_w; - PyArrayObject *__pyx_v_g_block = 0; - PyArrayObject *__pyx_v_s_array = 0; - PyArrayObject *__pyx_v_t_array = 0; - PyArrayObject *__pyx_v_dt = 0; - PyArrayObject *__pyx_v_mask_block = 0; - PyObject *__pyx_v_mask_raster = NULL; - PyObject *__pyx_v_mask_band = NULL; - PyObject *__pyx_v_raster_info = NULL; - PyObject *__pyx_v_g_raster = NULL; - PyObject *__pyx_v_g_band = NULL; - PyObject *__pyx_v_g_band_blocksize = NULL; - PyObject *__pyx_v_max_sample = NULL; - float __pyx_v_numerical_inf; - int __pyx_v_done; - float __pyx_v_distance_nodata; - PyObject *__pyx_v_target_distance_raster = NULL; - PyObject *__pyx_v_target_distance_band = NULL; - PyObject *__pyx_v_valid_mask = NULL; - __Pyx_LocalBuf_ND __pyx_pybuffernd_dt; - __Pyx_Buffer __pyx_pybuffer_dt; - __Pyx_LocalBuf_ND __pyx_pybuffernd_g_block; - __Pyx_Buffer __pyx_pybuffer_g_block; - __Pyx_LocalBuf_ND __pyx_pybuffernd_mask_block; - __Pyx_Buffer __pyx_pybuffer_mask_block; - __Pyx_LocalBuf_ND __pyx_pybuffernd_s_array; - __Pyx_Buffer __pyx_pybuffer_s_array; - __Pyx_LocalBuf_ND __pyx_pybuffernd_t_array; - __Pyx_Buffer __pyx_pybuffer_t_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; - PyObject *__pyx_t_6 = NULL; - float __pyx_t_7; - float __pyx_t_8; - float __pyx_t_9; - double __pyx_t_10; - double __pyx_t_11; - double __pyx_t_12; - PyArrayObject *__pyx_t_13 = NULL; - PyObject *__pyx_t_14 = NULL; - PyObject *__pyx_t_15 = NULL; - PyObject *__pyx_t_16 = NULL; - PyArrayObject *__pyx_t_17 = NULL; - PyObject *__pyx_t_18 = NULL; - Py_ssize_t __pyx_t_19; - PyObject *(*__pyx_t_20)(PyObject *); - int __pyx_t_21; - int __pyx_t_22; - int __pyx_t_23; - int __pyx_t_24; - int __pyx_t_25; - int __pyx_t_26; - Py_ssize_t __pyx_t_27; - Py_ssize_t __pyx_t_28; - Py_ssize_t __pyx_t_29; - Py_ssize_t __pyx_t_30; - PyArrayObject *__pyx_t_31 = NULL; - PyArrayObject *__pyx_t_32 = NULL; - PyArrayObject *__pyx_t_33 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("_distance_transform_edt", 0); - __pyx_pybuffer_g_block.pybuffer.buf = NULL; - __pyx_pybuffer_g_block.refcount = 0; - __pyx_pybuffernd_g_block.data = NULL; - __pyx_pybuffernd_g_block.rcbuffer = &__pyx_pybuffer_g_block; - __pyx_pybuffer_s_array.pybuffer.buf = NULL; - __pyx_pybuffer_s_array.refcount = 0; - __pyx_pybuffernd_s_array.data = NULL; - __pyx_pybuffernd_s_array.rcbuffer = &__pyx_pybuffer_s_array; - __pyx_pybuffer_t_array.pybuffer.buf = NULL; - __pyx_pybuffer_t_array.refcount = 0; - __pyx_pybuffernd_t_array.data = NULL; - __pyx_pybuffernd_t_array.rcbuffer = &__pyx_pybuffer_t_array; - __pyx_pybuffer_dt.pybuffer.buf = NULL; - __pyx_pybuffer_dt.refcount = 0; - __pyx_pybuffernd_dt.data = NULL; - __pyx_pybuffernd_dt.rcbuffer = &__pyx_pybuffer_dt; - __pyx_pybuffer_mask_block.pybuffer.buf = NULL; - __pyx_pybuffer_mask_block.refcount = 0; - __pyx_pybuffernd_mask_block.data = NULL; - __pyx_pybuffernd_mask_block.rcbuffer = &__pyx_pybuffer_mask_block; - - /* "pygeoprocessing/geoprocessing_core.pyx":126 - * cdef numpy.ndarray[numpy.int8_t, ndim=2] mask_block - * - * mask_raster = gdal.OpenEx(region_raster_path, gdal.OF_RASTER) # <<<<<<<<<<<<<< - * mask_band = mask_raster.GetRasterBand(1) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 126, __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, 126, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 126, __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, 126, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - __pyx_t_5 = 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_5 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_region_raster_path, __pyx_t_4}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 126, __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; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_region_raster_path, __pyx_t_4}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 126, __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; - } else - #endif - { - __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 126, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (__pyx_t_2) { - __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2); __pyx_t_2 = NULL; - } - __Pyx_INCREF(__pyx_v_region_raster_path); - __Pyx_GIVEREF(__pyx_v_region_raster_path); - PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_region_raster_path); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 126, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_mask_raster = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":127 - * - * mask_raster = gdal.OpenEx(region_raster_path, gdal.OF_RASTER) - * mask_band = mask_raster.GetRasterBand(1) # <<<<<<<<<<<<<< - * - * n_cols = mask_raster.RasterXSize - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_mask_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 127, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_6, __pyx_int_1) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_int_1); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 127, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_mask_band = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":129 - * mask_band = mask_raster.GetRasterBand(1) - * - * n_cols = mask_raster.RasterXSize # <<<<<<<<<<<<<< - * n_rows = mask_raster.RasterYSize - * - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_mask_raster, __pyx_n_s_RasterXSize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 129, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 129, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_n_cols = __pyx_t_5; - - /* "pygeoprocessing/geoprocessing_core.pyx":130 - * - * n_cols = mask_raster.RasterXSize - * n_rows = mask_raster.RasterYSize # <<<<<<<<<<<<<< - * - * raster_info = pygeoprocessing.get_raster_info(region_raster_path) - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_mask_raster, __pyx_n_s_RasterYSize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 130, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 130, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_n_rows = __pyx_t_5; - - /* "pygeoprocessing/geoprocessing_core.pyx":132 - * n_rows = mask_raster.RasterYSize - * - * raster_info = pygeoprocessing.get_raster_info(region_raster_path) # <<<<<<<<<<<<<< - * pygeoprocessing.new_raster_from_base( - * region_raster_path, g_raster_path, gdal.GDT_Float32, [_NODATA], - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 132, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 132, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(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); - } - } - __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_3, __pyx_v_region_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_region_raster_path); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 132, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_raster_info = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":133 - * - * raster_info = pygeoprocessing.get_raster_info(region_raster_path) - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * region_raster_path, g_raster_path, gdal.GDT_Float32, [_NODATA], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 133, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 133, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":134 - * raster_info = pygeoprocessing.get_raster_info(region_raster_path) - * pygeoprocessing.new_raster_from_base( - * region_raster_path, g_raster_path, gdal.GDT_Float32, [_NODATA], # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * g_raster = gdal.OpenEx(g_raster_path, gdal.OF_RASTER | gdal.GA_Update) - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 134, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Float32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 134, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_15pygeoprocessing_18geoprocessing_core__NODATA); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 134, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 134, __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; - - /* "pygeoprocessing/geoprocessing_core.pyx":133 - * - * raster_info = pygeoprocessing.get_raster_info(region_raster_path) - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * region_raster_path, g_raster_path, gdal.GDT_Float32, [_NODATA], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - */ - __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 133, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_region_raster_path); - __Pyx_GIVEREF(__pyx_v_region_raster_path); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_region_raster_path); - __Pyx_INCREF(__pyx_v_g_raster_path); - __Pyx_GIVEREF(__pyx_v_g_raster_path); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_g_raster_path); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_4); - __pyx_t_3 = 0; - __pyx_t_4 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":135 - * pygeoprocessing.new_raster_from_base( - * region_raster_path, g_raster_path, gdal.GDT_Float32, [_NODATA], - * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< - * g_raster = gdal.OpenEx(g_raster_path, gdal.OF_RASTER | gdal.GA_Update) - * g_band = g_raster.GetRasterBand(1) - */ - __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 135, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 135, __pyx_L1_error) - - /* "pygeoprocessing/geoprocessing_core.pyx":133 - * - * raster_info = pygeoprocessing.get_raster_info(region_raster_path) - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * region_raster_path, g_raster_path, gdal.GDT_Float32, [_NODATA], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 133, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":136 - * region_raster_path, g_raster_path, gdal.GDT_Float32, [_NODATA], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * g_raster = gdal.OpenEx(g_raster_path, gdal.OF_RASTER | gdal.GA_Update) # <<<<<<<<<<<<<< - * g_band = g_raster.GetRasterBand(1) - * g_band_blocksize = g_band.GetBlockSize() - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 136, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 136, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 136, __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, 136, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 136, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_GA_Update); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 136, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyNumber_Or(__pyx_t_6, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 136, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - __pyx_t_5 = 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_5 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_g_raster_path, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 136, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 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_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_g_raster_path, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 136, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - { - __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 136, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (__pyx_t_2) { - __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2); __pyx_t_2 = NULL; - } - __Pyx_INCREF(__pyx_v_g_raster_path); - __Pyx_GIVEREF(__pyx_v_g_raster_path); - PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_g_raster_path); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 136, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_g_raster = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":137 - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * g_raster = gdal.OpenEx(g_raster_path, gdal.OF_RASTER | gdal.GA_Update) - * g_band = g_raster.GetRasterBand(1) # <<<<<<<<<<<<<< - * g_band_blocksize = g_band.GetBlockSize() - * - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_g_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 137, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_6, __pyx_int_1) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_int_1); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 137, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_g_band = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":138 - * g_raster = gdal.OpenEx(g_raster_path, gdal.OF_RASTER | gdal.GA_Update) - * g_band = g_raster.GetRasterBand(1) - * g_band_blocksize = g_band.GetBlockSize() # <<<<<<<<<<<<<< - * - * # normalize the sample distances so we don't get a strange numerical - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_g_band, __pyx_n_s_GetBlockSize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 138, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 138, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_g_band_blocksize = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":142 - * # normalize the sample distances so we don't get a strange numerical - * # overflow - * max_sample = max(sample_d_x, sample_d_y) # <<<<<<<<<<<<<< - * sample_d_x /= max_sample - * sample_d_y /= max_sample - */ - __pyx_t_7 = __pyx_v_sample_d_y; - __pyx_t_8 = __pyx_v_sample_d_x; - if (((__pyx_t_7 > __pyx_t_8) != 0)) { - __pyx_t_9 = __pyx_t_7; - } else { - __pyx_t_9 = __pyx_t_8; - } - __pyx_t_3 = PyFloat_FromDouble(__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 142, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_max_sample = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":143 - * # overflow - * max_sample = max(sample_d_x, sample_d_y) - * sample_d_x /= max_sample # <<<<<<<<<<<<<< - * sample_d_y /= max_sample - * - */ - __pyx_t_3 = PyFloat_FromDouble(__pyx_v_sample_d_x); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 143, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __Pyx_PyNumber_InPlaceDivide(__pyx_t_3, __pyx_v_max_sample); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 143, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_9 = __pyx_PyFloat_AsFloat(__pyx_t_1); if (unlikely((__pyx_t_9 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 143, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_sample_d_x = __pyx_t_9; - - /* "pygeoprocessing/geoprocessing_core.pyx":144 - * max_sample = max(sample_d_x, sample_d_y) - * sample_d_x /= max_sample - * sample_d_y /= max_sample # <<<<<<<<<<<<<< - * - * # distances can't be larger than half the perimeter of the raster. - */ - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_sample_d_y); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 144, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyNumber_InPlaceDivide(__pyx_t_1, __pyx_v_max_sample); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 144, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_9 = __pyx_PyFloat_AsFloat(__pyx_t_3); if (unlikely((__pyx_t_9 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 144, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_sample_d_y = __pyx_t_9; - - /* "pygeoprocessing/geoprocessing_core.pyx":147 - * - * # distances can't be larger than half the perimeter of the raster. - * cdef float numerical_inf = max(sample_d_x, 1.0) * max(sample_d_y, 1.0) * ( # <<<<<<<<<<<<<< - * raster_info['raster_size'][0] + raster_info['raster_size'][1]) - * # scan 1 - */ - __pyx_t_10 = 1.0; - __pyx_t_9 = __pyx_v_sample_d_x; - if (((__pyx_t_10 > __pyx_t_9) != 0)) { - __pyx_t_11 = __pyx_t_10; - } else { - __pyx_t_11 = __pyx_t_9; - } - __pyx_t_10 = 1.0; - __pyx_t_9 = __pyx_v_sample_d_y; - if (((__pyx_t_10 > __pyx_t_9) != 0)) { - __pyx_t_12 = __pyx_t_10; - } else { - __pyx_t_12 = __pyx_t_9; - } - __pyx_t_3 = PyFloat_FromDouble((__pyx_t_11 * __pyx_t_12)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 147, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pygeoprocessing/geoprocessing_core.pyx":148 - * # distances can't be larger than half the perimeter of the raster. - * cdef float numerical_inf = max(sample_d_x, 1.0) * max(sample_d_y, 1.0) * ( - * raster_info['raster_size'][0] + raster_info['raster_size'][1]) # <<<<<<<<<<<<<< - * # scan 1 - * done = False - */ - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 148, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 148, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 148, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_1, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 148, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Add(__pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 148, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":147 - * - * # distances can't be larger than half the perimeter of the raster. - * cdef float numerical_inf = max(sample_d_x, 1.0) * max(sample_d_y, 1.0) * ( # <<<<<<<<<<<<<< - * raster_info['raster_size'][0] + raster_info['raster_size'][1]) - * # scan 1 - */ - __pyx_t_4 = PyNumber_Multiply(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 147, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_9 = __pyx_PyFloat_AsFloat(__pyx_t_4); if (unlikely((__pyx_t_9 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 147, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_numerical_inf = __pyx_t_9; - - /* "pygeoprocessing/geoprocessing_core.pyx":150 - * raster_info['raster_size'][0] + raster_info['raster_size'][1]) - * # scan 1 - * done = False # <<<<<<<<<<<<<< - * block_xsize = raster_info['block_size'][0] - * mask_block = numpy.empty((n_rows, block_xsize), dtype=numpy.int8) - */ - __pyx_v_done = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":151 - * # scan 1 - * done = False - * block_xsize = raster_info['block_size'][0] # <<<<<<<<<<<<<< - * mask_block = numpy.empty((n_rows, block_xsize), dtype=numpy.int8) - * g_block = numpy.empty((n_rows, block_xsize), dtype=numpy.float32) - */ - __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_block_size); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 151, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_4, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 151, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 151, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_block_xsize = __pyx_t_5; - - /* "pygeoprocessing/geoprocessing_core.pyx":152 - * done = False - * block_xsize = raster_info['block_size'][0] - * mask_block = numpy.empty((n_rows, block_xsize), dtype=numpy.int8) # <<<<<<<<<<<<<< - * g_block = numpy.empty((n_rows, block_xsize), dtype=numpy.float32) - * for xoff in numpy.arange(0, n_cols, block_xsize): - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 152, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 152, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_n_rows); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 152, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_block_xsize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 152, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 152, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_3); - __pyx_t_1 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 152, __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; - __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 152, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 152, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_int8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 152, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 152, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 152, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 152, __pyx_L1_error) - __pyx_t_13 = ((PyArrayObject *)__pyx_t_2); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer); - __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); - if (unlikely(__pyx_t_5 < 0)) { - PyErr_Fetch(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer, (PyObject*)__pyx_v_mask_block, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_16); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_14, __pyx_t_15, __pyx_t_16); - } - __pyx_t_14 = __pyx_t_15 = __pyx_t_16 = 0; - } - __pyx_pybuffernd_mask_block.diminfo[0].strides = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_mask_block.diminfo[0].shape = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_mask_block.diminfo[1].strides = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_mask_block.diminfo[1].shape = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.shape[1]; - if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 152, __pyx_L1_error) - } - __pyx_t_13 = 0; - __pyx_v_mask_block = ((PyArrayObject *)__pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":153 - * block_xsize = raster_info['block_size'][0] - * mask_block = numpy.empty((n_rows, block_xsize), dtype=numpy.int8) - * g_block = numpy.empty((n_rows, block_xsize), dtype=numpy.float32) # <<<<<<<<<<<<<< - * for xoff in numpy.arange(0, n_cols, block_xsize): - * win_xsize = block_xsize - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 153, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 153, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_n_rows); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 153, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_block_xsize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 153, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 153, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); - __pyx_t_2 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 153, __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 = 0; - __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 153, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 153, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 153, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 153, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 153, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 153, __pyx_L1_error) - __pyx_t_17 = ((PyArrayObject *)__pyx_t_1); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer); - __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer, (PyObject*)__pyx_t_17, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack); - if (unlikely(__pyx_t_5 < 0)) { - PyErr_Fetch(&__pyx_t_16, &__pyx_t_15, &__pyx_t_14); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer, (PyObject*)__pyx_v_g_block, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_16); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_14); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_16, __pyx_t_15, __pyx_t_14); - } - __pyx_t_16 = __pyx_t_15 = __pyx_t_14 = 0; - } - __pyx_pybuffernd_g_block.diminfo[0].strides = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_g_block.diminfo[0].shape = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_g_block.diminfo[1].strides = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_g_block.diminfo[1].shape = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.shape[1]; - if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 153, __pyx_L1_error) - } - __pyx_t_17 = 0; - __pyx_v_g_block = ((PyArrayObject *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":154 - * mask_block = numpy.empty((n_rows, block_xsize), dtype=numpy.int8) - * g_block = numpy.empty((n_rows, block_xsize), dtype=numpy.float32) - * for xoff in numpy.arange(0, n_cols, block_xsize): # <<<<<<<<<<<<<< - * win_xsize = block_xsize - * if xoff + win_xsize > n_cols: - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_numpy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 154, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_arange); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 154, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 154, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_block_xsize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 154, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_2 = NULL; - __pyx_t_5 = 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_5 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_int_0, __pyx_t_4, __pyx_t_6}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 154, __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_6); __pyx_t_6 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_int_0, __pyx_t_4, __pyx_t_6}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 154, __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_6); __pyx_t_6 = 0; - } else - #endif - { - __pyx_t_18 = PyTuple_New(3+__pyx_t_5); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 154, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - if (__pyx_t_2) { - __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_2); __pyx_t_2 = NULL; - } - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_18, 0+__pyx_t_5, __pyx_int_0); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_18, 1+__pyx_t_5, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_18, 2+__pyx_t_5, __pyx_t_6); - __pyx_t_4 = 0; - __pyx_t_6 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_18, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 154, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { - __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_19 = 0; - __pyx_t_20 = NULL; - } else { - __pyx_t_19 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 154, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_20 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 154, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - for (;;) { - if (likely(!__pyx_t_20)) { - if (likely(PyList_CheckExact(__pyx_t_3))) { - if (__pyx_t_19 >= PyList_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_19); __Pyx_INCREF(__pyx_t_1); __pyx_t_19++; if (unlikely(0 < 0)) __PYX_ERR(0, 154, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 154, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } else { - if (__pyx_t_19 >= PyTuple_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_19); __Pyx_INCREF(__pyx_t_1); __pyx_t_19++; if (unlikely(0 < 0)) __PYX_ERR(0, 154, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 154, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } - } else { - __pyx_t_1 = __pyx_t_20(__pyx_t_3); - 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, 154, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 154, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_xoff = __pyx_t_5; - - /* "pygeoprocessing/geoprocessing_core.pyx":155 - * g_block = numpy.empty((n_rows, block_xsize), dtype=numpy.float32) - * for xoff in numpy.arange(0, n_cols, block_xsize): - * win_xsize = block_xsize # <<<<<<<<<<<<<< - * if xoff + win_xsize > n_cols: - * win_xsize = n_cols - xoff - */ - __pyx_v_win_xsize = __pyx_v_block_xsize; - - /* "pygeoprocessing/geoprocessing_core.pyx":156 - * for xoff in numpy.arange(0, n_cols, block_xsize): - * win_xsize = block_xsize - * if xoff + win_xsize > n_cols: # <<<<<<<<<<<<<< - * win_xsize = n_cols - xoff - * mask_block = numpy.empty((n_rows, win_xsize), dtype=numpy.int8) - */ - __pyx_t_21 = (((__pyx_v_xoff + __pyx_v_win_xsize) > __pyx_v_n_cols) != 0); - if (__pyx_t_21) { - - /* "pygeoprocessing/geoprocessing_core.pyx":157 - * win_xsize = block_xsize - * if xoff + win_xsize > n_cols: - * win_xsize = n_cols - xoff # <<<<<<<<<<<<<< - * mask_block = numpy.empty((n_rows, win_xsize), dtype=numpy.int8) - * g_block = numpy.empty((n_rows, win_xsize), dtype=numpy.float32) - */ - __pyx_v_win_xsize = (__pyx_v_n_cols - __pyx_v_xoff); - - /* "pygeoprocessing/geoprocessing_core.pyx":158 - * if xoff + win_xsize > n_cols: - * win_xsize = n_cols - xoff - * mask_block = numpy.empty((n_rows, win_xsize), dtype=numpy.int8) # <<<<<<<<<<<<<< - * g_block = numpy.empty((n_rows, win_xsize), dtype=numpy.float32) - * done = True - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 158, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_18 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 158, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_n_rows); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 158, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 158, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 158, __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_6); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_6); - __pyx_t_1 = 0; - __pyx_t_6 = 0; - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 158, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 158, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 158, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_int8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 158, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 158, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_18, __pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 158, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 158, __pyx_L1_error) - __pyx_t_13 = ((PyArrayObject *)__pyx_t_2); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer); - __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); - if (unlikely(__pyx_t_5 < 0)) { - PyErr_Fetch(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer, (PyObject*)__pyx_v_mask_block, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_16); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_14, __pyx_t_15, __pyx_t_16); - } - __pyx_t_14 = __pyx_t_15 = __pyx_t_16 = 0; - } - __pyx_pybuffernd_mask_block.diminfo[0].strides = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_mask_block.diminfo[0].shape = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_mask_block.diminfo[1].strides = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_mask_block.diminfo[1].shape = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.shape[1]; - if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 158, __pyx_L1_error) - } - __pyx_t_13 = 0; - __Pyx_DECREF_SET(__pyx_v_mask_block, ((PyArrayObject *)__pyx_t_2)); - __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":159 - * win_xsize = n_cols - xoff - * mask_block = numpy.empty((n_rows, win_xsize), dtype=numpy.int8) - * g_block = numpy.empty((n_rows, win_xsize), dtype=numpy.float32) # <<<<<<<<<<<<<< - * done = True - * mask_band.ReadAsArray( - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 159, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 159, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_n_rows); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 159, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 159, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_18 = PyTuple_New(2); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 159, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_18, 1, __pyx_t_6); - __pyx_t_2 = 0; - __pyx_t_6 = 0; - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 159, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_18); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_18); - __pyx_t_18 = 0; - __pyx_t_18 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 159, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 159, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 159, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_t_18, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 159, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, __pyx_t_18); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 159, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 159, __pyx_L1_error) - __pyx_t_17 = ((PyArrayObject *)__pyx_t_1); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer); - __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer, (PyObject*)__pyx_t_17, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack); - if (unlikely(__pyx_t_5 < 0)) { - PyErr_Fetch(&__pyx_t_16, &__pyx_t_15, &__pyx_t_14); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer, (PyObject*)__pyx_v_g_block, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_16); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_14); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_16, __pyx_t_15, __pyx_t_14); - } - __pyx_t_16 = __pyx_t_15 = __pyx_t_14 = 0; - } - __pyx_pybuffernd_g_block.diminfo[0].strides = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_g_block.diminfo[0].shape = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_g_block.diminfo[1].strides = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_g_block.diminfo[1].shape = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.shape[1]; - if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 159, __pyx_L1_error) - } - __pyx_t_17 = 0; - __Pyx_DECREF_SET(__pyx_v_g_block, ((PyArrayObject *)__pyx_t_1)); - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":160 - * mask_block = numpy.empty((n_rows, win_xsize), dtype=numpy.int8) - * g_block = numpy.empty((n_rows, win_xsize), dtype=numpy.float32) - * done = True # <<<<<<<<<<<<<< - * mask_band.ReadAsArray( - * xoff=xoff, yoff=0, win_xsize=win_xsize, win_ysize=n_rows, - */ - __pyx_v_done = 1; - - /* "pygeoprocessing/geoprocessing_core.pyx":156 - * for xoff in numpy.arange(0, n_cols, block_xsize): - * win_xsize = block_xsize - * if xoff + win_xsize > n_cols: # <<<<<<<<<<<<<< - * win_xsize = n_cols - xoff - * mask_block = numpy.empty((n_rows, win_xsize), dtype=numpy.int8) - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":161 - * g_block = numpy.empty((n_rows, win_xsize), dtype=numpy.float32) - * done = True - * mask_band.ReadAsArray( # <<<<<<<<<<<<<< - * xoff=xoff, yoff=0, win_xsize=win_xsize, win_ysize=n_rows, - * buf_obj=mask_block) - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_mask_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 161, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/geoprocessing_core.pyx":162 - * done = True - * mask_band.ReadAsArray( - * xoff=xoff, yoff=0, win_xsize=win_xsize, win_ysize=n_rows, # <<<<<<<<<<<<<< - * buf_obj=mask_block) - * # base case - */ - __pyx_t_18 = __Pyx_PyDict_NewPresized(5); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 162, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_xoff); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 162, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_18, __pyx_n_s_xoff, __pyx_t_6) < 0) __PYX_ERR(0, 162, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (PyDict_SetItem(__pyx_t_18, __pyx_n_s_yoff, __pyx_int_0) < 0) __PYX_ERR(0, 162, __pyx_L1_error) - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 162, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_18, __pyx_n_s_win_xsize, __pyx_t_6) < 0) __PYX_ERR(0, 162, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_n_rows); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 162, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_18, __pyx_n_s_win_ysize, __pyx_t_6) < 0) __PYX_ERR(0, 162, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":163 - * mask_band.ReadAsArray( - * xoff=xoff, yoff=0, win_xsize=win_xsize, win_ysize=n_rows, - * buf_obj=mask_block) # <<<<<<<<<<<<<< - * # base case - * g_block[0, :] = (mask_block[0, :] == 0) * numerical_inf - */ - if (PyDict_SetItem(__pyx_t_18, __pyx_n_s_buf_obj, ((PyObject *)__pyx_v_mask_block)) < 0) __PYX_ERR(0, 162, __pyx_L1_error) - - /* "pygeoprocessing/geoprocessing_core.pyx":161 - * g_block = numpy.empty((n_rows, win_xsize), dtype=numpy.float32) - * done = True - * mask_band.ReadAsArray( # <<<<<<<<<<<<<< - * xoff=xoff, yoff=0, win_xsize=win_xsize, win_ysize=n_rows, - * buf_obj=mask_block) - */ - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_18); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 161, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":165 - * buf_obj=mask_block) - * # base case - * g_block[0, :] = (mask_block[0, :] == 0) * numerical_inf # <<<<<<<<<<<<<< - * for row_index in range(1, n_rows): - * for local_x_index in range(win_xsize): - */ - __pyx_t_6 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_mask_block), __pyx_tuple__2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 165, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_18 = __Pyx_PyInt_EqObjC(__pyx_t_6, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 165, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = PyFloat_FromDouble(__pyx_v_numerical_inf); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 165, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_1 = PyNumber_Multiply(__pyx_t_18, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 165, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_g_block), __pyx_tuple__2, __pyx_t_1) < 0)) __PYX_ERR(0, 165, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":166 - * # base case - * g_block[0, :] = (mask_block[0, :] == 0) * numerical_inf - * for row_index in range(1, n_rows): # <<<<<<<<<<<<<< - * for local_x_index in range(win_xsize): - * if mask_block[row_index, local_x_index] == 1: - */ - __pyx_t_5 = __pyx_v_n_rows; - __pyx_t_22 = __pyx_t_5; - for (__pyx_t_23 = 1; __pyx_t_23 < __pyx_t_22; __pyx_t_23+=1) { - __pyx_v_row_index = __pyx_t_23; - - /* "pygeoprocessing/geoprocessing_core.pyx":167 - * g_block[0, :] = (mask_block[0, :] == 0) * numerical_inf - * for row_index in range(1, n_rows): - * for local_x_index in range(win_xsize): # <<<<<<<<<<<<<< - * if mask_block[row_index, local_x_index] == 1: - * g_block[row_index, local_x_index] = 0 - */ - __pyx_t_24 = __pyx_v_win_xsize; - __pyx_t_25 = __pyx_t_24; - for (__pyx_t_26 = 0; __pyx_t_26 < __pyx_t_25; __pyx_t_26+=1) { - __pyx_v_local_x_index = __pyx_t_26; - - /* "pygeoprocessing/geoprocessing_core.pyx":168 - * for row_index in range(1, n_rows): - * for local_x_index in range(win_xsize): - * if mask_block[row_index, local_x_index] == 1: # <<<<<<<<<<<<<< - * g_block[row_index, local_x_index] = 0 - * else: - */ - __pyx_t_27 = __pyx_v_row_index; - __pyx_t_28 = __pyx_v_local_x_index; - __pyx_t_21 = (((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int8_t *, __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_mask_block.diminfo[0].strides, __pyx_t_28, __pyx_pybuffernd_mask_block.diminfo[1].strides)) == 1) != 0); - if (__pyx_t_21) { - - /* "pygeoprocessing/geoprocessing_core.pyx":169 - * for local_x_index in range(win_xsize): - * if mask_block[row_index, local_x_index] == 1: - * g_block[row_index, local_x_index] = 0 # <<<<<<<<<<<<<< - * else: - * g_block[row_index, local_x_index] = ( - */ - __pyx_t_28 = __pyx_v_row_index; - __pyx_t_27 = __pyx_v_local_x_index; - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_28, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_27, __pyx_pybuffernd_g_block.diminfo[1].strides) = 0.0; - - /* "pygeoprocessing/geoprocessing_core.pyx":168 - * for row_index in range(1, n_rows): - * for local_x_index in range(win_xsize): - * if mask_block[row_index, local_x_index] == 1: # <<<<<<<<<<<<<< - * g_block[row_index, local_x_index] = 0 - * else: - */ - goto __pyx_L10; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":172 - * else: - * g_block[row_index, local_x_index] = ( - * g_block[row_index-1, local_x_index] + sample_d_y) # <<<<<<<<<<<<<< - * for row_index in range(n_rows-2, -1, -1): - * for local_x_index in range(win_xsize): - */ - /*else*/ { - __pyx_t_27 = (__pyx_v_row_index - 1); - __pyx_t_28 = __pyx_v_local_x_index; - - /* "pygeoprocessing/geoprocessing_core.pyx":171 - * g_block[row_index, local_x_index] = 0 - * else: - * g_block[row_index, local_x_index] = ( # <<<<<<<<<<<<<< - * g_block[row_index-1, local_x_index] + sample_d_y) - * for row_index in range(n_rows-2, -1, -1): - */ - __pyx_t_29 = __pyx_v_row_index; - __pyx_t_30 = __pyx_v_local_x_index; - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_g_block.diminfo[1].strides) = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_28, __pyx_pybuffernd_g_block.diminfo[1].strides)) + __pyx_v_sample_d_y); - } - __pyx_L10:; - } - } - - /* "pygeoprocessing/geoprocessing_core.pyx":173 - * g_block[row_index, local_x_index] = ( - * g_block[row_index-1, local_x_index] + sample_d_y) - * for row_index in range(n_rows-2, -1, -1): # <<<<<<<<<<<<<< - * for local_x_index in range(win_xsize): - * if (g_block[row_index+1, local_x_index] < - */ - for (__pyx_t_5 = (__pyx_v_n_rows - 2); __pyx_t_5 > -1; __pyx_t_5-=1) { - __pyx_v_row_index = __pyx_t_5; - - /* "pygeoprocessing/geoprocessing_core.pyx":174 - * g_block[row_index-1, local_x_index] + sample_d_y) - * for row_index in range(n_rows-2, -1, -1): - * for local_x_index in range(win_xsize): # <<<<<<<<<<<<<< - * if (g_block[row_index+1, local_x_index] < - * g_block[row_index, local_x_index]): - */ - __pyx_t_22 = __pyx_v_win_xsize; - __pyx_t_23 = __pyx_t_22; - for (__pyx_t_24 = 0; __pyx_t_24 < __pyx_t_23; __pyx_t_24+=1) { - __pyx_v_local_x_index = __pyx_t_24; - - /* "pygeoprocessing/geoprocessing_core.pyx":175 - * for row_index in range(n_rows-2, -1, -1): - * for local_x_index in range(win_xsize): - * if (g_block[row_index+1, local_x_index] < # <<<<<<<<<<<<<< - * g_block[row_index, local_x_index]): - * g_block[row_index, local_x_index] = ( - */ - __pyx_t_28 = (__pyx_v_row_index + 1); - __pyx_t_27 = __pyx_v_local_x_index; - - /* "pygeoprocessing/geoprocessing_core.pyx":176 - * for local_x_index in range(win_xsize): - * if (g_block[row_index+1, local_x_index] < - * g_block[row_index, local_x_index]): # <<<<<<<<<<<<<< - * g_block[row_index, local_x_index] = ( - * sample_d_y + g_block[row_index+1, local_x_index]) - */ - __pyx_t_30 = __pyx_v_row_index; - __pyx_t_29 = __pyx_v_local_x_index; - - /* "pygeoprocessing/geoprocessing_core.pyx":175 - * for row_index in range(n_rows-2, -1, -1): - * for local_x_index in range(win_xsize): - * if (g_block[row_index+1, local_x_index] < # <<<<<<<<<<<<<< - * g_block[row_index, local_x_index]): - * g_block[row_index, local_x_index] = ( - */ - __pyx_t_21 = (((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_28, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_27, __pyx_pybuffernd_g_block.diminfo[1].strides)) < (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_g_block.diminfo[1].strides))) != 0); - if (__pyx_t_21) { - - /* "pygeoprocessing/geoprocessing_core.pyx":178 - * g_block[row_index, local_x_index]): - * g_block[row_index, local_x_index] = ( - * sample_d_y + g_block[row_index+1, local_x_index]) # <<<<<<<<<<<<<< - * g_band.WriteArray(g_block, xoff=xoff, yoff=0) - * if done: - */ - __pyx_t_29 = (__pyx_v_row_index + 1); - __pyx_t_30 = __pyx_v_local_x_index; - - /* "pygeoprocessing/geoprocessing_core.pyx":177 - * if (g_block[row_index+1, local_x_index] < - * g_block[row_index, local_x_index]): - * g_block[row_index, local_x_index] = ( # <<<<<<<<<<<<<< - * sample_d_y + g_block[row_index+1, local_x_index]) - * g_band.WriteArray(g_block, xoff=xoff, yoff=0) - */ - __pyx_t_27 = __pyx_v_row_index; - __pyx_t_28 = __pyx_v_local_x_index; - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_28, __pyx_pybuffernd_g_block.diminfo[1].strides) = (__pyx_v_sample_d_y + (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_g_block.diminfo[1].strides))); - - /* "pygeoprocessing/geoprocessing_core.pyx":175 - * for row_index in range(n_rows-2, -1, -1): - * for local_x_index in range(win_xsize): - * if (g_block[row_index+1, local_x_index] < # <<<<<<<<<<<<<< - * g_block[row_index, local_x_index]): - * g_block[row_index, local_x_index] = ( - */ - } - } - } - - /* "pygeoprocessing/geoprocessing_core.pyx":179 - * g_block[row_index, local_x_index] = ( - * sample_d_y + g_block[row_index+1, local_x_index]) - * g_band.WriteArray(g_block, xoff=xoff, yoff=0) # <<<<<<<<<<<<<< - * if done: - * break - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_g_band, __pyx_n_s_WriteArray); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 179, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 179, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_INCREF(((PyObject *)__pyx_v_g_block)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_g_block)); - PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_g_block)); - __pyx_t_18 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 179, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_xoff); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 179, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (PyDict_SetItem(__pyx_t_18, __pyx_n_s_xoff, __pyx_t_4) < 0) __PYX_ERR(0, 179, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (PyDict_SetItem(__pyx_t_18, __pyx_n_s_yoff, __pyx_int_0) < 0) __PYX_ERR(0, 179, __pyx_L1_error) - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, __pyx_t_18); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 179, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":180 - * sample_d_y + g_block[row_index+1, local_x_index]) - * g_band.WriteArray(g_block, xoff=xoff, yoff=0) - * if done: # <<<<<<<<<<<<<< - * break - * g_band.FlushCache() - */ - __pyx_t_21 = (__pyx_v_done != 0); - if (__pyx_t_21) { - - /* "pygeoprocessing/geoprocessing_core.pyx":181 - * g_band.WriteArray(g_block, xoff=xoff, yoff=0) - * if done: - * break # <<<<<<<<<<<<<< - * g_band.FlushCache() - * - */ - goto __pyx_L4_break; - - /* "pygeoprocessing/geoprocessing_core.pyx":180 - * sample_d_y + g_block[row_index+1, local_x_index]) - * g_band.WriteArray(g_block, xoff=xoff, yoff=0) - * if done: # <<<<<<<<<<<<<< - * break - * g_band.FlushCache() - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":154 - * mask_block = numpy.empty((n_rows, block_xsize), dtype=numpy.int8) - * g_block = numpy.empty((n_rows, block_xsize), dtype=numpy.float32) - * for xoff in numpy.arange(0, n_cols, block_xsize): # <<<<<<<<<<<<<< - * win_xsize = block_xsize - * if xoff + win_xsize > n_cols: - */ - } - __pyx_L4_break:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":182 - * if done: - * break - * g_band.FlushCache() # <<<<<<<<<<<<<< - * - * cdef float distance_nodata = -1.0 - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_g_band, __pyx_n_s_FlushCache); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 182, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_18 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_18 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_18)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_18); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - __pyx_t_3 = (__pyx_t_18) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_18) : __Pyx_PyObject_CallNoArg(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 182, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":184 - * g_band.FlushCache() - * - * cdef float distance_nodata = -1.0 # <<<<<<<<<<<<<< - * - * pygeoprocessing.new_raster_from_base( - */ - __pyx_v_distance_nodata = -1.0; - - /* "pygeoprocessing/geoprocessing_core.pyx":186 - * cdef float distance_nodata = -1.0 - * - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * region_raster_path, target_distance_raster_path.encode('utf-8'), - * gdal.GDT_Float32, [distance_nodata], - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":187 - * - * pygeoprocessing.new_raster_from_base( - * region_raster_path, target_distance_raster_path.encode('utf-8'), # <<<<<<<<<<<<<< - * gdal.GDT_Float32, [distance_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - */ - __pyx_t_18 = __Pyx_PyObject_GetAttrStr(__pyx_v_target_distance_raster_path, __pyx_n_s_encode); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 187, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_18))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_18); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_18); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_18, function); - } - } - __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_18, __pyx_t_6, __pyx_kp_u_utf_8) : __Pyx_PyObject_CallOneArg(__pyx_t_18, __pyx_kp_u_utf_8); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 187, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":188 - * pygeoprocessing.new_raster_from_base( - * region_raster_path, target_distance_raster_path.encode('utf-8'), - * gdal.GDT_Float32, [distance_nodata], # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * target_distance_raster = gdal.OpenEx( - */ - __Pyx_GetModuleGlobalName(__pyx_t_18, __pyx_n_s_gdal); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 188, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_18, __pyx_n_s_GDT_Float32); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 188, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __pyx_t_18 = PyFloat_FromDouble(__pyx_v_distance_nodata); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 188, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 188, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_18); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_18); - __pyx_t_18 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":186 - * cdef float distance_nodata = -1.0 - * - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * region_raster_path, target_distance_raster_path.encode('utf-8'), - * gdal.GDT_Float32, [distance_nodata], - */ - __pyx_t_18 = PyTuple_New(4); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_INCREF(__pyx_v_region_raster_path); - __Pyx_GIVEREF(__pyx_v_region_raster_path); - PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_v_region_raster_path); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_18, 1, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_18, 2, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_18, 3, __pyx_t_1); - __pyx_t_3 = 0; - __pyx_t_6 = 0; - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":189 - * region_raster_path, target_distance_raster_path.encode('utf-8'), - * gdal.GDT_Float32, [distance_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< - * target_distance_raster = gdal.OpenEx( - * target_distance_raster_path, gdal.OF_RASTER | gdal.GA_Update) - */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 189, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 189, __pyx_L1_error) - - /* "pygeoprocessing/geoprocessing_core.pyx":186 - * cdef float distance_nodata = -1.0 - * - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * region_raster_path, target_distance_raster_path.encode('utf-8'), - * gdal.GDT_Float32, [distance_nodata], - */ - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_18, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":190 - * gdal.GDT_Float32, [distance_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * target_distance_raster = gdal.OpenEx( # <<<<<<<<<<<<<< - * target_distance_raster_path, gdal.OF_RASTER | gdal.GA_Update) - * target_distance_band = target_distance_raster.GetRasterBand(1) - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 190, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_18 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 190, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":191 - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * target_distance_raster = gdal.OpenEx( - * target_distance_raster_path, gdal.OF_RASTER | gdal.GA_Update) # <<<<<<<<<<<<<< - * target_distance_band = target_distance_raster.GetRasterBand(1) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 191, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 191, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 191, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GA_Update); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 191, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Or(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 191, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - __pyx_t_5 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_18))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_18); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_18); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_18, function); - __pyx_t_5 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_18)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_target_distance_raster_path, __pyx_t_1}; - __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_18, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 190, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_18)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_target_distance_raster_path, __pyx_t_1}; - __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_18, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 190, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - { - __pyx_t_4 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 190, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_INCREF(__pyx_v_target_distance_raster_path); - __Pyx_GIVEREF(__pyx_v_target_distance_raster_path); - PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_5, __pyx_v_target_distance_raster_path); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_5, __pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_18, __pyx_t_4, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 190, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __pyx_v_target_distance_raster = __pyx_t_6; - __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":192 - * target_distance_raster = gdal.OpenEx( - * target_distance_raster_path, gdal.OF_RASTER | gdal.GA_Update) - * target_distance_band = target_distance_raster.GetRasterBand(1) # <<<<<<<<<<<<<< - * - * LOGGER.info('Distance Transform Phase 2') - */ - __pyx_t_18 = __Pyx_PyObject_GetAttrStr(__pyx_v_target_distance_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 192, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_18))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_18); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_18); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_18, function); - } - } - __pyx_t_6 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_18, __pyx_t_4, __pyx_int_1) : __Pyx_PyObject_CallOneArg(__pyx_t_18, __pyx_int_1); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 192, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __pyx_v_target_distance_band = __pyx_t_6; - __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":194 - * target_distance_band = target_distance_raster.GetRasterBand(1) - * - * LOGGER.info('Distance Transform Phase 2') # <<<<<<<<<<<<<< - * s_array = numpy.empty(n_cols, dtype=numpy.int32) - * t_array = numpy.empty(n_cols, dtype=numpy.int32) - */ - __Pyx_GetModuleGlobalName(__pyx_t_18, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 194, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_18, __pyx_n_s_info); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 194, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __pyx_t_18 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_18 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_18)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_18); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - __pyx_t_6 = (__pyx_t_18) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_18, __pyx_kp_u_Distance_Transform_Phase_2) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_Distance_Transform_Phase_2); - __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 194, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":195 - * - * LOGGER.info('Distance Transform Phase 2') - * s_array = numpy.empty(n_cols, dtype=numpy.int32) # <<<<<<<<<<<<<< - * t_array = numpy.empty(n_cols, dtype=numpy.int32) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_numpy); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 195, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 195, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 195, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_18 = PyTuple_New(1); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 195, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_6); - __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 195, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 195, __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, 195, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 195, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_18, __pyx_t_6); 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_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 195, __pyx_L1_error) - __pyx_t_31 = ((PyArrayObject *)__pyx_t_3); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_s_array.rcbuffer->pybuffer); - __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_s_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_31, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack); - if (unlikely(__pyx_t_5 < 0)) { - PyErr_Fetch(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_s_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_s_array, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_16); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_14, __pyx_t_15, __pyx_t_16); - } - __pyx_t_14 = __pyx_t_15 = __pyx_t_16 = 0; - } - __pyx_pybuffernd_s_array.diminfo[0].strides = __pyx_pybuffernd_s_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_s_array.diminfo[0].shape = __pyx_pybuffernd_s_array.rcbuffer->pybuffer.shape[0]; - if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 195, __pyx_L1_error) - } - __pyx_t_31 = 0; - __pyx_v_s_array = ((PyArrayObject *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":196 - * LOGGER.info('Distance Transform Phase 2') - * s_array = numpy.empty(n_cols, dtype=numpy.int32) - * t_array = numpy.empty(n_cols, dtype=numpy.int32) # <<<<<<<<<<<<<< - * - * done = False - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 196, __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, 196, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 196, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_18 = PyTuple_New(1); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 196, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 196, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_numpy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 196, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 196, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 196, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_18, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 196, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 196, __pyx_L1_error) - __pyx_t_32 = ((PyArrayObject *)__pyx_t_1); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t_array.rcbuffer->pybuffer); - __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_t_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_32, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack); - if (unlikely(__pyx_t_5 < 0)) { - PyErr_Fetch(&__pyx_t_16, &__pyx_t_15, &__pyx_t_14); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_t_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_t_array, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_16); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_14); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_16, __pyx_t_15, __pyx_t_14); - } - __pyx_t_16 = __pyx_t_15 = __pyx_t_14 = 0; - } - __pyx_pybuffernd_t_array.diminfo[0].strides = __pyx_pybuffernd_t_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_t_array.diminfo[0].shape = __pyx_pybuffernd_t_array.rcbuffer->pybuffer.shape[0]; - if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 196, __pyx_L1_error) - } - __pyx_t_32 = 0; - __pyx_v_t_array = ((PyArrayObject *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":198 - * t_array = numpy.empty(n_cols, dtype=numpy.int32) - * - * done = False # <<<<<<<<<<<<<< - * block_ysize = g_band_blocksize[1] - * g_block = numpy.empty((block_ysize, n_cols), dtype=numpy.float32) - */ - __pyx_v_done = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":199 - * - * done = False - * block_ysize = g_band_blocksize[1] # <<<<<<<<<<<<<< - * g_block = numpy.empty((block_ysize, n_cols), dtype=numpy.float32) - * dt = numpy.empty((block_ysize, n_cols), dtype=numpy.float32) - */ - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_g_band_blocksize, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 199, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 199, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_block_ysize = __pyx_t_5; - - /* "pygeoprocessing/geoprocessing_core.pyx":200 - * done = False - * block_ysize = g_band_blocksize[1] - * g_block = numpy.empty((block_ysize, n_cols), dtype=numpy.float32) # <<<<<<<<<<<<<< - * dt = numpy.empty((block_ysize, n_cols), dtype=numpy.float32) - * mask_block = numpy.empty((block_ysize, n_cols), dtype=numpy.int8) - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 200, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 200, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_block_ysize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 200, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_18 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 200, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 200, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_18); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_18); - __pyx_t_1 = 0; - __pyx_t_18 = 0; - __pyx_t_18 = PyTuple_New(1); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 200, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_6); - __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 200, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 200, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 200, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 200, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_18, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 200, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 200, __pyx_L1_error) - __pyx_t_17 = ((PyArrayObject *)__pyx_t_4); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer); - __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer, (PyObject*)__pyx_t_17, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack); - if (unlikely(__pyx_t_5 < 0)) { - PyErr_Fetch(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer, (PyObject*)__pyx_v_g_block, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_16); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_14, __pyx_t_15, __pyx_t_16); - } - __pyx_t_14 = __pyx_t_15 = __pyx_t_16 = 0; - } - __pyx_pybuffernd_g_block.diminfo[0].strides = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_g_block.diminfo[0].shape = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_g_block.diminfo[1].strides = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_g_block.diminfo[1].shape = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.shape[1]; - if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 200, __pyx_L1_error) - } - __pyx_t_17 = 0; - __Pyx_DECREF_SET(__pyx_v_g_block, ((PyArrayObject *)__pyx_t_4)); - __pyx_t_4 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":201 - * block_ysize = g_band_blocksize[1] - * g_block = numpy.empty((block_ysize, n_cols), dtype=numpy.float32) - * dt = numpy.empty((block_ysize, n_cols), dtype=numpy.float32) # <<<<<<<<<<<<<< - * mask_block = numpy.empty((block_ysize, n_cols), dtype=numpy.int8) - * sq = 0 # initialize so compiler doesn't complain - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_numpy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 201, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 201, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_block_ysize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 201, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_18 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 201, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 201, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_18); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_18); - __pyx_t_4 = 0; - __pyx_t_18 = 0; - __pyx_t_18 = PyTuple_New(1); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 201, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 201, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_numpy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 201, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 201, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 201, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_18, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 201, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 201, __pyx_L1_error) - __pyx_t_33 = ((PyArrayObject *)__pyx_t_1); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dt.rcbuffer->pybuffer); - __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dt.rcbuffer->pybuffer, (PyObject*)__pyx_t_33, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack); - if (unlikely(__pyx_t_5 < 0)) { - PyErr_Fetch(&__pyx_t_16, &__pyx_t_15, &__pyx_t_14); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dt.rcbuffer->pybuffer, (PyObject*)__pyx_v_dt, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_16); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_14); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_16, __pyx_t_15, __pyx_t_14); - } - __pyx_t_16 = __pyx_t_15 = __pyx_t_14 = 0; - } - __pyx_pybuffernd_dt.diminfo[0].strides = __pyx_pybuffernd_dt.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_dt.diminfo[0].shape = __pyx_pybuffernd_dt.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_dt.diminfo[1].strides = __pyx_pybuffernd_dt.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_dt.diminfo[1].shape = __pyx_pybuffernd_dt.rcbuffer->pybuffer.shape[1]; - if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 201, __pyx_L1_error) - } - __pyx_t_33 = 0; - __pyx_v_dt = ((PyArrayObject *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":202 - * g_block = numpy.empty((block_ysize, n_cols), dtype=numpy.float32) - * dt = numpy.empty((block_ysize, n_cols), dtype=numpy.float32) - * mask_block = numpy.empty((block_ysize, n_cols), dtype=numpy.int8) # <<<<<<<<<<<<<< - * sq = 0 # initialize so compiler doesn't complain - * gsq = 0 - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 202, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 202, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_block_ysize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 202, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_18 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 202, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 202, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_18); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_18); - __pyx_t_1 = 0; - __pyx_t_18 = 0; - __pyx_t_18 = PyTuple_New(1); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 202, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_6); - __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 202, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 202, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_int8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 202, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 202, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_18, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 202, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 202, __pyx_L1_error) - __pyx_t_13 = ((PyArrayObject *)__pyx_t_4); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer); - __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); - if (unlikely(__pyx_t_5 < 0)) { - PyErr_Fetch(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer, (PyObject*)__pyx_v_mask_block, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_16); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_14, __pyx_t_15, __pyx_t_16); - } - __pyx_t_14 = __pyx_t_15 = __pyx_t_16 = 0; - } - __pyx_pybuffernd_mask_block.diminfo[0].strides = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_mask_block.diminfo[0].shape = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_mask_block.diminfo[1].strides = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_mask_block.diminfo[1].shape = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.shape[1]; - if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 202, __pyx_L1_error) - } - __pyx_t_13 = 0; - __Pyx_DECREF_SET(__pyx_v_mask_block, ((PyArrayObject *)__pyx_t_4)); - __pyx_t_4 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":203 - * dt = numpy.empty((block_ysize, n_cols), dtype=numpy.float32) - * mask_block = numpy.empty((block_ysize, n_cols), dtype=numpy.int8) - * sq = 0 # initialize so compiler doesn't complain # <<<<<<<<<<<<<< - * gsq = 0 - * for yoff in numpy.arange(0, n_rows, block_ysize): - */ - __pyx_v_sq = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":204 - * mask_block = numpy.empty((block_ysize, n_cols), dtype=numpy.int8) - * sq = 0 # initialize so compiler doesn't complain - * gsq = 0 # <<<<<<<<<<<<<< - * for yoff in numpy.arange(0, n_rows, block_ysize): - * win_ysize = block_ysize - */ - __pyx_v_gsq = 0.0; - - /* "pygeoprocessing/geoprocessing_core.pyx":205 - * sq = 0 # initialize so compiler doesn't complain - * gsq = 0 - * for yoff in numpy.arange(0, n_rows, block_ysize): # <<<<<<<<<<<<<< - * win_ysize = block_ysize - * if yoff + win_ysize >= n_rows: - */ - __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_numpy); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 205, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_18 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_arange); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 205, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_n_rows); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 205, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_block_ysize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 205, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = NULL; - __pyx_t_5 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_18))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_18); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_18); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_18, function); - __pyx_t_5 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_18)) { - PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_int_0, __pyx_t_6, __pyx_t_3}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_18, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 205, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_18)) { - PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_int_0, __pyx_t_6, __pyx_t_3}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_18, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 205, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - { - __pyx_t_2 = PyTuple_New(3+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 205, __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_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_5, __pyx_int_0); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_5, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_2, 2+__pyx_t_5, __pyx_t_3); - __pyx_t_6 = 0; - __pyx_t_3 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_18, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 205, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) { - __pyx_t_18 = __pyx_t_4; __Pyx_INCREF(__pyx_t_18); __pyx_t_19 = 0; - __pyx_t_20 = NULL; - } else { - __pyx_t_19 = -1; __pyx_t_18 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 205, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __pyx_t_20 = Py_TYPE(__pyx_t_18)->tp_iternext; if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 205, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - for (;;) { - if (likely(!__pyx_t_20)) { - if (likely(PyList_CheckExact(__pyx_t_18))) { - if (__pyx_t_19 >= PyList_GET_SIZE(__pyx_t_18)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_18, __pyx_t_19); __Pyx_INCREF(__pyx_t_4); __pyx_t_19++; if (unlikely(0 < 0)) __PYX_ERR(0, 205, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_18, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 205, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } else { - if (__pyx_t_19 >= PyTuple_GET_SIZE(__pyx_t_18)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_18, __pyx_t_19); __Pyx_INCREF(__pyx_t_4); __pyx_t_19++; if (unlikely(0 < 0)) __PYX_ERR(0, 205, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_18, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 205, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } - } else { - __pyx_t_4 = __pyx_t_20(__pyx_t_18); - 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, 205, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 205, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_yoff = __pyx_t_5; - - /* "pygeoprocessing/geoprocessing_core.pyx":206 - * gsq = 0 - * for yoff in numpy.arange(0, n_rows, block_ysize): - * win_ysize = block_ysize # <<<<<<<<<<<<<< - * if yoff + win_ysize >= n_rows: - * win_ysize = n_rows - yoff - */ - __pyx_v_win_ysize = __pyx_v_block_ysize; - - /* "pygeoprocessing/geoprocessing_core.pyx":207 - * for yoff in numpy.arange(0, n_rows, block_ysize): - * win_ysize = block_ysize - * if yoff + win_ysize >= n_rows: # <<<<<<<<<<<<<< - * win_ysize = n_rows - yoff - * g_block = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) - */ - __pyx_t_21 = (((__pyx_v_yoff + __pyx_v_win_ysize) >= __pyx_v_n_rows) != 0); - if (__pyx_t_21) { - - /* "pygeoprocessing/geoprocessing_core.pyx":208 - * win_ysize = block_ysize - * if yoff + win_ysize >= n_rows: - * win_ysize = n_rows - yoff # <<<<<<<<<<<<<< - * g_block = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) - * mask_block = numpy.empty((win_ysize, n_cols), dtype=numpy.int8) - */ - __pyx_v_win_ysize = (__pyx_v_n_rows - __pyx_v_yoff); - - /* "pygeoprocessing/geoprocessing_core.pyx":209 - * if yoff + win_ysize >= n_rows: - * win_ysize = n_rows - yoff - * g_block = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) # <<<<<<<<<<<<<< - * mask_block = numpy.empty((win_ysize, n_cols), dtype=numpy.int8) - * dt = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_numpy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 209, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 209, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 209, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 209, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 209, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_3); - __pyx_t_4 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 209, __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; - __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 209, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_numpy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 209, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 209, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 209, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 209, __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_6); __pyx_t_6 = 0; - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 209, __pyx_L1_error) - __pyx_t_17 = ((PyArrayObject *)__pyx_t_1); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer); - __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer, (PyObject*)__pyx_t_17, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack); - if (unlikely(__pyx_t_5 < 0)) { - PyErr_Fetch(&__pyx_t_16, &__pyx_t_15, &__pyx_t_14); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer, (PyObject*)__pyx_v_g_block, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_16); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_14); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_16, __pyx_t_15, __pyx_t_14); - } - __pyx_t_16 = __pyx_t_15 = __pyx_t_14 = 0; - } - __pyx_pybuffernd_g_block.diminfo[0].strides = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_g_block.diminfo[0].shape = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_g_block.diminfo[1].strides = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_g_block.diminfo[1].shape = __pyx_pybuffernd_g_block.rcbuffer->pybuffer.shape[1]; - if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 209, __pyx_L1_error) - } - __pyx_t_17 = 0; - __Pyx_DECREF_SET(__pyx_v_g_block, ((PyArrayObject *)__pyx_t_1)); - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":210 - * win_ysize = n_rows - yoff - * g_block = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) - * mask_block = numpy.empty((win_ysize, n_cols), dtype=numpy.int8) # <<<<<<<<<<<<<< - * dt = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) - * done = True - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 210, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 210, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 210, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 210, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 210, __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_t_1 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 210, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 210, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 210, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_int8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 210, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 210, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 210, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 210, __pyx_L1_error) - __pyx_t_13 = ((PyArrayObject *)__pyx_t_4); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer); - __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); - if (unlikely(__pyx_t_5 < 0)) { - PyErr_Fetch(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer, (PyObject*)__pyx_v_mask_block, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_16); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_14, __pyx_t_15, __pyx_t_16); - } - __pyx_t_14 = __pyx_t_15 = __pyx_t_16 = 0; - } - __pyx_pybuffernd_mask_block.diminfo[0].strides = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_mask_block.diminfo[0].shape = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_mask_block.diminfo[1].strides = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_mask_block.diminfo[1].shape = __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.shape[1]; - if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 210, __pyx_L1_error) - } - __pyx_t_13 = 0; - __Pyx_DECREF_SET(__pyx_v_mask_block, ((PyArrayObject *)__pyx_t_4)); - __pyx_t_4 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":211 - * g_block = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) - * mask_block = numpy.empty((win_ysize, n_cols), dtype=numpy.int8) - * dt = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) # <<<<<<<<<<<<<< - * done = True - * g_band.ReadAsArray( - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_numpy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 211, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 211, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 211, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 211, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 211, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_3); - __pyx_t_4 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 211, __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; - __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 211, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_numpy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 211, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 211, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 211, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 211, __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_6); __pyx_t_6 = 0; - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 211, __pyx_L1_error) - __pyx_t_33 = ((PyArrayObject *)__pyx_t_1); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dt.rcbuffer->pybuffer); - __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dt.rcbuffer->pybuffer, (PyObject*)__pyx_t_33, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack); - if (unlikely(__pyx_t_5 < 0)) { - PyErr_Fetch(&__pyx_t_16, &__pyx_t_15, &__pyx_t_14); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dt.rcbuffer->pybuffer, (PyObject*)__pyx_v_dt, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_16); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_14); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_16, __pyx_t_15, __pyx_t_14); - } - __pyx_t_16 = __pyx_t_15 = __pyx_t_14 = 0; - } - __pyx_pybuffernd_dt.diminfo[0].strides = __pyx_pybuffernd_dt.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_dt.diminfo[0].shape = __pyx_pybuffernd_dt.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_dt.diminfo[1].strides = __pyx_pybuffernd_dt.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_dt.diminfo[1].shape = __pyx_pybuffernd_dt.rcbuffer->pybuffer.shape[1]; - if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 211, __pyx_L1_error) - } - __pyx_t_33 = 0; - __Pyx_DECREF_SET(__pyx_v_dt, ((PyArrayObject *)__pyx_t_1)); - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":212 - * mask_block = numpy.empty((win_ysize, n_cols), dtype=numpy.int8) - * dt = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) - * done = True # <<<<<<<<<<<<<< - * g_band.ReadAsArray( - * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, - */ - __pyx_v_done = 1; - - /* "pygeoprocessing/geoprocessing_core.pyx":207 - * for yoff in numpy.arange(0, n_rows, block_ysize): - * win_ysize = block_ysize - * if yoff + win_ysize >= n_rows: # <<<<<<<<<<<<<< - * win_ysize = n_rows - yoff - * g_block = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":213 - * dt = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) - * done = True - * g_band.ReadAsArray( # <<<<<<<<<<<<<< - * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, - * buf_obj=g_block) - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_g_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 213, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/geoprocessing_core.pyx":214 - * done = True - * g_band.ReadAsArray( - * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, # <<<<<<<<<<<<<< - * buf_obj=g_block) - * mask_band.ReadAsArray( - */ - __pyx_t_6 = __Pyx_PyDict_NewPresized(5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 214, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_xoff, __pyx_int_0) < 0) __PYX_ERR(0, 214, __pyx_L1_error) - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_yoff); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 214, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_yoff, __pyx_t_3) < 0) __PYX_ERR(0, 214, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 214, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_win_xsize, __pyx_t_3) < 0) __PYX_ERR(0, 214, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 214, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_win_ysize, __pyx_t_3) < 0) __PYX_ERR(0, 214, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":215 - * g_band.ReadAsArray( - * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, - * buf_obj=g_block) # <<<<<<<<<<<<<< - * mask_band.ReadAsArray( - * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, - */ - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_buf_obj, ((PyObject *)__pyx_v_g_block)) < 0) __PYX_ERR(0, 214, __pyx_L1_error) - - /* "pygeoprocessing/geoprocessing_core.pyx":213 - * dt = numpy.empty((win_ysize, n_cols), dtype=numpy.float32) - * done = True - * g_band.ReadAsArray( # <<<<<<<<<<<<<< - * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, - * buf_obj=g_block) - */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 213, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":216 - * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, - * buf_obj=g_block) - * mask_band.ReadAsArray( # <<<<<<<<<<<<<< - * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, - * buf_obj=mask_block) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_mask_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 216, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pygeoprocessing/geoprocessing_core.pyx":217 - * buf_obj=g_block) - * mask_band.ReadAsArray( - * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, # <<<<<<<<<<<<<< - * buf_obj=mask_block) - * for local_y_index in range(win_ysize): - */ - __pyx_t_6 = __Pyx_PyDict_NewPresized(5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 217, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_xoff, __pyx_int_0) < 0) __PYX_ERR(0, 217, __pyx_L1_error) - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_yoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 217, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_yoff, __pyx_t_1) < 0) __PYX_ERR(0, 217, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 217, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_win_xsize, __pyx_t_1) < 0) __PYX_ERR(0, 217, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 217, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_win_ysize, __pyx_t_1) < 0) __PYX_ERR(0, 217, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":218 - * mask_band.ReadAsArray( - * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, - * buf_obj=mask_block) # <<<<<<<<<<<<<< - * for local_y_index in range(win_ysize): - * q_index = 0 - */ - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_buf_obj, ((PyObject *)__pyx_v_mask_block)) < 0) __PYX_ERR(0, 217, __pyx_L1_error) - - /* "pygeoprocessing/geoprocessing_core.pyx":216 - * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, - * buf_obj=g_block) - * mask_band.ReadAsArray( # <<<<<<<<<<<<<< - * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, - * buf_obj=mask_block) - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_empty_tuple, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 216, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":219 - * xoff=0, yoff=yoff, win_xsize=n_cols, win_ysize=win_ysize, - * buf_obj=mask_block) - * for local_y_index in range(win_ysize): # <<<<<<<<<<<<<< - * q_index = 0 - * s_array[0] = 0 - */ - __pyx_t_5 = __pyx_v_win_ysize; - __pyx_t_22 = __pyx_t_5; - for (__pyx_t_23 = 0; __pyx_t_23 < __pyx_t_22; __pyx_t_23+=1) { - __pyx_v_local_y_index = __pyx_t_23; - - /* "pygeoprocessing/geoprocessing_core.pyx":220 - * buf_obj=mask_block) - * for local_y_index in range(win_ysize): - * q_index = 0 # <<<<<<<<<<<<<< - * s_array[0] = 0 - * t_array[0] = 0 - */ - __pyx_v_q_index = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":221 - * for local_y_index in range(win_ysize): - * q_index = 0 - * s_array[0] = 0 # <<<<<<<<<<<<<< - * t_array[0] = 0 - * for u_index in range(1, n_cols): - */ - __pyx_t_30 = 0; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_s_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_s_array.diminfo[0].strides) = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":222 - * q_index = 0 - * s_array[0] = 0 - * t_array[0] = 0 # <<<<<<<<<<<<<< - * for u_index in range(1, n_cols): - * gu = g_block[local_y_index, u_index]**2 - */ - __pyx_t_30 = 0; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_t_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_t_array.diminfo[0].strides) = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":223 - * s_array[0] = 0 - * t_array[0] = 0 - * for u_index in range(1, n_cols): # <<<<<<<<<<<<<< - * gu = g_block[local_y_index, u_index]**2 - * while (q_index >= 0): - */ - __pyx_t_24 = __pyx_v_n_cols; - __pyx_t_25 = __pyx_t_24; - for (__pyx_t_26 = 1; __pyx_t_26 < __pyx_t_25; __pyx_t_26+=1) { - __pyx_v_u_index = __pyx_t_26; - - /* "pygeoprocessing/geoprocessing_core.pyx":224 - * t_array[0] = 0 - * for u_index in range(1, n_cols): - * gu = g_block[local_y_index, u_index]**2 # <<<<<<<<<<<<<< - * while (q_index >= 0): - * tq = t_array[q_index] - */ - __pyx_t_30 = __pyx_v_local_y_index; - __pyx_t_29 = __pyx_v_u_index; - __pyx_v_gu = powf((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_g_block.diminfo[1].strides)), 2.0); - - /* "pygeoprocessing/geoprocessing_core.pyx":225 - * for u_index in range(1, n_cols): - * gu = g_block[local_y_index, u_index]**2 - * while (q_index >= 0): # <<<<<<<<<<<<<< - * tq = t_array[q_index] - * sq = s_array[q_index] - */ - while (1) { - __pyx_t_21 = ((__pyx_v_q_index >= 0) != 0); - if (!__pyx_t_21) break; - - /* "pygeoprocessing/geoprocessing_core.pyx":226 - * gu = g_block[local_y_index, u_index]**2 - * while (q_index >= 0): - * tq = t_array[q_index] # <<<<<<<<<<<<<< - * sq = s_array[q_index] - * gsq = g_block[local_y_index, sq]**2 - */ - __pyx_t_29 = __pyx_v_q_index; - __pyx_v_tq = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_t_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_t_array.diminfo[0].strides)); - - /* "pygeoprocessing/geoprocessing_core.pyx":227 - * while (q_index >= 0): - * tq = t_array[q_index] - * sq = s_array[q_index] # <<<<<<<<<<<<<< - * gsq = g_block[local_y_index, sq]**2 - * if ((sample_d_x*(tq-sq))**2 + gsq <= ( - */ - __pyx_t_29 = __pyx_v_q_index; - __pyx_v_sq = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_s_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_s_array.diminfo[0].strides)); - - /* "pygeoprocessing/geoprocessing_core.pyx":228 - * tq = t_array[q_index] - * sq = s_array[q_index] - * gsq = g_block[local_y_index, sq]**2 # <<<<<<<<<<<<<< - * if ((sample_d_x*(tq-sq))**2 + gsq <= ( - * sample_d_x*(tq-u_index))**2 + gu): - */ - __pyx_t_29 = __pyx_v_local_y_index; - __pyx_t_30 = __pyx_v_sq; - __pyx_v_gsq = powf((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_g_block.diminfo[1].strides)), 2.0); - - /* "pygeoprocessing/geoprocessing_core.pyx":229 - * sq = s_array[q_index] - * gsq = g_block[local_y_index, sq]**2 - * if ((sample_d_x*(tq-sq))**2 + gsq <= ( # <<<<<<<<<<<<<< - * sample_d_x*(tq-u_index))**2 + gu): - * break - */ - __pyx_t_21 = (((powf((__pyx_v_sample_d_x * (__pyx_v_tq - __pyx_v_sq)), 2.0) + __pyx_v_gsq) <= (powf((__pyx_v_sample_d_x * (__pyx_v_tq - __pyx_v_u_index)), 2.0) + __pyx_v_gu)) != 0); - if (__pyx_t_21) { - - /* "pygeoprocessing/geoprocessing_core.pyx":231 - * if ((sample_d_x*(tq-sq))**2 + gsq <= ( - * sample_d_x*(tq-u_index))**2 + gu): - * break # <<<<<<<<<<<<<< - * q_index -= 1 - * if q_index < 0: - */ - goto __pyx_L25_break; - - /* "pygeoprocessing/geoprocessing_core.pyx":229 - * sq = s_array[q_index] - * gsq = g_block[local_y_index, sq]**2 - * if ((sample_d_x*(tq-sq))**2 + gsq <= ( # <<<<<<<<<<<<<< - * sample_d_x*(tq-u_index))**2 + gu): - * break - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":232 - * sample_d_x*(tq-u_index))**2 + gu): - * break - * q_index -= 1 # <<<<<<<<<<<<<< - * if q_index < 0: - * q_index = 0 - */ - __pyx_v_q_index = (__pyx_v_q_index - 1); - } - __pyx_L25_break:; - - /* "pygeoprocessing/geoprocessing_core.pyx":233 - * break - * q_index -= 1 - * if q_index < 0: # <<<<<<<<<<<<<< - * q_index = 0 - * s_array[0] = u_index - */ - __pyx_t_21 = ((__pyx_v_q_index < 0) != 0); - if (__pyx_t_21) { - - /* "pygeoprocessing/geoprocessing_core.pyx":234 - * q_index -= 1 - * if q_index < 0: - * q_index = 0 # <<<<<<<<<<<<<< - * s_array[0] = u_index - * sq = u_index - */ - __pyx_v_q_index = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":235 - * if q_index < 0: - * q_index = 0 - * s_array[0] = u_index # <<<<<<<<<<<<<< - * sq = u_index - * gsq = g_block[local_y_index, sq]**2 - */ - __pyx_t_30 = 0; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_s_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_s_array.diminfo[0].strides) = __pyx_v_u_index; - - /* "pygeoprocessing/geoprocessing_core.pyx":236 - * q_index = 0 - * s_array[0] = u_index - * sq = u_index # <<<<<<<<<<<<<< - * gsq = g_block[local_y_index, sq]**2 - * else: - */ - __pyx_v_sq = __pyx_v_u_index; - - /* "pygeoprocessing/geoprocessing_core.pyx":237 - * s_array[0] = u_index - * sq = u_index - * gsq = g_block[local_y_index, sq]**2 # <<<<<<<<<<<<<< - * else: - * w = (float)(sample_d_x + (( - */ - __pyx_t_30 = __pyx_v_local_y_index; - __pyx_t_29 = __pyx_v_sq; - __pyx_v_gsq = powf((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_g_block.diminfo[1].strides)), 2.0); - - /* "pygeoprocessing/geoprocessing_core.pyx":233 - * break - * q_index -= 1 - * if q_index < 0: # <<<<<<<<<<<<<< - * q_index = 0 - * s_array[0] = u_index - */ - goto __pyx_L27; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":239 - * gsq = g_block[local_y_index, sq]**2 - * else: - * w = (float)(sample_d_x + (( # <<<<<<<<<<<<<< - * (sample_d_x*u_index)**2 - (sample_d_x*sq)**2 + - * gu - gsq) / (2*sample_d_x*(u_index-sq)))) - */ - /*else*/ { - - /* "pygeoprocessing/geoprocessing_core.pyx":241 - * w = (float)(sample_d_x + (( - * (sample_d_x*u_index)**2 - (sample_d_x*sq)**2 + - * gu - gsq) / (2*sample_d_x*(u_index-sq)))) # <<<<<<<<<<<<<< - * if w < n_cols*sample_d_x: - * q_index += 1 - */ - __pyx_v_w = ((double)(__pyx_v_sample_d_x + ((((powf((__pyx_v_sample_d_x * __pyx_v_u_index), 2.0) - powf((__pyx_v_sample_d_x * __pyx_v_sq), 2.0)) + __pyx_v_gu) - __pyx_v_gsq) / ((2.0 * __pyx_v_sample_d_x) * (__pyx_v_u_index - __pyx_v_sq))))); - - /* "pygeoprocessing/geoprocessing_core.pyx":242 - * (sample_d_x*u_index)**2 - (sample_d_x*sq)**2 + - * gu - gsq) / (2*sample_d_x*(u_index-sq)))) - * if w < n_cols*sample_d_x: # <<<<<<<<<<<<<< - * q_index += 1 - * s_array[q_index] = u_index - */ - __pyx_t_21 = ((__pyx_v_w < (__pyx_v_n_cols * __pyx_v_sample_d_x)) != 0); - if (__pyx_t_21) { - - /* "pygeoprocessing/geoprocessing_core.pyx":243 - * gu - gsq) / (2*sample_d_x*(u_index-sq)))) - * if w < n_cols*sample_d_x: - * q_index += 1 # <<<<<<<<<<<<<< - * s_array[q_index] = u_index - * t_array[q_index] = (w / sample_d_x) - */ - __pyx_v_q_index = (__pyx_v_q_index + 1); - - /* "pygeoprocessing/geoprocessing_core.pyx":244 - * if w < n_cols*sample_d_x: - * q_index += 1 - * s_array[q_index] = u_index # <<<<<<<<<<<<<< - * t_array[q_index] = (w / sample_d_x) - * - */ - __pyx_t_29 = __pyx_v_q_index; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_s_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_s_array.diminfo[0].strides) = __pyx_v_u_index; - - /* "pygeoprocessing/geoprocessing_core.pyx":245 - * q_index += 1 - * s_array[q_index] = u_index - * t_array[q_index] = (w / sample_d_x) # <<<<<<<<<<<<<< - * - * sq = s_array[q_index] - */ - __pyx_t_29 = __pyx_v_q_index; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_t_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_t_array.diminfo[0].strides) = ((int)(__pyx_v_w / __pyx_v_sample_d_x)); - - /* "pygeoprocessing/geoprocessing_core.pyx":242 - * (sample_d_x*u_index)**2 - (sample_d_x*sq)**2 + - * gu - gsq) / (2*sample_d_x*(u_index-sq)))) - * if w < n_cols*sample_d_x: # <<<<<<<<<<<<<< - * q_index += 1 - * s_array[q_index] = u_index - */ - } - } - __pyx_L27:; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":247 - * t_array[q_index] = (w / sample_d_x) - * - * sq = s_array[q_index] # <<<<<<<<<<<<<< - * gsq = g_block[local_y_index, sq]**2 - * tq = t_array[q_index] - */ - __pyx_t_29 = __pyx_v_q_index; - __pyx_v_sq = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_s_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_s_array.diminfo[0].strides)); - - /* "pygeoprocessing/geoprocessing_core.pyx":248 - * - * sq = s_array[q_index] - * gsq = g_block[local_y_index, sq]**2 # <<<<<<<<<<<<<< - * tq = t_array[q_index] - * for u_index in range(n_cols-1, -1, -1): - */ - __pyx_t_29 = __pyx_v_local_y_index; - __pyx_t_30 = __pyx_v_sq; - __pyx_v_gsq = powf((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_g_block.diminfo[1].strides)), 2.0); - - /* "pygeoprocessing/geoprocessing_core.pyx":249 - * sq = s_array[q_index] - * gsq = g_block[local_y_index, sq]**2 - * tq = t_array[q_index] # <<<<<<<<<<<<<< - * for u_index in range(n_cols-1, -1, -1): - * if mask_block[local_y_index, u_index] != 1: - */ - __pyx_t_30 = __pyx_v_q_index; - __pyx_v_tq = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_t_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_t_array.diminfo[0].strides)); - - /* "pygeoprocessing/geoprocessing_core.pyx":250 - * gsq = g_block[local_y_index, sq]**2 - * tq = t_array[q_index] - * for u_index in range(n_cols-1, -1, -1): # <<<<<<<<<<<<<< - * if mask_block[local_y_index, u_index] != 1: - * dt[local_y_index, u_index] = ( - */ - for (__pyx_t_24 = (__pyx_v_n_cols - 1); __pyx_t_24 > -1; __pyx_t_24-=1) { - __pyx_v_u_index = __pyx_t_24; - - /* "pygeoprocessing/geoprocessing_core.pyx":251 - * tq = t_array[q_index] - * for u_index in range(n_cols-1, -1, -1): - * if mask_block[local_y_index, u_index] != 1: # <<<<<<<<<<<<<< - * dt[local_y_index, u_index] = ( - * sample_d_x*(u_index-sq))**2+gsq - */ - __pyx_t_30 = __pyx_v_local_y_index; - __pyx_t_29 = __pyx_v_u_index; - __pyx_t_21 = (((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int8_t *, __pyx_pybuffernd_mask_block.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_mask_block.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_mask_block.diminfo[1].strides)) != 1) != 0); - if (__pyx_t_21) { - - /* "pygeoprocessing/geoprocessing_core.pyx":252 - * for u_index in range(n_cols-1, -1, -1): - * if mask_block[local_y_index, u_index] != 1: - * dt[local_y_index, u_index] = ( # <<<<<<<<<<<<<< - * sample_d_x*(u_index-sq))**2+gsq - * else: - */ - __pyx_t_29 = __pyx_v_local_y_index; - __pyx_t_30 = __pyx_v_u_index; - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_dt.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_dt.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_dt.diminfo[1].strides) = (powf((__pyx_v_sample_d_x * (__pyx_v_u_index - __pyx_v_sq)), 2.0) + __pyx_v_gsq); - - /* "pygeoprocessing/geoprocessing_core.pyx":251 - * tq = t_array[q_index] - * for u_index in range(n_cols-1, -1, -1): - * if mask_block[local_y_index, u_index] != 1: # <<<<<<<<<<<<<< - * dt[local_y_index, u_index] = ( - * sample_d_x*(u_index-sq))**2+gsq - */ - goto __pyx_L31; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":255 - * sample_d_x*(u_index-sq))**2+gsq - * else: - * dt[local_y_index, u_index] = 0 # <<<<<<<<<<<<<< - * if u_index <= tq: - * q_index -= 1 - */ - /*else*/ { - __pyx_t_30 = __pyx_v_local_y_index; - __pyx_t_29 = __pyx_v_u_index; - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_dt.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_dt.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_dt.diminfo[1].strides) = 0.0; - } - __pyx_L31:; - - /* "pygeoprocessing/geoprocessing_core.pyx":256 - * else: - * dt[local_y_index, u_index] = 0 - * if u_index <= tq: # <<<<<<<<<<<<<< - * q_index -= 1 - * if q_index >= 0: - */ - __pyx_t_21 = ((__pyx_v_u_index <= __pyx_v_tq) != 0); - if (__pyx_t_21) { - - /* "pygeoprocessing/geoprocessing_core.pyx":257 - * dt[local_y_index, u_index] = 0 - * if u_index <= tq: - * q_index -= 1 # <<<<<<<<<<<<<< - * if q_index >= 0: - * sq = s_array[q_index] - */ - __pyx_v_q_index = (__pyx_v_q_index - 1); - - /* "pygeoprocessing/geoprocessing_core.pyx":258 - * if u_index <= tq: - * q_index -= 1 - * if q_index >= 0: # <<<<<<<<<<<<<< - * sq = s_array[q_index] - * gsq = g_block[local_y_index, sq]**2 - */ - __pyx_t_21 = ((__pyx_v_q_index >= 0) != 0); - if (__pyx_t_21) { - - /* "pygeoprocessing/geoprocessing_core.pyx":259 - * q_index -= 1 - * if q_index >= 0: - * sq = s_array[q_index] # <<<<<<<<<<<<<< - * gsq = g_block[local_y_index, sq]**2 - * tq = t_array[q_index] - */ - __pyx_t_29 = __pyx_v_q_index; - __pyx_v_sq = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_s_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_s_array.diminfo[0].strides)); - - /* "pygeoprocessing/geoprocessing_core.pyx":260 - * if q_index >= 0: - * sq = s_array[q_index] - * gsq = g_block[local_y_index, sq]**2 # <<<<<<<<<<<<<< - * tq = t_array[q_index] - * - */ - __pyx_t_29 = __pyx_v_local_y_index; - __pyx_t_30 = __pyx_v_sq; - __pyx_v_gsq = powf((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_g_block.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_g_block.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_g_block.diminfo[1].strides)), 2.0); - - /* "pygeoprocessing/geoprocessing_core.pyx":261 - * sq = s_array[q_index] - * gsq = g_block[local_y_index, sq]**2 - * tq = t_array[q_index] # <<<<<<<<<<<<<< - * - * valid_mask = g_block != _NODATA - */ - __pyx_t_30 = __pyx_v_q_index; - __pyx_v_tq = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_t_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_t_array.diminfo[0].strides)); - - /* "pygeoprocessing/geoprocessing_core.pyx":258 - * if u_index <= tq: - * q_index -= 1 - * if q_index >= 0: # <<<<<<<<<<<<<< - * sq = s_array[q_index] - * gsq = g_block[local_y_index, sq]**2 - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":256 - * else: - * dt[local_y_index, u_index] = 0 - * if u_index <= tq: # <<<<<<<<<<<<<< - * q_index -= 1 - * if q_index >= 0: - */ - } - } - } - - /* "pygeoprocessing/geoprocessing_core.pyx":263 - * tq = t_array[q_index] - * - * valid_mask = g_block != _NODATA # <<<<<<<<<<<<<< - * # "unnormalize" distances along with square root - * dt[valid_mask] = numpy.sqrt(dt[valid_mask]) * max_sample - */ - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_15pygeoprocessing_18geoprocessing_core__NODATA); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 263, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = PyObject_RichCompare(((PyObject *)__pyx_v_g_block), __pyx_t_1, Py_NE); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 263, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF_SET(__pyx_v_valid_mask, __pyx_t_6); - __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":265 - * valid_mask = g_block != _NODATA - * # "unnormalize" distances along with square root - * dt[valid_mask] = numpy.sqrt(dt[valid_mask]) * max_sample # <<<<<<<<<<<<<< - * dt[~valid_mask] = _NODATA - * target_distance_band.WriteArray(dt, xoff=0, yoff=yoff) - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 265, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_sqrt); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 265, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_dt), __pyx_v_valid_mask); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 265, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = NULL; - 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_6 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 265, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Multiply(__pyx_t_6, __pyx_v_max_sample); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 265, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_dt), __pyx_v_valid_mask, __pyx_t_3) < 0)) __PYX_ERR(0, 265, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":266 - * # "unnormalize" distances along with square root - * dt[valid_mask] = numpy.sqrt(dt[valid_mask]) * max_sample - * dt[~valid_mask] = _NODATA # <<<<<<<<<<<<<< - * target_distance_band.WriteArray(dt, xoff=0, yoff=yoff) - * - */ - __pyx_t_3 = PyFloat_FromDouble(__pyx_v_15pygeoprocessing_18geoprocessing_core__NODATA); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 266, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = PyNumber_Invert(__pyx_v_valid_mask); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 266, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_dt), __pyx_t_6, __pyx_t_3) < 0)) __PYX_ERR(0, 266, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":267 - * dt[valid_mask] = numpy.sqrt(dt[valid_mask]) * max_sample - * dt[~valid_mask] = _NODATA - * target_distance_band.WriteArray(dt, xoff=0, yoff=yoff) # <<<<<<<<<<<<<< - * - * # we do this in the case where the blocksize is many times larger than - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_target_distance_band, __pyx_n_s_WriteArray); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 267, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 267, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_INCREF(((PyObject *)__pyx_v_dt)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_dt)); - PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_dt)); - __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 267, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_xoff, __pyx_int_0) < 0) __PYX_ERR(0, 267, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_yoff); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 267, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_yoff, __pyx_t_2) < 0) __PYX_ERR(0, 267, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 267, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":271 - * # we do this in the case where the blocksize is many times larger than - * # the raster size so we don't re-loop through the only block - * if done: # <<<<<<<<<<<<<< - * break - * - */ - __pyx_t_21 = (__pyx_v_done != 0); - if (__pyx_t_21) { - - /* "pygeoprocessing/geoprocessing_core.pyx":272 - * # the raster size so we don't re-loop through the only block - * if done: - * break # <<<<<<<<<<<<<< - * - * target_distance_band.ComputeStatistics(0) - */ - goto __pyx_L18_break; - - /* "pygeoprocessing/geoprocessing_core.pyx":271 - * # we do this in the case where the blocksize is many times larger than - * # the raster size so we don't re-loop through the only block - * if done: # <<<<<<<<<<<<<< - * break - * - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":205 - * sq = 0 # initialize so compiler doesn't complain - * gsq = 0 - * for yoff in numpy.arange(0, n_rows, block_ysize): # <<<<<<<<<<<<<< - * win_ysize = block_ysize - * if yoff + win_ysize >= n_rows: - */ - } - __pyx_L18_break:; - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":274 - * break - * - * target_distance_band.ComputeStatistics(0) # <<<<<<<<<<<<<< - * target_distance_band.FlushCache() - * target_distance_band = None - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_target_distance_band, __pyx_n_s_ComputeStatistics); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 274, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_18 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_1, __pyx_int_0) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_int_0); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 274, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":275 - * - * target_distance_band.ComputeStatistics(0) - * target_distance_band.FlushCache() # <<<<<<<<<<<<<< - * target_distance_band = None - * mask_band = None - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_target_distance_band, __pyx_n_s_FlushCache); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 275, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_18 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 275, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":276 - * target_distance_band.ComputeStatistics(0) - * target_distance_band.FlushCache() - * target_distance_band = None # <<<<<<<<<<<<<< - * mask_band = None - * g_band = None - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_target_distance_band, Py_None); - - /* "pygeoprocessing/geoprocessing_core.pyx":277 - * target_distance_band.FlushCache() - * target_distance_band = None - * mask_band = None # <<<<<<<<<<<<<< - * g_band = None - * target_distance_raster = None - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_mask_band, Py_None); - - /* "pygeoprocessing/geoprocessing_core.pyx":278 - * target_distance_band = None - * mask_band = None - * g_band = None # <<<<<<<<<<<<<< - * target_distance_raster = None - * mask_raster = None - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_g_band, Py_None); - - /* "pygeoprocessing/geoprocessing_core.pyx":279 - * mask_band = None - * g_band = None - * target_distance_raster = None # <<<<<<<<<<<<<< - * mask_raster = None - * g_raster = None - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_target_distance_raster, Py_None); - - /* "pygeoprocessing/geoprocessing_core.pyx":280 - * g_band = None - * target_distance_raster = None - * mask_raster = None # <<<<<<<<<<<<<< - * g_raster = None - * - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_mask_raster, Py_None); - - /* "pygeoprocessing/geoprocessing_core.pyx":281 - * target_distance_raster = None - * mask_raster = None - * g_raster = None # <<<<<<<<<<<<<< - * - * @cython.boundscheck(False) - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_g_raster, Py_None); - - /* "pygeoprocessing/geoprocessing_core.pyx":71 - * @cython.wraparound(False) - * @cython.cdivision(True) - * def _distance_transform_edt( # <<<<<<<<<<<<<< - * region_raster_path, g_raster_path, float sample_d_x, - * float sample_d_y, target_distance_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_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_18); - { 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_dt.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_s_array.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t_array.rcbuffer->pybuffer); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core._distance_transform_edt", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dt.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_g_block.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_mask_block.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_s_array.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t_array.rcbuffer->pybuffer); - __pyx_L2:; - __Pyx_XDECREF((PyObject *)__pyx_v_g_block); - __Pyx_XDECREF((PyObject *)__pyx_v_s_array); - __Pyx_XDECREF((PyObject *)__pyx_v_t_array); - __Pyx_XDECREF((PyObject *)__pyx_v_dt); - __Pyx_XDECREF((PyObject *)__pyx_v_mask_block); - __Pyx_XDECREF(__pyx_v_mask_raster); - __Pyx_XDECREF(__pyx_v_mask_band); - __Pyx_XDECREF(__pyx_v_raster_info); - __Pyx_XDECREF(__pyx_v_g_raster); - __Pyx_XDECREF(__pyx_v_g_band); - __Pyx_XDECREF(__pyx_v_g_band_blocksize); - __Pyx_XDECREF(__pyx_v_max_sample); - __Pyx_XDECREF(__pyx_v_target_distance_raster); - __Pyx_XDECREF(__pyx_v_target_distance_band); - __Pyx_XDECREF(__pyx_v_valid_mask); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pygeoprocessing/geoprocessing_core.pyx":287 - * @cython.nonecheck(False) - * @cython.cdivision(True) - * def calculate_slope( # <<<<<<<<<<<<<< - * base_elevation_raster_path_band, target_slope_path, - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_3calculate_slope(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_15pygeoprocessing_18geoprocessing_core_2calculate_slope[] = "Create a percent slope raster from DEM raster.\n\n Base algorithm is from Zevenbergen & Thorne \"Quantitative Analysis of Land\n Surface Topography\" 1987 although it has been modified to include the\n diagonal pixels by classic finite difference analysis.\n\n For the following notation, we define each pixel's DEM value by a letter\n with this spatial scheme::\n\n a b c\n d e f\n g h i\n\n Then the slope at ``e`` is defined at ``([dz/dx]^2 + [dz/dy]^2)^0.5``\n\n Where::\n\n [dz/dx] = ((c+2f+i)-(a+2d+g)/(8*x_cell_size)\n [dz/dy] = ((g+2h+i)-(a+2b+c))/(8*y_cell_size)\n\n In cases where a cell is nodata, we attempt to use the middle cell inline\n with the direction of differentiation (either in x or y direction). If\n no inline pixel is defined, we use ``e`` and multiply the difference by\n ``2^0.5`` to account for the diagonal projection.\n\n Parameters:\n base_elevation_raster_path_band (string): a path/band tuple to a\n raster of height values. (path_to_raster, band_index)\n target_slope_path (string): path to target slope raster; will be a\n 32 bit float GeoTIFF of same size/projection as calculate slope\n with units of percent slope.\n raster_driver_creation_tuple (tuple): a tuple containing a GDAL driver\n name string as the first element and a GDAL creation options\n tuple/list as the second. Defaults to\n geoprocessing.DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS.\n\n Returns:\n ``None``\n "; -static PyMethodDef __pyx_mdef_15pygeoprocessing_18geoprocessing_core_3calculate_slope = {"calculate_slope", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_18geoprocessing_core_3calculate_slope, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_18geoprocessing_core_2calculate_slope}; -static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_3calculate_slope(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_base_elevation_raster_path_band = 0; - PyObject *__pyx_v_target_slope_path = 0; - PyObject *__pyx_v_raster_driver_creation_tuple = 0; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("calculate_slope (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_base_elevation_raster_path_band,&__pyx_n_s_target_slope_path,&__pyx_n_s_raster_driver_creation_tuple,0}; - PyObject* values[3] = {0,0,0}; - values[2] = __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 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_base_elevation_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_slope_path)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("calculate_slope", 0, 2, 3, 1); __PYX_ERR(0, 287, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_raster_driver_creation_tuple); - if (value) { values[2] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "calculate_slope") < 0)) __PYX_ERR(0, 287, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - 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_base_elevation_raster_path_band = values[0]; - __pyx_v_target_slope_path = values[1]; - __pyx_v_raster_driver_creation_tuple = values[2]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("calculate_slope", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 287, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core.calculate_slope", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_15pygeoprocessing_18geoprocessing_core_2calculate_slope(__pyx_self, __pyx_v_base_elevation_raster_path_band, __pyx_v_target_slope_path, __pyx_v_raster_driver_creation_tuple); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core_2calculate_slope(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_base_elevation_raster_path_band, PyObject *__pyx_v_target_slope_path, PyObject *__pyx_v_raster_driver_creation_tuple) { - npy_float64 __pyx_v_a; - npy_float64 __pyx_v_b; - npy_float64 __pyx_v_c; - npy_float64 __pyx_v_d; - npy_float64 __pyx_v_e; - npy_float64 __pyx_v_f; - npy_float64 __pyx_v_g; - npy_float64 __pyx_v_h; - npy_float64 __pyx_v_i; - npy_float64 __pyx_v_dem_nodata; - npy_float64 __pyx_v_x_cell_size; - npy_float64 __pyx_v_y_cell_size; - npy_float64 __pyx_v_dzdx_accumulator; - npy_float64 __pyx_v_dzdy_accumulator; - int __pyx_v_row_index; - int __pyx_v_col_index; - int __pyx_v_n_rows; - int __pyx_v_n_cols; - int __pyx_v_x_denom_factor; - int __pyx_v_y_denom_factor; - int __pyx_v_win_xsize; - int __pyx_v_win_ysize; - PyArrayObject *__pyx_v_dem_array = 0; - PyArrayObject *__pyx_v_slope_array = 0; - PyArrayObject *__pyx_v_dzdx_array = 0; - PyArrayObject *__pyx_v_dzdy_array = 0; - PyObject *__pyx_v_dem_raster = NULL; - PyObject *__pyx_v_dem_band = NULL; - PyObject *__pyx_v_dem_info = NULL; - PyObject *__pyx_v_raw_nodata = NULL; - npy_float64 __pyx_v_slope_nodata; - PyObject *__pyx_v_target_slope_raster = NULL; - PyObject *__pyx_v_target_slope_band = NULL; - PyObject *__pyx_v_block_offset = NULL; - PyObject *__pyx_v_block_offset_copy = NULL; - PyObject *__pyx_v_x_start = NULL; - PyObject *__pyx_v_x_end = NULL; - PyObject *__pyx_v_y_start = NULL; - PyObject *__pyx_v_y_end = NULL; - PyObject *__pyx_v_valid_mask = NULL; - __Pyx_LocalBuf_ND __pyx_pybuffernd_dem_array; - __Pyx_Buffer __pyx_pybuffer_dem_array; - __Pyx_LocalBuf_ND __pyx_pybuffernd_dzdx_array; - __Pyx_Buffer __pyx_pybuffer_dzdx_array; - __Pyx_LocalBuf_ND __pyx_pybuffernd_dzdy_array; - __Pyx_Buffer __pyx_pybuffer_dzdy_array; - __Pyx_LocalBuf_ND __pyx_pybuffernd_slope_array; - __Pyx_Buffer __pyx_pybuffer_slope_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; - npy_float64 __pyx_t_7; - PyObject *(*__pyx_t_8)(PyObject *); - npy_float64 __pyx_t_9; - int __pyx_t_10; - int __pyx_t_11; - PyObject *__pyx_t_12 = NULL; - Py_ssize_t __pyx_t_13; - PyObject *(*__pyx_t_14)(PyObject *); - PyObject *__pyx_t_15 = NULL; - PyObject *__pyx_t_16 = NULL; - PyArrayObject *__pyx_t_17 = NULL; - PyObject *__pyx_t_18 = NULL; - PyObject *__pyx_t_19 = NULL; - PyObject *__pyx_t_20 = NULL; - PyArrayObject *__pyx_t_21 = NULL; - PyArrayObject *__pyx_t_22 = NULL; - PyArrayObject *__pyx_t_23 = NULL; - PyObject *__pyx_t_24 = NULL; - long __pyx_t_25; - long __pyx_t_26; - long __pyx_t_27; - long __pyx_t_28; - Py_ssize_t __pyx_t_29; - Py_ssize_t __pyx_t_30; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("calculate_slope", 0); - __pyx_pybuffer_dem_array.pybuffer.buf = NULL; - __pyx_pybuffer_dem_array.refcount = 0; - __pyx_pybuffernd_dem_array.data = NULL; - __pyx_pybuffernd_dem_array.rcbuffer = &__pyx_pybuffer_dem_array; - __pyx_pybuffer_slope_array.pybuffer.buf = NULL; - __pyx_pybuffer_slope_array.refcount = 0; - __pyx_pybuffernd_slope_array.data = NULL; - __pyx_pybuffernd_slope_array.rcbuffer = &__pyx_pybuffer_slope_array; - __pyx_pybuffer_dzdx_array.pybuffer.buf = NULL; - __pyx_pybuffer_dzdx_array.refcount = 0; - __pyx_pybuffernd_dzdx_array.data = NULL; - __pyx_pybuffernd_dzdx_array.rcbuffer = &__pyx_pybuffer_dzdx_array; - __pyx_pybuffer_dzdy_array.pybuffer.buf = NULL; - __pyx_pybuffer_dzdy_array.refcount = 0; - __pyx_pybuffernd_dzdy_array.data = NULL; - __pyx_pybuffernd_dzdy_array.rcbuffer = &__pyx_pybuffer_dzdy_array; - - /* "pygeoprocessing/geoprocessing_core.pyx":339 - * cdef numpy.ndarray[numpy.npy_float64, ndim=2] dzdy_array - * - * dem_raster = gdal.OpenEx(base_elevation_raster_path_band[0]) # <<<<<<<<<<<<<< - * dem_band = dem_raster.GetRasterBand(base_elevation_raster_path_band[1]) - * dem_info = pygeoprocessing.get_raster_info( - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 339, __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, 339, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_base_elevation_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 339, __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); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 339, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_dem_raster = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":340 - * - * dem_raster = gdal.OpenEx(base_elevation_raster_path_band[0]) - * dem_band = dem_raster.GetRasterBand(base_elevation_raster_path_band[1]) # <<<<<<<<<<<<<< - * dem_info = pygeoprocessing.get_raster_info( - * base_elevation_raster_path_band[0]) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_dem_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 340, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_base_elevation_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 340, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __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); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 340, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_dem_band = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":341 - * dem_raster = gdal.OpenEx(base_elevation_raster_path_band[0]) - * dem_band = dem_raster.GetRasterBand(base_elevation_raster_path_band[1]) - * dem_info = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< - * base_elevation_raster_path_band[0]) - * raw_nodata = dem_info['nodata'][0] - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 341, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 341, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":342 - * dem_band = dem_raster.GetRasterBand(base_elevation_raster_path_band[1]) - * dem_info = pygeoprocessing.get_raster_info( - * base_elevation_raster_path_band[0]) # <<<<<<<<<<<<<< - * raw_nodata = dem_info['nodata'][0] - * if raw_nodata is None: - */ - __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_base_elevation_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 342, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 341, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_dem_info = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":343 - * dem_info = pygeoprocessing.get_raster_info( - * base_elevation_raster_path_band[0]) - * raw_nodata = dem_info['nodata'][0] # <<<<<<<<<<<<<< - * if raw_nodata is None: - * # if nodata is undefined, choose most negative 32 bit float - */ - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_dem_info, __pyx_n_u_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 343, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 343, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_raw_nodata = __pyx_t_2; - __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":344 - * base_elevation_raster_path_band[0]) - * raw_nodata = dem_info['nodata'][0] - * if raw_nodata is None: # <<<<<<<<<<<<<< - * # if nodata is undefined, choose most negative 32 bit float - * raw_nodata = numpy.finfo(numpy.float32).min - */ - __pyx_t_5 = (__pyx_v_raw_nodata == Py_None); - __pyx_t_6 = (__pyx_t_5 != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":346 - * if raw_nodata is None: - * # if nodata is undefined, choose most negative 32 bit float - * raw_nodata = numpy.finfo(numpy.float32).min # <<<<<<<<<<<<<< - * dem_nodata = raw_nodata - * x_cell_size, y_cell_size = dem_info['pixel_size'] - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 346, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_finfo); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 346, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 346, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 346, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - 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_2 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_1, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 346, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_min); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 346, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF_SET(__pyx_v_raw_nodata, __pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":344 - * base_elevation_raster_path_band[0]) - * raw_nodata = dem_info['nodata'][0] - * if raw_nodata is None: # <<<<<<<<<<<<<< - * # if nodata is undefined, choose most negative 32 bit float - * raw_nodata = numpy.finfo(numpy.float32).min - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":347 - * # if nodata is undefined, choose most negative 32 bit float - * raw_nodata = numpy.finfo(numpy.float32).min - * dem_nodata = raw_nodata # <<<<<<<<<<<<<< - * x_cell_size, y_cell_size = dem_info['pixel_size'] - * n_cols, n_rows = dem_info['raster_size'] - */ - __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_v_raw_nodata); if (unlikely((__pyx_t_7 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 347, __pyx_L1_error) - __pyx_v_dem_nodata = __pyx_t_7; - - /* "pygeoprocessing/geoprocessing_core.pyx":348 - * raw_nodata = numpy.finfo(numpy.float32).min - * dem_nodata = raw_nodata - * x_cell_size, y_cell_size = dem_info['pixel_size'] # <<<<<<<<<<<<<< - * n_cols, n_rows = dem_info['raster_size'] - * cdef numpy.npy_float64 slope_nodata = numpy.finfo(numpy.float32).min - */ - __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_dem_info, __pyx_n_u_pixel_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 348, __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, 348, __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_4 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_2 = PyList_GET_ITEM(sequence, 0); - __pyx_t_4 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_4); - #else - __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 348, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 348, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #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, 348, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_1)->tp_iternext; - index = 0; __pyx_t_2 = __pyx_t_8(__pyx_t_1); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - index = 1; __pyx_t_4 = __pyx_t_8(__pyx_t_1); if (unlikely(!__pyx_t_4)) goto __pyx_L4_unpacking_failed; - __Pyx_GOTREF(__pyx_t_4); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_1), 2) < 0) __PYX_ERR(0, 348, __pyx_L1_error) - __pyx_t_8 = NULL; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L5_unpacking_done; - __pyx_L4_unpacking_failed:; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_8 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 348, __pyx_L1_error) - __pyx_L5_unpacking_done:; - } - __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_t_2); if (unlikely((__pyx_t_7 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 348, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_9 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_9 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 348, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_x_cell_size = __pyx_t_7; - __pyx_v_y_cell_size = __pyx_t_9; - - /* "pygeoprocessing/geoprocessing_core.pyx":349 - * dem_nodata = raw_nodata - * x_cell_size, y_cell_size = dem_info['pixel_size'] - * n_cols, n_rows = dem_info['raster_size'] # <<<<<<<<<<<<<< - * cdef numpy.npy_float64 slope_nodata = numpy.finfo(numpy.float32).min - * pygeoprocessing.new_raster_from_base( - */ - __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_dem_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 349, __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, 349, __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_2 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_4 = PyList_GET_ITEM(sequence, 0); - __pyx_t_2 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_2); - #else - __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 349, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 349, __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_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 349, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_1)->tp_iternext; - index = 0; __pyx_t_4 = __pyx_t_8(__pyx_t_1); if (unlikely(!__pyx_t_4)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_4); - index = 1; __pyx_t_2 = __pyx_t_8(__pyx_t_1); if (unlikely(!__pyx_t_2)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_1), 2) < 0) __PYX_ERR(0, 349, __pyx_L1_error) - __pyx_t_8 = NULL; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L7_unpacking_done; - __pyx_L6_unpacking_failed:; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_8 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 349, __pyx_L1_error) - __pyx_L7_unpacking_done:; - } - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 349, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 349, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_n_cols = __pyx_t_10; - __pyx_v_n_rows = __pyx_t_11; - - /* "pygeoprocessing/geoprocessing_core.pyx":350 - * x_cell_size, y_cell_size = dem_info['pixel_size'] - * n_cols, n_rows = dem_info['raster_size'] - * cdef numpy.npy_float64 slope_nodata = numpy.finfo(numpy.float32).min # <<<<<<<<<<<<<< - * pygeoprocessing.new_raster_from_base( - * base_elevation_raster_path_band[0], target_slope_path, - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 350, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_finfo); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 350, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 350, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 350, __pyx_L1_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_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_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_2, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 350, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_min); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 350, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_9 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_9 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 350, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_slope_nodata = __pyx_t_9; - - /* "pygeoprocessing/geoprocessing_core.pyx":351 - * n_cols, n_rows = dem_info['raster_size'] - * cdef numpy.npy_float64 slope_nodata = numpy.finfo(numpy.float32).min - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * base_elevation_raster_path_band[0], target_slope_path, - * gdal.GDT_Float32, [slope_nodata], - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 351, __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, 351, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":352 - * cdef numpy.npy_float64 slope_nodata = numpy.finfo(numpy.float32).min - * pygeoprocessing.new_raster_from_base( - * base_elevation_raster_path_band[0], target_slope_path, # <<<<<<<<<<<<<< - * gdal.GDT_Float32, [slope_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - */ - __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_base_elevation_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 352, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - - /* "pygeoprocessing/geoprocessing_core.pyx":353 - * pygeoprocessing.new_raster_from_base( - * base_elevation_raster_path_band[0], target_slope_path, - * gdal.GDT_Float32, [slope_nodata], # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * target_slope_raster = gdal.OpenEx(target_slope_path, gdal.GA_Update) - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 353, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Float32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 353, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_slope_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 353, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_12 = PyList_New(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 353, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_GIVEREF(__pyx_t_1); - PyList_SET_ITEM(__pyx_t_12, 0, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":351 - * n_cols, n_rows = dem_info['raster_size'] - * cdef numpy.npy_float64 slope_nodata = numpy.finfo(numpy.float32).min - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * base_elevation_raster_path_band[0], target_slope_path, - * gdal.GDT_Float32, [slope_nodata], - */ - __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 351, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4); - __Pyx_INCREF(__pyx_v_target_slope_path); - __Pyx_GIVEREF(__pyx_v_target_slope_path); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_target_slope_path); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_12); - PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_12); - __pyx_t_4 = 0; - __pyx_t_2 = 0; - __pyx_t_12 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":354 - * base_elevation_raster_path_band[0], target_slope_path, - * gdal.GDT_Float32, [slope_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< - * target_slope_raster = gdal.OpenEx(target_slope_path, gdal.GA_Update) - * target_slope_band = target_slope_raster.GetRasterBand(1) - */ - __pyx_t_12 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 354, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 354, __pyx_L1_error) - - /* "pygeoprocessing/geoprocessing_core.pyx":351 - * n_cols, n_rows = dem_info['raster_size'] - * cdef numpy.npy_float64 slope_nodata = numpy.finfo(numpy.float32).min - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * base_elevation_raster_path_band[0], target_slope_path, - * gdal.GDT_Float32, [slope_nodata], - */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, __pyx_t_12); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 351, __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; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":355 - * gdal.GDT_Float32, [slope_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * target_slope_raster = gdal.OpenEx(target_slope_path, gdal.GA_Update) # <<<<<<<<<<<<<< - * target_slope_band = target_slope_raster.GetRasterBand(1) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_gdal); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 355, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 355, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_gdal); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 355, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_GA_Update); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 355, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = NULL; - __pyx_t_11 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_12)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_12); - __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_12, __pyx_v_target_slope_path, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 355, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GOTREF(__pyx_t_2); - __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[3] = {__pyx_t_12, __pyx_v_target_slope_path, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 355, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - { - __pyx_t_4 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 355, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (__pyx_t_12) { - __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_12); __pyx_t_12 = NULL; - } - __Pyx_INCREF(__pyx_v_target_slope_path); - __Pyx_GIVEREF(__pyx_v_target_slope_path); - PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_11, __pyx_v_target_slope_path); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_11, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 355, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_target_slope_raster = __pyx_t_2; - __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":356 - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * target_slope_raster = gdal.OpenEx(target_slope_path, gdal.GA_Update) - * target_slope_band = target_slope_raster.GetRasterBand(1) # <<<<<<<<<<<<<< - * - * for block_offset in pygeoprocessing.iterblocks( - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_target_slope_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 356, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = NULL; - 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_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_4, __pyx_int_1) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_int_1); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 356, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_target_slope_band = __pyx_t_2; - __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":358 - * target_slope_band = target_slope_raster.GetRasterBand(1) - * - * for block_offset in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * base_elevation_raster_path_band, offset_only=True): - * block_offset_copy = block_offset.copy() - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 358, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 358, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":359 - * - * for block_offset in pygeoprocessing.iterblocks( - * base_elevation_raster_path_band, offset_only=True): # <<<<<<<<<<<<<< - * block_offset_copy = block_offset.copy() - * # try to expand the block around the edges if it fits - */ - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 358, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_base_elevation_raster_path_band); - __Pyx_GIVEREF(__pyx_v_base_elevation_raster_path_band); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_base_elevation_raster_path_band); - __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 359, __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, 359, __pyx_L1_error) - - /* "pygeoprocessing/geoprocessing_core.pyx":358 - * target_slope_band = target_slope_raster.GetRasterBand(1) - * - * for block_offset in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * base_elevation_raster_path_band, offset_only=True): - * block_offset_copy = block_offset.copy() - */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 358, __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(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) { - __pyx_t_4 = __pyx_t_3; __Pyx_INCREF(__pyx_t_4); __pyx_t_13 = 0; - __pyx_t_14 = NULL; - } else { - __pyx_t_13 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 358, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_14 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 358, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - for (;;) { - if (likely(!__pyx_t_14)) { - if (likely(PyList_CheckExact(__pyx_t_4))) { - if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_13); __Pyx_INCREF(__pyx_t_3); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 358, __pyx_L1_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 358, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - } else { - if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_13); __Pyx_INCREF(__pyx_t_3); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 358, __pyx_L1_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 358, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - } - } else { - __pyx_t_3 = __pyx_t_14(__pyx_t_4); - 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, 358, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_XDECREF_SET(__pyx_v_block_offset, __pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":360 - * for block_offset in pygeoprocessing.iterblocks( - * base_elevation_raster_path_band, offset_only=True): - * block_offset_copy = block_offset.copy() # <<<<<<<<<<<<<< - * # try to expand the block around the edges if it fits - * x_start = 1 - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_block_offset, __pyx_n_s_copy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 360, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_3 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 360, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF_SET(__pyx_v_block_offset_copy, __pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":362 - * block_offset_copy = block_offset.copy() - * # try to expand the block around the edges if it fits - * x_start = 1 # <<<<<<<<<<<<<< - * win_xsize = block_offset['win_xsize'] - * x_end = win_xsize+1 - */ - __Pyx_INCREF(__pyx_int_1); - __Pyx_XDECREF_SET(__pyx_v_x_start, __pyx_int_1); - - /* "pygeoprocessing/geoprocessing_core.pyx":363 - * # try to expand the block around the edges if it fits - * x_start = 1 - * win_xsize = block_offset['win_xsize'] # <<<<<<<<<<<<<< - * x_end = win_xsize+1 - * y_start = 1 - */ - __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 363, __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, 363, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_win_xsize = __pyx_t_11; - - /* "pygeoprocessing/geoprocessing_core.pyx":364 - * x_start = 1 - * win_xsize = block_offset['win_xsize'] - * x_end = win_xsize+1 # <<<<<<<<<<<<<< - * y_start = 1 - * win_ysize = block_offset['win_ysize'] - */ - __pyx_t_3 = __Pyx_PyInt_From_long((__pyx_v_win_xsize + 1)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 364, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XDECREF_SET(__pyx_v_x_end, __pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":365 - * win_xsize = block_offset['win_xsize'] - * x_end = win_xsize+1 - * y_start = 1 # <<<<<<<<<<<<<< - * win_ysize = block_offset['win_ysize'] - * y_end = win_ysize+1 - */ - __Pyx_INCREF(__pyx_int_1); - __Pyx_XDECREF_SET(__pyx_v_y_start, __pyx_int_1); - - /* "pygeoprocessing/geoprocessing_core.pyx":366 - * x_end = win_xsize+1 - * y_start = 1 - * win_ysize = block_offset['win_ysize'] # <<<<<<<<<<<<<< - * y_end = win_ysize+1 - * - */ - __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 366, __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, 366, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_win_ysize = __pyx_t_11; - - /* "pygeoprocessing/geoprocessing_core.pyx":367 - * y_start = 1 - * win_ysize = block_offset['win_ysize'] - * y_end = win_ysize+1 # <<<<<<<<<<<<<< - * - * if block_offset['xoff'] > 0: - */ - __pyx_t_3 = __Pyx_PyInt_From_long((__pyx_v_win_ysize + 1)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 367, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XDECREF_SET(__pyx_v_y_end, __pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":369 - * y_end = win_ysize+1 - * - * if block_offset['xoff'] > 0: # <<<<<<<<<<<<<< - * block_offset_copy['xoff'] -= 1 - * block_offset_copy['win_xsize'] += 1 - */ - __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset, __pyx_n_u_xoff); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 369, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 369, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 369, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":370 - * - * if block_offset['xoff'] > 0: - * block_offset_copy['xoff'] -= 1 # <<<<<<<<<<<<<< - * block_offset_copy['win_xsize'] += 1 - * x_start -= 1 - */ - __Pyx_INCREF(__pyx_n_u_xoff); - __pyx_t_15 = __pyx_n_u_xoff; - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset_copy, __pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 370, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_SubtractObjC(__pyx_t_2, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 370, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(PyObject_SetItem(__pyx_v_block_offset_copy, __pyx_t_15, __pyx_t_3) < 0)) __PYX_ERR(0, 370, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":371 - * if block_offset['xoff'] > 0: - * block_offset_copy['xoff'] -= 1 - * block_offset_copy['win_xsize'] += 1 # <<<<<<<<<<<<<< - * x_start -= 1 - * if block_offset['xoff']+win_xsize < n_cols: - */ - __Pyx_INCREF(__pyx_n_u_win_xsize); - __pyx_t_15 = __pyx_n_u_win_xsize; - __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset_copy, __pyx_t_15); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 371, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 371, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(PyObject_SetItem(__pyx_v_block_offset_copy, __pyx_t_15, __pyx_t_2) < 0)) __PYX_ERR(0, 371, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":372 - * block_offset_copy['xoff'] -= 1 - * block_offset_copy['win_xsize'] += 1 - * x_start -= 1 # <<<<<<<<<<<<<< - * if block_offset['xoff']+win_xsize < n_cols: - * block_offset_copy['win_xsize'] += 1 - */ - __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_v_x_start, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 372, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF_SET(__pyx_v_x_start, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":369 - * y_end = win_ysize+1 - * - * if block_offset['xoff'] > 0: # <<<<<<<<<<<<<< - * block_offset_copy['xoff'] -= 1 - * block_offset_copy['win_xsize'] += 1 - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":373 - * block_offset_copy['win_xsize'] += 1 - * x_start -= 1 - * if block_offset['xoff']+win_xsize < n_cols: # <<<<<<<<<<<<<< - * block_offset_copy['win_xsize'] += 1 - * x_end += 1 - */ - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset, __pyx_n_u_xoff); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 373, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 373, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyNumber_Add(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 373, __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_t_3 = __Pyx_PyInt_From_int(__pyx_v_n_cols); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 373, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 373, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 373, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":374 - * x_start -= 1 - * if block_offset['xoff']+win_xsize < n_cols: - * block_offset_copy['win_xsize'] += 1 # <<<<<<<<<<<<<< - * x_end += 1 - * if block_offset['yoff'] > 0: - */ - __Pyx_INCREF(__pyx_n_u_win_xsize); - __pyx_t_15 = __pyx_n_u_win_xsize; - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset_copy, __pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 374, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 374, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(PyObject_SetItem(__pyx_v_block_offset_copy, __pyx_t_15, __pyx_t_3) < 0)) __PYX_ERR(0, 374, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":375 - * if block_offset['xoff']+win_xsize < n_cols: - * block_offset_copy['win_xsize'] += 1 - * x_end += 1 # <<<<<<<<<<<<<< - * if block_offset['yoff'] > 0: - * block_offset_copy['yoff'] -= 1 - */ - __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_v_x_end, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 375, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF_SET(__pyx_v_x_end, __pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":373 - * block_offset_copy['win_xsize'] += 1 - * x_start -= 1 - * if block_offset['xoff']+win_xsize < n_cols: # <<<<<<<<<<<<<< - * block_offset_copy['win_xsize'] += 1 - * x_end += 1 - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":376 - * block_offset_copy['win_xsize'] += 1 - * x_end += 1 - * if block_offset['yoff'] > 0: # <<<<<<<<<<<<<< - * block_offset_copy['yoff'] -= 1 - * block_offset_copy['win_ysize'] += 1 - */ - __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset, __pyx_n_u_yoff); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 376, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 376, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 376, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":377 - * x_end += 1 - * if block_offset['yoff'] > 0: - * block_offset_copy['yoff'] -= 1 # <<<<<<<<<<<<<< - * block_offset_copy['win_ysize'] += 1 - * y_start -= 1 - */ - __Pyx_INCREF(__pyx_n_u_yoff); - __pyx_t_15 = __pyx_n_u_yoff; - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset_copy, __pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 377, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_SubtractObjC(__pyx_t_2, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 377, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(PyObject_SetItem(__pyx_v_block_offset_copy, __pyx_t_15, __pyx_t_3) < 0)) __PYX_ERR(0, 377, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":378 - * if block_offset['yoff'] > 0: - * block_offset_copy['yoff'] -= 1 - * block_offset_copy['win_ysize'] += 1 # <<<<<<<<<<<<<< - * y_start -= 1 - * if block_offset['yoff']+win_ysize < n_rows: - */ - __Pyx_INCREF(__pyx_n_u_win_ysize); - __pyx_t_15 = __pyx_n_u_win_ysize; - __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset_copy, __pyx_t_15); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 378, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 378, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(PyObject_SetItem(__pyx_v_block_offset_copy, __pyx_t_15, __pyx_t_2) < 0)) __PYX_ERR(0, 378, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":379 - * block_offset_copy['yoff'] -= 1 - * block_offset_copy['win_ysize'] += 1 - * y_start -= 1 # <<<<<<<<<<<<<< - * if block_offset['yoff']+win_ysize < n_rows: - * block_offset_copy['win_ysize'] += 1 - */ - __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_v_y_start, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 379, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF_SET(__pyx_v_y_start, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":376 - * block_offset_copy['win_xsize'] += 1 - * x_end += 1 - * if block_offset['yoff'] > 0: # <<<<<<<<<<<<<< - * block_offset_copy['yoff'] -= 1 - * block_offset_copy['win_ysize'] += 1 - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":380 - * block_offset_copy['win_ysize'] += 1 - * y_start -= 1 - * if block_offset['yoff']+win_ysize < n_rows: # <<<<<<<<<<<<<< - * block_offset_copy['win_ysize'] += 1 - * y_end += 1 - */ - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset, __pyx_n_u_yoff); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyNumber_Add(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 380, __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_t_3 = __Pyx_PyInt_From_int(__pyx_v_n_rows); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":381 - * y_start -= 1 - * if block_offset['yoff']+win_ysize < n_rows: - * block_offset_copy['win_ysize'] += 1 # <<<<<<<<<<<<<< - * y_end += 1 - * - */ - __Pyx_INCREF(__pyx_n_u_win_ysize); - __pyx_t_15 = __pyx_n_u_win_ysize; - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset_copy, __pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 381, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 381, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(PyObject_SetItem(__pyx_v_block_offset_copy, __pyx_t_15, __pyx_t_3) < 0)) __PYX_ERR(0, 381, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":382 - * if block_offset['yoff']+win_ysize < n_rows: - * block_offset_copy['win_ysize'] += 1 - * y_end += 1 # <<<<<<<<<<<<<< - * - * dem_array = numpy.empty( - */ - __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_v_y_end, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 382, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF_SET(__pyx_v_y_end, __pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":380 - * block_offset_copy['win_ysize'] += 1 - * y_start -= 1 - * if block_offset['yoff']+win_ysize < n_rows: # <<<<<<<<<<<<<< - * block_offset_copy['win_ysize'] += 1 - * y_end += 1 - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":384 - * y_end += 1 - * - * dem_array = numpy.empty( # <<<<<<<<<<<<<< - * (win_ysize+2, win_xsize+2), - * dtype=numpy.float64) - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 384, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 384, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":385 - * - * dem_array = numpy.empty( - * (win_ysize+2, win_xsize+2), # <<<<<<<<<<<<<< - * dtype=numpy.float64) - * dem_array[:] = dem_nodata - */ - __pyx_t_3 = __Pyx_PyInt_From_long((__pyx_v_win_ysize + 2)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 385, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __Pyx_PyInt_From_long((__pyx_v_win_xsize + 2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 385, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 385, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_1); - __pyx_t_3 = 0; - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":384 - * y_end += 1 - * - * dem_array = numpy.empty( # <<<<<<<<<<<<<< - * (win_ysize+2, win_xsize+2), - * dtype=numpy.float64) - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 384, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_12); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_12); - __pyx_t_12 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":386 - * dem_array = numpy.empty( - * (win_ysize+2, win_xsize+2), - * dtype=numpy.float64) # <<<<<<<<<<<<<< - * dem_array[:] = dem_nodata - * slope_array = numpy.empty( - */ - __pyx_t_12 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 386, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 386, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 386, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_dtype, __pyx_t_16) < 0) __PYX_ERR(0, 386, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":384 - * y_end += 1 - * - * dem_array = numpy.empty( # <<<<<<<<<<<<<< - * (win_ysize+2, win_xsize+2), - * dtype=numpy.float64) - */ - __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_12); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 384, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (!(likely(((__pyx_t_16) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_16, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 384, __pyx_L1_error) - __pyx_t_17 = ((PyArrayObject *)__pyx_t_16); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dem_array.rcbuffer->pybuffer); - __pyx_t_11 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dem_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_17, &__Pyx_TypeInfo_nn_npy_float64, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); - if (unlikely(__pyx_t_11 < 0)) { - PyErr_Fetch(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dem_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_dem_array, &__Pyx_TypeInfo_nn_npy_float64, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_18); Py_XDECREF(__pyx_t_19); Py_XDECREF(__pyx_t_20); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_18, __pyx_t_19, __pyx_t_20); - } - __pyx_t_18 = __pyx_t_19 = __pyx_t_20 = 0; - } - __pyx_pybuffernd_dem_array.diminfo[0].strides = __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_dem_array.diminfo[0].shape = __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_dem_array.diminfo[1].strides = __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_dem_array.diminfo[1].shape = __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.shape[1]; - if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 384, __pyx_L1_error) - } - __pyx_t_17 = 0; - __Pyx_XDECREF_SET(__pyx_v_dem_array, ((PyArrayObject *)__pyx_t_16)); - __pyx_t_16 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":387 - * (win_ysize+2, win_xsize+2), - * dtype=numpy.float64) - * dem_array[:] = dem_nodata # <<<<<<<<<<<<<< - * slope_array = numpy.empty( - * (win_ysize, win_xsize), - */ - __pyx_t_16 = PyFloat_FromDouble(__pyx_v_dem_nodata); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 387, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_dem_array), __pyx_slice_, __pyx_t_16) < 0)) __PYX_ERR(0, 387, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":388 - * dtype=numpy.float64) - * dem_array[:] = dem_nodata - * slope_array = numpy.empty( # <<<<<<<<<<<<<< - * (win_ysize, win_xsize), - * dtype=numpy.float64) - */ - __Pyx_GetModuleGlobalName(__pyx_t_16, __pyx_n_s_numpy); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 388, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_16, __pyx_n_s_empty); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 388, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":389 - * dem_array[:] = dem_nodata - * slope_array = numpy.empty( - * (win_ysize, win_xsize), # <<<<<<<<<<<<<< - * dtype=numpy.float64) - * dzdx_array = numpy.empty( - */ - __pyx_t_16 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 389, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 389, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 389, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_16); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_16); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1); - __pyx_t_16 = 0; - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":388 - * dtype=numpy.float64) - * dem_array[:] = dem_nodata - * slope_array = numpy.empty( # <<<<<<<<<<<<<< - * (win_ysize, win_xsize), - * dtype=numpy.float64) - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 388, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":390 - * slope_array = numpy.empty( - * (win_ysize, win_xsize), - * dtype=numpy.float64) # <<<<<<<<<<<<<< - * dzdx_array = numpy.empty( - * (win_ysize, win_xsize), - */ - __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 390, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GetModuleGlobalName(__pyx_t_16, __pyx_n_s_numpy); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 390, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_16, __pyx_n_s_float64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 390, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 390, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":388 - * dtype=numpy.float64) - * dem_array[:] = dem_nodata - * slope_array = numpy.empty( # <<<<<<<<<<<<<< - * (win_ysize, win_xsize), - * dtype=numpy.float64) - */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 388, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 388, __pyx_L1_error) - __pyx_t_21 = ((PyArrayObject *)__pyx_t_3); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_slope_array.rcbuffer->pybuffer); - __pyx_t_11 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_slope_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_21, &__Pyx_TypeInfo_nn_npy_float64, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); - if (unlikely(__pyx_t_11 < 0)) { - PyErr_Fetch(&__pyx_t_20, &__pyx_t_19, &__pyx_t_18); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_slope_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_slope_array, &__Pyx_TypeInfo_nn_npy_float64, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_20); Py_XDECREF(__pyx_t_19); Py_XDECREF(__pyx_t_18); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_20, __pyx_t_19, __pyx_t_18); - } - __pyx_t_20 = __pyx_t_19 = __pyx_t_18 = 0; - } - __pyx_pybuffernd_slope_array.diminfo[0].strides = __pyx_pybuffernd_slope_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_slope_array.diminfo[0].shape = __pyx_pybuffernd_slope_array.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_slope_array.diminfo[1].strides = __pyx_pybuffernd_slope_array.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_slope_array.diminfo[1].shape = __pyx_pybuffernd_slope_array.rcbuffer->pybuffer.shape[1]; - if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 388, __pyx_L1_error) - } - __pyx_t_21 = 0; - __Pyx_XDECREF_SET(__pyx_v_slope_array, ((PyArrayObject *)__pyx_t_3)); - __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":391 - * (win_ysize, win_xsize), - * dtype=numpy.float64) - * dzdx_array = numpy.empty( # <<<<<<<<<<<<<< - * (win_ysize, win_xsize), - * dtype=numpy.float64) - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 391, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 391, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":392 - * dtype=numpy.float64) - * dzdx_array = numpy.empty( - * (win_ysize, win_xsize), # <<<<<<<<<<<<<< - * dtype=numpy.float64) - * dzdy_array = numpy.empty( - */ - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 392, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 392, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 392, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_1); - __pyx_t_3 = 0; - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":391 - * (win_ysize, win_xsize), - * dtype=numpy.float64) - * dzdx_array = numpy.empty( # <<<<<<<<<<<<<< - * (win_ysize, win_xsize), - * dtype=numpy.float64) - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 391, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_12); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_12); - __pyx_t_12 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":393 - * dzdx_array = numpy.empty( - * (win_ysize, win_xsize), - * dtype=numpy.float64) # <<<<<<<<<<<<<< - * dzdy_array = numpy.empty( - * (win_ysize, win_xsize), - */ - __pyx_t_12 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 393, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 393, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 393, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_dtype, __pyx_t_16) < 0) __PYX_ERR(0, 393, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":391 - * (win_ysize, win_xsize), - * dtype=numpy.float64) - * dzdx_array = numpy.empty( # <<<<<<<<<<<<<< - * (win_ysize, win_xsize), - * dtype=numpy.float64) - */ - __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_12); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 391, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (!(likely(((__pyx_t_16) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_16, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 391, __pyx_L1_error) - __pyx_t_22 = ((PyArrayObject *)__pyx_t_16); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer); - __pyx_t_11 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_22, &__Pyx_TypeInfo_nn_npy_float64, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack); - if (unlikely(__pyx_t_11 < 0)) { - PyErr_Fetch(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_dzdx_array, &__Pyx_TypeInfo_nn_npy_float64, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_18); Py_XDECREF(__pyx_t_19); Py_XDECREF(__pyx_t_20); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_18, __pyx_t_19, __pyx_t_20); - } - __pyx_t_18 = __pyx_t_19 = __pyx_t_20 = 0; - } - __pyx_pybuffernd_dzdx_array.diminfo[0].strides = __pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_dzdx_array.diminfo[0].shape = __pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_dzdx_array.diminfo[1].strides = __pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_dzdx_array.diminfo[1].shape = __pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer.shape[1]; - if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 391, __pyx_L1_error) - } - __pyx_t_22 = 0; - __Pyx_XDECREF_SET(__pyx_v_dzdx_array, ((PyArrayObject *)__pyx_t_16)); - __pyx_t_16 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":394 - * (win_ysize, win_xsize), - * dtype=numpy.float64) - * dzdy_array = numpy.empty( # <<<<<<<<<<<<<< - * (win_ysize, win_xsize), - * dtype=numpy.float64) - */ - __Pyx_GetModuleGlobalName(__pyx_t_16, __pyx_n_s_numpy); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 394, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_16, __pyx_n_s_empty); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 394, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":395 - * dtype=numpy.float64) - * dzdy_array = numpy.empty( - * (win_ysize, win_xsize), # <<<<<<<<<<<<<< - * dtype=numpy.float64) - * - */ - __pyx_t_16 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 395, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 395, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 395, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_16); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_16); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1); - __pyx_t_16 = 0; - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":394 - * (win_ysize, win_xsize), - * dtype=numpy.float64) - * dzdy_array = numpy.empty( # <<<<<<<<<<<<<< - * (win_ysize, win_xsize), - * dtype=numpy.float64) - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 394, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":396 - * dzdy_array = numpy.empty( - * (win_ysize, win_xsize), - * dtype=numpy.float64) # <<<<<<<<<<<<<< - * - * dem_band.ReadAsArray( - */ - __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 396, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GetModuleGlobalName(__pyx_t_16, __pyx_n_s_numpy); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 396, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_16, __pyx_n_s_float64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 396, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 396, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":394 - * (win_ysize, win_xsize), - * dtype=numpy.float64) - * dzdy_array = numpy.empty( # <<<<<<<<<<<<<< - * (win_ysize, win_xsize), - * dtype=numpy.float64) - */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 394, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 394, __pyx_L1_error) - __pyx_t_23 = ((PyArrayObject *)__pyx_t_3); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dzdy_array.rcbuffer->pybuffer); - __pyx_t_11 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dzdy_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_23, &__Pyx_TypeInfo_nn_npy_float64, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack); - if (unlikely(__pyx_t_11 < 0)) { - PyErr_Fetch(&__pyx_t_20, &__pyx_t_19, &__pyx_t_18); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dzdy_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_dzdy_array, &__Pyx_TypeInfo_nn_npy_float64, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_20); Py_XDECREF(__pyx_t_19); Py_XDECREF(__pyx_t_18); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_20, __pyx_t_19, __pyx_t_18); - } - __pyx_t_20 = __pyx_t_19 = __pyx_t_18 = 0; - } - __pyx_pybuffernd_dzdy_array.diminfo[0].strides = __pyx_pybuffernd_dzdy_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_dzdy_array.diminfo[0].shape = __pyx_pybuffernd_dzdy_array.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_dzdy_array.diminfo[1].strides = __pyx_pybuffernd_dzdy_array.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_dzdy_array.diminfo[1].shape = __pyx_pybuffernd_dzdy_array.rcbuffer->pybuffer.shape[1]; - if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 394, __pyx_L1_error) - } - __pyx_t_23 = 0; - __Pyx_XDECREF_SET(__pyx_v_dzdy_array, ((PyArrayObject *)__pyx_t_3)); - __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":398 - * dtype=numpy.float64) - * - * dem_band.ReadAsArray( # <<<<<<<<<<<<<< - * buf_obj=dem_array[y_start:y_end, x_start:x_end], - * **block_offset_copy) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_dem_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 398, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pygeoprocessing/geoprocessing_core.pyx":399 - * - * dem_band.ReadAsArray( - * buf_obj=dem_array[y_start:y_end, x_start:x_end], # <<<<<<<<<<<<<< - * **block_offset_copy) - * - */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 399, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_12 = PySlice_New(__pyx_v_y_start, __pyx_v_y_end, Py_None); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 399, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_16 = PySlice_New(__pyx_v_x_start, __pyx_v_x_end, Py_None); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 399, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_24 = PyTuple_New(2); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 399, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_24); - __Pyx_GIVEREF(__pyx_t_12); - PyTuple_SET_ITEM(__pyx_t_24, 0, __pyx_t_12); - __Pyx_GIVEREF(__pyx_t_16); - PyTuple_SET_ITEM(__pyx_t_24, 1, __pyx_t_16); - __pyx_t_12 = 0; - __pyx_t_16 = 0; - __pyx_t_16 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_dem_array), __pyx_t_24); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 399, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_buf_obj, __pyx_t_16) < 0) __PYX_ERR(0, 399, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_2 = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":400 - * dem_band.ReadAsArray( - * buf_obj=dem_array[y_start:y_end, x_start:x_end], - * **block_offset_copy) # <<<<<<<<<<<<<< - * - * for row_index in range(1, win_ysize+1): - */ - if (unlikely(__pyx_v_block_offset_copy == Py_None)) { - PyErr_SetString(PyExc_TypeError, "argument after ** must be a mapping, not NoneType"); - __PYX_ERR(0, 400, __pyx_L1_error) - } - if (__Pyx_MergeKeywords(__pyx_t_2, __pyx_v_block_offset_copy) < 0) __PYX_ERR(0, 400, __pyx_L1_error) - - /* "pygeoprocessing/geoprocessing_core.pyx":398 - * dtype=numpy.float64) - * - * dem_band.ReadAsArray( # <<<<<<<<<<<<<< - * buf_obj=dem_array[y_start:y_end, x_start:x_end], - * **block_offset_copy) - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_empty_tuple, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 398, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":402 - * **block_offset_copy) - * - * for row_index in range(1, win_ysize+1): # <<<<<<<<<<<<<< - * for col_index in range(1, win_xsize+1): - * # Notation of the cell below comes from the algorithm - */ - __pyx_t_25 = (__pyx_v_win_ysize + 1); - __pyx_t_26 = __pyx_t_25; - for (__pyx_t_11 = 1; __pyx_t_11 < __pyx_t_26; __pyx_t_11+=1) { - __pyx_v_row_index = __pyx_t_11; - - /* "pygeoprocessing/geoprocessing_core.pyx":403 - * - * for row_index in range(1, win_ysize+1): - * for col_index in range(1, win_xsize+1): # <<<<<<<<<<<<<< - * # Notation of the cell below comes from the algorithm - * # description, cells are arraged as follows: - */ - __pyx_t_27 = (__pyx_v_win_xsize + 1); - __pyx_t_28 = __pyx_t_27; - for (__pyx_t_10 = 1; __pyx_t_10 < __pyx_t_28; __pyx_t_10+=1) { - __pyx_v_col_index = __pyx_t_10; - - /* "pygeoprocessing/geoprocessing_core.pyx":409 - * # def - * # ghi - * e = dem_array[row_index, col_index] # <<<<<<<<<<<<<< - * if e == dem_nodata: - * # we use dzdx as a guard below, no need to set dzdy - */ - __pyx_t_29 = __pyx_v_row_index; - __pyx_t_30 = __pyx_v_col_index; - __pyx_v_e = (*__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_dem_array.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_dem_array.diminfo[1].strides)); - - /* "pygeoprocessing/geoprocessing_core.pyx":410 - * # ghi - * e = dem_array[row_index, col_index] - * if e == dem_nodata: # <<<<<<<<<<<<<< - * # we use dzdx as a guard below, no need to set dzdy - * dzdx_array[row_index-1, col_index-1] = slope_nodata - */ - __pyx_t_6 = ((__pyx_v_e == __pyx_v_dem_nodata) != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":412 - * if e == dem_nodata: - * # we use dzdx as a guard below, no need to set dzdy - * dzdx_array[row_index-1, col_index-1] = slope_nodata # <<<<<<<<<<<<<< - * continue - * dzdx_accumulator = 0.0 - */ - __pyx_t_30 = (__pyx_v_row_index - 1); - __pyx_t_29 = (__pyx_v_col_index - 1); - *__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_dzdx_array.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_dzdx_array.diminfo[1].strides) = __pyx_v_slope_nodata; - - /* "pygeoprocessing/geoprocessing_core.pyx":413 - * # we use dzdx as a guard below, no need to set dzdy - * dzdx_array[row_index-1, col_index-1] = slope_nodata - * continue # <<<<<<<<<<<<<< - * dzdx_accumulator = 0.0 - * dzdy_accumulator = 0.0 - */ - goto __pyx_L16_continue; - - /* "pygeoprocessing/geoprocessing_core.pyx":410 - * # ghi - * e = dem_array[row_index, col_index] - * if e == dem_nodata: # <<<<<<<<<<<<<< - * # we use dzdx as a guard below, no need to set dzdy - * dzdx_array[row_index-1, col_index-1] = slope_nodata - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":414 - * dzdx_array[row_index-1, col_index-1] = slope_nodata - * continue - * dzdx_accumulator = 0.0 # <<<<<<<<<<<<<< - * dzdy_accumulator = 0.0 - * x_denom_factor = 0 - */ - __pyx_v_dzdx_accumulator = 0.0; - - /* "pygeoprocessing/geoprocessing_core.pyx":415 - * continue - * dzdx_accumulator = 0.0 - * dzdy_accumulator = 0.0 # <<<<<<<<<<<<<< - * x_denom_factor = 0 - * y_denom_factor = 0 - */ - __pyx_v_dzdy_accumulator = 0.0; - - /* "pygeoprocessing/geoprocessing_core.pyx":416 - * dzdx_accumulator = 0.0 - * dzdy_accumulator = 0.0 - * x_denom_factor = 0 # <<<<<<<<<<<<<< - * y_denom_factor = 0 - * a = dem_array[row_index-1, col_index-1] - */ - __pyx_v_x_denom_factor = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":417 - * dzdy_accumulator = 0.0 - * x_denom_factor = 0 - * y_denom_factor = 0 # <<<<<<<<<<<<<< - * a = dem_array[row_index-1, col_index-1] - * b = dem_array[row_index-1, col_index] - */ - __pyx_v_y_denom_factor = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":418 - * x_denom_factor = 0 - * y_denom_factor = 0 - * a = dem_array[row_index-1, col_index-1] # <<<<<<<<<<<<<< - * b = dem_array[row_index-1, col_index] - * c = dem_array[row_index-1, col_index+1] - */ - __pyx_t_29 = (__pyx_v_row_index - 1); - __pyx_t_30 = (__pyx_v_col_index - 1); - __pyx_v_a = (*__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_dem_array.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_dem_array.diminfo[1].strides)); - - /* "pygeoprocessing/geoprocessing_core.pyx":419 - * y_denom_factor = 0 - * a = dem_array[row_index-1, col_index-1] - * b = dem_array[row_index-1, col_index] # <<<<<<<<<<<<<< - * c = dem_array[row_index-1, col_index+1] - * d = dem_array[row_index, col_index-1] - */ - __pyx_t_30 = (__pyx_v_row_index - 1); - __pyx_t_29 = __pyx_v_col_index; - __pyx_v_b = (*__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_dem_array.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_dem_array.diminfo[1].strides)); - - /* "pygeoprocessing/geoprocessing_core.pyx":420 - * a = dem_array[row_index-1, col_index-1] - * b = dem_array[row_index-1, col_index] - * c = dem_array[row_index-1, col_index+1] # <<<<<<<<<<<<<< - * d = dem_array[row_index, col_index-1] - * f = dem_array[row_index, col_index+1] - */ - __pyx_t_29 = (__pyx_v_row_index - 1); - __pyx_t_30 = (__pyx_v_col_index + 1); - __pyx_v_c = (*__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_dem_array.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_dem_array.diminfo[1].strides)); - - /* "pygeoprocessing/geoprocessing_core.pyx":421 - * b = dem_array[row_index-1, col_index] - * c = dem_array[row_index-1, col_index+1] - * d = dem_array[row_index, col_index-1] # <<<<<<<<<<<<<< - * f = dem_array[row_index, col_index+1] - * g = dem_array[row_index+1, col_index-1] - */ - __pyx_t_30 = __pyx_v_row_index; - __pyx_t_29 = (__pyx_v_col_index - 1); - __pyx_v_d = (*__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_dem_array.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_dem_array.diminfo[1].strides)); - - /* "pygeoprocessing/geoprocessing_core.pyx":422 - * c = dem_array[row_index-1, col_index+1] - * d = dem_array[row_index, col_index-1] - * f = dem_array[row_index, col_index+1] # <<<<<<<<<<<<<< - * g = dem_array[row_index+1, col_index-1] - * h = dem_array[row_index+1, col_index] - */ - __pyx_t_29 = __pyx_v_row_index; - __pyx_t_30 = (__pyx_v_col_index + 1); - __pyx_v_f = (*__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_dem_array.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_dem_array.diminfo[1].strides)); - - /* "pygeoprocessing/geoprocessing_core.pyx":423 - * d = dem_array[row_index, col_index-1] - * f = dem_array[row_index, col_index+1] - * g = dem_array[row_index+1, col_index-1] # <<<<<<<<<<<<<< - * h = dem_array[row_index+1, col_index] - * i = dem_array[row_index+1, col_index+1] - */ - __pyx_t_30 = (__pyx_v_row_index + 1); - __pyx_t_29 = (__pyx_v_col_index - 1); - __pyx_v_g = (*__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_dem_array.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_dem_array.diminfo[1].strides)); - - /* "pygeoprocessing/geoprocessing_core.pyx":424 - * f = dem_array[row_index, col_index+1] - * g = dem_array[row_index+1, col_index-1] - * h = dem_array[row_index+1, col_index] # <<<<<<<<<<<<<< - * i = dem_array[row_index+1, col_index+1] - * - */ - __pyx_t_29 = (__pyx_v_row_index + 1); - __pyx_t_30 = __pyx_v_col_index; - __pyx_v_h = (*__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_dem_array.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_dem_array.diminfo[1].strides)); - - /* "pygeoprocessing/geoprocessing_core.pyx":425 - * g = dem_array[row_index+1, col_index-1] - * h = dem_array[row_index+1, col_index] - * i = dem_array[row_index+1, col_index+1] # <<<<<<<<<<<<<< - * - * # a - c direction - */ - __pyx_t_30 = (__pyx_v_row_index + 1); - __pyx_t_29 = (__pyx_v_col_index + 1); - __pyx_v_i = (*__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dem_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_dem_array.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_dem_array.diminfo[1].strides)); - - /* "pygeoprocessing/geoprocessing_core.pyx":428 - * - * # a - c direction - * if a != dem_nodata and c != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += a - c - * x_denom_factor += 2 - */ - __pyx_t_5 = ((__pyx_v_a != __pyx_v_dem_nodata) != 0); - if (__pyx_t_5) { - } else { - __pyx_t_6 = __pyx_t_5; - goto __pyx_L20_bool_binop_done; - } - __pyx_t_5 = ((__pyx_v_c != __pyx_v_dem_nodata) != 0); - __pyx_t_6 = __pyx_t_5; - __pyx_L20_bool_binop_done:; - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":429 - * # a - c direction - * if a != dem_nodata and c != dem_nodata: - * dzdx_accumulator += a - c # <<<<<<<<<<<<<< - * x_denom_factor += 2 - * elif a != dem_nodata and b != dem_nodata: - */ - __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + (__pyx_v_a - __pyx_v_c)); - - /* "pygeoprocessing/geoprocessing_core.pyx":430 - * if a != dem_nodata and c != dem_nodata: - * dzdx_accumulator += a - c - * x_denom_factor += 2 # <<<<<<<<<<<<<< - * elif a != dem_nodata and b != dem_nodata: - * dzdx_accumulator += a - b - */ - __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 2); - - /* "pygeoprocessing/geoprocessing_core.pyx":428 - * - * # a - c direction - * if a != dem_nodata and c != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += a - c - * x_denom_factor += 2 - */ - goto __pyx_L19; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":431 - * dzdx_accumulator += a - c - * x_denom_factor += 2 - * elif a != dem_nodata and b != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += a - b - * x_denom_factor += 1 - */ - __pyx_t_5 = ((__pyx_v_a != __pyx_v_dem_nodata) != 0); - if (__pyx_t_5) { - } else { - __pyx_t_6 = __pyx_t_5; - goto __pyx_L22_bool_binop_done; - } - __pyx_t_5 = ((__pyx_v_b != __pyx_v_dem_nodata) != 0); - __pyx_t_6 = __pyx_t_5; - __pyx_L22_bool_binop_done:; - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":432 - * x_denom_factor += 2 - * elif a != dem_nodata and b != dem_nodata: - * dzdx_accumulator += a - b # <<<<<<<<<<<<<< - * x_denom_factor += 1 - * elif b != dem_nodata and c != dem_nodata: - */ - __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + (__pyx_v_a - __pyx_v_b)); - - /* "pygeoprocessing/geoprocessing_core.pyx":433 - * elif a != dem_nodata and b != dem_nodata: - * dzdx_accumulator += a - b - * x_denom_factor += 1 # <<<<<<<<<<<<<< - * elif b != dem_nodata and c != dem_nodata: - * dzdx_accumulator += b - c - */ - __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 1); - - /* "pygeoprocessing/geoprocessing_core.pyx":431 - * dzdx_accumulator += a - c - * x_denom_factor += 2 - * elif a != dem_nodata and b != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += a - b - * x_denom_factor += 1 - */ - goto __pyx_L19; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":434 - * dzdx_accumulator += a - b - * x_denom_factor += 1 - * elif b != dem_nodata and c != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += b - c - * x_denom_factor += 1 - */ - __pyx_t_5 = ((__pyx_v_b != __pyx_v_dem_nodata) != 0); - if (__pyx_t_5) { - } else { - __pyx_t_6 = __pyx_t_5; - goto __pyx_L24_bool_binop_done; - } - __pyx_t_5 = ((__pyx_v_c != __pyx_v_dem_nodata) != 0); - __pyx_t_6 = __pyx_t_5; - __pyx_L24_bool_binop_done:; - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":435 - * x_denom_factor += 1 - * elif b != dem_nodata and c != dem_nodata: - * dzdx_accumulator += b - c # <<<<<<<<<<<<<< - * x_denom_factor += 1 - * elif a != dem_nodata: - */ - __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + (__pyx_v_b - __pyx_v_c)); - - /* "pygeoprocessing/geoprocessing_core.pyx":436 - * elif b != dem_nodata and c != dem_nodata: - * dzdx_accumulator += b - c - * x_denom_factor += 1 # <<<<<<<<<<<<<< - * elif a != dem_nodata: - * dzdx_accumulator += (a - e) * 2**0.5 - */ - __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 1); - - /* "pygeoprocessing/geoprocessing_core.pyx":434 - * dzdx_accumulator += a - b - * x_denom_factor += 1 - * elif b != dem_nodata and c != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += b - c - * x_denom_factor += 1 - */ - goto __pyx_L19; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":437 - * dzdx_accumulator += b - c - * x_denom_factor += 1 - * elif a != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += (a - e) * 2**0.5 - * x_denom_factor += 1 - */ - __pyx_t_6 = ((__pyx_v_a != __pyx_v_dem_nodata) != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":438 - * x_denom_factor += 1 - * elif a != dem_nodata: - * dzdx_accumulator += (a - e) * 2**0.5 # <<<<<<<<<<<<<< - * x_denom_factor += 1 - * elif c != dem_nodata: - */ - __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + ((__pyx_v_a - __pyx_v_e) * pow(2.0, 0.5))); - - /* "pygeoprocessing/geoprocessing_core.pyx":439 - * elif a != dem_nodata: - * dzdx_accumulator += (a - e) * 2**0.5 - * x_denom_factor += 1 # <<<<<<<<<<<<<< - * elif c != dem_nodata: - * dzdx_accumulator += (e - c) * 2**0.5 - */ - __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 1); - - /* "pygeoprocessing/geoprocessing_core.pyx":437 - * dzdx_accumulator += b - c - * x_denom_factor += 1 - * elif a != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += (a - e) * 2**0.5 - * x_denom_factor += 1 - */ - goto __pyx_L19; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":440 - * dzdx_accumulator += (a - e) * 2**0.5 - * x_denom_factor += 1 - * elif c != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += (e - c) * 2**0.5 - * x_denom_factor += 1 - */ - __pyx_t_6 = ((__pyx_v_c != __pyx_v_dem_nodata) != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":441 - * x_denom_factor += 1 - * elif c != dem_nodata: - * dzdx_accumulator += (e - c) * 2**0.5 # <<<<<<<<<<<<<< - * x_denom_factor += 1 - * - */ - __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + ((__pyx_v_e - __pyx_v_c) * pow(2.0, 0.5))); - - /* "pygeoprocessing/geoprocessing_core.pyx":442 - * elif c != dem_nodata: - * dzdx_accumulator += (e - c) * 2**0.5 - * x_denom_factor += 1 # <<<<<<<<<<<<<< - * - * # d - f direction - */ - __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 1); - - /* "pygeoprocessing/geoprocessing_core.pyx":440 - * dzdx_accumulator += (a - e) * 2**0.5 - * x_denom_factor += 1 - * elif c != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += (e - c) * 2**0.5 - * x_denom_factor += 1 - */ - } - __pyx_L19:; - - /* "pygeoprocessing/geoprocessing_core.pyx":445 - * - * # d - f direction - * if d != dem_nodata and f != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += 2 * (d - f) - * x_denom_factor += 4 - */ - __pyx_t_5 = ((__pyx_v_d != __pyx_v_dem_nodata) != 0); - if (__pyx_t_5) { - } else { - __pyx_t_6 = __pyx_t_5; - goto __pyx_L27_bool_binop_done; - } - __pyx_t_5 = ((__pyx_v_f != __pyx_v_dem_nodata) != 0); - __pyx_t_6 = __pyx_t_5; - __pyx_L27_bool_binop_done:; - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":446 - * # d - f direction - * if d != dem_nodata and f != dem_nodata: - * dzdx_accumulator += 2 * (d - f) # <<<<<<<<<<<<<< - * x_denom_factor += 4 - * elif d != dem_nodata: - */ - __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + (2.0 * (__pyx_v_d - __pyx_v_f))); - - /* "pygeoprocessing/geoprocessing_core.pyx":447 - * if d != dem_nodata and f != dem_nodata: - * dzdx_accumulator += 2 * (d - f) - * x_denom_factor += 4 # <<<<<<<<<<<<<< - * elif d != dem_nodata: - * dzdx_accumulator += 2 * (d - e) - */ - __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 4); - - /* "pygeoprocessing/geoprocessing_core.pyx":445 - * - * # d - f direction - * if d != dem_nodata and f != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += 2 * (d - f) - * x_denom_factor += 4 - */ - goto __pyx_L26; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":448 - * dzdx_accumulator += 2 * (d - f) - * x_denom_factor += 4 - * elif d != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += 2 * (d - e) - * x_denom_factor += 2 - */ - __pyx_t_6 = ((__pyx_v_d != __pyx_v_dem_nodata) != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":449 - * x_denom_factor += 4 - * elif d != dem_nodata: - * dzdx_accumulator += 2 * (d - e) # <<<<<<<<<<<<<< - * x_denom_factor += 2 - * elif f != dem_nodata: - */ - __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + (2.0 * (__pyx_v_d - __pyx_v_e))); - - /* "pygeoprocessing/geoprocessing_core.pyx":450 - * elif d != dem_nodata: - * dzdx_accumulator += 2 * (d - e) - * x_denom_factor += 2 # <<<<<<<<<<<<<< - * elif f != dem_nodata: - * dzdx_accumulator += 2 * (e - f) - */ - __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 2); - - /* "pygeoprocessing/geoprocessing_core.pyx":448 - * dzdx_accumulator += 2 * (d - f) - * x_denom_factor += 4 - * elif d != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += 2 * (d - e) - * x_denom_factor += 2 - */ - goto __pyx_L26; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":451 - * dzdx_accumulator += 2 * (d - e) - * x_denom_factor += 2 - * elif f != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += 2 * (e - f) - * x_denom_factor += 2 - */ - __pyx_t_6 = ((__pyx_v_f != __pyx_v_dem_nodata) != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":452 - * x_denom_factor += 2 - * elif f != dem_nodata: - * dzdx_accumulator += 2 * (e - f) # <<<<<<<<<<<<<< - * x_denom_factor += 2 - * - */ - __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + (2.0 * (__pyx_v_e - __pyx_v_f))); - - /* "pygeoprocessing/geoprocessing_core.pyx":453 - * elif f != dem_nodata: - * dzdx_accumulator += 2 * (e - f) - * x_denom_factor += 2 # <<<<<<<<<<<<<< - * - * # g - i direction - */ - __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 2); - - /* "pygeoprocessing/geoprocessing_core.pyx":451 - * dzdx_accumulator += 2 * (d - e) - * x_denom_factor += 2 - * elif f != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += 2 * (e - f) - * x_denom_factor += 2 - */ - } - __pyx_L26:; - - /* "pygeoprocessing/geoprocessing_core.pyx":456 - * - * # g - i direction - * if g != dem_nodata and i != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += g - i - * x_denom_factor += 2 - */ - __pyx_t_5 = ((__pyx_v_g != __pyx_v_dem_nodata) != 0); - if (__pyx_t_5) { - } else { - __pyx_t_6 = __pyx_t_5; - goto __pyx_L30_bool_binop_done; - } - __pyx_t_5 = ((__pyx_v_i != __pyx_v_dem_nodata) != 0); - __pyx_t_6 = __pyx_t_5; - __pyx_L30_bool_binop_done:; - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":457 - * # g - i direction - * if g != dem_nodata and i != dem_nodata: - * dzdx_accumulator += g - i # <<<<<<<<<<<<<< - * x_denom_factor += 2 - * elif g != dem_nodata and h != dem_nodata: - */ - __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + (__pyx_v_g - __pyx_v_i)); - - /* "pygeoprocessing/geoprocessing_core.pyx":458 - * if g != dem_nodata and i != dem_nodata: - * dzdx_accumulator += g - i - * x_denom_factor += 2 # <<<<<<<<<<<<<< - * elif g != dem_nodata and h != dem_nodata: - * dzdx_accumulator += g - h - */ - __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 2); - - /* "pygeoprocessing/geoprocessing_core.pyx":456 - * - * # g - i direction - * if g != dem_nodata and i != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += g - i - * x_denom_factor += 2 - */ - goto __pyx_L29; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":459 - * dzdx_accumulator += g - i - * x_denom_factor += 2 - * elif g != dem_nodata and h != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += g - h - * x_denom_factor += 1 - */ - __pyx_t_5 = ((__pyx_v_g != __pyx_v_dem_nodata) != 0); - if (__pyx_t_5) { - } else { - __pyx_t_6 = __pyx_t_5; - goto __pyx_L32_bool_binop_done; - } - __pyx_t_5 = ((__pyx_v_h != __pyx_v_dem_nodata) != 0); - __pyx_t_6 = __pyx_t_5; - __pyx_L32_bool_binop_done:; - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":460 - * x_denom_factor += 2 - * elif g != dem_nodata and h != dem_nodata: - * dzdx_accumulator += g - h # <<<<<<<<<<<<<< - * x_denom_factor += 1 - * elif h != dem_nodata and i != dem_nodata: - */ - __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + (__pyx_v_g - __pyx_v_h)); - - /* "pygeoprocessing/geoprocessing_core.pyx":461 - * elif g != dem_nodata and h != dem_nodata: - * dzdx_accumulator += g - h - * x_denom_factor += 1 # <<<<<<<<<<<<<< - * elif h != dem_nodata and i != dem_nodata: - * dzdx_accumulator += h - i - */ - __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 1); - - /* "pygeoprocessing/geoprocessing_core.pyx":459 - * dzdx_accumulator += g - i - * x_denom_factor += 2 - * elif g != dem_nodata and h != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += g - h - * x_denom_factor += 1 - */ - goto __pyx_L29; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":462 - * dzdx_accumulator += g - h - * x_denom_factor += 1 - * elif h != dem_nodata and i != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += h - i - * x_denom_factor += 1 - */ - __pyx_t_5 = ((__pyx_v_h != __pyx_v_dem_nodata) != 0); - if (__pyx_t_5) { - } else { - __pyx_t_6 = __pyx_t_5; - goto __pyx_L34_bool_binop_done; - } - __pyx_t_5 = ((__pyx_v_i != __pyx_v_dem_nodata) != 0); - __pyx_t_6 = __pyx_t_5; - __pyx_L34_bool_binop_done:; - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":463 - * x_denom_factor += 1 - * elif h != dem_nodata and i != dem_nodata: - * dzdx_accumulator += h - i # <<<<<<<<<<<<<< - * x_denom_factor += 1 - * elif g != dem_nodata: - */ - __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + (__pyx_v_h - __pyx_v_i)); - - /* "pygeoprocessing/geoprocessing_core.pyx":464 - * elif h != dem_nodata and i != dem_nodata: - * dzdx_accumulator += h - i - * x_denom_factor += 1 # <<<<<<<<<<<<<< - * elif g != dem_nodata: - * dzdx_accumulator += (g - e) * 2**0.5 - */ - __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 1); - - /* "pygeoprocessing/geoprocessing_core.pyx":462 - * dzdx_accumulator += g - h - * x_denom_factor += 1 - * elif h != dem_nodata and i != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += h - i - * x_denom_factor += 1 - */ - goto __pyx_L29; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":465 - * dzdx_accumulator += h - i - * x_denom_factor += 1 - * elif g != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += (g - e) * 2**0.5 - * x_denom_factor += 1 - */ - __pyx_t_6 = ((__pyx_v_g != __pyx_v_dem_nodata) != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":466 - * x_denom_factor += 1 - * elif g != dem_nodata: - * dzdx_accumulator += (g - e) * 2**0.5 # <<<<<<<<<<<<<< - * x_denom_factor += 1 - * elif i != dem_nodata: - */ - __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + ((__pyx_v_g - __pyx_v_e) * pow(2.0, 0.5))); - - /* "pygeoprocessing/geoprocessing_core.pyx":467 - * elif g != dem_nodata: - * dzdx_accumulator += (g - e) * 2**0.5 - * x_denom_factor += 1 # <<<<<<<<<<<<<< - * elif i != dem_nodata: - * dzdx_accumulator += (e - i) * 2**0.5 - */ - __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 1); - - /* "pygeoprocessing/geoprocessing_core.pyx":465 - * dzdx_accumulator += h - i - * x_denom_factor += 1 - * elif g != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += (g - e) * 2**0.5 - * x_denom_factor += 1 - */ - goto __pyx_L29; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":468 - * dzdx_accumulator += (g - e) * 2**0.5 - * x_denom_factor += 1 - * elif i != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += (e - i) * 2**0.5 - * x_denom_factor += 1 - */ - __pyx_t_6 = ((__pyx_v_i != __pyx_v_dem_nodata) != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":469 - * x_denom_factor += 1 - * elif i != dem_nodata: - * dzdx_accumulator += (e - i) * 2**0.5 # <<<<<<<<<<<<<< - * x_denom_factor += 1 - * - */ - __pyx_v_dzdx_accumulator = (__pyx_v_dzdx_accumulator + ((__pyx_v_e - __pyx_v_i) * pow(2.0, 0.5))); - - /* "pygeoprocessing/geoprocessing_core.pyx":470 - * elif i != dem_nodata: - * dzdx_accumulator += (e - i) * 2**0.5 - * x_denom_factor += 1 # <<<<<<<<<<<<<< - * - * # a - g direction - */ - __pyx_v_x_denom_factor = (__pyx_v_x_denom_factor + 1); - - /* "pygeoprocessing/geoprocessing_core.pyx":468 - * dzdx_accumulator += (g - e) * 2**0.5 - * x_denom_factor += 1 - * elif i != dem_nodata: # <<<<<<<<<<<<<< - * dzdx_accumulator += (e - i) * 2**0.5 - * x_denom_factor += 1 - */ - } - __pyx_L29:; - - /* "pygeoprocessing/geoprocessing_core.pyx":473 - * - * # a - g direction - * if a != dem_nodata and g != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += a - g - * y_denom_factor += 2 - */ - __pyx_t_5 = ((__pyx_v_a != __pyx_v_dem_nodata) != 0); - if (__pyx_t_5) { - } else { - __pyx_t_6 = __pyx_t_5; - goto __pyx_L37_bool_binop_done; - } - __pyx_t_5 = ((__pyx_v_g != __pyx_v_dem_nodata) != 0); - __pyx_t_6 = __pyx_t_5; - __pyx_L37_bool_binop_done:; - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":474 - * # a - g direction - * if a != dem_nodata and g != dem_nodata: - * dzdy_accumulator += a - g # <<<<<<<<<<<<<< - * y_denom_factor += 2 - * elif a != dem_nodata and d != dem_nodata: - */ - __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + (__pyx_v_a - __pyx_v_g)); - - /* "pygeoprocessing/geoprocessing_core.pyx":475 - * if a != dem_nodata and g != dem_nodata: - * dzdy_accumulator += a - g - * y_denom_factor += 2 # <<<<<<<<<<<<<< - * elif a != dem_nodata and d != dem_nodata: - * dzdy_accumulator += a - d - */ - __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 2); - - /* "pygeoprocessing/geoprocessing_core.pyx":473 - * - * # a - g direction - * if a != dem_nodata and g != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += a - g - * y_denom_factor += 2 - */ - goto __pyx_L36; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":476 - * dzdy_accumulator += a - g - * y_denom_factor += 2 - * elif a != dem_nodata and d != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += a - d - * y_denom_factor += 1 - */ - __pyx_t_5 = ((__pyx_v_a != __pyx_v_dem_nodata) != 0); - if (__pyx_t_5) { - } else { - __pyx_t_6 = __pyx_t_5; - goto __pyx_L39_bool_binop_done; - } - __pyx_t_5 = ((__pyx_v_d != __pyx_v_dem_nodata) != 0); - __pyx_t_6 = __pyx_t_5; - __pyx_L39_bool_binop_done:; - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":477 - * y_denom_factor += 2 - * elif a != dem_nodata and d != dem_nodata: - * dzdy_accumulator += a - d # <<<<<<<<<<<<<< - * y_denom_factor += 1 - * elif d != dem_nodata and g != dem_nodata: - */ - __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + (__pyx_v_a - __pyx_v_d)); - - /* "pygeoprocessing/geoprocessing_core.pyx":478 - * elif a != dem_nodata and d != dem_nodata: - * dzdy_accumulator += a - d - * y_denom_factor += 1 # <<<<<<<<<<<<<< - * elif d != dem_nodata and g != dem_nodata: - * dzdy_accumulator += d - g - */ - __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 1); - - /* "pygeoprocessing/geoprocessing_core.pyx":476 - * dzdy_accumulator += a - g - * y_denom_factor += 2 - * elif a != dem_nodata and d != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += a - d - * y_denom_factor += 1 - */ - goto __pyx_L36; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":479 - * dzdy_accumulator += a - d - * y_denom_factor += 1 - * elif d != dem_nodata and g != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += d - g - * y_denom_factor += 1 - */ - __pyx_t_5 = ((__pyx_v_d != __pyx_v_dem_nodata) != 0); - if (__pyx_t_5) { - } else { - __pyx_t_6 = __pyx_t_5; - goto __pyx_L41_bool_binop_done; - } - __pyx_t_5 = ((__pyx_v_g != __pyx_v_dem_nodata) != 0); - __pyx_t_6 = __pyx_t_5; - __pyx_L41_bool_binop_done:; - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":480 - * y_denom_factor += 1 - * elif d != dem_nodata and g != dem_nodata: - * dzdy_accumulator += d - g # <<<<<<<<<<<<<< - * y_denom_factor += 1 - * elif a != dem_nodata: - */ - __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + (__pyx_v_d - __pyx_v_g)); - - /* "pygeoprocessing/geoprocessing_core.pyx":481 - * elif d != dem_nodata and g != dem_nodata: - * dzdy_accumulator += d - g - * y_denom_factor += 1 # <<<<<<<<<<<<<< - * elif a != dem_nodata: - * dzdy_accumulator += (a - e) * 2**0.5 - */ - __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 1); - - /* "pygeoprocessing/geoprocessing_core.pyx":479 - * dzdy_accumulator += a - d - * y_denom_factor += 1 - * elif d != dem_nodata and g != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += d - g - * y_denom_factor += 1 - */ - goto __pyx_L36; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":482 - * dzdy_accumulator += d - g - * y_denom_factor += 1 - * elif a != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += (a - e) * 2**0.5 - * y_denom_factor += 1 - */ - __pyx_t_6 = ((__pyx_v_a != __pyx_v_dem_nodata) != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":483 - * y_denom_factor += 1 - * elif a != dem_nodata: - * dzdy_accumulator += (a - e) * 2**0.5 # <<<<<<<<<<<<<< - * y_denom_factor += 1 - * elif g != dem_nodata: - */ - __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + ((__pyx_v_a - __pyx_v_e) * pow(2.0, 0.5))); - - /* "pygeoprocessing/geoprocessing_core.pyx":484 - * elif a != dem_nodata: - * dzdy_accumulator += (a - e) * 2**0.5 - * y_denom_factor += 1 # <<<<<<<<<<<<<< - * elif g != dem_nodata: - * dzdy_accumulator += (e - g) * 2**0.5 - */ - __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 1); - - /* "pygeoprocessing/geoprocessing_core.pyx":482 - * dzdy_accumulator += d - g - * y_denom_factor += 1 - * elif a != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += (a - e) * 2**0.5 - * y_denom_factor += 1 - */ - goto __pyx_L36; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":485 - * dzdy_accumulator += (a - e) * 2**0.5 - * y_denom_factor += 1 - * elif g != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += (e - g) * 2**0.5 - * y_denom_factor += 1 - */ - __pyx_t_6 = ((__pyx_v_g != __pyx_v_dem_nodata) != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":486 - * y_denom_factor += 1 - * elif g != dem_nodata: - * dzdy_accumulator += (e - g) * 2**0.5 # <<<<<<<<<<<<<< - * y_denom_factor += 1 - * - */ - __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + ((__pyx_v_e - __pyx_v_g) * pow(2.0, 0.5))); - - /* "pygeoprocessing/geoprocessing_core.pyx":487 - * elif g != dem_nodata: - * dzdy_accumulator += (e - g) * 2**0.5 - * y_denom_factor += 1 # <<<<<<<<<<<<<< - * - * # b - h direction - */ - __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 1); - - /* "pygeoprocessing/geoprocessing_core.pyx":485 - * dzdy_accumulator += (a - e) * 2**0.5 - * y_denom_factor += 1 - * elif g != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += (e - g) * 2**0.5 - * y_denom_factor += 1 - */ - } - __pyx_L36:; - - /* "pygeoprocessing/geoprocessing_core.pyx":490 - * - * # b - h direction - * if b != dem_nodata and h != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += 2 * (b - h) - * y_denom_factor += 4 - */ - __pyx_t_5 = ((__pyx_v_b != __pyx_v_dem_nodata) != 0); - if (__pyx_t_5) { - } else { - __pyx_t_6 = __pyx_t_5; - goto __pyx_L44_bool_binop_done; - } - __pyx_t_5 = ((__pyx_v_h != __pyx_v_dem_nodata) != 0); - __pyx_t_6 = __pyx_t_5; - __pyx_L44_bool_binop_done:; - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":491 - * # b - h direction - * if b != dem_nodata and h != dem_nodata: - * dzdy_accumulator += 2 * (b - h) # <<<<<<<<<<<<<< - * y_denom_factor += 4 - * elif b != dem_nodata: - */ - __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + (2.0 * (__pyx_v_b - __pyx_v_h))); - - /* "pygeoprocessing/geoprocessing_core.pyx":492 - * if b != dem_nodata and h != dem_nodata: - * dzdy_accumulator += 2 * (b - h) - * y_denom_factor += 4 # <<<<<<<<<<<<<< - * elif b != dem_nodata: - * dzdy_accumulator += 2 * (b - e) - */ - __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 4); - - /* "pygeoprocessing/geoprocessing_core.pyx":490 - * - * # b - h direction - * if b != dem_nodata and h != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += 2 * (b - h) - * y_denom_factor += 4 - */ - goto __pyx_L43; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":493 - * dzdy_accumulator += 2 * (b - h) - * y_denom_factor += 4 - * elif b != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += 2 * (b - e) - * y_denom_factor += 2 - */ - __pyx_t_6 = ((__pyx_v_b != __pyx_v_dem_nodata) != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":494 - * y_denom_factor += 4 - * elif b != dem_nodata: - * dzdy_accumulator += 2 * (b - e) # <<<<<<<<<<<<<< - * y_denom_factor += 2 - * elif h != dem_nodata: - */ - __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + (2.0 * (__pyx_v_b - __pyx_v_e))); - - /* "pygeoprocessing/geoprocessing_core.pyx":495 - * elif b != dem_nodata: - * dzdy_accumulator += 2 * (b - e) - * y_denom_factor += 2 # <<<<<<<<<<<<<< - * elif h != dem_nodata: - * dzdy_accumulator += 2 * (e - h) - */ - __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 2); - - /* "pygeoprocessing/geoprocessing_core.pyx":493 - * dzdy_accumulator += 2 * (b - h) - * y_denom_factor += 4 - * elif b != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += 2 * (b - e) - * y_denom_factor += 2 - */ - goto __pyx_L43; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":496 - * dzdy_accumulator += 2 * (b - e) - * y_denom_factor += 2 - * elif h != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += 2 * (e - h) - * y_denom_factor += 2 - */ - __pyx_t_6 = ((__pyx_v_h != __pyx_v_dem_nodata) != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":497 - * y_denom_factor += 2 - * elif h != dem_nodata: - * dzdy_accumulator += 2 * (e - h) # <<<<<<<<<<<<<< - * y_denom_factor += 2 - * - */ - __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + (2.0 * (__pyx_v_e - __pyx_v_h))); - - /* "pygeoprocessing/geoprocessing_core.pyx":498 - * elif h != dem_nodata: - * dzdy_accumulator += 2 * (e - h) - * y_denom_factor += 2 # <<<<<<<<<<<<<< - * - * # c - i direction - */ - __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 2); - - /* "pygeoprocessing/geoprocessing_core.pyx":496 - * dzdy_accumulator += 2 * (b - e) - * y_denom_factor += 2 - * elif h != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += 2 * (e - h) - * y_denom_factor += 2 - */ - } - __pyx_L43:; - - /* "pygeoprocessing/geoprocessing_core.pyx":501 - * - * # c - i direction - * if c != dem_nodata and i != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += c - i - * y_denom_factor += 2 - */ - __pyx_t_5 = ((__pyx_v_c != __pyx_v_dem_nodata) != 0); - if (__pyx_t_5) { - } else { - __pyx_t_6 = __pyx_t_5; - goto __pyx_L47_bool_binop_done; - } - __pyx_t_5 = ((__pyx_v_i != __pyx_v_dem_nodata) != 0); - __pyx_t_6 = __pyx_t_5; - __pyx_L47_bool_binop_done:; - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":502 - * # c - i direction - * if c != dem_nodata and i != dem_nodata: - * dzdy_accumulator += c - i # <<<<<<<<<<<<<< - * y_denom_factor += 2 - * elif c != dem_nodata and f != dem_nodata: - */ - __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + (__pyx_v_c - __pyx_v_i)); - - /* "pygeoprocessing/geoprocessing_core.pyx":503 - * if c != dem_nodata and i != dem_nodata: - * dzdy_accumulator += c - i - * y_denom_factor += 2 # <<<<<<<<<<<<<< - * elif c != dem_nodata and f != dem_nodata: - * dzdy_accumulator += c - f - */ - __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 2); - - /* "pygeoprocessing/geoprocessing_core.pyx":501 - * - * # c - i direction - * if c != dem_nodata and i != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += c - i - * y_denom_factor += 2 - */ - goto __pyx_L46; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":504 - * dzdy_accumulator += c - i - * y_denom_factor += 2 - * elif c != dem_nodata and f != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += c - f - * y_denom_factor += 1 - */ - __pyx_t_5 = ((__pyx_v_c != __pyx_v_dem_nodata) != 0); - if (__pyx_t_5) { - } else { - __pyx_t_6 = __pyx_t_5; - goto __pyx_L49_bool_binop_done; - } - __pyx_t_5 = ((__pyx_v_f != __pyx_v_dem_nodata) != 0); - __pyx_t_6 = __pyx_t_5; - __pyx_L49_bool_binop_done:; - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":505 - * y_denom_factor += 2 - * elif c != dem_nodata and f != dem_nodata: - * dzdy_accumulator += c - f # <<<<<<<<<<<<<< - * y_denom_factor += 1 - * elif f != dem_nodata and i != dem_nodata: - */ - __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + (__pyx_v_c - __pyx_v_f)); - - /* "pygeoprocessing/geoprocessing_core.pyx":506 - * elif c != dem_nodata and f != dem_nodata: - * dzdy_accumulator += c - f - * y_denom_factor += 1 # <<<<<<<<<<<<<< - * elif f != dem_nodata and i != dem_nodata: - * dzdy_accumulator += f - i - */ - __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 1); - - /* "pygeoprocessing/geoprocessing_core.pyx":504 - * dzdy_accumulator += c - i - * y_denom_factor += 2 - * elif c != dem_nodata and f != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += c - f - * y_denom_factor += 1 - */ - goto __pyx_L46; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":507 - * dzdy_accumulator += c - f - * y_denom_factor += 1 - * elif f != dem_nodata and i != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += f - i - * y_denom_factor += 1 - */ - __pyx_t_5 = ((__pyx_v_f != __pyx_v_dem_nodata) != 0); - if (__pyx_t_5) { - } else { - __pyx_t_6 = __pyx_t_5; - goto __pyx_L51_bool_binop_done; - } - __pyx_t_5 = ((__pyx_v_i != __pyx_v_dem_nodata) != 0); - __pyx_t_6 = __pyx_t_5; - __pyx_L51_bool_binop_done:; - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":508 - * y_denom_factor += 1 - * elif f != dem_nodata and i != dem_nodata: - * dzdy_accumulator += f - i # <<<<<<<<<<<<<< - * y_denom_factor += 1 - * elif c != dem_nodata: - */ - __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + (__pyx_v_f - __pyx_v_i)); - - /* "pygeoprocessing/geoprocessing_core.pyx":509 - * elif f != dem_nodata and i != dem_nodata: - * dzdy_accumulator += f - i - * y_denom_factor += 1 # <<<<<<<<<<<<<< - * elif c != dem_nodata: - * dzdy_accumulator += (c - e) * 2**0.5 - */ - __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 1); - - /* "pygeoprocessing/geoprocessing_core.pyx":507 - * dzdy_accumulator += c - f - * y_denom_factor += 1 - * elif f != dem_nodata and i != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += f - i - * y_denom_factor += 1 - */ - goto __pyx_L46; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":510 - * dzdy_accumulator += f - i - * y_denom_factor += 1 - * elif c != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += (c - e) * 2**0.5 - * y_denom_factor += 1 - */ - __pyx_t_6 = ((__pyx_v_c != __pyx_v_dem_nodata) != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":511 - * y_denom_factor += 1 - * elif c != dem_nodata: - * dzdy_accumulator += (c - e) * 2**0.5 # <<<<<<<<<<<<<< - * y_denom_factor += 1 - * elif i != dem_nodata: - */ - __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + ((__pyx_v_c - __pyx_v_e) * pow(2.0, 0.5))); - - /* "pygeoprocessing/geoprocessing_core.pyx":512 - * elif c != dem_nodata: - * dzdy_accumulator += (c - e) * 2**0.5 - * y_denom_factor += 1 # <<<<<<<<<<<<<< - * elif i != dem_nodata: - * dzdy_accumulator += (e - i) * 2**0.5 - */ - __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 1); - - /* "pygeoprocessing/geoprocessing_core.pyx":510 - * dzdy_accumulator += f - i - * y_denom_factor += 1 - * elif c != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += (c - e) * 2**0.5 - * y_denom_factor += 1 - */ - goto __pyx_L46; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":513 - * dzdy_accumulator += (c - e) * 2**0.5 - * y_denom_factor += 1 - * elif i != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += (e - i) * 2**0.5 - * y_denom_factor += 1 - */ - __pyx_t_6 = ((__pyx_v_i != __pyx_v_dem_nodata) != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":514 - * y_denom_factor += 1 - * elif i != dem_nodata: - * dzdy_accumulator += (e - i) * 2**0.5 # <<<<<<<<<<<<<< - * y_denom_factor += 1 - * - */ - __pyx_v_dzdy_accumulator = (__pyx_v_dzdy_accumulator + ((__pyx_v_e - __pyx_v_i) * pow(2.0, 0.5))); - - /* "pygeoprocessing/geoprocessing_core.pyx":515 - * elif i != dem_nodata: - * dzdy_accumulator += (e - i) * 2**0.5 - * y_denom_factor += 1 # <<<<<<<<<<<<<< - * - * if x_denom_factor != 0: - */ - __pyx_v_y_denom_factor = (__pyx_v_y_denom_factor + 1); - - /* "pygeoprocessing/geoprocessing_core.pyx":513 - * dzdy_accumulator += (c - e) * 2**0.5 - * y_denom_factor += 1 - * elif i != dem_nodata: # <<<<<<<<<<<<<< - * dzdy_accumulator += (e - i) * 2**0.5 - * y_denom_factor += 1 - */ - } - __pyx_L46:; - - /* "pygeoprocessing/geoprocessing_core.pyx":517 - * y_denom_factor += 1 - * - * if x_denom_factor != 0: # <<<<<<<<<<<<<< - * dzdx_array[row_index-1, col_index-1] = ( - * dzdx_accumulator / (x_denom_factor * x_cell_size)) - */ - __pyx_t_6 = ((__pyx_v_x_denom_factor != 0) != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":518 - * - * if x_denom_factor != 0: - * dzdx_array[row_index-1, col_index-1] = ( # <<<<<<<<<<<<<< - * dzdx_accumulator / (x_denom_factor * x_cell_size)) - * else: - */ - __pyx_t_29 = (__pyx_v_row_index - 1); - __pyx_t_30 = (__pyx_v_col_index - 1); - *__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_dzdx_array.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_dzdx_array.diminfo[1].strides) = (__pyx_v_dzdx_accumulator / (__pyx_v_x_denom_factor * __pyx_v_x_cell_size)); - - /* "pygeoprocessing/geoprocessing_core.pyx":517 - * y_denom_factor += 1 - * - * if x_denom_factor != 0: # <<<<<<<<<<<<<< - * dzdx_array[row_index-1, col_index-1] = ( - * dzdx_accumulator / (x_denom_factor * x_cell_size)) - */ - goto __pyx_L53; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":521 - * dzdx_accumulator / (x_denom_factor * x_cell_size)) - * else: - * dzdx_array[row_index-1, col_index-1] = 0.0 # <<<<<<<<<<<<<< - * if y_denom_factor != 0: - * dzdy_array[row_index-1, col_index-1] = ( - */ - /*else*/ { - __pyx_t_30 = (__pyx_v_row_index - 1); - __pyx_t_29 = (__pyx_v_col_index - 1); - *__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_dzdx_array.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_dzdx_array.diminfo[1].strides) = 0.0; - } - __pyx_L53:; - - /* "pygeoprocessing/geoprocessing_core.pyx":522 - * else: - * dzdx_array[row_index-1, col_index-1] = 0.0 - * if y_denom_factor != 0: # <<<<<<<<<<<<<< - * dzdy_array[row_index-1, col_index-1] = ( - * dzdy_accumulator / (y_denom_factor * y_cell_size)) - */ - __pyx_t_6 = ((__pyx_v_y_denom_factor != 0) != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":523 - * dzdx_array[row_index-1, col_index-1] = 0.0 - * if y_denom_factor != 0: - * dzdy_array[row_index-1, col_index-1] = ( # <<<<<<<<<<<<<< - * dzdy_accumulator / (y_denom_factor * y_cell_size)) - * else: - */ - __pyx_t_29 = (__pyx_v_row_index - 1); - __pyx_t_30 = (__pyx_v_col_index - 1); - *__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dzdy_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_dzdy_array.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_dzdy_array.diminfo[1].strides) = (__pyx_v_dzdy_accumulator / (__pyx_v_y_denom_factor * __pyx_v_y_cell_size)); - - /* "pygeoprocessing/geoprocessing_core.pyx":522 - * else: - * dzdx_array[row_index-1, col_index-1] = 0.0 - * if y_denom_factor != 0: # <<<<<<<<<<<<<< - * dzdy_array[row_index-1, col_index-1] = ( - * dzdy_accumulator / (y_denom_factor * y_cell_size)) - */ - goto __pyx_L54; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":526 - * dzdy_accumulator / (y_denom_factor * y_cell_size)) - * else: - * dzdy_array[row_index-1, col_index-1] = 0.0 # <<<<<<<<<<<<<< - * valid_mask = dzdx_array != slope_nodata - * slope_array[:] = slope_nodata - */ - /*else*/ { - __pyx_t_30 = (__pyx_v_row_index - 1); - __pyx_t_29 = (__pyx_v_col_index - 1); - *__Pyx_BufPtrStrided2d(npy_float64 *, __pyx_pybuffernd_dzdy_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_dzdy_array.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_dzdy_array.diminfo[1].strides) = 0.0; - } - __pyx_L54:; - __pyx_L16_continue:; - } - } - - /* "pygeoprocessing/geoprocessing_core.pyx":527 - * else: - * dzdy_array[row_index-1, col_index-1] = 0.0 - * valid_mask = dzdx_array != slope_nodata # <<<<<<<<<<<<<< - * slope_array[:] = slope_nodata - * # multiply by 100 for percent output - */ - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_slope_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 527, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_RichCompare(((PyObject *)__pyx_v_dzdx_array), __pyx_t_1, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 527, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF_SET(__pyx_v_valid_mask, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":528 - * dzdy_array[row_index-1, col_index-1] = 0.0 - * valid_mask = dzdx_array != slope_nodata - * slope_array[:] = slope_nodata # <<<<<<<<<<<<<< - * # multiply by 100 for percent output - * slope_array[valid_mask] = 100.0 * numpy.sqrt( - */ - __pyx_t_2 = PyFloat_FromDouble(__pyx_v_slope_nodata); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 528, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_slope_array), __pyx_slice_, __pyx_t_2) < 0)) __PYX_ERR(0, 528, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":530 - * slope_array[:] = slope_nodata - * # multiply by 100 for percent output - * slope_array[valid_mask] = 100.0 * numpy.sqrt( # <<<<<<<<<<<<<< - * dzdx_array[valid_mask]**2 + dzdy_array[valid_mask]**2) - * target_slope_band.WriteArray( - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 530, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_sqrt); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 530, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":531 - * # multiply by 100 for percent output - * slope_array[valid_mask] = 100.0 * numpy.sqrt( - * dzdx_array[valid_mask]**2 + dzdy_array[valid_mask]**2) # <<<<<<<<<<<<<< - * target_slope_band.WriteArray( - * slope_array, xoff=block_offset['xoff'], - */ - __pyx_t_1 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_dzdx_array), __pyx_v_valid_mask); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 531, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_16 = PyNumber_Power(__pyx_t_1, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 531, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_dzdy_array), __pyx_v_valid_mask); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 531, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_24 = PyNumber_Power(__pyx_t_1, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 531, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_24); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Add(__pyx_t_16, __pyx_t_24); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 531, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - __pyx_t_24 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_24 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_24)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_24); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_2 = (__pyx_t_24) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_24, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1); - __Pyx_XDECREF(__pyx_t_24); __pyx_t_24 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 530, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":530 - * slope_array[:] = slope_nodata - * # multiply by 100 for percent output - * slope_array[valid_mask] = 100.0 * numpy.sqrt( # <<<<<<<<<<<<<< - * dzdx_array[valid_mask]**2 + dzdy_array[valid_mask]**2) - * target_slope_band.WriteArray( - */ - __pyx_t_3 = PyNumber_Multiply(__pyx_float_100_0, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 530, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_slope_array), __pyx_v_valid_mask, __pyx_t_3) < 0)) __PYX_ERR(0, 530, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":532 - * slope_array[valid_mask] = 100.0 * numpy.sqrt( - * dzdx_array[valid_mask]**2 + dzdy_array[valid_mask]**2) - * target_slope_band.WriteArray( # <<<<<<<<<<<<<< - * slope_array, xoff=block_offset['xoff'], - * yoff=block_offset['yoff']) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_target_slope_band, __pyx_n_s_WriteArray); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 532, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pygeoprocessing/geoprocessing_core.pyx":533 - * dzdx_array[valid_mask]**2 + dzdy_array[valid_mask]**2) - * target_slope_band.WriteArray( - * slope_array, xoff=block_offset['xoff'], # <<<<<<<<<<<<<< - * yoff=block_offset['yoff']) - * - */ - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 532, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_v_slope_array)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_slope_array)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_slope_array)); - __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 533, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_24 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset, __pyx_n_u_xoff); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 533, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_24); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_xoff, __pyx_t_24) < 0) __PYX_ERR(0, 533, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":534 - * target_slope_band.WriteArray( - * slope_array, xoff=block_offset['xoff'], - * yoff=block_offset['yoff']) # <<<<<<<<<<<<<< - * - * dem_band = None - */ - __pyx_t_24 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offset, __pyx_n_u_yoff); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 534, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_24); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_yoff, __pyx_t_24) < 0) __PYX_ERR(0, 533, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":532 - * slope_array[valid_mask] = 100.0 * numpy.sqrt( - * dzdx_array[valid_mask]**2 + dzdy_array[valid_mask]**2) - * target_slope_band.WriteArray( # <<<<<<<<<<<<<< - * slope_array, xoff=block_offset['xoff'], - * yoff=block_offset['yoff']) - */ - __pyx_t_24 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 532, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_24); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":358 - * target_slope_band = target_slope_raster.GetRasterBand(1) - * - * for block_offset in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * base_elevation_raster_path_band, offset_only=True): - * block_offset_copy = block_offset.copy() - */ - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":536 - * yoff=block_offset['yoff']) - * - * dem_band = None # <<<<<<<<<<<<<< - * target_slope_band = None - * dem_raster = None - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_dem_band, Py_None); - - /* "pygeoprocessing/geoprocessing_core.pyx":537 - * - * dem_band = None - * target_slope_band = None # <<<<<<<<<<<<<< - * dem_raster = None - * target_slope_raster = None - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_target_slope_band, Py_None); - - /* "pygeoprocessing/geoprocessing_core.pyx":538 - * dem_band = None - * target_slope_band = None - * dem_raster = None # <<<<<<<<<<<<<< - * target_slope_raster = None - * - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_dem_raster, Py_None); - - /* "pygeoprocessing/geoprocessing_core.pyx":539 - * target_slope_band = None - * dem_raster = None - * target_slope_raster = None # <<<<<<<<<<<<<< - * - * - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_target_slope_raster, Py_None); - - /* "pygeoprocessing/geoprocessing_core.pyx":287 - * @cython.nonecheck(False) - * @cython.cdivision(True) - * def calculate_slope( # <<<<<<<<<<<<<< - * base_elevation_raster_path_band, target_slope_path, - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_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_12); - __Pyx_XDECREF(__pyx_t_15); - __Pyx_XDECREF(__pyx_t_16); - __Pyx_XDECREF(__pyx_t_24); - { 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_array.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dzdy_array.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_slope_array.rcbuffer->pybuffer); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core.calculate_slope", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dem_array.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dzdx_array.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dzdy_array.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_slope_array.rcbuffer->pybuffer); - __pyx_L2:; - __Pyx_XDECREF((PyObject *)__pyx_v_dem_array); - __Pyx_XDECREF((PyObject *)__pyx_v_slope_array); - __Pyx_XDECREF((PyObject *)__pyx_v_dzdx_array); - __Pyx_XDECREF((PyObject *)__pyx_v_dzdy_array); - __Pyx_XDECREF(__pyx_v_dem_raster); - __Pyx_XDECREF(__pyx_v_dem_band); - __Pyx_XDECREF(__pyx_v_dem_info); - __Pyx_XDECREF(__pyx_v_raw_nodata); - __Pyx_XDECREF(__pyx_v_target_slope_raster); - __Pyx_XDECREF(__pyx_v_target_slope_band); - __Pyx_XDECREF(__pyx_v_block_offset); - __Pyx_XDECREF(__pyx_v_block_offset_copy); - __Pyx_XDECREF(__pyx_v_x_start); - __Pyx_XDECREF(__pyx_v_x_end); - __Pyx_XDECREF(__pyx_v_y_start); - __Pyx_XDECREF(__pyx_v_y_end); - __Pyx_XDECREF(__pyx_v_valid_mask); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pygeoprocessing/geoprocessing_core.pyx":544 - * @cython.boundscheck(False) - * @cython.cdivision(True) - * def stats_worker(stats_work_queue, expected_blocks): # <<<<<<<<<<<<<< - * """Worker to calculate continuous min, max, mean and standard deviation. - * - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_5stats_worker(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_15pygeoprocessing_18geoprocessing_core_4stats_worker[] = "Worker to calculate continuous min, max, mean and standard deviation.\n\n Parameters:\n stats_work_queue (Queue): a queue of 1D numpy arrays or None. If\n None, function puts a (min, max, mean, stddev) tuple to the\n queue and quits.\n expected_blocks (int): number of expected payloads through\n ``stats_work_queue``. Will terminate after this many.\n\n Returns:\n None\n\n "; -static PyMethodDef __pyx_mdef_15pygeoprocessing_18geoprocessing_core_5stats_worker = {"stats_worker", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_18geoprocessing_core_5stats_worker, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_18geoprocessing_core_4stats_worker}; -static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_5stats_worker(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_stats_work_queue = 0; - PyObject *__pyx_v_expected_blocks = 0; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("stats_worker (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_stats_work_queue,&__pyx_n_s_expected_blocks,0}; - PyObject* values[2] = {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 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_stats_work_queue)) != 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_expected_blocks)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("stats_worker", 1, 2, 2, 1); __PYX_ERR(0, 544, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "stats_worker") < 0)) __PYX_ERR(0, 544, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - } - __pyx_v_stats_work_queue = values[0]; - __pyx_v_expected_blocks = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("stats_worker", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 544, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core.stats_worker", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_15pygeoprocessing_18geoprocessing_core_4stats_worker(__pyx_self, __pyx_v_stats_work_queue, __pyx_v_expected_blocks); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core_4stats_worker(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_stats_work_queue, PyObject *__pyx_v_expected_blocks) { - PyArrayObject *__pyx_v_block = 0; - double __pyx_v_M_local; - double __pyx_v_S_local; - double __pyx_v_min_value; - double __pyx_v_max_value; - double __pyx_v_x; - int __pyx_v_i; - int __pyx_v_n_elements; - PY_LONG_LONG __pyx_v_n; - PyObject *__pyx_v_payload = NULL; - CYTHON_UNUSED PyObject *__pyx_v_index = NULL; - PyObject *__pyx_v_existing_shm = NULL; - PyObject *__pyx_v_shape = NULL; - PyObject *__pyx_v_dtype = NULL; - double __pyx_v_M_last; - CYTHON_UNUSED PyObject *__pyx_v_e = NULL; - __Pyx_LocalBuf_ND __pyx_pybuffernd_block; - __Pyx_Buffer __pyx_pybuffer_block; - 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; - Py_ssize_t __pyx_t_6; - PyObject *(*__pyx_t_7)(PyObject *); - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - int __pyx_t_11; - int __pyx_t_12; - int __pyx_t_13; - PyObject *__pyx_t_14 = NULL; - PyObject *__pyx_t_15 = NULL; - PyObject *__pyx_t_16 = NULL; - PyObject *(*__pyx_t_17)(PyObject *); - int __pyx_t_18; - int __pyx_t_19; - Py_ssize_t __pyx_t_20; - PyObject *__pyx_t_21 = NULL; - PyObject *__pyx_t_22 = NULL; - PyObject *__pyx_t_23 = NULL; - PyObject *__pyx_t_24 = NULL; - PyObject *__pyx_t_25 = NULL; - PyObject *__pyx_t_26 = NULL; - PyObject *__pyx_t_27 = NULL; - char const *__pyx_t_28; - PyObject *__pyx_t_29 = NULL; - PyObject *__pyx_t_30 = NULL; - PyObject *__pyx_t_31 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("stats_worker", 0); - __pyx_pybuffer_block.pybuffer.buf = NULL; - __pyx_pybuffer_block.refcount = 0; - __pyx_pybuffernd_block.data = NULL; - __pyx_pybuffernd_block.rcbuffer = &__pyx_pybuffer_block; - - /* "pygeoprocessing/geoprocessing_core.pyx":558 - * - * """ - * LOGGER.debug(f'stats worker PID: {os.getpid()}') # <<<<<<<<<<<<<< - * cdef numpy.ndarray[numpy.float64_t, ndim=1] block - * cdef double M_local = 0.0 - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 558, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_debug); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 558, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_os); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 558, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_getpid); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 558, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __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); - } - } - __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 558, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_FormatSimple(__pyx_t_2, __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 558, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyUnicode_Concat(__pyx_kp_u_stats_worker_PID, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 558, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = NULL; - 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_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 558, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":560 - * LOGGER.debug(f'stats worker PID: {os.getpid()}') - * cdef numpy.ndarray[numpy.float64_t, ndim=1] block - * cdef double M_local = 0.0 # <<<<<<<<<<<<<< - * cdef double S_local = 0.0 - * cdef double min_value = 0.0 - */ - __pyx_v_M_local = 0.0; - - /* "pygeoprocessing/geoprocessing_core.pyx":561 - * cdef numpy.ndarray[numpy.float64_t, ndim=1] block - * cdef double M_local = 0.0 - * cdef double S_local = 0.0 # <<<<<<<<<<<<<< - * cdef double min_value = 0.0 - * cdef double max_value = 0.0 - */ - __pyx_v_S_local = 0.0; - - /* "pygeoprocessing/geoprocessing_core.pyx":562 - * cdef double M_local = 0.0 - * cdef double S_local = 0.0 - * cdef double min_value = 0.0 # <<<<<<<<<<<<<< - * cdef double max_value = 0.0 - * cdef double x = 0.0 - */ - __pyx_v_min_value = 0.0; - - /* "pygeoprocessing/geoprocessing_core.pyx":563 - * cdef double S_local = 0.0 - * cdef double min_value = 0.0 - * cdef double max_value = 0.0 # <<<<<<<<<<<<<< - * cdef double x = 0.0 - * cdef int i, n_elements - */ - __pyx_v_max_value = 0.0; - - /* "pygeoprocessing/geoprocessing_core.pyx":564 - * cdef double min_value = 0.0 - * cdef double max_value = 0.0 - * cdef double x = 0.0 # <<<<<<<<<<<<<< - * cdef int i, n_elements - * cdef long long n = 0L - */ - __pyx_v_x = 0.0; - - /* "pygeoprocessing/geoprocessing_core.pyx":566 - * cdef double x = 0.0 - * cdef int i, n_elements - * cdef long long n = 0L # <<<<<<<<<<<<<< - * payload = None - * - */ - __pyx_v_n = 0L; - - /* "pygeoprocessing/geoprocessing_core.pyx":567 - * cdef int i, n_elements - * cdef long long n = 0L - * payload = None # <<<<<<<<<<<<<< - * - * for index in range(expected_blocks): - */ - __Pyx_INCREF(Py_None); - __pyx_v_payload = Py_None; - - /* "pygeoprocessing/geoprocessing_core.pyx":569 - * payload = None - * - * for index in range(expected_blocks): # <<<<<<<<<<<<<< - * try: - * existing_shm = None - */ - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_v_expected_blocks); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 569, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { - __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_6 = 0; - __pyx_t_7 = NULL; - } else { - __pyx_t_6 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 569, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 569, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - for (;;) { - if (likely(!__pyx_t_7)) { - if (likely(PyList_CheckExact(__pyx_t_3))) { - if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 569, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 569, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } else { - if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 569, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 569, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } - } else { - __pyx_t_1 = __pyx_t_7(__pyx_t_3); - 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, 569, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - __Pyx_XDECREF_SET(__pyx_v_index, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":570 - * - * for index in range(expected_blocks): - * try: # <<<<<<<<<<<<<< - * existing_shm = None - * payload = stats_work_queue.get() - */ - { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __Pyx_ExceptionSave(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10); - __Pyx_XGOTREF(__pyx_t_8); - __Pyx_XGOTREF(__pyx_t_9); - __Pyx_XGOTREF(__pyx_t_10); - /*try:*/ { - - /* "pygeoprocessing/geoprocessing_core.pyx":571 - * for index in range(expected_blocks): - * try: - * existing_shm = None # <<<<<<<<<<<<<< - * payload = stats_work_queue.get() - * if payload is None: - */ - __Pyx_INCREF(Py_None); - __Pyx_XDECREF_SET(__pyx_v_existing_shm, Py_None); - - /* "pygeoprocessing/geoprocessing_core.pyx":572 - * try: - * existing_shm = None - * payload = stats_work_queue.get() # <<<<<<<<<<<<<< - * if payload is None: - * break - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_stats_work_queue, __pyx_n_s_get); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 572, __pyx_L5_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 572, __pyx_L5_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF_SET(__pyx_v_payload, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":573 - * existing_shm = None - * payload = stats_work_queue.get() - * if payload is None: # <<<<<<<<<<<<<< - * break - * if isinstance(payload, numpy.ndarray): - */ - __pyx_t_11 = (__pyx_v_payload == Py_None); - __pyx_t_12 = (__pyx_t_11 != 0); - if (__pyx_t_12) { - - /* "pygeoprocessing/geoprocessing_core.pyx":574 - * payload = stats_work_queue.get() - * if payload is None: - * break # <<<<<<<<<<<<<< - * if isinstance(payload, numpy.ndarray): - * # if the payload is a normal array take it as the array block - */ - goto __pyx_L10_try_break; - - /* "pygeoprocessing/geoprocessing_core.pyx":573 - * existing_shm = None - * payload = stats_work_queue.get() - * if payload is None: # <<<<<<<<<<<<<< - * break - * if isinstance(payload, numpy.ndarray): - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":575 - * if payload is None: - * break - * if isinstance(payload, numpy.ndarray): # <<<<<<<<<<<<<< - * # if the payload is a normal array take it as the array block - * block = payload - */ - __pyx_t_12 = __Pyx_TypeCheck(__pyx_v_payload, __pyx_ptype_5numpy_ndarray); - __pyx_t_11 = (__pyx_t_12 != 0); - if (__pyx_t_11) { - - /* "pygeoprocessing/geoprocessing_core.pyx":577 - * if isinstance(payload, numpy.ndarray): - * # if the payload is a normal array take it as the array block - * block = payload # <<<<<<<<<<<<<< - * else: - * # if not an ndarray, it is a shared memory pointer tuple - */ - if (!(likely(((__pyx_v_payload) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_payload, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 577, __pyx_L5_error) - __pyx_t_1 = __pyx_v_payload; - __Pyx_INCREF(__pyx_t_1); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_block.rcbuffer->pybuffer); - __pyx_t_13 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_block.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack); - if (unlikely(__pyx_t_13 < 0)) { - PyErr_Fetch(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_block.rcbuffer->pybuffer, (PyObject*)__pyx_v_block, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_16); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_14, __pyx_t_15, __pyx_t_16); - } - __pyx_t_14 = __pyx_t_15 = __pyx_t_16 = 0; - } - __pyx_pybuffernd_block.diminfo[0].strides = __pyx_pybuffernd_block.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_block.diminfo[0].shape = __pyx_pybuffernd_block.rcbuffer->pybuffer.shape[0]; - if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 577, __pyx_L5_error) - } - __Pyx_XDECREF_SET(__pyx_v_block, ((PyArrayObject *)__pyx_t_1)); - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":575 - * if payload is None: - * break - * if isinstance(payload, numpy.ndarray): # <<<<<<<<<<<<<< - * # if the payload is a normal array take it as the array block - * block = payload - */ - goto __pyx_L14; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":580 - * else: - * # if not an ndarray, it is a shared memory pointer tuple - * shape, dtype, existing_shm = payload # <<<<<<<<<<<<<< - * block = numpy.ndarray( - * shape, dtype=dtype, buffer=existing_shm.buf) - */ - /*else*/ { - if ((likely(PyTuple_CheckExact(__pyx_v_payload))) || (PyList_CheckExact(__pyx_v_payload))) { - PyObject* sequence = __pyx_v_payload; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 3)) { - if (size > 3) __Pyx_RaiseTooManyValuesError(3); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 580, __pyx_L5_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_5 = PyTuple_GET_ITEM(sequence, 2); - } else { - __pyx_t_1 = PyList_GET_ITEM(sequence, 0); - __pyx_t_2 = PyList_GET_ITEM(sequence, 1); - __pyx_t_5 = PyList_GET_ITEM(sequence, 2); - } - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_5); - #else - __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 580, __pyx_L5_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 580, __pyx_L5_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 580, __pyx_L5_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - } else { - Py_ssize_t index = -1; - __pyx_t_4 = PyObject_GetIter(__pyx_v_payload); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 580, __pyx_L5_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_17 = Py_TYPE(__pyx_t_4)->tp_iternext; - index = 0; __pyx_t_1 = __pyx_t_17(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L15_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - index = 1; __pyx_t_2 = __pyx_t_17(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L15_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - index = 2; __pyx_t_5 = __pyx_t_17(__pyx_t_4); if (unlikely(!__pyx_t_5)) goto __pyx_L15_unpacking_failed; - __Pyx_GOTREF(__pyx_t_5); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_4), 3) < 0) __PYX_ERR(0, 580, __pyx_L5_error) - __pyx_t_17 = NULL; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L16_unpacking_done; - __pyx_L15_unpacking_failed:; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_17 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 580, __pyx_L5_error) - __pyx_L16_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v_shape, __pyx_t_1); - __pyx_t_1 = 0; - __Pyx_XDECREF_SET(__pyx_v_dtype, __pyx_t_2); - __pyx_t_2 = 0; - __Pyx_DECREF_SET(__pyx_v_existing_shm, __pyx_t_5); - __pyx_t_5 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":581 - * # if not an ndarray, it is a shared memory pointer tuple - * shape, dtype, existing_shm = payload - * block = numpy.ndarray( # <<<<<<<<<<<<<< - * shape, dtype=dtype, buffer=existing_shm.buf) - * if block.size == 0: - */ - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 581, __pyx_L5_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(__pyx_v_shape); - __Pyx_GIVEREF(__pyx_v_shape); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_shape); - - /* "pygeoprocessing/geoprocessing_core.pyx":582 - * shape, dtype, existing_shm = payload - * block = numpy.ndarray( - * shape, dtype=dtype, buffer=existing_shm.buf) # <<<<<<<<<<<<<< - * if block.size == 0: - * continue - */ - __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 582, __pyx_L5_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_v_dtype) < 0) __PYX_ERR(0, 582, __pyx_L5_error) - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_existing_shm, __pyx_n_s_buf); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 582, __pyx_L5_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_buffer, __pyx_t_1) < 0) __PYX_ERR(0, 582, __pyx_L5_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":581 - * # if not an ndarray, it is a shared memory pointer tuple - * shape, dtype, existing_shm = payload - * block = numpy.ndarray( # <<<<<<<<<<<<<< - * shape, dtype=dtype, buffer=existing_shm.buf) - * if block.size == 0: - */ - __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5numpy_ndarray), __pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 581, __pyx_L5_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_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_block.rcbuffer->pybuffer); - __pyx_t_13 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_block.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack); - if (unlikely(__pyx_t_13 < 0)) { - PyErr_Fetch(&__pyx_t_16, &__pyx_t_15, &__pyx_t_14); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_block.rcbuffer->pybuffer, (PyObject*)__pyx_v_block, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_16); Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_14); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_16, __pyx_t_15, __pyx_t_14); - } - __pyx_t_16 = __pyx_t_15 = __pyx_t_14 = 0; - } - __pyx_pybuffernd_block.diminfo[0].strides = __pyx_pybuffernd_block.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_block.diminfo[0].shape = __pyx_pybuffernd_block.rcbuffer->pybuffer.shape[0]; - if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 581, __pyx_L5_error) - } - __Pyx_XDECREF_SET(__pyx_v_block, ((PyArrayObject *)__pyx_t_1)); - __pyx_t_1 = 0; - } - __pyx_L14:; - - /* "pygeoprocessing/geoprocessing_core.pyx":583 - * block = numpy.ndarray( - * shape, dtype=dtype, buffer=existing_shm.buf) - * if block.size == 0: # <<<<<<<<<<<<<< - * continue - * n_elements = block.size - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_block), __pyx_n_s_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 583, __pyx_L5_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 583, __pyx_L5_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 583, __pyx_L5_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_11) { - - /* "pygeoprocessing/geoprocessing_core.pyx":584 - * shape, dtype=dtype, buffer=existing_shm.buf) - * if block.size == 0: - * continue # <<<<<<<<<<<<<< - * n_elements = block.size - * with nogil: - */ - goto __pyx_L11_try_continue; - - /* "pygeoprocessing/geoprocessing_core.pyx":583 - * block = numpy.ndarray( - * shape, dtype=dtype, buffer=existing_shm.buf) - * if block.size == 0: # <<<<<<<<<<<<<< - * continue - * n_elements = block.size - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":585 - * if block.size == 0: - * continue - * n_elements = block.size # <<<<<<<<<<<<<< - * with nogil: - * for i in range(n_elements): - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_block), __pyx_n_s_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 585, __pyx_L5_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 585, __pyx_L5_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_n_elements = __pyx_t_13; - - /* "pygeoprocessing/geoprocessing_core.pyx":586 - * continue - * n_elements = block.size - * with nogil: # <<<<<<<<<<<<<< - * for i in range(n_elements): - * n = n + 1 - */ - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { - - /* "pygeoprocessing/geoprocessing_core.pyx":587 - * n_elements = block.size - * with nogil: - * for i in range(n_elements): # <<<<<<<<<<<<<< - * n = n + 1 - * x = block[i] - */ - __pyx_t_13 = __pyx_v_n_elements; - __pyx_t_18 = __pyx_t_13; - for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_18; __pyx_t_19+=1) { - __pyx_v_i = __pyx_t_19; - - /* "pygeoprocessing/geoprocessing_core.pyx":588 - * with nogil: - * for i in range(n_elements): - * n = n + 1 # <<<<<<<<<<<<<< - * x = block[i] - * if n <= 0: - */ - __pyx_v_n = (__pyx_v_n + 1); - - /* "pygeoprocessing/geoprocessing_core.pyx":589 - * for i in range(n_elements): - * n = n + 1 - * x = block[i] # <<<<<<<<<<<<<< - * if n <= 0: - * with gil: - */ - __pyx_t_20 = __pyx_v_i; - if (__pyx_t_20 < 0) __pyx_t_20 += __pyx_pybuffernd_block.diminfo[0].shape; - __pyx_v_x = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_block.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_block.diminfo[0].strides)); - - /* "pygeoprocessing/geoprocessing_core.pyx":590 - * n = n + 1 - * x = block[i] - * if n <= 0: # <<<<<<<<<<<<<< - * with gil: - * LOGGER.error('invalid value for n %s' % n) - */ - __pyx_t_11 = ((__pyx_v_n <= 0) != 0); - if (__pyx_t_11) { - - /* "pygeoprocessing/geoprocessing_core.pyx":591 - * x = block[i] - * if n <= 0: - * with gil: # <<<<<<<<<<<<<< - * LOGGER.error('invalid value for n %s' % n) - * if n == 1: - */ - { - #ifdef WITH_THREAD - PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); - #endif - /*try:*/ { - - /* "pygeoprocessing/geoprocessing_core.pyx":592 - * if n <= 0: - * with gil: - * LOGGER.error('invalid value for n %s' % n) # <<<<<<<<<<<<<< - * if n == 1: - * M_local = x - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 592, __pyx_L29_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_error); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 592, __pyx_L29_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_n); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 592, __pyx_L29_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyUnicode_Format(__pyx_kp_u_invalid_value_for_n_s, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 592, __pyx_L29_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - } - } - __pyx_t_2 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_1, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 592, __pyx_L29_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":591 - * x = block[i] - * if n <= 0: - * with gil: # <<<<<<<<<<<<<< - * LOGGER.error('invalid value for n %s' % n) - * if n == 1: - */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_PyGILState_Release(__pyx_gilstate_save); - #endif - goto __pyx_L30; - } - __pyx_L29_error: { - #ifdef WITH_THREAD - __Pyx_PyGILState_Release(__pyx_gilstate_save); - #endif - goto __pyx_L21_error; - } - __pyx_L30:; - } - } - - /* "pygeoprocessing/geoprocessing_core.pyx":590 - * n = n + 1 - * x = block[i] - * if n <= 0: # <<<<<<<<<<<<<< - * with gil: - * LOGGER.error('invalid value for n %s' % n) - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":593 - * with gil: - * LOGGER.error('invalid value for n %s' % n) - * if n == 1: # <<<<<<<<<<<<<< - * M_local = x - * S_local = 0.0 - */ - __pyx_t_11 = ((__pyx_v_n == 1) != 0); - if (__pyx_t_11) { - - /* "pygeoprocessing/geoprocessing_core.pyx":594 - * LOGGER.error('invalid value for n %s' % n) - * if n == 1: - * M_local = x # <<<<<<<<<<<<<< - * S_local = 0.0 - * min_value = x - */ - __pyx_v_M_local = __pyx_v_x; - - /* "pygeoprocessing/geoprocessing_core.pyx":595 - * if n == 1: - * M_local = x - * S_local = 0.0 # <<<<<<<<<<<<<< - * min_value = x - * max_value = x - */ - __pyx_v_S_local = 0.0; - - /* "pygeoprocessing/geoprocessing_core.pyx":596 - * M_local = x - * S_local = 0.0 - * min_value = x # <<<<<<<<<<<<<< - * max_value = x - * else: - */ - __pyx_v_min_value = __pyx_v_x; - - /* "pygeoprocessing/geoprocessing_core.pyx":597 - * S_local = 0.0 - * min_value = x - * max_value = x # <<<<<<<<<<<<<< - * else: - * M_last = M_local - */ - __pyx_v_max_value = __pyx_v_x; - - /* "pygeoprocessing/geoprocessing_core.pyx":593 - * with gil: - * LOGGER.error('invalid value for n %s' % n) - * if n == 1: # <<<<<<<<<<<<<< - * M_local = x - * S_local = 0.0 - */ - goto __pyx_L31; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":599 - * max_value = x - * else: - * M_last = M_local # <<<<<<<<<<<<<< - * M_local = M_local+(x - M_local)/(n) - * S_local = S_local+(x-M_last)*(x-M_local) - */ - /*else*/ { - __pyx_v_M_last = __pyx_v_M_local; - - /* "pygeoprocessing/geoprocessing_core.pyx":600 - * else: - * M_last = M_local - * M_local = M_local+(x - M_local)/(n) # <<<<<<<<<<<<<< - * S_local = S_local+(x-M_last)*(x-M_local) - * if x < min_value: - */ - __pyx_v_M_local = (__pyx_v_M_local + ((__pyx_v_x - __pyx_v_M_local) / ((double)__pyx_v_n))); - - /* "pygeoprocessing/geoprocessing_core.pyx":601 - * M_last = M_local - * M_local = M_local+(x - M_local)/(n) - * S_local = S_local+(x-M_last)*(x-M_local) # <<<<<<<<<<<<<< - * if x < min_value: - * min_value = x - */ - __pyx_v_S_local = (__pyx_v_S_local + ((__pyx_v_x - __pyx_v_M_last) * (__pyx_v_x - __pyx_v_M_local))); - - /* "pygeoprocessing/geoprocessing_core.pyx":602 - * M_local = M_local+(x - M_local)/(n) - * S_local = S_local+(x-M_last)*(x-M_local) - * if x < min_value: # <<<<<<<<<<<<<< - * min_value = x - * elif x > max_value: - */ - __pyx_t_11 = ((__pyx_v_x < __pyx_v_min_value) != 0); - if (__pyx_t_11) { - - /* "pygeoprocessing/geoprocessing_core.pyx":603 - * S_local = S_local+(x-M_last)*(x-M_local) - * if x < min_value: - * min_value = x # <<<<<<<<<<<<<< - * elif x > max_value: - * max_value = x - */ - __pyx_v_min_value = __pyx_v_x; - - /* "pygeoprocessing/geoprocessing_core.pyx":602 - * M_local = M_local+(x - M_local)/(n) - * S_local = S_local+(x-M_last)*(x-M_local) - * if x < min_value: # <<<<<<<<<<<<<< - * min_value = x - * elif x > max_value: - */ - goto __pyx_L32; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":604 - * if x < min_value: - * min_value = x - * elif x > max_value: # <<<<<<<<<<<<<< - * max_value = x - * except Exception as e: - */ - __pyx_t_11 = ((__pyx_v_x > __pyx_v_max_value) != 0); - if (__pyx_t_11) { - - /* "pygeoprocessing/geoprocessing_core.pyx":605 - * min_value = x - * elif x > max_value: - * max_value = x # <<<<<<<<<<<<<< - * except Exception as e: - * LOGGER.exception( - */ - __pyx_v_max_value = __pyx_v_x; - - /* "pygeoprocessing/geoprocessing_core.pyx":604 - * if x < min_value: - * min_value = x - * elif x > max_value: # <<<<<<<<<<<<<< - * max_value = x - * except Exception as e: - */ - } - __pyx_L32:; - } - __pyx_L31:; - } - } - - /* "pygeoprocessing/geoprocessing_core.pyx":586 - * continue - * n_elements = block.size - * with nogil: # <<<<<<<<<<<<<< - * for i in range(n_elements): - * n = n + 1 - */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L22; - } - __pyx_L21_error: { - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L5_error; - } - __pyx_L22:; - } - } - - /* "pygeoprocessing/geoprocessing_core.pyx":570 - * - * for index in range(expected_blocks): - * try: # <<<<<<<<<<<<<< - * existing_shm = None - * payload = stats_work_queue.get() - */ - } - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - goto __pyx_L12_try_end; - __pyx_L5_error:; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":606 - * elif x > max_value: - * max_value = x - * except Exception as e: # <<<<<<<<<<<<<< - * LOGGER.exception( - * "exception %s %s %s %s %s", x, M_local, S_local, n, payload) - */ - __pyx_t_13 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0]))); - if (__pyx_t_13) { - __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core.stats_worker", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_5, &__pyx_t_4) < 0) __PYX_ERR(0, 606, __pyx_L7_except_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_5); - __pyx_v_e = __pyx_t_5; - /*try:*/ { - - /* "pygeoprocessing/geoprocessing_core.pyx":607 - * max_value = x - * except Exception as e: - * LOGGER.exception( # <<<<<<<<<<<<<< - * "exception %s %s %s %s %s", x, M_local, S_local, n, payload) - * raise - */ - __Pyx_GetModuleGlobalName(__pyx_t_21, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 607, __pyx_L38_error) - __Pyx_GOTREF(__pyx_t_21); - __pyx_t_22 = __Pyx_PyObject_GetAttrStr(__pyx_t_21, __pyx_n_s_exception); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 607, __pyx_L38_error) - __Pyx_GOTREF(__pyx_t_22); - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":608 - * except Exception as e: - * LOGGER.exception( - * "exception %s %s %s %s %s", x, M_local, S_local, n, payload) # <<<<<<<<<<<<<< - * raise - * - */ - __pyx_t_21 = PyFloat_FromDouble(__pyx_v_x); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 608, __pyx_L38_error) - __Pyx_GOTREF(__pyx_t_21); - __pyx_t_23 = PyFloat_FromDouble(__pyx_v_M_local); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 608, __pyx_L38_error) - __Pyx_GOTREF(__pyx_t_23); - __pyx_t_24 = PyFloat_FromDouble(__pyx_v_S_local); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 608, __pyx_L38_error) - __Pyx_GOTREF(__pyx_t_24); - __pyx_t_25 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_n); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 608, __pyx_L38_error) - __Pyx_GOTREF(__pyx_t_25); - __pyx_t_26 = NULL; - __pyx_t_13 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_22))) { - __pyx_t_26 = PyMethod_GET_SELF(__pyx_t_22); - if (likely(__pyx_t_26)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_22); - __Pyx_INCREF(__pyx_t_26); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_22, function); - __pyx_t_13 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_22)) { - PyObject *__pyx_temp[7] = {__pyx_t_26, __pyx_kp_u_exception_s_s_s_s_s, __pyx_t_21, __pyx_t_23, __pyx_t_24, __pyx_t_25, __pyx_v_payload}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_22, __pyx_temp+1-__pyx_t_13, 6+__pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 607, __pyx_L38_error) - __Pyx_XDECREF(__pyx_t_26); __pyx_t_26 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_22)) { - PyObject *__pyx_temp[7] = {__pyx_t_26, __pyx_kp_u_exception_s_s_s_s_s, __pyx_t_21, __pyx_t_23, __pyx_t_24, __pyx_t_25, __pyx_v_payload}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_22, __pyx_temp+1-__pyx_t_13, 6+__pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 607, __pyx_L38_error) - __Pyx_XDECREF(__pyx_t_26); __pyx_t_26 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0; - } else - #endif - { - __pyx_t_27 = PyTuple_New(6+__pyx_t_13); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 607, __pyx_L38_error) - __Pyx_GOTREF(__pyx_t_27); - if (__pyx_t_26) { - __Pyx_GIVEREF(__pyx_t_26); PyTuple_SET_ITEM(__pyx_t_27, 0, __pyx_t_26); __pyx_t_26 = NULL; - } - __Pyx_INCREF(__pyx_kp_u_exception_s_s_s_s_s); - __Pyx_GIVEREF(__pyx_kp_u_exception_s_s_s_s_s); - PyTuple_SET_ITEM(__pyx_t_27, 0+__pyx_t_13, __pyx_kp_u_exception_s_s_s_s_s); - __Pyx_GIVEREF(__pyx_t_21); - PyTuple_SET_ITEM(__pyx_t_27, 1+__pyx_t_13, __pyx_t_21); - __Pyx_GIVEREF(__pyx_t_23); - PyTuple_SET_ITEM(__pyx_t_27, 2+__pyx_t_13, __pyx_t_23); - __Pyx_GIVEREF(__pyx_t_24); - PyTuple_SET_ITEM(__pyx_t_27, 3+__pyx_t_13, __pyx_t_24); - __Pyx_GIVEREF(__pyx_t_25); - PyTuple_SET_ITEM(__pyx_t_27, 4+__pyx_t_13, __pyx_t_25); - __Pyx_INCREF(__pyx_v_payload); - __Pyx_GIVEREF(__pyx_v_payload); - PyTuple_SET_ITEM(__pyx_t_27, 5+__pyx_t_13, __pyx_v_payload); - __pyx_t_21 = 0; - __pyx_t_23 = 0; - __pyx_t_24 = 0; - __pyx_t_25 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_22, __pyx_t_27, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 607, __pyx_L38_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0; - } - __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":609 - * LOGGER.exception( - * "exception %s %s %s %s %s", x, M_local, S_local, n, payload) - * raise # <<<<<<<<<<<<<< - * - * if n > 0: - */ - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_4); - __Pyx_ErrRestoreWithState(__pyx_t_2, __pyx_t_5, __pyx_t_4); - __pyx_t_2 = 0; __pyx_t_5 = 0; __pyx_t_4 = 0; - __PYX_ERR(0, 609, __pyx_L38_error) - } - - /* "pygeoprocessing/geoprocessing_core.pyx":606 - * elif x > max_value: - * max_value = x - * except Exception as e: # <<<<<<<<<<<<<< - * LOGGER.exception( - * "exception %s %s %s %s %s", x, M_local, S_local, n, payload) - */ - /*finally:*/ { - __pyx_L38_error:; - /*exception exit:*/{ - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_29 = 0; __pyx_t_30 = 0; __pyx_t_31 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; - __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; - __Pyx_XDECREF(__pyx_t_23); __pyx_t_23 = 0; - __Pyx_XDECREF(__pyx_t_24); __pyx_t_24 = 0; - __Pyx_XDECREF(__pyx_t_25); __pyx_t_25 = 0; - __Pyx_XDECREF(__pyx_t_26); __pyx_t_26 = 0; - __Pyx_XDECREF(__pyx_t_27); __pyx_t_27 = 0; - if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_29, &__pyx_t_30, &__pyx_t_31); - if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16) < 0)) __Pyx_ErrFetch(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); - __Pyx_XGOTREF(__pyx_t_14); - __Pyx_XGOTREF(__pyx_t_15); - __Pyx_XGOTREF(__pyx_t_16); - __Pyx_XGOTREF(__pyx_t_29); - __Pyx_XGOTREF(__pyx_t_30); - __Pyx_XGOTREF(__pyx_t_31); - __pyx_t_13 = __pyx_lineno; __pyx_t_18 = __pyx_clineno; __pyx_t_28 = __pyx_filename; - { - __Pyx_DECREF(__pyx_v_e); - __pyx_v_e = NULL; - } - if (PY_MAJOR_VERSION >= 3) { - __Pyx_XGIVEREF(__pyx_t_29); - __Pyx_XGIVEREF(__pyx_t_30); - __Pyx_XGIVEREF(__pyx_t_31); - __Pyx_ExceptionReset(__pyx_t_29, __pyx_t_30, __pyx_t_31); - } - __Pyx_XGIVEREF(__pyx_t_14); - __Pyx_XGIVEREF(__pyx_t_15); - __Pyx_XGIVEREF(__pyx_t_16); - __Pyx_ErrRestore(__pyx_t_14, __pyx_t_15, __pyx_t_16); - __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_29 = 0; __pyx_t_30 = 0; __pyx_t_31 = 0; - __pyx_lineno = __pyx_t_13; __pyx_clineno = __pyx_t_18; __pyx_filename = __pyx_t_28; - goto __pyx_L7_except_error; - } - } - } - goto __pyx_L7_except_error; - __pyx_L7_except_error:; - - /* "pygeoprocessing/geoprocessing_core.pyx":570 - * - * for index in range(expected_blocks): - * try: # <<<<<<<<<<<<<< - * existing_shm = None - * payload = stats_work_queue.get() - */ - __Pyx_XGIVEREF(__pyx_t_8); - __Pyx_XGIVEREF(__pyx_t_9); - __Pyx_XGIVEREF(__pyx_t_10); - __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10); - goto __pyx_L1_error; - __pyx_L10_try_break:; - __Pyx_XGIVEREF(__pyx_t_8); - __Pyx_XGIVEREF(__pyx_t_9); - __Pyx_XGIVEREF(__pyx_t_10); - __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10); - goto __pyx_L4_break; - __pyx_L11_try_continue:; - __Pyx_XGIVEREF(__pyx_t_8); - __Pyx_XGIVEREF(__pyx_t_9); - __Pyx_XGIVEREF(__pyx_t_10); - __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10); - goto __pyx_L3_continue; - __pyx_L12_try_end:; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":569 - * payload = None - * - * for index in range(expected_blocks): # <<<<<<<<<<<<<< - * try: - * existing_shm = None - */ - __pyx_L3_continue:; - } - __pyx_L4_break:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":611 - * raise - * - * if n > 0: # <<<<<<<<<<<<<< - * stats_work_queue.put( - * (min_value, max_value, M_local, - */ - __pyx_t_11 = ((__pyx_v_n > 0) != 0); - if (__pyx_t_11) { - - /* "pygeoprocessing/geoprocessing_core.pyx":612 - * - * if n > 0: - * stats_work_queue.put( # <<<<<<<<<<<<<< - * (min_value, max_value, M_local, - * (S_local / n) ** 0.5)) - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_stats_work_queue, __pyx_n_s_put); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 612, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - - /* "pygeoprocessing/geoprocessing_core.pyx":613 - * if n > 0: - * stats_work_queue.put( - * (min_value, max_value, M_local, # <<<<<<<<<<<<<< - * (S_local / n) ** 0.5)) - * else: - */ - __pyx_t_5 = PyFloat_FromDouble(__pyx_v_min_value); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 613, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_2 = PyFloat_FromDouble(__pyx_v_max_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 613, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_M_local); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 613, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/geoprocessing_core.pyx":614 - * stats_work_queue.put( - * (min_value, max_value, M_local, - * (S_local / n) ** 0.5)) # <<<<<<<<<<<<<< - * else: - * LOGGER.warning( - */ - __pyx_t_22 = PyFloat_FromDouble(pow((__pyx_v_S_local / ((double)__pyx_v_n)), 0.5)); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 614, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_22); - - /* "pygeoprocessing/geoprocessing_core.pyx":613 - * if n > 0: - * stats_work_queue.put( - * (min_value, max_value, M_local, # <<<<<<<<<<<<<< - * (S_local / n) ** 0.5)) - * else: - */ - __pyx_t_27 = PyTuple_New(4); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 613, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_27); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_27, 0, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_27, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_27, 2, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_22); - PyTuple_SET_ITEM(__pyx_t_27, 3, __pyx_t_22); - __pyx_t_5 = 0; - __pyx_t_2 = 0; - __pyx_t_1 = 0; - __pyx_t_22 = 0; - __pyx_t_22 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_22 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_22)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_22); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - __pyx_t_3 = (__pyx_t_22) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_22, __pyx_t_27) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_27); - __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; - __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 612, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":611 - * raise - * - * if n > 0: # <<<<<<<<<<<<<< - * stats_work_queue.put( - * (min_value, max_value, M_local, - */ - goto __pyx_L44; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":616 - * (S_local / n) ** 0.5)) - * else: - * LOGGER.warning( # <<<<<<<<<<<<<< - * "No valid pixels were received, sending None.") - * stats_work_queue.put(None) - */ - /*else*/ { - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 616, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_27 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_warning); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 616, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_27); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_27))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_27); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_27); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_27, function); - } - } - __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_27, __pyx_t_4, __pyx_kp_u_No_valid_pixels_were_received_se) : __Pyx_PyObject_CallOneArg(__pyx_t_27, __pyx_kp_u_No_valid_pixels_were_received_se); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 616, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":618 - * LOGGER.warning( - * "No valid pixels were received, sending None.") - * stats_work_queue.put(None) # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_27 = __Pyx_PyObject_GetAttrStr(__pyx_v_stats_work_queue, __pyx_n_s_put); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 618, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_27); - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_27))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_27); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_27); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_27, function); - } - } - __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_27, __pyx_t_4, Py_None) : __Pyx_PyObject_CallOneArg(__pyx_t_27, Py_None); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 618, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __pyx_L44:; - - /* "pygeoprocessing/geoprocessing_core.pyx":544 - * @cython.boundscheck(False) - * @cython.cdivision(True) - * def stats_worker(stats_work_queue, expected_blocks): # <<<<<<<<<<<<<< - * """Worker to calculate continuous min, max, mean and standard deviation. - * - */ - - /* 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_21); - __Pyx_XDECREF(__pyx_t_22); - __Pyx_XDECREF(__pyx_t_23); - __Pyx_XDECREF(__pyx_t_24); - __Pyx_XDECREF(__pyx_t_25); - __Pyx_XDECREF(__pyx_t_26); - __Pyx_XDECREF(__pyx_t_27); - { 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.rcbuffer->pybuffer); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core.stats_worker", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_block.rcbuffer->pybuffer); - __pyx_L2:; - __Pyx_XDECREF((PyObject *)__pyx_v_block); - __Pyx_XDECREF(__pyx_v_payload); - __Pyx_XDECREF(__pyx_v_index); - __Pyx_XDECREF(__pyx_v_existing_shm); - __Pyx_XDECREF(__pyx_v_shape); - __Pyx_XDECREF(__pyx_v_dtype); - __Pyx_XDECREF(__pyx_v_e); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pygeoprocessing/geoprocessing_core.pyx":626 - * - * - * def raster_band_percentile( # <<<<<<<<<<<<<< - * base_raster_path_band, working_sort_directory, percentile_list, - * heap_buffer_size=2**28, ffi_buffer_size=2**10): - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_7raster_band_percentile(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_15pygeoprocessing_18geoprocessing_core_6raster_band_percentile[] = "Calculate percentiles of a raster band.\n\n Parameters:\n base_raster_path_band (tuple): raster path band tuple to a raster\n that is of any integer or real type.\n working_sort_directory (str): path to a directory that does not\n exist or is empty. This directory will be used to create heapfiles\n with sizes no larger than ``heap_buffer_size`` which are written in the\n of the pattern N.dat where N is in the numbering 0, 1, 2, ... up\n to the number of files necessary to handle the raster.\n percentile_list (list): sorted list of percentiles to report must\n contain values in the range [0, 100].\n heap_buffer_size (int): defines approximately how many elements to hold in\n a single heap file. This is proportional to the amount of maximum\n memory to use when storing elements before a sort and write to\n disk.\n ffi_buffer_size (int): defines how many elements will be stored per\n heap file buffer for iteration.\n\n Returns:\n A list of len(percentile_list) elements long containing the\n percentile values (ranging from [0, 100]) in ``base_raster_path_band``\n where the interpolation scheme is \"higher\" (i.e. any percentile splits\n will select the next element higher than the percentile cutoff).\n\n "; -static PyMethodDef __pyx_mdef_15pygeoprocessing_18geoprocessing_core_7raster_band_percentile = {"raster_band_percentile", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_18geoprocessing_core_7raster_band_percentile, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_18geoprocessing_core_6raster_band_percentile}; -static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_7raster_band_percentile(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_base_raster_path_band = 0; - PyObject *__pyx_v_working_sort_directory = 0; - PyObject *__pyx_v_percentile_list = 0; - PyObject *__pyx_v_heap_buffer_size = 0; - PyObject *__pyx_v_ffi_buffer_size = 0; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("raster_band_percentile (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_base_raster_path_band,&__pyx_n_s_working_sort_directory,&__pyx_n_s_percentile_list,&__pyx_n_s_heap_buffer_size,&__pyx_n_s_ffi_buffer_size,0}; - PyObject* values[5] = {0,0,0,0,0}; - values[3] = ((PyObject *)__pyx_int_268435456); - values[4] = ((PyObject *)__pyx_int_1024); - 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_base_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_working_sort_directory)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("raster_band_percentile", 0, 3, 5, 1); __PYX_ERR(0, 626, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_percentile_list)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("raster_band_percentile", 0, 3, 5, 2); __PYX_ERR(0, 626, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_heap_buffer_size); - 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_ffi_buffer_size); - if (value) { values[4] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "raster_band_percentile") < 0)) __PYX_ERR(0, 626, __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_base_raster_path_band = values[0]; - __pyx_v_working_sort_directory = values[1]; - __pyx_v_percentile_list = values[2]; - __pyx_v_heap_buffer_size = values[3]; - __pyx_v_ffi_buffer_size = values[4]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("raster_band_percentile", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 626, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core.raster_band_percentile", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_15pygeoprocessing_18geoprocessing_core_6raster_band_percentile(__pyx_self, __pyx_v_base_raster_path_band, __pyx_v_working_sort_directory, __pyx_v_percentile_list, __pyx_v_heap_buffer_size, __pyx_v_ffi_buffer_size); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core_6raster_band_percentile(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_base_raster_path_band, PyObject *__pyx_v_working_sort_directory, PyObject *__pyx_v_percentile_list, PyObject *__pyx_v_heap_buffer_size, PyObject *__pyx_v_ffi_buffer_size) { - PyObject *__pyx_v_raster_type = NULL; - 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("raster_band_percentile", 0); - - /* "pygeoprocessing/geoprocessing_core.pyx":655 - * - * """ - * raster_type = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< - * base_raster_path_band[0])['datatype'] - * if raster_type in ( - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 655, __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, 655, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":656 - * """ - * raster_type = pygeoprocessing.get_raster_info( - * base_raster_path_band[0])['datatype'] # <<<<<<<<<<<<<< - * if raster_type in ( - * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, - */ - __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_base_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 656, __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); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 655, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_t_1, __pyx_n_u_datatype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 656, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_raster_type = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":657 - * raster_type = pygeoprocessing.get_raster_info( - * base_raster_path_band[0])['datatype'] - * if raster_type in ( # <<<<<<<<<<<<<< - * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, - * gdal.GDT_UInt32): - */ - __Pyx_INCREF(__pyx_v_raster_type); - __pyx_t_3 = __pyx_v_raster_type; - - /* "pygeoprocessing/geoprocessing_core.pyx":658 - * base_raster_path_band[0])['datatype'] - * if raster_type in ( - * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, # <<<<<<<<<<<<<< - * gdal.GDT_UInt32): - * return _raster_band_percentile_int( - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 658, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 658, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 657, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":657 - * raster_type = pygeoprocessing.get_raster_info( - * base_raster_path_band[0])['datatype'] - * if raster_type in ( # <<<<<<<<<<<<<< - * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, - * gdal.GDT_UInt32): - */ - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 657, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L4_bool_binop_done; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":658 - * base_raster_path_band[0])['datatype'] - * if raster_type in ( - * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, # <<<<<<<<<<<<<< - * gdal.GDT_UInt32): - * return _raster_band_percentile_int( - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 658, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Int16); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 658, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 657, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":657 - * raster_type = pygeoprocessing.get_raster_info( - * base_raster_path_band[0])['datatype'] - * if raster_type in ( # <<<<<<<<<<<<<< - * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, - * gdal.GDT_UInt32): - */ - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 657, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L4_bool_binop_done; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":658 - * base_raster_path_band[0])['datatype'] - * if raster_type in ( - * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, # <<<<<<<<<<<<<< - * gdal.GDT_UInt32): - * return _raster_band_percentile_int( - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 658, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_UInt16); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 658, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 657, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":657 - * raster_type = pygeoprocessing.get_raster_info( - * base_raster_path_band[0])['datatype'] - * if raster_type in ( # <<<<<<<<<<<<<< - * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, - * gdal.GDT_UInt32): - */ - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 657, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L4_bool_binop_done; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":658 - * base_raster_path_band[0])['datatype'] - * if raster_type in ( - * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, # <<<<<<<<<<<<<< - * gdal.GDT_UInt32): - * return _raster_band_percentile_int( - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 658, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Int32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 658, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 657, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":657 - * raster_type = pygeoprocessing.get_raster_info( - * base_raster_path_band[0])['datatype'] - * if raster_type in ( # <<<<<<<<<<<<<< - * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, - * gdal.GDT_UInt32): - */ - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 657, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L4_bool_binop_done; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":659 - * if raster_type in ( - * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, - * gdal.GDT_UInt32): # <<<<<<<<<<<<<< - * return _raster_band_percentile_int( - * base_raster_path_band, working_sort_directory, percentile_list, - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 659, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_UInt32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 659, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 657, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":657 - * raster_type = pygeoprocessing.get_raster_info( - * base_raster_path_band[0])['datatype'] - * if raster_type in ( # <<<<<<<<<<<<<< - * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, - * gdal.GDT_UInt32): - */ - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 657, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_5 = __pyx_t_6; - __pyx_L4_bool_binop_done:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = (__pyx_t_5 != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/geoprocessing_core.pyx":660 - * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, - * gdal.GDT_UInt32): - * return _raster_band_percentile_int( # <<<<<<<<<<<<<< - * base_raster_path_band, working_sort_directory, percentile_list, - * heap_buffer_size, ffi_buffer_size) - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_raster_band_percentile_int); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 660, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/geoprocessing_core.pyx":662 - * return _raster_band_percentile_int( - * base_raster_path_band, working_sort_directory, percentile_list, - * heap_buffer_size, ffi_buffer_size) # <<<<<<<<<<<<<< - * elif raster_type in (gdal.GDT_Float32, gdal.GDT_Float64): - * return _raster_band_percentile_double( - */ - __pyx_t_2 = NULL; - __pyx_t_7 = 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_7 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[6] = {__pyx_t_2, __pyx_v_base_raster_path_band, __pyx_v_working_sort_directory, __pyx_v_percentile_list, __pyx_v_heap_buffer_size, __pyx_v_ffi_buffer_size}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_7, 5+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 660, __pyx_L1_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[6] = {__pyx_t_2, __pyx_v_base_raster_path_band, __pyx_v_working_sort_directory, __pyx_v_percentile_list, __pyx_v_heap_buffer_size, __pyx_v_ffi_buffer_size}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_7, 5+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 660, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - { - __pyx_t_4 = PyTuple_New(5+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 660, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (__pyx_t_2) { - __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __pyx_t_2 = NULL; - } - __Pyx_INCREF(__pyx_v_base_raster_path_band); - __Pyx_GIVEREF(__pyx_v_base_raster_path_band); - PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_7, __pyx_v_base_raster_path_band); - __Pyx_INCREF(__pyx_v_working_sort_directory); - __Pyx_GIVEREF(__pyx_v_working_sort_directory); - PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_7, __pyx_v_working_sort_directory); - __Pyx_INCREF(__pyx_v_percentile_list); - __Pyx_GIVEREF(__pyx_v_percentile_list); - PyTuple_SET_ITEM(__pyx_t_4, 2+__pyx_t_7, __pyx_v_percentile_list); - __Pyx_INCREF(__pyx_v_heap_buffer_size); - __Pyx_GIVEREF(__pyx_v_heap_buffer_size); - PyTuple_SET_ITEM(__pyx_t_4, 3+__pyx_t_7, __pyx_v_heap_buffer_size); - __Pyx_INCREF(__pyx_v_ffi_buffer_size); - __Pyx_GIVEREF(__pyx_v_ffi_buffer_size); - PyTuple_SET_ITEM(__pyx_t_4, 4+__pyx_t_7, __pyx_v_ffi_buffer_size); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 660, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - - /* "pygeoprocessing/geoprocessing_core.pyx":657 - * raster_type = pygeoprocessing.get_raster_info( - * base_raster_path_band[0])['datatype'] - * if raster_type in ( # <<<<<<<<<<<<<< - * gdal.GDT_Byte, gdal.GDT_Int16, gdal.GDT_UInt16, gdal.GDT_Int32, - * gdal.GDT_UInt32): - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":663 - * base_raster_path_band, working_sort_directory, percentile_list, - * heap_buffer_size, ffi_buffer_size) - * elif raster_type in (gdal.GDT_Float32, gdal.GDT_Float64): # <<<<<<<<<<<<<< - * return _raster_band_percentile_double( - * base_raster_path_band, working_sort_directory, percentile_list, - */ - __Pyx_INCREF(__pyx_v_raster_type); - __pyx_t_3 = __pyx_v_raster_type; - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 663, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Float32); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 663, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 663, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 663, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (!__pyx_t_5) { - } else { - __pyx_t_6 = __pyx_t_5; - goto __pyx_L9_bool_binop_done; - } - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 663, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 663, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 663, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 663, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_6 = __pyx_t_5; - __pyx_L9_bool_binop_done:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_5 = (__pyx_t_6 != 0); - if (likely(__pyx_t_5)) { - - /* "pygeoprocessing/geoprocessing_core.pyx":664 - * heap_buffer_size, ffi_buffer_size) - * elif raster_type in (gdal.GDT_Float32, gdal.GDT_Float64): - * return _raster_band_percentile_double( # <<<<<<<<<<<<<< - * base_raster_path_band, working_sort_directory, percentile_list, - * heap_buffer_size, ffi_buffer_size) - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_raster_band_percentile_double); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 664, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/geoprocessing_core.pyx":666 - * return _raster_band_percentile_double( - * base_raster_path_band, working_sort_directory, percentile_list, - * heap_buffer_size, ffi_buffer_size) # <<<<<<<<<<<<<< - * else: - * raise ValueError( - */ - __pyx_t_4 = NULL; - __pyx_t_7 = 0; - 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); - __pyx_t_7 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[6] = {__pyx_t_4, __pyx_v_base_raster_path_band, __pyx_v_working_sort_directory, __pyx_v_percentile_list, __pyx_v_heap_buffer_size, __pyx_v_ffi_buffer_size}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_7, 5+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 664, __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[6] = {__pyx_t_4, __pyx_v_base_raster_path_band, __pyx_v_working_sort_directory, __pyx_v_percentile_list, __pyx_v_heap_buffer_size, __pyx_v_ffi_buffer_size}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_7, 5+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 664, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - { - __pyx_t_2 = PyTuple_New(5+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 664, __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_INCREF(__pyx_v_base_raster_path_band); - __Pyx_GIVEREF(__pyx_v_base_raster_path_band); - PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_7, __pyx_v_base_raster_path_band); - __Pyx_INCREF(__pyx_v_working_sort_directory); - __Pyx_GIVEREF(__pyx_v_working_sort_directory); - PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_7, __pyx_v_working_sort_directory); - __Pyx_INCREF(__pyx_v_percentile_list); - __Pyx_GIVEREF(__pyx_v_percentile_list); - PyTuple_SET_ITEM(__pyx_t_2, 2+__pyx_t_7, __pyx_v_percentile_list); - __Pyx_INCREF(__pyx_v_heap_buffer_size); - __Pyx_GIVEREF(__pyx_v_heap_buffer_size); - PyTuple_SET_ITEM(__pyx_t_2, 3+__pyx_t_7, __pyx_v_heap_buffer_size); - __Pyx_INCREF(__pyx_v_ffi_buffer_size); - __Pyx_GIVEREF(__pyx_v_ffi_buffer_size); - PyTuple_SET_ITEM(__pyx_t_2, 4+__pyx_t_7, __pyx_v_ffi_buffer_size); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 664, __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_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - - /* "pygeoprocessing/geoprocessing_core.pyx":663 - * base_raster_path_band, working_sort_directory, percentile_list, - * heap_buffer_size, ffi_buffer_size) - * elif raster_type in (gdal.GDT_Float32, gdal.GDT_Float64): # <<<<<<<<<<<<<< - * return _raster_band_percentile_double( - * base_raster_path_band, working_sort_directory, percentile_list, - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":668 - * heap_buffer_size, ffi_buffer_size) - * else: - * raise ValueError( # <<<<<<<<<<<<<< - * 'Cannot process raster type %s (not a known integer nor float ' - * 'type)', raster_type) - */ - /*else*/ { - - /* "pygeoprocessing/geoprocessing_core.pyx":670 - * raise ValueError( - * 'Cannot process raster type %s (not a known integer nor float ' - * 'type)', raster_type) # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 668, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_kp_u_Cannot_process_raster_type_s_not); - __Pyx_GIVEREF(__pyx_kp_u_Cannot_process_raster_type_s_not); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_u_Cannot_process_raster_type_s_not); - __Pyx_INCREF(__pyx_v_raster_type); - __Pyx_GIVEREF(__pyx_v_raster_type); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_raster_type); - - /* "pygeoprocessing/geoprocessing_core.pyx":668 - * heap_buffer_size, ffi_buffer_size) - * else: - * raise ValueError( # <<<<<<<<<<<<<< - * 'Cannot process raster type %s (not a known integer nor float ' - * 'type)', raster_type) - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 668, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 668, __pyx_L1_error) - } - - /* "pygeoprocessing/geoprocessing_core.pyx":626 - * - * - * def raster_band_percentile( # <<<<<<<<<<<<<< - * base_raster_path_band, working_sort_directory, percentile_list, - * heap_buffer_size=2**28, ffi_buffer_size=2**10): - */ - - /* 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_4); - __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core.raster_band_percentile", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_raster_type); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pygeoprocessing/geoprocessing_core.pyx":673 - * - * - * def _raster_band_percentile_int( # <<<<<<<<<<<<<< - * base_raster_path_band, working_sort_directory, percentile_list, - * heap_buffer_size, ffi_buffer_size): - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_9_raster_band_percentile_int(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_15pygeoprocessing_18geoprocessing_core_8_raster_band_percentile_int[] = "Calculate percentiles of a raster band of an integer type.\n\n Parameters:\n base_raster_path_band (tuple): raster path band tuple to a raster that\n is of an integer type.\n working_sort_directory (str): path to a directory that does not\n exist or is empty. This directory will be used to create heapfiles\n with sizes no larger than ``heap_buffer_size`` which are written in the\n of the pattern N.dat where N is in the numbering 0, 1, 2, ... up\n to the number of files necessary to handle the raster.\n percentile_list (list): sorted list of percentiles to report must\n contain values in the range [0, 100].\n heap_buffer_size (int): defines approximately how many elements to hold in\n a single heap file. This is proportional to the amount of maximum\n memory to use when storing elements before a sort and write to\n disk.\n ffi_buffer_size (int): defines how many elements to store in a file\n buffer at any time.\n\n Returns:\n A list of len(percentile_list) elements long containing the\n percentile values (ranging from [0, 100]) in ``base_raster_path_band``\n where the interpolation scheme is \"higher\" (i.e. any percentile splits\n will select the next element higher than the percentile cutoff).\n\n "; -static PyMethodDef __pyx_mdef_15pygeoprocessing_18geoprocessing_core_9_raster_band_percentile_int = {"_raster_band_percentile_int", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_18geoprocessing_core_9_raster_band_percentile_int, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_18geoprocessing_core_8_raster_band_percentile_int}; -static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_9_raster_band_percentile_int(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_base_raster_path_band = 0; - PyObject *__pyx_v_working_sort_directory = 0; - PyObject *__pyx_v_percentile_list = 0; - PyObject *__pyx_v_heap_buffer_size = 0; - PyObject *__pyx_v_ffi_buffer_size = 0; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_raster_band_percentile_int (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_base_raster_path_band,&__pyx_n_s_working_sort_directory,&__pyx_n_s_percentile_list,&__pyx_n_s_heap_buffer_size,&__pyx_n_s_ffi_buffer_size,0}; - PyObject* values[5] = {0,0,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 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_base_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_working_sort_directory)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_raster_band_percentile_int", 1, 5, 5, 1); __PYX_ERR(0, 673, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_percentile_list)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_raster_band_percentile_int", 1, 5, 5, 2); __PYX_ERR(0, 673, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_heap_buffer_size)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_raster_band_percentile_int", 1, 5, 5, 3); __PYX_ERR(0, 673, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 4: - if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_ffi_buffer_size)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_raster_band_percentile_int", 1, 5, 5, 4); __PYX_ERR(0, 673, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_raster_band_percentile_int") < 0)) __PYX_ERR(0, 673, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 5) { - 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); - values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - } - __pyx_v_base_raster_path_band = values[0]; - __pyx_v_working_sort_directory = values[1]; - __pyx_v_percentile_list = values[2]; - __pyx_v_heap_buffer_size = values[3]; - __pyx_v_ffi_buffer_size = values[4]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_raster_band_percentile_int", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 673, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core._raster_band_percentile_int", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_15pygeoprocessing_18geoprocessing_core_8_raster_band_percentile_int(__pyx_self, __pyx_v_base_raster_path_band, __pyx_v_working_sort_directory, __pyx_v_percentile_list, __pyx_v_heap_buffer_size, __pyx_v_ffi_buffer_size); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core_8_raster_band_percentile_int(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_base_raster_path_band, PyObject *__pyx_v_working_sort_directory, PyObject *__pyx_v_percentile_list, PyObject *__pyx_v_heap_buffer_size, PyObject *__pyx_v_ffi_buffer_size) { - FILE *__pyx_v_fptr; - __pyx_t_15pygeoprocessing_18geoprocessing_core_FastFileIteratorLongLongIntPtr __pyx_v_fast_file_iterator; - std::vector<__pyx_t_15pygeoprocessing_18geoprocessing_core_FastFileIteratorLongLongIntPtr> __pyx_v_fast_file_iterator_vector; - std::vector<__pyx_t_15pygeoprocessing_18geoprocessing_core_FastFileIteratorLongLongIntPtr> ::iterator __pyx_v_ffiv_iter; - int __pyx_v_percentile_index; - PY_LONG_LONG __pyx_v_i; - PY_LONG_LONG __pyx_v_n_elements; - __pyx_t_15pygeoprocessing_18geoprocessing_core_int64t __pyx_v_next_val; - double __pyx_v_step_size; - double __pyx_v_current_percentile; - double __pyx_v_current_step; - PyObject *__pyx_v_result_list = NULL; - int __pyx_v_rm_dir_when_done; - __Pyx_memviewslice __pyx_v_buffer_data = { 0, 0, { 0 }, { 0 }, { 0 } }; - PyObject *__pyx_v_heapfile_list = NULL; - PyObject *__pyx_v_file_index = NULL; - PyObject *__pyx_v_raster_info = NULL; - PyObject *__pyx_v_nodata = NULL; - PY_LONG_LONG __pyx_v_n_pixels; - PY_LONG_LONG __pyx_v_pixels_processed; - PyObject *__pyx_v_last_update = NULL; - CYTHON_UNUSED PyObject *__pyx_v__ = NULL; - PyObject *__pyx_v_block_data = NULL; - PyObject *__pyx_v_file_path = NULL; - 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; - PyObject *__pyx_t_6 = NULL; - int __pyx_t_7; - PyObject *__pyx_t_8 = NULL; - PY_LONG_LONG __pyx_t_9; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - Py_ssize_t __pyx_t_12; - PyObject *(*__pyx_t_13)(PyObject *); - PyObject *(*__pyx_t_14)(PyObject *); - int __pyx_t_15; - Py_ssize_t __pyx_t_16; - Py_UCS4 __pyx_t_17; - double __pyx_t_18; - PyObject *__pyx_t_19 = NULL; - PyObject *__pyx_t_20 = NULL; - __Pyx_memviewslice __pyx_t_21 = { 0, 0, { 0 }, { 0 }, { 0 } }; - int __pyx_t_22; - char const *__pyx_t_23; - Py_ssize_t __pyx_t_24; - size_t __pyx_t_25; - char const *__pyx_t_26; - PY_LONG_LONG __pyx_t_27; - PY_LONG_LONG __pyx_t_28; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("_raster_band_percentile_int", 0); - - /* "pygeoprocessing/geoprocessing_core.pyx":706 - * cdef vector[FastFileIteratorLongLongIntPtr] fast_file_iterator_vector - * cdef vector[FastFileIteratorLongLongIntPtr].iterator ffiv_iter - * cdef int percentile_index = 0 # <<<<<<<<<<<<<< - * cdef long long i, n_elements = 0 - * cdef int64t next_val = 0L - */ - __pyx_v_percentile_index = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":707 - * cdef vector[FastFileIteratorLongLongIntPtr].iterator ffiv_iter - * cdef int percentile_index = 0 - * cdef long long i, n_elements = 0 # <<<<<<<<<<<<<< - * cdef int64t next_val = 0L - * cdef double step_size, current_percentile - */ - __pyx_v_n_elements = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":708 - * cdef int percentile_index = 0 - * cdef long long i, n_elements = 0 - * cdef int64t next_val = 0L # <<<<<<<<<<<<<< - * cdef double step_size, current_percentile - * cdef double current_step = 0.0 - */ - __pyx_v_next_val = 0L; - - /* "pygeoprocessing/geoprocessing_core.pyx":710 - * cdef int64t next_val = 0L - * cdef double step_size, current_percentile - * cdef double current_step = 0.0 # <<<<<<<<<<<<<< - * result_list = [] - * rm_dir_when_done = False - */ - __pyx_v_current_step = 0.0; - - /* "pygeoprocessing/geoprocessing_core.pyx":711 - * cdef double step_size, current_percentile - * cdef double current_step = 0.0 - * result_list = [] # <<<<<<<<<<<<<< - * rm_dir_when_done = False - * try: - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 711, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_result_list = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":712 - * cdef double current_step = 0.0 - * result_list = [] - * rm_dir_when_done = False # <<<<<<<<<<<<<< - * try: - * os.makedirs(working_sort_directory) - */ - __pyx_v_rm_dir_when_done = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":713 - * result_list = [] - * rm_dir_when_done = False - * try: # <<<<<<<<<<<<<< - * os.makedirs(working_sort_directory) - * rm_dir_when_done = True - */ - { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __Pyx_ExceptionSave(&__pyx_t_2, &__pyx_t_3, &__pyx_t_4); - __Pyx_XGOTREF(__pyx_t_2); - __Pyx_XGOTREF(__pyx_t_3); - __Pyx_XGOTREF(__pyx_t_4); - /*try:*/ { - - /* "pygeoprocessing/geoprocessing_core.pyx":714 - * rm_dir_when_done = False - * try: - * os.makedirs(working_sort_directory) # <<<<<<<<<<<<<< - * rm_dir_when_done = True - * except OSError: - */ - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_os); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 714, __pyx_L3_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_makedirs); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 714, __pyx_L3_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_6))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_v_working_sort_directory) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_working_sort_directory); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 714, __pyx_L3_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":715 - * try: - * os.makedirs(working_sort_directory) - * rm_dir_when_done = True # <<<<<<<<<<<<<< - * except OSError: - * pass - */ - __pyx_v_rm_dir_when_done = 1; - - /* "pygeoprocessing/geoprocessing_core.pyx":713 - * result_list = [] - * rm_dir_when_done = False - * try: # <<<<<<<<<<<<<< - * os.makedirs(working_sort_directory) - * rm_dir_when_done = True - */ - } - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L8_try_end; - __pyx_L3_error:; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":716 - * os.makedirs(working_sort_directory) - * rm_dir_when_done = True - * except OSError: # <<<<<<<<<<<<<< - * pass - * - */ - __pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OSError); - if (__pyx_t_7) { - __Pyx_ErrRestore(0,0,0); - goto __pyx_L4_exception_handled; - } - goto __pyx_L5_except_error; - __pyx_L5_except_error:; - - /* "pygeoprocessing/geoprocessing_core.pyx":713 - * result_list = [] - * rm_dir_when_done = False - * try: # <<<<<<<<<<<<<< - * os.makedirs(working_sort_directory) - * rm_dir_when_done = True - */ - __Pyx_XGIVEREF(__pyx_t_2); - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_XGIVEREF(__pyx_t_4); - __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4); - goto __pyx_L1_error; - __pyx_L4_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_2); - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_XGIVEREF(__pyx_t_4); - __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4); - __pyx_L8_try_end:; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":721 - * cdef int64t[:] buffer_data - * - * heapfile_list = [] # <<<<<<<<<<<<<< - * file_index = 0 - * raster_info = pygeoprocessing.get_raster_info( - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 721, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_heapfile_list = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":722 - * - * heapfile_list = [] - * file_index = 0 # <<<<<<<<<<<<<< - * raster_info = pygeoprocessing.get_raster_info( - * base_raster_path_band[0]) - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_v_file_index = __pyx_int_0; - - /* "pygeoprocessing/geoprocessing_core.pyx":723 - * heapfile_list = [] - * file_index = 0 - * raster_info = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< - * base_raster_path_band[0]) - * nodata = raster_info['nodata'][base_raster_path_band[1]-1] - */ - __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 723, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 723, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":724 - * file_index = 0 - * raster_info = pygeoprocessing.get_raster_info( - * base_raster_path_band[0]) # <<<<<<<<<<<<<< - * nodata = raster_info['nodata'][base_raster_path_band[1]-1] - * cdef long long n_pixels = raster_info['raster_size'][0] * raster_info['raster_size'][1] - */ - __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_base_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 724, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - } - } - __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 723, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_raster_info = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":725 - * raster_info = pygeoprocessing.get_raster_info( - * base_raster_path_band[0]) - * nodata = raster_info['nodata'][base_raster_path_band[1]-1] # <<<<<<<<<<<<<< - * cdef long long n_pixels = raster_info['raster_size'][0] * raster_info['raster_size'][1] - * - */ - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 725, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_base_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 725, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyInt_SubtractObjC(__pyx_t_5, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 725, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 725, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_nodata = __pyx_t_5; - __pyx_t_5 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":726 - * base_raster_path_band[0]) - * nodata = raster_info['nodata'][base_raster_path_band[1]-1] - * cdef long long n_pixels = raster_info['raster_size'][0] * raster_info['raster_size'][1] # <<<<<<<<<<<<<< - * - * LOGGER.debug('total number of pixels %s (%s)', n_pixels, raster_info['raster_size']) - */ - __pyx_t_5 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 726, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_5, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 726, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 726, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_5, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 726, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyNumber_Multiply(__pyx_t_6, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 726, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_9 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_t_5); if (unlikely((__pyx_t_9 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 726, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_n_pixels = __pyx_t_9; - - /* "pygeoprocessing/geoprocessing_core.pyx":728 - * cdef long long n_pixels = raster_info['raster_size'][0] * raster_info['raster_size'][1] - * - * LOGGER.debug('total number of pixels %s (%s)', n_pixels, raster_info['raster_size']) # <<<<<<<<<<<<<< - * cdef long long pixels_processed = 0 - * LOGGER.debug('sorting data to heap') - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 728, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_debug); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 728, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_n_pixels); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 728, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 728, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_10 = NULL; - __pyx_t_7 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_10)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - __pyx_t_7 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[4] = {__pyx_t_10, __pyx_kp_u_total_number_of_pixels_s_s, __pyx_t_1, __pyx_t_8}; - __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 3+__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 728, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[4] = {__pyx_t_10, __pyx_kp_u_total_number_of_pixels_s_s, __pyx_t_1, __pyx_t_8}; - __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 3+__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 728, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - { - __pyx_t_11 = PyTuple_New(3+__pyx_t_7); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 728, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - if (__pyx_t_10) { - __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10); __pyx_t_10 = NULL; - } - __Pyx_INCREF(__pyx_kp_u_total_number_of_pixels_s_s); - __Pyx_GIVEREF(__pyx_kp_u_total_number_of_pixels_s_s); - PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_7, __pyx_kp_u_total_number_of_pixels_s_s); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_7, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_11, 2+__pyx_t_7, __pyx_t_8); - __pyx_t_1 = 0; - __pyx_t_8 = 0; - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_11, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 728, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":729 - * - * LOGGER.debug('total number of pixels %s (%s)', n_pixels, raster_info['raster_size']) - * cdef long long pixels_processed = 0 # <<<<<<<<<<<<<< - * LOGGER.debug('sorting data to heap') - * last_update = time.time() - */ - __pyx_v_pixels_processed = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":730 - * LOGGER.debug('total number of pixels %s (%s)', n_pixels, raster_info['raster_size']) - * cdef long long pixels_processed = 0 - * LOGGER.debug('sorting data to heap') # <<<<<<<<<<<<<< - * last_update = time.time() - * for _, block_data in pygeoprocessing.iterblocks( - */ - __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 730, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_debug); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 730, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - } - } - __pyx_t_5 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_6, __pyx_kp_u_sorting_data_to_heap) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_kp_u_sorting_data_to_heap); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 730, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":731 - * cdef long long pixels_processed = 0 - * LOGGER.debug('sorting data to heap') - * last_update = time.time() # <<<<<<<<<<<<<< - * for _, block_data in pygeoprocessing.iterblocks( - * base_raster_path_band, largest_block=heap_buffer_size): - */ - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_time); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 731, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_time); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 731, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - __pyx_t_5 = (__pyx_t_11) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_11) : __Pyx_PyObject_CallNoArg(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 731, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_last_update = __pyx_t_5; - __pyx_t_5 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":732 - * LOGGER.debug('sorting data to heap') - * last_update = time.time() - * for _, block_data in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * base_raster_path_band, largest_block=heap_buffer_size): - * pixels_processed += block_data.size - */ - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 732, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 732, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":733 - * last_update = time.time() - * for _, block_data in pygeoprocessing.iterblocks( - * base_raster_path_band, largest_block=heap_buffer_size): # <<<<<<<<<<<<<< - * pixels_processed += block_data.size - * if time.time() - last_update > 5.0: - */ - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 732, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(__pyx_v_base_raster_path_band); - __Pyx_GIVEREF(__pyx_v_base_raster_path_band); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_base_raster_path_band); - __pyx_t_11 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 733, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_largest_block, __pyx_v_heap_buffer_size) < 0) __PYX_ERR(0, 733, __pyx_L1_error) - - /* "pygeoprocessing/geoprocessing_core.pyx":732 - * LOGGER.debug('sorting data to heap') - * last_update = time.time() - * for _, block_data in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * base_raster_path_band, largest_block=heap_buffer_size): - * pixels_processed += block_data.size - */ - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 732, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - if (likely(PyList_CheckExact(__pyx_t_8)) || PyTuple_CheckExact(__pyx_t_8)) { - __pyx_t_11 = __pyx_t_8; __Pyx_INCREF(__pyx_t_11); __pyx_t_12 = 0; - __pyx_t_13 = NULL; - } else { - __pyx_t_12 = -1; __pyx_t_11 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 732, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_13 = Py_TYPE(__pyx_t_11)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 732, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - for (;;) { - if (likely(!__pyx_t_13)) { - if (likely(PyList_CheckExact(__pyx_t_11))) { - if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_11)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_8 = PyList_GET_ITEM(__pyx_t_11, __pyx_t_12); __Pyx_INCREF(__pyx_t_8); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 732, __pyx_L1_error) - #else - __pyx_t_8 = PySequence_ITEM(__pyx_t_11, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 732, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - #endif - } else { - if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_11)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_11, __pyx_t_12); __Pyx_INCREF(__pyx_t_8); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 732, __pyx_L1_error) - #else - __pyx_t_8 = PySequence_ITEM(__pyx_t_11, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 732, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - #endif - } - } else { - __pyx_t_8 = __pyx_t_13(__pyx_t_11); - if (unlikely(!__pyx_t_8)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 732, __pyx_L1_error) - } - break; - } - __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, 732, __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_6 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_5 = PyList_GET_ITEM(sequence, 0); - __pyx_t_6 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(__pyx_t_6); - #else - __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 732, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 732, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - #endif - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_1 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 732, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_14 = Py_TYPE(__pyx_t_1)->tp_iternext; - index = 0; __pyx_t_5 = __pyx_t_14(__pyx_t_1); if (unlikely(!__pyx_t_5)) goto __pyx_L11_unpacking_failed; - __Pyx_GOTREF(__pyx_t_5); - index = 1; __pyx_t_6 = __pyx_t_14(__pyx_t_1); if (unlikely(!__pyx_t_6)) goto __pyx_L11_unpacking_failed; - __Pyx_GOTREF(__pyx_t_6); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_14(__pyx_t_1), 2) < 0) __PYX_ERR(0, 732, __pyx_L1_error) - __pyx_t_14 = NULL; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L12_unpacking_done; - __pyx_L11_unpacking_failed:; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_14 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 732, __pyx_L1_error) - __pyx_L12_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_5); - __pyx_t_5 = 0; - __Pyx_XDECREF_SET(__pyx_v_block_data, __pyx_t_6); - __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":734 - * for _, block_data in pygeoprocessing.iterblocks( - * base_raster_path_band, largest_block=heap_buffer_size): - * pixels_processed += block_data.size # <<<<<<<<<<<<<< - * if time.time() - last_update > 5.0: - * LOGGER.debug( - */ - __pyx_t_8 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_pixels_processed); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 734, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_block_data, __pyx_n_s_size); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 734, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_t_8, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 734, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_9 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_t_5); if (unlikely((__pyx_t_9 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 734, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_pixels_processed = __pyx_t_9; - - /* "pygeoprocessing/geoprocessing_core.pyx":735 - * base_raster_path_band, largest_block=heap_buffer_size): - * pixels_processed += block_data.size - * if time.time() - last_update > 5.0: # <<<<<<<<<<<<<< - * LOGGER.debug( - * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' - */ - __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_time); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 735, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_time); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 735, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - } - } - __pyx_t_5 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 735, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = PyNumber_Subtract(__pyx_t_5, __pyx_v_last_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 735, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyObject_RichCompare(__pyx_t_8, __pyx_float_5_0, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 735, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_15 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_15 < 0)) __PYX_ERR(0, 735, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_15) { - - /* "pygeoprocessing/geoprocessing_core.pyx":736 - * pixels_processed += block_data.size - * if time.time() - last_update > 5.0: - * LOGGER.debug( # <<<<<<<<<<<<<< - * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' - * f'complete, {pixels_processed} out of {n_pixels}'), - */ - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 736, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_debug); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 736, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":737 - * if time.time() - last_update > 5.0: - * LOGGER.debug( - * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' # <<<<<<<<<<<<<< - * f'complete, {pixels_processed} out of {n_pixels}'), - * - */ - __pyx_t_8 = PyTuple_New(6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 737, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_16 = 0; - __pyx_t_17 = 127; - __Pyx_INCREF(__pyx_kp_u_data_sort_to_heap); - __pyx_t_16 += 18; - __Pyx_GIVEREF(__pyx_kp_u_data_sort_to_heap); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_kp_u_data_sort_to_heap); - __pyx_t_18 = (100. * __pyx_v_pixels_processed); - if (unlikely(__pyx_v_n_pixels == 0)) { - PyErr_SetString(PyExc_ZeroDivisionError, "float division"); - __PYX_ERR(0, 737, __pyx_L1_error) - } - __pyx_t_1 = PyFloat_FromDouble((__pyx_t_18 / ((double)__pyx_v_n_pixels))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 737, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = __Pyx_PyObject_Format(__pyx_t_1, __pyx_kp_u_1f); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 737, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_17 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_10) > __pyx_t_17) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_10) : __pyx_t_17; - __pyx_t_16 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_10); - __pyx_t_10 = 0; - __Pyx_INCREF(__pyx_kp_u_complete); - __pyx_t_16 += 12; - __Pyx_GIVEREF(__pyx_kp_u_complete); - PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_kp_u_complete); - - /* "pygeoprocessing/geoprocessing_core.pyx":738 - * LOGGER.debug( - * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' - * f'complete, {pixels_processed} out of {n_pixels}'), # <<<<<<<<<<<<<< - * - * last_update = time.time() - */ - __pyx_t_10 = __Pyx_PyUnicode_From_PY_LONG_LONG(__pyx_v_pixels_processed, 0, ' ', 'd'); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 738, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_16 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_10); - __pyx_t_10 = 0; - __Pyx_INCREF(__pyx_kp_u_out_of); - __pyx_t_16 += 8; - __Pyx_GIVEREF(__pyx_kp_u_out_of); - PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_kp_u_out_of); - __pyx_t_10 = __Pyx_PyUnicode_From_PY_LONG_LONG(__pyx_v_n_pixels, 0, ' ', 'd'); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 738, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_16 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_8, 5, __pyx_t_10); - __pyx_t_10 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":737 - * if time.time() - last_update > 5.0: - * LOGGER.debug( - * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' # <<<<<<<<<<<<<< - * f'complete, {pixels_processed} out of {n_pixels}'), - * - */ - __pyx_t_10 = __Pyx_PyUnicode_Join(__pyx_t_8, 6, __pyx_t_16, __pyx_t_17); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 737, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - __pyx_t_5 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_8, __pyx_t_10) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_10); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 736, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":736 - * pixels_processed += block_data.size - * if time.time() - last_update > 5.0: - * LOGGER.debug( # <<<<<<<<<<<<<< - * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' - * f'complete, {pixels_processed} out of {n_pixels}'), - */ - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 736, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); - __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":740 - * f'complete, {pixels_processed} out of {n_pixels}'), - * - * last_update = time.time() # <<<<<<<<<<<<<< - * buffer_data = numpy.sort( - * block_data[~numpy.isclose(block_data, nodata)]).astype( - */ - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 740, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 740, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_10); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_10, function); - } - } - __pyx_t_6 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 740, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF_SET(__pyx_v_last_update, __pyx_t_6); - __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":735 - * base_raster_path_band, largest_block=heap_buffer_size): - * pixels_processed += block_data.size - * if time.time() - last_update > 5.0: # <<<<<<<<<<<<<< - * LOGGER.debug( - * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":741 - * - * last_update = time.time() - * buffer_data = numpy.sort( # <<<<<<<<<<<<<< - * block_data[~numpy.isclose(block_data, nodata)]).astype( - * numpy.int64) - */ - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_numpy); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 741, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_sort); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 741, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":742 - * last_update = time.time() - * buffer_data = numpy.sort( - * block_data[~numpy.isclose(block_data, nodata)]).astype( # <<<<<<<<<<<<<< - * numpy.int64) - * if buffer_data.size == 0: - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 742, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_isclose); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 742, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - __pyx_t_7 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_19))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_19); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_19, function); - __pyx_t_7 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_19)) { - PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_block_data, __pyx_v_nodata}; - __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_19, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 742, __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_19)) { - PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_block_data, __pyx_v_nodata}; - __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_19, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 742, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_5); - } else - #endif - { - __pyx_t_20 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 742, __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_block_data); - __Pyx_GIVEREF(__pyx_v_block_data); - PyTuple_SET_ITEM(__pyx_t_20, 0+__pyx_t_7, __pyx_v_block_data); - __Pyx_INCREF(__pyx_v_nodata); - __Pyx_GIVEREF(__pyx_v_nodata); - PyTuple_SET_ITEM(__pyx_t_20, 1+__pyx_t_7, __pyx_v_nodata); - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_19, __pyx_t_20, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 742, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - } - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __pyx_t_19 = PyNumber_Invert(__pyx_t_5); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 742, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_block_data, __pyx_t_19); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 742, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __pyx_t_19 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_19)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_19); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - } - } - __pyx_t_10 = (__pyx_t_19) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_19, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_5); - __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 741, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_astype); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 742, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":743 - * buffer_data = numpy.sort( - * block_data[~numpy.isclose(block_data, nodata)]).astype( - * numpy.int64) # <<<<<<<<<<<<<< - * if buffer_data.size == 0: - * continue - */ - __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_numpy); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 743, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 743, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_10)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - } - } - __pyx_t_6 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_10, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_5); - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 742, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":742 - * last_update = time.time() - * buffer_data = numpy.sort( - * block_data[~numpy.isclose(block_data, nodata)]).astype( # <<<<<<<<<<<<<< - * numpy.int64) - * if buffer_data.size == 0: - */ - __pyx_t_21 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_21.memview)) __PYX_ERR(0, 742, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __PYX_XDEC_MEMVIEW(&__pyx_v_buffer_data, 1); - __pyx_v_buffer_data = __pyx_t_21; - __pyx_t_21.memview = NULL; - __pyx_t_21.data = NULL; - - /* "pygeoprocessing/geoprocessing_core.pyx":744 - * block_data[~numpy.isclose(block_data, nodata)]).astype( - * numpy.int64) - * if buffer_data.size == 0: # <<<<<<<<<<<<<< - * continue - * n_elements += buffer_data.size - */ - __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_buffer_data, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 744, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_size); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 744, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyInt_EqObjC(__pyx_t_8, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 744, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_15 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_15 < 0)) __PYX_ERR(0, 744, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (__pyx_t_15) { - - /* "pygeoprocessing/geoprocessing_core.pyx":745 - * numpy.int64) - * if buffer_data.size == 0: - * continue # <<<<<<<<<<<<<< - * n_elements += buffer_data.size - * file_path = os.path.join( - */ - goto __pyx_L9_continue; - - /* "pygeoprocessing/geoprocessing_core.pyx":744 - * block_data[~numpy.isclose(block_data, nodata)]).astype( - * numpy.int64) - * if buffer_data.size == 0: # <<<<<<<<<<<<<< - * continue - * n_elements += buffer_data.size - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":746 - * if buffer_data.size == 0: - * continue - * n_elements += buffer_data.size # <<<<<<<<<<<<<< - * file_path = os.path.join( - * working_sort_directory, '%d.dat' % file_index) - */ - __pyx_t_6 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_n_elements); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 746, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_8 = __pyx_memoryview_fromslice(__pyx_v_buffer_data, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t, 0);; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 746, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_size); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 746, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = PyNumber_InPlaceAdd(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 746, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_9 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_t_8); if (unlikely((__pyx_t_9 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 746, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_n_elements = __pyx_t_9; - - /* "pygeoprocessing/geoprocessing_core.pyx":747 - * continue - * n_elements += buffer_data.size - * file_path = os.path.join( # <<<<<<<<<<<<<< - * working_sort_directory, '%d.dat' % file_index) - * heapfile_list.append(file_path) - */ - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_os); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 747, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_path); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 747, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_join); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 747, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":748 - * n_elements += buffer_data.size - * file_path = os.path.join( - * working_sort_directory, '%d.dat' % file_index) # <<<<<<<<<<<<<< - * heapfile_list.append(file_path) - * fptr = fopen(bytes(file_path.encode()), "wb") - */ - __pyx_t_6 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_d_dat, __pyx_v_file_index); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 748, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_10 = NULL; - __pyx_t_7 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_10)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - __pyx_t_7 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_working_sort_directory, __pyx_t_6}; - __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 747, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_8); - __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_10, __pyx_v_working_sort_directory, __pyx_t_6}; - __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 747, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } else - #endif - { - __pyx_t_19 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 747, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - if (__pyx_t_10) { - __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_10); __pyx_t_10 = NULL; - } - __Pyx_INCREF(__pyx_v_working_sort_directory); - __Pyx_GIVEREF(__pyx_v_working_sort_directory); - PyTuple_SET_ITEM(__pyx_t_19, 0+__pyx_t_7, __pyx_v_working_sort_directory); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_19, 1+__pyx_t_7, __pyx_t_6); - __pyx_t_6 = 0; - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_19, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 747, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF_SET(__pyx_v_file_path, __pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":749 - * file_path = os.path.join( - * working_sort_directory, '%d.dat' % file_index) - * heapfile_list.append(file_path) # <<<<<<<<<<<<<< - * fptr = fopen(bytes(file_path.encode()), "wb") - * fwrite( - */ - __pyx_t_22 = __Pyx_PyList_Append(__pyx_v_heapfile_list, __pyx_v_file_path); if (unlikely(__pyx_t_22 == ((int)-1))) __PYX_ERR(0, 749, __pyx_L1_error) - - /* "pygeoprocessing/geoprocessing_core.pyx":750 - * working_sort_directory, '%d.dat' % file_index) - * heapfile_list.append(file_path) - * fptr = fopen(bytes(file_path.encode()), "wb") # <<<<<<<<<<<<<< - * fwrite( - * &buffer_data[0], sizeof(int64t), buffer_data.size, - */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_file_path, __pyx_n_s_encode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 750, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_19 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_19)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_19); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - } - } - __pyx_t_8 = (__pyx_t_19) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_19) : __Pyx_PyObject_CallNoArg(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 750, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 750, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_23 = __Pyx_PyBytes_AsString(__pyx_t_5); if (unlikely((!__pyx_t_23) && PyErr_Occurred())) __PYX_ERR(0, 750, __pyx_L1_error) - __pyx_v_fptr = fopen(__pyx_t_23, ((char const *)"wb")); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":752 - * fptr = fopen(bytes(file_path.encode()), "wb") - * fwrite( - * &buffer_data[0], sizeof(int64t), buffer_data.size, # <<<<<<<<<<<<<< - * fptr) - * fclose(fptr) - */ - __pyx_t_24 = 0; - __pyx_t_7 = -1; - if (__pyx_t_24 < 0) { - __pyx_t_24 += __pyx_v_buffer_data.shape[0]; - if (unlikely(__pyx_t_24 < 0)) __pyx_t_7 = 0; - } else if (unlikely(__pyx_t_24 >= __pyx_v_buffer_data.shape[0])) __pyx_t_7 = 0; - if (unlikely(__pyx_t_7 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_7); - __PYX_ERR(0, 752, __pyx_L1_error) - } - __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_buffer_data, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 752, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_size); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 752, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_25 = __Pyx_PyInt_As_size_t(__pyx_t_8); if (unlikely((__pyx_t_25 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 752, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":751 - * heapfile_list.append(file_path) - * fptr = fopen(bytes(file_path.encode()), "wb") - * fwrite( # <<<<<<<<<<<<<< - * &buffer_data[0], sizeof(int64t), buffer_data.size, - * fptr) - */ - (void)(fwrite(((__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t *)(&(*((__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t *) ( /* dim=0 */ (__pyx_v_buffer_data.data + __pyx_t_24 * __pyx_v_buffer_data.strides[0]) ))))), (sizeof(__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t)), __pyx_t_25, __pyx_v_fptr)); - - /* "pygeoprocessing/geoprocessing_core.pyx":754 - * &buffer_data[0], sizeof(int64t), buffer_data.size, - * fptr) - * fclose(fptr) # <<<<<<<<<<<<<< - * file_index += 1 - * - */ - (void)(fclose(__pyx_v_fptr)); - - /* "pygeoprocessing/geoprocessing_core.pyx":755 - * fptr) - * fclose(fptr) - * file_index += 1 # <<<<<<<<<<<<<< - * - * fast_file_iterator = new FastFileIterator[int64t]( - */ - __pyx_t_8 = __Pyx_PyInt_AddObjC(__pyx_v_file_index, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 755, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF_SET(__pyx_v_file_index, __pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":758 - * - * fast_file_iterator = new FastFileIterator[int64t]( - * (bytes(file_path.encode())), ffi_buffer_size) # <<<<<<<<<<<<<< - * fast_file_iterator_vector.push_back(fast_file_iterator) - * push_heap( - */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_file_path, __pyx_n_s_encode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 758, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_19 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_19)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_19); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - } - } - __pyx_t_8 = (__pyx_t_19) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_19) : __Pyx_PyObject_CallNoArg(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 758, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 758, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_26 = __Pyx_PyBytes_AsString(__pyx_t_5); if (unlikely((!__pyx_t_26) && PyErr_Occurred())) __PYX_ERR(0, 758, __pyx_L1_error) - __pyx_t_25 = __Pyx_PyInt_As_size_t(__pyx_v_ffi_buffer_size); if (unlikely((__pyx_t_25 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 758, __pyx_L1_error) - - /* "pygeoprocessing/geoprocessing_core.pyx":757 - * file_index += 1 - * - * fast_file_iterator = new FastFileIterator[int64t]( # <<<<<<<<<<<<<< - * (bytes(file_path.encode())), ffi_buffer_size) - * fast_file_iterator_vector.push_back(fast_file_iterator) - */ - __pyx_v_fast_file_iterator = new FastFileIterator<__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t> (__pyx_t_26, __pyx_t_25); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":759 - * fast_file_iterator = new FastFileIterator[int64t]( - * (bytes(file_path.encode())), ffi_buffer_size) - * fast_file_iterator_vector.push_back(fast_file_iterator) # <<<<<<<<<<<<<< - * push_heap( - * fast_file_iterator_vector.begin(), - */ - try { - __pyx_v_fast_file_iterator_vector.push_back(__pyx_v_fast_file_iterator); - } catch(...) { - __Pyx_CppExn2PyErr(); - __PYX_ERR(0, 759, __pyx_L1_error) - } - - /* "pygeoprocessing/geoprocessing_core.pyx":760 - * (bytes(file_path.encode())), ffi_buffer_size) - * fast_file_iterator_vector.push_back(fast_file_iterator) - * push_heap( # <<<<<<<<<<<<<< - * fast_file_iterator_vector.begin(), - * fast_file_iterator_vector.end(), - */ - std::push_heap(__pyx_v_fast_file_iterator_vector.begin(), __pyx_v_fast_file_iterator_vector.end(), FastFileIteratorCompare<__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t>); - - /* "pygeoprocessing/geoprocessing_core.pyx":732 - * LOGGER.debug('sorting data to heap') - * last_update = time.time() - * for _, block_data in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * base_raster_path_band, largest_block=heap_buffer_size): - * pixels_processed += block_data.size - */ - __pyx_L9_continue:; - } - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":764 - * fast_file_iterator_vector.end(), - * FastFileIteratorCompare[int64t]) - * LOGGER.debug('calculating percentiles') # <<<<<<<<<<<<<< - * current_percentile = percentile_list[percentile_index] - * step_size = 0 - */ - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 764, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_debug); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 764, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - } - } - __pyx_t_11 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_5, __pyx_kp_u_calculating_percentiles) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_kp_u_calculating_percentiles); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 764, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":765 - * FastFileIteratorCompare[int64t]) - * LOGGER.debug('calculating percentiles') - * current_percentile = percentile_list[percentile_index] # <<<<<<<<<<<<<< - * step_size = 0 - * if n_elements > 0: - */ - __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_percentile_list, __pyx_v_percentile_index, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 765, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_18 = __pyx_PyFloat_AsDouble(__pyx_t_11); if (unlikely((__pyx_t_18 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 765, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_v_current_percentile = __pyx_t_18; - - /* "pygeoprocessing/geoprocessing_core.pyx":766 - * LOGGER.debug('calculating percentiles') - * current_percentile = percentile_list[percentile_index] - * step_size = 0 # <<<<<<<<<<<<<< - * if n_elements > 0: - * step_size = 100.0 / n_elements - */ - __pyx_v_step_size = 0.0; - - /* "pygeoprocessing/geoprocessing_core.pyx":767 - * current_percentile = percentile_list[percentile_index] - * step_size = 0 - * if n_elements > 0: # <<<<<<<<<<<<<< - * step_size = 100.0 / n_elements - * - */ - __pyx_t_15 = ((__pyx_v_n_elements > 0) != 0); - if (__pyx_t_15) { - - /* "pygeoprocessing/geoprocessing_core.pyx":768 - * step_size = 0 - * if n_elements > 0: - * step_size = 100.0 / n_elements # <<<<<<<<<<<<<< - * - * for i in range(n_elements): - */ - if (unlikely(__pyx_v_n_elements == 0)) { - PyErr_SetString(PyExc_ZeroDivisionError, "float division"); - __PYX_ERR(0, 768, __pyx_L1_error) - } - __pyx_v_step_size = (100.0 / ((double)__pyx_v_n_elements)); - - /* "pygeoprocessing/geoprocessing_core.pyx":767 - * current_percentile = percentile_list[percentile_index] - * step_size = 0 - * if n_elements > 0: # <<<<<<<<<<<<<< - * step_size = 100.0 / n_elements - * - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":770 - * step_size = 100.0 / n_elements - * - * for i in range(n_elements): # <<<<<<<<<<<<<< - * if time.time() - last_update > 5.0: - * LOGGER.debug( - */ - __pyx_t_9 = __pyx_v_n_elements; - __pyx_t_27 = __pyx_t_9; - for (__pyx_t_28 = 0; __pyx_t_28 < __pyx_t_27; __pyx_t_28+=1) { - __pyx_v_i = __pyx_t_28; - - /* "pygeoprocessing/geoprocessing_core.pyx":771 - * - * for i in range(n_elements): - * if time.time() - last_update > 5.0: # <<<<<<<<<<<<<< - * LOGGER.debug( - * 'calculating percentiles %.2f%% complete', - */ - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_time); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 771, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 771, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - } - } - __pyx_t_11 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 771, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyNumber_Subtract(__pyx_t_11, __pyx_v_last_update); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 771, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = PyObject_RichCompare(__pyx_t_5, __pyx_float_5_0, Py_GT); __Pyx_XGOTREF(__pyx_t_11); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 771, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_15 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_15 < 0)) __PYX_ERR(0, 771, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - if (__pyx_t_15) { - - /* "pygeoprocessing/geoprocessing_core.pyx":772 - * for i in range(n_elements): - * if time.time() - last_update > 5.0: - * LOGGER.debug( # <<<<<<<<<<<<<< - * 'calculating percentiles %.2f%% complete', - * 100.0 * i / float(n_elements)) - */ - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 772, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_debug); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 772, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":774 - * LOGGER.debug( - * 'calculating percentiles %.2f%% complete', - * 100.0 * i / float(n_elements)) # <<<<<<<<<<<<<< - * last_update = time.time() - * current_step = step_size * i - */ - __pyx_t_18 = (100.0 * __pyx_v_i); - if (unlikely(((double)__pyx_v_n_elements) == 0)) { - PyErr_SetString(PyExc_ZeroDivisionError, "float division"); - __PYX_ERR(0, 774, __pyx_L1_error) - } - __pyx_t_5 = PyFloat_FromDouble((__pyx_t_18 / ((double)__pyx_v_n_elements))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 774, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_19 = NULL; - __pyx_t_7 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_19)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_19); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - __pyx_t_7 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[3] = {__pyx_t_19, __pyx_kp_u_calculating_percentiles_2f_compl, __pyx_t_5}; - __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 772, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[3] = {__pyx_t_19, __pyx_kp_u_calculating_percentiles_2f_compl, __pyx_t_5}; - __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 772, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - { - __pyx_t_6 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 772, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (__pyx_t_19) { - __Pyx_GIVEREF(__pyx_t_19); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_19); __pyx_t_19 = NULL; - } - __Pyx_INCREF(__pyx_kp_u_calculating_percentiles_2f_compl); - __Pyx_GIVEREF(__pyx_kp_u_calculating_percentiles_2f_compl); - PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_7, __pyx_kp_u_calculating_percentiles_2f_compl); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_7, __pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_6, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 772, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":775 - * 'calculating percentiles %.2f%% complete', - * 100.0 * i / float(n_elements)) - * last_update = time.time() # <<<<<<<<<<<<<< - * current_step = step_size * i - * next_val = fast_file_iterator_vector.front().next() - */ - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_time); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 775, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_time); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 775, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - __pyx_t_11 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 775, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF_SET(__pyx_v_last_update, __pyx_t_11); - __pyx_t_11 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":771 - * - * for i in range(n_elements): - * if time.time() - last_update > 5.0: # <<<<<<<<<<<<<< - * LOGGER.debug( - * 'calculating percentiles %.2f%% complete', - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":776 - * 100.0 * i / float(n_elements)) - * last_update = time.time() - * current_step = step_size * i # <<<<<<<<<<<<<< - * next_val = fast_file_iterator_vector.front().next() - * if current_step >= current_percentile: - */ - __pyx_v_current_step = (__pyx_v_step_size * __pyx_v_i); - - /* "pygeoprocessing/geoprocessing_core.pyx":777 - * last_update = time.time() - * current_step = step_size * i - * next_val = fast_file_iterator_vector.front().next() # <<<<<<<<<<<<<< - * if current_step >= current_percentile: - * result_list.append(next_val) - */ - __pyx_v_next_val = __pyx_v_fast_file_iterator_vector.front()->next(); - - /* "pygeoprocessing/geoprocessing_core.pyx":778 - * current_step = step_size * i - * next_val = fast_file_iterator_vector.front().next() - * if current_step >= current_percentile: # <<<<<<<<<<<<<< - * result_list.append(next_val) - * percentile_index += 1 - */ - __pyx_t_15 = ((__pyx_v_current_step >= __pyx_v_current_percentile) != 0); - if (__pyx_t_15) { - - /* "pygeoprocessing/geoprocessing_core.pyx":779 - * next_val = fast_file_iterator_vector.front().next() - * if current_step >= current_percentile: - * result_list.append(next_val) # <<<<<<<<<<<<<< - * percentile_index += 1 - * if percentile_index >= len(percentile_list): - */ - __pyx_t_11 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_next_val); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 779, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_22 = __Pyx_PyList_Append(__pyx_v_result_list, __pyx_t_11); if (unlikely(__pyx_t_22 == ((int)-1))) __PYX_ERR(0, 779, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":780 - * if current_step >= current_percentile: - * result_list.append(next_val) - * percentile_index += 1 # <<<<<<<<<<<<<< - * if percentile_index >= len(percentile_list): - * break - */ - __pyx_v_percentile_index = (__pyx_v_percentile_index + 1); - - /* "pygeoprocessing/geoprocessing_core.pyx":781 - * result_list.append(next_val) - * percentile_index += 1 - * if percentile_index >= len(percentile_list): # <<<<<<<<<<<<<< - * break - * current_percentile = percentile_list[percentile_index] - */ - __pyx_t_12 = PyObject_Length(__pyx_v_percentile_list); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 781, __pyx_L1_error) - __pyx_t_15 = ((__pyx_v_percentile_index >= __pyx_t_12) != 0); - if (__pyx_t_15) { - - /* "pygeoprocessing/geoprocessing_core.pyx":782 - * percentile_index += 1 - * if percentile_index >= len(percentile_list): - * break # <<<<<<<<<<<<<< - * current_percentile = percentile_list[percentile_index] - * pop_heap( - */ - goto __pyx_L17_break; - - /* "pygeoprocessing/geoprocessing_core.pyx":781 - * result_list.append(next_val) - * percentile_index += 1 - * if percentile_index >= len(percentile_list): # <<<<<<<<<<<<<< - * break - * current_percentile = percentile_list[percentile_index] - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":783 - * if percentile_index >= len(percentile_list): - * break - * current_percentile = percentile_list[percentile_index] # <<<<<<<<<<<<<< - * pop_heap( - * fast_file_iterator_vector.begin(), - */ - __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_percentile_list, __pyx_v_percentile_index, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 783, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_18 = __pyx_PyFloat_AsDouble(__pyx_t_11); if (unlikely((__pyx_t_18 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 783, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_v_current_percentile = __pyx_t_18; - - /* "pygeoprocessing/geoprocessing_core.pyx":778 - * current_step = step_size * i - * next_val = fast_file_iterator_vector.front().next() - * if current_step >= current_percentile: # <<<<<<<<<<<<<< - * result_list.append(next_val) - * percentile_index += 1 - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":784 - * break - * current_percentile = percentile_list[percentile_index] - * pop_heap( # <<<<<<<<<<<<<< - * fast_file_iterator_vector.begin(), - * fast_file_iterator_vector.end(), - */ - std::pop_heap(__pyx_v_fast_file_iterator_vector.begin(), __pyx_v_fast_file_iterator_vector.end(), FastFileIteratorCompare<__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t>); - - /* "pygeoprocessing/geoprocessing_core.pyx":788 - * fast_file_iterator_vector.end(), - * FastFileIteratorCompare[int64t]) - * if fast_file_iterator_vector.back().size() > 0: # <<<<<<<<<<<<<< - * push_heap( - * fast_file_iterator_vector.begin(), - */ - __pyx_t_15 = ((__pyx_v_fast_file_iterator_vector.back()->size() > 0) != 0); - if (__pyx_t_15) { - - /* "pygeoprocessing/geoprocessing_core.pyx":789 - * FastFileIteratorCompare[int64t]) - * if fast_file_iterator_vector.back().size() > 0: - * push_heap( # <<<<<<<<<<<<<< - * fast_file_iterator_vector.begin(), - * fast_file_iterator_vector.end(), - */ - std::push_heap(__pyx_v_fast_file_iterator_vector.begin(), __pyx_v_fast_file_iterator_vector.end(), FastFileIteratorCompare<__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t>); - - /* "pygeoprocessing/geoprocessing_core.pyx":788 - * fast_file_iterator_vector.end(), - * FastFileIteratorCompare[int64t]) - * if fast_file_iterator_vector.back().size() > 0: # <<<<<<<<<<<<<< - * push_heap( - * fast_file_iterator_vector.begin(), - */ - goto __pyx_L21; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":794 - * FastFileIteratorCompare[int64t]) - * else: - * fast_file_iterator = fast_file_iterator_vector.back() # <<<<<<<<<<<<<< - * del fast_file_iterator - * fast_file_iterator_vector.pop_back() - */ - /*else*/ { - __pyx_v_fast_file_iterator = __pyx_v_fast_file_iterator_vector.back(); - - /* "pygeoprocessing/geoprocessing_core.pyx":795 - * else: - * fast_file_iterator = fast_file_iterator_vector.back() - * del fast_file_iterator # <<<<<<<<<<<<<< - * fast_file_iterator_vector.pop_back() - * if percentile_index < len(percentile_list): - */ - delete __pyx_v_fast_file_iterator; - - /* "pygeoprocessing/geoprocessing_core.pyx":796 - * fast_file_iterator = fast_file_iterator_vector.back() - * del fast_file_iterator - * fast_file_iterator_vector.pop_back() # <<<<<<<<<<<<<< - * if percentile_index < len(percentile_list): - * result_list.append(next_val) - */ - __pyx_v_fast_file_iterator_vector.pop_back(); - } - __pyx_L21:; - } - __pyx_L17_break:; - - /* "pygeoprocessing/geoprocessing_core.pyx":797 - * del fast_file_iterator - * fast_file_iterator_vector.pop_back() - * if percentile_index < len(percentile_list): # <<<<<<<<<<<<<< - * result_list.append(next_val) - * - */ - __pyx_t_12 = PyObject_Length(__pyx_v_percentile_list); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 797, __pyx_L1_error) - __pyx_t_15 = ((__pyx_v_percentile_index < __pyx_t_12) != 0); - if (__pyx_t_15) { - - /* "pygeoprocessing/geoprocessing_core.pyx":798 - * fast_file_iterator_vector.pop_back() - * if percentile_index < len(percentile_list): - * result_list.append(next_val) # <<<<<<<<<<<<<< - * - * # free all the iterator memory - */ - __pyx_t_11 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_next_val); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 798, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_22 = __Pyx_PyList_Append(__pyx_v_result_list, __pyx_t_11); if (unlikely(__pyx_t_22 == ((int)-1))) __PYX_ERR(0, 798, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":797 - * del fast_file_iterator - * fast_file_iterator_vector.pop_back() - * if percentile_index < len(percentile_list): # <<<<<<<<<<<<<< - * result_list.append(next_val) - * - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":801 - * - * # free all the iterator memory - * ffiv_iter = fast_file_iterator_vector.begin() # <<<<<<<<<<<<<< - * while ffiv_iter != fast_file_iterator_vector.end(): - * fast_file_iterator = deref(ffiv_iter) - */ - __pyx_v_ffiv_iter = __pyx_v_fast_file_iterator_vector.begin(); - - /* "pygeoprocessing/geoprocessing_core.pyx":802 - * # free all the iterator memory - * ffiv_iter = fast_file_iterator_vector.begin() - * while ffiv_iter != fast_file_iterator_vector.end(): # <<<<<<<<<<<<<< - * fast_file_iterator = deref(ffiv_iter) - * del fast_file_iterator - */ - while (1) { - __pyx_t_15 = ((__pyx_v_ffiv_iter != __pyx_v_fast_file_iterator_vector.end()) != 0); - if (!__pyx_t_15) break; - - /* "pygeoprocessing/geoprocessing_core.pyx":803 - * ffiv_iter = fast_file_iterator_vector.begin() - * while ffiv_iter != fast_file_iterator_vector.end(): - * fast_file_iterator = deref(ffiv_iter) # <<<<<<<<<<<<<< - * del fast_file_iterator - * inc(ffiv_iter) - */ - __pyx_v_fast_file_iterator = (*__pyx_v_ffiv_iter); - - /* "pygeoprocessing/geoprocessing_core.pyx":804 - * while ffiv_iter != fast_file_iterator_vector.end(): - * fast_file_iterator = deref(ffiv_iter) - * del fast_file_iterator # <<<<<<<<<<<<<< - * inc(ffiv_iter) - * fast_file_iterator_vector.clear() - */ - delete __pyx_v_fast_file_iterator; - - /* "pygeoprocessing/geoprocessing_core.pyx":805 - * fast_file_iterator = deref(ffiv_iter) - * del fast_file_iterator - * inc(ffiv_iter) # <<<<<<<<<<<<<< - * fast_file_iterator_vector.clear() - * # delete all the heap files - */ - (void)((++__pyx_v_ffiv_iter)); - } - - /* "pygeoprocessing/geoprocessing_core.pyx":806 - * del fast_file_iterator - * inc(ffiv_iter) - * fast_file_iterator_vector.clear() # <<<<<<<<<<<<<< - * # delete all the heap files - * for file_path in heapfile_list: - */ - __pyx_v_fast_file_iterator_vector.clear(); - - /* "pygeoprocessing/geoprocessing_core.pyx":808 - * fast_file_iterator_vector.clear() - * # delete all the heap files - * for file_path in heapfile_list: # <<<<<<<<<<<<<< - * try: - * os.remove(file_path) - */ - __pyx_t_11 = __pyx_v_heapfile_list; __Pyx_INCREF(__pyx_t_11); __pyx_t_12 = 0; - for (;;) { - if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_11)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_6 = PyList_GET_ITEM(__pyx_t_11, __pyx_t_12); __Pyx_INCREF(__pyx_t_6); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 808, __pyx_L1_error) - #else - __pyx_t_6 = PySequence_ITEM(__pyx_t_11, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 808, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - #endif - __Pyx_XDECREF_SET(__pyx_v_file_path, __pyx_t_6); - __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":809 - * # delete all the heap files - * for file_path in heapfile_list: - * try: # <<<<<<<<<<<<<< - * os.remove(file_path) - * except OSError: - */ - { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __Pyx_ExceptionSave(&__pyx_t_4, &__pyx_t_3, &__pyx_t_2); - __Pyx_XGOTREF(__pyx_t_4); - __Pyx_XGOTREF(__pyx_t_3); - __Pyx_XGOTREF(__pyx_t_2); - /*try:*/ { - - /* "pygeoprocessing/geoprocessing_core.pyx":810 - * for file_path in heapfile_list: - * try: - * os.remove(file_path) # <<<<<<<<<<<<<< - * except OSError: - * # you never know if this might fail! - */ - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_os); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 810, __pyx_L27_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_remove); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 810, __pyx_L27_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - } - } - __pyx_t_6 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_8, __pyx_v_file_path) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_file_path); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 810, __pyx_L27_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":809 - * # delete all the heap files - * for file_path in heapfile_list: - * try: # <<<<<<<<<<<<<< - * os.remove(file_path) - * except OSError: - */ - } - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L34_try_end; - __pyx_L27_error:; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; - __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; - __PYX_XDEC_MEMVIEW(&__pyx_t_21, 1); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":811 - * try: - * os.remove(file_path) - * except OSError: # <<<<<<<<<<<<<< - * # you never know if this might fail! - * LOGGER.warning('unable to remove %s', file_path) - */ - __pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OSError); - if (__pyx_t_7) { - __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core._raster_band_percentile_int", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_5, &__pyx_t_8) < 0) __PYX_ERR(0, 811, __pyx_L29_except_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GOTREF(__pyx_t_8); - - /* "pygeoprocessing/geoprocessing_core.pyx":813 - * except OSError: - * # you never know if this might fail! - * LOGGER.warning('unable to remove %s', file_path) # <<<<<<<<<<<<<< - * if rm_dir_when_done: - * shutil.rmtree(working_sort_directory) - */ - __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 813, __pyx_L29_except_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_warning); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 813, __pyx_L29_except_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = NULL; - __pyx_t_7 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_20))) { - __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_20); - if (likely(__pyx_t_10)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_20); - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_20, function); - __pyx_t_7 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_20)) { - PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_kp_u_unable_to_remove_s, __pyx_v_file_path}; - __pyx_t_19 = __Pyx_PyFunction_FastCall(__pyx_t_20, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 813, __pyx_L29_except_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_19); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_20)) { - PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_kp_u_unable_to_remove_s, __pyx_v_file_path}; - __pyx_t_19 = __Pyx_PyCFunction_FastCall(__pyx_t_20, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 813, __pyx_L29_except_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_19); - } else - #endif - { - __pyx_t_1 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 813, __pyx_L29_except_error) - __Pyx_GOTREF(__pyx_t_1); - if (__pyx_t_10) { - __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_10); __pyx_t_10 = NULL; - } - __Pyx_INCREF(__pyx_kp_u_unable_to_remove_s); - __Pyx_GIVEREF(__pyx_kp_u_unable_to_remove_s); - PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_7, __pyx_kp_u_unable_to_remove_s); - __Pyx_INCREF(__pyx_v_file_path); - __Pyx_GIVEREF(__pyx_v_file_path); - PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_7, __pyx_v_file_path); - __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_20, __pyx_t_1, NULL); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 813, __pyx_L29_except_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - goto __pyx_L28_exception_handled; - } - goto __pyx_L29_except_error; - __pyx_L29_except_error:; - - /* "pygeoprocessing/geoprocessing_core.pyx":809 - * # delete all the heap files - * for file_path in heapfile_list: - * try: # <<<<<<<<<<<<<< - * os.remove(file_path) - * except OSError: - */ - __Pyx_XGIVEREF(__pyx_t_4); - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_XGIVEREF(__pyx_t_2); - __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_3, __pyx_t_2); - goto __pyx_L1_error; - __pyx_L28_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_4); - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_XGIVEREF(__pyx_t_2); - __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_3, __pyx_t_2); - __pyx_L34_try_end:; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":808 - * fast_file_iterator_vector.clear() - * # delete all the heap files - * for file_path in heapfile_list: # <<<<<<<<<<<<<< - * try: - * os.remove(file_path) - */ - } - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":814 - * # you never know if this might fail! - * LOGGER.warning('unable to remove %s', file_path) - * if rm_dir_when_done: # <<<<<<<<<<<<<< - * shutil.rmtree(working_sort_directory) - * return result_list - */ - __pyx_t_15 = (__pyx_v_rm_dir_when_done != 0); - if (__pyx_t_15) { - - /* "pygeoprocessing/geoprocessing_core.pyx":815 - * LOGGER.warning('unable to remove %s', file_path) - * if rm_dir_when_done: - * shutil.rmtree(working_sort_directory) # <<<<<<<<<<<<<< - * return result_list - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_shutil); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 815, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_rmtree); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 815, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - } - } - __pyx_t_11 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_8, __pyx_v_working_sort_directory) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_working_sort_directory); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 815, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":814 - * # you never know if this might fail! - * LOGGER.warning('unable to remove %s', file_path) - * if rm_dir_when_done: # <<<<<<<<<<<<<< - * shutil.rmtree(working_sort_directory) - * return result_list - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":816 - * if rm_dir_when_done: - * shutil.rmtree(working_sort_directory) - * return result_list # <<<<<<<<<<<<<< - * - * - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_result_list); - __pyx_r = __pyx_v_result_list; - goto __pyx_L0; - - /* "pygeoprocessing/geoprocessing_core.pyx":673 - * - * - * def _raster_band_percentile_int( # <<<<<<<<<<<<<< - * base_raster_path_band, working_sort_directory, percentile_list, - * heap_buffer_size, ffi_buffer_size): - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_19); - __Pyx_XDECREF(__pyx_t_20); - __PYX_XDEC_MEMVIEW(&__pyx_t_21, 1); - __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core._raster_band_percentile_int", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_result_list); - __PYX_XDEC_MEMVIEW(&__pyx_v_buffer_data, 1); - __Pyx_XDECREF(__pyx_v_heapfile_list); - __Pyx_XDECREF(__pyx_v_file_index); - __Pyx_XDECREF(__pyx_v_raster_info); - __Pyx_XDECREF(__pyx_v_nodata); - __Pyx_XDECREF(__pyx_v_last_update); - __Pyx_XDECREF(__pyx_v__); - __Pyx_XDECREF(__pyx_v_block_data); - __Pyx_XDECREF(__pyx_v_file_path); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pygeoprocessing/geoprocessing_core.pyx":819 - * - * - * def _raster_band_percentile_double( # <<<<<<<<<<<<<< - * base_raster_path_band, working_sort_directory, percentile_list, - * heap_buffer_size, ffi_buffer_size): - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_11_raster_band_percentile_double(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_15pygeoprocessing_18geoprocessing_core_10_raster_band_percentile_double[] = "Calculate percentiles of a raster band of a real type.\n\n Parameters:\n base_raster_path_band (tuple): raster path band tuple to raster that\n is a real/float type.\n working_sort_directory (str): path to a directory that does not\n exist or is empty. This directory will be used to create heapfiles\n with sizes no larger than ``heap_buffer_size`` which are written in the\n of the pattern N.dat where N is in the numbering 0, 1, 2, ... up\n to the number of files necessary to handle the raster.\n percentile_list (list): sorted list of percentiles to report must\n contain values in the range [0, 100].\n heap_buffer_size (int): defines approximately how many elements to hold in\n a single heap file. This is proportional to the amount of maximum\n memory to use when storing elements before a sort and write to\n disk.\n ffi_buffer_size (int): defines how many elements to store in a file\n buffer at any time.\n\n Returns:\n A list of len(percentile_list) elements long containing the\n percentile values (ranging from [0, 100]) in ``base_raster_path_band``\n where the interpolation scheme is \"higher\" (i.e. any percentile splits\n will select the next element higher than the percentile cutoff).\n\n "; -static PyMethodDef __pyx_mdef_15pygeoprocessing_18geoprocessing_core_11_raster_band_percentile_double = {"_raster_band_percentile_double", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_18geoprocessing_core_11_raster_band_percentile_double, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_18geoprocessing_core_10_raster_band_percentile_double}; -static PyObject *__pyx_pw_15pygeoprocessing_18geoprocessing_core_11_raster_band_percentile_double(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_base_raster_path_band = 0; - PyObject *__pyx_v_working_sort_directory = 0; - PyObject *__pyx_v_percentile_list = 0; - PyObject *__pyx_v_heap_buffer_size = 0; - PyObject *__pyx_v_ffi_buffer_size = 0; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_raster_band_percentile_double (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_base_raster_path_band,&__pyx_n_s_working_sort_directory,&__pyx_n_s_percentile_list,&__pyx_n_s_heap_buffer_size,&__pyx_n_s_ffi_buffer_size,0}; - PyObject* values[5] = {0,0,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 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_base_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_working_sort_directory)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_raster_band_percentile_double", 1, 5, 5, 1); __PYX_ERR(0, 819, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_percentile_list)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_raster_band_percentile_double", 1, 5, 5, 2); __PYX_ERR(0, 819, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_heap_buffer_size)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_raster_band_percentile_double", 1, 5, 5, 3); __PYX_ERR(0, 819, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 4: - if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_ffi_buffer_size)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_raster_band_percentile_double", 1, 5, 5, 4); __PYX_ERR(0, 819, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_raster_band_percentile_double") < 0)) __PYX_ERR(0, 819, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 5) { - 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); - values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - } - __pyx_v_base_raster_path_band = values[0]; - __pyx_v_working_sort_directory = values[1]; - __pyx_v_percentile_list = values[2]; - __pyx_v_heap_buffer_size = values[3]; - __pyx_v_ffi_buffer_size = values[4]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_raster_band_percentile_double", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 819, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core._raster_band_percentile_double", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_15pygeoprocessing_18geoprocessing_core_10_raster_band_percentile_double(__pyx_self, __pyx_v_base_raster_path_band, __pyx_v_working_sort_directory, __pyx_v_percentile_list, __pyx_v_heap_buffer_size, __pyx_v_ffi_buffer_size); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15pygeoprocessing_18geoprocessing_core_10_raster_band_percentile_double(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_base_raster_path_band, PyObject *__pyx_v_working_sort_directory, PyObject *__pyx_v_percentile_list, PyObject *__pyx_v_heap_buffer_size, PyObject *__pyx_v_ffi_buffer_size) { - FILE *__pyx_v_fptr; - __Pyx_memviewslice __pyx_v_buffer_data = { 0, 0, { 0 }, { 0 }, { 0 } }; - __pyx_t_15pygeoprocessing_18geoprocessing_core_FastFileIteratorDoublePtr __pyx_v_fast_file_iterator; - std::vector<__pyx_t_15pygeoprocessing_18geoprocessing_core_FastFileIteratorDoublePtr> __pyx_v_fast_file_iterator_vector; - int __pyx_v_percentile_index; - PY_LONG_LONG __pyx_v_i; - PY_LONG_LONG __pyx_v_n_elements; - double __pyx_v_next_val; - double __pyx_v_current_step; - double __pyx_v_step_size; - double __pyx_v_current_percentile; - PyObject *__pyx_v_result_list = NULL; - int __pyx_v_rm_dir_when_done; - PyObject *__pyx_v_e = NULL; - PyObject *__pyx_v_file_index = NULL; - PyObject *__pyx_v_nodata = NULL; - PyObject *__pyx_v_heapfile_list = NULL; - PyObject *__pyx_v_raster_info = NULL; - PY_LONG_LONG __pyx_v_n_pixels; - PY_LONG_LONG __pyx_v_pixels_processed; - PyObject *__pyx_v_last_update = NULL; - CYTHON_UNUSED PyObject *__pyx_v__ = NULL; - PyObject *__pyx_v_block_data = NULL; - PyObject *__pyx_v_file_path = NULL; - std::vector<__pyx_t_15pygeoprocessing_18geoprocessing_core_FastFileIteratorDoublePtr> ::iterator __pyx_v_ffiv_iter; - 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; - PyObject *__pyx_t_6 = NULL; - int __pyx_t_7; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - PyObject *__pyx_t_12 = NULL; - int __pyx_t_13; - char const *__pyx_t_14; - PyObject *__pyx_t_15 = NULL; - PyObject *__pyx_t_16 = NULL; - PyObject *__pyx_t_17 = NULL; - PyObject *__pyx_t_18 = NULL; - PyObject *__pyx_t_19 = NULL; - PyObject *__pyx_t_20 = NULL; - PY_LONG_LONG __pyx_t_21; - Py_ssize_t __pyx_t_22; - PyObject *(*__pyx_t_23)(PyObject *); - PyObject *(*__pyx_t_24)(PyObject *); - int __pyx_t_25; - Py_ssize_t __pyx_t_26; - Py_UCS4 __pyx_t_27; - double __pyx_t_28; - __Pyx_memviewslice __pyx_t_29 = { 0, 0, { 0 }, { 0 }, { 0 } }; - int __pyx_t_30; - char const *__pyx_t_31; - Py_ssize_t __pyx_t_32; - size_t __pyx_t_33; - char const *__pyx_t_34; - PY_LONG_LONG __pyx_t_35; - PY_LONG_LONG __pyx_t_36; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("_raster_band_percentile_double", 0); - - /* "pygeoprocessing/geoprocessing_core.pyx":852 - * cdef FastFileIteratorDoublePtr fast_file_iterator - * cdef vector[FastFileIteratorDoublePtr] fast_file_iterator_vector - * cdef int percentile_index = 0 # <<<<<<<<<<<<<< - * cdef long long i, n_elements = 0 - * cdef double next_val = 0.0 - */ - __pyx_v_percentile_index = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":853 - * cdef vector[FastFileIteratorDoublePtr] fast_file_iterator_vector - * cdef int percentile_index = 0 - * cdef long long i, n_elements = 0 # <<<<<<<<<<<<<< - * cdef double next_val = 0.0 - * cdef double current_step = 0.0 - */ - __pyx_v_n_elements = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":854 - * cdef int percentile_index = 0 - * cdef long long i, n_elements = 0 - * cdef double next_val = 0.0 # <<<<<<<<<<<<<< - * cdef double current_step = 0.0 - * cdef double step_size, current_percentile - */ - __pyx_v_next_val = 0.0; - - /* "pygeoprocessing/geoprocessing_core.pyx":855 - * cdef long long i, n_elements = 0 - * cdef double next_val = 0.0 - * cdef double current_step = 0.0 # <<<<<<<<<<<<<< - * cdef double step_size, current_percentile - * result_list = [] - */ - __pyx_v_current_step = 0.0; - - /* "pygeoprocessing/geoprocessing_core.pyx":857 - * cdef double current_step = 0.0 - * cdef double step_size, current_percentile - * result_list = [] # <<<<<<<<<<<<<< - * rm_dir_when_done = False - * try: - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 857, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_result_list = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":858 - * cdef double step_size, current_percentile - * result_list = [] - * rm_dir_when_done = False # <<<<<<<<<<<<<< - * try: - * os.makedirs(working_sort_directory) - */ - __pyx_v_rm_dir_when_done = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":859 - * result_list = [] - * rm_dir_when_done = False - * try: # <<<<<<<<<<<<<< - * os.makedirs(working_sort_directory) - * rm_dir_when_done = True - */ - { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __Pyx_ExceptionSave(&__pyx_t_2, &__pyx_t_3, &__pyx_t_4); - __Pyx_XGOTREF(__pyx_t_2); - __Pyx_XGOTREF(__pyx_t_3); - __Pyx_XGOTREF(__pyx_t_4); - /*try:*/ { - - /* "pygeoprocessing/geoprocessing_core.pyx":860 - * rm_dir_when_done = False - * try: - * os.makedirs(working_sort_directory) # <<<<<<<<<<<<<< - * rm_dir_when_done = True - * except OSError as e: - */ - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_os); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 860, __pyx_L3_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_makedirs); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 860, __pyx_L3_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_6))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_v_working_sort_directory) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_working_sort_directory); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 860, __pyx_L3_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":861 - * try: - * os.makedirs(working_sort_directory) - * rm_dir_when_done = True # <<<<<<<<<<<<<< - * except OSError as e: - * LOGGER.warning("couldn't make working_sort_directory: %s", str(e)) - */ - __pyx_v_rm_dir_when_done = 1; - - /* "pygeoprocessing/geoprocessing_core.pyx":859 - * result_list = [] - * rm_dir_when_done = False - * try: # <<<<<<<<<<<<<< - * os.makedirs(working_sort_directory) - * rm_dir_when_done = True - */ - } - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L8_try_end; - __pyx_L3_error:; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":862 - * os.makedirs(working_sort_directory) - * rm_dir_when_done = True - * except OSError as e: # <<<<<<<<<<<<<< - * LOGGER.warning("couldn't make working_sort_directory: %s", str(e)) - * file_index = 0 - */ - __pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OSError); - if (__pyx_t_7) { - __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core._raster_band_percentile_double", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_6, &__pyx_t_5) < 0) __PYX_ERR(0, 862, __pyx_L5_except_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(__pyx_t_6); - __pyx_v_e = __pyx_t_6; - /*try:*/ { - - /* "pygeoprocessing/geoprocessing_core.pyx":863 - * rm_dir_when_done = True - * except OSError as e: - * LOGGER.warning("couldn't make working_sort_directory: %s", str(e)) # <<<<<<<<<<<<<< - * file_index = 0 - * nodata = pygeoprocessing.get_raster_info( - */ - __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 863, __pyx_L14_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_warning); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 863, __pyx_L14_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_v_e); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 863, __pyx_L14_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_11 = NULL; - __pyx_t_7 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_10); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_10, function); - __pyx_t_7 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_kp_u_couldn_t_make_working_sort_direc, __pyx_t_9}; - __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 863, __pyx_L14_error) - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 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_10)) { - PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_kp_u_couldn_t_make_working_sort_direc, __pyx_t_9}; - __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 863, __pyx_L14_error) - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } else - #endif - { - __pyx_t_12 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 863, __pyx_L14_error) - __Pyx_GOTREF(__pyx_t_12); - if (__pyx_t_11) { - __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11); __pyx_t_11 = NULL; - } - __Pyx_INCREF(__pyx_kp_u_couldn_t_make_working_sort_direc); - __Pyx_GIVEREF(__pyx_kp_u_couldn_t_make_working_sort_direc); - PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_7, __pyx_kp_u_couldn_t_make_working_sort_direc); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_7, __pyx_t_9); - __pyx_t_9 = 0; - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_12, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 863, __pyx_L14_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":862 - * os.makedirs(working_sort_directory) - * rm_dir_when_done = True - * except OSError as e: # <<<<<<<<<<<<<< - * LOGGER.warning("couldn't make working_sort_directory: %s", str(e)) - * file_index = 0 - */ - /*finally:*/ { - /*normal exit:*/{ - __Pyx_DECREF(__pyx_v_e); - __pyx_v_e = NULL; - goto __pyx_L15; - } - __pyx_L14_error:; - /*exception exit:*/{ - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20); - if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17) < 0)) __Pyx_ErrFetch(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17); - __Pyx_XGOTREF(__pyx_t_15); - __Pyx_XGOTREF(__pyx_t_16); - __Pyx_XGOTREF(__pyx_t_17); - __Pyx_XGOTREF(__pyx_t_18); - __Pyx_XGOTREF(__pyx_t_19); - __Pyx_XGOTREF(__pyx_t_20); - __pyx_t_7 = __pyx_lineno; __pyx_t_13 = __pyx_clineno; __pyx_t_14 = __pyx_filename; - { - __Pyx_DECREF(__pyx_v_e); - __pyx_v_e = NULL; - } - if (PY_MAJOR_VERSION >= 3) { - __Pyx_XGIVEREF(__pyx_t_18); - __Pyx_XGIVEREF(__pyx_t_19); - __Pyx_XGIVEREF(__pyx_t_20); - __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_19, __pyx_t_20); - } - __Pyx_XGIVEREF(__pyx_t_15); - __Pyx_XGIVEREF(__pyx_t_16); - __Pyx_XGIVEREF(__pyx_t_17); - __Pyx_ErrRestore(__pyx_t_15, __pyx_t_16, __pyx_t_17); - __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; - __pyx_lineno = __pyx_t_7; __pyx_clineno = __pyx_t_13; __pyx_filename = __pyx_t_14; - goto __pyx_L5_except_error; - } - __pyx_L15:; - } - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - goto __pyx_L4_exception_handled; - } - goto __pyx_L5_except_error; - __pyx_L5_except_error:; - - /* "pygeoprocessing/geoprocessing_core.pyx":859 - * result_list = [] - * rm_dir_when_done = False - * try: # <<<<<<<<<<<<<< - * os.makedirs(working_sort_directory) - * rm_dir_when_done = True - */ - __Pyx_XGIVEREF(__pyx_t_2); - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_XGIVEREF(__pyx_t_4); - __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4); - goto __pyx_L1_error; - __pyx_L4_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_2); - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_XGIVEREF(__pyx_t_4); - __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4); - __pyx_L8_try_end:; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":864 - * except OSError as e: - * LOGGER.warning("couldn't make working_sort_directory: %s", str(e)) - * file_index = 0 # <<<<<<<<<<<<<< - * nodata = pygeoprocessing.get_raster_info( - * base_raster_path_band[0])['nodata'][base_raster_path_band[1]-1] - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_v_file_index = __pyx_int_0; - - /* "pygeoprocessing/geoprocessing_core.pyx":865 - * LOGGER.warning("couldn't make working_sort_directory: %s", str(e)) - * file_index = 0 - * nodata = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< - * base_raster_path_band[0])['nodata'][base_raster_path_band[1]-1] - * heapfile_list = [] - */ - __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 865, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 865, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":866 - * file_index = 0 - * nodata = pygeoprocessing.get_raster_info( - * base_raster_path_band[0])['nodata'][base_raster_path_band[1]-1] # <<<<<<<<<<<<<< - * heapfile_list = [] - * - */ - __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_base_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 866, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_5 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_6); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 865, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_t_5, __pyx_n_u_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 866, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_base_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 866, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyInt_SubtractObjC(__pyx_t_5, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 866, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 866, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_nodata = __pyx_t_5; - __pyx_t_5 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":867 - * nodata = pygeoprocessing.get_raster_info( - * base_raster_path_band[0])['nodata'][base_raster_path_band[1]-1] - * heapfile_list = [] # <<<<<<<<<<<<<< - * - * raster_info = pygeoprocessing.get_raster_info( - */ - __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 867, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_v_heapfile_list = ((PyObject*)__pyx_t_5); - __pyx_t_5 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":869 - * heapfile_list = [] - * - * raster_info = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< - * base_raster_path_band[0]) - * nodata = raster_info['nodata'][base_raster_path_band[1]-1] - */ - __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 869, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 869, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":870 - * - * raster_info = pygeoprocessing.get_raster_info( - * base_raster_path_band[0]) # <<<<<<<<<<<<<< - * nodata = raster_info['nodata'][base_raster_path_band[1]-1] - * cdef long long n_pixels = ( - */ - __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_base_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 870, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_5 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_6); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 869, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_raster_info = __pyx_t_5; - __pyx_t_5 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":871 - * raster_info = pygeoprocessing.get_raster_info( - * base_raster_path_band[0]) - * nodata = raster_info['nodata'][base_raster_path_band[1]-1] # <<<<<<<<<<<<<< - * cdef long long n_pixels = ( - * raster_info['raster_size'][0] * raster_info['raster_size'][1]) - */ - __pyx_t_5 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_nodata); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 871, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_base_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 871, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = __Pyx_PyInt_SubtractObjC(__pyx_t_1, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 871, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 871, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF_SET(__pyx_v_nodata, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":873 - * nodata = raster_info['nodata'][base_raster_path_band[1]-1] - * cdef long long n_pixels = ( - * raster_info['raster_size'][0] * raster_info['raster_size'][1]) # <<<<<<<<<<<<<< - * cdef long long pixels_processed = 0 - * - */ - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 873, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 873, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 873, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_1, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 873, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Multiply(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 873, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_21 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_21 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 873, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_n_pixels = __pyx_t_21; - - /* "pygeoprocessing/geoprocessing_core.pyx":874 - * cdef long long n_pixels = ( - * raster_info['raster_size'][0] * raster_info['raster_size'][1]) - * cdef long long pixels_processed = 0 # <<<<<<<<<<<<<< - * - * last_update = time.time() - */ - __pyx_v_pixels_processed = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":876 - * cdef long long pixels_processed = 0 - * - * last_update = time.time() # <<<<<<<<<<<<<< - * LOGGER.debug('sorting data to heap') - * for _, block_data in pygeoprocessing.iterblocks( - */ - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 876, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 876, __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_6))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 876, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_last_update = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":877 - * - * last_update = time.time() - * LOGGER.debug('sorting data to heap') # <<<<<<<<<<<<<< - * for _, block_data in pygeoprocessing.iterblocks( - * base_raster_path_band, largest_block=heap_buffer_size): - */ - __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 877, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_debug); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 877, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __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); - } - } - __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_kp_u_sorting_data_to_heap) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_kp_u_sorting_data_to_heap); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 877, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":878 - * last_update = time.time() - * LOGGER.debug('sorting data to heap') - * for _, block_data in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * base_raster_path_band, largest_block=heap_buffer_size): - * pixels_processed += block_data.size - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 878, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 878, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":879 - * LOGGER.debug('sorting data to heap') - * for _, block_data in pygeoprocessing.iterblocks( - * base_raster_path_band, largest_block=heap_buffer_size): # <<<<<<<<<<<<<< - * pixels_processed += block_data.size - * if time.time() - last_update > 5.0: - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 878, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_base_raster_path_band); - __Pyx_GIVEREF(__pyx_v_base_raster_path_band); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_base_raster_path_band); - __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 879, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_largest_block, __pyx_v_heap_buffer_size) < 0) __PYX_ERR(0, 879, __pyx_L1_error) - - /* "pygeoprocessing/geoprocessing_core.pyx":878 - * last_update = time.time() - * LOGGER.debug('sorting data to heap') - * for _, block_data in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * base_raster_path_band, largest_block=heap_buffer_size): - * pixels_processed += block_data.size - */ - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 878, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (likely(PyList_CheckExact(__pyx_t_8)) || PyTuple_CheckExact(__pyx_t_8)) { - __pyx_t_6 = __pyx_t_8; __Pyx_INCREF(__pyx_t_6); __pyx_t_22 = 0; - __pyx_t_23 = NULL; - } else { - __pyx_t_22 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 878, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_23 = Py_TYPE(__pyx_t_6)->tp_iternext; if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 878, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - for (;;) { - if (likely(!__pyx_t_23)) { - if (likely(PyList_CheckExact(__pyx_t_6))) { - if (__pyx_t_22 >= PyList_GET_SIZE(__pyx_t_6)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_8 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_22); __Pyx_INCREF(__pyx_t_8); __pyx_t_22++; if (unlikely(0 < 0)) __PYX_ERR(0, 878, __pyx_L1_error) - #else - __pyx_t_8 = PySequence_ITEM(__pyx_t_6, __pyx_t_22); __pyx_t_22++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 878, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - #endif - } else { - if (__pyx_t_22 >= PyTuple_GET_SIZE(__pyx_t_6)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_22); __Pyx_INCREF(__pyx_t_8); __pyx_t_22++; if (unlikely(0 < 0)) __PYX_ERR(0, 878, __pyx_L1_error) - #else - __pyx_t_8 = PySequence_ITEM(__pyx_t_6, __pyx_t_22); __pyx_t_22++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 878, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - #endif - } - } else { - __pyx_t_8 = __pyx_t_23(__pyx_t_6); - if (unlikely(!__pyx_t_8)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 878, __pyx_L1_error) - } - break; - } - __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, 878, __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_5 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_1 = PyList_GET_ITEM(sequence, 0); - __pyx_t_5 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_5); - #else - __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 878, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 878, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_10 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 878, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_24 = Py_TYPE(__pyx_t_10)->tp_iternext; - index = 0; __pyx_t_1 = __pyx_t_24(__pyx_t_10); if (unlikely(!__pyx_t_1)) goto __pyx_L22_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - index = 1; __pyx_t_5 = __pyx_t_24(__pyx_t_10); if (unlikely(!__pyx_t_5)) goto __pyx_L22_unpacking_failed; - __Pyx_GOTREF(__pyx_t_5); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_24(__pyx_t_10), 2) < 0) __PYX_ERR(0, 878, __pyx_L1_error) - __pyx_t_24 = NULL; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - goto __pyx_L23_unpacking_done; - __pyx_L22_unpacking_failed:; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_24 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 878, __pyx_L1_error) - __pyx_L23_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_1); - __pyx_t_1 = 0; - __Pyx_XDECREF_SET(__pyx_v_block_data, __pyx_t_5); - __pyx_t_5 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":880 - * for _, block_data in pygeoprocessing.iterblocks( - * base_raster_path_band, largest_block=heap_buffer_size): - * pixels_processed += block_data.size # <<<<<<<<<<<<<< - * if time.time() - last_update > 5.0: - * LOGGER.debug( - */ - __pyx_t_8 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_pixels_processed); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 880, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_block_data, __pyx_n_s_size); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 880, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_t_8, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 880, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_21 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_21 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 880, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_pixels_processed = __pyx_t_21; - - /* "pygeoprocessing/geoprocessing_core.pyx":881 - * base_raster_path_band, largest_block=heap_buffer_size): - * pixels_processed += block_data.size - * if time.time() - last_update > 5.0: # <<<<<<<<<<<<<< - * LOGGER.debug( - * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' - */ - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 881, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 881, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - } - } - __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 881, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = PyNumber_Subtract(__pyx_t_1, __pyx_v_last_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 881, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_RichCompare(__pyx_t_8, __pyx_float_5_0, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 881, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_25 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_25 < 0)) __PYX_ERR(0, 881, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_25) { - - /* "pygeoprocessing/geoprocessing_core.pyx":882 - * pixels_processed += block_data.size - * if time.time() - last_update > 5.0: - * LOGGER.debug( # <<<<<<<<<<<<<< - * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' - * f'complete, {pixels_processed} out of {n_pixels}'), - */ - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 882, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_debug); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 882, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":883 - * if time.time() - last_update > 5.0: - * LOGGER.debug( - * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' # <<<<<<<<<<<<<< - * f'complete, {pixels_processed} out of {n_pixels}'), - * - */ - __pyx_t_8 = PyTuple_New(6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 883, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_26 = 0; - __pyx_t_27 = 127; - __Pyx_INCREF(__pyx_kp_u_data_sort_to_heap); - __pyx_t_26 += 18; - __Pyx_GIVEREF(__pyx_kp_u_data_sort_to_heap); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_kp_u_data_sort_to_heap); - __pyx_t_28 = (100. * __pyx_v_pixels_processed); - if (unlikely(__pyx_v_n_pixels == 0)) { - PyErr_SetString(PyExc_ZeroDivisionError, "float division"); - __PYX_ERR(0, 883, __pyx_L1_error) - } - __pyx_t_10 = PyFloat_FromDouble((__pyx_t_28 / ((double)__pyx_v_n_pixels))); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 883, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_12 = __Pyx_PyObject_Format(__pyx_t_10, __pyx_kp_u_1f); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 883, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_27 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_12) > __pyx_t_27) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_12) : __pyx_t_27; - __pyx_t_26 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_12); - __Pyx_GIVEREF(__pyx_t_12); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_12); - __pyx_t_12 = 0; - __Pyx_INCREF(__pyx_kp_u_complete); - __pyx_t_26 += 12; - __Pyx_GIVEREF(__pyx_kp_u_complete); - PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_kp_u_complete); - - /* "pygeoprocessing/geoprocessing_core.pyx":884 - * LOGGER.debug( - * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' - * f'complete, {pixels_processed} out of {n_pixels}'), # <<<<<<<<<<<<<< - * - * last_update = time.time() - */ - __pyx_t_12 = __Pyx_PyUnicode_From_PY_LONG_LONG(__pyx_v_pixels_processed, 0, ' ', 'd'); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 884, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_26 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_12); - __Pyx_GIVEREF(__pyx_t_12); - PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_12); - __pyx_t_12 = 0; - __Pyx_INCREF(__pyx_kp_u_out_of); - __pyx_t_26 += 8; - __Pyx_GIVEREF(__pyx_kp_u_out_of); - PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_kp_u_out_of); - __pyx_t_12 = __Pyx_PyUnicode_From_PY_LONG_LONG(__pyx_v_n_pixels, 0, ' ', 'd'); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 884, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_26 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_12); - __Pyx_GIVEREF(__pyx_t_12); - PyTuple_SET_ITEM(__pyx_t_8, 5, __pyx_t_12); - __pyx_t_12 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":883 - * if time.time() - last_update > 5.0: - * LOGGER.debug( - * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' # <<<<<<<<<<<<<< - * f'complete, {pixels_processed} out of {n_pixels}'), - * - */ - __pyx_t_12 = __Pyx_PyUnicode_Join(__pyx_t_8, 6, __pyx_t_26, __pyx_t_27); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 883, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - } - } - __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_8, __pyx_t_12) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_12); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 882, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":882 - * pixels_processed += block_data.size - * if time.time() - last_update > 5.0: - * LOGGER.debug( # <<<<<<<<<<<<<< - * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' - * f'complete, {pixels_processed} out of {n_pixels}'), - */ - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 882, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); - __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":886 - * f'complete, {pixels_processed} out of {n_pixels}'), - * - * last_update = time.time() # <<<<<<<<<<<<<< - * buffer_data = numpy.sort( - * block_data[~numpy.isclose(block_data, nodata)]).astype( - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_time); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 886, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_time); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 886, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - } - } - __pyx_t_5 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_12); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 886, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF_SET(__pyx_v_last_update, __pyx_t_5); - __pyx_t_5 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":881 - * base_raster_path_band, largest_block=heap_buffer_size): - * pixels_processed += block_data.size - * if time.time() - last_update > 5.0: # <<<<<<<<<<<<<< - * LOGGER.debug( - * f'data sort to heap {(100.*pixels_processed)/n_pixels:.1f}% ' - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":887 - * - * last_update = time.time() - * buffer_data = numpy.sort( # <<<<<<<<<<<<<< - * block_data[~numpy.isclose(block_data, nodata)]).astype( - * numpy.double) - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 887, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_sort); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 887, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":888 - * last_update = time.time() - * buffer_data = numpy.sort( - * block_data[~numpy.isclose(block_data, nodata)]).astype( # <<<<<<<<<<<<<< - * numpy.double) - * if buffer_data.size == 0: - */ - __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_numpy); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 888, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_isclose); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 888, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = NULL; - __pyx_t_13 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) { - __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9); - if (likely(__pyx_t_10)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_9, function); - __pyx_t_13 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_block_data, __pyx_v_nodata}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 888, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_block_data, __pyx_v_nodata}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 888, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_11 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 888, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - if (__pyx_t_10) { - __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10); __pyx_t_10 = NULL; - } - __Pyx_INCREF(__pyx_v_block_data); - __Pyx_GIVEREF(__pyx_v_block_data); - PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_13, __pyx_v_block_data); - __Pyx_INCREF(__pyx_v_nodata); - __Pyx_GIVEREF(__pyx_v_nodata); - PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_13, __pyx_v_nodata); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_11, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 888, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = PyNumber_Invert(__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 888, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_block_data, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 888, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(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); - } - } - __pyx_t_12 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_9, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_1); - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 887, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_astype); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 888, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":889 - * buffer_data = numpy.sort( - * block_data[~numpy.isclose(block_data, nodata)]).astype( - * numpy.double) # <<<<<<<<<<<<<< - * if buffer_data.size == 0: - * continue - */ - __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_numpy); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 889, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_double); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 889, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_12)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_12); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - } - } - __pyx_t_5 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_12, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_1); - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 888, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":888 - * last_update = time.time() - * buffer_data = numpy.sort( - * block_data[~numpy.isclose(block_data, nodata)]).astype( # <<<<<<<<<<<<<< - * numpy.double) - * if buffer_data.size == 0: - */ - __pyx_t_29 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_29.memview)) __PYX_ERR(0, 888, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_XDEC_MEMVIEW(&__pyx_v_buffer_data, 1); - __pyx_v_buffer_data = __pyx_t_29; - __pyx_t_29.memview = NULL; - __pyx_t_29.data = NULL; - - /* "pygeoprocessing/geoprocessing_core.pyx":890 - * block_data[~numpy.isclose(block_data, nodata)]).astype( - * numpy.double) - * if buffer_data.size == 0: # <<<<<<<<<<<<<< - * continue - * n_elements += buffer_data.size - */ - __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_buffer_data, 1, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 890, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_size); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 890, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyInt_EqObjC(__pyx_t_8, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 890, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_25 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_25 < 0)) __PYX_ERR(0, 890, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_25) { - - /* "pygeoprocessing/geoprocessing_core.pyx":891 - * numpy.double) - * if buffer_data.size == 0: - * continue # <<<<<<<<<<<<<< - * n_elements += buffer_data.size - * file_path = os.path.join( - */ - goto __pyx_L20_continue; - - /* "pygeoprocessing/geoprocessing_core.pyx":890 - * block_data[~numpy.isclose(block_data, nodata)]).astype( - * numpy.double) - * if buffer_data.size == 0: # <<<<<<<<<<<<<< - * continue - * n_elements += buffer_data.size - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":892 - * if buffer_data.size == 0: - * continue - * n_elements += buffer_data.size # <<<<<<<<<<<<<< - * file_path = os.path.join( - * working_sort_directory, '%d.dat' % file_index) - */ - __pyx_t_5 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_n_elements); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 892, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_8 = __pyx_memoryview_fromslice(__pyx_v_buffer_data, 1, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 892, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 892, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = PyNumber_InPlaceAdd(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 892, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_21 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_t_8); if (unlikely((__pyx_t_21 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 892, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_n_elements = __pyx_t_21; - - /* "pygeoprocessing/geoprocessing_core.pyx":893 - * continue - * n_elements += buffer_data.size - * file_path = os.path.join( # <<<<<<<<<<<<<< - * working_sort_directory, '%d.dat' % file_index) - * heapfile_list.append(file_path) - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 893, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_path); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 893, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_join); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 893, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":894 - * n_elements += buffer_data.size - * file_path = os.path.join( - * working_sort_directory, '%d.dat' % file_index) # <<<<<<<<<<<<<< - * heapfile_list.append(file_path) - * fptr = fopen(bytes(file_path.encode()), "wb") - */ - __pyx_t_5 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_d_dat, __pyx_v_file_index); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 894, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_12 = NULL; - __pyx_t_13 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_12)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_12); - __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_12, __pyx_v_working_sort_directory, __pyx_t_5}; - __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 893, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GOTREF(__pyx_t_8); - __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[3] = {__pyx_t_12, __pyx_v_working_sort_directory, __pyx_t_5}; - __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 893, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - { - __pyx_t_9 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 893, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - if (__pyx_t_12) { - __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_12); __pyx_t_12 = NULL; - } - __Pyx_INCREF(__pyx_v_working_sort_directory); - __Pyx_GIVEREF(__pyx_v_working_sort_directory); - PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_13, __pyx_v_working_sort_directory); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_13, __pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 893, __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_XDECREF_SET(__pyx_v_file_path, __pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":895 - * file_path = os.path.join( - * working_sort_directory, '%d.dat' % file_index) - * heapfile_list.append(file_path) # <<<<<<<<<<<<<< - * fptr = fopen(bytes(file_path.encode()), "wb") - * fwrite( - */ - __pyx_t_30 = __Pyx_PyList_Append(__pyx_v_heapfile_list, __pyx_v_file_path); if (unlikely(__pyx_t_30 == ((int)-1))) __PYX_ERR(0, 895, __pyx_L1_error) - - /* "pygeoprocessing/geoprocessing_core.pyx":896 - * working_sort_directory, '%d.dat' % file_index) - * heapfile_list.append(file_path) - * fptr = fopen(bytes(file_path.encode()), "wb") # <<<<<<<<<<<<<< - * fwrite( - * &buffer_data[0], sizeof(double), buffer_data.size, fptr) - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_file_path, __pyx_n_s_encode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 896, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_8 = (__pyx_t_9) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_9) : __Pyx_PyObject_CallNoArg(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 896, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 896, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_31 = __Pyx_PyBytes_AsString(__pyx_t_1); if (unlikely((!__pyx_t_31) && PyErr_Occurred())) __PYX_ERR(0, 896, __pyx_L1_error) - __pyx_v_fptr = fopen(__pyx_t_31, ((char const *)"wb")); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":898 - * fptr = fopen(bytes(file_path.encode()), "wb") - * fwrite( - * &buffer_data[0], sizeof(double), buffer_data.size, fptr) # <<<<<<<<<<<<<< - * fclose(fptr) - * file_index += 1 - */ - __pyx_t_32 = 0; - __pyx_t_13 = -1; - if (__pyx_t_32 < 0) { - __pyx_t_32 += __pyx_v_buffer_data.shape[0]; - if (unlikely(__pyx_t_32 < 0)) __pyx_t_13 = 0; - } else if (unlikely(__pyx_t_32 >= __pyx_v_buffer_data.shape[0])) __pyx_t_13 = 0; - if (unlikely(__pyx_t_13 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_13); - __PYX_ERR(0, 898, __pyx_L1_error) - } - __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_buffer_data, 1, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 898, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_size); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 898, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_33 = __Pyx_PyInt_As_size_t(__pyx_t_8); if (unlikely((__pyx_t_33 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 898, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":897 - * heapfile_list.append(file_path) - * fptr = fopen(bytes(file_path.encode()), "wb") - * fwrite( # <<<<<<<<<<<<<< - * &buffer_data[0], sizeof(double), buffer_data.size, fptr) - * fclose(fptr) - */ - (void)(fwrite(((double *)(&(*((double *) ( /* dim=0 */ (__pyx_v_buffer_data.data + __pyx_t_32 * __pyx_v_buffer_data.strides[0]) ))))), (sizeof(double)), __pyx_t_33, __pyx_v_fptr)); - - /* "pygeoprocessing/geoprocessing_core.pyx":899 - * fwrite( - * &buffer_data[0], sizeof(double), buffer_data.size, fptr) - * fclose(fptr) # <<<<<<<<<<<<<< - * file_index += 1 - * - */ - (void)(fclose(__pyx_v_fptr)); - - /* "pygeoprocessing/geoprocessing_core.pyx":900 - * &buffer_data[0], sizeof(double), buffer_data.size, fptr) - * fclose(fptr) - * file_index += 1 # <<<<<<<<<<<<<< - * - * fast_file_iterator = new FastFileIterator[double]( - */ - __pyx_t_8 = __Pyx_PyInt_AddObjC(__pyx_v_file_index, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 900, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF_SET(__pyx_v_file_index, __pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":903 - * - * fast_file_iterator = new FastFileIterator[double]( - * (bytes(file_path.encode())), ffi_buffer_size) # <<<<<<<<<<<<<< - * fast_file_iterator_vector.push_back(fast_file_iterator) - * push_heap( - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_file_path, __pyx_n_s_encode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 903, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_8 = (__pyx_t_9) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_9) : __Pyx_PyObject_CallNoArg(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 903, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 903, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_34 = __Pyx_PyBytes_AsString(__pyx_t_1); if (unlikely((!__pyx_t_34) && PyErr_Occurred())) __PYX_ERR(0, 903, __pyx_L1_error) - __pyx_t_33 = __Pyx_PyInt_As_size_t(__pyx_v_ffi_buffer_size); if (unlikely((__pyx_t_33 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 903, __pyx_L1_error) - - /* "pygeoprocessing/geoprocessing_core.pyx":902 - * file_index += 1 - * - * fast_file_iterator = new FastFileIterator[double]( # <<<<<<<<<<<<<< - * (bytes(file_path.encode())), ffi_buffer_size) - * fast_file_iterator_vector.push_back(fast_file_iterator) - */ - __pyx_v_fast_file_iterator = new FastFileIterator (__pyx_t_34, __pyx_t_33); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":904 - * fast_file_iterator = new FastFileIterator[double]( - * (bytes(file_path.encode())), ffi_buffer_size) - * fast_file_iterator_vector.push_back(fast_file_iterator) # <<<<<<<<<<<<<< - * push_heap( - * fast_file_iterator_vector.begin(), - */ - try { - __pyx_v_fast_file_iterator_vector.push_back(__pyx_v_fast_file_iterator); - } catch(...) { - __Pyx_CppExn2PyErr(); - __PYX_ERR(0, 904, __pyx_L1_error) - } - - /* "pygeoprocessing/geoprocessing_core.pyx":905 - * (bytes(file_path.encode())), ffi_buffer_size) - * fast_file_iterator_vector.push_back(fast_file_iterator) - * push_heap( # <<<<<<<<<<<<<< - * fast_file_iterator_vector.begin(), - * fast_file_iterator_vector.end(), - */ - std::push_heap(__pyx_v_fast_file_iterator_vector.begin(), __pyx_v_fast_file_iterator_vector.end(), FastFileIteratorCompare); - - /* "pygeoprocessing/geoprocessing_core.pyx":878 - * last_update = time.time() - * LOGGER.debug('sorting data to heap') - * for _, block_data in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * base_raster_path_band, largest_block=heap_buffer_size): - * pixels_processed += block_data.size - */ - __pyx_L20_continue:; - } - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":910 - * FastFileIteratorCompare[double]) - * - * current_percentile = percentile_list[percentile_index] # <<<<<<<<<<<<<< - * step_size = 0 - * if n_elements > 0: - */ - __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_percentile_list, __pyx_v_percentile_index, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 910, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_28 = __pyx_PyFloat_AsDouble(__pyx_t_6); if (unlikely((__pyx_t_28 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 910, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_current_percentile = __pyx_t_28; - - /* "pygeoprocessing/geoprocessing_core.pyx":911 - * - * current_percentile = percentile_list[percentile_index] - * step_size = 0 # <<<<<<<<<<<<<< - * if n_elements > 0: - * step_size = 100.0 / n_elements - */ - __pyx_v_step_size = 0.0; - - /* "pygeoprocessing/geoprocessing_core.pyx":912 - * current_percentile = percentile_list[percentile_index] - * step_size = 0 - * if n_elements > 0: # <<<<<<<<<<<<<< - * step_size = 100.0 / n_elements - * - */ - __pyx_t_25 = ((__pyx_v_n_elements > 0) != 0); - if (__pyx_t_25) { - - /* "pygeoprocessing/geoprocessing_core.pyx":913 - * step_size = 0 - * if n_elements > 0: - * step_size = 100.0 / n_elements # <<<<<<<<<<<<<< - * - * LOGGER.debug('calculating percentiles') - */ - if (unlikely(__pyx_v_n_elements == 0)) { - PyErr_SetString(PyExc_ZeroDivisionError, "float division"); - __PYX_ERR(0, 913, __pyx_L1_error) - } - __pyx_v_step_size = (100.0 / ((double)__pyx_v_n_elements)); - - /* "pygeoprocessing/geoprocessing_core.pyx":912 - * current_percentile = percentile_list[percentile_index] - * step_size = 0 - * if n_elements > 0: # <<<<<<<<<<<<<< - * step_size = 100.0 / n_elements - * - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":915 - * step_size = 100.0 / n_elements - * - * LOGGER.debug('calculating percentiles') # <<<<<<<<<<<<<< - * for i in range(n_elements): - * if time.time() - last_update > 5.0: - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 915, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_debug); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 915, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - } - } - __pyx_t_6 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_1, __pyx_kp_u_calculating_percentiles) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_kp_u_calculating_percentiles); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 915, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":916 - * - * LOGGER.debug('calculating percentiles') - * for i in range(n_elements): # <<<<<<<<<<<<<< - * if time.time() - last_update > 5.0: - * LOGGER.debug( - */ - __pyx_t_21 = __pyx_v_n_elements; - __pyx_t_35 = __pyx_t_21; - for (__pyx_t_36 = 0; __pyx_t_36 < __pyx_t_35; __pyx_t_36+=1) { - __pyx_v_i = __pyx_t_36; - - /* "pygeoprocessing/geoprocessing_core.pyx":917 - * LOGGER.debug('calculating percentiles') - * for i in range(n_elements): - * if time.time() - last_update > 5.0: # <<<<<<<<<<<<<< - * LOGGER.debug( - * 'calculating percentiles %.2f%% complete', - */ - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_time); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 917, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_time); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 917, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_6 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 917, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Subtract(__pyx_t_6, __pyx_v_last_update); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 917, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = PyObject_RichCompare(__pyx_t_1, __pyx_float_5_0, Py_GT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 917, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_25 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_25 < 0)) __PYX_ERR(0, 917, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (__pyx_t_25) { - - /* "pygeoprocessing/geoprocessing_core.pyx":918 - * for i in range(n_elements): - * if time.time() - last_update > 5.0: - * LOGGER.debug( # <<<<<<<<<<<<<< - * 'calculating percentiles %.2f%% complete', - * 100.0 * i / float(n_elements)) - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 918, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_debug); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 918, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":920 - * LOGGER.debug( - * 'calculating percentiles %.2f%% complete', - * 100.0 * i / float(n_elements)) # <<<<<<<<<<<<<< - * last_update = time.time() - * current_step = step_size * i - */ - __pyx_t_28 = (100.0 * __pyx_v_i); - if (unlikely(((double)__pyx_v_n_elements) == 0)) { - PyErr_SetString(PyExc_ZeroDivisionError, "float division"); - __PYX_ERR(0, 920, __pyx_L1_error) - } - __pyx_t_1 = PyFloat_FromDouble((__pyx_t_28 / ((double)__pyx_v_n_elements))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 920, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = NULL; - __pyx_t_13 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(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); - __pyx_t_13 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_kp_u_calculating_percentiles_2f_compl, __pyx_t_1}; - __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 918, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_6); - __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[3] = {__pyx_t_9, __pyx_kp_u_calculating_percentiles_2f_compl, __pyx_t_1}; - __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 918, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - { - __pyx_t_5 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 918, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (__pyx_t_9) { - __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_9); __pyx_t_9 = NULL; - } - __Pyx_INCREF(__pyx_kp_u_calculating_percentiles_2f_compl); - __Pyx_GIVEREF(__pyx_kp_u_calculating_percentiles_2f_compl); - PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_13, __pyx_kp_u_calculating_percentiles_2f_compl); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_13, __pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_5, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 918, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":921 - * 'calculating percentiles %.2f%% complete', - * 100.0 * i / float(n_elements)) - * last_update = time.time() # <<<<<<<<<<<<<< - * current_step = step_size * i - * next_val = fast_file_iterator_vector.front().next() - */ - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_time); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 921, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 921, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - } - } - __pyx_t_6 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 921, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF_SET(__pyx_v_last_update, __pyx_t_6); - __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":917 - * LOGGER.debug('calculating percentiles') - * for i in range(n_elements): - * if time.time() - last_update > 5.0: # <<<<<<<<<<<<<< - * LOGGER.debug( - * 'calculating percentiles %.2f%% complete', - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":922 - * 100.0 * i / float(n_elements)) - * last_update = time.time() - * current_step = step_size * i # <<<<<<<<<<<<<< - * next_val = fast_file_iterator_vector.front().next() - * if current_step >= current_percentile: - */ - __pyx_v_current_step = (__pyx_v_step_size * __pyx_v_i); - - /* "pygeoprocessing/geoprocessing_core.pyx":923 - * last_update = time.time() - * current_step = step_size * i - * next_val = fast_file_iterator_vector.front().next() # <<<<<<<<<<<<<< - * if current_step >= current_percentile: - * result_list.append(next_val) - */ - __pyx_v_next_val = __pyx_v_fast_file_iterator_vector.front()->next(); - - /* "pygeoprocessing/geoprocessing_core.pyx":924 - * current_step = step_size * i - * next_val = fast_file_iterator_vector.front().next() - * if current_step >= current_percentile: # <<<<<<<<<<<<<< - * result_list.append(next_val) - * percentile_index += 1 - */ - __pyx_t_25 = ((__pyx_v_current_step >= __pyx_v_current_percentile) != 0); - if (__pyx_t_25) { - - /* "pygeoprocessing/geoprocessing_core.pyx":925 - * next_val = fast_file_iterator_vector.front().next() - * if current_step >= current_percentile: - * result_list.append(next_val) # <<<<<<<<<<<<<< - * percentile_index += 1 - * if percentile_index >= len(percentile_list): - */ - __pyx_t_6 = PyFloat_FromDouble(__pyx_v_next_val); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 925, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_30 = __Pyx_PyList_Append(__pyx_v_result_list, __pyx_t_6); if (unlikely(__pyx_t_30 == ((int)-1))) __PYX_ERR(0, 925, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":926 - * if current_step >= current_percentile: - * result_list.append(next_val) - * percentile_index += 1 # <<<<<<<<<<<<<< - * if percentile_index >= len(percentile_list): - * break - */ - __pyx_v_percentile_index = (__pyx_v_percentile_index + 1); - - /* "pygeoprocessing/geoprocessing_core.pyx":927 - * result_list.append(next_val) - * percentile_index += 1 - * if percentile_index >= len(percentile_list): # <<<<<<<<<<<<<< - * break - * current_percentile = percentile_list[percentile_index] - */ - __pyx_t_22 = PyObject_Length(__pyx_v_percentile_list); if (unlikely(__pyx_t_22 == ((Py_ssize_t)-1))) __PYX_ERR(0, 927, __pyx_L1_error) - __pyx_t_25 = ((__pyx_v_percentile_index >= __pyx_t_22) != 0); - if (__pyx_t_25) { - - /* "pygeoprocessing/geoprocessing_core.pyx":928 - * percentile_index += 1 - * if percentile_index >= len(percentile_list): - * break # <<<<<<<<<<<<<< - * current_percentile = percentile_list[percentile_index] - * pop_heap( - */ - goto __pyx_L28_break; - - /* "pygeoprocessing/geoprocessing_core.pyx":927 - * result_list.append(next_val) - * percentile_index += 1 - * if percentile_index >= len(percentile_list): # <<<<<<<<<<<<<< - * break - * current_percentile = percentile_list[percentile_index] - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":929 - * if percentile_index >= len(percentile_list): - * break - * current_percentile = percentile_list[percentile_index] # <<<<<<<<<<<<<< - * pop_heap( - * fast_file_iterator_vector.begin(), - */ - __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_percentile_list, __pyx_v_percentile_index, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 929, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_28 = __pyx_PyFloat_AsDouble(__pyx_t_6); if (unlikely((__pyx_t_28 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 929, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_current_percentile = __pyx_t_28; - - /* "pygeoprocessing/geoprocessing_core.pyx":924 - * current_step = step_size * i - * next_val = fast_file_iterator_vector.front().next() - * if current_step >= current_percentile: # <<<<<<<<<<<<<< - * result_list.append(next_val) - * percentile_index += 1 - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":930 - * break - * current_percentile = percentile_list[percentile_index] - * pop_heap( # <<<<<<<<<<<<<< - * fast_file_iterator_vector.begin(), - * fast_file_iterator_vector.end(), - */ - std::pop_heap(__pyx_v_fast_file_iterator_vector.begin(), __pyx_v_fast_file_iterator_vector.end(), FastFileIteratorCompare); - - /* "pygeoprocessing/geoprocessing_core.pyx":934 - * fast_file_iterator_vector.end(), - * FastFileIteratorCompare[double]) - * if fast_file_iterator_vector.back().size() > 0: # <<<<<<<<<<<<<< - * push_heap( - * fast_file_iterator_vector.begin(), - */ - __pyx_t_25 = ((__pyx_v_fast_file_iterator_vector.back()->size() > 0) != 0); - if (__pyx_t_25) { - - /* "pygeoprocessing/geoprocessing_core.pyx":935 - * FastFileIteratorCompare[double]) - * if fast_file_iterator_vector.back().size() > 0: - * push_heap( # <<<<<<<<<<<<<< - * fast_file_iterator_vector.begin(), - * fast_file_iterator_vector.end(), - */ - std::push_heap(__pyx_v_fast_file_iterator_vector.begin(), __pyx_v_fast_file_iterator_vector.end(), FastFileIteratorCompare); - - /* "pygeoprocessing/geoprocessing_core.pyx":934 - * fast_file_iterator_vector.end(), - * FastFileIteratorCompare[double]) - * if fast_file_iterator_vector.back().size() > 0: # <<<<<<<<<<<<<< - * push_heap( - * fast_file_iterator_vector.begin(), - */ - goto __pyx_L32; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":940 - * FastFileIteratorCompare[double]) - * else: - * fast_file_iterator_vector.pop_back() # <<<<<<<<<<<<<< - * if percentile_index < len(percentile_list): - * result_list.append(next_val) - */ - /*else*/ { - __pyx_v_fast_file_iterator_vector.pop_back(); - } - __pyx_L32:; - } - __pyx_L28_break:; - - /* "pygeoprocessing/geoprocessing_core.pyx":941 - * else: - * fast_file_iterator_vector.pop_back() - * if percentile_index < len(percentile_list): # <<<<<<<<<<<<<< - * result_list.append(next_val) - * # free all the iterator memory - */ - __pyx_t_22 = PyObject_Length(__pyx_v_percentile_list); if (unlikely(__pyx_t_22 == ((Py_ssize_t)-1))) __PYX_ERR(0, 941, __pyx_L1_error) - __pyx_t_25 = ((__pyx_v_percentile_index < __pyx_t_22) != 0); - if (__pyx_t_25) { - - /* "pygeoprocessing/geoprocessing_core.pyx":942 - * fast_file_iterator_vector.pop_back() - * if percentile_index < len(percentile_list): - * result_list.append(next_val) # <<<<<<<<<<<<<< - * # free all the iterator memory - * ffiv_iter = fast_file_iterator_vector.begin() - */ - __pyx_t_6 = PyFloat_FromDouble(__pyx_v_next_val); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 942, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_30 = __Pyx_PyList_Append(__pyx_v_result_list, __pyx_t_6); if (unlikely(__pyx_t_30 == ((int)-1))) __PYX_ERR(0, 942, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":941 - * else: - * fast_file_iterator_vector.pop_back() - * if percentile_index < len(percentile_list): # <<<<<<<<<<<<<< - * result_list.append(next_val) - * # free all the iterator memory - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":944 - * result_list.append(next_val) - * # free all the iterator memory - * ffiv_iter = fast_file_iterator_vector.begin() # <<<<<<<<<<<<<< - * while ffiv_iter != fast_file_iterator_vector.end(): - * fast_file_iterator = deref(ffiv_iter) - */ - __pyx_v_ffiv_iter = __pyx_v_fast_file_iterator_vector.begin(); - - /* "pygeoprocessing/geoprocessing_core.pyx":945 - * # free all the iterator memory - * ffiv_iter = fast_file_iterator_vector.begin() - * while ffiv_iter != fast_file_iterator_vector.end(): # <<<<<<<<<<<<<< - * fast_file_iterator = deref(ffiv_iter) - * del fast_file_iterator - */ - while (1) { - __pyx_t_25 = ((__pyx_v_ffiv_iter != __pyx_v_fast_file_iterator_vector.end()) != 0); - if (!__pyx_t_25) break; - - /* "pygeoprocessing/geoprocessing_core.pyx":946 - * ffiv_iter = fast_file_iterator_vector.begin() - * while ffiv_iter != fast_file_iterator_vector.end(): - * fast_file_iterator = deref(ffiv_iter) # <<<<<<<<<<<<<< - * del fast_file_iterator - * inc(ffiv_iter) - */ - __pyx_v_fast_file_iterator = (*__pyx_v_ffiv_iter); - - /* "pygeoprocessing/geoprocessing_core.pyx":947 - * while ffiv_iter != fast_file_iterator_vector.end(): - * fast_file_iterator = deref(ffiv_iter) - * del fast_file_iterator # <<<<<<<<<<<<<< - * inc(ffiv_iter) - * fast_file_iterator_vector.clear() - */ - delete __pyx_v_fast_file_iterator; - - /* "pygeoprocessing/geoprocessing_core.pyx":948 - * fast_file_iterator = deref(ffiv_iter) - * del fast_file_iterator - * inc(ffiv_iter) # <<<<<<<<<<<<<< - * fast_file_iterator_vector.clear() - * # delete all the heap files - */ - (void)((++__pyx_v_ffiv_iter)); - } - - /* "pygeoprocessing/geoprocessing_core.pyx":949 - * del fast_file_iterator - * inc(ffiv_iter) - * fast_file_iterator_vector.clear() # <<<<<<<<<<<<<< - * # delete all the heap files - * for file_path in heapfile_list: - */ - __pyx_v_fast_file_iterator_vector.clear(); - - /* "pygeoprocessing/geoprocessing_core.pyx":951 - * fast_file_iterator_vector.clear() - * # delete all the heap files - * for file_path in heapfile_list: # <<<<<<<<<<<<<< - * try: - * os.remove(file_path) - */ - __pyx_t_6 = __pyx_v_heapfile_list; __Pyx_INCREF(__pyx_t_6); __pyx_t_22 = 0; - for (;;) { - if (__pyx_t_22 >= 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_22); __Pyx_INCREF(__pyx_t_5); __pyx_t_22++; if (unlikely(0 < 0)) __PYX_ERR(0, 951, __pyx_L1_error) - #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_6, __pyx_t_22); __pyx_t_22++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 951, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - __Pyx_XDECREF_SET(__pyx_v_file_path, __pyx_t_5); - __pyx_t_5 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":952 - * # delete all the heap files - * for file_path in heapfile_list: - * try: # <<<<<<<<<<<<<< - * os.remove(file_path) - * except OSError: - */ - { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __Pyx_ExceptionSave(&__pyx_t_4, &__pyx_t_3, &__pyx_t_2); - __Pyx_XGOTREF(__pyx_t_4); - __Pyx_XGOTREF(__pyx_t_3); - __Pyx_XGOTREF(__pyx_t_2); - /*try:*/ { - - /* "pygeoprocessing/geoprocessing_core.pyx":953 - * for file_path in heapfile_list: - * try: - * os.remove(file_path) # <<<<<<<<<<<<<< - * except OSError: - * # you never know if this might fail! - */ - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_os); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 953, __pyx_L38_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_remove); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 953, __pyx_L38_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_5 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_8, __pyx_v_file_path) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_file_path); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 953, __pyx_L38_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/geoprocessing_core.pyx":952 - * # delete all the heap files - * for file_path in heapfile_list: - * try: # <<<<<<<<<<<<<< - * os.remove(file_path) - * except OSError: - */ - } - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L45_try_end; - __pyx_L38_error:; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __PYX_XDEC_MEMVIEW(&__pyx_t_29, 1); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":954 - * try: - * os.remove(file_path) - * except OSError: # <<<<<<<<<<<<<< - * # you never know if this might fail! - * LOGGER.warning('unable to remove %s', file_path) - */ - __pyx_t_13 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OSError); - if (__pyx_t_13) { - __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core._raster_band_percentile_double", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_1, &__pyx_t_8) < 0) __PYX_ERR(0, 954, __pyx_L40_except_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_t_8); - - /* "pygeoprocessing/geoprocessing_core.pyx":956 - * except OSError: - * # you never know if this might fail! - * LOGGER.warning('unable to remove %s', file_path) # <<<<<<<<<<<<<< - * if rm_dir_when_done: - * shutil.rmtree(working_sort_directory) - */ - __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 956, __pyx_L40_except_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_warning); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 956, __pyx_L40_except_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = NULL; - __pyx_t_13 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_12)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_12); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - __pyx_t_13 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_11)) { - PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_kp_u_unable_to_remove_s, __pyx_v_file_path}; - __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 956, __pyx_L40_except_error) - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GOTREF(__pyx_t_9); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { - PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_kp_u_unable_to_remove_s, __pyx_v_file_path}; - __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 956, __pyx_L40_except_error) - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GOTREF(__pyx_t_9); - } else - #endif - { - __pyx_t_10 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 956, __pyx_L40_except_error) - __Pyx_GOTREF(__pyx_t_10); - if (__pyx_t_12) { - __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_12); __pyx_t_12 = NULL; - } - __Pyx_INCREF(__pyx_kp_u_unable_to_remove_s); - __Pyx_GIVEREF(__pyx_kp_u_unable_to_remove_s); - PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_13, __pyx_kp_u_unable_to_remove_s); - __Pyx_INCREF(__pyx_v_file_path); - __Pyx_GIVEREF(__pyx_v_file_path); - PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_13, __pyx_v_file_path); - __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_10, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 956, __pyx_L40_except_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - goto __pyx_L39_exception_handled; - } - goto __pyx_L40_except_error; - __pyx_L40_except_error:; - - /* "pygeoprocessing/geoprocessing_core.pyx":952 - * # delete all the heap files - * for file_path in heapfile_list: - * try: # <<<<<<<<<<<<<< - * os.remove(file_path) - * except OSError: - */ - __Pyx_XGIVEREF(__pyx_t_4); - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_XGIVEREF(__pyx_t_2); - __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_3, __pyx_t_2); - goto __pyx_L1_error; - __pyx_L39_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_4); - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_XGIVEREF(__pyx_t_2); - __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_3, __pyx_t_2); - __pyx_L45_try_end:; - } - - /* "pygeoprocessing/geoprocessing_core.pyx":951 - * fast_file_iterator_vector.clear() - * # delete all the heap files - * for file_path in heapfile_list: # <<<<<<<<<<<<<< - * try: - * os.remove(file_path) - */ - } - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":957 - * # you never know if this might fail! - * LOGGER.warning('unable to remove %s', file_path) - * if rm_dir_when_done: # <<<<<<<<<<<<<< - * shutil.rmtree(working_sort_directory) - * LOGGER.debug('here is percentile_list: %s', str(result_list)) - */ - __pyx_t_25 = (__pyx_v_rm_dir_when_done != 0); - if (__pyx_t_25) { - - /* "pygeoprocessing/geoprocessing_core.pyx":958 - * LOGGER.warning('unable to remove %s', file_path) - * if rm_dir_when_done: - * shutil.rmtree(working_sort_directory) # <<<<<<<<<<<<<< - * LOGGER.debug('here is percentile_list: %s', str(result_list)) - * return result_list - */ - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_shutil); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 958, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_rmtree); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 958, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_6 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_8, __pyx_v_working_sort_directory) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_working_sort_directory); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 958, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":957 - * # you never know if this might fail! - * LOGGER.warning('unable to remove %s', file_path) - * if rm_dir_when_done: # <<<<<<<<<<<<<< - * shutil.rmtree(working_sort_directory) - * LOGGER.debug('here is percentile_list: %s', str(result_list)) - */ - } - - /* "pygeoprocessing/geoprocessing_core.pyx":959 - * if rm_dir_when_done: - * shutil.rmtree(working_sort_directory) - * LOGGER.debug('here is percentile_list: %s', str(result_list)) # <<<<<<<<<<<<<< - * return result_list - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 959, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_debug); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 959, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_v_result_list); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 959, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = NULL; - __pyx_t_13 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - __pyx_t_13 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_kp_u_here_is_percentile_list_s, __pyx_t_1}; - __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 959, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_6); - __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[3] = {__pyx_t_5, __pyx_kp_u_here_is_percentile_list_s, __pyx_t_1}; - __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 959, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - { - __pyx_t_9 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 959, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - if (__pyx_t_5) { - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_5); __pyx_t_5 = NULL; - } - __Pyx_INCREF(__pyx_kp_u_here_is_percentile_list_s); - __Pyx_GIVEREF(__pyx_kp_u_here_is_percentile_list_s); - PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_13, __pyx_kp_u_here_is_percentile_list_s); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_13, __pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_9, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 959, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":960 - * shutil.rmtree(working_sort_directory) - * LOGGER.debug('here is percentile_list: %s', str(result_list)) - * return result_list # <<<<<<<<<<<<<< - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_result_list); - __pyx_r = __pyx_v_result_list; - goto __pyx_L0; - - /* "pygeoprocessing/geoprocessing_core.pyx":819 - * - * - * def _raster_band_percentile_double( # <<<<<<<<<<<<<< - * base_raster_path_band, working_sort_directory, percentile_list, - * heap_buffer_size, ffi_buffer_size): - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_12); - __PYX_XDEC_MEMVIEW(&__pyx_t_29, 1); - __Pyx_AddTraceback("pygeoprocessing.geoprocessing_core._raster_band_percentile_double", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __PYX_XDEC_MEMVIEW(&__pyx_v_buffer_data, 1); - __Pyx_XDECREF(__pyx_v_result_list); - __Pyx_XDECREF(__pyx_v_e); - __Pyx_XDECREF(__pyx_v_file_index); - __Pyx_XDECREF(__pyx_v_nodata); - __Pyx_XDECREF(__pyx_v_heapfile_list); - __Pyx_XDECREF(__pyx_v_raster_info); - __Pyx_XDECREF(__pyx_v_last_update); - __Pyx_XDECREF(__pyx_v__); - __Pyx_XDECREF(__pyx_v_block_data); - __Pyx_XDECREF(__pyx_v_file_path); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":735 - * ctypedef npy_cdouble complex_t - * - * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(1, 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew1", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":736 - * - * cdef inline object PyArray_MultiIterNew1(a): - * return PyArray_MultiIterNew(1, 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(1, 736, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":735 - * ctypedef npy_cdouble complex_t - * - * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(1, 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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":738 - * return PyArray_MultiIterNew(1, a) - * - * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(2, a, 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew2", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":739 - * - * cdef inline object PyArray_MultiIterNew2(a, b): - * return PyArray_MultiIterNew(2, a, 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(1, 739, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":738 - * return PyArray_MultiIterNew(1, a) - * - * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(2, a, 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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":741 - * return PyArray_MultiIterNew(2, a, b) - * - * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(3, a, b, 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew3", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":742 - * - * cdef inline object PyArray_MultiIterNew3(a, b, c): - * return PyArray_MultiIterNew(3, a, b, 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(1, 742, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":741 - * return PyArray_MultiIterNew(2, a, b) - * - * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(3, a, b, 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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":744 - * return PyArray_MultiIterNew(3, a, b, c) - * - * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(4, a, b, c, 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew4", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":745 - * - * cdef inline object PyArray_MultiIterNew4(a, b, c, d): - * return PyArray_MultiIterNew(4, a, b, c, 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(1, 745, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":744 - * return PyArray_MultiIterNew(3, a, b, c) - * - * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(4, a, b, c, 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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":747 - * return PyArray_MultiIterNew(4, a, b, c, d) - * - * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(5, a, b, c, d, 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew5", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":748 - * - * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): - * return PyArray_MultiIterNew(5, a, b, c, d, 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(1, 748, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":747 - * return PyArray_MultiIterNew(4, a, b, c, d) - * - * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(5, a, b, c, d, 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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":750 - * return PyArray_MultiIterNew(5, a, b, c, d, e) - * - * cdef inline tuple PyDataType_SHAPE(dtype d): # <<<<<<<<<<<<<< - * if PyDataType_HASSUBARRAY(d): - * return 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); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":751 - * - * cdef inline tuple PyDataType_SHAPE(dtype d): - * if PyDataType_HASSUBARRAY(d): # <<<<<<<<<<<<<< - * return d.subarray.shape - * else: - */ - __pyx_t_1 = (PyDataType_HASSUBARRAY(__pyx_v_d) != 0); - if (__pyx_t_1) { - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":752 - * cdef inline tuple PyDataType_SHAPE(dtype d): - * if PyDataType_HASSUBARRAY(d): - * return 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; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":751 - * - * cdef inline tuple PyDataType_SHAPE(dtype d): - * if PyDataType_HASSUBARRAY(d): # <<<<<<<<<<<<<< - * return d.subarray.shape - * else: - */ - } - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":754 - * return d.subarray.shape - * else: - * return () # <<<<<<<<<<<<<< - * - * - */ - /*else*/ { - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_empty_tuple); - __pyx_r = __pyx_empty_tuple; - goto __pyx_L0; - } - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":750 - * return PyArray_MultiIterNew(5, a, b, c, d, e) - * - * cdef inline tuple PyDataType_SHAPE(dtype d): # <<<<<<<<<<<<<< - * if PyDataType_HASSUBARRAY(d): - * return d.subarray.shape - */ - - /* function exit code */ - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":931 - * int _import_umath() except -1 - * - * cdef inline void set_array_base(ndarray arr, object base): # <<<<<<<<<<<<<< - * Py_INCREF(base) # important to do this before stealing the reference below! - * PyArray_SetBaseObject(arr, base) - */ - -static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_arr, PyObject *__pyx_v_base) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("set_array_base", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":932 - * - * cdef inline void set_array_base(ndarray arr, object base): - * Py_INCREF(base) # important to do this before stealing the reference below! # <<<<<<<<<<<<<< - * PyArray_SetBaseObject(arr, base) - * - */ - Py_INCREF(__pyx_v_base); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":933 - * cdef inline void set_array_base(ndarray arr, object base): - * Py_INCREF(base) # important to do this before stealing the reference below! - * PyArray_SetBaseObject(arr, base) # <<<<<<<<<<<<<< - * - * cdef inline object get_array_base(ndarray arr): - */ - (void)(PyArray_SetBaseObject(__pyx_v_arr, __pyx_v_base)); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":931 - * int _import_umath() except -1 - * - * cdef inline void set_array_base(ndarray arr, object base): # <<<<<<<<<<<<<< - * Py_INCREF(base) # important to do this before stealing the reference below! - * PyArray_SetBaseObject(arr, base) - */ - - /* function exit code */ - __Pyx_RefNannyFinishContext(); -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":935 - * PyArray_SetBaseObject(arr, base) - * - * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< - * base = PyArray_BASE(arr) - * if base is NULL: - */ - -static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__pyx_v_arr) { - PyObject *__pyx_v_base; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("get_array_base", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":936 - * - * cdef inline object get_array_base(ndarray arr): - * base = PyArray_BASE(arr) # <<<<<<<<<<<<<< - * if base is NULL: - * return None - */ - __pyx_v_base = PyArray_BASE(__pyx_v_arr); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":937 - * cdef inline object get_array_base(ndarray arr): - * base = PyArray_BASE(arr) - * if base is NULL: # <<<<<<<<<<<<<< - * return None - * return base - */ - __pyx_t_1 = ((__pyx_v_base == NULL) != 0); - if (__pyx_t_1) { - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":938 - * base = PyArray_BASE(arr) - * if base is NULL: - * return None # <<<<<<<<<<<<<< - * return base - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":937 - * cdef inline object get_array_base(ndarray arr): - * base = PyArray_BASE(arr) - * if base is NULL: # <<<<<<<<<<<<<< - * return None - * return base - */ - } - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":939 - * if base is NULL: - * return None - * return base # <<<<<<<<<<<<<< - * - * # Versions of the import_* functions which are more suitable for - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_base)); - __pyx_r = ((PyObject *)__pyx_v_base); - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":935 - * PyArray_SetBaseObject(arr, base) - * - * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< - * base = PyArray_BASE(arr) - * if base is NULL: - */ - - /* function exit code */ - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":943 - * # Versions of the import_* functions which are more suitable for - * # Cython code. - * cdef inline int import_array() except -1: # <<<<<<<<<<<<<< - * try: - * __pyx_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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("import_array", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":944 - * # Cython code. - * cdef inline int import_array() except -1: - * try: # <<<<<<<<<<<<<< - * __pyx_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:*/ { - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":945 - * cdef inline int import_array() except -1: - * try: - * __pyx_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(1, 945, __pyx_L3_error) - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":944 - * # Cython code. - * cdef inline int import_array() except -1: - * try: # <<<<<<<<<<<<<< - * __pyx_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:; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":946 - * try: - * __pyx_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(1, 946, __pyx_L5_except_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GOTREF(__pyx_t_7); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":947 - * __pyx_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__4, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 947, __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(1, 947, __pyx_L5_except_error) - } - goto __pyx_L5_except_error; - __pyx_L5_except_error:; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":944 - * # Cython code. - * cdef inline int import_array() except -1: - * try: # <<<<<<<<<<<<<< - * __pyx_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:; - } - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":943 - * # Versions of the import_* functions which are more suitable for - * # Cython code. - * cdef inline int import_array() except -1: # <<<<<<<<<<<<<< - * try: - * __pyx_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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":949 - * 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("import_umath", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":950 - * - * 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:*/ { - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":951 - * 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(1, 951, __pyx_L3_error) - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":950 - * - * 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:; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":952 - * 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(1, 952, __pyx_L5_except_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GOTREF(__pyx_t_7); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":953 - * _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__5, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 953, __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(1, 953, __pyx_L5_except_error) - } - goto __pyx_L5_except_error; - __pyx_L5_except_error:; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":950 - * - * 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:; - } - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":949 - * 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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":955 - * 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("import_ufunc", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":956 - * - * 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:*/ { - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":957 - * 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(1, 957, __pyx_L3_error) - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":956 - * - * 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:; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":958 - * 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(1, 958, __pyx_L5_except_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GOTREF(__pyx_t_7); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":959 - * _import_umath() - * except Exception: - * raise ImportError("numpy.core.umath failed to import") # <<<<<<<<<<<<<< - * - * cdef extern from *: - */ - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 959, __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(1, 959, __pyx_L5_except_error) - } - goto __pyx_L5_except_error; - __pyx_L5_except_error:; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":956 - * - * 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:; - } - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":955 - * 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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":969 - * - * - * cdef inline bint is_timedelta64_object(object obj): # <<<<<<<<<<<<<< - * """ - * Cython equivalent of `isinstance(obj, np.timedelta64)` - */ - -static CYTHON_INLINE int __pyx_f_5numpy_is_timedelta64_object(PyObject *__pyx_v_obj) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("is_timedelta64_object", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":981 - * bool - * """ - * return PyObject_TypeCheck(obj, &PyTimedeltaArrType_Type) # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = PyObject_TypeCheck(__pyx_v_obj, (&PyTimedeltaArrType_Type)); - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":969 - * - * - * cdef inline bint is_timedelta64_object(object obj): # <<<<<<<<<<<<<< - * """ - * Cython equivalent of `isinstance(obj, np.timedelta64)` - */ - - /* function exit code */ - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":984 - * - * - * cdef inline bint is_datetime64_object(object obj): # <<<<<<<<<<<<<< - * """ - * Cython equivalent of `isinstance(obj, np.datetime64)` - */ - -static CYTHON_INLINE int __pyx_f_5numpy_is_datetime64_object(PyObject *__pyx_v_obj) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("is_datetime64_object", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":996 - * bool - * """ - * return PyObject_TypeCheck(obj, &PyDatetimeArrType_Type) # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = PyObject_TypeCheck(__pyx_v_obj, (&PyDatetimeArrType_Type)); - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":984 - * - * - * cdef inline bint is_datetime64_object(object obj): # <<<<<<<<<<<<<< - * """ - * Cython equivalent of `isinstance(obj, np.datetime64)` - */ - - /* function exit code */ - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":999 - * - * - * cdef inline npy_datetime get_datetime64_value(object obj) nogil: # <<<<<<<<<<<<<< - * """ - * returns the int64 value underlying scalar numpy datetime64 object - */ - -static CYTHON_INLINE npy_datetime __pyx_f_5numpy_get_datetime64_value(PyObject *__pyx_v_obj) { - npy_datetime __pyx_r; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1006 - * also needed. That can be found using `get_datetime64_unit`. - * """ - * return (obj).obval # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = ((PyDatetimeScalarObject *)__pyx_v_obj)->obval; - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":999 - * - * - * cdef inline npy_datetime get_datetime64_value(object obj) nogil: # <<<<<<<<<<<<<< - * """ - * returns the int64 value underlying scalar numpy datetime64 object - */ - - /* function exit code */ - __pyx_L0:; - return __pyx_r; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1009 - * - * - * cdef inline npy_timedelta get_timedelta64_value(object obj) nogil: # <<<<<<<<<<<<<< - * """ - * returns the int64 value underlying scalar numpy timedelta64 object - */ - -static CYTHON_INLINE npy_timedelta __pyx_f_5numpy_get_timedelta64_value(PyObject *__pyx_v_obj) { - npy_timedelta __pyx_r; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1013 - * returns the int64 value underlying scalar numpy timedelta64 object - * """ - * return (obj).obval # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = ((PyTimedeltaScalarObject *)__pyx_v_obj)->obval; - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1009 - * - * - * cdef inline npy_timedelta get_timedelta64_value(object obj) nogil: # <<<<<<<<<<<<<< - * """ - * returns the int64 value underlying scalar numpy timedelta64 object - */ - - /* function exit code */ - __pyx_L0:; - return __pyx_r; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1016 - * - * - * cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil: # <<<<<<<<<<<<<< - * """ - * returns the unit part of the dtype for a numpy datetime64 object. - */ - -static CYTHON_INLINE NPY_DATETIMEUNIT __pyx_f_5numpy_get_datetime64_unit(PyObject *__pyx_v_obj) { - NPY_DATETIMEUNIT __pyx_r; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1020 - * returns the unit part of the dtype for a numpy datetime64 object. - * """ - * return (obj).obmeta.base # <<<<<<<<<<<<<< - */ - __pyx_r = ((NPY_DATETIMEUNIT)((PyDatetimeScalarObject *)__pyx_v_obj)->obmeta.base); - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1016 - * - * - * cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil: # <<<<<<<<<<<<<< - * """ - * returns the unit part of the dtype for a numpy datetime64 object. - */ - - /* function exit code */ - __pyx_L0:; - return __pyx_r; -} - -/* "View.MemoryView":122 - * cdef bint dtype_is_object - * - * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, # <<<<<<<<<<<<<< - * mode="c", bint allocate_buffer=True): - * - */ - -/* Python wrapper */ -static int __pyx_array___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_array___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_shape = 0; - Py_ssize_t __pyx_v_itemsize; - PyObject *__pyx_v_format = 0; - PyObject *__pyx_v_mode = 0; - int __pyx_v_allocate_buffer; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_shape,&__pyx_n_s_itemsize,&__pyx_n_s_format,&__pyx_n_s_mode,&__pyx_n_s_allocate_buffer,0}; - PyObject* values[5] = {0,0,0,0,0}; - values[3] = ((PyObject *)__pyx_n_s_c); - 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_shape)) != 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_itemsize)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 1); __PYX_ERR(2, 122, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_format)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 2); __PYX_ERR(2, 122, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mode); - 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_allocate_buffer); - if (value) { values[4] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(2, 122, __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_shape = ((PyObject*)values[0]); - __pyx_v_itemsize = __Pyx_PyIndex_AsSsize_t(values[1]); if (unlikely((__pyx_v_itemsize == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 122, __pyx_L3_error) - __pyx_v_format = values[2]; - __pyx_v_mode = values[3]; - if (values[4]) { - __pyx_v_allocate_buffer = __Pyx_PyObject_IsTrue(values[4]); if (unlikely((__pyx_v_allocate_buffer == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 123, __pyx_L3_error) - } else { - - /* "View.MemoryView":123 - * - * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, - * mode="c", bint allocate_buffer=True): # <<<<<<<<<<<<<< - * - * cdef int idx - */ - __pyx_v_allocate_buffer = ((int)1); - } - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 122, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("View.MemoryView.array.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_shape), (&PyTuple_Type), 1, "shape", 1))) __PYX_ERR(2, 122, __pyx_L1_error) - if (unlikely(((PyObject *)__pyx_v_format) == Py_None)) { - PyErr_Format(PyExc_TypeError, "Argument '%.200s' must not be None", "format"); __PYX_ERR(2, 122, __pyx_L1_error) - } - __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(((struct __pyx_array_obj *)__pyx_v_self), __pyx_v_shape, __pyx_v_itemsize, __pyx_v_format, __pyx_v_mode, __pyx_v_allocate_buffer); - - /* "View.MemoryView":122 - * cdef bint dtype_is_object - * - * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, # <<<<<<<<<<<<<< - * mode="c", bint allocate_buffer=True): - * - */ - - /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, PyObject *__pyx_v_format, PyObject *__pyx_v_mode, int __pyx_v_allocate_buffer) { - int __pyx_v_idx; - Py_ssize_t __pyx_v_i; - Py_ssize_t __pyx_v_dim; - PyObject **__pyx_v_p; - char __pyx_v_order; - int __pyx_r; - __Pyx_RefNannyDeclarations - Py_ssize_t __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - char *__pyx_t_7; - int __pyx_t_8; - Py_ssize_t __pyx_t_9; - PyObject *__pyx_t_10 = NULL; - Py_ssize_t __pyx_t_11; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); - __Pyx_INCREF(__pyx_v_format); - - /* "View.MemoryView":129 - * cdef PyObject **p - * - * self.ndim = len(shape) # <<<<<<<<<<<<<< - * self.itemsize = itemsize - * - */ - if (unlikely(__pyx_v_shape == Py_None)) { - PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(2, 129, __pyx_L1_error) - } - __pyx_t_1 = PyTuple_GET_SIZE(__pyx_v_shape); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(2, 129, __pyx_L1_error) - __pyx_v_self->ndim = ((int)__pyx_t_1); - - /* "View.MemoryView":130 - * - * self.ndim = len(shape) - * self.itemsize = itemsize # <<<<<<<<<<<<<< - * - * if not self.ndim: - */ - __pyx_v_self->itemsize = __pyx_v_itemsize; - - /* "View.MemoryView":132 - * self.itemsize = itemsize - * - * if not self.ndim: # <<<<<<<<<<<<<< - * raise ValueError("Empty shape tuple for cython.array") - * - */ - __pyx_t_2 = ((!(__pyx_v_self->ndim != 0)) != 0); - if (unlikely(__pyx_t_2)) { - - /* "View.MemoryView":133 - * - * if not self.ndim: - * raise ValueError("Empty shape tuple for cython.array") # <<<<<<<<<<<<<< - * - * if itemsize <= 0: - */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 133, __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, 133, __pyx_L1_error) - - /* "View.MemoryView":132 - * self.itemsize = itemsize - * - * if not self.ndim: # <<<<<<<<<<<<<< - * raise ValueError("Empty shape tuple for cython.array") - * - */ - } - - /* "View.MemoryView":135 - * raise ValueError("Empty shape tuple for cython.array") - * - * if itemsize <= 0: # <<<<<<<<<<<<<< - * raise ValueError("itemsize <= 0 for cython.array") - * - */ - __pyx_t_2 = ((__pyx_v_itemsize <= 0) != 0); - if (unlikely(__pyx_t_2)) { - - /* "View.MemoryView":136 - * - * if itemsize <= 0: - * raise ValueError("itemsize <= 0 for cython.array") # <<<<<<<<<<<<<< - * - * if not isinstance(format, bytes): - */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 136, __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, 136, __pyx_L1_error) - - /* "View.MemoryView":135 - * raise ValueError("Empty shape tuple for cython.array") - * - * if itemsize <= 0: # <<<<<<<<<<<<<< - * raise ValueError("itemsize <= 0 for cython.array") - * - */ - } - - /* "View.MemoryView":138 - * raise ValueError("itemsize <= 0 for cython.array") - * - * if not isinstance(format, bytes): # <<<<<<<<<<<<<< - * format = format.encode('ASCII') - * self._format = format # keep a reference to the byte string - */ - __pyx_t_2 = PyBytes_Check(__pyx_v_format); - __pyx_t_4 = ((!(__pyx_t_2 != 0)) != 0); - if (__pyx_t_4) { - - /* "View.MemoryView":139 - * - * if not isinstance(format, bytes): - * format = format.encode('ASCII') # <<<<<<<<<<<<<< - * self._format = format # keep a reference to the byte string - * self.format = self._format - */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_format, __pyx_n_s_encode); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 139, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __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); - } - } - __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_n_s_ASCII) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_n_s_ASCII); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 139, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF_SET(__pyx_v_format, __pyx_t_3); - __pyx_t_3 = 0; - - /* "View.MemoryView":138 - * raise ValueError("itemsize <= 0 for cython.array") - * - * if not isinstance(format, bytes): # <<<<<<<<<<<<<< - * format = format.encode('ASCII') - * self._format = format # keep a reference to the byte string - */ - } - - /* "View.MemoryView":140 - * if not isinstance(format, bytes): - * format = format.encode('ASCII') - * self._format = format # keep a reference to the byte string # <<<<<<<<<<<<<< - * self.format = self._format - * - */ - if (!(likely(PyBytes_CheckExact(__pyx_v_format))||((__pyx_v_format) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_v_format)->tp_name), 0))) __PYX_ERR(2, 140, __pyx_L1_error) - __pyx_t_3 = __pyx_v_format; - __Pyx_INCREF(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __Pyx_GOTREF(__pyx_v_self->_format); - __Pyx_DECREF(__pyx_v_self->_format); - __pyx_v_self->_format = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; - - /* "View.MemoryView":141 - * format = format.encode('ASCII') - * self._format = format # keep a reference to the byte string - * self.format = self._format # <<<<<<<<<<<<<< - * - * - */ - if (unlikely(__pyx_v_self->_format == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(2, 141, __pyx_L1_error) - } - __pyx_t_7 = __Pyx_PyBytes_AsWritableString(__pyx_v_self->_format); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(2, 141, __pyx_L1_error) - __pyx_v_self->format = __pyx_t_7; - - /* "View.MemoryView":144 - * - * - * self._shape = PyObject_Malloc(sizeof(Py_ssize_t)*self.ndim*2) # <<<<<<<<<<<<<< - * self._strides = self._shape + self.ndim - * - */ - __pyx_v_self->_shape = ((Py_ssize_t *)PyObject_Malloc((((sizeof(Py_ssize_t)) * __pyx_v_self->ndim) * 2))); - - /* "View.MemoryView":145 - * - * self._shape = PyObject_Malloc(sizeof(Py_ssize_t)*self.ndim*2) - * self._strides = self._shape + self.ndim # <<<<<<<<<<<<<< - * - * if not self._shape: - */ - __pyx_v_self->_strides = (__pyx_v_self->_shape + __pyx_v_self->ndim); - - /* "View.MemoryView":147 - * self._strides = self._shape + self.ndim - * - * if not self._shape: # <<<<<<<<<<<<<< - * raise MemoryError("unable to allocate shape and strides.") - * - */ - __pyx_t_4 = ((!(__pyx_v_self->_shape != 0)) != 0); - if (unlikely(__pyx_t_4)) { - - /* "View.MemoryView":148 - * - * if not self._shape: - * raise MemoryError("unable to allocate shape and strides.") # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 148, __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, 148, __pyx_L1_error) - - /* "View.MemoryView":147 - * self._strides = self._shape + self.ndim - * - * if not self._shape: # <<<<<<<<<<<<<< - * raise MemoryError("unable to allocate shape and strides.") - * - */ - } - - /* "View.MemoryView":151 - * - * - * for idx, dim in enumerate(shape): # <<<<<<<<<<<<<< - * if dim <= 0: - * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) - */ - __pyx_t_8 = 0; - __pyx_t_3 = __pyx_v_shape; __Pyx_INCREF(__pyx_t_3); __pyx_t_1 = 0; - for (;;) { - if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_5); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(2, 151, __pyx_L1_error) - #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 151, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - __pyx_t_9 = __Pyx_PyIndex_AsSsize_t(__pyx_t_5); if (unlikely((__pyx_t_9 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 151, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_dim = __pyx_t_9; - __pyx_v_idx = __pyx_t_8; - __pyx_t_8 = (__pyx_t_8 + 1); - - /* "View.MemoryView":152 - * - * for idx, dim in enumerate(shape): - * if dim <= 0: # <<<<<<<<<<<<<< - * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) - * self._shape[idx] = dim - */ - __pyx_t_4 = ((__pyx_v_dim <= 0) != 0); - if (unlikely(__pyx_t_4)) { - - /* "View.MemoryView":153 - * for idx, dim in enumerate(shape): - * if dim <= 0: - * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) # <<<<<<<<<<<<<< - * self._shape[idx] = dim - * - */ - __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 153, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 153, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 153, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_6); - __pyx_t_5 = 0; - __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_Invalid_shape_in_axis_d_d, __pyx_t_10); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 153, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_6); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 153, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_Raise(__pyx_t_10, 0, 0, 0); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __PYX_ERR(2, 153, __pyx_L1_error) - - /* "View.MemoryView":152 - * - * for idx, dim in enumerate(shape): - * if dim <= 0: # <<<<<<<<<<<<<< - * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) - * self._shape[idx] = dim - */ - } - - /* "View.MemoryView":154 - * if dim <= 0: - * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) - * self._shape[idx] = dim # <<<<<<<<<<<<<< - * - * cdef char order - */ - (__pyx_v_self->_shape[__pyx_v_idx]) = __pyx_v_dim; - - /* "View.MemoryView":151 - * - * - * for idx, dim in enumerate(shape): # <<<<<<<<<<<<<< - * if dim <= 0: - * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) - */ - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "View.MemoryView":157 - * - * cdef char order - * if mode == 'fortran': # <<<<<<<<<<<<<< - * order = b'F' - * self.mode = u'fortran' - */ - __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_fortran, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(2, 157, __pyx_L1_error) - if (__pyx_t_4) { - - /* "View.MemoryView":158 - * cdef char order - * if mode == 'fortran': - * order = b'F' # <<<<<<<<<<<<<< - * self.mode = u'fortran' - * elif mode == 'c': - */ - __pyx_v_order = 'F'; - - /* "View.MemoryView":159 - * if mode == 'fortran': - * order = b'F' - * self.mode = u'fortran' # <<<<<<<<<<<<<< - * elif mode == 'c': - * order = b'C' - */ - __Pyx_INCREF(__pyx_n_u_fortran); - __Pyx_GIVEREF(__pyx_n_u_fortran); - __Pyx_GOTREF(__pyx_v_self->mode); - __Pyx_DECREF(__pyx_v_self->mode); - __pyx_v_self->mode = __pyx_n_u_fortran; - - /* "View.MemoryView":157 - * - * cdef char order - * if mode == 'fortran': # <<<<<<<<<<<<<< - * order = b'F' - * self.mode = u'fortran' - */ - goto __pyx_L10; - } - - /* "View.MemoryView":160 - * order = b'F' - * self.mode = u'fortran' - * elif mode == 'c': # <<<<<<<<<<<<<< - * order = b'C' - * self.mode = u'c' - */ - __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_c, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(2, 160, __pyx_L1_error) - if (likely(__pyx_t_4)) { - - /* "View.MemoryView":161 - * self.mode = u'fortran' - * elif mode == 'c': - * order = b'C' # <<<<<<<<<<<<<< - * self.mode = u'c' - * else: - */ - __pyx_v_order = 'C'; - - /* "View.MemoryView":162 - * elif mode == 'c': - * order = b'C' - * self.mode = u'c' # <<<<<<<<<<<<<< - * else: - * raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode) - */ - __Pyx_INCREF(__pyx_n_u_c); - __Pyx_GIVEREF(__pyx_n_u_c); - __Pyx_GOTREF(__pyx_v_self->mode); - __Pyx_DECREF(__pyx_v_self->mode); - __pyx_v_self->mode = __pyx_n_u_c; - - /* "View.MemoryView":160 - * order = b'F' - * self.mode = u'fortran' - * elif mode == 'c': # <<<<<<<<<<<<<< - * order = b'C' - * self.mode = u'c' - */ - goto __pyx_L10; - } - - /* "View.MemoryView":164 - * self.mode = u'c' - * else: - * raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode) # <<<<<<<<<<<<<< - * - * self.len = fill_contig_strides_array(self._shape, self._strides, - */ - /*else*/ { - __pyx_t_3 = __Pyx_PyString_FormatSafe(__pyx_kp_s_Invalid_mode_expected_c_or_fortr, __pyx_v_mode); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 164, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 164, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_10, 0, 0, 0); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __PYX_ERR(2, 164, __pyx_L1_error) - } - __pyx_L10:; - - /* "View.MemoryView":166 - * raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode) - * - * self.len = fill_contig_strides_array(self._shape, self._strides, # <<<<<<<<<<<<<< - * itemsize, self.ndim, order) - * - */ - __pyx_v_self->len = __pyx_fill_contig_strides_array(__pyx_v_self->_shape, __pyx_v_self->_strides, __pyx_v_itemsize, __pyx_v_self->ndim, __pyx_v_order); - - /* "View.MemoryView":169 - * itemsize, self.ndim, order) - * - * self.free_data = allocate_buffer # <<<<<<<<<<<<<< - * self.dtype_is_object = format == b'O' - * if allocate_buffer: - */ - __pyx_v_self->free_data = __pyx_v_allocate_buffer; - - /* "View.MemoryView":170 - * - * self.free_data = allocate_buffer - * self.dtype_is_object = format == b'O' # <<<<<<<<<<<<<< - * if allocate_buffer: - * - */ - __pyx_t_10 = PyObject_RichCompare(__pyx_v_format, __pyx_n_b_O, Py_EQ); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 170, __pyx_L1_error) - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 170, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_v_self->dtype_is_object = __pyx_t_4; - - /* "View.MemoryView":171 - * self.free_data = allocate_buffer - * self.dtype_is_object = format == b'O' - * if allocate_buffer: # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_4 = (__pyx_v_allocate_buffer != 0); - if (__pyx_t_4) { - - /* "View.MemoryView":174 - * - * - * self.data = malloc(self.len) # <<<<<<<<<<<<<< - * if not self.data: - * raise MemoryError("unable to allocate array data.") - */ - __pyx_v_self->data = ((char *)malloc(__pyx_v_self->len)); - - /* "View.MemoryView":175 - * - * self.data = malloc(self.len) - * if not self.data: # <<<<<<<<<<<<<< - * raise MemoryError("unable to allocate array data.") - * - */ - __pyx_t_4 = ((!(__pyx_v_self->data != 0)) != 0); - if (unlikely(__pyx_t_4)) { - - /* "View.MemoryView":176 - * self.data = malloc(self.len) - * if not self.data: - * raise MemoryError("unable to allocate array data.") # <<<<<<<<<<<<<< - * - * if self.dtype_is_object: - */ - __pyx_t_10 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 176, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_Raise(__pyx_t_10, 0, 0, 0); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __PYX_ERR(2, 176, __pyx_L1_error) - - /* "View.MemoryView":175 - * - * self.data = malloc(self.len) - * if not self.data: # <<<<<<<<<<<<<< - * raise MemoryError("unable to allocate array data.") - * - */ - } - - /* "View.MemoryView":178 - * raise MemoryError("unable to allocate array data.") - * - * if self.dtype_is_object: # <<<<<<<<<<<<<< - * p = self.data - * for i in range(self.len / itemsize): - */ - __pyx_t_4 = (__pyx_v_self->dtype_is_object != 0); - if (__pyx_t_4) { - - /* "View.MemoryView":179 - * - * if self.dtype_is_object: - * p = self.data # <<<<<<<<<<<<<< - * for i in range(self.len / itemsize): - * p[i] = Py_None - */ - __pyx_v_p = ((PyObject **)__pyx_v_self->data); - - /* "View.MemoryView":180 - * if self.dtype_is_object: - * p = self.data - * for i in range(self.len / itemsize): # <<<<<<<<<<<<<< - * p[i] = Py_None - * Py_INCREF(Py_None) - */ - if (unlikely(__pyx_v_itemsize == 0)) { - PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero"); - __PYX_ERR(2, 180, __pyx_L1_error) - } - else if (sizeof(Py_ssize_t) == sizeof(long) && (!(((Py_ssize_t)-1) > 0)) && unlikely(__pyx_v_itemsize == (Py_ssize_t)-1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_self->len))) { - PyErr_SetString(PyExc_OverflowError, "value too large to perform division"); - __PYX_ERR(2, 180, __pyx_L1_error) - } - __pyx_t_1 = __Pyx_div_Py_ssize_t(__pyx_v_self->len, __pyx_v_itemsize); - __pyx_t_9 = __pyx_t_1; - for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_9; __pyx_t_11+=1) { - __pyx_v_i = __pyx_t_11; - - /* "View.MemoryView":181 - * p = self.data - * for i in range(self.len / itemsize): - * p[i] = Py_None # <<<<<<<<<<<<<< - * Py_INCREF(Py_None) - * - */ - (__pyx_v_p[__pyx_v_i]) = Py_None; - - /* "View.MemoryView":182 - * for i in range(self.len / itemsize): - * p[i] = Py_None - * Py_INCREF(Py_None) # <<<<<<<<<<<<<< - * - * @cname('getbuffer') - */ - Py_INCREF(Py_None); - } - - /* "View.MemoryView":178 - * raise MemoryError("unable to allocate array data.") - * - * if self.dtype_is_object: # <<<<<<<<<<<<<< - * p = self.data - * for i in range(self.len / itemsize): - */ - } - - /* "View.MemoryView":171 - * self.free_data = allocate_buffer - * self.dtype_is_object = format == b'O' - * if allocate_buffer: # <<<<<<<<<<<<<< - * - * - */ - } - - /* "View.MemoryView":122 - * cdef bint dtype_is_object - * - * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, # <<<<<<<<<<<<<< - * mode="c", bint allocate_buffer=True): - * - */ - - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_AddTraceback("View.MemoryView.array.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_format); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":185 - * - * @cname('getbuffer') - * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<< - * cdef int bufmode = -1 - * if self.mode == u"c": - */ - -/* Python wrapper */ -static CYTHON_UNUSED int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ -static CYTHON_UNUSED int __pyx_array_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_array___pyx_pf_15View_dot_MemoryView_5array_2__getbuffer__(((struct __pyx_array_obj *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_2__getbuffer__(struct __pyx_array_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { - int __pyx_v_bufmode; - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - char *__pyx_t_4; - Py_ssize_t __pyx_t_5; - int __pyx_t_6; - Py_ssize_t *__pyx_t_7; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - 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); - - /* "View.MemoryView":186 - * @cname('getbuffer') - * def __getbuffer__(self, Py_buffer *info, int flags): - * cdef int bufmode = -1 # <<<<<<<<<<<<<< - * if self.mode == u"c": - * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - */ - __pyx_v_bufmode = -1; - - /* "View.MemoryView":187 - * def __getbuffer__(self, Py_buffer *info, int flags): - * cdef int bufmode = -1 - * if self.mode == u"c": # <<<<<<<<<<<<<< - * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - * elif self.mode == u"fortran": - */ - __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_self->mode, __pyx_n_u_c, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(2, 187, __pyx_L1_error) - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":188 - * cdef int bufmode = -1 - * if self.mode == u"c": - * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS # <<<<<<<<<<<<<< - * elif self.mode == u"fortran": - * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - */ - __pyx_v_bufmode = (PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS); - - /* "View.MemoryView":187 - * def __getbuffer__(self, Py_buffer *info, int flags): - * cdef int bufmode = -1 - * if self.mode == u"c": # <<<<<<<<<<<<<< - * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - * elif self.mode == u"fortran": - */ - goto __pyx_L3; - } - - /* "View.MemoryView":189 - * if self.mode == u"c": - * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - * elif self.mode == u"fortran": # <<<<<<<<<<<<<< - * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - * if not (flags & bufmode): - */ - __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_self->mode, __pyx_n_u_fortran, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(2, 189, __pyx_L1_error) - __pyx_t_1 = (__pyx_t_2 != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":190 - * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - * elif self.mode == u"fortran": - * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS # <<<<<<<<<<<<<< - * if not (flags & bufmode): - * raise ValueError("Can only create a buffer that is contiguous in memory.") - */ - __pyx_v_bufmode = (PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS); - - /* "View.MemoryView":189 - * if self.mode == u"c": - * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - * elif self.mode == u"fortran": # <<<<<<<<<<<<<< - * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - * if not (flags & bufmode): - */ - } - __pyx_L3:; - - /* "View.MemoryView":191 - * elif self.mode == u"fortran": - * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - * if not (flags & bufmode): # <<<<<<<<<<<<<< - * raise ValueError("Can only create a buffer that is contiguous in memory.") - * info.buf = self.data - */ - __pyx_t_1 = ((!((__pyx_v_flags & __pyx_v_bufmode) != 0)) != 0); - if (unlikely(__pyx_t_1)) { - - /* "View.MemoryView":192 - * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - * if not (flags & bufmode): - * raise ValueError("Can only create a buffer that is contiguous in memory.") # <<<<<<<<<<<<<< - * info.buf = self.data - * info.len = self.len - */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 192, __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, 192, __pyx_L1_error) - - /* "View.MemoryView":191 - * elif self.mode == u"fortran": - * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - * if not (flags & bufmode): # <<<<<<<<<<<<<< - * raise ValueError("Can only create a buffer that is contiguous in memory.") - * info.buf = self.data - */ - } - - /* "View.MemoryView":193 - * if not (flags & bufmode): - * raise ValueError("Can only create a buffer that is contiguous in memory.") - * info.buf = self.data # <<<<<<<<<<<<<< - * info.len = self.len - * info.ndim = self.ndim - */ - __pyx_t_4 = __pyx_v_self->data; - __pyx_v_info->buf = __pyx_t_4; - - /* "View.MemoryView":194 - * raise ValueError("Can only create a buffer that is contiguous in memory.") - * info.buf = self.data - * info.len = self.len # <<<<<<<<<<<<<< - * info.ndim = self.ndim - * info.shape = self._shape - */ - __pyx_t_5 = __pyx_v_self->len; - __pyx_v_info->len = __pyx_t_5; - - /* "View.MemoryView":195 - * info.buf = self.data - * info.len = self.len - * info.ndim = self.ndim # <<<<<<<<<<<<<< - * info.shape = self._shape - * info.strides = self._strides - */ - __pyx_t_6 = __pyx_v_self->ndim; - __pyx_v_info->ndim = __pyx_t_6; - - /* "View.MemoryView":196 - * info.len = self.len - * info.ndim = self.ndim - * info.shape = self._shape # <<<<<<<<<<<<<< - * info.strides = self._strides - * info.suboffsets = NULL - */ - __pyx_t_7 = __pyx_v_self->_shape; - __pyx_v_info->shape = __pyx_t_7; - - /* "View.MemoryView":197 - * info.ndim = self.ndim - * info.shape = self._shape - * info.strides = self._strides # <<<<<<<<<<<<<< - * info.suboffsets = NULL - * info.itemsize = self.itemsize - */ - __pyx_t_7 = __pyx_v_self->_strides; - __pyx_v_info->strides = __pyx_t_7; - - /* "View.MemoryView":198 - * info.shape = self._shape - * info.strides = self._strides - * info.suboffsets = NULL # <<<<<<<<<<<<<< - * info.itemsize = self.itemsize - * info.readonly = 0 - */ - __pyx_v_info->suboffsets = NULL; - - /* "View.MemoryView":199 - * info.strides = self._strides - * info.suboffsets = NULL - * info.itemsize = self.itemsize # <<<<<<<<<<<<<< - * info.readonly = 0 - * - */ - __pyx_t_5 = __pyx_v_self->itemsize; - __pyx_v_info->itemsize = __pyx_t_5; - - /* "View.MemoryView":200 - * info.suboffsets = NULL - * info.itemsize = self.itemsize - * info.readonly = 0 # <<<<<<<<<<<<<< - * - * if flags & PyBUF_FORMAT: - */ - __pyx_v_info->readonly = 0; - - /* "View.MemoryView":202 - * info.readonly = 0 - * - * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< - * info.format = self.format - * else: - */ - __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":203 - * - * if flags & PyBUF_FORMAT: - * info.format = self.format # <<<<<<<<<<<<<< - * else: - * info.format = NULL - */ - __pyx_t_4 = __pyx_v_self->format; - __pyx_v_info->format = __pyx_t_4; - - /* "View.MemoryView":202 - * info.readonly = 0 - * - * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< - * info.format = self.format - * else: - */ - goto __pyx_L5; - } - - /* "View.MemoryView":205 - * info.format = self.format - * else: - * info.format = NULL # <<<<<<<<<<<<<< - * - * info.obj = self - */ - /*else*/ { - __pyx_v_info->format = NULL; - } - __pyx_L5:; - - /* "View.MemoryView":207 - * info.format = NULL - * - * info.obj = self # <<<<<<<<<<<<<< - * - * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)") - */ - __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); - - /* "View.MemoryView":185 - * - * @cname('getbuffer') - * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<< - * cdef int bufmode = -1 - * if self.mode == u"c": - */ - - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("View.MemoryView.array.__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_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":211 - * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)") - * - * def __dealloc__(array self): # <<<<<<<<<<<<<< - * if self.callback_free_data != NULL: - * self.callback_free_data(self.data) - */ - -/* Python wrapper */ -static void __pyx_array___dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_array___dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_array___pyx_pf_15View_dot_MemoryView_5array_4__dealloc__(((struct __pyx_array_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); -} - -static void __pyx_array___pyx_pf_15View_dot_MemoryView_5array_4__dealloc__(struct __pyx_array_obj *__pyx_v_self) { - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("__dealloc__", 0); - - /* "View.MemoryView":212 - * - * def __dealloc__(array self): - * if self.callback_free_data != NULL: # <<<<<<<<<<<<<< - * self.callback_free_data(self.data) - * elif self.free_data: - */ - __pyx_t_1 = ((__pyx_v_self->callback_free_data != NULL) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":213 - * def __dealloc__(array self): - * if self.callback_free_data != NULL: - * self.callback_free_data(self.data) # <<<<<<<<<<<<<< - * elif self.free_data: - * if self.dtype_is_object: - */ - __pyx_v_self->callback_free_data(__pyx_v_self->data); - - /* "View.MemoryView":212 - * - * def __dealloc__(array self): - * if self.callback_free_data != NULL: # <<<<<<<<<<<<<< - * self.callback_free_data(self.data) - * elif self.free_data: - */ - goto __pyx_L3; - } - - /* "View.MemoryView":214 - * if self.callback_free_data != NULL: - * self.callback_free_data(self.data) - * elif self.free_data: # <<<<<<<<<<<<<< - * if self.dtype_is_object: - * refcount_objects_in_slice(self.data, self._shape, - */ - __pyx_t_1 = (__pyx_v_self->free_data != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":215 - * self.callback_free_data(self.data) - * elif self.free_data: - * if self.dtype_is_object: # <<<<<<<<<<<<<< - * refcount_objects_in_slice(self.data, self._shape, - * self._strides, self.ndim, False) - */ - __pyx_t_1 = (__pyx_v_self->dtype_is_object != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":216 - * elif self.free_data: - * if self.dtype_is_object: - * refcount_objects_in_slice(self.data, self._shape, # <<<<<<<<<<<<<< - * self._strides, self.ndim, False) - * free(self.data) - */ - __pyx_memoryview_refcount_objects_in_slice(__pyx_v_self->data, __pyx_v_self->_shape, __pyx_v_self->_strides, __pyx_v_self->ndim, 0); - - /* "View.MemoryView":215 - * self.callback_free_data(self.data) - * elif self.free_data: - * if self.dtype_is_object: # <<<<<<<<<<<<<< - * refcount_objects_in_slice(self.data, self._shape, - * self._strides, self.ndim, False) - */ - } - - /* "View.MemoryView":218 - * refcount_objects_in_slice(self.data, self._shape, - * self._strides, self.ndim, False) - * free(self.data) # <<<<<<<<<<<<<< - * PyObject_Free(self._shape) - * - */ - free(__pyx_v_self->data); - - /* "View.MemoryView":214 - * if self.callback_free_data != NULL: - * self.callback_free_data(self.data) - * elif self.free_data: # <<<<<<<<<<<<<< - * if self.dtype_is_object: - * refcount_objects_in_slice(self.data, self._shape, - */ - } - __pyx_L3:; - - /* "View.MemoryView":219 - * self._strides, self.ndim, False) - * free(self.data) - * PyObject_Free(self._shape) # <<<<<<<<<<<<<< - * - * @property - */ - PyObject_Free(__pyx_v_self->_shape); - - /* "View.MemoryView":211 - * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)") - * - * def __dealloc__(array self): # <<<<<<<<<<<<<< - * if self.callback_free_data != NULL: - * self.callback_free_data(self.data) - */ - - /* function exit code */ - __Pyx_RefNannyFinishContext(); -} - -/* "View.MemoryView":222 - * - * @property - * def memview(self): # <<<<<<<<<<<<<< - * return self.get_memview() - * - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_5array_7memview_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_15View_dot_MemoryView_5array_7memview_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_15View_dot_MemoryView_5array_7memview___get__(((struct __pyx_array_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15View_dot_MemoryView_5array_7memview___get__(struct __pyx_array_obj *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); - - /* "View.MemoryView":223 - * @property - * def memview(self): - * return self.get_memview() # <<<<<<<<<<<<<< - * - * @cname('get_memview') - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((struct __pyx_vtabstruct_array *)__pyx_v_self->__pyx_vtab)->get_memview(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 223, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "View.MemoryView":222 - * - * @property - * def memview(self): # <<<<<<<<<<<<<< - * return self.get_memview() - * - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("View.MemoryView.array.memview.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":226 - * - * @cname('get_memview') - * cdef get_memview(self): # <<<<<<<<<<<<<< - * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE - * return memoryview(self, flags, self.dtype_is_object) - */ - -static PyObject *__pyx_array_get_memview(struct __pyx_array_obj *__pyx_v_self) { - int __pyx_v_flags; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("get_memview", 0); - - /* "View.MemoryView":227 - * @cname('get_memview') - * cdef get_memview(self): - * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE # <<<<<<<<<<<<<< - * return memoryview(self, flags, self.dtype_is_object) - * - */ - __pyx_v_flags = ((PyBUF_ANY_CONTIGUOUS | PyBUF_FORMAT) | PyBUF_WRITABLE); - - /* "View.MemoryView":228 - * cdef get_memview(self): - * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE - * return memoryview(self, flags, self.dtype_is_object) # <<<<<<<<<<<<<< - * - * def __len__(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_flags); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 228, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_self->dtype_is_object); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 228, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 228, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); - __pyx_t_1 = 0; - __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 228, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - - /* "View.MemoryView":226 - * - * @cname('get_memview') - * cdef get_memview(self): # <<<<<<<<<<<<<< - * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE - * return memoryview(self, flags, self.dtype_is_object) - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("View.MemoryView.array.get_memview", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":230 - * return memoryview(self, flags, self.dtype_is_object) - * - * def __len__(self): # <<<<<<<<<<<<<< - * return self._shape[0] - * - */ - -/* Python wrapper */ -static Py_ssize_t __pyx_array___len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_array___len__(PyObject *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_6__len__(((struct __pyx_array_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static Py_ssize_t __pyx_array___pyx_pf_15View_dot_MemoryView_5array_6__len__(struct __pyx_array_obj *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__", 0); - - /* "View.MemoryView":231 - * - * def __len__(self): - * return self._shape[0] # <<<<<<<<<<<<<< - * - * def __getattr__(self, attr): - */ - __pyx_r = (__pyx_v_self->_shape[0]); - goto __pyx_L0; - - /* "View.MemoryView":230 - * return memoryview(self, flags, self.dtype_is_object) - * - * def __len__(self): # <<<<<<<<<<<<<< - * return self._shape[0] - * - */ - - /* function exit code */ - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":233 - * return self._shape[0] - * - * def __getattr__(self, attr): # <<<<<<<<<<<<<< - * return getattr(self.memview, attr) - * - */ - -/* Python wrapper */ -static PyObject *__pyx_array___getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_attr); /*proto*/ -static PyObject *__pyx_array___getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_attr) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getattr__ (wrapper)", 0); - __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_8__getattr__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_attr)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_8__getattr__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_attr) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__getattr__", 0); - - /* "View.MemoryView":234 - * - * def __getattr__(self, attr): - * return getattr(self.memview, attr) # <<<<<<<<<<<<<< - * - * def __getitem__(self, item): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 234, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_GetAttr(__pyx_t_1, __pyx_v_attr); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 234, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - - /* "View.MemoryView":233 - * return self._shape[0] - * - * def __getattr__(self, attr): # <<<<<<<<<<<<<< - * return getattr(self.memview, attr) - * - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("View.MemoryView.array.__getattr__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":236 - * return getattr(self.memview, attr) - * - * def __getitem__(self, item): # <<<<<<<<<<<<<< - * return self.memview[item] - * - */ - -/* Python wrapper */ -static PyObject *__pyx_array___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item); /*proto*/ -static PyObject *__pyx_array___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); - __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_10__getitem__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_item)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_10__getitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__getitem__", 0); - - /* "View.MemoryView":237 - * - * def __getitem__(self, item): - * return self.memview[item] # <<<<<<<<<<<<<< - * - * def __setitem__(self, item, value): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 237, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_item); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 237, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - - /* "View.MemoryView":236 - * return getattr(self.memview, attr) - * - * def __getitem__(self, item): # <<<<<<<<<<<<<< - * return self.memview[item] - * - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("View.MemoryView.array.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":239 - * return self.memview[item] - * - * def __setitem__(self, item, value): # <<<<<<<<<<<<<< - * self.memview[item] = value - * - */ - -/* Python wrapper */ -static int __pyx_array___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_array___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); - __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_12__setitem__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_item), ((PyObject *)__pyx_v_value)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_12__setitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__setitem__", 0); - - /* "View.MemoryView":240 - * - * def __setitem__(self, item, value): - * self.memview[item] = value # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 240, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (unlikely(PyObject_SetItem(__pyx_t_1, __pyx_v_item, __pyx_v_value) < 0)) __PYX_ERR(2, 240, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "View.MemoryView":239 - * return self.memview[item] - * - * def __setitem__(self, item, value): # <<<<<<<<<<<<<< - * self.memview[item] = value - * - */ - - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("View.MemoryView.array.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "(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___pyx_array_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw___pyx_array_1__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___pyx_array___reduce_cython__(((struct __pyx_array_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf___pyx_array___reduce_cython__(CYTHON_UNUSED struct __pyx_array_obj *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __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__11, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 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(2, 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("View.MemoryView.array.__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___pyx_array_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static PyObject *__pyx_pw___pyx_array_3__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___pyx_array_2__setstate_cython__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf___pyx_array_2__setstate_cython__(CYTHON_UNUSED struct __pyx_array_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __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__12, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 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(2, 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("View.MemoryView.array.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":244 - * - * @cname("__pyx_array_new") - * cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format, # <<<<<<<<<<<<<< - * char *mode, char *buf): - * cdef array result - */ - -static struct __pyx_array_obj *__pyx_array_new(PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, char *__pyx_v_format, char *__pyx_v_mode, char *__pyx_v_buf) { - struct __pyx_array_obj *__pyx_v_result = 0; - struct __pyx_array_obj *__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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("array_cwrapper", 0); - - /* "View.MemoryView":248 - * cdef array result - * - * if buf == NULL: # <<<<<<<<<<<<<< - * result = array(shape, itemsize, format, mode.decode('ASCII')) - * else: - */ - __pyx_t_1 = ((__pyx_v_buf == NULL) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":249 - * - * if buf == NULL: - * result = array(shape, itemsize, format, mode.decode('ASCII')) # <<<<<<<<<<<<<< - * else: - * result = array(shape, itemsize, format, mode.decode('ASCII'), - */ - __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_itemsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 249, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 249, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_decode_c_string(__pyx_v_mode, 0, strlen(__pyx_v_mode), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 249, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 249, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(__pyx_v_shape); - __Pyx_GIVEREF(__pyx_v_shape); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_shape); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_4); - __pyx_t_2 = 0; - __pyx_t_3 = 0; - __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_array_type), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 249, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_result = ((struct __pyx_array_obj *)__pyx_t_4); - __pyx_t_4 = 0; - - /* "View.MemoryView":248 - * cdef array result - * - * if buf == NULL: # <<<<<<<<<<<<<< - * result = array(shape, itemsize, format, mode.decode('ASCII')) - * else: - */ - goto __pyx_L3; - } - - /* "View.MemoryView":251 - * result = array(shape, itemsize, format, mode.decode('ASCII')) - * else: - * result = array(shape, itemsize, format, mode.decode('ASCII'), # <<<<<<<<<<<<<< - * allocate_buffer=False) - * result.data = buf - */ - /*else*/ { - __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_itemsize); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 251, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyBytes_FromString(__pyx_v_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 251, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __Pyx_decode_c_string(__pyx_v_mode, 0, strlen(__pyx_v_mode), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 251, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 251, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_shape); - __Pyx_GIVEREF(__pyx_v_shape); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_shape); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_3); - __pyx_t_4 = 0; - __pyx_t_5 = 0; - __pyx_t_3 = 0; - - /* "View.MemoryView":252 - * else: - * result = array(shape, itemsize, format, mode.decode('ASCII'), - * allocate_buffer=False) # <<<<<<<<<<<<<< - * result.data = buf - * - */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 252, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_allocate_buffer, Py_False) < 0) __PYX_ERR(2, 252, __pyx_L1_error) - - /* "View.MemoryView":251 - * result = array(shape, itemsize, format, mode.decode('ASCII')) - * else: - * result = array(shape, itemsize, format, mode.decode('ASCII'), # <<<<<<<<<<<<<< - * allocate_buffer=False) - * result.data = buf - */ - __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_array_type), __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 251, __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_result = ((struct __pyx_array_obj *)__pyx_t_5); - __pyx_t_5 = 0; - - /* "View.MemoryView":253 - * result = array(shape, itemsize, format, mode.decode('ASCII'), - * allocate_buffer=False) - * result.data = buf # <<<<<<<<<<<<<< - * - * return result - */ - __pyx_v_result->data = __pyx_v_buf; - } - __pyx_L3:; - - /* "View.MemoryView":255 - * result.data = buf - * - * return result # <<<<<<<<<<<<<< - * - * - */ - __Pyx_XDECREF(((PyObject *)__pyx_r)); - __Pyx_INCREF(((PyObject *)__pyx_v_result)); - __pyx_r = __pyx_v_result; - goto __pyx_L0; - - /* "View.MemoryView":244 - * - * @cname("__pyx_array_new") - * cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format, # <<<<<<<<<<<<<< - * char *mode, char *buf): - * cdef array result - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("View.MemoryView.array_cwrapper", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_result); - __Pyx_XGIVEREF((PyObject *)__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":281 - * cdef class Enum(object): - * cdef object name - * def __init__(self, name): # <<<<<<<<<<<<<< - * self.name = name - * def __repr__(self): - */ - -/* Python wrapper */ -static int __pyx_MemviewEnum___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_MemviewEnum___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_name = 0; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_name,0}; - PyObject* values[1] = {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 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_name)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(2, 281, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - } - __pyx_v_name = values[0]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 281, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("View.MemoryView.Enum.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum___init__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self), __pyx_v_name); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum___init__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v_name) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__init__", 0); - - /* "View.MemoryView":282 - * cdef object name - * def __init__(self, name): - * self.name = name # <<<<<<<<<<<<<< - * def __repr__(self): - * return self.name - */ - __Pyx_INCREF(__pyx_v_name); - __Pyx_GIVEREF(__pyx_v_name); - __Pyx_GOTREF(__pyx_v_self->name); - __Pyx_DECREF(__pyx_v_self->name); - __pyx_v_self->name = __pyx_v_name; - - /* "View.MemoryView":281 - * cdef class Enum(object): - * cdef object name - * def __init__(self, name): # <<<<<<<<<<<<<< - * self.name = name - * def __repr__(self): - */ - - /* function exit code */ - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":283 - * def __init__(self, name): - * self.name = name - * def __repr__(self): # <<<<<<<<<<<<<< - * return self.name - * - */ - -/* Python wrapper */ -static PyObject *__pyx_MemviewEnum___repr__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_MemviewEnum___repr__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0); - __pyx_r = __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum_2__repr__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum_2__repr__(struct __pyx_MemviewEnum_obj *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__repr__", 0); - - /* "View.MemoryView":284 - * self.name = name - * def __repr__(self): - * return self.name # <<<<<<<<<<<<<< - * - * cdef generic = Enum("") - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self->name); - __pyx_r = __pyx_v_self->name; - goto __pyx_L0; - - /* "View.MemoryView":283 - * def __init__(self, name): - * self.name = name - * def __repr__(self): # <<<<<<<<<<<<<< - * return self.name - * - */ - - /* function exit code */ - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "(tree fragment)":1 - * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * cdef tuple state - * cdef object _dict - */ - -/* Python wrapper */ -static PyObject *__pyx_pw___pyx_MemviewEnum_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw___pyx_MemviewEnum_1__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___pyx_MemviewEnum___reduce_cython__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf___pyx_MemviewEnum___reduce_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self) { - PyObject *__pyx_v_state = 0; - PyObject *__pyx_v__dict = 0; - int __pyx_v_use_setstate; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__reduce_cython__", 0); - - /* "(tree fragment)":5 - * cdef object _dict - * cdef bint use_setstate - * state = (self.name,) # <<<<<<<<<<<<<< - * _dict = getattr(self, '__dict__', None) - * if _dict is not None: - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 5, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_self->name); - __Pyx_GIVEREF(__pyx_v_self->name); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->name); - __pyx_v_state = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; - - /* "(tree fragment)":6 - * cdef bint use_setstate - * state = (self.name,) - * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< - * if _dict is not None: - * state += (_dict,) - */ - __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 6, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v__dict = __pyx_t_1; - __pyx_t_1 = 0; - - /* "(tree fragment)":7 - * state = (self.name,) - * _dict = getattr(self, '__dict__', None) - * if _dict is not None: # <<<<<<<<<<<<<< - * state += (_dict,) - * use_setstate = True - */ - __pyx_t_2 = (__pyx_v__dict != Py_None); - __pyx_t_3 = (__pyx_t_2 != 0); - if (__pyx_t_3) { - - /* "(tree fragment)":8 - * _dict = getattr(self, '__dict__', None) - * if _dict is not None: - * state += (_dict,) # <<<<<<<<<<<<<< - * use_setstate = True - * else: - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 8, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v__dict); - __Pyx_GIVEREF(__pyx_v__dict); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict); - __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 8, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4)); - __pyx_t_4 = 0; - - /* "(tree fragment)":9 - * if _dict is not None: - * state += (_dict,) - * use_setstate = True # <<<<<<<<<<<<<< - * else: - * use_setstate = self.name is not None - */ - __pyx_v_use_setstate = 1; - - /* "(tree fragment)":7 - * state = (self.name,) - * _dict = getattr(self, '__dict__', None) - * if _dict is not None: # <<<<<<<<<<<<<< - * state += (_dict,) - * use_setstate = True - */ - goto __pyx_L3; - } - - /* "(tree fragment)":11 - * use_setstate = True - * else: - * use_setstate = self.name is not None # <<<<<<<<<<<<<< - * if use_setstate: - * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state - */ - /*else*/ { - __pyx_t_3 = (__pyx_v_self->name != Py_None); - __pyx_v_use_setstate = __pyx_t_3; - } - __pyx_L3:; - - /* "(tree fragment)":12 - * else: - * use_setstate = self.name is not None - * if use_setstate: # <<<<<<<<<<<<<< - * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state - * else: - */ - __pyx_t_3 = (__pyx_v_use_setstate != 0); - if (__pyx_t_3) { - - /* "(tree fragment)":13 - * use_setstate = self.name is not None - * if use_setstate: - * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state # <<<<<<<<<<<<<< - * else: - * return __pyx_unpickle_Enum, (type(self), 0xb068931, state) - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pyx_unpickle_Enum); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 13, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 13, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - __Pyx_INCREF(__pyx_int_184977713); - __Pyx_GIVEREF(__pyx_int_184977713); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_184977713); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None); - __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 13, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); - __Pyx_INCREF(__pyx_v_state); - __Pyx_GIVEREF(__pyx_v_state); - PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_state); - __pyx_t_4 = 0; - __pyx_t_1 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; - goto __pyx_L0; - - /* "(tree fragment)":12 - * else: - * use_setstate = self.name is not None - * if use_setstate: # <<<<<<<<<<<<<< - * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state - * else: - */ - } - - /* "(tree fragment)":15 - * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state - * else: - * return __pyx_unpickle_Enum, (type(self), 0xb068931, state) # <<<<<<<<<<<<<< - * def __setstate_cython__(self, __pyx_state): - * __pyx_unpickle_Enum__set_state(self, __pyx_state) - */ - /*else*/ { - __Pyx_XDECREF(__pyx_r); - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_pyx_unpickle_Enum); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 15, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 15, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - __Pyx_INCREF(__pyx_int_184977713); - __Pyx_GIVEREF(__pyx_int_184977713); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_184977713); - __Pyx_INCREF(__pyx_v_state); - __Pyx_GIVEREF(__pyx_v_state); - PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 15, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1); - __pyx_t_5 = 0; - __pyx_t_1 = 0; - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L0; - } - - /* "(tree fragment)":1 - * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * cdef tuple state - * cdef object _dict - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("View.MemoryView.Enum.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_state); - __Pyx_XDECREF(__pyx_v__dict); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "(tree fragment)":16 - * else: - * return __pyx_unpickle_Enum, (type(self), 0xb068931, state) - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * __pyx_unpickle_Enum__set_state(self, __pyx_state) - */ - -/* Python wrapper */ -static PyObject *__pyx_pw___pyx_MemviewEnum_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static PyObject *__pyx_pw___pyx_MemviewEnum_3__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___pyx_MemviewEnum_2__setstate_cython__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf___pyx_MemviewEnum_2__setstate_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v___pyx_state) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__setstate_cython__", 0); - - /* "(tree fragment)":17 - * return __pyx_unpickle_Enum, (type(self), 0xb068931, state) - * def __setstate_cython__(self, __pyx_state): - * __pyx_unpickle_Enum__set_state(self, __pyx_state) # <<<<<<<<<<<<<< - */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 17, __pyx_L1_error) - __pyx_t_1 = __pyx_unpickle_Enum__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 17, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "(tree fragment)":16 - * else: - * return __pyx_unpickle_Enum, (type(self), 0xb068931, state) - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * __pyx_unpickle_Enum__set_state(self, __pyx_state) - */ - - /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("View.MemoryView.Enum.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":298 - * - * @cname('__pyx_align_pointer') - * cdef void *align_pointer(void *memory, size_t alignment) nogil: # <<<<<<<<<<<<<< - * "Align pointer memory on a given boundary" - * cdef Py_intptr_t aligned_p = memory - */ - -static void *__pyx_align_pointer(void *__pyx_v_memory, size_t __pyx_v_alignment) { - Py_intptr_t __pyx_v_aligned_p; - size_t __pyx_v_offset; - void *__pyx_r; - int __pyx_t_1; - - /* "View.MemoryView":300 - * cdef void *align_pointer(void *memory, size_t alignment) nogil: - * "Align pointer memory on a given boundary" - * cdef Py_intptr_t aligned_p = memory # <<<<<<<<<<<<<< - * cdef size_t offset - * - */ - __pyx_v_aligned_p = ((Py_intptr_t)__pyx_v_memory); - - /* "View.MemoryView":304 - * - * with cython.cdivision(True): - * offset = aligned_p % alignment # <<<<<<<<<<<<<< - * - * if offset > 0: - */ - __pyx_v_offset = (__pyx_v_aligned_p % __pyx_v_alignment); - - /* "View.MemoryView":306 - * offset = aligned_p % alignment - * - * if offset > 0: # <<<<<<<<<<<<<< - * aligned_p += alignment - offset - * - */ - __pyx_t_1 = ((__pyx_v_offset > 0) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":307 - * - * if offset > 0: - * aligned_p += alignment - offset # <<<<<<<<<<<<<< - * - * return aligned_p - */ - __pyx_v_aligned_p = (__pyx_v_aligned_p + (__pyx_v_alignment - __pyx_v_offset)); - - /* "View.MemoryView":306 - * offset = aligned_p % alignment - * - * if offset > 0: # <<<<<<<<<<<<<< - * aligned_p += alignment - offset - * - */ - } - - /* "View.MemoryView":309 - * aligned_p += alignment - offset - * - * return aligned_p # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = ((void *)__pyx_v_aligned_p); - goto __pyx_L0; - - /* "View.MemoryView":298 - * - * @cname('__pyx_align_pointer') - * cdef void *align_pointer(void *memory, size_t alignment) nogil: # <<<<<<<<<<<<<< - * "Align pointer memory on a given boundary" - * cdef Py_intptr_t aligned_p = memory - */ - - /* function exit code */ - __pyx_L0:; - return __pyx_r; -} - -/* "View.MemoryView":345 - * cdef __Pyx_TypeInfo *typeinfo - * - * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False): # <<<<<<<<<<<<<< - * self.obj = obj - * self.flags = flags - */ - -/* Python wrapper */ -static int __pyx_memoryview___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_memoryview___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_obj = 0; - int __pyx_v_flags; - int __pyx_v_dtype_is_object; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_obj,&__pyx_n_s_flags,&__pyx_n_s_dtype_is_object,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_obj)) != 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_flags)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, 1); __PYX_ERR(2, 345, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dtype_is_object); - if (value) { values[2] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(2, 345, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - 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_obj = values[0]; - __pyx_v_flags = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_flags == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 345, __pyx_L3_error) - if (values[2]) { - __pyx_v_dtype_is_object = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_dtype_is_object == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 345, __pyx_L3_error) - } else { - __pyx_v_dtype_is_object = ((int)0); - } - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 345, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("View.MemoryView.memoryview.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview___cinit__(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_obj, __pyx_v_flags, __pyx_v_dtype_is_object); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview___cinit__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj, int __pyx_v_flags, int __pyx_v_dtype_is_object) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "View.MemoryView":346 - * - * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False): - * self.obj = obj # <<<<<<<<<<<<<< - * self.flags = flags - * if type(self) is memoryview or obj is not None: - */ - __Pyx_INCREF(__pyx_v_obj); - __Pyx_GIVEREF(__pyx_v_obj); - __Pyx_GOTREF(__pyx_v_self->obj); - __Pyx_DECREF(__pyx_v_self->obj); - __pyx_v_self->obj = __pyx_v_obj; - - /* "View.MemoryView":347 - * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False): - * self.obj = obj - * self.flags = flags # <<<<<<<<<<<<<< - * if type(self) is memoryview or obj is not None: - * __Pyx_GetBuffer(obj, &self.view, flags) - */ - __pyx_v_self->flags = __pyx_v_flags; - - /* "View.MemoryView":348 - * self.obj = obj - * self.flags = flags - * if type(self) is memoryview or obj is not None: # <<<<<<<<<<<<<< - * __Pyx_GetBuffer(obj, &self.view, flags) - * if self.view.obj == NULL: - */ - __pyx_t_2 = (((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))) == ((PyObject *)__pyx_memoryview_type)); - __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 = (__pyx_v_obj != Py_None); - __pyx_t_2 = (__pyx_t_3 != 0); - __pyx_t_1 = __pyx_t_2; - __pyx_L4_bool_binop_done:; - if (__pyx_t_1) { - - /* "View.MemoryView":349 - * self.flags = flags - * if type(self) is memoryview or obj is not None: - * __Pyx_GetBuffer(obj, &self.view, flags) # <<<<<<<<<<<<<< - * if self.view.obj == NULL: - * (<__pyx_buffer *> &self.view).obj = Py_None - */ - __pyx_t_4 = __Pyx_GetBuffer(__pyx_v_obj, (&__pyx_v_self->view), __pyx_v_flags); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(2, 349, __pyx_L1_error) - - /* "View.MemoryView":350 - * if type(self) is memoryview or obj is not None: - * __Pyx_GetBuffer(obj, &self.view, flags) - * if self.view.obj == NULL: # <<<<<<<<<<<<<< - * (<__pyx_buffer *> &self.view).obj = Py_None - * Py_INCREF(Py_None) - */ - __pyx_t_1 = ((((PyObject *)__pyx_v_self->view.obj) == NULL) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":351 - * __Pyx_GetBuffer(obj, &self.view, flags) - * if self.view.obj == NULL: - * (<__pyx_buffer *> &self.view).obj = Py_None # <<<<<<<<<<<<<< - * Py_INCREF(Py_None) - * - */ - ((Py_buffer *)(&__pyx_v_self->view))->obj = Py_None; - - /* "View.MemoryView":352 - * if self.view.obj == NULL: - * (<__pyx_buffer *> &self.view).obj = Py_None - * Py_INCREF(Py_None) # <<<<<<<<<<<<<< - * - * global __pyx_memoryview_thread_locks_used - */ - Py_INCREF(Py_None); - - /* "View.MemoryView":350 - * if type(self) is memoryview or obj is not None: - * __Pyx_GetBuffer(obj, &self.view, flags) - * if self.view.obj == NULL: # <<<<<<<<<<<<<< - * (<__pyx_buffer *> &self.view).obj = Py_None - * Py_INCREF(Py_None) - */ - } - - /* "View.MemoryView":348 - * self.obj = obj - * self.flags = flags - * if type(self) is memoryview or obj is not None: # <<<<<<<<<<<<<< - * __Pyx_GetBuffer(obj, &self.view, flags) - * if self.view.obj == NULL: - */ - } - - /* "View.MemoryView":355 - * - * global __pyx_memoryview_thread_locks_used - * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED: # <<<<<<<<<<<<<< - * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] - * __pyx_memoryview_thread_locks_used += 1 - */ - __pyx_t_1 = ((__pyx_memoryview_thread_locks_used < 8) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":356 - * global __pyx_memoryview_thread_locks_used - * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED: - * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] # <<<<<<<<<<<<<< - * __pyx_memoryview_thread_locks_used += 1 - * if self.lock is NULL: - */ - __pyx_v_self->lock = (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]); - - /* "View.MemoryView":357 - * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED: - * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] - * __pyx_memoryview_thread_locks_used += 1 # <<<<<<<<<<<<<< - * if self.lock is NULL: - * self.lock = PyThread_allocate_lock() - */ - __pyx_memoryview_thread_locks_used = (__pyx_memoryview_thread_locks_used + 1); - - /* "View.MemoryView":355 - * - * global __pyx_memoryview_thread_locks_used - * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED: # <<<<<<<<<<<<<< - * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] - * __pyx_memoryview_thread_locks_used += 1 - */ - } - - /* "View.MemoryView":358 - * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] - * __pyx_memoryview_thread_locks_used += 1 - * if self.lock is NULL: # <<<<<<<<<<<<<< - * self.lock = PyThread_allocate_lock() - * if self.lock is NULL: - */ - __pyx_t_1 = ((__pyx_v_self->lock == NULL) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":359 - * __pyx_memoryview_thread_locks_used += 1 - * if self.lock is NULL: - * self.lock = PyThread_allocate_lock() # <<<<<<<<<<<<<< - * if self.lock is NULL: - * raise MemoryError - */ - __pyx_v_self->lock = PyThread_allocate_lock(); - - /* "View.MemoryView":360 - * if self.lock is NULL: - * self.lock = PyThread_allocate_lock() - * if self.lock is NULL: # <<<<<<<<<<<<<< - * raise MemoryError - * - */ - __pyx_t_1 = ((__pyx_v_self->lock == NULL) != 0); - if (unlikely(__pyx_t_1)) { - - /* "View.MemoryView":361 - * self.lock = PyThread_allocate_lock() - * if self.lock is NULL: - * raise MemoryError # <<<<<<<<<<<<<< - * - * if flags & PyBUF_FORMAT: - */ - PyErr_NoMemory(); __PYX_ERR(2, 361, __pyx_L1_error) - - /* "View.MemoryView":360 - * if self.lock is NULL: - * self.lock = PyThread_allocate_lock() - * if self.lock is NULL: # <<<<<<<<<<<<<< - * raise MemoryError - * - */ - } - - /* "View.MemoryView":358 - * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] - * __pyx_memoryview_thread_locks_used += 1 - * if self.lock is NULL: # <<<<<<<<<<<<<< - * self.lock = PyThread_allocate_lock() - * if self.lock is NULL: - */ - } - - /* "View.MemoryView":363 - * raise MemoryError - * - * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< - * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0') - * else: - */ - __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":364 - * - * if flags & PyBUF_FORMAT: - * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0') # <<<<<<<<<<<<<< - * else: - * self.dtype_is_object = dtype_is_object - */ - __pyx_t_2 = (((__pyx_v_self->view.format[0]) == 'O') != 0); - if (__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L11_bool_binop_done; - } - __pyx_t_2 = (((__pyx_v_self->view.format[1]) == '\x00') != 0); - __pyx_t_1 = __pyx_t_2; - __pyx_L11_bool_binop_done:; - __pyx_v_self->dtype_is_object = __pyx_t_1; - - /* "View.MemoryView":363 - * raise MemoryError - * - * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< - * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0') - * else: - */ - goto __pyx_L10; - } - - /* "View.MemoryView":366 - * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0') - * else: - * self.dtype_is_object = dtype_is_object # <<<<<<<<<<<<<< - * - * self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer( - */ - /*else*/ { - __pyx_v_self->dtype_is_object = __pyx_v_dtype_is_object; - } - __pyx_L10:; - - /* "View.MemoryView":368 - * self.dtype_is_object = dtype_is_object - * - * self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer( # <<<<<<<<<<<<<< - * &self.acquisition_count[0], sizeof(__pyx_atomic_int)) - * self.typeinfo = NULL - */ - __pyx_v_self->acquisition_count_aligned_p = ((__pyx_atomic_int *)__pyx_align_pointer(((void *)(&(__pyx_v_self->acquisition_count[0]))), (sizeof(__pyx_atomic_int)))); - - /* "View.MemoryView":370 - * self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer( - * &self.acquisition_count[0], sizeof(__pyx_atomic_int)) - * self.typeinfo = NULL # <<<<<<<<<<<<<< - * - * def __dealloc__(memoryview self): - */ - __pyx_v_self->typeinfo = NULL; - - /* "View.MemoryView":345 - * cdef __Pyx_TypeInfo *typeinfo - * - * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False): # <<<<<<<<<<<<<< - * self.obj = obj - * self.flags = flags - */ - - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("View.MemoryView.memoryview.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":372 - * self.typeinfo = NULL - * - * def __dealloc__(memoryview self): # <<<<<<<<<<<<<< - * if self.obj is not None: - * __Pyx_ReleaseBuffer(&self.view) - */ - -/* Python wrapper */ -static void __pyx_memoryview___dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_memoryview___dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_2__dealloc__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); -} - -static void __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_2__dealloc__(struct __pyx_memoryview_obj *__pyx_v_self) { - int __pyx_v_i; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - PyThread_type_lock __pyx_t_6; - PyThread_type_lock __pyx_t_7; - __Pyx_RefNannySetupContext("__dealloc__", 0); - - /* "View.MemoryView":373 - * - * def __dealloc__(memoryview self): - * if self.obj is not None: # <<<<<<<<<<<<<< - * __Pyx_ReleaseBuffer(&self.view) - * elif (<__pyx_buffer *> &self.view).obj == Py_None: - */ - __pyx_t_1 = (__pyx_v_self->obj != Py_None); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":374 - * def __dealloc__(memoryview self): - * if self.obj is not None: - * __Pyx_ReleaseBuffer(&self.view) # <<<<<<<<<<<<<< - * elif (<__pyx_buffer *> &self.view).obj == Py_None: - * - */ - __Pyx_ReleaseBuffer((&__pyx_v_self->view)); - - /* "View.MemoryView":373 - * - * def __dealloc__(memoryview self): - * if self.obj is not None: # <<<<<<<<<<<<<< - * __Pyx_ReleaseBuffer(&self.view) - * elif (<__pyx_buffer *> &self.view).obj == Py_None: - */ - goto __pyx_L3; - } - - /* "View.MemoryView":375 - * if self.obj is not None: - * __Pyx_ReleaseBuffer(&self.view) - * elif (<__pyx_buffer *> &self.view).obj == Py_None: # <<<<<<<<<<<<<< - * - * (<__pyx_buffer *> &self.view).obj = NULL - */ - __pyx_t_2 = ((((Py_buffer *)(&__pyx_v_self->view))->obj == Py_None) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":377 - * elif (<__pyx_buffer *> &self.view).obj == Py_None: - * - * (<__pyx_buffer *> &self.view).obj = NULL # <<<<<<<<<<<<<< - * Py_DECREF(Py_None) - * - */ - ((Py_buffer *)(&__pyx_v_self->view))->obj = NULL; - - /* "View.MemoryView":378 - * - * (<__pyx_buffer *> &self.view).obj = NULL - * Py_DECREF(Py_None) # <<<<<<<<<<<<<< - * - * cdef int i - */ - Py_DECREF(Py_None); - - /* "View.MemoryView":375 - * if self.obj is not None: - * __Pyx_ReleaseBuffer(&self.view) - * elif (<__pyx_buffer *> &self.view).obj == Py_None: # <<<<<<<<<<<<<< - * - * (<__pyx_buffer *> &self.view).obj = NULL - */ - } - __pyx_L3:; - - /* "View.MemoryView":382 - * cdef int i - * global __pyx_memoryview_thread_locks_used - * if self.lock != NULL: # <<<<<<<<<<<<<< - * for i in range(__pyx_memoryview_thread_locks_used): - * if __pyx_memoryview_thread_locks[i] is self.lock: - */ - __pyx_t_2 = ((__pyx_v_self->lock != NULL) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":383 - * global __pyx_memoryview_thread_locks_used - * if self.lock != NULL: - * for i in range(__pyx_memoryview_thread_locks_used): # <<<<<<<<<<<<<< - * if __pyx_memoryview_thread_locks[i] is self.lock: - * __pyx_memoryview_thread_locks_used -= 1 - */ - __pyx_t_3 = __pyx_memoryview_thread_locks_used; - __pyx_t_4 = __pyx_t_3; - for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { - __pyx_v_i = __pyx_t_5; - - /* "View.MemoryView":384 - * if self.lock != NULL: - * for i in range(__pyx_memoryview_thread_locks_used): - * if __pyx_memoryview_thread_locks[i] is self.lock: # <<<<<<<<<<<<<< - * __pyx_memoryview_thread_locks_used -= 1 - * if i != __pyx_memoryview_thread_locks_used: - */ - __pyx_t_2 = (((__pyx_memoryview_thread_locks[__pyx_v_i]) == __pyx_v_self->lock) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":385 - * for i in range(__pyx_memoryview_thread_locks_used): - * if __pyx_memoryview_thread_locks[i] is self.lock: - * __pyx_memoryview_thread_locks_used -= 1 # <<<<<<<<<<<<<< - * if i != __pyx_memoryview_thread_locks_used: - * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( - */ - __pyx_memoryview_thread_locks_used = (__pyx_memoryview_thread_locks_used - 1); - - /* "View.MemoryView":386 - * if __pyx_memoryview_thread_locks[i] is self.lock: - * __pyx_memoryview_thread_locks_used -= 1 - * if i != __pyx_memoryview_thread_locks_used: # <<<<<<<<<<<<<< - * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( - * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i]) - */ - __pyx_t_2 = ((__pyx_v_i != __pyx_memoryview_thread_locks_used) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":388 - * if i != __pyx_memoryview_thread_locks_used: - * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( - * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i]) # <<<<<<<<<<<<<< - * break - * else: - */ - __pyx_t_6 = (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]); - __pyx_t_7 = (__pyx_memoryview_thread_locks[__pyx_v_i]); - - /* "View.MemoryView":387 - * __pyx_memoryview_thread_locks_used -= 1 - * if i != __pyx_memoryview_thread_locks_used: - * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( # <<<<<<<<<<<<<< - * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i]) - * break - */ - (__pyx_memoryview_thread_locks[__pyx_v_i]) = __pyx_t_6; - (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]) = __pyx_t_7; - - /* "View.MemoryView":386 - * if __pyx_memoryview_thread_locks[i] is self.lock: - * __pyx_memoryview_thread_locks_used -= 1 - * if i != __pyx_memoryview_thread_locks_used: # <<<<<<<<<<<<<< - * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( - * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i]) - */ - } - - /* "View.MemoryView":389 - * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( - * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i]) - * break # <<<<<<<<<<<<<< - * else: - * PyThread_free_lock(self.lock) - */ - goto __pyx_L6_break; - - /* "View.MemoryView":384 - * if self.lock != NULL: - * for i in range(__pyx_memoryview_thread_locks_used): - * if __pyx_memoryview_thread_locks[i] is self.lock: # <<<<<<<<<<<<<< - * __pyx_memoryview_thread_locks_used -= 1 - * if i != __pyx_memoryview_thread_locks_used: - */ - } - } - /*else*/ { - - /* "View.MemoryView":391 - * break - * else: - * PyThread_free_lock(self.lock) # <<<<<<<<<<<<<< - * - * cdef char *get_item_pointer(memoryview self, object index) except NULL: - */ - PyThread_free_lock(__pyx_v_self->lock); - } - __pyx_L6_break:; - - /* "View.MemoryView":382 - * cdef int i - * global __pyx_memoryview_thread_locks_used - * if self.lock != NULL: # <<<<<<<<<<<<<< - * for i in range(__pyx_memoryview_thread_locks_used): - * if __pyx_memoryview_thread_locks[i] is self.lock: - */ - } - - /* "View.MemoryView":372 - * self.typeinfo = NULL - * - * def __dealloc__(memoryview self): # <<<<<<<<<<<<<< - * if self.obj is not None: - * __Pyx_ReleaseBuffer(&self.view) - */ - - /* function exit code */ - __Pyx_RefNannyFinishContext(); -} - -/* "View.MemoryView":393 - * PyThread_free_lock(self.lock) - * - * cdef char *get_item_pointer(memoryview self, object index) except NULL: # <<<<<<<<<<<<<< - * cdef Py_ssize_t dim - * cdef char *itemp = self.view.buf - */ - -static char *__pyx_memoryview_get_item_pointer(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index) { - Py_ssize_t __pyx_v_dim; - char *__pyx_v_itemp; - PyObject *__pyx_v_idx = NULL; - char *__pyx_r; - __Pyx_RefNannyDeclarations - Py_ssize_t __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - Py_ssize_t __pyx_t_3; - PyObject *(*__pyx_t_4)(PyObject *); - PyObject *__pyx_t_5 = NULL; - Py_ssize_t __pyx_t_6; - char *__pyx_t_7; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("get_item_pointer", 0); - - /* "View.MemoryView":395 - * cdef char *get_item_pointer(memoryview self, object index) except NULL: - * cdef Py_ssize_t dim - * cdef char *itemp = self.view.buf # <<<<<<<<<<<<<< - * - * for dim, idx in enumerate(index): - */ - __pyx_v_itemp = ((char *)__pyx_v_self->view.buf); - - /* "View.MemoryView":397 - * cdef char *itemp = self.view.buf - * - * for dim, idx in enumerate(index): # <<<<<<<<<<<<<< - * itemp = pybuffer_index(&self.view, itemp, idx, dim) - * - */ - __pyx_t_1 = 0; - if (likely(PyList_CheckExact(__pyx_v_index)) || PyTuple_CheckExact(__pyx_v_index)) { - __pyx_t_2 = __pyx_v_index; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; - __pyx_t_4 = NULL; - } else { - __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 397, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 397, __pyx_L1_error) - } - for (;;) { - if (likely(!__pyx_t_4)) { - if (likely(PyList_CheckExact(__pyx_t_2))) { - if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(2, 397, __pyx_L1_error) - #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 397, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - } else { - if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(2, 397, __pyx_L1_error) - #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 397, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - } - } else { - __pyx_t_5 = __pyx_t_4(__pyx_t_2); - 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(2, 397, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_5); - } - __Pyx_XDECREF_SET(__pyx_v_idx, __pyx_t_5); - __pyx_t_5 = 0; - __pyx_v_dim = __pyx_t_1; - __pyx_t_1 = (__pyx_t_1 + 1); - - /* "View.MemoryView":398 - * - * for dim, idx in enumerate(index): - * itemp = pybuffer_index(&self.view, itemp, idx, dim) # <<<<<<<<<<<<<< - * - * return itemp - */ - __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_v_idx); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 398, __pyx_L1_error) - __pyx_t_7 = __pyx_pybuffer_index((&__pyx_v_self->view), __pyx_v_itemp, __pyx_t_6, __pyx_v_dim); if (unlikely(__pyx_t_7 == ((char *)NULL))) __PYX_ERR(2, 398, __pyx_L1_error) - __pyx_v_itemp = __pyx_t_7; - - /* "View.MemoryView":397 - * cdef char *itemp = self.view.buf - * - * for dim, idx in enumerate(index): # <<<<<<<<<<<<<< - * itemp = pybuffer_index(&self.view, itemp, idx, dim) - * - */ - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "View.MemoryView":400 - * itemp = pybuffer_index(&self.view, itemp, idx, dim) - * - * return itemp # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = __pyx_v_itemp; - goto __pyx_L0; - - /* "View.MemoryView":393 - * PyThread_free_lock(self.lock) - * - * cdef char *get_item_pointer(memoryview self, object index) except NULL: # <<<<<<<<<<<<<< - * cdef Py_ssize_t dim - * cdef char *itemp = self.view.buf - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("View.MemoryView.memoryview.get_item_pointer", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_idx); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":403 - * - * - * def __getitem__(memoryview self, object index): # <<<<<<<<<<<<<< - * if index is Ellipsis: - * return self - */ - -/* Python wrapper */ -static PyObject *__pyx_memoryview___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index); /*proto*/ -static PyObject *__pyx_memoryview___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); - __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_4__getitem__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v_index)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_4__getitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index) { - PyObject *__pyx_v_have_slices = NULL; - PyObject *__pyx_v_indices = NULL; - char *__pyx_v_itemp; - 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; - char *__pyx_t_6; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__getitem__", 0); - - /* "View.MemoryView":404 - * - * def __getitem__(memoryview self, object index): - * if index is Ellipsis: # <<<<<<<<<<<<<< - * return self - * - */ - __pyx_t_1 = (__pyx_v_index == __pyx_builtin_Ellipsis); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":405 - * def __getitem__(memoryview self, object index): - * if index is Ellipsis: - * return self # <<<<<<<<<<<<<< - * - * have_slices, indices = _unellipsify(index, self.view.ndim) - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __pyx_r = ((PyObject *)__pyx_v_self); - goto __pyx_L0; - - /* "View.MemoryView":404 - * - * def __getitem__(memoryview self, object index): - * if index is Ellipsis: # <<<<<<<<<<<<<< - * return self - * - */ - } - - /* "View.MemoryView":407 - * return self - * - * have_slices, indices = _unellipsify(index, self.view.ndim) # <<<<<<<<<<<<<< - * - * cdef char *itemp - */ - __pyx_t_3 = _unellipsify(__pyx_v_index, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 407, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (likely(__pyx_t_3 != Py_None)) { - 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(2, 407, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_5); - #else - __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 407, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 407, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(2, 407, __pyx_L1_error) - } - __pyx_v_have_slices = __pyx_t_4; - __pyx_t_4 = 0; - __pyx_v_indices = __pyx_t_5; - __pyx_t_5 = 0; - - /* "View.MemoryView":410 - * - * cdef char *itemp - * if have_slices: # <<<<<<<<<<<<<< - * return memview_slice(self, indices) - * else: - */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(2, 410, __pyx_L1_error) - if (__pyx_t_2) { - - /* "View.MemoryView":411 - * cdef char *itemp - * if have_slices: - * return memview_slice(self, indices) # <<<<<<<<<<<<<< - * else: - * itemp = self.get_item_pointer(indices) - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = ((PyObject *)__pyx_memview_slice(__pyx_v_self, __pyx_v_indices)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 411, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - - /* "View.MemoryView":410 - * - * cdef char *itemp - * if have_slices: # <<<<<<<<<<<<<< - * return memview_slice(self, indices) - * else: - */ - } - - /* "View.MemoryView":413 - * return memview_slice(self, indices) - * else: - * itemp = self.get_item_pointer(indices) # <<<<<<<<<<<<<< - * return self.convert_item_to_object(itemp) - * - */ - /*else*/ { - __pyx_t_6 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->get_item_pointer(__pyx_v_self, __pyx_v_indices); if (unlikely(__pyx_t_6 == ((char *)NULL))) __PYX_ERR(2, 413, __pyx_L1_error) - __pyx_v_itemp = __pyx_t_6; - - /* "View.MemoryView":414 - * else: - * itemp = self.get_item_pointer(indices) - * return self.convert_item_to_object(itemp) # <<<<<<<<<<<<<< - * - * def __setitem__(memoryview self, object index, object value): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->convert_item_to_object(__pyx_v_self, __pyx_v_itemp); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 414, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - } - - /* "View.MemoryView":403 - * - * - * def __getitem__(memoryview self, object index): # <<<<<<<<<<<<<< - * if index is Ellipsis: - * return self - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("View.MemoryView.memoryview.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_have_slices); - __Pyx_XDECREF(__pyx_v_indices); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":416 - * return self.convert_item_to_object(itemp) - * - * def __setitem__(memoryview self, object index, object value): # <<<<<<<<<<<<<< - * if self.view.readonly: - * raise TypeError("Cannot assign to read-only memoryview") - */ - -/* Python wrapper */ -static int __pyx_memoryview___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_memoryview___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); - __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_6__setitem__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v_index), ((PyObject *)__pyx_v_value)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_6__setitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) { - PyObject *__pyx_v_have_slices = NULL; - PyObject *__pyx_v_obj = NULL; - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__setitem__", 0); - __Pyx_INCREF(__pyx_v_index); - - /* "View.MemoryView":417 - * - * def __setitem__(memoryview self, object index, object value): - * if self.view.readonly: # <<<<<<<<<<<<<< - * raise TypeError("Cannot assign to read-only memoryview") - * - */ - __pyx_t_1 = (__pyx_v_self->view.readonly != 0); - if (unlikely(__pyx_t_1)) { - - /* "View.MemoryView":418 - * def __setitem__(memoryview self, object index, object value): - * if self.view.readonly: - * raise TypeError("Cannot assign to read-only memoryview") # <<<<<<<<<<<<<< - * - * have_slices, index = _unellipsify(index, self.view.ndim) - */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 418, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(2, 418, __pyx_L1_error) - - /* "View.MemoryView":417 - * - * def __setitem__(memoryview self, object index, object value): - * if self.view.readonly: # <<<<<<<<<<<<<< - * raise TypeError("Cannot assign to read-only memoryview") - * - */ - } - - /* "View.MemoryView":420 - * raise TypeError("Cannot assign to read-only memoryview") - * - * have_slices, index = _unellipsify(index, self.view.ndim) # <<<<<<<<<<<<<< - * - * if have_slices: - */ - __pyx_t_2 = _unellipsify(__pyx_v_index, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 420, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (likely(__pyx_t_2 != Py_None)) { - PyObject* sequence = __pyx_t_2; - 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, 420, __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, 420, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 420, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else { - __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(2, 420, __pyx_L1_error) - } - __pyx_v_have_slices = __pyx_t_3; - __pyx_t_3 = 0; - __Pyx_DECREF_SET(__pyx_v_index, __pyx_t_4); - __pyx_t_4 = 0; - - /* "View.MemoryView":422 - * have_slices, index = _unellipsify(index, self.view.ndim) - * - * if have_slices: # <<<<<<<<<<<<<< - * obj = self.is_slice(value) - * if obj: - */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(2, 422, __pyx_L1_error) - if (__pyx_t_1) { - - /* "View.MemoryView":423 - * - * if have_slices: - * obj = self.is_slice(value) # <<<<<<<<<<<<<< - * if obj: - * self.setitem_slice_assignment(self[index], obj) - */ - __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->is_slice(__pyx_v_self, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 423, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_v_obj = __pyx_t_2; - __pyx_t_2 = 0; - - /* "View.MemoryView":424 - * if have_slices: - * obj = self.is_slice(value) - * if obj: # <<<<<<<<<<<<<< - * self.setitem_slice_assignment(self[index], obj) - * else: - */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_obj); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(2, 424, __pyx_L1_error) - if (__pyx_t_1) { - - /* "View.MemoryView":425 - * obj = self.is_slice(value) - * if obj: - * self.setitem_slice_assignment(self[index], obj) # <<<<<<<<<<<<<< - * else: - * self.setitem_slice_assign_scalar(self[index], value) - */ - __pyx_t_2 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 425, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_slice_assignment(__pyx_v_self, __pyx_t_2, __pyx_v_obj); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 425, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "View.MemoryView":424 - * if have_slices: - * obj = self.is_slice(value) - * if obj: # <<<<<<<<<<<<<< - * self.setitem_slice_assignment(self[index], obj) - * else: - */ - goto __pyx_L5; - } - - /* "View.MemoryView":427 - * self.setitem_slice_assignment(self[index], obj) - * else: - * self.setitem_slice_assign_scalar(self[index], value) # <<<<<<<<<<<<<< - * else: - * self.setitem_indexed(index, value) - */ - /*else*/ { - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_index); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 427, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_memoryview_type))))) __PYX_ERR(2, 427, __pyx_L1_error) - __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_slice_assign_scalar(__pyx_v_self, ((struct __pyx_memoryview_obj *)__pyx_t_4), __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 427, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __pyx_L5:; - - /* "View.MemoryView":422 - * have_slices, index = _unellipsify(index, self.view.ndim) - * - * if have_slices: # <<<<<<<<<<<<<< - * obj = self.is_slice(value) - * if obj: - */ - goto __pyx_L4; - } - - /* "View.MemoryView":429 - * self.setitem_slice_assign_scalar(self[index], value) - * else: - * self.setitem_indexed(index, value) # <<<<<<<<<<<<<< - * - * cdef is_slice(self, obj): - */ - /*else*/ { - __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_indexed(__pyx_v_self, __pyx_v_index, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 429, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __pyx_L4:; - - /* "View.MemoryView":416 - * return self.convert_item_to_object(itemp) - * - * def __setitem__(memoryview self, object index, object value): # <<<<<<<<<<<<<< - * if self.view.readonly: - * raise TypeError("Cannot assign to read-only memoryview") - */ - - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("View.MemoryView.memoryview.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_have_slices); - __Pyx_XDECREF(__pyx_v_obj); - __Pyx_XDECREF(__pyx_v_index); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":431 - * self.setitem_indexed(index, value) - * - * cdef is_slice(self, obj): # <<<<<<<<<<<<<< - * if not isinstance(obj, memoryview): - * try: - */ - -static PyObject *__pyx_memoryview_is_slice(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj) { - 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; - PyObject *__pyx_t_8 = NULL; - int __pyx_t_9; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("is_slice", 0); - __Pyx_INCREF(__pyx_v_obj); - - /* "View.MemoryView":432 - * - * cdef is_slice(self, obj): - * if not isinstance(obj, memoryview): # <<<<<<<<<<<<<< - * try: - * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS, - */ - __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_obj, __pyx_memoryview_type); - __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":433 - * cdef is_slice(self, obj): - * if not isinstance(obj, memoryview): - * try: # <<<<<<<<<<<<<< - * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS, - * self.dtype_is_object) - */ - { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __Pyx_ExceptionSave(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5); - __Pyx_XGOTREF(__pyx_t_3); - __Pyx_XGOTREF(__pyx_t_4); - __Pyx_XGOTREF(__pyx_t_5); - /*try:*/ { - - /* "View.MemoryView":434 - * if not isinstance(obj, memoryview): - * try: - * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS, # <<<<<<<<<<<<<< - * self.dtype_is_object) - * except TypeError: - */ - __pyx_t_6 = __Pyx_PyInt_From_int(((__pyx_v_self->flags & (~PyBUF_WRITABLE)) | PyBUF_ANY_CONTIGUOUS)); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 434, __pyx_L4_error) - __Pyx_GOTREF(__pyx_t_6); - - /* "View.MemoryView":435 - * try: - * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS, - * self.dtype_is_object) # <<<<<<<<<<<<<< - * except TypeError: - * return None - */ - __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_self->dtype_is_object); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 435, __pyx_L4_error) - __Pyx_GOTREF(__pyx_t_7); - - /* "View.MemoryView":434 - * if not isinstance(obj, memoryview): - * try: - * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS, # <<<<<<<<<<<<<< - * self.dtype_is_object) - * except TypeError: - */ - __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 434, __pyx_L4_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(__pyx_v_obj); - __Pyx_GIVEREF(__pyx_v_obj); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_obj); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7); - __pyx_t_6 = 0; - __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 434, __pyx_L4_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF_SET(__pyx_v_obj, __pyx_t_7); - __pyx_t_7 = 0; - - /* "View.MemoryView":433 - * cdef is_slice(self, obj): - * if not isinstance(obj, memoryview): - * try: # <<<<<<<<<<<<<< - * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS, - * self.dtype_is_object) - */ - } - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - goto __pyx_L9_try_end; - __pyx_L4_error:; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "View.MemoryView":436 - * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS, - * self.dtype_is_object) - * except TypeError: # <<<<<<<<<<<<<< - * return None - * - */ - __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_TypeError); - if (__pyx_t_9) { - __Pyx_AddTraceback("View.MemoryView.memoryview.is_slice", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_8, &__pyx_t_6) < 0) __PYX_ERR(2, 436, __pyx_L6_except_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_GOTREF(__pyx_t_8); - __Pyx_GOTREF(__pyx_t_6); - - /* "View.MemoryView":437 - * self.dtype_is_object) - * except TypeError: - * return None # <<<<<<<<<<<<<< - * - * return obj - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - goto __pyx_L7_except_return; - } - goto __pyx_L6_except_error; - __pyx_L6_except_error:; - - /* "View.MemoryView":433 - * cdef is_slice(self, obj): - * if not isinstance(obj, memoryview): - * try: # <<<<<<<<<<<<<< - * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS, - * self.dtype_is_object) - */ - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_XGIVEREF(__pyx_t_4); - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5); - goto __pyx_L1_error; - __pyx_L7_except_return:; - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_XGIVEREF(__pyx_t_4); - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5); - goto __pyx_L0; - __pyx_L9_try_end:; - } - - /* "View.MemoryView":432 - * - * cdef is_slice(self, obj): - * if not isinstance(obj, memoryview): # <<<<<<<<<<<<<< - * try: - * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS, - */ - } - - /* "View.MemoryView":439 - * return None - * - * return obj # <<<<<<<<<<<<<< - * - * cdef setitem_slice_assignment(self, dst, src): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_obj); - __pyx_r = __pyx_v_obj; - goto __pyx_L0; - - /* "View.MemoryView":431 - * self.setitem_indexed(index, value) - * - * cdef is_slice(self, obj): # <<<<<<<<<<<<<< - * if not isinstance(obj, memoryview): - * try: - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("View.MemoryView.memoryview.is_slice", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_obj); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":441 - * return obj - * - * cdef setitem_slice_assignment(self, dst, src): # <<<<<<<<<<<<<< - * cdef __Pyx_memviewslice dst_slice - * cdef __Pyx_memviewslice src_slice - */ - -static PyObject *__pyx_memoryview_setitem_slice_assignment(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_dst, PyObject *__pyx_v_src) { - __Pyx_memviewslice __pyx_v_dst_slice; - __Pyx_memviewslice __pyx_v_src_slice; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_memviewslice *__pyx_t_1; - __Pyx_memviewslice *__pyx_t_2; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("setitem_slice_assignment", 0); - - /* "View.MemoryView":445 - * cdef __Pyx_memviewslice src_slice - * - * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0], # <<<<<<<<<<<<<< - * get_slice_from_memview(dst, &dst_slice)[0], - * src.ndim, dst.ndim, self.dtype_is_object) - */ - if (!(likely(((__pyx_v_src) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_src, __pyx_memoryview_type))))) __PYX_ERR(2, 445, __pyx_L1_error) - __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(((struct __pyx_memoryview_obj *)__pyx_v_src), (&__pyx_v_src_slice)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(2, 445, __pyx_L1_error) - - /* "View.MemoryView":446 - * - * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0], - * get_slice_from_memview(dst, &dst_slice)[0], # <<<<<<<<<<<<<< - * src.ndim, dst.ndim, self.dtype_is_object) - * - */ - if (!(likely(((__pyx_v_dst) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_dst, __pyx_memoryview_type))))) __PYX_ERR(2, 446, __pyx_L1_error) - __pyx_t_2 = __pyx_memoryview_get_slice_from_memoryview(((struct __pyx_memoryview_obj *)__pyx_v_dst), (&__pyx_v_dst_slice)); if (unlikely(__pyx_t_2 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(2, 446, __pyx_L1_error) - - /* "View.MemoryView":447 - * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0], - * get_slice_from_memview(dst, &dst_slice)[0], - * src.ndim, dst.ndim, self.dtype_is_object) # <<<<<<<<<<<<<< - * - * cdef setitem_slice_assign_scalar(self, memoryview dst, value): - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_src, __pyx_n_s_ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 447, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 447, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_dst, __pyx_n_s_ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 447, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 447, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "View.MemoryView":445 - * cdef __Pyx_memviewslice src_slice - * - * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0], # <<<<<<<<<<<<<< - * get_slice_from_memview(dst, &dst_slice)[0], - * src.ndim, dst.ndim, self.dtype_is_object) - */ - __pyx_t_6 = __pyx_memoryview_copy_contents((__pyx_t_1[0]), (__pyx_t_2[0]), __pyx_t_4, __pyx_t_5, __pyx_v_self->dtype_is_object); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(2, 445, __pyx_L1_error) - - /* "View.MemoryView":441 - * return obj - * - * cdef setitem_slice_assignment(self, dst, src): # <<<<<<<<<<<<<< - * cdef __Pyx_memviewslice dst_slice - * cdef __Pyx_memviewslice src_slice - */ - - /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_slice_assignment", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":449 - * src.ndim, dst.ndim, self.dtype_is_object) - * - * cdef setitem_slice_assign_scalar(self, memoryview dst, value): # <<<<<<<<<<<<<< - * cdef int array[128] - * cdef void *tmp = NULL - */ - -static PyObject *__pyx_memoryview_setitem_slice_assign_scalar(struct __pyx_memoryview_obj *__pyx_v_self, struct __pyx_memoryview_obj *__pyx_v_dst, PyObject *__pyx_v_value) { - int __pyx_v_array[0x80]; - void *__pyx_v_tmp; - void *__pyx_v_item; - __Pyx_memviewslice *__pyx_v_dst_slice; - __Pyx_memviewslice __pyx_v_tmp_slice; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_memviewslice *__pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - int __pyx_t_5; - char const *__pyx_t_6; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - PyObject *__pyx_t_12 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("setitem_slice_assign_scalar", 0); - - /* "View.MemoryView":451 - * cdef setitem_slice_assign_scalar(self, memoryview dst, value): - * cdef int array[128] - * cdef void *tmp = NULL # <<<<<<<<<<<<<< - * cdef void *item - * - */ - __pyx_v_tmp = NULL; - - /* "View.MemoryView":456 - * cdef __Pyx_memviewslice *dst_slice - * cdef __Pyx_memviewslice tmp_slice - * dst_slice = get_slice_from_memview(dst, &tmp_slice) # <<<<<<<<<<<<<< - * - * if self.view.itemsize > sizeof(array): - */ - __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_dst, (&__pyx_v_tmp_slice)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(2, 456, __pyx_L1_error) - __pyx_v_dst_slice = __pyx_t_1; - - /* "View.MemoryView":458 - * dst_slice = get_slice_from_memview(dst, &tmp_slice) - * - * if self.view.itemsize > sizeof(array): # <<<<<<<<<<<<<< - * tmp = PyMem_Malloc(self.view.itemsize) - * if tmp == NULL: - */ - __pyx_t_2 = ((((size_t)__pyx_v_self->view.itemsize) > (sizeof(__pyx_v_array))) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":459 - * - * if self.view.itemsize > sizeof(array): - * tmp = PyMem_Malloc(self.view.itemsize) # <<<<<<<<<<<<<< - * if tmp == NULL: - * raise MemoryError - */ - __pyx_v_tmp = PyMem_Malloc(__pyx_v_self->view.itemsize); - - /* "View.MemoryView":460 - * if self.view.itemsize > sizeof(array): - * tmp = PyMem_Malloc(self.view.itemsize) - * if tmp == NULL: # <<<<<<<<<<<<<< - * raise MemoryError - * item = tmp - */ - __pyx_t_2 = ((__pyx_v_tmp == NULL) != 0); - if (unlikely(__pyx_t_2)) { - - /* "View.MemoryView":461 - * tmp = PyMem_Malloc(self.view.itemsize) - * if tmp == NULL: - * raise MemoryError # <<<<<<<<<<<<<< - * item = tmp - * else: - */ - PyErr_NoMemory(); __PYX_ERR(2, 461, __pyx_L1_error) - - /* "View.MemoryView":460 - * if self.view.itemsize > sizeof(array): - * tmp = PyMem_Malloc(self.view.itemsize) - * if tmp == NULL: # <<<<<<<<<<<<<< - * raise MemoryError - * item = tmp - */ - } - - /* "View.MemoryView":462 - * if tmp == NULL: - * raise MemoryError - * item = tmp # <<<<<<<<<<<<<< - * else: - * item = array - */ - __pyx_v_item = __pyx_v_tmp; - - /* "View.MemoryView":458 - * dst_slice = get_slice_from_memview(dst, &tmp_slice) - * - * if self.view.itemsize > sizeof(array): # <<<<<<<<<<<<<< - * tmp = PyMem_Malloc(self.view.itemsize) - * if tmp == NULL: - */ - goto __pyx_L3; - } - - /* "View.MemoryView":464 - * item = tmp - * else: - * item = array # <<<<<<<<<<<<<< - * - * try: - */ - /*else*/ { - __pyx_v_item = ((void *)__pyx_v_array); - } - __pyx_L3:; - - /* "View.MemoryView":466 - * item = array - * - * try: # <<<<<<<<<<<<<< - * if self.dtype_is_object: - * ( item)[0] = value - */ - /*try:*/ { - - /* "View.MemoryView":467 - * - * try: - * if self.dtype_is_object: # <<<<<<<<<<<<<< - * ( item)[0] = value - * else: - */ - __pyx_t_2 = (__pyx_v_self->dtype_is_object != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":468 - * try: - * if self.dtype_is_object: - * ( item)[0] = value # <<<<<<<<<<<<<< - * else: - * self.assign_item_from_object( item, value) - */ - (((PyObject **)__pyx_v_item)[0]) = ((PyObject *)__pyx_v_value); - - /* "View.MemoryView":467 - * - * try: - * if self.dtype_is_object: # <<<<<<<<<<<<<< - * ( item)[0] = value - * else: - */ - goto __pyx_L8; - } - - /* "View.MemoryView":470 - * ( item)[0] = value - * else: - * self.assign_item_from_object( item, value) # <<<<<<<<<<<<<< - * - * - */ - /*else*/ { - __pyx_t_3 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->assign_item_from_object(__pyx_v_self, ((char *)__pyx_v_item), __pyx_v_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 470, __pyx_L6_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __pyx_L8:; - - /* "View.MemoryView":474 - * - * - * if self.view.suboffsets != NULL: # <<<<<<<<<<<<<< - * assert_direct_dimensions(self.view.suboffsets, self.view.ndim) - * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize, - */ - __pyx_t_2 = ((__pyx_v_self->view.suboffsets != NULL) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":475 - * - * if self.view.suboffsets != NULL: - * assert_direct_dimensions(self.view.suboffsets, self.view.ndim) # <<<<<<<<<<<<<< - * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize, - * item, self.dtype_is_object) - */ - __pyx_t_3 = assert_direct_dimensions(__pyx_v_self->view.suboffsets, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 475, __pyx_L6_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "View.MemoryView":474 - * - * - * if self.view.suboffsets != NULL: # <<<<<<<<<<<<<< - * assert_direct_dimensions(self.view.suboffsets, self.view.ndim) - * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize, - */ - } - - /* "View.MemoryView":476 - * if self.view.suboffsets != NULL: - * assert_direct_dimensions(self.view.suboffsets, self.view.ndim) - * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize, # <<<<<<<<<<<<<< - * item, self.dtype_is_object) - * finally: - */ - __pyx_memoryview_slice_assign_scalar(__pyx_v_dst_slice, __pyx_v_dst->view.ndim, __pyx_v_self->view.itemsize, __pyx_v_item, __pyx_v_self->dtype_is_object); - } - - /* "View.MemoryView":479 - * item, self.dtype_is_object) - * finally: - * PyMem_Free(tmp) # <<<<<<<<<<<<<< - * - * cdef setitem_indexed(self, index, value): - */ - /*finally:*/ { - /*normal exit:*/{ - PyMem_Free(__pyx_v_tmp); - goto __pyx_L7; - } - __pyx_L6_error:; - /*exception exit:*/{ - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12); - if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9) < 0)) __Pyx_ErrFetch(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9); - __Pyx_XGOTREF(__pyx_t_7); - __Pyx_XGOTREF(__pyx_t_8); - __Pyx_XGOTREF(__pyx_t_9); - __Pyx_XGOTREF(__pyx_t_10); - __Pyx_XGOTREF(__pyx_t_11); - __Pyx_XGOTREF(__pyx_t_12); - __pyx_t_4 = __pyx_lineno; __pyx_t_5 = __pyx_clineno; __pyx_t_6 = __pyx_filename; - { - PyMem_Free(__pyx_v_tmp); - } - if (PY_MAJOR_VERSION >= 3) { - __Pyx_XGIVEREF(__pyx_t_10); - __Pyx_XGIVEREF(__pyx_t_11); - __Pyx_XGIVEREF(__pyx_t_12); - __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); - } - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_XGIVEREF(__pyx_t_8); - __Pyx_XGIVEREF(__pyx_t_9); - __Pyx_ErrRestore(__pyx_t_7, __pyx_t_8, __pyx_t_9); - __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; - __pyx_lineno = __pyx_t_4; __pyx_clineno = __pyx_t_5; __pyx_filename = __pyx_t_6; - goto __pyx_L1_error; - } - __pyx_L7:; - } - - /* "View.MemoryView":449 - * src.ndim, dst.ndim, self.dtype_is_object) - * - * cdef setitem_slice_assign_scalar(self, memoryview dst, value): # <<<<<<<<<<<<<< - * cdef int array[128] - * cdef void *tmp = NULL - */ - - /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_slice_assign_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":481 - * PyMem_Free(tmp) - * - * cdef setitem_indexed(self, index, value): # <<<<<<<<<<<<<< - * cdef char *itemp = self.get_item_pointer(index) - * self.assign_item_from_object(itemp, value) - */ - -static PyObject *__pyx_memoryview_setitem_indexed(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) { - char *__pyx_v_itemp; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - char *__pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("setitem_indexed", 0); - - /* "View.MemoryView":482 - * - * cdef setitem_indexed(self, index, value): - * cdef char *itemp = self.get_item_pointer(index) # <<<<<<<<<<<<<< - * self.assign_item_from_object(itemp, value) - * - */ - __pyx_t_1 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->get_item_pointer(__pyx_v_self, __pyx_v_index); if (unlikely(__pyx_t_1 == ((char *)NULL))) __PYX_ERR(2, 482, __pyx_L1_error) - __pyx_v_itemp = __pyx_t_1; - - /* "View.MemoryView":483 - * cdef setitem_indexed(self, index, value): - * cdef char *itemp = self.get_item_pointer(index) - * self.assign_item_from_object(itemp, value) # <<<<<<<<<<<<<< - * - * cdef convert_item_to_object(self, char *itemp): - */ - __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->assign_item_from_object(__pyx_v_self, __pyx_v_itemp, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 483, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "View.MemoryView":481 - * PyMem_Free(tmp) - * - * cdef setitem_indexed(self, index, value): # <<<<<<<<<<<<<< - * cdef char *itemp = self.get_item_pointer(index) - * self.assign_item_from_object(itemp, value) - */ - - /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_indexed", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":485 - * self.assign_item_from_object(itemp, value) - * - * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<< - * """Only used if instantiated manually by the user, or if Cython doesn't - * know how to convert the type""" - */ - -static PyObject *__pyx_memoryview_convert_item_to_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp) { - PyObject *__pyx_v_struct = NULL; - PyObject *__pyx_v_bytesitem = 0; - PyObject *__pyx_v_result = NULL; - 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; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - int __pyx_t_8; - PyObject *__pyx_t_9 = NULL; - size_t __pyx_t_10; - int __pyx_t_11; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("convert_item_to_object", 0); - - /* "View.MemoryView":488 - * """Only used if instantiated manually by the user, or if Cython doesn't - * know how to convert the type""" - * import struct # <<<<<<<<<<<<<< - * cdef bytes bytesitem - * - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_struct, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 488, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_struct = __pyx_t_1; - __pyx_t_1 = 0; - - /* "View.MemoryView":491 - * cdef bytes bytesitem - * - * bytesitem = itemp[:self.view.itemsize] # <<<<<<<<<<<<<< - * try: - * result = struct.unpack(self.view.format, bytesitem) - */ - __pyx_t_1 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_itemp + 0, __pyx_v_self->view.itemsize - 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 491, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_bytesitem = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; - - /* "View.MemoryView":492 - * - * bytesitem = itemp[:self.view.itemsize] - * try: # <<<<<<<<<<<<<< - * result = struct.unpack(self.view.format, bytesitem) - * except struct.error: - */ - { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __Pyx_ExceptionSave(&__pyx_t_2, &__pyx_t_3, &__pyx_t_4); - __Pyx_XGOTREF(__pyx_t_2); - __Pyx_XGOTREF(__pyx_t_3); - __Pyx_XGOTREF(__pyx_t_4); - /*try:*/ { - - /* "View.MemoryView":493 - * bytesitem = itemp[:self.view.itemsize] - * try: - * result = struct.unpack(self.view.format, bytesitem) # <<<<<<<<<<<<<< - * except struct.error: - * raise ValueError("Unable to convert item to object") - */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_unpack); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 493, __pyx_L3_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 493, __pyx_L3_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = NULL; - __pyx_t_8 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - __pyx_t_8 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_6, __pyx_v_bytesitem}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 493, __pyx_L3_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_1); - __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_7, __pyx_t_6, __pyx_v_bytesitem}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 493, __pyx_L3_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } else - #endif - { - __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 493, __pyx_L3_error) - __Pyx_GOTREF(__pyx_t_9); - if (__pyx_t_7) { - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL; - } - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_t_6); - __Pyx_INCREF(__pyx_v_bytesitem); - __Pyx_GIVEREF(__pyx_v_bytesitem); - PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_v_bytesitem); - __pyx_t_6 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 493, __pyx_L3_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_result = __pyx_t_1; - __pyx_t_1 = 0; - - /* "View.MemoryView":492 - * - * bytesitem = itemp[:self.view.itemsize] - * try: # <<<<<<<<<<<<<< - * result = struct.unpack(self.view.format, bytesitem) - * except struct.error: - */ - } - - /* "View.MemoryView":497 - * raise ValueError("Unable to convert item to object") - * else: - * if len(self.view.format) == 1: # <<<<<<<<<<<<<< - * return result[0] - * return result - */ - /*else:*/ { - __pyx_t_10 = strlen(__pyx_v_self->view.format); - __pyx_t_11 = ((__pyx_t_10 == 1) != 0); - if (__pyx_t_11) { - - /* "View.MemoryView":498 - * else: - * if len(self.view.format) == 1: - * return result[0] # <<<<<<<<<<<<<< - * return result - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_result, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 498, __pyx_L5_except_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L6_except_return; - - /* "View.MemoryView":497 - * raise ValueError("Unable to convert item to object") - * else: - * if len(self.view.format) == 1: # <<<<<<<<<<<<<< - * return result[0] - * return result - */ - } - - /* "View.MemoryView":499 - * if len(self.view.format) == 1: - * return result[0] - * return result # <<<<<<<<<<<<<< - * - * cdef assign_item_from_object(self, char *itemp, object value): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_result); - __pyx_r = __pyx_v_result; - goto __pyx_L6_except_return; - } - __pyx_L3_error:; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "View.MemoryView":494 - * try: - * result = struct.unpack(self.view.format, bytesitem) - * except struct.error: # <<<<<<<<<<<<<< - * raise ValueError("Unable to convert item to object") - * else: - */ - __Pyx_ErrFetch(&__pyx_t_1, &__pyx_t_5, &__pyx_t_9); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_error); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 494, __pyx_L5_except_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_8 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_1, __pyx_t_6); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_ErrRestore(__pyx_t_1, __pyx_t_5, __pyx_t_9); - __pyx_t_1 = 0; __pyx_t_5 = 0; __pyx_t_9 = 0; - if (__pyx_t_8) { - __Pyx_AddTraceback("View.MemoryView.memoryview.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_5, &__pyx_t_1) < 0) __PYX_ERR(2, 494, __pyx_L5_except_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GOTREF(__pyx_t_1); - - /* "View.MemoryView":495 - * result = struct.unpack(self.view.format, bytesitem) - * except struct.error: - * raise ValueError("Unable to convert item to object") # <<<<<<<<<<<<<< - * else: - * if len(self.view.format) == 1: - */ - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 495, __pyx_L5_except_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_Raise(__pyx_t_6, 0, 0, 0); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __PYX_ERR(2, 495, __pyx_L5_except_error) - } - goto __pyx_L5_except_error; - __pyx_L5_except_error:; - - /* "View.MemoryView":492 - * - * bytesitem = itemp[:self.view.itemsize] - * try: # <<<<<<<<<<<<<< - * result = struct.unpack(self.view.format, bytesitem) - * except struct.error: - */ - __Pyx_XGIVEREF(__pyx_t_2); - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_XGIVEREF(__pyx_t_4); - __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4); - goto __pyx_L1_error; - __pyx_L6_except_return:; - __Pyx_XGIVEREF(__pyx_t_2); - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_XGIVEREF(__pyx_t_4); - __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4); - goto __pyx_L0; - } - - /* "View.MemoryView":485 - * self.assign_item_from_object(itemp, value) - * - * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<< - * """Only used if instantiated manually by the user, or if Cython doesn't - * know how to convert the type""" - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("View.MemoryView.memoryview.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_struct); - __Pyx_XDECREF(__pyx_v_bytesitem); - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":501 - * return result - * - * cdef assign_item_from_object(self, char *itemp, object value): # <<<<<<<<<<<<<< - * """Only used if instantiated manually by the user, or if Cython doesn't - * know how to convert the type""" - */ - -static PyObject *__pyx_memoryview_assign_item_from_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp, PyObject *__pyx_v_value) { - PyObject *__pyx_v_struct = NULL; - char __pyx_v_c; - PyObject *__pyx_v_bytesvalue = 0; - Py_ssize_t __pyx_v_i; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - int __pyx_t_7; - PyObject *__pyx_t_8 = NULL; - Py_ssize_t __pyx_t_9; - PyObject *__pyx_t_10 = NULL; - char *__pyx_t_11; - char *__pyx_t_12; - char *__pyx_t_13; - char *__pyx_t_14; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("assign_item_from_object", 0); - - /* "View.MemoryView":504 - * """Only used if instantiated manually by the user, or if Cython doesn't - * know how to convert the type""" - * import struct # <<<<<<<<<<<<<< - * cdef char c - * cdef bytes bytesvalue - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_struct, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 504, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_struct = __pyx_t_1; - __pyx_t_1 = 0; - - /* "View.MemoryView":509 - * cdef Py_ssize_t i - * - * if isinstance(value, tuple): # <<<<<<<<<<<<<< - * bytesvalue = struct.pack(self.view.format, *value) - * else: - */ - __pyx_t_2 = PyTuple_Check(__pyx_v_value); - __pyx_t_3 = (__pyx_t_2 != 0); - if (__pyx_t_3) { - - /* "View.MemoryView":510 - * - * if isinstance(value, tuple): - * bytesvalue = struct.pack(self.view.format, *value) # <<<<<<<<<<<<<< - * else: - * bytesvalue = struct.pack(self.view.format, value) - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_pack); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 510, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 510, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 510, __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 = 0; - __pyx_t_4 = __Pyx_PySequence_Tuple(__pyx_v_value); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 510, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = PyNumber_Add(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 510, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 510, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(2, 510, __pyx_L1_error) - __pyx_v_bytesvalue = ((PyObject*)__pyx_t_4); - __pyx_t_4 = 0; - - /* "View.MemoryView":509 - * cdef Py_ssize_t i - * - * if isinstance(value, tuple): # <<<<<<<<<<<<<< - * bytesvalue = struct.pack(self.view.format, *value) - * else: - */ - goto __pyx_L3; - } - - /* "View.MemoryView":512 - * bytesvalue = struct.pack(self.view.format, *value) - * else: - * bytesvalue = struct.pack(self.view.format, value) # <<<<<<<<<<<<<< - * - * for i, c in enumerate(bytesvalue): - */ - /*else*/ { - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_pack); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 512, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 512, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = NULL; - __pyx_t_7 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - __pyx_t_7 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_1, __pyx_v_value}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 512, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 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_6)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_1, __pyx_v_value}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 512, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - { - __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 512, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - if (__pyx_t_5) { - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5); __pyx_t_5 = NULL; - } - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_t_1); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_v_value); - __pyx_t_1 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 512, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(2, 512, __pyx_L1_error) - __pyx_v_bytesvalue = ((PyObject*)__pyx_t_4); - __pyx_t_4 = 0; - } - __pyx_L3:; - - /* "View.MemoryView":514 - * bytesvalue = struct.pack(self.view.format, value) - * - * for i, c in enumerate(bytesvalue): # <<<<<<<<<<<<<< - * itemp[i] = c - * - */ - __pyx_t_9 = 0; - if (unlikely(__pyx_v_bytesvalue == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' is not iterable"); - __PYX_ERR(2, 514, __pyx_L1_error) - } - __Pyx_INCREF(__pyx_v_bytesvalue); - __pyx_t_10 = __pyx_v_bytesvalue; - __pyx_t_12 = PyBytes_AS_STRING(__pyx_t_10); - __pyx_t_13 = (__pyx_t_12 + PyBytes_GET_SIZE(__pyx_t_10)); - for (__pyx_t_14 = __pyx_t_12; __pyx_t_14 < __pyx_t_13; __pyx_t_14++) { - __pyx_t_11 = __pyx_t_14; - __pyx_v_c = (__pyx_t_11[0]); - - /* "View.MemoryView":515 - * - * for i, c in enumerate(bytesvalue): - * itemp[i] = c # <<<<<<<<<<<<<< - * - * @cname('getbuffer') - */ - __pyx_v_i = __pyx_t_9; - - /* "View.MemoryView":514 - * bytesvalue = struct.pack(self.view.format, value) - * - * for i, c in enumerate(bytesvalue): # <<<<<<<<<<<<<< - * itemp[i] = c - * - */ - __pyx_t_9 = (__pyx_t_9 + 1); - - /* "View.MemoryView":515 - * - * for i, c in enumerate(bytesvalue): - * itemp[i] = c # <<<<<<<<<<<<<< - * - * @cname('getbuffer') - */ - (__pyx_v_itemp[__pyx_v_i]) = __pyx_v_c; - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "View.MemoryView":501 - * return result - * - * cdef assign_item_from_object(self, char *itemp, object value): # <<<<<<<<<<<<<< - * """Only used if instantiated manually by the user, or if Cython doesn't - * know how to convert the type""" - */ - - /* 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_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_AddTraceback("View.MemoryView.memoryview.assign_item_from_object", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_struct); - __Pyx_XDECREF(__pyx_v_bytesvalue); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":518 - * - * @cname('getbuffer') - * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<< - * if flags & PyBUF_WRITABLE and self.view.readonly: - * raise ValueError("Cannot create writable memory view from read-only memoryview") - */ - -/* Python wrapper */ -static CYTHON_UNUSED int __pyx_memoryview_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ -static CYTHON_UNUSED int __pyx_memoryview_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_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_8__getbuffer__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_8__getbuffer__(struct __pyx_memoryview_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - Py_ssize_t *__pyx_t_4; - char *__pyx_t_5; - void *__pyx_t_6; - int __pyx_t_7; - Py_ssize_t __pyx_t_8; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - 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); - - /* "View.MemoryView":519 - * @cname('getbuffer') - * def __getbuffer__(self, Py_buffer *info, int flags): - * if flags & PyBUF_WRITABLE and self.view.readonly: # <<<<<<<<<<<<<< - * raise ValueError("Cannot create writable memory view from read-only memoryview") - * - */ - __pyx_t_2 = ((__pyx_v_flags & PyBUF_WRITABLE) != 0); - if (__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_2 = (__pyx_v_self->view.readonly != 0); - __pyx_t_1 = __pyx_t_2; - __pyx_L4_bool_binop_done:; - if (unlikely(__pyx_t_1)) { - - /* "View.MemoryView":520 - * def __getbuffer__(self, Py_buffer *info, int flags): - * if flags & PyBUF_WRITABLE and self.view.readonly: - * raise ValueError("Cannot create writable memory view from read-only memoryview") # <<<<<<<<<<<<<< - * - * if flags & PyBUF_ND: - */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 520, __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, 520, __pyx_L1_error) - - /* "View.MemoryView":519 - * @cname('getbuffer') - * def __getbuffer__(self, Py_buffer *info, int flags): - * if flags & PyBUF_WRITABLE and self.view.readonly: # <<<<<<<<<<<<<< - * raise ValueError("Cannot create writable memory view from read-only memoryview") - * - */ - } - - /* "View.MemoryView":522 - * raise ValueError("Cannot create writable memory view from read-only memoryview") - * - * if flags & PyBUF_ND: # <<<<<<<<<<<<<< - * info.shape = self.view.shape - * else: - */ - __pyx_t_1 = ((__pyx_v_flags & PyBUF_ND) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":523 - * - * if flags & PyBUF_ND: - * info.shape = self.view.shape # <<<<<<<<<<<<<< - * else: - * info.shape = NULL - */ - __pyx_t_4 = __pyx_v_self->view.shape; - __pyx_v_info->shape = __pyx_t_4; - - /* "View.MemoryView":522 - * raise ValueError("Cannot create writable memory view from read-only memoryview") - * - * if flags & PyBUF_ND: # <<<<<<<<<<<<<< - * info.shape = self.view.shape - * else: - */ - goto __pyx_L6; - } - - /* "View.MemoryView":525 - * info.shape = self.view.shape - * else: - * info.shape = NULL # <<<<<<<<<<<<<< - * - * if flags & PyBUF_STRIDES: - */ - /*else*/ { - __pyx_v_info->shape = NULL; - } - __pyx_L6:; - - /* "View.MemoryView":527 - * info.shape = NULL - * - * if flags & PyBUF_STRIDES: # <<<<<<<<<<<<<< - * info.strides = self.view.strides - * else: - */ - __pyx_t_1 = ((__pyx_v_flags & PyBUF_STRIDES) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":528 - * - * if flags & PyBUF_STRIDES: - * info.strides = self.view.strides # <<<<<<<<<<<<<< - * else: - * info.strides = NULL - */ - __pyx_t_4 = __pyx_v_self->view.strides; - __pyx_v_info->strides = __pyx_t_4; - - /* "View.MemoryView":527 - * info.shape = NULL - * - * if flags & PyBUF_STRIDES: # <<<<<<<<<<<<<< - * info.strides = self.view.strides - * else: - */ - goto __pyx_L7; - } - - /* "View.MemoryView":530 - * info.strides = self.view.strides - * else: - * info.strides = NULL # <<<<<<<<<<<<<< - * - * if flags & PyBUF_INDIRECT: - */ - /*else*/ { - __pyx_v_info->strides = NULL; - } - __pyx_L7:; - - /* "View.MemoryView":532 - * info.strides = NULL - * - * if flags & PyBUF_INDIRECT: # <<<<<<<<<<<<<< - * info.suboffsets = self.view.suboffsets - * else: - */ - __pyx_t_1 = ((__pyx_v_flags & PyBUF_INDIRECT) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":533 - * - * if flags & PyBUF_INDIRECT: - * info.suboffsets = self.view.suboffsets # <<<<<<<<<<<<<< - * else: - * info.suboffsets = NULL - */ - __pyx_t_4 = __pyx_v_self->view.suboffsets; - __pyx_v_info->suboffsets = __pyx_t_4; - - /* "View.MemoryView":532 - * info.strides = NULL - * - * if flags & PyBUF_INDIRECT: # <<<<<<<<<<<<<< - * info.suboffsets = self.view.suboffsets - * else: - */ - goto __pyx_L8; - } - - /* "View.MemoryView":535 - * info.suboffsets = self.view.suboffsets - * else: - * info.suboffsets = NULL # <<<<<<<<<<<<<< - * - * if flags & PyBUF_FORMAT: - */ - /*else*/ { - __pyx_v_info->suboffsets = NULL; - } - __pyx_L8:; - - /* "View.MemoryView":537 - * info.suboffsets = NULL - * - * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< - * info.format = self.view.format - * else: - */ - __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":538 - * - * if flags & PyBUF_FORMAT: - * info.format = self.view.format # <<<<<<<<<<<<<< - * else: - * info.format = NULL - */ - __pyx_t_5 = __pyx_v_self->view.format; - __pyx_v_info->format = __pyx_t_5; - - /* "View.MemoryView":537 - * info.suboffsets = NULL - * - * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< - * info.format = self.view.format - * else: - */ - goto __pyx_L9; - } - - /* "View.MemoryView":540 - * info.format = self.view.format - * else: - * info.format = NULL # <<<<<<<<<<<<<< - * - * info.buf = self.view.buf - */ - /*else*/ { - __pyx_v_info->format = NULL; - } - __pyx_L9:; - - /* "View.MemoryView":542 - * info.format = NULL - * - * info.buf = self.view.buf # <<<<<<<<<<<<<< - * info.ndim = self.view.ndim - * info.itemsize = self.view.itemsize - */ - __pyx_t_6 = __pyx_v_self->view.buf; - __pyx_v_info->buf = __pyx_t_6; - - /* "View.MemoryView":543 - * - * info.buf = self.view.buf - * info.ndim = self.view.ndim # <<<<<<<<<<<<<< - * info.itemsize = self.view.itemsize - * info.len = self.view.len - */ - __pyx_t_7 = __pyx_v_self->view.ndim; - __pyx_v_info->ndim = __pyx_t_7; - - /* "View.MemoryView":544 - * info.buf = self.view.buf - * info.ndim = self.view.ndim - * info.itemsize = self.view.itemsize # <<<<<<<<<<<<<< - * info.len = self.view.len - * info.readonly = self.view.readonly - */ - __pyx_t_8 = __pyx_v_self->view.itemsize; - __pyx_v_info->itemsize = __pyx_t_8; - - /* "View.MemoryView":545 - * info.ndim = self.view.ndim - * info.itemsize = self.view.itemsize - * info.len = self.view.len # <<<<<<<<<<<<<< - * info.readonly = self.view.readonly - * info.obj = self - */ - __pyx_t_8 = __pyx_v_self->view.len; - __pyx_v_info->len = __pyx_t_8; - - /* "View.MemoryView":546 - * info.itemsize = self.view.itemsize - * info.len = self.view.len - * info.readonly = self.view.readonly # <<<<<<<<<<<<<< - * info.obj = self - * - */ - __pyx_t_1 = __pyx_v_self->view.readonly; - __pyx_v_info->readonly = __pyx_t_1; - - /* "View.MemoryView":547 - * info.len = self.view.len - * info.readonly = self.view.readonly - * info.obj = self # <<<<<<<<<<<<<< - * - * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") - */ - __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); - - /* "View.MemoryView":518 - * - * @cname('getbuffer') - * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<< - * if flags & PyBUF_WRITABLE and self.view.readonly: - * raise ValueError("Cannot create writable memory view from read-only memoryview") - */ - - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("View.MemoryView.memoryview.__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_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":553 - * - * @property - * def T(self): # <<<<<<<<<<<<<< - * cdef _memoryviewslice result = memoryview_copy(self) - * transpose_memslice(&result.from_slice) - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_1T_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_1T_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_1T___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_1T___get__(struct __pyx_memoryview_obj *__pyx_v_self) { - struct __pyx_memoryviewslice_obj *__pyx_v_result = 0; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); - - /* "View.MemoryView":554 - * @property - * def T(self): - * cdef _memoryviewslice result = memoryview_copy(self) # <<<<<<<<<<<<<< - * transpose_memslice(&result.from_slice) - * return result - */ - __pyx_t_1 = __pyx_memoryview_copy_object(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 554, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_memoryviewslice_type))))) __PYX_ERR(2, 554, __pyx_L1_error) - __pyx_v_result = ((struct __pyx_memoryviewslice_obj *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "View.MemoryView":555 - * def T(self): - * cdef _memoryviewslice result = memoryview_copy(self) - * transpose_memslice(&result.from_slice) # <<<<<<<<<<<<<< - * return result - * - */ - __pyx_t_2 = __pyx_memslice_transpose((&__pyx_v_result->from_slice)); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(2, 555, __pyx_L1_error) - - /* "View.MemoryView":556 - * cdef _memoryviewslice result = memoryview_copy(self) - * transpose_memslice(&result.from_slice) - * return result # <<<<<<<<<<<<<< - * - * @property - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_result)); - __pyx_r = ((PyObject *)__pyx_v_result); - goto __pyx_L0; - - /* "View.MemoryView":553 - * - * @property - * def T(self): # <<<<<<<<<<<<<< - * cdef _memoryviewslice result = memoryview_copy(self) - * transpose_memslice(&result.from_slice) - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("View.MemoryView.memoryview.T.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_result); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":559 - * - * @property - * def base(self): # <<<<<<<<<<<<<< - * return self.obj - * - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4base_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4base_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4base___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4base___get__(struct __pyx_memoryview_obj *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__", 0); - - /* "View.MemoryView":560 - * @property - * def base(self): - * return self.obj # <<<<<<<<<<<<<< - * - * @property - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self->obj); - __pyx_r = __pyx_v_self->obj; - goto __pyx_L0; - - /* "View.MemoryView":559 - * - * @property - * def base(self): # <<<<<<<<<<<<<< - * return self.obj - * - */ - - /* function exit code */ - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":563 - * - * @property - * def shape(self): # <<<<<<<<<<<<<< - * return tuple([length for length in self.view.shape[:self.view.ndim]]) - * - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_5shape_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_5shape_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_5shape___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_5shape___get__(struct __pyx_memoryview_obj *__pyx_v_self) { - Py_ssize_t __pyx_v_length; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - Py_ssize_t *__pyx_t_2; - Py_ssize_t *__pyx_t_3; - Py_ssize_t *__pyx_t_4; - PyObject *__pyx_t_5 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); - - /* "View.MemoryView":564 - * @property - * def shape(self): - * return tuple([length for length in self.view.shape[:self.view.ndim]]) # <<<<<<<<<<<<<< - * - * @property - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 564, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = (__pyx_v_self->view.shape + __pyx_v_self->view.ndim); - for (__pyx_t_4 = __pyx_v_self->view.shape; __pyx_t_4 < __pyx_t_3; __pyx_t_4++) { - __pyx_t_2 = __pyx_t_4; - __pyx_v_length = (__pyx_t_2[0]); - __pyx_t_5 = PyInt_FromSsize_t(__pyx_v_length); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 564, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_5))) __PYX_ERR(2, 564, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - __pyx_t_5 = PyList_AsTuple(((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 564, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; - goto __pyx_L0; - - /* "View.MemoryView":563 - * - * @property - * def shape(self): # <<<<<<<<<<<<<< - * return tuple([length for length in self.view.shape[:self.view.ndim]]) - * - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("View.MemoryView.memoryview.shape.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":567 - * - * @property - * def strides(self): # <<<<<<<<<<<<<< - * if self.view.strides == NULL: - * - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_7strides_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_7strides_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_7strides___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_7strides___get__(struct __pyx_memoryview_obj *__pyx_v_self) { - Py_ssize_t __pyx_v_stride; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - Py_ssize_t *__pyx_t_3; - Py_ssize_t *__pyx_t_4; - Py_ssize_t *__pyx_t_5; - PyObject *__pyx_t_6 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); - - /* "View.MemoryView":568 - * @property - * def strides(self): - * if self.view.strides == NULL: # <<<<<<<<<<<<<< - * - * raise ValueError("Buffer view does not expose strides") - */ - __pyx_t_1 = ((__pyx_v_self->view.strides == NULL) != 0); - if (unlikely(__pyx_t_1)) { - - /* "View.MemoryView":570 - * if self.view.strides == NULL: - * - * raise ValueError("Buffer view does not expose strides") # <<<<<<<<<<<<<< - * - * return tuple([stride for stride in self.view.strides[:self.view.ndim]]) - */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 570, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(2, 570, __pyx_L1_error) - - /* "View.MemoryView":568 - * @property - * def strides(self): - * if self.view.strides == NULL: # <<<<<<<<<<<<<< - * - * raise ValueError("Buffer view does not expose strides") - */ - } - - /* "View.MemoryView":572 - * raise ValueError("Buffer view does not expose strides") - * - * return tuple([stride for stride in self.view.strides[:self.view.ndim]]) # <<<<<<<<<<<<<< - * - * @property - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 572, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = (__pyx_v_self->view.strides + __pyx_v_self->view.ndim); - for (__pyx_t_5 = __pyx_v_self->view.strides; __pyx_t_5 < __pyx_t_4; __pyx_t_5++) { - __pyx_t_3 = __pyx_t_5; - __pyx_v_stride = (__pyx_t_3[0]); - __pyx_t_6 = PyInt_FromSsize_t(__pyx_v_stride); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 572, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_6))) __PYX_ERR(2, 572, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - __pyx_t_6 = PyList_AsTuple(((PyObject*)__pyx_t_2)); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 572, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_6; - __pyx_t_6 = 0; - goto __pyx_L0; - - /* "View.MemoryView":567 - * - * @property - * def strides(self): # <<<<<<<<<<<<<< - * if self.view.strides == NULL: - * - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("View.MemoryView.memoryview.strides.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":575 - * - * @property - * def suboffsets(self): # <<<<<<<<<<<<<< - * if self.view.suboffsets == NULL: - * return (-1,) * self.view.ndim - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_10suboffsets_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_10suboffsets_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_10suboffsets___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_10suboffsets___get__(struct __pyx_memoryview_obj *__pyx_v_self) { - Py_ssize_t __pyx_v_suboffset; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - Py_ssize_t *__pyx_t_4; - Py_ssize_t *__pyx_t_5; - Py_ssize_t *__pyx_t_6; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); - - /* "View.MemoryView":576 - * @property - * def suboffsets(self): - * if self.view.suboffsets == NULL: # <<<<<<<<<<<<<< - * return (-1,) * self.view.ndim - * - */ - __pyx_t_1 = ((__pyx_v_self->view.suboffsets == NULL) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":577 - * def suboffsets(self): - * if self.view.suboffsets == NULL: - * return (-1,) * self.view.ndim # <<<<<<<<<<<<<< - * - * return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]]) - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->view.ndim); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 577, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_Multiply(__pyx_tuple__17, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 577, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - - /* "View.MemoryView":576 - * @property - * def suboffsets(self): - * if self.view.suboffsets == NULL: # <<<<<<<<<<<<<< - * return (-1,) * self.view.ndim - * - */ - } - - /* "View.MemoryView":579 - * return (-1,) * self.view.ndim - * - * return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]]) # <<<<<<<<<<<<<< - * - * @property - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 579, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = (__pyx_v_self->view.suboffsets + __pyx_v_self->view.ndim); - for (__pyx_t_6 = __pyx_v_self->view.suboffsets; __pyx_t_6 < __pyx_t_5; __pyx_t_6++) { - __pyx_t_4 = __pyx_t_6; - __pyx_v_suboffset = (__pyx_t_4[0]); - __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_suboffset); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 579, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_2))) __PYX_ERR(2, 579, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __pyx_t_2 = PyList_AsTuple(((PyObject*)__pyx_t_3)); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 579, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - - /* "View.MemoryView":575 - * - * @property - * def suboffsets(self): # <<<<<<<<<<<<<< - * if self.view.suboffsets == NULL: - * return (-1,) * self.view.ndim - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("View.MemoryView.memoryview.suboffsets.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":582 - * - * @property - * def ndim(self): # <<<<<<<<<<<<<< - * return self.view.ndim - * - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4ndim_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4ndim_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4ndim___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4ndim___get__(struct __pyx_memoryview_obj *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); - - /* "View.MemoryView":583 - * @property - * def ndim(self): - * return self.view.ndim # <<<<<<<<<<<<<< - * - * @property - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->view.ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 583, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "View.MemoryView":582 - * - * @property - * def ndim(self): # <<<<<<<<<<<<<< - * return self.view.ndim - * - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("View.MemoryView.memoryview.ndim.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":586 - * - * @property - * def itemsize(self): # <<<<<<<<<<<<<< - * return self.view.itemsize - * - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_8itemsize_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_8itemsize_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_8itemsize___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_8itemsize___get__(struct __pyx_memoryview_obj *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); - - /* "View.MemoryView":587 - * @property - * def itemsize(self): - * return self.view.itemsize # <<<<<<<<<<<<<< - * - * @property - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_self->view.itemsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 587, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "View.MemoryView":586 - * - * @property - * def itemsize(self): # <<<<<<<<<<<<<< - * return self.view.itemsize - * - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("View.MemoryView.memoryview.itemsize.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":590 - * - * @property - * def nbytes(self): # <<<<<<<<<<<<<< - * return self.size * self.view.itemsize - * - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_6nbytes_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_6nbytes_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_6nbytes___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_6nbytes___get__(struct __pyx_memoryview_obj *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); - - /* "View.MemoryView":591 - * @property - * def nbytes(self): - * return self.size * self.view.itemsize # <<<<<<<<<<<<<< - * - * @property - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 591, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_self->view.itemsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 591, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_Multiply(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 591, __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_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - - /* "View.MemoryView":590 - * - * @property - * def nbytes(self): # <<<<<<<<<<<<<< - * return self.size * self.view.itemsize - * - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("View.MemoryView.memoryview.nbytes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":594 - * - * @property - * def size(self): # <<<<<<<<<<<<<< - * if self._size is None: - * result = 1 - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4size_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4size_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4size___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4size___get__(struct __pyx_memoryview_obj *__pyx_v_self) { - PyObject *__pyx_v_result = NULL; - PyObject *__pyx_v_length = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - Py_ssize_t *__pyx_t_3; - Py_ssize_t *__pyx_t_4; - Py_ssize_t *__pyx_t_5; - PyObject *__pyx_t_6 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); - - /* "View.MemoryView":595 - * @property - * def size(self): - * if self._size is None: # <<<<<<<<<<<<<< - * result = 1 - * - */ - __pyx_t_1 = (__pyx_v_self->_size == Py_None); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":596 - * def size(self): - * if self._size is None: - * result = 1 # <<<<<<<<<<<<<< - * - * for length in self.view.shape[:self.view.ndim]: - */ - __Pyx_INCREF(__pyx_int_1); - __pyx_v_result = __pyx_int_1; - - /* "View.MemoryView":598 - * result = 1 - * - * for length in self.view.shape[:self.view.ndim]: # <<<<<<<<<<<<<< - * result *= length - * - */ - __pyx_t_4 = (__pyx_v_self->view.shape + __pyx_v_self->view.ndim); - for (__pyx_t_5 = __pyx_v_self->view.shape; __pyx_t_5 < __pyx_t_4; __pyx_t_5++) { - __pyx_t_3 = __pyx_t_5; - __pyx_t_6 = PyInt_FromSsize_t((__pyx_t_3[0])); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 598, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_XDECREF_SET(__pyx_v_length, __pyx_t_6); - __pyx_t_6 = 0; - - /* "View.MemoryView":599 - * - * for length in self.view.shape[:self.view.ndim]: - * result *= length # <<<<<<<<<<<<<< - * - * self._size = result - */ - __pyx_t_6 = PyNumber_InPlaceMultiply(__pyx_v_result, __pyx_v_length); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 599, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF_SET(__pyx_v_result, __pyx_t_6); - __pyx_t_6 = 0; - } - - /* "View.MemoryView":601 - * result *= length - * - * self._size = result # <<<<<<<<<<<<<< - * - * return self._size - */ - __Pyx_INCREF(__pyx_v_result); - __Pyx_GIVEREF(__pyx_v_result); - __Pyx_GOTREF(__pyx_v_self->_size); - __Pyx_DECREF(__pyx_v_self->_size); - __pyx_v_self->_size = __pyx_v_result; - - /* "View.MemoryView":595 - * @property - * def size(self): - * if self._size is None: # <<<<<<<<<<<<<< - * result = 1 - * - */ - } - - /* "View.MemoryView":603 - * self._size = result - * - * return self._size # <<<<<<<<<<<<<< - * - * def __len__(self): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self->_size); - __pyx_r = __pyx_v_self->_size; - goto __pyx_L0; - - /* "View.MemoryView":594 - * - * @property - * def size(self): # <<<<<<<<<<<<<< - * if self._size is None: - * result = 1 - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("View.MemoryView.memoryview.size.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XDECREF(__pyx_v_length); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":605 - * return self._size - * - * def __len__(self): # <<<<<<<<<<<<<< - * if self.view.ndim >= 1: - * return self.view.shape[0] - */ - -/* Python wrapper */ -static Py_ssize_t __pyx_memoryview___len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_memoryview___len__(PyObject *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_10__len__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static Py_ssize_t __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_10__len__(struct __pyx_memoryview_obj *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("__len__", 0); - - /* "View.MemoryView":606 - * - * def __len__(self): - * if self.view.ndim >= 1: # <<<<<<<<<<<<<< - * return self.view.shape[0] - * - */ - __pyx_t_1 = ((__pyx_v_self->view.ndim >= 1) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":607 - * def __len__(self): - * if self.view.ndim >= 1: - * return self.view.shape[0] # <<<<<<<<<<<<<< - * - * return 0 - */ - __pyx_r = (__pyx_v_self->view.shape[0]); - goto __pyx_L0; - - /* "View.MemoryView":606 - * - * def __len__(self): - * if self.view.ndim >= 1: # <<<<<<<<<<<<<< - * return self.view.shape[0] - * - */ - } - - /* "View.MemoryView":609 - * return self.view.shape[0] - * - * return 0 # <<<<<<<<<<<<<< - * - * def __repr__(self): - */ - __pyx_r = 0; - goto __pyx_L0; - - /* "View.MemoryView":605 - * return self._size - * - * def __len__(self): # <<<<<<<<<<<<<< - * if self.view.ndim >= 1: - * return self.view.shape[0] - */ - - /* function exit code */ - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":611 - * return 0 - * - * def __repr__(self): # <<<<<<<<<<<<<< - * return "" % (self.base.__class__.__name__, - * id(self)) - */ - -/* Python wrapper */ -static PyObject *__pyx_memoryview___repr__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_memoryview___repr__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0); - __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_12__repr__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_12__repr__(struct __pyx_memoryview_obj *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__repr__", 0); - - /* "View.MemoryView":612 - * - * def __repr__(self): - * return "" % (self.base.__class__.__name__, # <<<<<<<<<<<<<< - * id(self)) - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 612, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_class); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 612, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_name_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 612, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "View.MemoryView":613 - * def __repr__(self): - * return "" % (self.base.__class__.__name__, - * id(self)) # <<<<<<<<<<<<<< - * - * def __str__(self): - */ - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_id, ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 613, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - - /* "View.MemoryView":612 - * - * def __repr__(self): - * return "" % (self.base.__class__.__name__, # <<<<<<<<<<<<<< - * id(self)) - * - */ - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 612, __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_2); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); - __pyx_t_1 = 0; - __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_MemoryView_of_r_at_0x_x, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 612, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - - /* "View.MemoryView":611 - * return 0 - * - * def __repr__(self): # <<<<<<<<<<<<<< - * return "" % (self.base.__class__.__name__, - * id(self)) - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("View.MemoryView.memoryview.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":615 - * id(self)) - * - * def __str__(self): # <<<<<<<<<<<<<< - * return "" % (self.base.__class__.__name__,) - * - */ - -/* Python wrapper */ -static PyObject *__pyx_memoryview___str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_memoryview___str__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_14__str__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_14__str__(struct __pyx_memoryview_obj *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__str__", 0); - - /* "View.MemoryView":616 - * - * def __str__(self): - * return "" % (self.base.__class__.__name__,) # <<<<<<<<<<<<<< - * - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 616, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_class); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 616, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_name_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 616, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 616, __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 = 0; - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_MemoryView_of_r_object, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 616, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "View.MemoryView":615 - * id(self)) - * - * def __str__(self): # <<<<<<<<<<<<<< - * return "" % (self.base.__class__.__name__,) - * - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("View.MemoryView.memoryview.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":619 - * - * - * def is_c_contig(self): # <<<<<<<<<<<<<< - * cdef __Pyx_memviewslice *mslice - * cdef __Pyx_memviewslice tmp - */ - -/* Python wrapper */ -static PyObject *__pyx_memoryview_is_c_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_memoryview_is_c_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("is_c_contig (wrapper)", 0); - __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_16is_c_contig(((struct __pyx_memoryview_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_16is_c_contig(struct __pyx_memoryview_obj *__pyx_v_self) { - __Pyx_memviewslice *__pyx_v_mslice; - __Pyx_memviewslice __pyx_v_tmp; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_memviewslice *__pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("is_c_contig", 0); - - /* "View.MemoryView":622 - * cdef __Pyx_memviewslice *mslice - * cdef __Pyx_memviewslice tmp - * mslice = get_slice_from_memview(self, &tmp) # <<<<<<<<<<<<<< - * return slice_is_contig(mslice[0], 'C', self.view.ndim) - * - */ - __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_self, (&__pyx_v_tmp)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(2, 622, __pyx_L1_error) - __pyx_v_mslice = __pyx_t_1; - - /* "View.MemoryView":623 - * cdef __Pyx_memviewslice tmp - * mslice = get_slice_from_memview(self, &tmp) - * return slice_is_contig(mslice[0], 'C', self.view.ndim) # <<<<<<<<<<<<<< - * - * def is_f_contig(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_memviewslice_is_contig((__pyx_v_mslice[0]), 'C', __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 623, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - - /* "View.MemoryView":619 - * - * - * def is_c_contig(self): # <<<<<<<<<<<<<< - * cdef __Pyx_memviewslice *mslice - * cdef __Pyx_memviewslice tmp - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("View.MemoryView.memoryview.is_c_contig", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":625 - * return slice_is_contig(mslice[0], 'C', self.view.ndim) - * - * def is_f_contig(self): # <<<<<<<<<<<<<< - * cdef __Pyx_memviewslice *mslice - * cdef __Pyx_memviewslice tmp - */ - -/* Python wrapper */ -static PyObject *__pyx_memoryview_is_f_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_memoryview_is_f_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("is_f_contig (wrapper)", 0); - __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_18is_f_contig(((struct __pyx_memoryview_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_18is_f_contig(struct __pyx_memoryview_obj *__pyx_v_self) { - __Pyx_memviewslice *__pyx_v_mslice; - __Pyx_memviewslice __pyx_v_tmp; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_memviewslice *__pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("is_f_contig", 0); - - /* "View.MemoryView":628 - * cdef __Pyx_memviewslice *mslice - * cdef __Pyx_memviewslice tmp - * mslice = get_slice_from_memview(self, &tmp) # <<<<<<<<<<<<<< - * return slice_is_contig(mslice[0], 'F', self.view.ndim) - * - */ - __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_self, (&__pyx_v_tmp)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(2, 628, __pyx_L1_error) - __pyx_v_mslice = __pyx_t_1; - - /* "View.MemoryView":629 - * cdef __Pyx_memviewslice tmp - * mslice = get_slice_from_memview(self, &tmp) - * return slice_is_contig(mslice[0], 'F', self.view.ndim) # <<<<<<<<<<<<<< - * - * def copy(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_memviewslice_is_contig((__pyx_v_mslice[0]), 'F', __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 629, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - - /* "View.MemoryView":625 - * return slice_is_contig(mslice[0], 'C', self.view.ndim) - * - * def is_f_contig(self): # <<<<<<<<<<<<<< - * cdef __Pyx_memviewslice *mslice - * cdef __Pyx_memviewslice tmp - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("View.MemoryView.memoryview.is_f_contig", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":631 - * return slice_is_contig(mslice[0], 'F', self.view.ndim) - * - * def copy(self): # <<<<<<<<<<<<<< - * cdef __Pyx_memviewslice mslice - * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS - */ - -/* Python wrapper */ -static PyObject *__pyx_memoryview_copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_memoryview_copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("copy (wrapper)", 0); - __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_20copy(((struct __pyx_memoryview_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_20copy(struct __pyx_memoryview_obj *__pyx_v_self) { - __Pyx_memviewslice __pyx_v_mslice; - int __pyx_v_flags; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_memviewslice __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("copy", 0); - - /* "View.MemoryView":633 - * def copy(self): - * cdef __Pyx_memviewslice mslice - * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS # <<<<<<<<<<<<<< - * - * slice_copy(self, &mslice) - */ - __pyx_v_flags = (__pyx_v_self->flags & (~PyBUF_F_CONTIGUOUS)); - - /* "View.MemoryView":635 - * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS - * - * slice_copy(self, &mslice) # <<<<<<<<<<<<<< - * mslice = slice_copy_contig(&mslice, "c", self.view.ndim, - * self.view.itemsize, - */ - __pyx_memoryview_slice_copy(__pyx_v_self, (&__pyx_v_mslice)); - - /* "View.MemoryView":636 - * - * slice_copy(self, &mslice) - * mslice = slice_copy_contig(&mslice, "c", self.view.ndim, # <<<<<<<<<<<<<< - * self.view.itemsize, - * flags|PyBUF_C_CONTIGUOUS, - */ - __pyx_t_1 = __pyx_memoryview_copy_new_contig((&__pyx_v_mslice), ((char *)"c"), __pyx_v_self->view.ndim, __pyx_v_self->view.itemsize, (__pyx_v_flags | PyBUF_C_CONTIGUOUS), __pyx_v_self->dtype_is_object); if (unlikely(PyErr_Occurred())) __PYX_ERR(2, 636, __pyx_L1_error) - __pyx_v_mslice = __pyx_t_1; - - /* "View.MemoryView":641 - * self.dtype_is_object) - * - * return memoryview_copy_from_slice(self, &mslice) # <<<<<<<<<<<<<< - * - * def copy_fortran(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __pyx_memoryview_copy_object_from_slice(__pyx_v_self, (&__pyx_v_mslice)); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 641, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - - /* "View.MemoryView":631 - * return slice_is_contig(mslice[0], 'F', self.view.ndim) - * - * def copy(self): # <<<<<<<<<<<<<< - * cdef __Pyx_memviewslice mslice - * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("View.MemoryView.memoryview.copy", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":643 - * return memoryview_copy_from_slice(self, &mslice) - * - * def copy_fortran(self): # <<<<<<<<<<<<<< - * cdef __Pyx_memviewslice src, dst - * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS - */ - -/* Python wrapper */ -static PyObject *__pyx_memoryview_copy_fortran(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_memoryview_copy_fortran(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("copy_fortran (wrapper)", 0); - __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_22copy_fortran(((struct __pyx_memoryview_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_22copy_fortran(struct __pyx_memoryview_obj *__pyx_v_self) { - __Pyx_memviewslice __pyx_v_src; - __Pyx_memviewslice __pyx_v_dst; - int __pyx_v_flags; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_memviewslice __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("copy_fortran", 0); - - /* "View.MemoryView":645 - * def copy_fortran(self): - * cdef __Pyx_memviewslice src, dst - * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS # <<<<<<<<<<<<<< - * - * slice_copy(self, &src) - */ - __pyx_v_flags = (__pyx_v_self->flags & (~PyBUF_C_CONTIGUOUS)); - - /* "View.MemoryView":647 - * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS - * - * slice_copy(self, &src) # <<<<<<<<<<<<<< - * dst = slice_copy_contig(&src, "fortran", self.view.ndim, - * self.view.itemsize, - */ - __pyx_memoryview_slice_copy(__pyx_v_self, (&__pyx_v_src)); - - /* "View.MemoryView":648 - * - * slice_copy(self, &src) - * dst = slice_copy_contig(&src, "fortran", self.view.ndim, # <<<<<<<<<<<<<< - * self.view.itemsize, - * flags|PyBUF_F_CONTIGUOUS, - */ - __pyx_t_1 = __pyx_memoryview_copy_new_contig((&__pyx_v_src), ((char *)"fortran"), __pyx_v_self->view.ndim, __pyx_v_self->view.itemsize, (__pyx_v_flags | PyBUF_F_CONTIGUOUS), __pyx_v_self->dtype_is_object); if (unlikely(PyErr_Occurred())) __PYX_ERR(2, 648, __pyx_L1_error) - __pyx_v_dst = __pyx_t_1; - - /* "View.MemoryView":653 - * self.dtype_is_object) - * - * return memoryview_copy_from_slice(self, &dst) # <<<<<<<<<<<<<< - * - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __pyx_memoryview_copy_object_from_slice(__pyx_v_self, (&__pyx_v_dst)); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 653, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - - /* "View.MemoryView":643 - * return memoryview_copy_from_slice(self, &mslice) - * - * def copy_fortran(self): # <<<<<<<<<<<<<< - * cdef __Pyx_memviewslice src, dst - * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("View.MemoryView.memoryview.copy_fortran", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "(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___pyx_memoryview_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw___pyx_memoryview_1__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___pyx_memoryview___reduce_cython__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf___pyx_memoryview___reduce_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __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__18, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 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(2, 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("View.MemoryView.memoryview.__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___pyx_memoryview_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static PyObject *__pyx_pw___pyx_memoryview_3__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___pyx_memoryview_2__setstate_cython__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf___pyx_memoryview_2__setstate_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __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__19, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 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(2, 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("View.MemoryView.memoryview.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":657 - * - * @cname('__pyx_memoryview_new') - * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo): # <<<<<<<<<<<<<< - * cdef memoryview result = memoryview(o, flags, dtype_is_object) - * result.typeinfo = typeinfo - */ - -static PyObject *__pyx_memoryview_new(PyObject *__pyx_v_o, int __pyx_v_flags, int __pyx_v_dtype_is_object, __Pyx_TypeInfo *__pyx_v_typeinfo) { - struct __pyx_memoryview_obj *__pyx_v_result = 0; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("memoryview_cwrapper", 0); - - /* "View.MemoryView":658 - * @cname('__pyx_memoryview_new') - * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo): - * cdef memoryview result = memoryview(o, flags, dtype_is_object) # <<<<<<<<<<<<<< - * result.typeinfo = typeinfo - * return result - */ - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_flags); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 658, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_dtype_is_object); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 658, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 658, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_o); - __Pyx_GIVEREF(__pyx_v_o); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_o); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); - __pyx_t_1 = 0; - __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 658, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_result = ((struct __pyx_memoryview_obj *)__pyx_t_2); - __pyx_t_2 = 0; - - /* "View.MemoryView":659 - * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo): - * cdef memoryview result = memoryview(o, flags, dtype_is_object) - * result.typeinfo = typeinfo # <<<<<<<<<<<<<< - * return result - * - */ - __pyx_v_result->typeinfo = __pyx_v_typeinfo; - - /* "View.MemoryView":660 - * cdef memoryview result = memoryview(o, flags, dtype_is_object) - * result.typeinfo = typeinfo - * return result # <<<<<<<<<<<<<< - * - * @cname('__pyx_memoryview_check') - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_result)); - __pyx_r = ((PyObject *)__pyx_v_result); - goto __pyx_L0; - - /* "View.MemoryView":657 - * - * @cname('__pyx_memoryview_new') - * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo): # <<<<<<<<<<<<<< - * cdef memoryview result = memoryview(o, flags, dtype_is_object) - * result.typeinfo = typeinfo - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("View.MemoryView.memoryview_cwrapper", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_result); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":663 - * - * @cname('__pyx_memoryview_check') - * cdef inline bint memoryview_check(object o): # <<<<<<<<<<<<<< - * return isinstance(o, memoryview) - * - */ - -static CYTHON_INLINE int __pyx_memoryview_check(PyObject *__pyx_v_o) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("memoryview_check", 0); - - /* "View.MemoryView":664 - * @cname('__pyx_memoryview_check') - * cdef inline bint memoryview_check(object o): - * return isinstance(o, memoryview) # <<<<<<<<<<<<<< - * - * cdef tuple _unellipsify(object index, int ndim): - */ - __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_o, __pyx_memoryview_type); - __pyx_r = __pyx_t_1; - goto __pyx_L0; - - /* "View.MemoryView":663 - * - * @cname('__pyx_memoryview_check') - * cdef inline bint memoryview_check(object o): # <<<<<<<<<<<<<< - * return isinstance(o, memoryview) - * - */ - - /* function exit code */ - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":666 - * return isinstance(o, memoryview) - * - * cdef tuple _unellipsify(object index, int ndim): # <<<<<<<<<<<<<< - * """ - * Replace all ellipses with full slices and fill incomplete indices with - */ - -static PyObject *_unellipsify(PyObject *__pyx_v_index, int __pyx_v_ndim) { - PyObject *__pyx_v_tup = NULL; - PyObject *__pyx_v_result = NULL; - int __pyx_v_have_slices; - int __pyx_v_seen_ellipsis; - CYTHON_UNUSED PyObject *__pyx_v_idx = NULL; - PyObject *__pyx_v_item = NULL; - Py_ssize_t __pyx_v_nslices; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - Py_ssize_t __pyx_t_5; - PyObject *(*__pyx_t_6)(PyObject *); - PyObject *__pyx_t_7 = NULL; - Py_ssize_t __pyx_t_8; - int __pyx_t_9; - int __pyx_t_10; - PyObject *__pyx_t_11 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("_unellipsify", 0); - - /* "View.MemoryView":671 - * full slices. - * """ - * if not isinstance(index, tuple): # <<<<<<<<<<<<<< - * tup = (index,) - * else: - */ - __pyx_t_1 = PyTuple_Check(__pyx_v_index); - __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":672 - * """ - * if not isinstance(index, tuple): - * tup = (index,) # <<<<<<<<<<<<<< - * else: - * tup = index - */ - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 672, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_index); - __Pyx_GIVEREF(__pyx_v_index); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_index); - __pyx_v_tup = __pyx_t_3; - __pyx_t_3 = 0; - - /* "View.MemoryView":671 - * full slices. - * """ - * if not isinstance(index, tuple): # <<<<<<<<<<<<<< - * tup = (index,) - * else: - */ - goto __pyx_L3; - } - - /* "View.MemoryView":674 - * tup = (index,) - * else: - * tup = index # <<<<<<<<<<<<<< - * - * result = [] - */ - /*else*/ { - __Pyx_INCREF(__pyx_v_index); - __pyx_v_tup = __pyx_v_index; - } - __pyx_L3:; - - /* "View.MemoryView":676 - * tup = index - * - * result = [] # <<<<<<<<<<<<<< - * have_slices = False - * seen_ellipsis = False - */ - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 676, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_result = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; - - /* "View.MemoryView":677 - * - * result = [] - * have_slices = False # <<<<<<<<<<<<<< - * seen_ellipsis = False - * for idx, item in enumerate(tup): - */ - __pyx_v_have_slices = 0; - - /* "View.MemoryView":678 - * result = [] - * have_slices = False - * seen_ellipsis = False # <<<<<<<<<<<<<< - * for idx, item in enumerate(tup): - * if item is Ellipsis: - */ - __pyx_v_seen_ellipsis = 0; - - /* "View.MemoryView":679 - * have_slices = False - * seen_ellipsis = False - * for idx, item in enumerate(tup): # <<<<<<<<<<<<<< - * if item is Ellipsis: - * if not seen_ellipsis: - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_t_3 = __pyx_int_0; - if (likely(PyList_CheckExact(__pyx_v_tup)) || PyTuple_CheckExact(__pyx_v_tup)) { - __pyx_t_4 = __pyx_v_tup; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0; - __pyx_t_6 = NULL; - } else { - __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_tup); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 679, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 679, __pyx_L1_error) - } - for (;;) { - if (likely(!__pyx_t_6)) { - if (likely(PyList_CheckExact(__pyx_t_4))) { - if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(2, 679, __pyx_L1_error) - #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 679, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - #endif - } else { - if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(2, 679, __pyx_L1_error) - #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 679, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - #endif - } - } else { - __pyx_t_7 = __pyx_t_6(__pyx_t_4); - if (unlikely(!__pyx_t_7)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(2, 679, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_7); - } - __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_INCREF(__pyx_t_3); - __Pyx_XDECREF_SET(__pyx_v_idx, __pyx_t_3); - __pyx_t_7 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 679, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); - __pyx_t_3 = __pyx_t_7; - __pyx_t_7 = 0; - - /* "View.MemoryView":680 - * seen_ellipsis = False - * for idx, item in enumerate(tup): - * if item is Ellipsis: # <<<<<<<<<<<<<< - * if not seen_ellipsis: - * result.extend([slice(None)] * (ndim - len(tup) + 1)) - */ - __pyx_t_2 = (__pyx_v_item == __pyx_builtin_Ellipsis); - __pyx_t_1 = (__pyx_t_2 != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":681 - * for idx, item in enumerate(tup): - * if item is Ellipsis: - * if not seen_ellipsis: # <<<<<<<<<<<<<< - * result.extend([slice(None)] * (ndim - len(tup) + 1)) - * seen_ellipsis = True - */ - __pyx_t_1 = ((!(__pyx_v_seen_ellipsis != 0)) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":682 - * if item is Ellipsis: - * if not seen_ellipsis: - * result.extend([slice(None)] * (ndim - len(tup) + 1)) # <<<<<<<<<<<<<< - * seen_ellipsis = True - * else: - */ - __pyx_t_8 = PyObject_Length(__pyx_v_tup); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(2, 682, __pyx_L1_error) - __pyx_t_7 = PyList_New(1 * ((((__pyx_v_ndim - __pyx_t_8) + 1)<0) ? 0:((__pyx_v_ndim - __pyx_t_8) + 1))); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 682, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - { Py_ssize_t __pyx_temp; - for (__pyx_temp=0; __pyx_temp < ((__pyx_v_ndim - __pyx_t_8) + 1); __pyx_temp++) { - __Pyx_INCREF(__pyx_slice_); - __Pyx_GIVEREF(__pyx_slice_); - PyList_SET_ITEM(__pyx_t_7, __pyx_temp, __pyx_slice_); - } - } - __pyx_t_9 = __Pyx_PyList_Extend(__pyx_v_result, __pyx_t_7); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(2, 682, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "View.MemoryView":683 - * if not seen_ellipsis: - * result.extend([slice(None)] * (ndim - len(tup) + 1)) - * seen_ellipsis = True # <<<<<<<<<<<<<< - * else: - * result.append(slice(None)) - */ - __pyx_v_seen_ellipsis = 1; - - /* "View.MemoryView":681 - * for idx, item in enumerate(tup): - * if item is Ellipsis: - * if not seen_ellipsis: # <<<<<<<<<<<<<< - * result.extend([slice(None)] * (ndim - len(tup) + 1)) - * seen_ellipsis = True - */ - goto __pyx_L7; - } - - /* "View.MemoryView":685 - * seen_ellipsis = True - * else: - * result.append(slice(None)) # <<<<<<<<<<<<<< - * have_slices = True - * else: - */ - /*else*/ { - __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_slice_); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(2, 685, __pyx_L1_error) - } - __pyx_L7:; - - /* "View.MemoryView":686 - * else: - * result.append(slice(None)) - * have_slices = True # <<<<<<<<<<<<<< - * else: - * if not isinstance(item, slice) and not PyIndex_Check(item): - */ - __pyx_v_have_slices = 1; - - /* "View.MemoryView":680 - * seen_ellipsis = False - * for idx, item in enumerate(tup): - * if item is Ellipsis: # <<<<<<<<<<<<<< - * if not seen_ellipsis: - * result.extend([slice(None)] * (ndim - len(tup) + 1)) - */ - goto __pyx_L6; - } - - /* "View.MemoryView":688 - * have_slices = True - * else: - * if not isinstance(item, slice) and not PyIndex_Check(item): # <<<<<<<<<<<<<< - * raise TypeError("Cannot index with type '%s'" % type(item)) - * - */ - /*else*/ { - __pyx_t_2 = PySlice_Check(__pyx_v_item); - __pyx_t_10 = ((!(__pyx_t_2 != 0)) != 0); - if (__pyx_t_10) { - } else { - __pyx_t_1 = __pyx_t_10; - goto __pyx_L9_bool_binop_done; - } - __pyx_t_10 = ((!(PyIndex_Check(__pyx_v_item) != 0)) != 0); - __pyx_t_1 = __pyx_t_10; - __pyx_L9_bool_binop_done:; - if (unlikely(__pyx_t_1)) { - - /* "View.MemoryView":689 - * else: - * if not isinstance(item, slice) and not PyIndex_Check(item): - * raise TypeError("Cannot index with type '%s'" % type(item)) # <<<<<<<<<<<<<< - * - * have_slices = have_slices or isinstance(item, slice) - */ - __pyx_t_7 = __Pyx_PyString_FormatSafe(__pyx_kp_s_Cannot_index_with_type_s, ((PyObject *)Py_TYPE(__pyx_v_item))); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 689, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_7); if (unlikely(!__pyx_t_11)) __PYX_ERR(2, 689, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_Raise(__pyx_t_11, 0, 0, 0); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __PYX_ERR(2, 689, __pyx_L1_error) - - /* "View.MemoryView":688 - * have_slices = True - * else: - * if not isinstance(item, slice) and not PyIndex_Check(item): # <<<<<<<<<<<<<< - * raise TypeError("Cannot index with type '%s'" % type(item)) - * - */ - } - - /* "View.MemoryView":691 - * raise TypeError("Cannot index with type '%s'" % type(item)) - * - * have_slices = have_slices or isinstance(item, slice) # <<<<<<<<<<<<<< - * result.append(item) - * - */ - __pyx_t_10 = (__pyx_v_have_slices != 0); - if (!__pyx_t_10) { - } else { - __pyx_t_1 = __pyx_t_10; - goto __pyx_L11_bool_binop_done; - } - __pyx_t_10 = PySlice_Check(__pyx_v_item); - __pyx_t_2 = (__pyx_t_10 != 0); - __pyx_t_1 = __pyx_t_2; - __pyx_L11_bool_binop_done:; - __pyx_v_have_slices = __pyx_t_1; - - /* "View.MemoryView":692 - * - * have_slices = have_slices or isinstance(item, slice) - * result.append(item) # <<<<<<<<<<<<<< - * - * nslices = ndim - len(result) - */ - __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_v_item); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(2, 692, __pyx_L1_error) - } - __pyx_L6:; - - /* "View.MemoryView":679 - * have_slices = False - * seen_ellipsis = False - * for idx, item in enumerate(tup): # <<<<<<<<<<<<<< - * if item is Ellipsis: - * if not seen_ellipsis: - */ - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "View.MemoryView":694 - * result.append(item) - * - * nslices = ndim - len(result) # <<<<<<<<<<<<<< - * if nslices: - * result.extend([slice(None)] * nslices) - */ - __pyx_t_5 = PyList_GET_SIZE(__pyx_v_result); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(2, 694, __pyx_L1_error) - __pyx_v_nslices = (__pyx_v_ndim - __pyx_t_5); - - /* "View.MemoryView":695 - * - * nslices = ndim - len(result) - * if nslices: # <<<<<<<<<<<<<< - * result.extend([slice(None)] * nslices) - * - */ - __pyx_t_1 = (__pyx_v_nslices != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":696 - * nslices = ndim - len(result) - * if nslices: - * result.extend([slice(None)] * nslices) # <<<<<<<<<<<<<< - * - * return have_slices or nslices, tuple(result) - */ - __pyx_t_3 = PyList_New(1 * ((__pyx_v_nslices<0) ? 0:__pyx_v_nslices)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 696, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - { Py_ssize_t __pyx_temp; - for (__pyx_temp=0; __pyx_temp < __pyx_v_nslices; __pyx_temp++) { - __Pyx_INCREF(__pyx_slice_); - __Pyx_GIVEREF(__pyx_slice_); - PyList_SET_ITEM(__pyx_t_3, __pyx_temp, __pyx_slice_); - } - } - __pyx_t_9 = __Pyx_PyList_Extend(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(2, 696, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "View.MemoryView":695 - * - * nslices = ndim - len(result) - * if nslices: # <<<<<<<<<<<<<< - * result.extend([slice(None)] * nslices) - * - */ - } - - /* "View.MemoryView":698 - * result.extend([slice(None)] * nslices) - * - * return have_slices or nslices, tuple(result) # <<<<<<<<<<<<<< - * - * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): - */ - __Pyx_XDECREF(__pyx_r); - if (!__pyx_v_have_slices) { - } else { - __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_v_have_slices); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 698, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L14_bool_binop_done; - } - __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_nslices); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 698, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = __pyx_t_4; - __pyx_t_4 = 0; - __pyx_L14_bool_binop_done:; - __pyx_t_4 = PyList_AsTuple(__pyx_v_result); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 698, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(2, 698, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_4); - __pyx_t_3 = 0; - __pyx_t_4 = 0; - __pyx_r = ((PyObject*)__pyx_t_11); - __pyx_t_11 = 0; - goto __pyx_L0; - - /* "View.MemoryView":666 - * return isinstance(o, memoryview) - * - * cdef tuple _unellipsify(object index, int ndim): # <<<<<<<<<<<<<< - * """ - * Replace all ellipses with full slices and fill incomplete indices with - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_AddTraceback("View.MemoryView._unellipsify", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_tup); - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XDECREF(__pyx_v_idx); - __Pyx_XDECREF(__pyx_v_item); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":700 - * return have_slices or nslices, tuple(result) - * - * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): # <<<<<<<<<<<<<< - * for suboffset in suboffsets[:ndim]: - * if suboffset >= 0: - */ - -static PyObject *assert_direct_dimensions(Py_ssize_t *__pyx_v_suboffsets, int __pyx_v_ndim) { - Py_ssize_t __pyx_v_suboffset; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - Py_ssize_t *__pyx_t_1; - Py_ssize_t *__pyx_t_2; - Py_ssize_t *__pyx_t_3; - int __pyx_t_4; - PyObject *__pyx_t_5 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("assert_direct_dimensions", 0); - - /* "View.MemoryView":701 - * - * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): - * for suboffset in suboffsets[:ndim]: # <<<<<<<<<<<<<< - * if suboffset >= 0: - * raise ValueError("Indirect dimensions not supported") - */ - __pyx_t_2 = (__pyx_v_suboffsets + __pyx_v_ndim); - for (__pyx_t_3 = __pyx_v_suboffsets; __pyx_t_3 < __pyx_t_2; __pyx_t_3++) { - __pyx_t_1 = __pyx_t_3; - __pyx_v_suboffset = (__pyx_t_1[0]); - - /* "View.MemoryView":702 - * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): - * for suboffset in suboffsets[:ndim]: - * if suboffset >= 0: # <<<<<<<<<<<<<< - * raise ValueError("Indirect dimensions not supported") - * - */ - __pyx_t_4 = ((__pyx_v_suboffset >= 0) != 0); - if (unlikely(__pyx_t_4)) { - - /* "View.MemoryView":703 - * for suboffset in suboffsets[:ndim]: - * if suboffset >= 0: - * raise ValueError("Indirect dimensions not supported") # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__20, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 703, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_Raise(__pyx_t_5, 0, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(2, 703, __pyx_L1_error) - - /* "View.MemoryView":702 - * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): - * for suboffset in suboffsets[:ndim]: - * if suboffset >= 0: # <<<<<<<<<<<<<< - * raise ValueError("Indirect dimensions not supported") - * - */ - } - } - - /* "View.MemoryView":700 - * return have_slices or nslices, tuple(result) - * - * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): # <<<<<<<<<<<<<< - * for suboffset in suboffsets[:ndim]: - * if suboffset >= 0: - */ - - /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("View.MemoryView.assert_direct_dimensions", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":710 - * - * @cname('__pyx_memview_slice') - * cdef memoryview memview_slice(memoryview memview, object indices): # <<<<<<<<<<<<<< - * cdef int new_ndim = 0, suboffset_dim = -1, dim - * cdef bint negative_step - */ - -static struct __pyx_memoryview_obj *__pyx_memview_slice(struct __pyx_memoryview_obj *__pyx_v_memview, PyObject *__pyx_v_indices) { - int __pyx_v_new_ndim; - int __pyx_v_suboffset_dim; - int __pyx_v_dim; - __Pyx_memviewslice __pyx_v_src; - __Pyx_memviewslice __pyx_v_dst; - __Pyx_memviewslice *__pyx_v_p_src; - struct __pyx_memoryviewslice_obj *__pyx_v_memviewsliceobj = 0; - __Pyx_memviewslice *__pyx_v_p_dst; - int *__pyx_v_p_suboffset_dim; - Py_ssize_t __pyx_v_start; - Py_ssize_t __pyx_v_stop; - Py_ssize_t __pyx_v_step; - int __pyx_v_have_start; - int __pyx_v_have_stop; - int __pyx_v_have_step; - PyObject *__pyx_v_index = NULL; - struct __pyx_memoryview_obj *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - struct __pyx_memoryview_obj *__pyx_t_4; - char *__pyx_t_5; - int __pyx_t_6; - Py_ssize_t __pyx_t_7; - PyObject *(*__pyx_t_8)(PyObject *); - PyObject *__pyx_t_9 = NULL; - Py_ssize_t __pyx_t_10; - int __pyx_t_11; - Py_ssize_t __pyx_t_12; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("memview_slice", 0); - - /* "View.MemoryView":711 - * @cname('__pyx_memview_slice') - * cdef memoryview memview_slice(memoryview memview, object indices): - * cdef int new_ndim = 0, suboffset_dim = -1, dim # <<<<<<<<<<<<<< - * cdef bint negative_step - * cdef __Pyx_memviewslice src, dst - */ - __pyx_v_new_ndim = 0; - __pyx_v_suboffset_dim = -1; - - /* "View.MemoryView":718 - * - * - * memset(&dst, 0, sizeof(dst)) # <<<<<<<<<<<<<< - * - * cdef _memoryviewslice memviewsliceobj - */ - (void)(memset((&__pyx_v_dst), 0, (sizeof(__pyx_v_dst)))); - - /* "View.MemoryView":722 - * cdef _memoryviewslice memviewsliceobj - * - * assert memview.view.ndim > 0 # <<<<<<<<<<<<<< - * - * if isinstance(memview, _memoryviewslice): - */ - #ifndef CYTHON_WITHOUT_ASSERTIONS - if (unlikely(!Py_OptimizeFlag)) { - if (unlikely(!((__pyx_v_memview->view.ndim > 0) != 0))) { - PyErr_SetNone(PyExc_AssertionError); - __PYX_ERR(2, 722, __pyx_L1_error) - } - } - #endif - - /* "View.MemoryView":724 - * assert memview.view.ndim > 0 - * - * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< - * memviewsliceobj = memview - * p_src = &memviewsliceobj.from_slice - */ - __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":725 - * - * if isinstance(memview, _memoryviewslice): - * memviewsliceobj = memview # <<<<<<<<<<<<<< - * p_src = &memviewsliceobj.from_slice - * else: - */ - if (!(likely(((((PyObject *)__pyx_v_memview)) == Py_None) || likely(__Pyx_TypeTest(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type))))) __PYX_ERR(2, 725, __pyx_L1_error) - __pyx_t_3 = ((PyObject *)__pyx_v_memview); - __Pyx_INCREF(__pyx_t_3); - __pyx_v_memviewsliceobj = ((struct __pyx_memoryviewslice_obj *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "View.MemoryView":726 - * if isinstance(memview, _memoryviewslice): - * memviewsliceobj = memview - * p_src = &memviewsliceobj.from_slice # <<<<<<<<<<<<<< - * else: - * slice_copy(memview, &src) - */ - __pyx_v_p_src = (&__pyx_v_memviewsliceobj->from_slice); - - /* "View.MemoryView":724 - * assert memview.view.ndim > 0 - * - * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< - * memviewsliceobj = memview - * p_src = &memviewsliceobj.from_slice - */ - goto __pyx_L3; - } - - /* "View.MemoryView":728 - * p_src = &memviewsliceobj.from_slice - * else: - * slice_copy(memview, &src) # <<<<<<<<<<<<<< - * p_src = &src - * - */ - /*else*/ { - __pyx_memoryview_slice_copy(__pyx_v_memview, (&__pyx_v_src)); - - /* "View.MemoryView":729 - * else: - * slice_copy(memview, &src) - * p_src = &src # <<<<<<<<<<<<<< - * - * - */ - __pyx_v_p_src = (&__pyx_v_src); - } - __pyx_L3:; - - /* "View.MemoryView":735 - * - * - * dst.memview = p_src.memview # <<<<<<<<<<<<<< - * dst.data = p_src.data - * - */ - __pyx_t_4 = __pyx_v_p_src->memview; - __pyx_v_dst.memview = __pyx_t_4; - - /* "View.MemoryView":736 - * - * dst.memview = p_src.memview - * dst.data = p_src.data # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_5 = __pyx_v_p_src->data; - __pyx_v_dst.data = __pyx_t_5; - - /* "View.MemoryView":741 - * - * - * cdef __Pyx_memviewslice *p_dst = &dst # <<<<<<<<<<<<<< - * cdef int *p_suboffset_dim = &suboffset_dim - * cdef Py_ssize_t start, stop, step - */ - __pyx_v_p_dst = (&__pyx_v_dst); - - /* "View.MemoryView":742 - * - * cdef __Pyx_memviewslice *p_dst = &dst - * cdef int *p_suboffset_dim = &suboffset_dim # <<<<<<<<<<<<<< - * cdef Py_ssize_t start, stop, step - * cdef bint have_start, have_stop, have_step - */ - __pyx_v_p_suboffset_dim = (&__pyx_v_suboffset_dim); - - /* "View.MemoryView":746 - * cdef bint have_start, have_stop, have_step - * - * for dim, index in enumerate(indices): # <<<<<<<<<<<<<< - * if PyIndex_Check(index): - * slice_memviewslice( - */ - __pyx_t_6 = 0; - if (likely(PyList_CheckExact(__pyx_v_indices)) || PyTuple_CheckExact(__pyx_v_indices)) { - __pyx_t_3 = __pyx_v_indices; __Pyx_INCREF(__pyx_t_3); __pyx_t_7 = 0; - __pyx_t_8 = NULL; - } else { - __pyx_t_7 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_indices); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 746, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_8 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 746, __pyx_L1_error) - } - for (;;) { - if (likely(!__pyx_t_8)) { - if (likely(PyList_CheckExact(__pyx_t_3))) { - if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_9 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_9); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(2, 746, __pyx_L1_error) - #else - __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 746, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - #endif - } else { - if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_9); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(2, 746, __pyx_L1_error) - #else - __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 746, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - #endif - } - } else { - __pyx_t_9 = __pyx_t_8(__pyx_t_3); - 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(2, 746, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_9); - } - __Pyx_XDECREF_SET(__pyx_v_index, __pyx_t_9); - __pyx_t_9 = 0; - __pyx_v_dim = __pyx_t_6; - __pyx_t_6 = (__pyx_t_6 + 1); - - /* "View.MemoryView":747 - * - * for dim, index in enumerate(indices): - * if PyIndex_Check(index): # <<<<<<<<<<<<<< - * slice_memviewslice( - * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim], - */ - __pyx_t_2 = (PyIndex_Check(__pyx_v_index) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":751 - * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim], - * dim, new_ndim, p_suboffset_dim, - * index, 0, 0, # start, stop, step # <<<<<<<<<<<<<< - * 0, 0, 0, # have_{start,stop,step} - * False) - */ - __pyx_t_10 = __Pyx_PyIndex_AsSsize_t(__pyx_v_index); if (unlikely((__pyx_t_10 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 751, __pyx_L1_error) - - /* "View.MemoryView":748 - * for dim, index in enumerate(indices): - * if PyIndex_Check(index): - * slice_memviewslice( # <<<<<<<<<<<<<< - * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim], - * dim, new_ndim, p_suboffset_dim, - */ - __pyx_t_11 = __pyx_memoryview_slice_memviewslice(__pyx_v_p_dst, (__pyx_v_p_src->shape[__pyx_v_dim]), (__pyx_v_p_src->strides[__pyx_v_dim]), (__pyx_v_p_src->suboffsets[__pyx_v_dim]), __pyx_v_dim, __pyx_v_new_ndim, __pyx_v_p_suboffset_dim, __pyx_t_10, 0, 0, 0, 0, 0, 0); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(2, 748, __pyx_L1_error) - - /* "View.MemoryView":747 - * - * for dim, index in enumerate(indices): - * if PyIndex_Check(index): # <<<<<<<<<<<<<< - * slice_memviewslice( - * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim], - */ - goto __pyx_L6; - } - - /* "View.MemoryView":754 - * 0, 0, 0, # have_{start,stop,step} - * False) - * elif index is None: # <<<<<<<<<<<<<< - * p_dst.shape[new_ndim] = 1 - * p_dst.strides[new_ndim] = 0 - */ - __pyx_t_2 = (__pyx_v_index == Py_None); - __pyx_t_1 = (__pyx_t_2 != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":755 - * False) - * elif index is None: - * p_dst.shape[new_ndim] = 1 # <<<<<<<<<<<<<< - * p_dst.strides[new_ndim] = 0 - * p_dst.suboffsets[new_ndim] = -1 - */ - (__pyx_v_p_dst->shape[__pyx_v_new_ndim]) = 1; - - /* "View.MemoryView":756 - * elif index is None: - * p_dst.shape[new_ndim] = 1 - * p_dst.strides[new_ndim] = 0 # <<<<<<<<<<<<<< - * p_dst.suboffsets[new_ndim] = -1 - * new_ndim += 1 - */ - (__pyx_v_p_dst->strides[__pyx_v_new_ndim]) = 0; - - /* "View.MemoryView":757 - * p_dst.shape[new_ndim] = 1 - * p_dst.strides[new_ndim] = 0 - * p_dst.suboffsets[new_ndim] = -1 # <<<<<<<<<<<<<< - * new_ndim += 1 - * else: - */ - (__pyx_v_p_dst->suboffsets[__pyx_v_new_ndim]) = -1L; - - /* "View.MemoryView":758 - * p_dst.strides[new_ndim] = 0 - * p_dst.suboffsets[new_ndim] = -1 - * new_ndim += 1 # <<<<<<<<<<<<<< - * else: - * start = index.start or 0 - */ - __pyx_v_new_ndim = (__pyx_v_new_ndim + 1); - - /* "View.MemoryView":754 - * 0, 0, 0, # have_{start,stop,step} - * False) - * elif index is None: # <<<<<<<<<<<<<< - * p_dst.shape[new_ndim] = 1 - * p_dst.strides[new_ndim] = 0 - */ - goto __pyx_L6; - } - - /* "View.MemoryView":760 - * new_ndim += 1 - * else: - * start = index.start or 0 # <<<<<<<<<<<<<< - * stop = index.stop or 0 - * step = index.step or 0 - */ - /*else*/ { - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_start); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 760, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(2, 760, __pyx_L1_error) - if (!__pyx_t_1) { - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } else { - __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 760, __pyx_L1_error) - __pyx_t_10 = __pyx_t_12; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - goto __pyx_L7_bool_binop_done; - } - __pyx_t_10 = 0; - __pyx_L7_bool_binop_done:; - __pyx_v_start = __pyx_t_10; - - /* "View.MemoryView":761 - * else: - * start = index.start or 0 - * stop = index.stop or 0 # <<<<<<<<<<<<<< - * step = index.step or 0 - * - */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_stop); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 761, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(2, 761, __pyx_L1_error) - if (!__pyx_t_1) { - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } else { - __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 761, __pyx_L1_error) - __pyx_t_10 = __pyx_t_12; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - goto __pyx_L9_bool_binop_done; - } - __pyx_t_10 = 0; - __pyx_L9_bool_binop_done:; - __pyx_v_stop = __pyx_t_10; - - /* "View.MemoryView":762 - * start = index.start or 0 - * stop = index.stop or 0 - * step = index.step or 0 # <<<<<<<<<<<<<< - * - * have_start = index.start is not None - */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_step); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 762, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(2, 762, __pyx_L1_error) - if (!__pyx_t_1) { - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } else { - __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 762, __pyx_L1_error) - __pyx_t_10 = __pyx_t_12; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - goto __pyx_L11_bool_binop_done; - } - __pyx_t_10 = 0; - __pyx_L11_bool_binop_done:; - __pyx_v_step = __pyx_t_10; - - /* "View.MemoryView":764 - * step = index.step or 0 - * - * have_start = index.start is not None # <<<<<<<<<<<<<< - * have_stop = index.stop is not None - * have_step = index.step is not None - */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_start); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 764, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = (__pyx_t_9 != Py_None); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_v_have_start = __pyx_t_1; - - /* "View.MemoryView":765 - * - * have_start = index.start is not None - * have_stop = index.stop is not None # <<<<<<<<<<<<<< - * have_step = index.step is not None - * - */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_stop); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 765, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = (__pyx_t_9 != Py_None); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_v_have_stop = __pyx_t_1; - - /* "View.MemoryView":766 - * have_start = index.start is not None - * have_stop = index.stop is not None - * have_step = index.step is not None # <<<<<<<<<<<<<< - * - * slice_memviewslice( - */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_step); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 766, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = (__pyx_t_9 != Py_None); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_v_have_step = __pyx_t_1; - - /* "View.MemoryView":768 - * have_step = index.step is not None - * - * slice_memviewslice( # <<<<<<<<<<<<<< - * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim], - * dim, new_ndim, p_suboffset_dim, - */ - __pyx_t_11 = __pyx_memoryview_slice_memviewslice(__pyx_v_p_dst, (__pyx_v_p_src->shape[__pyx_v_dim]), (__pyx_v_p_src->strides[__pyx_v_dim]), (__pyx_v_p_src->suboffsets[__pyx_v_dim]), __pyx_v_dim, __pyx_v_new_ndim, __pyx_v_p_suboffset_dim, __pyx_v_start, __pyx_v_stop, __pyx_v_step, __pyx_v_have_start, __pyx_v_have_stop, __pyx_v_have_step, 1); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(2, 768, __pyx_L1_error) - - /* "View.MemoryView":774 - * have_start, have_stop, have_step, - * True) - * new_ndim += 1 # <<<<<<<<<<<<<< - * - * if isinstance(memview, _memoryviewslice): - */ - __pyx_v_new_ndim = (__pyx_v_new_ndim + 1); - } - __pyx_L6:; - - /* "View.MemoryView":746 - * cdef bint have_start, have_stop, have_step - * - * for dim, index in enumerate(indices): # <<<<<<<<<<<<<< - * if PyIndex_Check(index): - * slice_memviewslice( - */ - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "View.MemoryView":776 - * new_ndim += 1 - * - * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< - * return memoryview_fromslice(dst, new_ndim, - * memviewsliceobj.to_object_func, - */ - __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":777 - * - * if isinstance(memview, _memoryviewslice): - * return memoryview_fromslice(dst, new_ndim, # <<<<<<<<<<<<<< - * memviewsliceobj.to_object_func, - * memviewsliceobj.to_dtype_func, - */ - __Pyx_XDECREF(((PyObject *)__pyx_r)); - - /* "View.MemoryView":778 - * if isinstance(memview, _memoryviewslice): - * return memoryview_fromslice(dst, new_ndim, - * memviewsliceobj.to_object_func, # <<<<<<<<<<<<<< - * memviewsliceobj.to_dtype_func, - * memview.dtype_is_object) - */ - if (unlikely(!__pyx_v_memviewsliceobj)) { __Pyx_RaiseUnboundLocalError("memviewsliceobj"); __PYX_ERR(2, 778, __pyx_L1_error) } - - /* "View.MemoryView":779 - * return memoryview_fromslice(dst, new_ndim, - * memviewsliceobj.to_object_func, - * memviewsliceobj.to_dtype_func, # <<<<<<<<<<<<<< - * memview.dtype_is_object) - * else: - */ - if (unlikely(!__pyx_v_memviewsliceobj)) { __Pyx_RaiseUnboundLocalError("memviewsliceobj"); __PYX_ERR(2, 779, __pyx_L1_error) } - - /* "View.MemoryView":777 - * - * if isinstance(memview, _memoryviewslice): - * return memoryview_fromslice(dst, new_ndim, # <<<<<<<<<<<<<< - * memviewsliceobj.to_object_func, - * memviewsliceobj.to_dtype_func, - */ - __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_dst, __pyx_v_new_ndim, __pyx_v_memviewsliceobj->to_object_func, __pyx_v_memviewsliceobj->to_dtype_func, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 777, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_memoryview_type))))) __PYX_ERR(2, 777, __pyx_L1_error) - __pyx_r = ((struct __pyx_memoryview_obj *)__pyx_t_3); - __pyx_t_3 = 0; - goto __pyx_L0; - - /* "View.MemoryView":776 - * new_ndim += 1 - * - * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< - * return memoryview_fromslice(dst, new_ndim, - * memviewsliceobj.to_object_func, - */ - } - - /* "View.MemoryView":782 - * memview.dtype_is_object) - * else: - * return memoryview_fromslice(dst, new_ndim, NULL, NULL, # <<<<<<<<<<<<<< - * memview.dtype_is_object) - * - */ - /*else*/ { - __Pyx_XDECREF(((PyObject *)__pyx_r)); - - /* "View.MemoryView":783 - * else: - * return memoryview_fromslice(dst, new_ndim, NULL, NULL, - * memview.dtype_is_object) # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_dst, __pyx_v_new_ndim, NULL, NULL, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 782, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "View.MemoryView":782 - * memview.dtype_is_object) - * else: - * return memoryview_fromslice(dst, new_ndim, NULL, NULL, # <<<<<<<<<<<<<< - * memview.dtype_is_object) - * - */ - if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_memoryview_type))))) __PYX_ERR(2, 782, __pyx_L1_error) - __pyx_r = ((struct __pyx_memoryview_obj *)__pyx_t_3); - __pyx_t_3 = 0; - goto __pyx_L0; - } - - /* "View.MemoryView":710 - * - * @cname('__pyx_memview_slice') - * cdef memoryview memview_slice(memoryview memview, object indices): # <<<<<<<<<<<<<< - * cdef int new_ndim = 0, suboffset_dim = -1, dim - * cdef bint negative_step - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("View.MemoryView.memview_slice", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_memviewsliceobj); - __Pyx_XDECREF(__pyx_v_index); - __Pyx_XGIVEREF((PyObject *)__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":807 - * - * @cname('__pyx_memoryview_slice_memviewslice') - * cdef int slice_memviewslice( # <<<<<<<<<<<<<< - * __Pyx_memviewslice *dst, - * Py_ssize_t shape, Py_ssize_t stride, Py_ssize_t suboffset, - */ - -static int __pyx_memoryview_slice_memviewslice(__Pyx_memviewslice *__pyx_v_dst, Py_ssize_t __pyx_v_shape, Py_ssize_t __pyx_v_stride, Py_ssize_t __pyx_v_suboffset, int __pyx_v_dim, int __pyx_v_new_ndim, int *__pyx_v_suboffset_dim, Py_ssize_t __pyx_v_start, Py_ssize_t __pyx_v_stop, Py_ssize_t __pyx_v_step, int __pyx_v_have_start, int __pyx_v_have_stop, int __pyx_v_have_step, int __pyx_v_is_slice) { - Py_ssize_t __pyx_v_new_shape; - int __pyx_v_negative_step; - int __pyx_r; - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - - /* "View.MemoryView":827 - * cdef bint negative_step - * - * if not is_slice: # <<<<<<<<<<<<<< - * - * if start < 0: - */ - __pyx_t_1 = ((!(__pyx_v_is_slice != 0)) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":829 - * if not is_slice: - * - * if start < 0: # <<<<<<<<<<<<<< - * start += shape - * if not 0 <= start < shape: - */ - __pyx_t_1 = ((__pyx_v_start < 0) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":830 - * - * if start < 0: - * start += shape # <<<<<<<<<<<<<< - * if not 0 <= start < shape: - * _err_dim(IndexError, "Index out of bounds (axis %d)", dim) - */ - __pyx_v_start = (__pyx_v_start + __pyx_v_shape); - - /* "View.MemoryView":829 - * if not is_slice: - * - * if start < 0: # <<<<<<<<<<<<<< - * start += shape - * if not 0 <= start < shape: - */ - } - - /* "View.MemoryView":831 - * if start < 0: - * start += shape - * if not 0 <= start < shape: # <<<<<<<<<<<<<< - * _err_dim(IndexError, "Index out of bounds (axis %d)", dim) - * else: - */ - __pyx_t_1 = (0 <= __pyx_v_start); - if (__pyx_t_1) { - __pyx_t_1 = (__pyx_v_start < __pyx_v_shape); - } - __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":832 - * start += shape - * if not 0 <= start < shape: - * _err_dim(IndexError, "Index out of bounds (axis %d)", dim) # <<<<<<<<<<<<<< - * else: - * - */ - __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_IndexError, ((char *)"Index out of bounds (axis %d)"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(2, 832, __pyx_L1_error) - - /* "View.MemoryView":831 - * if start < 0: - * start += shape - * if not 0 <= start < shape: # <<<<<<<<<<<<<< - * _err_dim(IndexError, "Index out of bounds (axis %d)", dim) - * else: - */ - } - - /* "View.MemoryView":827 - * cdef bint negative_step - * - * if not is_slice: # <<<<<<<<<<<<<< - * - * if start < 0: - */ - goto __pyx_L3; - } - - /* "View.MemoryView":835 - * else: - * - * negative_step = have_step != 0 and step < 0 # <<<<<<<<<<<<<< - * - * if have_step and step == 0: - */ - /*else*/ { - __pyx_t_1 = ((__pyx_v_have_step != 0) != 0); - if (__pyx_t_1) { - } else { - __pyx_t_2 = __pyx_t_1; - goto __pyx_L6_bool_binop_done; - } - __pyx_t_1 = ((__pyx_v_step < 0) != 0); - __pyx_t_2 = __pyx_t_1; - __pyx_L6_bool_binop_done:; - __pyx_v_negative_step = __pyx_t_2; - - /* "View.MemoryView":837 - * negative_step = have_step != 0 and step < 0 - * - * if have_step and step == 0: # <<<<<<<<<<<<<< - * _err_dim(ValueError, "Step may not be zero (axis %d)", dim) - * - */ - __pyx_t_1 = (__pyx_v_have_step != 0); - if (__pyx_t_1) { - } else { - __pyx_t_2 = __pyx_t_1; - goto __pyx_L9_bool_binop_done; - } - __pyx_t_1 = ((__pyx_v_step == 0) != 0); - __pyx_t_2 = __pyx_t_1; - __pyx_L9_bool_binop_done:; - if (__pyx_t_2) { - - /* "View.MemoryView":838 - * - * if have_step and step == 0: - * _err_dim(ValueError, "Step may not be zero (axis %d)", dim) # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_ValueError, ((char *)"Step may not be zero (axis %d)"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(2, 838, __pyx_L1_error) - - /* "View.MemoryView":837 - * negative_step = have_step != 0 and step < 0 - * - * if have_step and step == 0: # <<<<<<<<<<<<<< - * _err_dim(ValueError, "Step may not be zero (axis %d)", dim) - * - */ - } - - /* "View.MemoryView":841 - * - * - * if have_start: # <<<<<<<<<<<<<< - * if start < 0: - * start += shape - */ - __pyx_t_2 = (__pyx_v_have_start != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":842 - * - * if have_start: - * if start < 0: # <<<<<<<<<<<<<< - * start += shape - * if start < 0: - */ - __pyx_t_2 = ((__pyx_v_start < 0) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":843 - * if have_start: - * if start < 0: - * start += shape # <<<<<<<<<<<<<< - * if start < 0: - * start = 0 - */ - __pyx_v_start = (__pyx_v_start + __pyx_v_shape); - - /* "View.MemoryView":844 - * if start < 0: - * start += shape - * if start < 0: # <<<<<<<<<<<<<< - * start = 0 - * elif start >= shape: - */ - __pyx_t_2 = ((__pyx_v_start < 0) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":845 - * start += shape - * if start < 0: - * start = 0 # <<<<<<<<<<<<<< - * elif start >= shape: - * if negative_step: - */ - __pyx_v_start = 0; - - /* "View.MemoryView":844 - * if start < 0: - * start += shape - * if start < 0: # <<<<<<<<<<<<<< - * start = 0 - * elif start >= shape: - */ - } - - /* "View.MemoryView":842 - * - * if have_start: - * if start < 0: # <<<<<<<<<<<<<< - * start += shape - * if start < 0: - */ - goto __pyx_L12; - } - - /* "View.MemoryView":846 - * if start < 0: - * start = 0 - * elif start >= shape: # <<<<<<<<<<<<<< - * if negative_step: - * start = shape - 1 - */ - __pyx_t_2 = ((__pyx_v_start >= __pyx_v_shape) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":847 - * start = 0 - * elif start >= shape: - * if negative_step: # <<<<<<<<<<<<<< - * start = shape - 1 - * else: - */ - __pyx_t_2 = (__pyx_v_negative_step != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":848 - * elif start >= shape: - * if negative_step: - * start = shape - 1 # <<<<<<<<<<<<<< - * else: - * start = shape - */ - __pyx_v_start = (__pyx_v_shape - 1); - - /* "View.MemoryView":847 - * start = 0 - * elif start >= shape: - * if negative_step: # <<<<<<<<<<<<<< - * start = shape - 1 - * else: - */ - goto __pyx_L14; - } - - /* "View.MemoryView":850 - * start = shape - 1 - * else: - * start = shape # <<<<<<<<<<<<<< - * else: - * if negative_step: - */ - /*else*/ { - __pyx_v_start = __pyx_v_shape; - } - __pyx_L14:; - - /* "View.MemoryView":846 - * if start < 0: - * start = 0 - * elif start >= shape: # <<<<<<<<<<<<<< - * if negative_step: - * start = shape - 1 - */ - } - __pyx_L12:; - - /* "View.MemoryView":841 - * - * - * if have_start: # <<<<<<<<<<<<<< - * if start < 0: - * start += shape - */ - goto __pyx_L11; - } - - /* "View.MemoryView":852 - * start = shape - * else: - * if negative_step: # <<<<<<<<<<<<<< - * start = shape - 1 - * else: - */ - /*else*/ { - __pyx_t_2 = (__pyx_v_negative_step != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":853 - * else: - * if negative_step: - * start = shape - 1 # <<<<<<<<<<<<<< - * else: - * start = 0 - */ - __pyx_v_start = (__pyx_v_shape - 1); - - /* "View.MemoryView":852 - * start = shape - * else: - * if negative_step: # <<<<<<<<<<<<<< - * start = shape - 1 - * else: - */ - goto __pyx_L15; - } - - /* "View.MemoryView":855 - * start = shape - 1 - * else: - * start = 0 # <<<<<<<<<<<<<< - * - * if have_stop: - */ - /*else*/ { - __pyx_v_start = 0; - } - __pyx_L15:; - } - __pyx_L11:; - - /* "View.MemoryView":857 - * start = 0 - * - * if have_stop: # <<<<<<<<<<<<<< - * if stop < 0: - * stop += shape - */ - __pyx_t_2 = (__pyx_v_have_stop != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":858 - * - * if have_stop: - * if stop < 0: # <<<<<<<<<<<<<< - * stop += shape - * if stop < 0: - */ - __pyx_t_2 = ((__pyx_v_stop < 0) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":859 - * if have_stop: - * if stop < 0: - * stop += shape # <<<<<<<<<<<<<< - * if stop < 0: - * stop = 0 - */ - __pyx_v_stop = (__pyx_v_stop + __pyx_v_shape); - - /* "View.MemoryView":860 - * if stop < 0: - * stop += shape - * if stop < 0: # <<<<<<<<<<<<<< - * stop = 0 - * elif stop > shape: - */ - __pyx_t_2 = ((__pyx_v_stop < 0) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":861 - * stop += shape - * if stop < 0: - * stop = 0 # <<<<<<<<<<<<<< - * elif stop > shape: - * stop = shape - */ - __pyx_v_stop = 0; - - /* "View.MemoryView":860 - * if stop < 0: - * stop += shape - * if stop < 0: # <<<<<<<<<<<<<< - * stop = 0 - * elif stop > shape: - */ - } - - /* "View.MemoryView":858 - * - * if have_stop: - * if stop < 0: # <<<<<<<<<<<<<< - * stop += shape - * if stop < 0: - */ - goto __pyx_L17; - } - - /* "View.MemoryView":862 - * if stop < 0: - * stop = 0 - * elif stop > shape: # <<<<<<<<<<<<<< - * stop = shape - * else: - */ - __pyx_t_2 = ((__pyx_v_stop > __pyx_v_shape) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":863 - * stop = 0 - * elif stop > shape: - * stop = shape # <<<<<<<<<<<<<< - * else: - * if negative_step: - */ - __pyx_v_stop = __pyx_v_shape; - - /* "View.MemoryView":862 - * if stop < 0: - * stop = 0 - * elif stop > shape: # <<<<<<<<<<<<<< - * stop = shape - * else: - */ - } - __pyx_L17:; - - /* "View.MemoryView":857 - * start = 0 - * - * if have_stop: # <<<<<<<<<<<<<< - * if stop < 0: - * stop += shape - */ - goto __pyx_L16; - } - - /* "View.MemoryView":865 - * stop = shape - * else: - * if negative_step: # <<<<<<<<<<<<<< - * stop = -1 - * else: - */ - /*else*/ { - __pyx_t_2 = (__pyx_v_negative_step != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":866 - * else: - * if negative_step: - * stop = -1 # <<<<<<<<<<<<<< - * else: - * stop = shape - */ - __pyx_v_stop = -1L; - - /* "View.MemoryView":865 - * stop = shape - * else: - * if negative_step: # <<<<<<<<<<<<<< - * stop = -1 - * else: - */ - goto __pyx_L19; - } - - /* "View.MemoryView":868 - * stop = -1 - * else: - * stop = shape # <<<<<<<<<<<<<< - * - * if not have_step: - */ - /*else*/ { - __pyx_v_stop = __pyx_v_shape; - } - __pyx_L19:; - } - __pyx_L16:; - - /* "View.MemoryView":870 - * stop = shape - * - * if not have_step: # <<<<<<<<<<<<<< - * step = 1 - * - */ - __pyx_t_2 = ((!(__pyx_v_have_step != 0)) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":871 - * - * if not have_step: - * step = 1 # <<<<<<<<<<<<<< - * - * - */ - __pyx_v_step = 1; - - /* "View.MemoryView":870 - * stop = shape - * - * if not have_step: # <<<<<<<<<<<<<< - * step = 1 - * - */ - } - - /* "View.MemoryView":875 - * - * with cython.cdivision(True): - * new_shape = (stop - start) // step # <<<<<<<<<<<<<< - * - * if (stop - start) - step * new_shape: - */ - __pyx_v_new_shape = ((__pyx_v_stop - __pyx_v_start) / __pyx_v_step); - - /* "View.MemoryView":877 - * new_shape = (stop - start) // step - * - * if (stop - start) - step * new_shape: # <<<<<<<<<<<<<< - * new_shape += 1 - * - */ - __pyx_t_2 = (((__pyx_v_stop - __pyx_v_start) - (__pyx_v_step * __pyx_v_new_shape)) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":878 - * - * if (stop - start) - step * new_shape: - * new_shape += 1 # <<<<<<<<<<<<<< - * - * if new_shape < 0: - */ - __pyx_v_new_shape = (__pyx_v_new_shape + 1); - - /* "View.MemoryView":877 - * new_shape = (stop - start) // step - * - * if (stop - start) - step * new_shape: # <<<<<<<<<<<<<< - * new_shape += 1 - * - */ - } - - /* "View.MemoryView":880 - * new_shape += 1 - * - * if new_shape < 0: # <<<<<<<<<<<<<< - * new_shape = 0 - * - */ - __pyx_t_2 = ((__pyx_v_new_shape < 0) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":881 - * - * if new_shape < 0: - * new_shape = 0 # <<<<<<<<<<<<<< - * - * - */ - __pyx_v_new_shape = 0; - - /* "View.MemoryView":880 - * new_shape += 1 - * - * if new_shape < 0: # <<<<<<<<<<<<<< - * new_shape = 0 - * - */ - } - - /* "View.MemoryView":884 - * - * - * dst.strides[new_ndim] = stride * step # <<<<<<<<<<<<<< - * dst.shape[new_ndim] = new_shape - * dst.suboffsets[new_ndim] = suboffset - */ - (__pyx_v_dst->strides[__pyx_v_new_ndim]) = (__pyx_v_stride * __pyx_v_step); - - /* "View.MemoryView":885 - * - * dst.strides[new_ndim] = stride * step - * dst.shape[new_ndim] = new_shape # <<<<<<<<<<<<<< - * dst.suboffsets[new_ndim] = suboffset - * - */ - (__pyx_v_dst->shape[__pyx_v_new_ndim]) = __pyx_v_new_shape; - - /* "View.MemoryView":886 - * dst.strides[new_ndim] = stride * step - * dst.shape[new_ndim] = new_shape - * dst.suboffsets[new_ndim] = suboffset # <<<<<<<<<<<<<< - * - * - */ - (__pyx_v_dst->suboffsets[__pyx_v_new_ndim]) = __pyx_v_suboffset; - } - __pyx_L3:; - - /* "View.MemoryView":889 - * - * - * if suboffset_dim[0] < 0: # <<<<<<<<<<<<<< - * dst.data += start * stride - * else: - */ - __pyx_t_2 = (((__pyx_v_suboffset_dim[0]) < 0) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":890 - * - * if suboffset_dim[0] < 0: - * dst.data += start * stride # <<<<<<<<<<<<<< - * else: - * dst.suboffsets[suboffset_dim[0]] += start * stride - */ - __pyx_v_dst->data = (__pyx_v_dst->data + (__pyx_v_start * __pyx_v_stride)); - - /* "View.MemoryView":889 - * - * - * if suboffset_dim[0] < 0: # <<<<<<<<<<<<<< - * dst.data += start * stride - * else: - */ - goto __pyx_L23; - } - - /* "View.MemoryView":892 - * dst.data += start * stride - * else: - * dst.suboffsets[suboffset_dim[0]] += start * stride # <<<<<<<<<<<<<< - * - * if suboffset >= 0: - */ - /*else*/ { - __pyx_t_3 = (__pyx_v_suboffset_dim[0]); - (__pyx_v_dst->suboffsets[__pyx_t_3]) = ((__pyx_v_dst->suboffsets[__pyx_t_3]) + (__pyx_v_start * __pyx_v_stride)); - } - __pyx_L23:; - - /* "View.MemoryView":894 - * dst.suboffsets[suboffset_dim[0]] += start * stride - * - * if suboffset >= 0: # <<<<<<<<<<<<<< - * if not is_slice: - * if new_ndim == 0: - */ - __pyx_t_2 = ((__pyx_v_suboffset >= 0) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":895 - * - * if suboffset >= 0: - * if not is_slice: # <<<<<<<<<<<<<< - * if new_ndim == 0: - * dst.data = ( dst.data)[0] + suboffset - */ - __pyx_t_2 = ((!(__pyx_v_is_slice != 0)) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":896 - * if suboffset >= 0: - * if not is_slice: - * if new_ndim == 0: # <<<<<<<<<<<<<< - * dst.data = ( dst.data)[0] + suboffset - * else: - */ - __pyx_t_2 = ((__pyx_v_new_ndim == 0) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":897 - * if not is_slice: - * if new_ndim == 0: - * dst.data = ( dst.data)[0] + suboffset # <<<<<<<<<<<<<< - * else: - * _err_dim(IndexError, "All dimensions preceding dimension %d " - */ - __pyx_v_dst->data = ((((char **)__pyx_v_dst->data)[0]) + __pyx_v_suboffset); - - /* "View.MemoryView":896 - * if suboffset >= 0: - * if not is_slice: - * if new_ndim == 0: # <<<<<<<<<<<<<< - * dst.data = ( dst.data)[0] + suboffset - * else: - */ - goto __pyx_L26; - } - - /* "View.MemoryView":899 - * dst.data = ( dst.data)[0] + suboffset - * else: - * _err_dim(IndexError, "All dimensions preceding dimension %d " # <<<<<<<<<<<<<< - * "must be indexed and not sliced", dim) - * else: - */ - /*else*/ { - - /* "View.MemoryView":900 - * else: - * _err_dim(IndexError, "All dimensions preceding dimension %d " - * "must be indexed and not sliced", dim) # <<<<<<<<<<<<<< - * else: - * suboffset_dim[0] = new_ndim - */ - __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_IndexError, ((char *)"All dimensions preceding dimension %d must be indexed and not sliced"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(2, 899, __pyx_L1_error) - } - __pyx_L26:; - - /* "View.MemoryView":895 - * - * if suboffset >= 0: - * if not is_slice: # <<<<<<<<<<<<<< - * if new_ndim == 0: - * dst.data = ( dst.data)[0] + suboffset - */ - goto __pyx_L25; - } - - /* "View.MemoryView":902 - * "must be indexed and not sliced", dim) - * else: - * suboffset_dim[0] = new_ndim # <<<<<<<<<<<<<< - * - * return 0 - */ - /*else*/ { - (__pyx_v_suboffset_dim[0]) = __pyx_v_new_ndim; - } - __pyx_L25:; - - /* "View.MemoryView":894 - * dst.suboffsets[suboffset_dim[0]] += start * stride - * - * if suboffset >= 0: # <<<<<<<<<<<<<< - * if not is_slice: - * if new_ndim == 0: - */ - } - - /* "View.MemoryView":904 - * suboffset_dim[0] = new_ndim - * - * return 0 # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = 0; - goto __pyx_L0; - - /* "View.MemoryView":807 - * - * @cname('__pyx_memoryview_slice_memviewslice') - * cdef int slice_memviewslice( # <<<<<<<<<<<<<< - * __Pyx_memviewslice *dst, - * Py_ssize_t shape, Py_ssize_t stride, Py_ssize_t suboffset, - */ - - /* function exit code */ - __pyx_L1_error:; - { - #ifdef WITH_THREAD - PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); - #endif - __Pyx_AddTraceback("View.MemoryView.slice_memviewslice", __pyx_clineno, __pyx_lineno, __pyx_filename); - #ifdef WITH_THREAD - __Pyx_PyGILState_Release(__pyx_gilstate_save); - #endif - } - __pyx_r = -1; - __pyx_L0:; - return __pyx_r; -} - -/* "View.MemoryView":910 - * - * @cname('__pyx_pybuffer_index') - * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index, # <<<<<<<<<<<<<< - * Py_ssize_t dim) except NULL: - * cdef Py_ssize_t shape, stride, suboffset = -1 - */ - -static char *__pyx_pybuffer_index(Py_buffer *__pyx_v_view, char *__pyx_v_bufp, Py_ssize_t __pyx_v_index, Py_ssize_t __pyx_v_dim) { - Py_ssize_t __pyx_v_shape; - Py_ssize_t __pyx_v_stride; - Py_ssize_t __pyx_v_suboffset; - Py_ssize_t __pyx_v_itemsize; - char *__pyx_v_resultp; - char *__pyx_r; - __Pyx_RefNannyDeclarations - Py_ssize_t __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("pybuffer_index", 0); - - /* "View.MemoryView":912 - * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index, - * Py_ssize_t dim) except NULL: - * cdef Py_ssize_t shape, stride, suboffset = -1 # <<<<<<<<<<<<<< - * cdef Py_ssize_t itemsize = view.itemsize - * cdef char *resultp - */ - __pyx_v_suboffset = -1L; - - /* "View.MemoryView":913 - * Py_ssize_t dim) except NULL: - * cdef Py_ssize_t shape, stride, suboffset = -1 - * cdef Py_ssize_t itemsize = view.itemsize # <<<<<<<<<<<<<< - * cdef char *resultp - * - */ - __pyx_t_1 = __pyx_v_view->itemsize; - __pyx_v_itemsize = __pyx_t_1; - - /* "View.MemoryView":916 - * cdef char *resultp - * - * if view.ndim == 0: # <<<<<<<<<<<<<< - * shape = view.len / itemsize - * stride = itemsize - */ - __pyx_t_2 = ((__pyx_v_view->ndim == 0) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":917 - * - * if view.ndim == 0: - * shape = view.len / itemsize # <<<<<<<<<<<<<< - * stride = itemsize - * else: - */ - if (unlikely(__pyx_v_itemsize == 0)) { - PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero"); - __PYX_ERR(2, 917, __pyx_L1_error) - } - else if (sizeof(Py_ssize_t) == sizeof(long) && (!(((Py_ssize_t)-1) > 0)) && unlikely(__pyx_v_itemsize == (Py_ssize_t)-1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_view->len))) { - PyErr_SetString(PyExc_OverflowError, "value too large to perform division"); - __PYX_ERR(2, 917, __pyx_L1_error) - } - __pyx_v_shape = __Pyx_div_Py_ssize_t(__pyx_v_view->len, __pyx_v_itemsize); - - /* "View.MemoryView":918 - * if view.ndim == 0: - * shape = view.len / itemsize - * stride = itemsize # <<<<<<<<<<<<<< - * else: - * shape = view.shape[dim] - */ - __pyx_v_stride = __pyx_v_itemsize; - - /* "View.MemoryView":916 - * cdef char *resultp - * - * if view.ndim == 0: # <<<<<<<<<<<<<< - * shape = view.len / itemsize - * stride = itemsize - */ - goto __pyx_L3; - } - - /* "View.MemoryView":920 - * stride = itemsize - * else: - * shape = view.shape[dim] # <<<<<<<<<<<<<< - * stride = view.strides[dim] - * if view.suboffsets != NULL: - */ - /*else*/ { - __pyx_v_shape = (__pyx_v_view->shape[__pyx_v_dim]); - - /* "View.MemoryView":921 - * else: - * shape = view.shape[dim] - * stride = view.strides[dim] # <<<<<<<<<<<<<< - * if view.suboffsets != NULL: - * suboffset = view.suboffsets[dim] - */ - __pyx_v_stride = (__pyx_v_view->strides[__pyx_v_dim]); - - /* "View.MemoryView":922 - * shape = view.shape[dim] - * stride = view.strides[dim] - * if view.suboffsets != NULL: # <<<<<<<<<<<<<< - * suboffset = view.suboffsets[dim] - * - */ - __pyx_t_2 = ((__pyx_v_view->suboffsets != NULL) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":923 - * stride = view.strides[dim] - * if view.suboffsets != NULL: - * suboffset = view.suboffsets[dim] # <<<<<<<<<<<<<< - * - * if index < 0: - */ - __pyx_v_suboffset = (__pyx_v_view->suboffsets[__pyx_v_dim]); - - /* "View.MemoryView":922 - * shape = view.shape[dim] - * stride = view.strides[dim] - * if view.suboffsets != NULL: # <<<<<<<<<<<<<< - * suboffset = view.suboffsets[dim] - * - */ - } - } - __pyx_L3:; - - /* "View.MemoryView":925 - * suboffset = view.suboffsets[dim] - * - * if index < 0: # <<<<<<<<<<<<<< - * index += view.shape[dim] - * if index < 0: - */ - __pyx_t_2 = ((__pyx_v_index < 0) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":926 - * - * if index < 0: - * index += view.shape[dim] # <<<<<<<<<<<<<< - * if index < 0: - * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) - */ - __pyx_v_index = (__pyx_v_index + (__pyx_v_view->shape[__pyx_v_dim])); - - /* "View.MemoryView":927 - * if index < 0: - * index += view.shape[dim] - * if index < 0: # <<<<<<<<<<<<<< - * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) - * - */ - __pyx_t_2 = ((__pyx_v_index < 0) != 0); - if (unlikely(__pyx_t_2)) { - - /* "View.MemoryView":928 - * index += view.shape[dim] - * if index < 0: - * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) # <<<<<<<<<<<<<< - * - * if index >= shape: - */ - __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 928, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Out_of_bounds_on_buffer_access_a, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 928, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 928, __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(2, 928, __pyx_L1_error) - - /* "View.MemoryView":927 - * if index < 0: - * index += view.shape[dim] - * if index < 0: # <<<<<<<<<<<<<< - * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) - * - */ - } - - /* "View.MemoryView":925 - * suboffset = view.suboffsets[dim] - * - * if index < 0: # <<<<<<<<<<<<<< - * index += view.shape[dim] - * if index < 0: - */ - } - - /* "View.MemoryView":930 - * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) - * - * if index >= shape: # <<<<<<<<<<<<<< - * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) - * - */ - __pyx_t_2 = ((__pyx_v_index >= __pyx_v_shape) != 0); - if (unlikely(__pyx_t_2)) { - - /* "View.MemoryView":931 - * - * if index >= shape: - * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) # <<<<<<<<<<<<<< - * - * resultp = bufp + index * stride - */ - __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 931, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Out_of_bounds_on_buffer_access_a, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 931, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 931, __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(2, 931, __pyx_L1_error) - - /* "View.MemoryView":930 - * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) - * - * if index >= shape: # <<<<<<<<<<<<<< - * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) - * - */ - } - - /* "View.MemoryView":933 - * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) - * - * resultp = bufp + index * stride # <<<<<<<<<<<<<< - * if suboffset >= 0: - * resultp = ( resultp)[0] + suboffset - */ - __pyx_v_resultp = (__pyx_v_bufp + (__pyx_v_index * __pyx_v_stride)); - - /* "View.MemoryView":934 - * - * resultp = bufp + index * stride - * if suboffset >= 0: # <<<<<<<<<<<<<< - * resultp = ( resultp)[0] + suboffset - * - */ - __pyx_t_2 = ((__pyx_v_suboffset >= 0) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":935 - * resultp = bufp + index * stride - * if suboffset >= 0: - * resultp = ( resultp)[0] + suboffset # <<<<<<<<<<<<<< - * - * return resultp - */ - __pyx_v_resultp = ((((char **)__pyx_v_resultp)[0]) + __pyx_v_suboffset); - - /* "View.MemoryView":934 - * - * resultp = bufp + index * stride - * if suboffset >= 0: # <<<<<<<<<<<<<< - * resultp = ( resultp)[0] + suboffset - * - */ - } - - /* "View.MemoryView":937 - * resultp = ( resultp)[0] + suboffset - * - * return resultp # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = __pyx_v_resultp; - goto __pyx_L0; - - /* "View.MemoryView":910 - * - * @cname('__pyx_pybuffer_index') - * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index, # <<<<<<<<<<<<<< - * Py_ssize_t dim) except NULL: - * cdef Py_ssize_t shape, stride, suboffset = -1 - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("View.MemoryView.pybuffer_index", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":943 - * - * @cname('__pyx_memslice_transpose') - * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0: # <<<<<<<<<<<<<< - * cdef int ndim = memslice.memview.view.ndim - * - */ - -static int __pyx_memslice_transpose(__Pyx_memviewslice *__pyx_v_memslice) { - int __pyx_v_ndim; - Py_ssize_t *__pyx_v_shape; - Py_ssize_t *__pyx_v_strides; - int __pyx_v_i; - int __pyx_v_j; - int __pyx_r; - int __pyx_t_1; - Py_ssize_t *__pyx_t_2; - long __pyx_t_3; - long __pyx_t_4; - Py_ssize_t __pyx_t_5; - Py_ssize_t __pyx_t_6; - int __pyx_t_7; - int __pyx_t_8; - int __pyx_t_9; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - - /* "View.MemoryView":944 - * @cname('__pyx_memslice_transpose') - * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0: - * cdef int ndim = memslice.memview.view.ndim # <<<<<<<<<<<<<< - * - * cdef Py_ssize_t *shape = memslice.shape - */ - __pyx_t_1 = __pyx_v_memslice->memview->view.ndim; - __pyx_v_ndim = __pyx_t_1; - - /* "View.MemoryView":946 - * cdef int ndim = memslice.memview.view.ndim - * - * cdef Py_ssize_t *shape = memslice.shape # <<<<<<<<<<<<<< - * cdef Py_ssize_t *strides = memslice.strides - * - */ - __pyx_t_2 = __pyx_v_memslice->shape; - __pyx_v_shape = __pyx_t_2; - - /* "View.MemoryView":947 - * - * cdef Py_ssize_t *shape = memslice.shape - * cdef Py_ssize_t *strides = memslice.strides # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_2 = __pyx_v_memslice->strides; - __pyx_v_strides = __pyx_t_2; - - /* "View.MemoryView":951 - * - * cdef int i, j - * for i in range(ndim / 2): # <<<<<<<<<<<<<< - * j = ndim - 1 - i - * strides[i], strides[j] = strides[j], strides[i] - */ - __pyx_t_3 = __Pyx_div_long(__pyx_v_ndim, 2); - __pyx_t_4 = __pyx_t_3; - for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_4; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "View.MemoryView":952 - * cdef int i, j - * for i in range(ndim / 2): - * j = ndim - 1 - i # <<<<<<<<<<<<<< - * strides[i], strides[j] = strides[j], strides[i] - * shape[i], shape[j] = shape[j], shape[i] - */ - __pyx_v_j = ((__pyx_v_ndim - 1) - __pyx_v_i); - - /* "View.MemoryView":953 - * for i in range(ndim / 2): - * j = ndim - 1 - i - * strides[i], strides[j] = strides[j], strides[i] # <<<<<<<<<<<<<< - * shape[i], shape[j] = shape[j], shape[i] - * - */ - __pyx_t_5 = (__pyx_v_strides[__pyx_v_j]); - __pyx_t_6 = (__pyx_v_strides[__pyx_v_i]); - (__pyx_v_strides[__pyx_v_i]) = __pyx_t_5; - (__pyx_v_strides[__pyx_v_j]) = __pyx_t_6; - - /* "View.MemoryView":954 - * j = ndim - 1 - i - * strides[i], strides[j] = strides[j], strides[i] - * shape[i], shape[j] = shape[j], shape[i] # <<<<<<<<<<<<<< - * - * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0: - */ - __pyx_t_6 = (__pyx_v_shape[__pyx_v_j]); - __pyx_t_5 = (__pyx_v_shape[__pyx_v_i]); - (__pyx_v_shape[__pyx_v_i]) = __pyx_t_6; - (__pyx_v_shape[__pyx_v_j]) = __pyx_t_5; - - /* "View.MemoryView":956 - * shape[i], shape[j] = shape[j], shape[i] - * - * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0: # <<<<<<<<<<<<<< - * _err(ValueError, "Cannot transpose memoryview with indirect dimensions") - * - */ - __pyx_t_8 = (((__pyx_v_memslice->suboffsets[__pyx_v_i]) >= 0) != 0); - if (!__pyx_t_8) { - } else { - __pyx_t_7 = __pyx_t_8; - goto __pyx_L6_bool_binop_done; - } - __pyx_t_8 = (((__pyx_v_memslice->suboffsets[__pyx_v_j]) >= 0) != 0); - __pyx_t_7 = __pyx_t_8; - __pyx_L6_bool_binop_done:; - if (__pyx_t_7) { - - /* "View.MemoryView":957 - * - * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0: - * _err(ValueError, "Cannot transpose memoryview with indirect dimensions") # <<<<<<<<<<<<<< - * - * return 1 - */ - __pyx_t_9 = __pyx_memoryview_err(__pyx_builtin_ValueError, ((char *)"Cannot transpose memoryview with indirect dimensions")); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(2, 957, __pyx_L1_error) - - /* "View.MemoryView":956 - * shape[i], shape[j] = shape[j], shape[i] - * - * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0: # <<<<<<<<<<<<<< - * _err(ValueError, "Cannot transpose memoryview with indirect dimensions") - * - */ - } - } - - /* "View.MemoryView":959 - * _err(ValueError, "Cannot transpose memoryview with indirect dimensions") - * - * return 1 # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = 1; - goto __pyx_L0; - - /* "View.MemoryView":943 - * - * @cname('__pyx_memslice_transpose') - * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0: # <<<<<<<<<<<<<< - * cdef int ndim = memslice.memview.view.ndim - * - */ - - /* function exit code */ - __pyx_L1_error:; - { - #ifdef WITH_THREAD - PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); - #endif - __Pyx_AddTraceback("View.MemoryView.transpose_memslice", __pyx_clineno, __pyx_lineno, __pyx_filename); - #ifdef WITH_THREAD - __Pyx_PyGILState_Release(__pyx_gilstate_save); - #endif - } - __pyx_r = 0; - __pyx_L0:; - return __pyx_r; -} - -/* "View.MemoryView":976 - * cdef int (*to_dtype_func)(char *, object) except 0 - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) - * - */ - -/* Python wrapper */ -static void __pyx_memoryviewslice___dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_memoryviewslice___dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_memoryviewslice___pyx_pf_15View_dot_MemoryView_16_memoryviewslice___dealloc__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); -} - -static void __pyx_memoryviewslice___pyx_pf_15View_dot_MemoryView_16_memoryviewslice___dealloc__(struct __pyx_memoryviewslice_obj *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); - - /* "View.MemoryView":977 - * - * def __dealloc__(self): - * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) # <<<<<<<<<<<<<< - * - * cdef convert_item_to_object(self, char *itemp): - */ - __PYX_XDEC_MEMVIEW((&__pyx_v_self->from_slice), 1); - - /* "View.MemoryView":976 - * cdef int (*to_dtype_func)(char *, object) except 0 - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) - * - */ - - /* function exit code */ - __Pyx_RefNannyFinishContext(); -} - -/* "View.MemoryView":979 - * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) - * - * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<< - * if self.to_object_func != NULL: - * return self.to_object_func(itemp) - */ - -static PyObject *__pyx_memoryviewslice_convert_item_to_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("convert_item_to_object", 0); - - /* "View.MemoryView":980 - * - * cdef convert_item_to_object(self, char *itemp): - * if self.to_object_func != NULL: # <<<<<<<<<<<<<< - * return self.to_object_func(itemp) - * else: - */ - __pyx_t_1 = ((__pyx_v_self->to_object_func != NULL) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":981 - * cdef convert_item_to_object(self, char *itemp): - * if self.to_object_func != NULL: - * return self.to_object_func(itemp) # <<<<<<<<<<<<<< - * else: - * return memoryview.convert_item_to_object(self, itemp) - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __pyx_v_self->to_object_func(__pyx_v_itemp); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 981, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - - /* "View.MemoryView":980 - * - * cdef convert_item_to_object(self, char *itemp): - * if self.to_object_func != NULL: # <<<<<<<<<<<<<< - * return self.to_object_func(itemp) - * else: - */ - } - - /* "View.MemoryView":983 - * return self.to_object_func(itemp) - * else: - * return memoryview.convert_item_to_object(self, itemp) # <<<<<<<<<<<<<< - * - * cdef assign_item_from_object(self, char *itemp, object value): - */ - /*else*/ { - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __pyx_memoryview_convert_item_to_object(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_itemp); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 983, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - } - - /* "View.MemoryView":979 - * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) - * - * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<< - * if self.to_object_func != NULL: - * return self.to_object_func(itemp) - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("View.MemoryView._memoryviewslice.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":985 - * return memoryview.convert_item_to_object(self, itemp) - * - * cdef assign_item_from_object(self, char *itemp, object value): # <<<<<<<<<<<<<< - * if self.to_dtype_func != NULL: - * self.to_dtype_func(itemp, value) - */ - -static PyObject *__pyx_memoryviewslice_assign_item_from_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp, PyObject *__pyx_v_value) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("assign_item_from_object", 0); - - /* "View.MemoryView":986 - * - * cdef assign_item_from_object(self, char *itemp, object value): - * if self.to_dtype_func != NULL: # <<<<<<<<<<<<<< - * self.to_dtype_func(itemp, value) - * else: - */ - __pyx_t_1 = ((__pyx_v_self->to_dtype_func != NULL) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":987 - * cdef assign_item_from_object(self, char *itemp, object value): - * if self.to_dtype_func != NULL: - * self.to_dtype_func(itemp, value) # <<<<<<<<<<<<<< - * else: - * memoryview.assign_item_from_object(self, itemp, value) - */ - __pyx_t_2 = __pyx_v_self->to_dtype_func(__pyx_v_itemp, __pyx_v_value); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(2, 987, __pyx_L1_error) - - /* "View.MemoryView":986 - * - * cdef assign_item_from_object(self, char *itemp, object value): - * if self.to_dtype_func != NULL: # <<<<<<<<<<<<<< - * self.to_dtype_func(itemp, value) - * else: - */ - goto __pyx_L3; - } - - /* "View.MemoryView":989 - * self.to_dtype_func(itemp, value) - * else: - * memoryview.assign_item_from_object(self, itemp, value) # <<<<<<<<<<<<<< - * - * @property - */ - /*else*/ { - __pyx_t_3 = __pyx_memoryview_assign_item_from_object(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_itemp, __pyx_v_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 989, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __pyx_L3:; - - /* "View.MemoryView":985 - * return memoryview.convert_item_to_object(self, itemp) - * - * cdef assign_item_from_object(self, char *itemp, object value): # <<<<<<<<<<<<<< - * if self.to_dtype_func != NULL: - * self.to_dtype_func(itemp, value) - */ - - /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("View.MemoryView._memoryviewslice.assign_item_from_object", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":992 - * - * @property - * def base(self): # <<<<<<<<<<<<<< - * return self.from_object - * - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_16_memoryviewslice_4base_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_15View_dot_MemoryView_16_memoryviewslice_4base_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_15View_dot_MemoryView_16_memoryviewslice_4base___get__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15View_dot_MemoryView_16_memoryviewslice_4base___get__(struct __pyx_memoryviewslice_obj *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__", 0); - - /* "View.MemoryView":993 - * @property - * def base(self): - * return self.from_object # <<<<<<<<<<<<<< - * - * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self->from_object); - __pyx_r = __pyx_v_self->from_object; - goto __pyx_L0; - - /* "View.MemoryView":992 - * - * @property - * def base(self): # <<<<<<<<<<<<<< - * return self.from_object - * - */ - - /* function exit code */ - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "(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___pyx_memoryviewslice_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw___pyx_memoryviewslice_1__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___pyx_memoryviewslice___reduce_cython__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf___pyx_memoryviewslice___reduce_cython__(CYTHON_UNUSED struct __pyx_memoryviewslice_obj *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __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__21, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 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(2, 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("View.MemoryView._memoryviewslice.__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___pyx_memoryviewslice_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static PyObject *__pyx_pw___pyx_memoryviewslice_3__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___pyx_memoryviewslice_2__setstate_cython__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf___pyx_memoryviewslice_2__setstate_cython__(CYTHON_UNUSED struct __pyx_memoryviewslice_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __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__22, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 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(2, 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("View.MemoryView._memoryviewslice.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":999 - * - * @cname('__pyx_memoryview_fromslice') - * cdef memoryview_fromslice(__Pyx_memviewslice memviewslice, # <<<<<<<<<<<<<< - * int ndim, - * object (*to_object_func)(char *), - */ - -static PyObject *__pyx_memoryview_fromslice(__Pyx_memviewslice __pyx_v_memviewslice, int __pyx_v_ndim, PyObject *(*__pyx_v_to_object_func)(char *), int (*__pyx_v_to_dtype_func)(char *, PyObject *), int __pyx_v_dtype_is_object) { - struct __pyx_memoryviewslice_obj *__pyx_v_result = 0; - Py_ssize_t __pyx_v_suboffset; - PyObject *__pyx_v_length = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_TypeInfo *__pyx_t_4; - Py_buffer __pyx_t_5; - Py_ssize_t *__pyx_t_6; - Py_ssize_t *__pyx_t_7; - Py_ssize_t *__pyx_t_8; - Py_ssize_t __pyx_t_9; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("memoryview_fromslice", 0); - - /* "View.MemoryView":1007 - * cdef _memoryviewslice result - * - * if memviewslice.memview == Py_None: # <<<<<<<<<<<<<< - * return None - * - */ - __pyx_t_1 = ((((PyObject *)__pyx_v_memviewslice.memview) == Py_None) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":1008 - * - * if memviewslice.memview == Py_None: - * return None # <<<<<<<<<<<<<< - * - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - - /* "View.MemoryView":1007 - * cdef _memoryviewslice result - * - * if memviewslice.memview == Py_None: # <<<<<<<<<<<<<< - * return None - * - */ - } - - /* "View.MemoryView":1013 - * - * - * result = _memoryviewslice(None, 0, dtype_is_object) # <<<<<<<<<<<<<< - * - * result.from_slice = memviewslice - */ - __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_dtype_is_object); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1013, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 1013, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - PyTuple_SET_ITEM(__pyx_t_3, 0, Py_None); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryviewslice_type), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1013, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_result = ((struct __pyx_memoryviewslice_obj *)__pyx_t_2); - __pyx_t_2 = 0; - - /* "View.MemoryView":1015 - * result = _memoryviewslice(None, 0, dtype_is_object) - * - * result.from_slice = memviewslice # <<<<<<<<<<<<<< - * __PYX_INC_MEMVIEW(&memviewslice, 1) - * - */ - __pyx_v_result->from_slice = __pyx_v_memviewslice; - - /* "View.MemoryView":1016 - * - * result.from_slice = memviewslice - * __PYX_INC_MEMVIEW(&memviewslice, 1) # <<<<<<<<<<<<<< - * - * result.from_object = ( memviewslice.memview).base - */ - __PYX_INC_MEMVIEW((&__pyx_v_memviewslice), 1); - - /* "View.MemoryView":1018 - * __PYX_INC_MEMVIEW(&memviewslice, 1) - * - * result.from_object = ( memviewslice.memview).base # <<<<<<<<<<<<<< - * result.typeinfo = memviewslice.memview.typeinfo - * - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_memviewslice.memview), __pyx_n_s_base); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1018, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_GOTREF(__pyx_v_result->from_object); - __Pyx_DECREF(__pyx_v_result->from_object); - __pyx_v_result->from_object = __pyx_t_2; - __pyx_t_2 = 0; - - /* "View.MemoryView":1019 - * - * result.from_object = ( memviewslice.memview).base - * result.typeinfo = memviewslice.memview.typeinfo # <<<<<<<<<<<<<< - * - * result.view = memviewslice.memview.view - */ - __pyx_t_4 = __pyx_v_memviewslice.memview->typeinfo; - __pyx_v_result->__pyx_base.typeinfo = __pyx_t_4; - - /* "View.MemoryView":1021 - * result.typeinfo = memviewslice.memview.typeinfo - * - * result.view = memviewslice.memview.view # <<<<<<<<<<<<<< - * result.view.buf = memviewslice.data - * result.view.ndim = ndim - */ - __pyx_t_5 = __pyx_v_memviewslice.memview->view; - __pyx_v_result->__pyx_base.view = __pyx_t_5; - - /* "View.MemoryView":1022 - * - * result.view = memviewslice.memview.view - * result.view.buf = memviewslice.data # <<<<<<<<<<<<<< - * result.view.ndim = ndim - * (<__pyx_buffer *> &result.view).obj = Py_None - */ - __pyx_v_result->__pyx_base.view.buf = ((void *)__pyx_v_memviewslice.data); - - /* "View.MemoryView":1023 - * result.view = memviewslice.memview.view - * result.view.buf = memviewslice.data - * result.view.ndim = ndim # <<<<<<<<<<<<<< - * (<__pyx_buffer *> &result.view).obj = Py_None - * Py_INCREF(Py_None) - */ - __pyx_v_result->__pyx_base.view.ndim = __pyx_v_ndim; - - /* "View.MemoryView":1024 - * result.view.buf = memviewslice.data - * result.view.ndim = ndim - * (<__pyx_buffer *> &result.view).obj = Py_None # <<<<<<<<<<<<<< - * Py_INCREF(Py_None) - * - */ - ((Py_buffer *)(&__pyx_v_result->__pyx_base.view))->obj = Py_None; - - /* "View.MemoryView":1025 - * result.view.ndim = ndim - * (<__pyx_buffer *> &result.view).obj = Py_None - * Py_INCREF(Py_None) # <<<<<<<<<<<<<< - * - * if (memviewslice.memview).flags & PyBUF_WRITABLE: - */ - Py_INCREF(Py_None); - - /* "View.MemoryView":1027 - * Py_INCREF(Py_None) - * - * if (memviewslice.memview).flags & PyBUF_WRITABLE: # <<<<<<<<<<<<<< - * result.flags = PyBUF_RECORDS - * else: - */ - __pyx_t_1 = ((((struct __pyx_memoryview_obj *)__pyx_v_memviewslice.memview)->flags & PyBUF_WRITABLE) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":1028 - * - * if (memviewslice.memview).flags & PyBUF_WRITABLE: - * result.flags = PyBUF_RECORDS # <<<<<<<<<<<<<< - * else: - * result.flags = PyBUF_RECORDS_RO - */ - __pyx_v_result->__pyx_base.flags = PyBUF_RECORDS; - - /* "View.MemoryView":1027 - * Py_INCREF(Py_None) - * - * if (memviewslice.memview).flags & PyBUF_WRITABLE: # <<<<<<<<<<<<<< - * result.flags = PyBUF_RECORDS - * else: - */ - goto __pyx_L4; - } - - /* "View.MemoryView":1030 - * result.flags = PyBUF_RECORDS - * else: - * result.flags = PyBUF_RECORDS_RO # <<<<<<<<<<<<<< - * - * result.view.shape = result.from_slice.shape - */ - /*else*/ { - __pyx_v_result->__pyx_base.flags = PyBUF_RECORDS_RO; - } - __pyx_L4:; - - /* "View.MemoryView":1032 - * result.flags = PyBUF_RECORDS_RO - * - * result.view.shape = result.from_slice.shape # <<<<<<<<<<<<<< - * result.view.strides = result.from_slice.strides - * - */ - __pyx_v_result->__pyx_base.view.shape = ((Py_ssize_t *)__pyx_v_result->from_slice.shape); - - /* "View.MemoryView":1033 - * - * result.view.shape = result.from_slice.shape - * result.view.strides = result.from_slice.strides # <<<<<<<<<<<<<< - * - * - */ - __pyx_v_result->__pyx_base.view.strides = ((Py_ssize_t *)__pyx_v_result->from_slice.strides); - - /* "View.MemoryView":1036 - * - * - * result.view.suboffsets = NULL # <<<<<<<<<<<<<< - * for suboffset in result.from_slice.suboffsets[:ndim]: - * if suboffset >= 0: - */ - __pyx_v_result->__pyx_base.view.suboffsets = NULL; - - /* "View.MemoryView":1037 - * - * result.view.suboffsets = NULL - * for suboffset in result.from_slice.suboffsets[:ndim]: # <<<<<<<<<<<<<< - * if suboffset >= 0: - * result.view.suboffsets = result.from_slice.suboffsets - */ - __pyx_t_7 = (__pyx_v_result->from_slice.suboffsets + __pyx_v_ndim); - for (__pyx_t_8 = __pyx_v_result->from_slice.suboffsets; __pyx_t_8 < __pyx_t_7; __pyx_t_8++) { - __pyx_t_6 = __pyx_t_8; - __pyx_v_suboffset = (__pyx_t_6[0]); - - /* "View.MemoryView":1038 - * result.view.suboffsets = NULL - * for suboffset in result.from_slice.suboffsets[:ndim]: - * if suboffset >= 0: # <<<<<<<<<<<<<< - * result.view.suboffsets = result.from_slice.suboffsets - * break - */ - __pyx_t_1 = ((__pyx_v_suboffset >= 0) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":1039 - * for suboffset in result.from_slice.suboffsets[:ndim]: - * if suboffset >= 0: - * result.view.suboffsets = result.from_slice.suboffsets # <<<<<<<<<<<<<< - * break - * - */ - __pyx_v_result->__pyx_base.view.suboffsets = ((Py_ssize_t *)__pyx_v_result->from_slice.suboffsets); - - /* "View.MemoryView":1040 - * if suboffset >= 0: - * result.view.suboffsets = result.from_slice.suboffsets - * break # <<<<<<<<<<<<<< - * - * result.view.len = result.view.itemsize - */ - goto __pyx_L6_break; - - /* "View.MemoryView":1038 - * result.view.suboffsets = NULL - * for suboffset in result.from_slice.suboffsets[:ndim]: - * if suboffset >= 0: # <<<<<<<<<<<<<< - * result.view.suboffsets = result.from_slice.suboffsets - * break - */ - } - } - __pyx_L6_break:; - - /* "View.MemoryView":1042 - * break - * - * result.view.len = result.view.itemsize # <<<<<<<<<<<<<< - * for length in result.view.shape[:ndim]: - * result.view.len *= length - */ - __pyx_t_9 = __pyx_v_result->__pyx_base.view.itemsize; - __pyx_v_result->__pyx_base.view.len = __pyx_t_9; - - /* "View.MemoryView":1043 - * - * result.view.len = result.view.itemsize - * for length in result.view.shape[:ndim]: # <<<<<<<<<<<<<< - * result.view.len *= length - * - */ - __pyx_t_7 = (__pyx_v_result->__pyx_base.view.shape + __pyx_v_ndim); - for (__pyx_t_8 = __pyx_v_result->__pyx_base.view.shape; __pyx_t_8 < __pyx_t_7; __pyx_t_8++) { - __pyx_t_6 = __pyx_t_8; - __pyx_t_2 = PyInt_FromSsize_t((__pyx_t_6[0])); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1043, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_XDECREF_SET(__pyx_v_length, __pyx_t_2); - __pyx_t_2 = 0; - - /* "View.MemoryView":1044 - * result.view.len = result.view.itemsize - * for length in result.view.shape[:ndim]: - * result.view.len *= length # <<<<<<<<<<<<<< - * - * result.to_object_func = to_object_func - */ - __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_result->__pyx_base.view.len); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1044, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_InPlaceMultiply(__pyx_t_2, __pyx_v_length); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 1044, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_9 = __Pyx_PyIndex_AsSsize_t(__pyx_t_3); if (unlikely((__pyx_t_9 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 1044, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_result->__pyx_base.view.len = __pyx_t_9; - } - - /* "View.MemoryView":1046 - * result.view.len *= length - * - * result.to_object_func = to_object_func # <<<<<<<<<<<<<< - * result.to_dtype_func = to_dtype_func - * - */ - __pyx_v_result->to_object_func = __pyx_v_to_object_func; - - /* "View.MemoryView":1047 - * - * result.to_object_func = to_object_func - * result.to_dtype_func = to_dtype_func # <<<<<<<<<<<<<< - * - * return result - */ - __pyx_v_result->to_dtype_func = __pyx_v_to_dtype_func; - - /* "View.MemoryView":1049 - * result.to_dtype_func = to_dtype_func - * - * return result # <<<<<<<<<<<<<< - * - * @cname('__pyx_memoryview_get_slice_from_memoryview') - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_result)); - __pyx_r = ((PyObject *)__pyx_v_result); - goto __pyx_L0; - - /* "View.MemoryView":999 - * - * @cname('__pyx_memoryview_fromslice') - * cdef memoryview_fromslice(__Pyx_memviewslice memviewslice, # <<<<<<<<<<<<<< - * int ndim, - * object (*to_object_func)(char *), - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("View.MemoryView.memoryview_fromslice", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_result); - __Pyx_XDECREF(__pyx_v_length); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":1052 - * - * @cname('__pyx_memoryview_get_slice_from_memoryview') - * cdef __Pyx_memviewslice *get_slice_from_memview(memoryview memview, # <<<<<<<<<<<<<< - * __Pyx_memviewslice *mslice) except NULL: - * cdef _memoryviewslice obj - */ - -static __Pyx_memviewslice *__pyx_memoryview_get_slice_from_memoryview(struct __pyx_memoryview_obj *__pyx_v_memview, __Pyx_memviewslice *__pyx_v_mslice) { - struct __pyx_memoryviewslice_obj *__pyx_v_obj = 0; - __Pyx_memviewslice *__pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("get_slice_from_memview", 0); - - /* "View.MemoryView":1055 - * __Pyx_memviewslice *mslice) except NULL: - * cdef _memoryviewslice obj - * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< - * obj = memview - * return &obj.from_slice - */ - __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":1056 - * cdef _memoryviewslice obj - * if isinstance(memview, _memoryviewslice): - * obj = memview # <<<<<<<<<<<<<< - * return &obj.from_slice - * else: - */ - if (!(likely(((((PyObject *)__pyx_v_memview)) == Py_None) || likely(__Pyx_TypeTest(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type))))) __PYX_ERR(2, 1056, __pyx_L1_error) - __pyx_t_3 = ((PyObject *)__pyx_v_memview); - __Pyx_INCREF(__pyx_t_3); - __pyx_v_obj = ((struct __pyx_memoryviewslice_obj *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "View.MemoryView":1057 - * if isinstance(memview, _memoryviewslice): - * obj = memview - * return &obj.from_slice # <<<<<<<<<<<<<< - * else: - * slice_copy(memview, mslice) - */ - __pyx_r = (&__pyx_v_obj->from_slice); - goto __pyx_L0; - - /* "View.MemoryView":1055 - * __Pyx_memviewslice *mslice) except NULL: - * cdef _memoryviewslice obj - * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< - * obj = memview - * return &obj.from_slice - */ - } - - /* "View.MemoryView":1059 - * return &obj.from_slice - * else: - * slice_copy(memview, mslice) # <<<<<<<<<<<<<< - * return mslice - * - */ - /*else*/ { - __pyx_memoryview_slice_copy(__pyx_v_memview, __pyx_v_mslice); - - /* "View.MemoryView":1060 - * else: - * slice_copy(memview, mslice) - * return mslice # <<<<<<<<<<<<<< - * - * @cname('__pyx_memoryview_slice_copy') - */ - __pyx_r = __pyx_v_mslice; - goto __pyx_L0; - } - - /* "View.MemoryView":1052 - * - * @cname('__pyx_memoryview_get_slice_from_memoryview') - * cdef __Pyx_memviewslice *get_slice_from_memview(memoryview memview, # <<<<<<<<<<<<<< - * __Pyx_memviewslice *mslice) except NULL: - * cdef _memoryviewslice obj - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("View.MemoryView.get_slice_from_memview", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_obj); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":1063 - * - * @cname('__pyx_memoryview_slice_copy') - * cdef void slice_copy(memoryview memview, __Pyx_memviewslice *dst): # <<<<<<<<<<<<<< - * cdef int dim - * cdef (Py_ssize_t*) shape, strides, suboffsets - */ - -static void __pyx_memoryview_slice_copy(struct __pyx_memoryview_obj *__pyx_v_memview, __Pyx_memviewslice *__pyx_v_dst) { - int __pyx_v_dim; - Py_ssize_t *__pyx_v_shape; - Py_ssize_t *__pyx_v_strides; - Py_ssize_t *__pyx_v_suboffsets; - __Pyx_RefNannyDeclarations - Py_ssize_t *__pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - Py_ssize_t __pyx_t_5; - __Pyx_RefNannySetupContext("slice_copy", 0); - - /* "View.MemoryView":1067 - * cdef (Py_ssize_t*) shape, strides, suboffsets - * - * shape = memview.view.shape # <<<<<<<<<<<<<< - * strides = memview.view.strides - * suboffsets = memview.view.suboffsets - */ - __pyx_t_1 = __pyx_v_memview->view.shape; - __pyx_v_shape = __pyx_t_1; - - /* "View.MemoryView":1068 - * - * shape = memview.view.shape - * strides = memview.view.strides # <<<<<<<<<<<<<< - * suboffsets = memview.view.suboffsets - * - */ - __pyx_t_1 = __pyx_v_memview->view.strides; - __pyx_v_strides = __pyx_t_1; - - /* "View.MemoryView":1069 - * shape = memview.view.shape - * strides = memview.view.strides - * suboffsets = memview.view.suboffsets # <<<<<<<<<<<<<< - * - * dst.memview = <__pyx_memoryview *> memview - */ - __pyx_t_1 = __pyx_v_memview->view.suboffsets; - __pyx_v_suboffsets = __pyx_t_1; - - /* "View.MemoryView":1071 - * suboffsets = memview.view.suboffsets - * - * dst.memview = <__pyx_memoryview *> memview # <<<<<<<<<<<<<< - * dst.data = memview.view.buf - * - */ - __pyx_v_dst->memview = ((struct __pyx_memoryview_obj *)__pyx_v_memview); - - /* "View.MemoryView":1072 - * - * dst.memview = <__pyx_memoryview *> memview - * dst.data = memview.view.buf # <<<<<<<<<<<<<< - * - * for dim in range(memview.view.ndim): - */ - __pyx_v_dst->data = ((char *)__pyx_v_memview->view.buf); - - /* "View.MemoryView":1074 - * dst.data = memview.view.buf - * - * for dim in range(memview.view.ndim): # <<<<<<<<<<<<<< - * dst.shape[dim] = shape[dim] - * dst.strides[dim] = strides[dim] - */ - __pyx_t_2 = __pyx_v_memview->view.ndim; - __pyx_t_3 = __pyx_t_2; - for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { - __pyx_v_dim = __pyx_t_4; - - /* "View.MemoryView":1075 - * - * for dim in range(memview.view.ndim): - * dst.shape[dim] = shape[dim] # <<<<<<<<<<<<<< - * dst.strides[dim] = strides[dim] - * dst.suboffsets[dim] = suboffsets[dim] if suboffsets else -1 - */ - (__pyx_v_dst->shape[__pyx_v_dim]) = (__pyx_v_shape[__pyx_v_dim]); - - /* "View.MemoryView":1076 - * for dim in range(memview.view.ndim): - * dst.shape[dim] = shape[dim] - * dst.strides[dim] = strides[dim] # <<<<<<<<<<<<<< - * dst.suboffsets[dim] = suboffsets[dim] if suboffsets else -1 - * - */ - (__pyx_v_dst->strides[__pyx_v_dim]) = (__pyx_v_strides[__pyx_v_dim]); - - /* "View.MemoryView":1077 - * dst.shape[dim] = shape[dim] - * dst.strides[dim] = strides[dim] - * dst.suboffsets[dim] = suboffsets[dim] if suboffsets else -1 # <<<<<<<<<<<<<< - * - * @cname('__pyx_memoryview_copy_object') - */ - if ((__pyx_v_suboffsets != 0)) { - __pyx_t_5 = (__pyx_v_suboffsets[__pyx_v_dim]); - } else { - __pyx_t_5 = -1L; - } - (__pyx_v_dst->suboffsets[__pyx_v_dim]) = __pyx_t_5; - } - - /* "View.MemoryView":1063 - * - * @cname('__pyx_memoryview_slice_copy') - * cdef void slice_copy(memoryview memview, __Pyx_memviewslice *dst): # <<<<<<<<<<<<<< - * cdef int dim - * cdef (Py_ssize_t*) shape, strides, suboffsets - */ - - /* function exit code */ - __Pyx_RefNannyFinishContext(); -} - -/* "View.MemoryView":1080 - * - * @cname('__pyx_memoryview_copy_object') - * cdef memoryview_copy(memoryview memview): # <<<<<<<<<<<<<< - * "Create a new memoryview object" - * cdef __Pyx_memviewslice memviewslice - */ - -static PyObject *__pyx_memoryview_copy_object(struct __pyx_memoryview_obj *__pyx_v_memview) { - __Pyx_memviewslice __pyx_v_memviewslice; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("memoryview_copy", 0); - - /* "View.MemoryView":1083 - * "Create a new memoryview object" - * cdef __Pyx_memviewslice memviewslice - * slice_copy(memview, &memviewslice) # <<<<<<<<<<<<<< - * return memoryview_copy_from_slice(memview, &memviewslice) - * - */ - __pyx_memoryview_slice_copy(__pyx_v_memview, (&__pyx_v_memviewslice)); - - /* "View.MemoryView":1084 - * cdef __Pyx_memviewslice memviewslice - * slice_copy(memview, &memviewslice) - * return memoryview_copy_from_slice(memview, &memviewslice) # <<<<<<<<<<<<<< - * - * @cname('__pyx_memoryview_copy_object_from_slice') - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_memoryview_copy_object_from_slice(__pyx_v_memview, (&__pyx_v_memviewslice)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1084, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "View.MemoryView":1080 - * - * @cname('__pyx_memoryview_copy_object') - * cdef memoryview_copy(memoryview memview): # <<<<<<<<<<<<<< - * "Create a new memoryview object" - * cdef __Pyx_memviewslice memviewslice - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("View.MemoryView.memoryview_copy", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":1087 - * - * @cname('__pyx_memoryview_copy_object_from_slice') - * cdef memoryview_copy_from_slice(memoryview memview, __Pyx_memviewslice *memviewslice): # <<<<<<<<<<<<<< - * """ - * Create a new memoryview object from a given memoryview object and slice. - */ - -static PyObject *__pyx_memoryview_copy_object_from_slice(struct __pyx_memoryview_obj *__pyx_v_memview, __Pyx_memviewslice *__pyx_v_memviewslice) { - PyObject *(*__pyx_v_to_object_func)(char *); - int (*__pyx_v_to_dtype_func)(char *, PyObject *); - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *(*__pyx_t_3)(char *); - int (*__pyx_t_4)(char *, PyObject *); - PyObject *__pyx_t_5 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("memoryview_copy_from_slice", 0); - - /* "View.MemoryView":1094 - * cdef int (*to_dtype_func)(char *, object) except 0 - * - * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< - * to_object_func = (<_memoryviewslice> memview).to_object_func - * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func - */ - __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":1095 - * - * if isinstance(memview, _memoryviewslice): - * to_object_func = (<_memoryviewslice> memview).to_object_func # <<<<<<<<<<<<<< - * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func - * else: - */ - __pyx_t_3 = ((struct __pyx_memoryviewslice_obj *)__pyx_v_memview)->to_object_func; - __pyx_v_to_object_func = __pyx_t_3; - - /* "View.MemoryView":1096 - * if isinstance(memview, _memoryviewslice): - * to_object_func = (<_memoryviewslice> memview).to_object_func - * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func # <<<<<<<<<<<<<< - * else: - * to_object_func = NULL - */ - __pyx_t_4 = ((struct __pyx_memoryviewslice_obj *)__pyx_v_memview)->to_dtype_func; - __pyx_v_to_dtype_func = __pyx_t_4; - - /* "View.MemoryView":1094 - * cdef int (*to_dtype_func)(char *, object) except 0 - * - * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< - * to_object_func = (<_memoryviewslice> memview).to_object_func - * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func - */ - goto __pyx_L3; - } - - /* "View.MemoryView":1098 - * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func - * else: - * to_object_func = NULL # <<<<<<<<<<<<<< - * to_dtype_func = NULL - * - */ - /*else*/ { - __pyx_v_to_object_func = NULL; - - /* "View.MemoryView":1099 - * else: - * to_object_func = NULL - * to_dtype_func = NULL # <<<<<<<<<<<<<< - * - * return memoryview_fromslice(memviewslice[0], memview.view.ndim, - */ - __pyx_v_to_dtype_func = NULL; - } - __pyx_L3:; - - /* "View.MemoryView":1101 - * to_dtype_func = NULL - * - * return memoryview_fromslice(memviewslice[0], memview.view.ndim, # <<<<<<<<<<<<<< - * to_object_func, to_dtype_func, - * memview.dtype_is_object) - */ - __Pyx_XDECREF(__pyx_r); - - /* "View.MemoryView":1103 - * return memoryview_fromslice(memviewslice[0], memview.view.ndim, - * to_object_func, to_dtype_func, - * memview.dtype_is_object) # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_5 = __pyx_memoryview_fromslice((__pyx_v_memviewslice[0]), __pyx_v_memview->view.ndim, __pyx_v_to_object_func, __pyx_v_to_dtype_func, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 1101, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; - goto __pyx_L0; - - /* "View.MemoryView":1087 - * - * @cname('__pyx_memoryview_copy_object_from_slice') - * cdef memoryview_copy_from_slice(memoryview memview, __Pyx_memviewslice *memviewslice): # <<<<<<<<<<<<<< - * """ - * Create a new memoryview object from a given memoryview object and slice. - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("View.MemoryView.memoryview_copy_from_slice", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":1109 - * - * - * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil: # <<<<<<<<<<<<<< - * if arg < 0: - * return -arg - */ - -static Py_ssize_t abs_py_ssize_t(Py_ssize_t __pyx_v_arg) { - Py_ssize_t __pyx_r; - int __pyx_t_1; - - /* "View.MemoryView":1110 - * - * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil: - * if arg < 0: # <<<<<<<<<<<<<< - * return -arg - * else: - */ - __pyx_t_1 = ((__pyx_v_arg < 0) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":1111 - * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil: - * if arg < 0: - * return -arg # <<<<<<<<<<<<<< - * else: - * return arg - */ - __pyx_r = (-__pyx_v_arg); - goto __pyx_L0; - - /* "View.MemoryView":1110 - * - * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil: - * if arg < 0: # <<<<<<<<<<<<<< - * return -arg - * else: - */ - } - - /* "View.MemoryView":1113 - * return -arg - * else: - * return arg # <<<<<<<<<<<<<< - * - * @cname('__pyx_get_best_slice_order') - */ - /*else*/ { - __pyx_r = __pyx_v_arg; - goto __pyx_L0; - } - - /* "View.MemoryView":1109 - * - * - * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil: # <<<<<<<<<<<<<< - * if arg < 0: - * return -arg - */ - - /* function exit code */ - __pyx_L0:; - return __pyx_r; -} - -/* "View.MemoryView":1116 - * - * @cname('__pyx_get_best_slice_order') - * cdef char get_best_order(__Pyx_memviewslice *mslice, int ndim) nogil: # <<<<<<<<<<<<<< - * """ - * Figure out the best memory access order for a given slice. - */ - -static char __pyx_get_best_slice_order(__Pyx_memviewslice *__pyx_v_mslice, int __pyx_v_ndim) { - int __pyx_v_i; - Py_ssize_t __pyx_v_c_stride; - Py_ssize_t __pyx_v_f_stride; - char __pyx_r; - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - - /* "View.MemoryView":1121 - * """ - * cdef int i - * cdef Py_ssize_t c_stride = 0 # <<<<<<<<<<<<<< - * cdef Py_ssize_t f_stride = 0 - * - */ - __pyx_v_c_stride = 0; - - /* "View.MemoryView":1122 - * cdef int i - * cdef Py_ssize_t c_stride = 0 - * cdef Py_ssize_t f_stride = 0 # <<<<<<<<<<<<<< - * - * for i in range(ndim - 1, -1, -1): - */ - __pyx_v_f_stride = 0; - - /* "View.MemoryView":1124 - * cdef Py_ssize_t f_stride = 0 - * - * for i in range(ndim - 1, -1, -1): # <<<<<<<<<<<<<< - * if mslice.shape[i] > 1: - * c_stride = mslice.strides[i] - */ - for (__pyx_t_1 = (__pyx_v_ndim - 1); __pyx_t_1 > -1; __pyx_t_1-=1) { - __pyx_v_i = __pyx_t_1; - - /* "View.MemoryView":1125 - * - * for i in range(ndim - 1, -1, -1): - * if mslice.shape[i] > 1: # <<<<<<<<<<<<<< - * c_stride = mslice.strides[i] - * break - */ - __pyx_t_2 = (((__pyx_v_mslice->shape[__pyx_v_i]) > 1) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":1126 - * for i in range(ndim - 1, -1, -1): - * if mslice.shape[i] > 1: - * c_stride = mslice.strides[i] # <<<<<<<<<<<<<< - * break - * - */ - __pyx_v_c_stride = (__pyx_v_mslice->strides[__pyx_v_i]); - - /* "View.MemoryView":1127 - * if mslice.shape[i] > 1: - * c_stride = mslice.strides[i] - * break # <<<<<<<<<<<<<< - * - * for i in range(ndim): - */ - goto __pyx_L4_break; - - /* "View.MemoryView":1125 - * - * for i in range(ndim - 1, -1, -1): - * if mslice.shape[i] > 1: # <<<<<<<<<<<<<< - * c_stride = mslice.strides[i] - * break - */ - } - } - __pyx_L4_break:; - - /* "View.MemoryView":1129 - * break - * - * for i in range(ndim): # <<<<<<<<<<<<<< - * if mslice.shape[i] > 1: - * f_stride = mslice.strides[i] - */ - __pyx_t_1 = __pyx_v_ndim; - __pyx_t_3 = __pyx_t_1; - for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { - __pyx_v_i = __pyx_t_4; - - /* "View.MemoryView":1130 - * - * for i in range(ndim): - * if mslice.shape[i] > 1: # <<<<<<<<<<<<<< - * f_stride = mslice.strides[i] - * break - */ - __pyx_t_2 = (((__pyx_v_mslice->shape[__pyx_v_i]) > 1) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":1131 - * for i in range(ndim): - * if mslice.shape[i] > 1: - * f_stride = mslice.strides[i] # <<<<<<<<<<<<<< - * break - * - */ - __pyx_v_f_stride = (__pyx_v_mslice->strides[__pyx_v_i]); - - /* "View.MemoryView":1132 - * if mslice.shape[i] > 1: - * f_stride = mslice.strides[i] - * break # <<<<<<<<<<<<<< - * - * if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride): - */ - goto __pyx_L7_break; - - /* "View.MemoryView":1130 - * - * for i in range(ndim): - * if mslice.shape[i] > 1: # <<<<<<<<<<<<<< - * f_stride = mslice.strides[i] - * break - */ - } - } - __pyx_L7_break:; - - /* "View.MemoryView":1134 - * break - * - * if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride): # <<<<<<<<<<<<<< - * return 'C' - * else: - */ - __pyx_t_2 = ((abs_py_ssize_t(__pyx_v_c_stride) <= abs_py_ssize_t(__pyx_v_f_stride)) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":1135 - * - * if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride): - * return 'C' # <<<<<<<<<<<<<< - * else: - * return 'F' - */ - __pyx_r = 'C'; - goto __pyx_L0; - - /* "View.MemoryView":1134 - * break - * - * if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride): # <<<<<<<<<<<<<< - * return 'C' - * else: - */ - } - - /* "View.MemoryView":1137 - * return 'C' - * else: - * return 'F' # <<<<<<<<<<<<<< - * - * @cython.cdivision(True) - */ - /*else*/ { - __pyx_r = 'F'; - goto __pyx_L0; - } - - /* "View.MemoryView":1116 - * - * @cname('__pyx_get_best_slice_order') - * cdef char get_best_order(__Pyx_memviewslice *mslice, int ndim) nogil: # <<<<<<<<<<<<<< - * """ - * Figure out the best memory access order for a given slice. - */ - - /* function exit code */ - __pyx_L0:; - return __pyx_r; -} - -/* "View.MemoryView":1140 - * - * @cython.cdivision(True) - * cdef void _copy_strided_to_strided(char *src_data, Py_ssize_t *src_strides, # <<<<<<<<<<<<<< - * char *dst_data, Py_ssize_t *dst_strides, - * Py_ssize_t *src_shape, Py_ssize_t *dst_shape, - */ - -static void _copy_strided_to_strided(char *__pyx_v_src_data, Py_ssize_t *__pyx_v_src_strides, char *__pyx_v_dst_data, Py_ssize_t *__pyx_v_dst_strides, Py_ssize_t *__pyx_v_src_shape, Py_ssize_t *__pyx_v_dst_shape, int __pyx_v_ndim, size_t __pyx_v_itemsize) { - CYTHON_UNUSED Py_ssize_t __pyx_v_i; - CYTHON_UNUSED Py_ssize_t __pyx_v_src_extent; - Py_ssize_t __pyx_v_dst_extent; - Py_ssize_t __pyx_v_src_stride; - Py_ssize_t __pyx_v_dst_stride; - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - Py_ssize_t __pyx_t_4; - Py_ssize_t __pyx_t_5; - Py_ssize_t __pyx_t_6; - - /* "View.MemoryView":1147 - * - * cdef Py_ssize_t i - * cdef Py_ssize_t src_extent = src_shape[0] # <<<<<<<<<<<<<< - * cdef Py_ssize_t dst_extent = dst_shape[0] - * cdef Py_ssize_t src_stride = src_strides[0] - */ - __pyx_v_src_extent = (__pyx_v_src_shape[0]); - - /* "View.MemoryView":1148 - * cdef Py_ssize_t i - * cdef Py_ssize_t src_extent = src_shape[0] - * cdef Py_ssize_t dst_extent = dst_shape[0] # <<<<<<<<<<<<<< - * cdef Py_ssize_t src_stride = src_strides[0] - * cdef Py_ssize_t dst_stride = dst_strides[0] - */ - __pyx_v_dst_extent = (__pyx_v_dst_shape[0]); - - /* "View.MemoryView":1149 - * cdef Py_ssize_t src_extent = src_shape[0] - * cdef Py_ssize_t dst_extent = dst_shape[0] - * cdef Py_ssize_t src_stride = src_strides[0] # <<<<<<<<<<<<<< - * cdef Py_ssize_t dst_stride = dst_strides[0] - * - */ - __pyx_v_src_stride = (__pyx_v_src_strides[0]); - - /* "View.MemoryView":1150 - * cdef Py_ssize_t dst_extent = dst_shape[0] - * cdef Py_ssize_t src_stride = src_strides[0] - * cdef Py_ssize_t dst_stride = dst_strides[0] # <<<<<<<<<<<<<< - * - * if ndim == 1: - */ - __pyx_v_dst_stride = (__pyx_v_dst_strides[0]); - - /* "View.MemoryView":1152 - * cdef Py_ssize_t dst_stride = dst_strides[0] - * - * if ndim == 1: # <<<<<<<<<<<<<< - * if (src_stride > 0 and dst_stride > 0 and - * src_stride == itemsize == dst_stride): - */ - __pyx_t_1 = ((__pyx_v_ndim == 1) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":1153 - * - * if ndim == 1: - * if (src_stride > 0 and dst_stride > 0 and # <<<<<<<<<<<<<< - * src_stride == itemsize == dst_stride): - * memcpy(dst_data, src_data, itemsize * dst_extent) - */ - __pyx_t_2 = ((__pyx_v_src_stride > 0) != 0); - if (__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L5_bool_binop_done; - } - __pyx_t_2 = ((__pyx_v_dst_stride > 0) != 0); - if (__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L5_bool_binop_done; - } - - /* "View.MemoryView":1154 - * if ndim == 1: - * if (src_stride > 0 and dst_stride > 0 and - * src_stride == itemsize == dst_stride): # <<<<<<<<<<<<<< - * memcpy(dst_data, src_data, itemsize * dst_extent) - * else: - */ - __pyx_t_2 = (((size_t)__pyx_v_src_stride) == __pyx_v_itemsize); - if (__pyx_t_2) { - __pyx_t_2 = (__pyx_v_itemsize == ((size_t)__pyx_v_dst_stride)); - } - __pyx_t_3 = (__pyx_t_2 != 0); - __pyx_t_1 = __pyx_t_3; - __pyx_L5_bool_binop_done:; - - /* "View.MemoryView":1153 - * - * if ndim == 1: - * if (src_stride > 0 and dst_stride > 0 and # <<<<<<<<<<<<<< - * src_stride == itemsize == dst_stride): - * memcpy(dst_data, src_data, itemsize * dst_extent) - */ - if (__pyx_t_1) { - - /* "View.MemoryView":1155 - * if (src_stride > 0 and dst_stride > 0 and - * src_stride == itemsize == dst_stride): - * memcpy(dst_data, src_data, itemsize * dst_extent) # <<<<<<<<<<<<<< - * else: - * for i in range(dst_extent): - */ - (void)(memcpy(__pyx_v_dst_data, __pyx_v_src_data, (__pyx_v_itemsize * __pyx_v_dst_extent))); - - /* "View.MemoryView":1153 - * - * if ndim == 1: - * if (src_stride > 0 and dst_stride > 0 and # <<<<<<<<<<<<<< - * src_stride == itemsize == dst_stride): - * memcpy(dst_data, src_data, itemsize * dst_extent) - */ - goto __pyx_L4; - } - - /* "View.MemoryView":1157 - * memcpy(dst_data, src_data, itemsize * dst_extent) - * else: - * for i in range(dst_extent): # <<<<<<<<<<<<<< - * memcpy(dst_data, src_data, itemsize) - * src_data += src_stride - */ - /*else*/ { - __pyx_t_4 = __pyx_v_dst_extent; - __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; - - /* "View.MemoryView":1158 - * else: - * for i in range(dst_extent): - * memcpy(dst_data, src_data, itemsize) # <<<<<<<<<<<<<< - * src_data += src_stride - * dst_data += dst_stride - */ - (void)(memcpy(__pyx_v_dst_data, __pyx_v_src_data, __pyx_v_itemsize)); - - /* "View.MemoryView":1159 - * for i in range(dst_extent): - * memcpy(dst_data, src_data, itemsize) - * src_data += src_stride # <<<<<<<<<<<<<< - * dst_data += dst_stride - * else: - */ - __pyx_v_src_data = (__pyx_v_src_data + __pyx_v_src_stride); - - /* "View.MemoryView":1160 - * memcpy(dst_data, src_data, itemsize) - * src_data += src_stride - * dst_data += dst_stride # <<<<<<<<<<<<<< - * else: - * for i in range(dst_extent): - */ - __pyx_v_dst_data = (__pyx_v_dst_data + __pyx_v_dst_stride); - } - } - __pyx_L4:; - - /* "View.MemoryView":1152 - * cdef Py_ssize_t dst_stride = dst_strides[0] - * - * if ndim == 1: # <<<<<<<<<<<<<< - * if (src_stride > 0 and dst_stride > 0 and - * src_stride == itemsize == dst_stride): - */ - goto __pyx_L3; - } - - /* "View.MemoryView":1162 - * dst_data += dst_stride - * else: - * for i in range(dst_extent): # <<<<<<<<<<<<<< - * _copy_strided_to_strided(src_data, src_strides + 1, - * dst_data, dst_strides + 1, - */ - /*else*/ { - __pyx_t_4 = __pyx_v_dst_extent; - __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; - - /* "View.MemoryView":1163 - * else: - * for i in range(dst_extent): - * _copy_strided_to_strided(src_data, src_strides + 1, # <<<<<<<<<<<<<< - * dst_data, dst_strides + 1, - * src_shape + 1, dst_shape + 1, - */ - _copy_strided_to_strided(__pyx_v_src_data, (__pyx_v_src_strides + 1), __pyx_v_dst_data, (__pyx_v_dst_strides + 1), (__pyx_v_src_shape + 1), (__pyx_v_dst_shape + 1), (__pyx_v_ndim - 1), __pyx_v_itemsize); - - /* "View.MemoryView":1167 - * src_shape + 1, dst_shape + 1, - * ndim - 1, itemsize) - * src_data += src_stride # <<<<<<<<<<<<<< - * dst_data += dst_stride - * - */ - __pyx_v_src_data = (__pyx_v_src_data + __pyx_v_src_stride); - - /* "View.MemoryView":1168 - * ndim - 1, itemsize) - * src_data += src_stride - * dst_data += dst_stride # <<<<<<<<<<<<<< - * - * cdef void copy_strided_to_strided(__Pyx_memviewslice *src, - */ - __pyx_v_dst_data = (__pyx_v_dst_data + __pyx_v_dst_stride); - } - } - __pyx_L3:; - - /* "View.MemoryView":1140 - * - * @cython.cdivision(True) - * cdef void _copy_strided_to_strided(char *src_data, Py_ssize_t *src_strides, # <<<<<<<<<<<<<< - * char *dst_data, Py_ssize_t *dst_strides, - * Py_ssize_t *src_shape, Py_ssize_t *dst_shape, - */ - - /* function exit code */ -} - -/* "View.MemoryView":1170 - * dst_data += dst_stride - * - * cdef void copy_strided_to_strided(__Pyx_memviewslice *src, # <<<<<<<<<<<<<< - * __Pyx_memviewslice *dst, - * int ndim, size_t itemsize) nogil: - */ - -static void copy_strided_to_strided(__Pyx_memviewslice *__pyx_v_src, __Pyx_memviewslice *__pyx_v_dst, int __pyx_v_ndim, size_t __pyx_v_itemsize) { - - /* "View.MemoryView":1173 - * __Pyx_memviewslice *dst, - * int ndim, size_t itemsize) nogil: - * _copy_strided_to_strided(src.data, src.strides, dst.data, dst.strides, # <<<<<<<<<<<<<< - * src.shape, dst.shape, ndim, itemsize) - * - */ - _copy_strided_to_strided(__pyx_v_src->data, __pyx_v_src->strides, __pyx_v_dst->data, __pyx_v_dst->strides, __pyx_v_src->shape, __pyx_v_dst->shape, __pyx_v_ndim, __pyx_v_itemsize); - - /* "View.MemoryView":1170 - * dst_data += dst_stride - * - * cdef void copy_strided_to_strided(__Pyx_memviewslice *src, # <<<<<<<<<<<<<< - * __Pyx_memviewslice *dst, - * int ndim, size_t itemsize) nogil: - */ - - /* function exit code */ -} - -/* "View.MemoryView":1177 - * - * @cname('__pyx_memoryview_slice_get_size') - * cdef Py_ssize_t slice_get_size(__Pyx_memviewslice *src, int ndim) nogil: # <<<<<<<<<<<<<< - * "Return the size of the memory occupied by the slice in number of bytes" - * cdef Py_ssize_t shape, size = src.memview.view.itemsize - */ - -static Py_ssize_t __pyx_memoryview_slice_get_size(__Pyx_memviewslice *__pyx_v_src, int __pyx_v_ndim) { - Py_ssize_t __pyx_v_shape; - Py_ssize_t __pyx_v_size; - Py_ssize_t __pyx_r; - Py_ssize_t __pyx_t_1; - Py_ssize_t *__pyx_t_2; - Py_ssize_t *__pyx_t_3; - Py_ssize_t *__pyx_t_4; - - /* "View.MemoryView":1179 - * cdef Py_ssize_t slice_get_size(__Pyx_memviewslice *src, int ndim) nogil: - * "Return the size of the memory occupied by the slice in number of bytes" - * cdef Py_ssize_t shape, size = src.memview.view.itemsize # <<<<<<<<<<<<<< - * - * for shape in src.shape[:ndim]: - */ - __pyx_t_1 = __pyx_v_src->memview->view.itemsize; - __pyx_v_size = __pyx_t_1; - - /* "View.MemoryView":1181 - * cdef Py_ssize_t shape, size = src.memview.view.itemsize - * - * for shape in src.shape[:ndim]: # <<<<<<<<<<<<<< - * size *= shape - * - */ - __pyx_t_3 = (__pyx_v_src->shape + __pyx_v_ndim); - for (__pyx_t_4 = __pyx_v_src->shape; __pyx_t_4 < __pyx_t_3; __pyx_t_4++) { - __pyx_t_2 = __pyx_t_4; - __pyx_v_shape = (__pyx_t_2[0]); - - /* "View.MemoryView":1182 - * - * for shape in src.shape[:ndim]: - * size *= shape # <<<<<<<<<<<<<< - * - * return size - */ - __pyx_v_size = (__pyx_v_size * __pyx_v_shape); - } - - /* "View.MemoryView":1184 - * size *= shape - * - * return size # <<<<<<<<<<<<<< - * - * @cname('__pyx_fill_contig_strides_array') - */ - __pyx_r = __pyx_v_size; - goto __pyx_L0; - - /* "View.MemoryView":1177 - * - * @cname('__pyx_memoryview_slice_get_size') - * cdef Py_ssize_t slice_get_size(__Pyx_memviewslice *src, int ndim) nogil: # <<<<<<<<<<<<<< - * "Return the size of the memory occupied by the slice in number of bytes" - * cdef Py_ssize_t shape, size = src.memview.view.itemsize - */ - - /* function exit code */ - __pyx_L0:; - return __pyx_r; -} - -/* "View.MemoryView":1187 - * - * @cname('__pyx_fill_contig_strides_array') - * cdef Py_ssize_t fill_contig_strides_array( # <<<<<<<<<<<<<< - * Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t stride, - * int ndim, char order) nogil: - */ - -static Py_ssize_t __pyx_fill_contig_strides_array(Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, Py_ssize_t __pyx_v_stride, int __pyx_v_ndim, char __pyx_v_order) { - int __pyx_v_idx; - Py_ssize_t __pyx_r; - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - - /* "View.MemoryView":1196 - * cdef int idx - * - * if order == 'F': # <<<<<<<<<<<<<< - * for idx in range(ndim): - * strides[idx] = stride - */ - __pyx_t_1 = ((__pyx_v_order == 'F') != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":1197 - * - * if order == 'F': - * for idx in range(ndim): # <<<<<<<<<<<<<< - * strides[idx] = stride - * stride *= shape[idx] - */ - __pyx_t_2 = __pyx_v_ndim; - __pyx_t_3 = __pyx_t_2; - for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { - __pyx_v_idx = __pyx_t_4; - - /* "View.MemoryView":1198 - * if order == 'F': - * for idx in range(ndim): - * strides[idx] = stride # <<<<<<<<<<<<<< - * stride *= shape[idx] - * else: - */ - (__pyx_v_strides[__pyx_v_idx]) = __pyx_v_stride; - - /* "View.MemoryView":1199 - * for idx in range(ndim): - * strides[idx] = stride - * stride *= shape[idx] # <<<<<<<<<<<<<< - * else: - * for idx in range(ndim - 1, -1, -1): - */ - __pyx_v_stride = (__pyx_v_stride * (__pyx_v_shape[__pyx_v_idx])); - } - - /* "View.MemoryView":1196 - * cdef int idx - * - * if order == 'F': # <<<<<<<<<<<<<< - * for idx in range(ndim): - * strides[idx] = stride - */ - goto __pyx_L3; - } - - /* "View.MemoryView":1201 - * stride *= shape[idx] - * else: - * for idx in range(ndim - 1, -1, -1): # <<<<<<<<<<<<<< - * strides[idx] = stride - * stride *= shape[idx] - */ - /*else*/ { - for (__pyx_t_2 = (__pyx_v_ndim - 1); __pyx_t_2 > -1; __pyx_t_2-=1) { - __pyx_v_idx = __pyx_t_2; - - /* "View.MemoryView":1202 - * else: - * for idx in range(ndim - 1, -1, -1): - * strides[idx] = stride # <<<<<<<<<<<<<< - * stride *= shape[idx] - * - */ - (__pyx_v_strides[__pyx_v_idx]) = __pyx_v_stride; - - /* "View.MemoryView":1203 - * for idx in range(ndim - 1, -1, -1): - * strides[idx] = stride - * stride *= shape[idx] # <<<<<<<<<<<<<< - * - * return stride - */ - __pyx_v_stride = (__pyx_v_stride * (__pyx_v_shape[__pyx_v_idx])); - } - } - __pyx_L3:; - - /* "View.MemoryView":1205 - * stride *= shape[idx] - * - * return stride # <<<<<<<<<<<<<< - * - * @cname('__pyx_memoryview_copy_data_to_temp') - */ - __pyx_r = __pyx_v_stride; - goto __pyx_L0; - - /* "View.MemoryView":1187 - * - * @cname('__pyx_fill_contig_strides_array') - * cdef Py_ssize_t fill_contig_strides_array( # <<<<<<<<<<<<<< - * Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t stride, - * int ndim, char order) nogil: - */ - - /* function exit code */ - __pyx_L0:; - return __pyx_r; -} - -/* "View.MemoryView":1208 - * - * @cname('__pyx_memoryview_copy_data_to_temp') - * cdef void *copy_data_to_temp(__Pyx_memviewslice *src, # <<<<<<<<<<<<<< - * __Pyx_memviewslice *tmpslice, - * char order, - */ - -static void *__pyx_memoryview_copy_data_to_temp(__Pyx_memviewslice *__pyx_v_src, __Pyx_memviewslice *__pyx_v_tmpslice, char __pyx_v_order, int __pyx_v_ndim) { - int __pyx_v_i; - void *__pyx_v_result; - size_t __pyx_v_itemsize; - size_t __pyx_v_size; - void *__pyx_r; - Py_ssize_t __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - struct __pyx_memoryview_obj *__pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - - /* "View.MemoryView":1219 - * cdef void *result - * - * cdef size_t itemsize = src.memview.view.itemsize # <<<<<<<<<<<<<< - * cdef size_t size = slice_get_size(src, ndim) - * - */ - __pyx_t_1 = __pyx_v_src->memview->view.itemsize; - __pyx_v_itemsize = __pyx_t_1; - - /* "View.MemoryView":1220 - * - * cdef size_t itemsize = src.memview.view.itemsize - * cdef size_t size = slice_get_size(src, ndim) # <<<<<<<<<<<<<< - * - * result = malloc(size) - */ - __pyx_v_size = __pyx_memoryview_slice_get_size(__pyx_v_src, __pyx_v_ndim); - - /* "View.MemoryView":1222 - * cdef size_t size = slice_get_size(src, ndim) - * - * result = malloc(size) # <<<<<<<<<<<<<< - * if not result: - * _err(MemoryError, NULL) - */ - __pyx_v_result = malloc(__pyx_v_size); - - /* "View.MemoryView":1223 - * - * result = malloc(size) - * if not result: # <<<<<<<<<<<<<< - * _err(MemoryError, NULL) - * - */ - __pyx_t_2 = ((!(__pyx_v_result != 0)) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":1224 - * result = malloc(size) - * if not result: - * _err(MemoryError, NULL) # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_3 = __pyx_memoryview_err(__pyx_builtin_MemoryError, NULL); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(2, 1224, __pyx_L1_error) - - /* "View.MemoryView":1223 - * - * result = malloc(size) - * if not result: # <<<<<<<<<<<<<< - * _err(MemoryError, NULL) - * - */ - } - - /* "View.MemoryView":1227 - * - * - * tmpslice.data = result # <<<<<<<<<<<<<< - * tmpslice.memview = src.memview - * for i in range(ndim): - */ - __pyx_v_tmpslice->data = ((char *)__pyx_v_result); - - /* "View.MemoryView":1228 - * - * tmpslice.data = result - * tmpslice.memview = src.memview # <<<<<<<<<<<<<< - * for i in range(ndim): - * tmpslice.shape[i] = src.shape[i] - */ - __pyx_t_4 = __pyx_v_src->memview; - __pyx_v_tmpslice->memview = __pyx_t_4; - - /* "View.MemoryView":1229 - * tmpslice.data = result - * tmpslice.memview = src.memview - * for i in range(ndim): # <<<<<<<<<<<<<< - * tmpslice.shape[i] = src.shape[i] - * tmpslice.suboffsets[i] = -1 - */ - __pyx_t_3 = __pyx_v_ndim; - __pyx_t_5 = __pyx_t_3; - for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { - __pyx_v_i = __pyx_t_6; - - /* "View.MemoryView":1230 - * tmpslice.memview = src.memview - * for i in range(ndim): - * tmpslice.shape[i] = src.shape[i] # <<<<<<<<<<<<<< - * tmpslice.suboffsets[i] = -1 - * - */ - (__pyx_v_tmpslice->shape[__pyx_v_i]) = (__pyx_v_src->shape[__pyx_v_i]); - - /* "View.MemoryView":1231 - * for i in range(ndim): - * tmpslice.shape[i] = src.shape[i] - * tmpslice.suboffsets[i] = -1 # <<<<<<<<<<<<<< - * - * fill_contig_strides_array(&tmpslice.shape[0], &tmpslice.strides[0], itemsize, - */ - (__pyx_v_tmpslice->suboffsets[__pyx_v_i]) = -1L; - } - - /* "View.MemoryView":1233 - * tmpslice.suboffsets[i] = -1 - * - * fill_contig_strides_array(&tmpslice.shape[0], &tmpslice.strides[0], itemsize, # <<<<<<<<<<<<<< - * ndim, order) - * - */ - (void)(__pyx_fill_contig_strides_array((&(__pyx_v_tmpslice->shape[0])), (&(__pyx_v_tmpslice->strides[0])), __pyx_v_itemsize, __pyx_v_ndim, __pyx_v_order)); - - /* "View.MemoryView":1237 - * - * - * for i in range(ndim): # <<<<<<<<<<<<<< - * if tmpslice.shape[i] == 1: - * tmpslice.strides[i] = 0 - */ - __pyx_t_3 = __pyx_v_ndim; - __pyx_t_5 = __pyx_t_3; - for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { - __pyx_v_i = __pyx_t_6; - - /* "View.MemoryView":1238 - * - * for i in range(ndim): - * if tmpslice.shape[i] == 1: # <<<<<<<<<<<<<< - * tmpslice.strides[i] = 0 - * - */ - __pyx_t_2 = (((__pyx_v_tmpslice->shape[__pyx_v_i]) == 1) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":1239 - * for i in range(ndim): - * if tmpslice.shape[i] == 1: - * tmpslice.strides[i] = 0 # <<<<<<<<<<<<<< - * - * if slice_is_contig(src[0], order, ndim): - */ - (__pyx_v_tmpslice->strides[__pyx_v_i]) = 0; - - /* "View.MemoryView":1238 - * - * for i in range(ndim): - * if tmpslice.shape[i] == 1: # <<<<<<<<<<<<<< - * tmpslice.strides[i] = 0 - * - */ - } - } - - /* "View.MemoryView":1241 - * tmpslice.strides[i] = 0 - * - * if slice_is_contig(src[0], order, ndim): # <<<<<<<<<<<<<< - * memcpy(result, src.data, size) - * else: - */ - __pyx_t_2 = (__pyx_memviewslice_is_contig((__pyx_v_src[0]), __pyx_v_order, __pyx_v_ndim) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":1242 - * - * if slice_is_contig(src[0], order, ndim): - * memcpy(result, src.data, size) # <<<<<<<<<<<<<< - * else: - * copy_strided_to_strided(src, tmpslice, ndim, itemsize) - */ - (void)(memcpy(__pyx_v_result, __pyx_v_src->data, __pyx_v_size)); - - /* "View.MemoryView":1241 - * tmpslice.strides[i] = 0 - * - * if slice_is_contig(src[0], order, ndim): # <<<<<<<<<<<<<< - * memcpy(result, src.data, size) - * else: - */ - goto __pyx_L9; - } - - /* "View.MemoryView":1244 - * memcpy(result, src.data, size) - * else: - * copy_strided_to_strided(src, tmpslice, ndim, itemsize) # <<<<<<<<<<<<<< - * - * return result - */ - /*else*/ { - copy_strided_to_strided(__pyx_v_src, __pyx_v_tmpslice, __pyx_v_ndim, __pyx_v_itemsize); - } - __pyx_L9:; - - /* "View.MemoryView":1246 - * copy_strided_to_strided(src, tmpslice, ndim, itemsize) - * - * return result # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = __pyx_v_result; - goto __pyx_L0; - - /* "View.MemoryView":1208 - * - * @cname('__pyx_memoryview_copy_data_to_temp') - * cdef void *copy_data_to_temp(__Pyx_memviewslice *src, # <<<<<<<<<<<<<< - * __Pyx_memviewslice *tmpslice, - * char order, - */ - - /* function exit code */ - __pyx_L1_error:; - { - #ifdef WITH_THREAD - PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); - #endif - __Pyx_AddTraceback("View.MemoryView.copy_data_to_temp", __pyx_clineno, __pyx_lineno, __pyx_filename); - #ifdef WITH_THREAD - __Pyx_PyGILState_Release(__pyx_gilstate_save); - #endif - } - __pyx_r = NULL; - __pyx_L0:; - return __pyx_r; -} - -/* "View.MemoryView":1251 - * - * @cname('__pyx_memoryview_err_extents') - * cdef int _err_extents(int i, Py_ssize_t extent1, # <<<<<<<<<<<<<< - * Py_ssize_t extent2) except -1 with gil: - * raise ValueError("got differing extents in dimension %d (got %d and %d)" % - */ - -static int __pyx_memoryview_err_extents(int __pyx_v_i, Py_ssize_t __pyx_v_extent1, Py_ssize_t __pyx_v_extent2) { - 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_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - #ifdef WITH_THREAD - PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); - #endif - __Pyx_RefNannySetupContext("_err_extents", 0); - - /* "View.MemoryView":1254 - * Py_ssize_t extent2) except -1 with gil: - * raise ValueError("got differing extents in dimension %d (got %d and %d)" % - * (i, extent1, extent2)) # <<<<<<<<<<<<<< - * - * @cname('__pyx_memoryview_err_dim') - */ - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1254, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_extent1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1254, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_extent2); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 1254, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 1254, __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_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); - __pyx_t_1 = 0; - __pyx_t_2 = 0; - __pyx_t_3 = 0; - - /* "View.MemoryView":1253 - * cdef int _err_extents(int i, Py_ssize_t extent1, - * Py_ssize_t extent2) except -1 with gil: - * raise ValueError("got differing extents in dimension %d (got %d and %d)" % # <<<<<<<<<<<<<< - * (i, extent1, extent2)) - * - */ - __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_got_differing_extents_in_dimensi, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 1253, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 1253, __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, 1253, __pyx_L1_error) - - /* "View.MemoryView":1251 - * - * @cname('__pyx_memoryview_err_extents') - * cdef int _err_extents(int i, Py_ssize_t extent1, # <<<<<<<<<<<<<< - * Py_ssize_t extent2) except -1 with gil: - * raise ValueError("got differing extents in dimension %d (got %d and %d)" % - */ - - /* 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_4); - __Pyx_AddTraceback("View.MemoryView._err_extents", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __Pyx_RefNannyFinishContext(); - #ifdef WITH_THREAD - __Pyx_PyGILState_Release(__pyx_gilstate_save); - #endif - return __pyx_r; -} - -/* "View.MemoryView":1257 - * - * @cname('__pyx_memoryview_err_dim') - * cdef int _err_dim(object error, char *msg, int dim) except -1 with gil: # <<<<<<<<<<<<<< - * raise error(msg.decode('ascii') % dim) - * - */ - -static int __pyx_memoryview_err_dim(PyObject *__pyx_v_error, char *__pyx_v_msg, int __pyx_v_dim) { - 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_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - #ifdef WITH_THREAD - PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); - #endif - __Pyx_RefNannySetupContext("_err_dim", 0); - __Pyx_INCREF(__pyx_v_error); - - /* "View.MemoryView":1258 - * @cname('__pyx_memoryview_err_dim') - * cdef int _err_dim(object error, char *msg, int dim) except -1 with gil: - * raise error(msg.decode('ascii') % dim) # <<<<<<<<<<<<<< - * - * @cname('__pyx_memoryview_err') - */ - __pyx_t_2 = __Pyx_decode_c_string(__pyx_v_msg, 0, strlen(__pyx_v_msg), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1258, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 1258, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyUnicode_Format(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 1258, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_INCREF(__pyx_v_error); - __pyx_t_3 = __pyx_v_error; __pyx_t_2 = NULL; - 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_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1258, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(2, 1258, __pyx_L1_error) - - /* "View.MemoryView":1257 - * - * @cname('__pyx_memoryview_err_dim') - * cdef int _err_dim(object error, char *msg, int dim) except -1 with gil: # <<<<<<<<<<<<<< - * raise error(msg.decode('ascii') % dim) - * - */ - - /* 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_4); - __Pyx_AddTraceback("View.MemoryView._err_dim", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __Pyx_XDECREF(__pyx_v_error); - __Pyx_RefNannyFinishContext(); - #ifdef WITH_THREAD - __Pyx_PyGILState_Release(__pyx_gilstate_save); - #endif - return __pyx_r; -} - -/* "View.MemoryView":1261 - * - * @cname('__pyx_memoryview_err') - * cdef int _err(object error, char *msg) except -1 with gil: # <<<<<<<<<<<<<< - * if msg != NULL: - * raise error(msg.decode('ascii')) - */ - -static int __pyx_memoryview_err(PyObject *__pyx_v_error, char *__pyx_v_msg) { - int __pyx_r; - __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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - #ifdef WITH_THREAD - PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); - #endif - __Pyx_RefNannySetupContext("_err", 0); - __Pyx_INCREF(__pyx_v_error); - - /* "View.MemoryView":1262 - * @cname('__pyx_memoryview_err') - * cdef int _err(object error, char *msg) except -1 with gil: - * if msg != NULL: # <<<<<<<<<<<<<< - * raise error(msg.decode('ascii')) - * else: - */ - __pyx_t_1 = ((__pyx_v_msg != NULL) != 0); - if (unlikely(__pyx_t_1)) { - - /* "View.MemoryView":1263 - * cdef int _err(object error, char *msg) except -1 with gil: - * if msg != NULL: - * raise error(msg.decode('ascii')) # <<<<<<<<<<<<<< - * else: - * raise error - */ - __pyx_t_3 = __Pyx_decode_c_string(__pyx_v_msg, 0, strlen(__pyx_v_msg), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 1263, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_error); - __pyx_t_4 = __pyx_v_error; __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); - } - } - __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1263, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(2, 1263, __pyx_L1_error) - - /* "View.MemoryView":1262 - * @cname('__pyx_memoryview_err') - * cdef int _err(object error, char *msg) except -1 with gil: - * if msg != NULL: # <<<<<<<<<<<<<< - * raise error(msg.decode('ascii')) - * else: - */ - } - - /* "View.MemoryView":1265 - * raise error(msg.decode('ascii')) - * else: - * raise error # <<<<<<<<<<<<<< - * - * @cname('__pyx_memoryview_copy_contents') - */ - /*else*/ { - __Pyx_Raise(__pyx_v_error, 0, 0, 0); - __PYX_ERR(2, 1265, __pyx_L1_error) - } - - /* "View.MemoryView":1261 - * - * @cname('__pyx_memoryview_err') - * cdef int _err(object error, char *msg) except -1 with gil: # <<<<<<<<<<<<<< - * if msg != NULL: - * raise error(msg.decode('ascii')) - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("View.MemoryView._err", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __Pyx_XDECREF(__pyx_v_error); - __Pyx_RefNannyFinishContext(); - #ifdef WITH_THREAD - __Pyx_PyGILState_Release(__pyx_gilstate_save); - #endif - return __pyx_r; -} - -/* "View.MemoryView":1268 - * - * @cname('__pyx_memoryview_copy_contents') - * cdef int memoryview_copy_contents(__Pyx_memviewslice src, # <<<<<<<<<<<<<< - * __Pyx_memviewslice dst, - * int src_ndim, int dst_ndim, - */ - -static int __pyx_memoryview_copy_contents(__Pyx_memviewslice __pyx_v_src, __Pyx_memviewslice __pyx_v_dst, int __pyx_v_src_ndim, int __pyx_v_dst_ndim, int __pyx_v_dtype_is_object) { - void *__pyx_v_tmpdata; - size_t __pyx_v_itemsize; - int __pyx_v_i; - char __pyx_v_order; - int __pyx_v_broadcasting; - int __pyx_v_direct_copy; - __Pyx_memviewslice __pyx_v_tmp; - int __pyx_v_ndim; - int __pyx_r; - Py_ssize_t __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - void *__pyx_t_7; - int __pyx_t_8; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - - /* "View.MemoryView":1276 - * Check for overlapping memory and verify the shapes. - * """ - * cdef void *tmpdata = NULL # <<<<<<<<<<<<<< - * cdef size_t itemsize = src.memview.view.itemsize - * cdef int i - */ - __pyx_v_tmpdata = NULL; - - /* "View.MemoryView":1277 - * """ - * cdef void *tmpdata = NULL - * cdef size_t itemsize = src.memview.view.itemsize # <<<<<<<<<<<<<< - * cdef int i - * cdef char order = get_best_order(&src, src_ndim) - */ - __pyx_t_1 = __pyx_v_src.memview->view.itemsize; - __pyx_v_itemsize = __pyx_t_1; - - /* "View.MemoryView":1279 - * cdef size_t itemsize = src.memview.view.itemsize - * cdef int i - * cdef char order = get_best_order(&src, src_ndim) # <<<<<<<<<<<<<< - * cdef bint broadcasting = False - * cdef bint direct_copy = False - */ - __pyx_v_order = __pyx_get_best_slice_order((&__pyx_v_src), __pyx_v_src_ndim); - - /* "View.MemoryView":1280 - * cdef int i - * cdef char order = get_best_order(&src, src_ndim) - * cdef bint broadcasting = False # <<<<<<<<<<<<<< - * cdef bint direct_copy = False - * cdef __Pyx_memviewslice tmp - */ - __pyx_v_broadcasting = 0; - - /* "View.MemoryView":1281 - * cdef char order = get_best_order(&src, src_ndim) - * cdef bint broadcasting = False - * cdef bint direct_copy = False # <<<<<<<<<<<<<< - * cdef __Pyx_memviewslice tmp - * - */ - __pyx_v_direct_copy = 0; - - /* "View.MemoryView":1284 - * cdef __Pyx_memviewslice tmp - * - * if src_ndim < dst_ndim: # <<<<<<<<<<<<<< - * broadcast_leading(&src, src_ndim, dst_ndim) - * elif dst_ndim < src_ndim: - */ - __pyx_t_2 = ((__pyx_v_src_ndim < __pyx_v_dst_ndim) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":1285 - * - * if src_ndim < dst_ndim: - * broadcast_leading(&src, src_ndim, dst_ndim) # <<<<<<<<<<<<<< - * elif dst_ndim < src_ndim: - * broadcast_leading(&dst, dst_ndim, src_ndim) - */ - __pyx_memoryview_broadcast_leading((&__pyx_v_src), __pyx_v_src_ndim, __pyx_v_dst_ndim); - - /* "View.MemoryView":1284 - * cdef __Pyx_memviewslice tmp - * - * if src_ndim < dst_ndim: # <<<<<<<<<<<<<< - * broadcast_leading(&src, src_ndim, dst_ndim) - * elif dst_ndim < src_ndim: - */ - goto __pyx_L3; - } - - /* "View.MemoryView":1286 - * if src_ndim < dst_ndim: - * broadcast_leading(&src, src_ndim, dst_ndim) - * elif dst_ndim < src_ndim: # <<<<<<<<<<<<<< - * broadcast_leading(&dst, dst_ndim, src_ndim) - * - */ - __pyx_t_2 = ((__pyx_v_dst_ndim < __pyx_v_src_ndim) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":1287 - * broadcast_leading(&src, src_ndim, dst_ndim) - * elif dst_ndim < src_ndim: - * broadcast_leading(&dst, dst_ndim, src_ndim) # <<<<<<<<<<<<<< - * - * cdef int ndim = max(src_ndim, dst_ndim) - */ - __pyx_memoryview_broadcast_leading((&__pyx_v_dst), __pyx_v_dst_ndim, __pyx_v_src_ndim); - - /* "View.MemoryView":1286 - * if src_ndim < dst_ndim: - * broadcast_leading(&src, src_ndim, dst_ndim) - * elif dst_ndim < src_ndim: # <<<<<<<<<<<<<< - * broadcast_leading(&dst, dst_ndim, src_ndim) - * - */ - } - __pyx_L3:; - - /* "View.MemoryView":1289 - * broadcast_leading(&dst, dst_ndim, src_ndim) - * - * cdef int ndim = max(src_ndim, dst_ndim) # <<<<<<<<<<<<<< - * - * for i in range(ndim): - */ - __pyx_t_3 = __pyx_v_dst_ndim; - __pyx_t_4 = __pyx_v_src_ndim; - if (((__pyx_t_3 > __pyx_t_4) != 0)) { - __pyx_t_5 = __pyx_t_3; - } else { - __pyx_t_5 = __pyx_t_4; - } - __pyx_v_ndim = __pyx_t_5; - - /* "View.MemoryView":1291 - * cdef int ndim = max(src_ndim, dst_ndim) - * - * for i in range(ndim): # <<<<<<<<<<<<<< - * if src.shape[i] != dst.shape[i]: - * if src.shape[i] == 1: - */ - __pyx_t_5 = __pyx_v_ndim; - __pyx_t_3 = __pyx_t_5; - for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { - __pyx_v_i = __pyx_t_4; - - /* "View.MemoryView":1292 - * - * for i in range(ndim): - * if src.shape[i] != dst.shape[i]: # <<<<<<<<<<<<<< - * if src.shape[i] == 1: - * broadcasting = True - */ - __pyx_t_2 = (((__pyx_v_src.shape[__pyx_v_i]) != (__pyx_v_dst.shape[__pyx_v_i])) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":1293 - * for i in range(ndim): - * if src.shape[i] != dst.shape[i]: - * if src.shape[i] == 1: # <<<<<<<<<<<<<< - * broadcasting = True - * src.strides[i] = 0 - */ - __pyx_t_2 = (((__pyx_v_src.shape[__pyx_v_i]) == 1) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":1294 - * if src.shape[i] != dst.shape[i]: - * if src.shape[i] == 1: - * broadcasting = True # <<<<<<<<<<<<<< - * src.strides[i] = 0 - * else: - */ - __pyx_v_broadcasting = 1; - - /* "View.MemoryView":1295 - * if src.shape[i] == 1: - * broadcasting = True - * src.strides[i] = 0 # <<<<<<<<<<<<<< - * else: - * _err_extents(i, dst.shape[i], src.shape[i]) - */ - (__pyx_v_src.strides[__pyx_v_i]) = 0; - - /* "View.MemoryView":1293 - * for i in range(ndim): - * if src.shape[i] != dst.shape[i]: - * if src.shape[i] == 1: # <<<<<<<<<<<<<< - * broadcasting = True - * src.strides[i] = 0 - */ - goto __pyx_L7; - } - - /* "View.MemoryView":1297 - * src.strides[i] = 0 - * else: - * _err_extents(i, dst.shape[i], src.shape[i]) # <<<<<<<<<<<<<< - * - * if src.suboffsets[i] >= 0: - */ - /*else*/ { - __pyx_t_6 = __pyx_memoryview_err_extents(__pyx_v_i, (__pyx_v_dst.shape[__pyx_v_i]), (__pyx_v_src.shape[__pyx_v_i])); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(2, 1297, __pyx_L1_error) - } - __pyx_L7:; - - /* "View.MemoryView":1292 - * - * for i in range(ndim): - * if src.shape[i] != dst.shape[i]: # <<<<<<<<<<<<<< - * if src.shape[i] == 1: - * broadcasting = True - */ - } - - /* "View.MemoryView":1299 - * _err_extents(i, dst.shape[i], src.shape[i]) - * - * if src.suboffsets[i] >= 0: # <<<<<<<<<<<<<< - * _err_dim(ValueError, "Dimension %d is not direct", i) - * - */ - __pyx_t_2 = (((__pyx_v_src.suboffsets[__pyx_v_i]) >= 0) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":1300 - * - * if src.suboffsets[i] >= 0: - * _err_dim(ValueError, "Dimension %d is not direct", i) # <<<<<<<<<<<<<< - * - * if slices_overlap(&src, &dst, ndim, itemsize): - */ - __pyx_t_6 = __pyx_memoryview_err_dim(__pyx_builtin_ValueError, ((char *)"Dimension %d is not direct"), __pyx_v_i); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(2, 1300, __pyx_L1_error) - - /* "View.MemoryView":1299 - * _err_extents(i, dst.shape[i], src.shape[i]) - * - * if src.suboffsets[i] >= 0: # <<<<<<<<<<<<<< - * _err_dim(ValueError, "Dimension %d is not direct", i) - * - */ - } - } - - /* "View.MemoryView":1302 - * _err_dim(ValueError, "Dimension %d is not direct", i) - * - * if slices_overlap(&src, &dst, ndim, itemsize): # <<<<<<<<<<<<<< - * - * if not slice_is_contig(src, order, ndim): - */ - __pyx_t_2 = (__pyx_slices_overlap((&__pyx_v_src), (&__pyx_v_dst), __pyx_v_ndim, __pyx_v_itemsize) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":1304 - * if slices_overlap(&src, &dst, ndim, itemsize): - * - * if not slice_is_contig(src, order, ndim): # <<<<<<<<<<<<<< - * order = get_best_order(&dst, ndim) - * - */ - __pyx_t_2 = ((!(__pyx_memviewslice_is_contig(__pyx_v_src, __pyx_v_order, __pyx_v_ndim) != 0)) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":1305 - * - * if not slice_is_contig(src, order, ndim): - * order = get_best_order(&dst, ndim) # <<<<<<<<<<<<<< - * - * tmpdata = copy_data_to_temp(&src, &tmp, order, ndim) - */ - __pyx_v_order = __pyx_get_best_slice_order((&__pyx_v_dst), __pyx_v_ndim); - - /* "View.MemoryView":1304 - * if slices_overlap(&src, &dst, ndim, itemsize): - * - * if not slice_is_contig(src, order, ndim): # <<<<<<<<<<<<<< - * order = get_best_order(&dst, ndim) - * - */ - } - - /* "View.MemoryView":1307 - * order = get_best_order(&dst, ndim) - * - * tmpdata = copy_data_to_temp(&src, &tmp, order, ndim) # <<<<<<<<<<<<<< - * src = tmp - * - */ - __pyx_t_7 = __pyx_memoryview_copy_data_to_temp((&__pyx_v_src), (&__pyx_v_tmp), __pyx_v_order, __pyx_v_ndim); if (unlikely(__pyx_t_7 == ((void *)NULL))) __PYX_ERR(2, 1307, __pyx_L1_error) - __pyx_v_tmpdata = __pyx_t_7; - - /* "View.MemoryView":1308 - * - * tmpdata = copy_data_to_temp(&src, &tmp, order, ndim) - * src = tmp # <<<<<<<<<<<<<< - * - * if not broadcasting: - */ - __pyx_v_src = __pyx_v_tmp; - - /* "View.MemoryView":1302 - * _err_dim(ValueError, "Dimension %d is not direct", i) - * - * if slices_overlap(&src, &dst, ndim, itemsize): # <<<<<<<<<<<<<< - * - * if not slice_is_contig(src, order, ndim): - */ - } - - /* "View.MemoryView":1310 - * src = tmp - * - * if not broadcasting: # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_2 = ((!(__pyx_v_broadcasting != 0)) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":1313 - * - * - * if slice_is_contig(src, 'C', ndim): # <<<<<<<<<<<<<< - * direct_copy = slice_is_contig(dst, 'C', ndim) - * elif slice_is_contig(src, 'F', ndim): - */ - __pyx_t_2 = (__pyx_memviewslice_is_contig(__pyx_v_src, 'C', __pyx_v_ndim) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":1314 - * - * if slice_is_contig(src, 'C', ndim): - * direct_copy = slice_is_contig(dst, 'C', ndim) # <<<<<<<<<<<<<< - * elif slice_is_contig(src, 'F', ndim): - * direct_copy = slice_is_contig(dst, 'F', ndim) - */ - __pyx_v_direct_copy = __pyx_memviewslice_is_contig(__pyx_v_dst, 'C', __pyx_v_ndim); - - /* "View.MemoryView":1313 - * - * - * if slice_is_contig(src, 'C', ndim): # <<<<<<<<<<<<<< - * direct_copy = slice_is_contig(dst, 'C', ndim) - * elif slice_is_contig(src, 'F', ndim): - */ - goto __pyx_L12; - } - - /* "View.MemoryView":1315 - * if slice_is_contig(src, 'C', ndim): - * direct_copy = slice_is_contig(dst, 'C', ndim) - * elif slice_is_contig(src, 'F', ndim): # <<<<<<<<<<<<<< - * direct_copy = slice_is_contig(dst, 'F', ndim) - * - */ - __pyx_t_2 = (__pyx_memviewslice_is_contig(__pyx_v_src, 'F', __pyx_v_ndim) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":1316 - * direct_copy = slice_is_contig(dst, 'C', ndim) - * elif slice_is_contig(src, 'F', ndim): - * direct_copy = slice_is_contig(dst, 'F', ndim) # <<<<<<<<<<<<<< - * - * if direct_copy: - */ - __pyx_v_direct_copy = __pyx_memviewslice_is_contig(__pyx_v_dst, 'F', __pyx_v_ndim); - - /* "View.MemoryView":1315 - * if slice_is_contig(src, 'C', ndim): - * direct_copy = slice_is_contig(dst, 'C', ndim) - * elif slice_is_contig(src, 'F', ndim): # <<<<<<<<<<<<<< - * direct_copy = slice_is_contig(dst, 'F', ndim) - * - */ - } - __pyx_L12:; - - /* "View.MemoryView":1318 - * direct_copy = slice_is_contig(dst, 'F', ndim) - * - * if direct_copy: # <<<<<<<<<<<<<< - * - * refcount_copying(&dst, dtype_is_object, ndim, False) - */ - __pyx_t_2 = (__pyx_v_direct_copy != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":1320 - * if direct_copy: - * - * refcount_copying(&dst, dtype_is_object, ndim, False) # <<<<<<<<<<<<<< - * memcpy(dst.data, src.data, slice_get_size(&src, ndim)) - * refcount_copying(&dst, dtype_is_object, ndim, True) - */ - __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 0); - - /* "View.MemoryView":1321 - * - * refcount_copying(&dst, dtype_is_object, ndim, False) - * memcpy(dst.data, src.data, slice_get_size(&src, ndim)) # <<<<<<<<<<<<<< - * refcount_copying(&dst, dtype_is_object, ndim, True) - * free(tmpdata) - */ - (void)(memcpy(__pyx_v_dst.data, __pyx_v_src.data, __pyx_memoryview_slice_get_size((&__pyx_v_src), __pyx_v_ndim))); - - /* "View.MemoryView":1322 - * refcount_copying(&dst, dtype_is_object, ndim, False) - * memcpy(dst.data, src.data, slice_get_size(&src, ndim)) - * refcount_copying(&dst, dtype_is_object, ndim, True) # <<<<<<<<<<<<<< - * free(tmpdata) - * return 0 - */ - __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 1); - - /* "View.MemoryView":1323 - * memcpy(dst.data, src.data, slice_get_size(&src, ndim)) - * refcount_copying(&dst, dtype_is_object, ndim, True) - * free(tmpdata) # <<<<<<<<<<<<<< - * return 0 - * - */ - free(__pyx_v_tmpdata); - - /* "View.MemoryView":1324 - * refcount_copying(&dst, dtype_is_object, ndim, True) - * free(tmpdata) - * return 0 # <<<<<<<<<<<<<< - * - * if order == 'F' == get_best_order(&dst, ndim): - */ - __pyx_r = 0; - goto __pyx_L0; - - /* "View.MemoryView":1318 - * direct_copy = slice_is_contig(dst, 'F', ndim) - * - * if direct_copy: # <<<<<<<<<<<<<< - * - * refcount_copying(&dst, dtype_is_object, ndim, False) - */ - } - - /* "View.MemoryView":1310 - * src = tmp - * - * if not broadcasting: # <<<<<<<<<<<<<< - * - * - */ - } - - /* "View.MemoryView":1326 - * return 0 - * - * if order == 'F' == get_best_order(&dst, ndim): # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_2 = (__pyx_v_order == 'F'); - if (__pyx_t_2) { - __pyx_t_2 = ('F' == __pyx_get_best_slice_order((&__pyx_v_dst), __pyx_v_ndim)); - } - __pyx_t_8 = (__pyx_t_2 != 0); - if (__pyx_t_8) { - - /* "View.MemoryView":1329 - * - * - * transpose_memslice(&src) # <<<<<<<<<<<<<< - * transpose_memslice(&dst) - * - */ - __pyx_t_5 = __pyx_memslice_transpose((&__pyx_v_src)); if (unlikely(__pyx_t_5 == ((int)0))) __PYX_ERR(2, 1329, __pyx_L1_error) - - /* "View.MemoryView":1330 - * - * transpose_memslice(&src) - * transpose_memslice(&dst) # <<<<<<<<<<<<<< - * - * refcount_copying(&dst, dtype_is_object, ndim, False) - */ - __pyx_t_5 = __pyx_memslice_transpose((&__pyx_v_dst)); if (unlikely(__pyx_t_5 == ((int)0))) __PYX_ERR(2, 1330, __pyx_L1_error) - - /* "View.MemoryView":1326 - * return 0 - * - * if order == 'F' == get_best_order(&dst, ndim): # <<<<<<<<<<<<<< - * - * - */ - } - - /* "View.MemoryView":1332 - * transpose_memslice(&dst) - * - * refcount_copying(&dst, dtype_is_object, ndim, False) # <<<<<<<<<<<<<< - * copy_strided_to_strided(&src, &dst, ndim, itemsize) - * refcount_copying(&dst, dtype_is_object, ndim, True) - */ - __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 0); - - /* "View.MemoryView":1333 - * - * refcount_copying(&dst, dtype_is_object, ndim, False) - * copy_strided_to_strided(&src, &dst, ndim, itemsize) # <<<<<<<<<<<<<< - * refcount_copying(&dst, dtype_is_object, ndim, True) - * - */ - copy_strided_to_strided((&__pyx_v_src), (&__pyx_v_dst), __pyx_v_ndim, __pyx_v_itemsize); - - /* "View.MemoryView":1334 - * refcount_copying(&dst, dtype_is_object, ndim, False) - * copy_strided_to_strided(&src, &dst, ndim, itemsize) - * refcount_copying(&dst, dtype_is_object, ndim, True) # <<<<<<<<<<<<<< - * - * free(tmpdata) - */ - __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 1); - - /* "View.MemoryView":1336 - * refcount_copying(&dst, dtype_is_object, ndim, True) - * - * free(tmpdata) # <<<<<<<<<<<<<< - * return 0 - * - */ - free(__pyx_v_tmpdata); - - /* "View.MemoryView":1337 - * - * free(tmpdata) - * return 0 # <<<<<<<<<<<<<< - * - * @cname('__pyx_memoryview_broadcast_leading') - */ - __pyx_r = 0; - goto __pyx_L0; - - /* "View.MemoryView":1268 - * - * @cname('__pyx_memoryview_copy_contents') - * cdef int memoryview_copy_contents(__Pyx_memviewslice src, # <<<<<<<<<<<<<< - * __Pyx_memviewslice dst, - * int src_ndim, int dst_ndim, - */ - - /* function exit code */ - __pyx_L1_error:; - { - #ifdef WITH_THREAD - PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); - #endif - __Pyx_AddTraceback("View.MemoryView.memoryview_copy_contents", __pyx_clineno, __pyx_lineno, __pyx_filename); - #ifdef WITH_THREAD - __Pyx_PyGILState_Release(__pyx_gilstate_save); - #endif - } - __pyx_r = -1; - __pyx_L0:; - return __pyx_r; -} - -/* "View.MemoryView":1340 - * - * @cname('__pyx_memoryview_broadcast_leading') - * cdef void broadcast_leading(__Pyx_memviewslice *mslice, # <<<<<<<<<<<<<< - * int ndim, - * int ndim_other) nogil: - */ - -static void __pyx_memoryview_broadcast_leading(__Pyx_memviewslice *__pyx_v_mslice, int __pyx_v_ndim, int __pyx_v_ndim_other) { - int __pyx_v_i; - int __pyx_v_offset; - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - - /* "View.MemoryView":1344 - * int ndim_other) nogil: - * cdef int i - * cdef int offset = ndim_other - ndim # <<<<<<<<<<<<<< - * - * for i in range(ndim - 1, -1, -1): - */ - __pyx_v_offset = (__pyx_v_ndim_other - __pyx_v_ndim); - - /* "View.MemoryView":1346 - * cdef int offset = ndim_other - ndim - * - * for i in range(ndim - 1, -1, -1): # <<<<<<<<<<<<<< - * mslice.shape[i + offset] = mslice.shape[i] - * mslice.strides[i + offset] = mslice.strides[i] - */ - for (__pyx_t_1 = (__pyx_v_ndim - 1); __pyx_t_1 > -1; __pyx_t_1-=1) { - __pyx_v_i = __pyx_t_1; - - /* "View.MemoryView":1347 - * - * for i in range(ndim - 1, -1, -1): - * mslice.shape[i + offset] = mslice.shape[i] # <<<<<<<<<<<<<< - * mslice.strides[i + offset] = mslice.strides[i] - * mslice.suboffsets[i + offset] = mslice.suboffsets[i] - */ - (__pyx_v_mslice->shape[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_mslice->shape[__pyx_v_i]); - - /* "View.MemoryView":1348 - * for i in range(ndim - 1, -1, -1): - * mslice.shape[i + offset] = mslice.shape[i] - * mslice.strides[i + offset] = mslice.strides[i] # <<<<<<<<<<<<<< - * mslice.suboffsets[i + offset] = mslice.suboffsets[i] - * - */ - (__pyx_v_mslice->strides[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_mslice->strides[__pyx_v_i]); - - /* "View.MemoryView":1349 - * mslice.shape[i + offset] = mslice.shape[i] - * mslice.strides[i + offset] = mslice.strides[i] - * mslice.suboffsets[i + offset] = mslice.suboffsets[i] # <<<<<<<<<<<<<< - * - * for i in range(offset): - */ - (__pyx_v_mslice->suboffsets[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_mslice->suboffsets[__pyx_v_i]); - } - - /* "View.MemoryView":1351 - * mslice.suboffsets[i + offset] = mslice.suboffsets[i] - * - * for i in range(offset): # <<<<<<<<<<<<<< - * mslice.shape[i] = 1 - * mslice.strides[i] = mslice.strides[0] - */ - __pyx_t_1 = __pyx_v_offset; - __pyx_t_2 = __pyx_t_1; - for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_v_i = __pyx_t_3; - - /* "View.MemoryView":1352 - * - * for i in range(offset): - * mslice.shape[i] = 1 # <<<<<<<<<<<<<< - * mslice.strides[i] = mslice.strides[0] - * mslice.suboffsets[i] = -1 - */ - (__pyx_v_mslice->shape[__pyx_v_i]) = 1; - - /* "View.MemoryView":1353 - * for i in range(offset): - * mslice.shape[i] = 1 - * mslice.strides[i] = mslice.strides[0] # <<<<<<<<<<<<<< - * mslice.suboffsets[i] = -1 - * - */ - (__pyx_v_mslice->strides[__pyx_v_i]) = (__pyx_v_mslice->strides[0]); - - /* "View.MemoryView":1354 - * mslice.shape[i] = 1 - * mslice.strides[i] = mslice.strides[0] - * mslice.suboffsets[i] = -1 # <<<<<<<<<<<<<< - * - * - */ - (__pyx_v_mslice->suboffsets[__pyx_v_i]) = -1L; - } - - /* "View.MemoryView":1340 - * - * @cname('__pyx_memoryview_broadcast_leading') - * cdef void broadcast_leading(__Pyx_memviewslice *mslice, # <<<<<<<<<<<<<< - * int ndim, - * int ndim_other) nogil: - */ - - /* function exit code */ -} - -/* "View.MemoryView":1362 - * - * @cname('__pyx_memoryview_refcount_copying') - * cdef void refcount_copying(__Pyx_memviewslice *dst, bint dtype_is_object, # <<<<<<<<<<<<<< - * int ndim, bint inc) nogil: - * - */ - -static void __pyx_memoryview_refcount_copying(__Pyx_memviewslice *__pyx_v_dst, int __pyx_v_dtype_is_object, int __pyx_v_ndim, int __pyx_v_inc) { - int __pyx_t_1; - - /* "View.MemoryView":1366 - * - * - * if dtype_is_object: # <<<<<<<<<<<<<< - * refcount_objects_in_slice_with_gil(dst.data, dst.shape, - * dst.strides, ndim, inc) - */ - __pyx_t_1 = (__pyx_v_dtype_is_object != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":1367 - * - * if dtype_is_object: - * refcount_objects_in_slice_with_gil(dst.data, dst.shape, # <<<<<<<<<<<<<< - * dst.strides, ndim, inc) - * - */ - __pyx_memoryview_refcount_objects_in_slice_with_gil(__pyx_v_dst->data, __pyx_v_dst->shape, __pyx_v_dst->strides, __pyx_v_ndim, __pyx_v_inc); - - /* "View.MemoryView":1366 - * - * - * if dtype_is_object: # <<<<<<<<<<<<<< - * refcount_objects_in_slice_with_gil(dst.data, dst.shape, - * dst.strides, ndim, inc) - */ - } - - /* "View.MemoryView":1362 - * - * @cname('__pyx_memoryview_refcount_copying') - * cdef void refcount_copying(__Pyx_memviewslice *dst, bint dtype_is_object, # <<<<<<<<<<<<<< - * int ndim, bint inc) nogil: - * - */ - - /* function exit code */ -} - -/* "View.MemoryView":1371 - * - * @cname('__pyx_memoryview_refcount_objects_in_slice_with_gil') - * cdef void refcount_objects_in_slice_with_gil(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< - * Py_ssize_t *strides, int ndim, - * bint inc) with gil: - */ - -static void __pyx_memoryview_refcount_objects_in_slice_with_gil(char *__pyx_v_data, Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, int __pyx_v_ndim, int __pyx_v_inc) { - __Pyx_RefNannyDeclarations - #ifdef WITH_THREAD - PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); - #endif - __Pyx_RefNannySetupContext("refcount_objects_in_slice_with_gil", 0); - - /* "View.MemoryView":1374 - * Py_ssize_t *strides, int ndim, - * bint inc) with gil: - * refcount_objects_in_slice(data, shape, strides, ndim, inc) # <<<<<<<<<<<<<< - * - * @cname('__pyx_memoryview_refcount_objects_in_slice') - */ - __pyx_memoryview_refcount_objects_in_slice(__pyx_v_data, __pyx_v_shape, __pyx_v_strides, __pyx_v_ndim, __pyx_v_inc); - - /* "View.MemoryView":1371 - * - * @cname('__pyx_memoryview_refcount_objects_in_slice_with_gil') - * cdef void refcount_objects_in_slice_with_gil(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< - * Py_ssize_t *strides, int ndim, - * bint inc) with gil: - */ - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - #ifdef WITH_THREAD - __Pyx_PyGILState_Release(__pyx_gilstate_save); - #endif -} - -/* "View.MemoryView":1377 - * - * @cname('__pyx_memoryview_refcount_objects_in_slice') - * cdef void refcount_objects_in_slice(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< - * Py_ssize_t *strides, int ndim, bint inc): - * cdef Py_ssize_t i - */ - -static void __pyx_memoryview_refcount_objects_in_slice(char *__pyx_v_data, Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, int __pyx_v_ndim, int __pyx_v_inc) { - CYTHON_UNUSED Py_ssize_t __pyx_v_i; - __Pyx_RefNannyDeclarations - Py_ssize_t __pyx_t_1; - Py_ssize_t __pyx_t_2; - Py_ssize_t __pyx_t_3; - int __pyx_t_4; - __Pyx_RefNannySetupContext("refcount_objects_in_slice", 0); - - /* "View.MemoryView":1381 - * cdef Py_ssize_t i - * - * for i in range(shape[0]): # <<<<<<<<<<<<<< - * if ndim == 1: - * if inc: - */ - __pyx_t_1 = (__pyx_v_shape[0]); - __pyx_t_2 = __pyx_t_1; - for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_v_i = __pyx_t_3; - - /* "View.MemoryView":1382 - * - * for i in range(shape[0]): - * if ndim == 1: # <<<<<<<<<<<<<< - * if inc: - * Py_INCREF(( data)[0]) - */ - __pyx_t_4 = ((__pyx_v_ndim == 1) != 0); - if (__pyx_t_4) { - - /* "View.MemoryView":1383 - * for i in range(shape[0]): - * if ndim == 1: - * if inc: # <<<<<<<<<<<<<< - * Py_INCREF(( data)[0]) - * else: - */ - __pyx_t_4 = (__pyx_v_inc != 0); - if (__pyx_t_4) { - - /* "View.MemoryView":1384 - * if ndim == 1: - * if inc: - * Py_INCREF(( data)[0]) # <<<<<<<<<<<<<< - * else: - * Py_DECREF(( data)[0]) - */ - Py_INCREF((((PyObject **)__pyx_v_data)[0])); - - /* "View.MemoryView":1383 - * for i in range(shape[0]): - * if ndim == 1: - * if inc: # <<<<<<<<<<<<<< - * Py_INCREF(( data)[0]) - * else: - */ - goto __pyx_L6; - } - - /* "View.MemoryView":1386 - * Py_INCREF(( data)[0]) - * else: - * Py_DECREF(( data)[0]) # <<<<<<<<<<<<<< - * else: - * refcount_objects_in_slice(data, shape + 1, strides + 1, - */ - /*else*/ { - Py_DECREF((((PyObject **)__pyx_v_data)[0])); - } - __pyx_L6:; - - /* "View.MemoryView":1382 - * - * for i in range(shape[0]): - * if ndim == 1: # <<<<<<<<<<<<<< - * if inc: - * Py_INCREF(( data)[0]) - */ - goto __pyx_L5; - } - - /* "View.MemoryView":1388 - * Py_DECREF(( data)[0]) - * else: - * refcount_objects_in_slice(data, shape + 1, strides + 1, # <<<<<<<<<<<<<< - * ndim - 1, inc) - * - */ - /*else*/ { - - /* "View.MemoryView":1389 - * else: - * refcount_objects_in_slice(data, shape + 1, strides + 1, - * ndim - 1, inc) # <<<<<<<<<<<<<< - * - * data += strides[0] - */ - __pyx_memoryview_refcount_objects_in_slice(__pyx_v_data, (__pyx_v_shape + 1), (__pyx_v_strides + 1), (__pyx_v_ndim - 1), __pyx_v_inc); - } - __pyx_L5:; - - /* "View.MemoryView":1391 - * ndim - 1, inc) - * - * data += strides[0] # <<<<<<<<<<<<<< - * - * - */ - __pyx_v_data = (__pyx_v_data + (__pyx_v_strides[0])); - } - - /* "View.MemoryView":1377 - * - * @cname('__pyx_memoryview_refcount_objects_in_slice') - * cdef void refcount_objects_in_slice(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< - * Py_ssize_t *strides, int ndim, bint inc): - * cdef Py_ssize_t i - */ - - /* function exit code */ - __Pyx_RefNannyFinishContext(); -} - -/* "View.MemoryView":1397 - * - * @cname('__pyx_memoryview_slice_assign_scalar') - * cdef void slice_assign_scalar(__Pyx_memviewslice *dst, int ndim, # <<<<<<<<<<<<<< - * size_t itemsize, void *item, - * bint dtype_is_object) nogil: - */ - -static void __pyx_memoryview_slice_assign_scalar(__Pyx_memviewslice *__pyx_v_dst, int __pyx_v_ndim, size_t __pyx_v_itemsize, void *__pyx_v_item, int __pyx_v_dtype_is_object) { - - /* "View.MemoryView":1400 - * size_t itemsize, void *item, - * bint dtype_is_object) nogil: - * refcount_copying(dst, dtype_is_object, ndim, False) # <<<<<<<<<<<<<< - * _slice_assign_scalar(dst.data, dst.shape, dst.strides, ndim, - * itemsize, item) - */ - __pyx_memoryview_refcount_copying(__pyx_v_dst, __pyx_v_dtype_is_object, __pyx_v_ndim, 0); - - /* "View.MemoryView":1401 - * bint dtype_is_object) nogil: - * refcount_copying(dst, dtype_is_object, ndim, False) - * _slice_assign_scalar(dst.data, dst.shape, dst.strides, ndim, # <<<<<<<<<<<<<< - * itemsize, item) - * refcount_copying(dst, dtype_is_object, ndim, True) - */ - __pyx_memoryview__slice_assign_scalar(__pyx_v_dst->data, __pyx_v_dst->shape, __pyx_v_dst->strides, __pyx_v_ndim, __pyx_v_itemsize, __pyx_v_item); - - /* "View.MemoryView":1403 - * _slice_assign_scalar(dst.data, dst.shape, dst.strides, ndim, - * itemsize, item) - * refcount_copying(dst, dtype_is_object, ndim, True) # <<<<<<<<<<<<<< - * - * - */ - __pyx_memoryview_refcount_copying(__pyx_v_dst, __pyx_v_dtype_is_object, __pyx_v_ndim, 1); - - /* "View.MemoryView":1397 - * - * @cname('__pyx_memoryview_slice_assign_scalar') - * cdef void slice_assign_scalar(__Pyx_memviewslice *dst, int ndim, # <<<<<<<<<<<<<< - * size_t itemsize, void *item, - * bint dtype_is_object) nogil: - */ - - /* function exit code */ -} - -/* "View.MemoryView":1407 - * - * @cname('__pyx_memoryview__slice_assign_scalar') - * cdef void _slice_assign_scalar(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< - * Py_ssize_t *strides, int ndim, - * size_t itemsize, void *item) nogil: - */ - -static void __pyx_memoryview__slice_assign_scalar(char *__pyx_v_data, Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, int __pyx_v_ndim, size_t __pyx_v_itemsize, void *__pyx_v_item) { - CYTHON_UNUSED Py_ssize_t __pyx_v_i; - Py_ssize_t __pyx_v_stride; - Py_ssize_t __pyx_v_extent; - int __pyx_t_1; - Py_ssize_t __pyx_t_2; - Py_ssize_t __pyx_t_3; - Py_ssize_t __pyx_t_4; - - /* "View.MemoryView":1411 - * size_t itemsize, void *item) nogil: - * cdef Py_ssize_t i - * cdef Py_ssize_t stride = strides[0] # <<<<<<<<<<<<<< - * cdef Py_ssize_t extent = shape[0] - * - */ - __pyx_v_stride = (__pyx_v_strides[0]); - - /* "View.MemoryView":1412 - * cdef Py_ssize_t i - * cdef Py_ssize_t stride = strides[0] - * cdef Py_ssize_t extent = shape[0] # <<<<<<<<<<<<<< - * - * if ndim == 1: - */ - __pyx_v_extent = (__pyx_v_shape[0]); - - /* "View.MemoryView":1414 - * cdef Py_ssize_t extent = shape[0] - * - * if ndim == 1: # <<<<<<<<<<<<<< - * for i in range(extent): - * memcpy(data, item, itemsize) - */ - __pyx_t_1 = ((__pyx_v_ndim == 1) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":1415 - * - * if ndim == 1: - * for i in range(extent): # <<<<<<<<<<<<<< - * memcpy(data, item, itemsize) - * data += stride - */ - __pyx_t_2 = __pyx_v_extent; - __pyx_t_3 = __pyx_t_2; - for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { - __pyx_v_i = __pyx_t_4; - - /* "View.MemoryView":1416 - * if ndim == 1: - * for i in range(extent): - * memcpy(data, item, itemsize) # <<<<<<<<<<<<<< - * data += stride - * else: - */ - (void)(memcpy(__pyx_v_data, __pyx_v_item, __pyx_v_itemsize)); - - /* "View.MemoryView":1417 - * for i in range(extent): - * memcpy(data, item, itemsize) - * data += stride # <<<<<<<<<<<<<< - * else: - * for i in range(extent): - */ - __pyx_v_data = (__pyx_v_data + __pyx_v_stride); - } - - /* "View.MemoryView":1414 - * cdef Py_ssize_t extent = shape[0] - * - * if ndim == 1: # <<<<<<<<<<<<<< - * for i in range(extent): - * memcpy(data, item, itemsize) - */ - goto __pyx_L3; - } - - /* "View.MemoryView":1419 - * data += stride - * else: - * for i in range(extent): # <<<<<<<<<<<<<< - * _slice_assign_scalar(data, shape + 1, strides + 1, - * ndim - 1, itemsize, item) - */ - /*else*/ { - __pyx_t_2 = __pyx_v_extent; - __pyx_t_3 = __pyx_t_2; - for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { - __pyx_v_i = __pyx_t_4; - - /* "View.MemoryView":1420 - * else: - * for i in range(extent): - * _slice_assign_scalar(data, shape + 1, strides + 1, # <<<<<<<<<<<<<< - * ndim - 1, itemsize, item) - * data += stride - */ - __pyx_memoryview__slice_assign_scalar(__pyx_v_data, (__pyx_v_shape + 1), (__pyx_v_strides + 1), (__pyx_v_ndim - 1), __pyx_v_itemsize, __pyx_v_item); - - /* "View.MemoryView":1422 - * _slice_assign_scalar(data, shape + 1, strides + 1, - * ndim - 1, itemsize, item) - * data += stride # <<<<<<<<<<<<<< - * - * - */ - __pyx_v_data = (__pyx_v_data + __pyx_v_stride); - } - } - __pyx_L3:; - - /* "View.MemoryView":1407 - * - * @cname('__pyx_memoryview__slice_assign_scalar') - * cdef void _slice_assign_scalar(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< - * Py_ssize_t *strides, int ndim, - * size_t itemsize, void *item) nogil: - */ - - /* function exit code */ -} - -/* "(tree fragment)":1 - * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< - * cdef object __pyx_PickleError - * cdef object __pyx_result - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_1__pyx_unpickle_Enum(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyMethodDef __pyx_mdef_15View_dot_MemoryView_1__pyx_unpickle_Enum = {"__pyx_unpickle_Enum", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15View_dot_MemoryView_1__pyx_unpickle_Enum, METH_VARARGS|METH_KEYWORDS, 0}; -static PyObject *__pyx_pw_15View_dot_MemoryView_1__pyx_unpickle_Enum(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v___pyx_type = 0; - long __pyx_v___pyx_checksum; - PyObject *__pyx_v___pyx_state = 0; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__pyx_unpickle_Enum (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,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_pyx_type)) != 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_pyx_checksum)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Enum", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Enum", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_Enum") < 0)) __PYX_ERR(2, 1, __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___pyx_type = values[0]; - __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error) - __pyx_v___pyx_state = values[2]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Enum", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("View.MemoryView.__pyx_unpickle_Enum", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_15View_dot_MemoryView___pyx_unpickle_Enum(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15View_dot_MemoryView___pyx_unpickle_Enum(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { - PyObject *__pyx_v___pyx_PickleError = 0; - PyObject *__pyx_v___pyx_result = 0; - 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; - int __pyx_t_6; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__pyx_unpickle_Enum", 0); - - /* "(tree fragment)":4 - * cdef object __pyx_PickleError - * cdef object __pyx_result - * if __pyx_checksum != 0xb068931: # <<<<<<<<<<<<<< - * from pickle import PickleError as __pyx_PickleError - * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) - */ - __pyx_t_1 = ((__pyx_v___pyx_checksum != 0xb068931) != 0); - if (__pyx_t_1) { - - /* "(tree fragment)":5 - * cdef object __pyx_result - * if __pyx_checksum != 0xb068931: - * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< - * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) - * __pyx_result = Enum.__new__(__pyx_type) - */ - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_n_s_PickleError); - __Pyx_GIVEREF(__pyx_n_s_PickleError); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); - __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_2); - __pyx_v___pyx_PickleError = __pyx_t_2; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "(tree fragment)":6 - * if __pyx_checksum != 0xb068931: - * from pickle import PickleError as __pyx_PickleError - * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) # <<<<<<<<<<<<<< - * __pyx_result = Enum.__new__(__pyx_type) - * if __pyx_state is not None: - */ - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 6, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xb0, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 6, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_INCREF(__pyx_v___pyx_PickleError); - __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 6, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(2, 6, __pyx_L1_error) - - /* "(tree fragment)":4 - * cdef object __pyx_PickleError - * cdef object __pyx_result - * if __pyx_checksum != 0xb068931: # <<<<<<<<<<<<<< - * from pickle import PickleError as __pyx_PickleError - * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) - */ - } - - /* "(tree fragment)":7 - * from pickle import PickleError as __pyx_PickleError - * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) - * __pyx_result = Enum.__new__(__pyx_type) # <<<<<<<<<<<<<< - * if __pyx_state is not None: - * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_MemviewEnum_type), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 7, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v___pyx_result = __pyx_t_3; - __pyx_t_3 = 0; - - /* "(tree fragment)":8 - * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) - * __pyx_result = Enum.__new__(__pyx_type) - * if __pyx_state is not None: # <<<<<<<<<<<<<< - * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) - * return __pyx_result - */ - __pyx_t_1 = (__pyx_v___pyx_state != Py_None); - __pyx_t_6 = (__pyx_t_1 != 0); - if (__pyx_t_6) { - - /* "(tree fragment)":9 - * __pyx_result = Enum.__new__(__pyx_type) - * if __pyx_state is not None: - * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< - * return __pyx_result - * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): - */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 9, __pyx_L1_error) - __pyx_t_3 = __pyx_unpickle_Enum__set_state(((struct __pyx_MemviewEnum_obj *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 9, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "(tree fragment)":8 - * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) - * __pyx_result = Enum.__new__(__pyx_type) - * if __pyx_state is not None: # <<<<<<<<<<<<<< - * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) - * return __pyx_result - */ - } - - /* "(tree fragment)":10 - * if __pyx_state is not None: - * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) - * return __pyx_result # <<<<<<<<<<<<<< - * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): - * __pyx_result.name = __pyx_state[0] - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v___pyx_result); - __pyx_r = __pyx_v___pyx_result; - goto __pyx_L0; - - /* "(tree fragment)":1 - * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< - * cdef object __pyx_PickleError - * cdef object __pyx_result - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("View.MemoryView.__pyx_unpickle_Enum", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v___pyx_PickleError); - __Pyx_XDECREF(__pyx_v___pyx_result); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "(tree fragment)":11 - * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) - * return __pyx_result - * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< - * __pyx_result.name = __pyx_state[0] - * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): - */ - -static PyObject *__pyx_unpickle_Enum__set_state(struct __pyx_MemviewEnum_obj *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - Py_ssize_t __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__pyx_unpickle_Enum__set_state", 0); - - /* "(tree fragment)":12 - * return __pyx_result - * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): - * __pyx_result.name = __pyx_state[0] # <<<<<<<<<<<<<< - * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): - * __pyx_result.__dict__.update(__pyx_state[1]) - */ - if (unlikely(__pyx_v___pyx_state == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(2, 12, __pyx_L1_error) - } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v___pyx_result->name); - __Pyx_DECREF(__pyx_v___pyx_result->name); - __pyx_v___pyx_result->name = __pyx_t_1; - __pyx_t_1 = 0; - - /* "(tree fragment)":13 - * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): - * __pyx_result.name = __pyx_state[0] - * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< - * __pyx_result.__dict__.update(__pyx_state[1]) - */ - if (unlikely(__pyx_v___pyx_state == Py_None)) { - PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(2, 13, __pyx_L1_error) - } - __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(2, 13, __pyx_L1_error) - __pyx_t_4 = ((__pyx_t_3 > 1) != 0); - if (__pyx_t_4) { - } else { - __pyx_t_2 = __pyx_t_4; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(2, 13, __pyx_L1_error) - __pyx_t_5 = (__pyx_t_4 != 0); - __pyx_t_2 = __pyx_t_5; - __pyx_L4_bool_binop_done:; - if (__pyx_t_2) { - - /* "(tree fragment)":14 - * __pyx_result.name = __pyx_state[0] - * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): - * __pyx_result.__dict__.update(__pyx_state[1]) # <<<<<<<<<<<<<< - */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 14, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 14, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(__pyx_v___pyx_state == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(2, 14, __pyx_L1_error) - } - __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 14, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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); - } - } - __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 14, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "(tree fragment)":13 - * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): - * __pyx_result.name = __pyx_state[0] - * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< - * __pyx_result.__dict__.update(__pyx_state[1]) - */ - } - - /* "(tree fragment)":11 - * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) - * return __pyx_result - * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< - * __pyx_result.name = __pyx_state[0] - * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): - */ - - /* 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_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("View.MemoryView.__pyx_unpickle_Enum__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -static struct __pyx_vtabstruct_array __pyx_vtable_array; - -static PyObject *__pyx_tp_new_array(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_array_obj *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_array_obj *)o); - p->__pyx_vtab = __pyx_vtabptr_array; - p->mode = ((PyObject*)Py_None); Py_INCREF(Py_None); - p->_format = ((PyObject*)Py_None); Py_INCREF(Py_None); - if (unlikely(__pyx_array___cinit__(o, a, k) < 0)) goto bad; - return o; - bad: - Py_DECREF(o); o = 0; - return NULL; -} - -static void __pyx_tp_dealloc_array(PyObject *o) { - struct __pyx_array_obj *p = (struct __pyx_array_obj *)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); - __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1); - __pyx_array___dealloc__(o); - __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1); - PyErr_Restore(etype, eval, etb); - } - Py_CLEAR(p->mode); - Py_CLEAR(p->_format); - (*Py_TYPE(o)->tp_free)(o); -} -static PyObject *__pyx_sq_item_array(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; -} - -static int __pyx_mp_ass_subscript_array(PyObject *o, PyObject *i, PyObject *v) { - if (v) { - return __pyx_array___setitem__(o, i, v); - } - else { - PyErr_Format(PyExc_NotImplementedError, - "Subscript deletion not supported by %.200s", Py_TYPE(o)->tp_name); - return -1; - } -} - -static PyObject *__pyx_tp_getattro_array(PyObject *o, PyObject *n) { - PyObject *v = __Pyx_PyObject_GenericGetAttr(o, n); - if (!v && PyErr_ExceptionMatches(PyExc_AttributeError)) { - PyErr_Clear(); - v = __pyx_array___getattr__(o, n); - } - return v; -} - -static PyObject *__pyx_getprop___pyx_array_memview(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_15View_dot_MemoryView_5array_7memview_1__get__(o); -} - -static PyMethodDef __pyx_methods_array[] = { - {"__getattr__", (PyCFunction)__pyx_array___getattr__, METH_O|METH_COEXIST, 0}, - {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_array_1__reduce_cython__, METH_NOARGS, 0}, - {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_array_3__setstate_cython__, METH_O, 0}, - {0, 0, 0, 0} -}; - -static struct PyGetSetDef __pyx_getsets_array[] = { - {(char *)"memview", __pyx_getprop___pyx_array_memview, 0, (char *)0, 0}, - {0, 0, 0, 0, 0} -}; - -static PySequenceMethods __pyx_tp_as_sequence_array = { - __pyx_array___len__, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - __pyx_sq_item_array, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - 0, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; - -static PyMappingMethods __pyx_tp_as_mapping_array = { - __pyx_array___len__, /*mp_length*/ - __pyx_array___getitem__, /*mp_subscript*/ - __pyx_mp_ass_subscript_array, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_array = { - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getreadbuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getwritebuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getsegcount*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getcharbuffer*/ - #endif - __pyx_array_getbuffer, /*bf_getbuffer*/ - 0, /*bf_releasebuffer*/ -}; - -static PyTypeObject __pyx_type___pyx_array = { - PyVarObject_HEAD_INIT(0, 0) - "pygeoprocessing.geoprocessing_core.array", /*tp_name*/ - sizeof(struct __pyx_array_obj), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_array, /*tp_dealloc*/ - #if PY_VERSION_HEX < 0x030800b4 - 0, /*tp_print*/ - #endif - #if PY_VERSION_HEX >= 0x030800b4 - 0, /*tp_vectorcall_offset*/ - #endif - 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*/ - &__pyx_tp_as_sequence_array, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_array, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - __pyx_tp_getattro_array, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_array, /*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_array, /*tp_methods*/ - 0, /*tp_members*/ - __pyx_getsets_array, /*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_array, /*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 - #if PY_VERSION_HEX >= 0x030800b1 - 0, /*tp_vectorcall*/ - #endif - #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000 - 0, /*tp_print*/ - #endif -}; - -static PyObject *__pyx_tp_new_Enum(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { - struct __pyx_MemviewEnum_obj *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_MemviewEnum_obj *)o); - p->name = Py_None; Py_INCREF(Py_None); - return o; -} - -static void __pyx_tp_dealloc_Enum(PyObject *o) { - struct __pyx_MemviewEnum_obj *p = (struct __pyx_MemviewEnum_obj *)o; - #if CYTHON_USE_TP_FINALIZE - if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { - if (PyObject_CallFinalizerFromDealloc(o)) return; - } - #endif - PyObject_GC_UnTrack(o); - Py_CLEAR(p->name); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_Enum(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_MemviewEnum_obj *p = (struct __pyx_MemviewEnum_obj *)o; - if (p->name) { - e = (*v)(p->name, a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_Enum(PyObject *o) { - PyObject* tmp; - struct __pyx_MemviewEnum_obj *p = (struct __pyx_MemviewEnum_obj *)o; - tmp = ((PyObject*)p->name); - p->name = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyMethodDef __pyx_methods_Enum[] = { - {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_MemviewEnum_1__reduce_cython__, METH_NOARGS, 0}, - {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_MemviewEnum_3__setstate_cython__, METH_O, 0}, - {0, 0, 0, 0} -}; - -static PyTypeObject __pyx_type___pyx_MemviewEnum = { - PyVarObject_HEAD_INIT(0, 0) - "pygeoprocessing.geoprocessing_core.Enum", /*tp_name*/ - sizeof(struct __pyx_MemviewEnum_obj), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_Enum, /*tp_dealloc*/ - #if PY_VERSION_HEX < 0x030800b4 - 0, /*tp_print*/ - #endif - #if PY_VERSION_HEX >= 0x030800b4 - 0, /*tp_vectorcall_offset*/ - #endif - 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 - __pyx_MemviewEnum___repr__, /*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|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_Enum, /*tp_traverse*/ - __pyx_tp_clear_Enum, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_Enum, /*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*/ - __pyx_MemviewEnum___init__, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_Enum, /*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 - #if PY_VERSION_HEX >= 0x030800b1 - 0, /*tp_vectorcall*/ - #endif - #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000 - 0, /*tp_print*/ - #endif -}; -static struct __pyx_vtabstruct_memoryview __pyx_vtable_memoryview; - -static PyObject *__pyx_tp_new_memoryview(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_memoryview_obj *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_memoryview_obj *)o); - p->__pyx_vtab = __pyx_vtabptr_memoryview; - p->obj = Py_None; Py_INCREF(Py_None); - p->_size = Py_None; Py_INCREF(Py_None); - p->_array_interface = Py_None; Py_INCREF(Py_None); - p->view.obj = NULL; - if (unlikely(__pyx_memoryview___cinit__(o, a, k) < 0)) goto bad; - return o; - bad: - Py_DECREF(o); o = 0; - return NULL; -} - -static void __pyx_tp_dealloc_memoryview(PyObject *o) { - struct __pyx_memoryview_obj *p = (struct __pyx_memoryview_obj *)o; - #if CYTHON_USE_TP_FINALIZE - if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { - if (PyObject_CallFinalizerFromDealloc(o)) return; - } - #endif - PyObject_GC_UnTrack(o); - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1); - __pyx_memoryview___dealloc__(o); - __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1); - PyErr_Restore(etype, eval, etb); - } - Py_CLEAR(p->obj); - Py_CLEAR(p->_size); - Py_CLEAR(p->_array_interface); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_memoryview(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_memoryview_obj *p = (struct __pyx_memoryview_obj *)o; - if (p->obj) { - e = (*v)(p->obj, a); if (e) return e; - } - if (p->_size) { - e = (*v)(p->_size, a); if (e) return e; - } - if (p->_array_interface) { - e = (*v)(p->_array_interface, a); if (e) return e; - } - if (p->view.obj) { - e = (*v)(p->view.obj, a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_memoryview(PyObject *o) { - PyObject* tmp; - struct __pyx_memoryview_obj *p = (struct __pyx_memoryview_obj *)o; - tmp = ((PyObject*)p->obj); - p->obj = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->_size); - p->_size = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->_array_interface); - p->_array_interface = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - Py_CLEAR(p->view.obj); - return 0; -} -static PyObject *__pyx_sq_item_memoryview(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; -} - -static int __pyx_mp_ass_subscript_memoryview(PyObject *o, PyObject *i, PyObject *v) { - if (v) { - return __pyx_memoryview___setitem__(o, i, v); - } - else { - PyErr_Format(PyExc_NotImplementedError, - "Subscript deletion not supported by %.200s", Py_TYPE(o)->tp_name); - return -1; - } -} - -static PyObject *__pyx_getprop___pyx_memoryview_T(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_15View_dot_MemoryView_10memoryview_1T_1__get__(o); -} - -static PyObject *__pyx_getprop___pyx_memoryview_base(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_15View_dot_MemoryView_10memoryview_4base_1__get__(o); -} - -static PyObject *__pyx_getprop___pyx_memoryview_shape(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_15View_dot_MemoryView_10memoryview_5shape_1__get__(o); -} - -static PyObject *__pyx_getprop___pyx_memoryview_strides(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_15View_dot_MemoryView_10memoryview_7strides_1__get__(o); -} - -static PyObject *__pyx_getprop___pyx_memoryview_suboffsets(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_15View_dot_MemoryView_10memoryview_10suboffsets_1__get__(o); -} - -static PyObject *__pyx_getprop___pyx_memoryview_ndim(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_15View_dot_MemoryView_10memoryview_4ndim_1__get__(o); -} - -static PyObject *__pyx_getprop___pyx_memoryview_itemsize(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_15View_dot_MemoryView_10memoryview_8itemsize_1__get__(o); -} - -static PyObject *__pyx_getprop___pyx_memoryview_nbytes(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_15View_dot_MemoryView_10memoryview_6nbytes_1__get__(o); -} - -static PyObject *__pyx_getprop___pyx_memoryview_size(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_15View_dot_MemoryView_10memoryview_4size_1__get__(o); -} - -static PyMethodDef __pyx_methods_memoryview[] = { - {"is_c_contig", (PyCFunction)__pyx_memoryview_is_c_contig, METH_NOARGS, 0}, - {"is_f_contig", (PyCFunction)__pyx_memoryview_is_f_contig, METH_NOARGS, 0}, - {"copy", (PyCFunction)__pyx_memoryview_copy, METH_NOARGS, 0}, - {"copy_fortran", (PyCFunction)__pyx_memoryview_copy_fortran, METH_NOARGS, 0}, - {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_memoryview_1__reduce_cython__, METH_NOARGS, 0}, - {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_memoryview_3__setstate_cython__, METH_O, 0}, - {0, 0, 0, 0} -}; - -static struct PyGetSetDef __pyx_getsets_memoryview[] = { - {(char *)"T", __pyx_getprop___pyx_memoryview_T, 0, (char *)0, 0}, - {(char *)"base", __pyx_getprop___pyx_memoryview_base, 0, (char *)0, 0}, - {(char *)"shape", __pyx_getprop___pyx_memoryview_shape, 0, (char *)0, 0}, - {(char *)"strides", __pyx_getprop___pyx_memoryview_strides, 0, (char *)0, 0}, - {(char *)"suboffsets", __pyx_getprop___pyx_memoryview_suboffsets, 0, (char *)0, 0}, - {(char *)"ndim", __pyx_getprop___pyx_memoryview_ndim, 0, (char *)0, 0}, - {(char *)"itemsize", __pyx_getprop___pyx_memoryview_itemsize, 0, (char *)0, 0}, - {(char *)"nbytes", __pyx_getprop___pyx_memoryview_nbytes, 0, (char *)0, 0}, - {(char *)"size", __pyx_getprop___pyx_memoryview_size, 0, (char *)0, 0}, - {0, 0, 0, 0, 0} -}; - -static PySequenceMethods __pyx_tp_as_sequence_memoryview = { - __pyx_memoryview___len__, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - __pyx_sq_item_memoryview, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - 0, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; - -static PyMappingMethods __pyx_tp_as_mapping_memoryview = { - __pyx_memoryview___len__, /*mp_length*/ - __pyx_memoryview___getitem__, /*mp_subscript*/ - __pyx_mp_ass_subscript_memoryview, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_memoryview = { - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getreadbuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getwritebuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getsegcount*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getcharbuffer*/ - #endif - __pyx_memoryview_getbuffer, /*bf_getbuffer*/ - 0, /*bf_releasebuffer*/ -}; - -static PyTypeObject __pyx_type___pyx_memoryview = { - PyVarObject_HEAD_INIT(0, 0) - "pygeoprocessing.geoprocessing_core.memoryview", /*tp_name*/ - sizeof(struct __pyx_memoryview_obj), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_memoryview, /*tp_dealloc*/ - #if PY_VERSION_HEX < 0x030800b4 - 0, /*tp_print*/ - #endif - #if PY_VERSION_HEX >= 0x030800b4 - 0, /*tp_vectorcall_offset*/ - #endif - 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 - __pyx_memoryview___repr__, /*tp_repr*/ - 0, /*tp_as_number*/ - &__pyx_tp_as_sequence_memoryview, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_memoryview, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - __pyx_memoryview___str__, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_memoryview, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_memoryview, /*tp_traverse*/ - __pyx_tp_clear_memoryview, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_memoryview, /*tp_methods*/ - 0, /*tp_members*/ - __pyx_getsets_memoryview, /*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_memoryview, /*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 - #if PY_VERSION_HEX >= 0x030800b1 - 0, /*tp_vectorcall*/ - #endif - #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000 - 0, /*tp_print*/ - #endif -}; -static struct __pyx_vtabstruct__memoryviewslice __pyx_vtable__memoryviewslice; - -static PyObject *__pyx_tp_new__memoryviewslice(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_memoryviewslice_obj *p; - PyObject *o = __pyx_tp_new_memoryview(t, a, k); - if (unlikely(!o)) return 0; - p = ((struct __pyx_memoryviewslice_obj *)o); - p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_memoryview*)__pyx_vtabptr__memoryviewslice; - p->from_object = Py_None; Py_INCREF(Py_None); - p->from_slice.memview = NULL; - return o; -} - -static void __pyx_tp_dealloc__memoryviewslice(PyObject *o) { - struct __pyx_memoryviewslice_obj *p = (struct __pyx_memoryviewslice_obj *)o; - #if CYTHON_USE_TP_FINALIZE - if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { - if (PyObject_CallFinalizerFromDealloc(o)) return; - } - #endif - PyObject_GC_UnTrack(o); - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1); - __pyx_memoryviewslice___dealloc__(o); - __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1); - PyErr_Restore(etype, eval, etb); - } - Py_CLEAR(p->from_object); - PyObject_GC_Track(o); - __pyx_tp_dealloc_memoryview(o); -} - -static int __pyx_tp_traverse__memoryviewslice(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_memoryviewslice_obj *p = (struct __pyx_memoryviewslice_obj *)o; - e = __pyx_tp_traverse_memoryview(o, v, a); if (e) return e; - if (p->from_object) { - e = (*v)(p->from_object, a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear__memoryviewslice(PyObject *o) { - PyObject* tmp; - struct __pyx_memoryviewslice_obj *p = (struct __pyx_memoryviewslice_obj *)o; - __pyx_tp_clear_memoryview(o); - tmp = ((PyObject*)p->from_object); - p->from_object = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - __PYX_XDEC_MEMVIEW(&p->from_slice, 1); - return 0; -} - -static PyObject *__pyx_getprop___pyx_memoryviewslice_base(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_15View_dot_MemoryView_16_memoryviewslice_4base_1__get__(o); -} - -static PyMethodDef __pyx_methods__memoryviewslice[] = { - {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_memoryviewslice_1__reduce_cython__, METH_NOARGS, 0}, - {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_memoryviewslice_3__setstate_cython__, METH_O, 0}, - {0, 0, 0, 0} -}; - -static struct PyGetSetDef __pyx_getsets__memoryviewslice[] = { - {(char *)"base", __pyx_getprop___pyx_memoryviewslice_base, 0, (char *)0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyTypeObject __pyx_type___pyx_memoryviewslice = { - PyVarObject_HEAD_INIT(0, 0) - "pygeoprocessing.geoprocessing_core._memoryviewslice", /*tp_name*/ - sizeof(struct __pyx_memoryviewslice_obj), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc__memoryviewslice, /*tp_dealloc*/ - #if PY_VERSION_HEX < 0x030800b4 - 0, /*tp_print*/ - #endif - #if PY_VERSION_HEX >= 0x030800b4 - 0, /*tp_vectorcall_offset*/ - #endif - 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 - #if CYTHON_COMPILING_IN_PYPY - __pyx_memoryview___repr__, /*tp_repr*/ - #else - 0, /*tp_repr*/ - #endif - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - #if CYTHON_COMPILING_IN_PYPY - __pyx_memoryview___str__, /*tp_str*/ - #else - 0, /*tp_str*/ - #endif - 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|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - "Internal class for passing memoryview slices to Python", /*tp_doc*/ - __pyx_tp_traverse__memoryviewslice, /*tp_traverse*/ - __pyx_tp_clear__memoryviewslice, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods__memoryviewslice, /*tp_methods*/ - 0, /*tp_members*/ - __pyx_getsets__memoryviewslice, /*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__memoryviewslice, /*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 - #if PY_VERSION_HEX >= 0x030800b1 - 0, /*tp_vectorcall*/ - #endif - #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000 - 0, /*tp_print*/ - #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_geoprocessing_core(PyObject* module); /*proto*/ -static PyModuleDef_Slot __pyx_moduledef_slots[] = { - {Py_mod_create, (void*)__pyx_pymod_create}, - {Py_mod_exec, (void*)__pyx_pymod_exec_geoprocessing_core}, - {0, NULL} -}; -#endif - -static struct PyModuleDef __pyx_moduledef = { - PyModuleDef_HEAD_INIT, - "geoprocessing_core", - 0, /* 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 -#ifndef CYTHON_SMALL_CODE -#if defined(__clang__) - #define CYTHON_SMALL_CODE -#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) - #define CYTHON_SMALL_CODE __attribute__((cold)) -#else - #define CYTHON_SMALL_CODE -#endif -#endif - -static __Pyx_StringTabEntry __pyx_string_tab[] = { - {&__pyx_kp_u_1f, __pyx_k_1f, sizeof(__pyx_k_1f), 0, 1, 0, 0}, - {&__pyx_n_s_ASCII, __pyx_k_ASCII, sizeof(__pyx_k_ASCII), 0, 0, 1, 1}, - {&__pyx_kp_u_BIGTIFF_YES, __pyx_k_BIGTIFF_YES, sizeof(__pyx_k_BIGTIFF_YES), 0, 1, 0, 0}, - {&__pyx_kp_u_BLOCKXSIZE_256, __pyx_k_BLOCKXSIZE_256, sizeof(__pyx_k_BLOCKXSIZE_256), 0, 1, 0, 0}, - {&__pyx_kp_u_BLOCKYSIZE_256, __pyx_k_BLOCKYSIZE_256, sizeof(__pyx_k_BLOCKYSIZE_256), 0, 1, 0, 0}, - {&__pyx_kp_s_Buffer_view_does_not_expose_stri, __pyx_k_Buffer_view_does_not_expose_stri, sizeof(__pyx_k_Buffer_view_does_not_expose_stri), 0, 0, 1, 0}, - {&__pyx_kp_u_COMPRESS_LZW, __pyx_k_COMPRESS_LZW, sizeof(__pyx_k_COMPRESS_LZW), 0, 1, 0, 0}, - {&__pyx_kp_s_Can_only_create_a_buffer_that_is, __pyx_k_Can_only_create_a_buffer_that_is, sizeof(__pyx_k_Can_only_create_a_buffer_that_is), 0, 0, 1, 0}, - {&__pyx_kp_s_Cannot_assign_to_read_only_memor, __pyx_k_Cannot_assign_to_read_only_memor, sizeof(__pyx_k_Cannot_assign_to_read_only_memor), 0, 0, 1, 0}, - {&__pyx_kp_s_Cannot_create_writable_memory_vi, __pyx_k_Cannot_create_writable_memory_vi, sizeof(__pyx_k_Cannot_create_writable_memory_vi), 0, 0, 1, 0}, - {&__pyx_kp_s_Cannot_index_with_type_s, __pyx_k_Cannot_index_with_type_s, sizeof(__pyx_k_Cannot_index_with_type_s), 0, 0, 1, 0}, - {&__pyx_kp_u_Cannot_process_raster_type_s_not, __pyx_k_Cannot_process_raster_type_s_not, sizeof(__pyx_k_Cannot_process_raster_type_s_not), 0, 1, 0, 0}, - {&__pyx_n_s_ComputeStatistics, __pyx_k_ComputeStatistics, sizeof(__pyx_k_ComputeStatistics), 0, 0, 1, 1}, - {&__pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT, __pyx_k_DEFAULT_GTIFF_CREATION_TUPLE_OPT, sizeof(__pyx_k_DEFAULT_GTIFF_CREATION_TUPLE_OPT), 0, 0, 1, 1}, - {&__pyx_n_s_DEFAULT_OSR_AXIS_MAPPING_STRATEG, __pyx_k_DEFAULT_OSR_AXIS_MAPPING_STRATEG, sizeof(__pyx_k_DEFAULT_OSR_AXIS_MAPPING_STRATEG), 0, 0, 1, 1}, - {&__pyx_kp_u_Distance_Transform_Phase_2, __pyx_k_Distance_Transform_Phase_2, sizeof(__pyx_k_Distance_Transform_Phase_2), 0, 1, 0, 0}, - {&__pyx_n_s_Ellipsis, __pyx_k_Ellipsis, sizeof(__pyx_k_Ellipsis), 0, 0, 1, 1}, - {&__pyx_kp_s_Empty_shape_tuple_for_cython_arr, __pyx_k_Empty_shape_tuple_for_cython_arr, sizeof(__pyx_k_Empty_shape_tuple_for_cython_arr), 0, 0, 1, 0}, - {&__pyx_n_s_FlushCache, __pyx_k_FlushCache, sizeof(__pyx_k_FlushCache), 0, 0, 1, 1}, - {&__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_Float32, __pyx_k_GDT_Float32, sizeof(__pyx_k_GDT_Float32), 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_Int16, __pyx_k_GDT_Int16, sizeof(__pyx_k_GDT_Int16), 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_GDT_UInt16, __pyx_k_GDT_UInt16, sizeof(__pyx_k_GDT_UInt16), 0, 0, 1, 1}, - {&__pyx_n_s_GDT_UInt32, __pyx_k_GDT_UInt32, sizeof(__pyx_k_GDT_UInt32), 0, 0, 1, 1}, - {&__pyx_n_u_GTIFF, __pyx_k_GTIFF, sizeof(__pyx_k_GTIFF), 0, 1, 0, 1}, - {&__pyx_n_s_GetBlockSize, __pyx_k_GetBlockSize, sizeof(__pyx_k_GetBlockSize), 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_kp_s_Incompatible_checksums_s_vs_0xb0, __pyx_k_Incompatible_checksums_s_vs_0xb0, sizeof(__pyx_k_Incompatible_checksums_s_vs_0xb0), 0, 0, 1, 0}, - {&__pyx_n_s_IndexError, __pyx_k_IndexError, sizeof(__pyx_k_IndexError), 0, 0, 1, 1}, - {&__pyx_kp_s_Indirect_dimensions_not_supporte, __pyx_k_Indirect_dimensions_not_supporte, sizeof(__pyx_k_Indirect_dimensions_not_supporte), 0, 0, 1, 0}, - {&__pyx_kp_s_Invalid_mode_expected_c_or_fortr, __pyx_k_Invalid_mode_expected_c_or_fortr, sizeof(__pyx_k_Invalid_mode_expected_c_or_fortr), 0, 0, 1, 0}, - {&__pyx_kp_s_Invalid_shape_in_axis_d_d, __pyx_k_Invalid_shape_in_axis_d_d, sizeof(__pyx_k_Invalid_shape_in_axis_d_d), 0, 0, 1, 0}, - {&__pyx_n_s_LOGGER, __pyx_k_LOGGER, sizeof(__pyx_k_LOGGER), 0, 0, 1, 1}, - {&__pyx_n_s_M_last, __pyx_k_M_last, sizeof(__pyx_k_M_last), 0, 0, 1, 1}, - {&__pyx_n_s_M_local, __pyx_k_M_local, sizeof(__pyx_k_M_local), 0, 0, 1, 1}, - {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1}, - {&__pyx_kp_s_MemoryView_of_r_at_0x_x, __pyx_k_MemoryView_of_r_at_0x_x, sizeof(__pyx_k_MemoryView_of_r_at_0x_x), 0, 0, 1, 0}, - {&__pyx_kp_s_MemoryView_of_r_object, __pyx_k_MemoryView_of_r_object, sizeof(__pyx_k_MemoryView_of_r_object), 0, 0, 1, 0}, - {&__pyx_kp_u_No_valid_pixels_were_received_se, __pyx_k_No_valid_pixels_were_received_se, sizeof(__pyx_k_No_valid_pixels_were_received_se), 0, 1, 0, 0}, - {&__pyx_n_b_O, __pyx_k_O, sizeof(__pyx_k_O), 0, 0, 0, 1}, - {&__pyx_n_s_OAMS_TRADITIONAL_GIS_ORDER, __pyx_k_OAMS_TRADITIONAL_GIS_ORDER, sizeof(__pyx_k_OAMS_TRADITIONAL_GIS_ORDER), 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_kp_s_Out_of_bounds_on_buffer_access_a, __pyx_k_Out_of_bounds_on_buffer_access_a, sizeof(__pyx_k_Out_of_bounds_on_buffer_access_a), 0, 0, 1, 0}, - {&__pyx_n_s_PickleError, __pyx_k_PickleError, sizeof(__pyx_k_PickleError), 0, 0, 1, 1}, - {&__pyx_n_s_RasterXSize, __pyx_k_RasterXSize, sizeof(__pyx_k_RasterXSize), 0, 0, 1, 1}, - {&__pyx_n_s_RasterYSize, __pyx_k_RasterYSize, sizeof(__pyx_k_RasterYSize), 0, 0, 1, 1}, - {&__pyx_n_s_ReadAsArray, __pyx_k_ReadAsArray, sizeof(__pyx_k_ReadAsArray), 0, 0, 1, 1}, - {&__pyx_n_s_S_local, __pyx_k_S_local, sizeof(__pyx_k_S_local), 0, 0, 1, 1}, - {&__pyx_kp_u_TILED_YES, __pyx_k_TILED_YES, sizeof(__pyx_k_TILED_YES), 0, 1, 0, 0}, - {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1}, - {&__pyx_kp_s_Unable_to_convert_item_to_object, __pyx_k_Unable_to_convert_item_to_object, sizeof(__pyx_k_Unable_to_convert_item_to_object), 0, 0, 1, 0}, - {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1}, - {&__pyx_n_s_View_MemoryView, __pyx_k_View_MemoryView, sizeof(__pyx_k_View_MemoryView), 0, 0, 1, 1}, - {&__pyx_n_s_WriteArray, __pyx_k_WriteArray, sizeof(__pyx_k_WriteArray), 0, 0, 1, 1}, - {&__pyx_n_s__34, __pyx_k__34, sizeof(__pyx_k__34), 0, 0, 1, 1}, - {&__pyx_n_s_a, __pyx_k_a, sizeof(__pyx_k_a), 0, 0, 1, 1}, - {&__pyx_n_s_allocate_buffer, __pyx_k_allocate_buffer, sizeof(__pyx_k_allocate_buffer), 0, 0, 1, 1}, - {&__pyx_n_s_arange, __pyx_k_arange, sizeof(__pyx_k_arange), 0, 0, 1, 1}, - {&__pyx_n_s_astype, __pyx_k_astype, sizeof(__pyx_k_astype), 0, 0, 1, 1}, - {&__pyx_n_s_b, __pyx_k_b, sizeof(__pyx_k_b), 0, 0, 1, 1}, - {&__pyx_n_s_base, __pyx_k_base, sizeof(__pyx_k_base), 0, 0, 1, 1}, - {&__pyx_n_s_base_elevation_raster_path_band, __pyx_k_base_elevation_raster_path_band, sizeof(__pyx_k_base_elevation_raster_path_band), 0, 0, 1, 1}, - {&__pyx_n_s_base_raster_path_band, __pyx_k_base_raster_path_band, sizeof(__pyx_k_base_raster_path_band), 0, 0, 1, 1}, - {&__pyx_n_s_block, __pyx_k_block, sizeof(__pyx_k_block), 0, 0, 1, 1}, - {&__pyx_n_s_block_data, __pyx_k_block_data, sizeof(__pyx_k_block_data), 0, 0, 1, 1}, - {&__pyx_n_s_block_offset, __pyx_k_block_offset, sizeof(__pyx_k_block_offset), 0, 0, 1, 1}, - {&__pyx_n_s_block_offset_copy, __pyx_k_block_offset_copy, sizeof(__pyx_k_block_offset_copy), 0, 0, 1, 1}, - {&__pyx_n_u_block_size, __pyx_k_block_size, sizeof(__pyx_k_block_size), 0, 1, 0, 1}, - {&__pyx_n_s_block_xsize, __pyx_k_block_xsize, sizeof(__pyx_k_block_xsize), 0, 0, 1, 1}, - {&__pyx_n_s_block_ysize, __pyx_k_block_ysize, sizeof(__pyx_k_block_ysize), 0, 0, 1, 1}, - {&__pyx_n_s_buf, __pyx_k_buf, sizeof(__pyx_k_buf), 0, 0, 1, 1}, - {&__pyx_n_s_buf_obj, __pyx_k_buf_obj, sizeof(__pyx_k_buf_obj), 0, 0, 1, 1}, - {&__pyx_n_s_buffer, __pyx_k_buffer, sizeof(__pyx_k_buffer), 0, 0, 1, 1}, - {&__pyx_n_s_buffer_data, __pyx_k_buffer_data, sizeof(__pyx_k_buffer_data), 0, 0, 1, 1}, - {&__pyx_n_s_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 0, 1, 1}, - {&__pyx_n_u_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 1, 0, 1}, - {&__pyx_n_s_calculate_slope, __pyx_k_calculate_slope, sizeof(__pyx_k_calculate_slope), 0, 0, 1, 1}, - {&__pyx_kp_u_calculating_percentiles, __pyx_k_calculating_percentiles, sizeof(__pyx_k_calculating_percentiles), 0, 1, 0, 0}, - {&__pyx_kp_u_calculating_percentiles_2f_compl, __pyx_k_calculating_percentiles_2f_compl, sizeof(__pyx_k_calculating_percentiles_2f_compl), 0, 1, 0, 0}, - {&__pyx_n_s_class, __pyx_k_class, sizeof(__pyx_k_class), 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_col_index, __pyx_k_col_index, sizeof(__pyx_k_col_index), 0, 0, 1, 1}, - {&__pyx_kp_u_complete, __pyx_k_complete, sizeof(__pyx_k_complete), 0, 1, 0, 0}, - {&__pyx_kp_s_contiguous_and_direct, __pyx_k_contiguous_and_direct, sizeof(__pyx_k_contiguous_and_direct), 0, 0, 1, 0}, - {&__pyx_kp_s_contiguous_and_indirect, __pyx_k_contiguous_and_indirect, sizeof(__pyx_k_contiguous_and_indirect), 0, 0, 1, 0}, - {&__pyx_n_s_copy, __pyx_k_copy, sizeof(__pyx_k_copy), 0, 0, 1, 1}, - {&__pyx_kp_u_couldn_t_make_working_sort_direc, __pyx_k_couldn_t_make_working_sort_direc, sizeof(__pyx_k_couldn_t_make_working_sort_direc), 0, 1, 0, 0}, - {&__pyx_n_s_current_percentile, __pyx_k_current_percentile, sizeof(__pyx_k_current_percentile), 0, 0, 1, 1}, - {&__pyx_n_s_current_step, __pyx_k_current_step, sizeof(__pyx_k_current_step), 0, 0, 1, 1}, - {&__pyx_n_s_d, __pyx_k_d, sizeof(__pyx_k_d), 0, 0, 1, 1}, - {&__pyx_kp_u_d_dat, __pyx_k_d_dat, sizeof(__pyx_k_d_dat), 0, 1, 0, 0}, - {&__pyx_kp_u_data_sort_to_heap, __pyx_k_data_sort_to_heap, sizeof(__pyx_k_data_sort_to_heap), 0, 1, 0, 0}, - {&__pyx_n_u_datatype, __pyx_k_datatype, sizeof(__pyx_k_datatype), 0, 1, 0, 1}, - {&__pyx_n_s_debug, __pyx_k_debug, sizeof(__pyx_k_debug), 0, 0, 1, 1}, - {&__pyx_n_s_dem_array, __pyx_k_dem_array, sizeof(__pyx_k_dem_array), 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_info, __pyx_k_dem_info, sizeof(__pyx_k_dem_info), 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_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 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_transform_edt, __pyx_k_distance_transform_edt, sizeof(__pyx_k_distance_transform_edt), 0, 0, 1, 1}, - {&__pyx_n_s_done, __pyx_k_done, sizeof(__pyx_k_done), 0, 0, 1, 1}, - {&__pyx_n_s_double, __pyx_k_double, sizeof(__pyx_k_double), 0, 0, 1, 1}, - {&__pyx_n_s_dt, __pyx_k_dt, sizeof(__pyx_k_dt), 0, 0, 1, 1}, - {&__pyx_n_s_dtype, __pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 0, 1, 1}, - {&__pyx_n_s_dtype_is_object, __pyx_k_dtype_is_object, sizeof(__pyx_k_dtype_is_object), 0, 0, 1, 1}, - {&__pyx_n_s_dzdx_accumulator, __pyx_k_dzdx_accumulator, sizeof(__pyx_k_dzdx_accumulator), 0, 0, 1, 1}, - {&__pyx_n_s_dzdx_array, __pyx_k_dzdx_array, sizeof(__pyx_k_dzdx_array), 0, 0, 1, 1}, - {&__pyx_n_s_dzdy_accumulator, __pyx_k_dzdy_accumulator, sizeof(__pyx_k_dzdy_accumulator), 0, 0, 1, 1}, - {&__pyx_n_s_dzdy_array, __pyx_k_dzdy_array, sizeof(__pyx_k_dzdy_array), 0, 0, 1, 1}, - {&__pyx_n_s_e, __pyx_k_e, sizeof(__pyx_k_e), 0, 0, 1, 1}, - {&__pyx_n_s_empty, __pyx_k_empty, sizeof(__pyx_k_empty), 0, 0, 1, 1}, - {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1}, - {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1}, - {&__pyx_n_s_error, __pyx_k_error, sizeof(__pyx_k_error), 0, 0, 1, 1}, - {&__pyx_n_s_exception, __pyx_k_exception, sizeof(__pyx_k_exception), 0, 0, 1, 1}, - {&__pyx_kp_u_exception_s_s_s_s_s, __pyx_k_exception_s_s_s_s_s, sizeof(__pyx_k_exception_s_s_s_s_s), 0, 1, 0, 0}, - {&__pyx_n_s_existing_shm, __pyx_k_existing_shm, sizeof(__pyx_k_existing_shm), 0, 0, 1, 1}, - {&__pyx_n_s_expected_blocks, __pyx_k_expected_blocks, sizeof(__pyx_k_expected_blocks), 0, 0, 1, 1}, - {&__pyx_n_s_f, __pyx_k_f, sizeof(__pyx_k_f), 0, 0, 1, 1}, - {&__pyx_n_s_fast_file_iterator, __pyx_k_fast_file_iterator, sizeof(__pyx_k_fast_file_iterator), 0, 0, 1, 1}, - {&__pyx_n_s_fast_file_iterator_vector, __pyx_k_fast_file_iterator_vector, sizeof(__pyx_k_fast_file_iterator_vector), 0, 0, 1, 1}, - {&__pyx_n_s_ffi_buffer_size, __pyx_k_ffi_buffer_size, sizeof(__pyx_k_ffi_buffer_size), 0, 0, 1, 1}, - {&__pyx_n_s_ffiv_iter, __pyx_k_ffiv_iter, sizeof(__pyx_k_ffiv_iter), 0, 0, 1, 1}, - {&__pyx_n_s_file_index, __pyx_k_file_index, sizeof(__pyx_k_file_index), 0, 0, 1, 1}, - {&__pyx_n_s_file_path, __pyx_k_file_path, sizeof(__pyx_k_file_path), 0, 0, 1, 1}, - {&__pyx_n_s_finfo, __pyx_k_finfo, sizeof(__pyx_k_finfo), 0, 0, 1, 1}, - {&__pyx_n_s_flags, __pyx_k_flags, sizeof(__pyx_k_flags), 0, 0, 1, 1}, - {&__pyx_n_s_float32, __pyx_k_float32, sizeof(__pyx_k_float32), 0, 0, 1, 1}, - {&__pyx_n_s_float64, __pyx_k_float64, sizeof(__pyx_k_float64), 0, 0, 1, 1}, - {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1}, - {&__pyx_n_s_fortran, __pyx_k_fortran, sizeof(__pyx_k_fortran), 0, 0, 1, 1}, - {&__pyx_n_u_fortran, __pyx_k_fortran, sizeof(__pyx_k_fortran), 0, 1, 0, 1}, - {&__pyx_n_s_fptr, __pyx_k_fptr, sizeof(__pyx_k_fptr), 0, 0, 1, 1}, - {&__pyx_n_s_g, __pyx_k_g, sizeof(__pyx_k_g), 0, 0, 1, 1}, - {&__pyx_n_s_g_band, __pyx_k_g_band, sizeof(__pyx_k_g_band), 0, 0, 1, 1}, - {&__pyx_n_s_g_band_blocksize, __pyx_k_g_band_blocksize, sizeof(__pyx_k_g_band_blocksize), 0, 0, 1, 1}, - {&__pyx_n_s_g_block, __pyx_k_g_block, sizeof(__pyx_k_g_block), 0, 0, 1, 1}, - {&__pyx_n_s_g_raster, __pyx_k_g_raster, sizeof(__pyx_k_g_raster), 0, 0, 1, 1}, - {&__pyx_n_s_g_raster_path, __pyx_k_g_raster_path, sizeof(__pyx_k_g_raster_path), 0, 0, 1, 1}, - {&__pyx_n_s_gdal, __pyx_k_gdal, sizeof(__pyx_k_gdal), 0, 0, 1, 1}, - {&__pyx_n_s_get, __pyx_k_get, sizeof(__pyx_k_get), 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_getpid, __pyx_k_getpid, sizeof(__pyx_k_getpid), 0, 0, 1, 1}, - {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1}, - {&__pyx_kp_s_got_differing_extents_in_dimensi, __pyx_k_got_differing_extents_in_dimensi, sizeof(__pyx_k_got_differing_extents_in_dimensi), 0, 0, 1, 0}, - {&__pyx_n_s_gsq, __pyx_k_gsq, sizeof(__pyx_k_gsq), 0, 0, 1, 1}, - {&__pyx_n_s_gu, __pyx_k_gu, sizeof(__pyx_k_gu), 0, 0, 1, 1}, - {&__pyx_n_s_h, __pyx_k_h, sizeof(__pyx_k_h), 0, 0, 1, 1}, - {&__pyx_n_s_heap_buffer_size, __pyx_k_heap_buffer_size, sizeof(__pyx_k_heap_buffer_size), 0, 0, 1, 1}, - {&__pyx_n_s_heapfile_list, __pyx_k_heapfile_list, sizeof(__pyx_k_heapfile_list), 0, 0, 1, 1}, - {&__pyx_kp_u_here_is_percentile_list_s, __pyx_k_here_is_percentile_list_s, sizeof(__pyx_k_here_is_percentile_list_s), 0, 1, 0, 0}, - {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1}, - {&__pyx_n_s_id, __pyx_k_id, sizeof(__pyx_k_id), 0, 0, 1, 1}, - {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, - {&__pyx_n_s_index, __pyx_k_index, sizeof(__pyx_k_index), 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_int64, __pyx_k_int64, sizeof(__pyx_k_int64), 0, 0, 1, 1}, - {&__pyx_n_s_int8, __pyx_k_int8, sizeof(__pyx_k_int8), 0, 0, 1, 1}, - {&__pyx_kp_u_invalid_value_for_n_s, __pyx_k_invalid_value_for_n_s, sizeof(__pyx_k_invalid_value_for_n_s), 0, 1, 0, 0}, - {&__pyx_n_s_isclose, __pyx_k_isclose, sizeof(__pyx_k_isclose), 0, 0, 1, 1}, - {&__pyx_n_s_items, __pyx_k_items, sizeof(__pyx_k_items), 0, 0, 1, 1}, - {&__pyx_n_s_itemsize, __pyx_k_itemsize, sizeof(__pyx_k_itemsize), 0, 0, 1, 1}, - {&__pyx_kp_s_itemsize_0_for_cython_array, __pyx_k_itemsize_0_for_cython_array, sizeof(__pyx_k_itemsize_0_for_cython_array), 0, 0, 1, 0}, - {&__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_last_update, __pyx_k_last_update, sizeof(__pyx_k_last_update), 0, 0, 1, 1}, - {&__pyx_n_s_local_x_index, __pyx_k_local_x_index, sizeof(__pyx_k_local_x_index), 0, 0, 1, 1}, - {&__pyx_n_s_local_y_index, __pyx_k_local_y_index, sizeof(__pyx_k_local_y_index), 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_band, __pyx_k_mask_band, sizeof(__pyx_k_mask_band), 0, 0, 1, 1}, - {&__pyx_n_s_mask_block, __pyx_k_mask_block, sizeof(__pyx_k_mask_block), 0, 0, 1, 1}, - {&__pyx_n_s_mask_raster, __pyx_k_mask_raster, sizeof(__pyx_k_mask_raster), 0, 0, 1, 1}, - {&__pyx_n_s_max_sample, __pyx_k_max_sample, sizeof(__pyx_k_max_sample), 0, 0, 1, 1}, - {&__pyx_n_s_max_value, __pyx_k_max_value, sizeof(__pyx_k_max_value), 0, 0, 1, 1}, - {&__pyx_n_s_memview, __pyx_k_memview, sizeof(__pyx_k_memview), 0, 0, 1, 1}, - {&__pyx_n_s_min, __pyx_k_min, sizeof(__pyx_k_min), 0, 0, 1, 1}, - {&__pyx_n_s_min_value, __pyx_k_min_value, sizeof(__pyx_k_min_value), 0, 0, 1, 1}, - {&__pyx_n_s_mode, __pyx_k_mode, sizeof(__pyx_k_mode), 0, 0, 1, 1}, - {&__pyx_n_s_multiprocessing, __pyx_k_multiprocessing, sizeof(__pyx_k_multiprocessing), 0, 0, 1, 1}, - {&__pyx_n_s_n, __pyx_k_n, sizeof(__pyx_k_n), 0, 0, 1, 1}, - {&__pyx_n_s_n_cols, __pyx_k_n_cols, sizeof(__pyx_k_n_cols), 0, 0, 1, 1}, - {&__pyx_n_s_n_elements, __pyx_k_n_elements, sizeof(__pyx_k_n_elements), 0, 0, 1, 1}, - {&__pyx_n_s_n_pixels, __pyx_k_n_pixels, sizeof(__pyx_k_n_pixels), 0, 0, 1, 1}, - {&__pyx_n_s_n_rows, __pyx_k_n_rows, sizeof(__pyx_k_n_rows), 0, 0, 1, 1}, - {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, - {&__pyx_n_s_name_2, __pyx_k_name_2, sizeof(__pyx_k_name_2), 0, 0, 1, 1}, - {&__pyx_n_s_ndim, __pyx_k_ndim, sizeof(__pyx_k_ndim), 0, 0, 1, 1}, - {&__pyx_n_s_new, __pyx_k_new, sizeof(__pyx_k_new), 0, 0, 1, 1}, - {&__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_n_s_next_val, __pyx_k_next_val, sizeof(__pyx_k_next_val), 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_u_nodata, __pyx_k_nodata, sizeof(__pyx_k_nodata), 0, 1, 0, 1}, - {&__pyx_n_s_numerical_inf, __pyx_k_numerical_inf, sizeof(__pyx_k_numerical_inf), 0, 0, 1, 1}, - {&__pyx_n_s_numpy, __pyx_k_numpy, sizeof(__pyx_k_numpy), 0, 0, 1, 1}, - {&__pyx_kp_u_numpy_core_multiarray_failed_to, __pyx_k_numpy_core_multiarray_failed_to, sizeof(__pyx_k_numpy_core_multiarray_failed_to), 0, 1, 0, 0}, - {&__pyx_kp_u_numpy_core_umath_failed_to_impor, __pyx_k_numpy_core_umath_failed_to_impor, sizeof(__pyx_k_numpy_core_umath_failed_to_impor), 0, 1, 0, 0}, - {&__pyx_n_s_obj, __pyx_k_obj, sizeof(__pyx_k_obj), 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_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_osr, __pyx_k_osr, sizeof(__pyx_k_osr), 0, 0, 1, 1}, - {&__pyx_kp_u_out_of, __pyx_k_out_of, sizeof(__pyx_k_out_of), 0, 1, 0, 0}, - {&__pyx_n_s_pack, __pyx_k_pack, sizeof(__pyx_k_pack), 0, 0, 1, 1}, - {&__pyx_n_s_path, __pyx_k_path, sizeof(__pyx_k_path), 0, 0, 1, 1}, - {&__pyx_n_s_payload, __pyx_k_payload, sizeof(__pyx_k_payload), 0, 0, 1, 1}, - {&__pyx_n_s_percentile_index, __pyx_k_percentile_index, sizeof(__pyx_k_percentile_index), 0, 0, 1, 1}, - {&__pyx_n_s_percentile_list, __pyx_k_percentile_list, sizeof(__pyx_k_percentile_list), 0, 0, 1, 1}, - {&__pyx_n_s_pickle, __pyx_k_pickle, sizeof(__pyx_k_pickle), 0, 0, 1, 1}, - {&__pyx_n_u_pixel_size, __pyx_k_pixel_size, sizeof(__pyx_k_pixel_size), 0, 1, 0, 1}, - {&__pyx_n_s_pixels_processed, __pyx_k_pixels_processed, sizeof(__pyx_k_pixels_processed), 0, 0, 1, 1}, - {&__pyx_n_s_put, __pyx_k_put, sizeof(__pyx_k_put), 0, 0, 1, 1}, - {&__pyx_n_s_pygeoprocessing, __pyx_k_pygeoprocessing, sizeof(__pyx_k_pygeoprocessing), 0, 0, 1, 1}, - {&__pyx_n_s_pygeoprocessing_geoprocessing_co, __pyx_k_pygeoprocessing_geoprocessing_co, sizeof(__pyx_k_pygeoprocessing_geoprocessing_co), 0, 0, 1, 1}, - {&__pyx_kp_u_pygeoprocessing_geoprocessing_co, __pyx_k_pygeoprocessing_geoprocessing_co, sizeof(__pyx_k_pygeoprocessing_geoprocessing_co), 0, 1, 0, 0}, - {&__pyx_n_s_pyx_PickleError, __pyx_k_pyx_PickleError, sizeof(__pyx_k_pyx_PickleError), 0, 0, 1, 1}, - {&__pyx_n_s_pyx_checksum, __pyx_k_pyx_checksum, sizeof(__pyx_k_pyx_checksum), 0, 0, 1, 1}, - {&__pyx_n_s_pyx_getbuffer, __pyx_k_pyx_getbuffer, sizeof(__pyx_k_pyx_getbuffer), 0, 0, 1, 1}, - {&__pyx_n_s_pyx_result, __pyx_k_pyx_result, sizeof(__pyx_k_pyx_result), 0, 0, 1, 1}, - {&__pyx_n_s_pyx_state, __pyx_k_pyx_state, sizeof(__pyx_k_pyx_state), 0, 0, 1, 1}, - {&__pyx_n_s_pyx_type, __pyx_k_pyx_type, sizeof(__pyx_k_pyx_type), 0, 0, 1, 1}, - {&__pyx_n_s_pyx_unpickle_Enum, __pyx_k_pyx_unpickle_Enum, sizeof(__pyx_k_pyx_unpickle_Enum), 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_q_index, __pyx_k_q_index, sizeof(__pyx_k_q_index), 0, 0, 1, 1}, - {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1}, - {&__pyx_n_s_raster_band_percentile, __pyx_k_raster_band_percentile, sizeof(__pyx_k_raster_band_percentile), 0, 0, 1, 1}, - {&__pyx_n_s_raster_band_percentile_double, __pyx_k_raster_band_percentile_double, sizeof(__pyx_k_raster_band_percentile_double), 0, 0, 1, 1}, - {&__pyx_n_s_raster_band_percentile_int, __pyx_k_raster_band_percentile_int, sizeof(__pyx_k_raster_band_percentile_int), 0, 0, 1, 1}, - {&__pyx_n_s_raster_driver_creation_tuple, __pyx_k_raster_driver_creation_tuple, sizeof(__pyx_k_raster_driver_creation_tuple), 0, 0, 1, 1}, - {&__pyx_n_s_raster_info, __pyx_k_raster_info, sizeof(__pyx_k_raster_info), 0, 0, 1, 1}, - {&__pyx_n_u_raster_size, __pyx_k_raster_size, sizeof(__pyx_k_raster_size), 0, 1, 0, 1}, - {&__pyx_n_s_raster_type, __pyx_k_raster_type, sizeof(__pyx_k_raster_type), 0, 0, 1, 1}, - {&__pyx_n_s_raw_nodata, __pyx_k_raw_nodata, sizeof(__pyx_k_raw_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_region_raster_path, __pyx_k_region_raster_path, sizeof(__pyx_k_region_raster_path), 0, 0, 1, 1}, - {&__pyx_n_s_remove, __pyx_k_remove, sizeof(__pyx_k_remove), 0, 0, 1, 1}, - {&__pyx_n_s_result_list, __pyx_k_result_list, sizeof(__pyx_k_result_list), 0, 0, 1, 1}, - {&__pyx_n_s_rm_dir_when_done, __pyx_k_rm_dir_when_done, sizeof(__pyx_k_rm_dir_when_done), 0, 0, 1, 1}, - {&__pyx_n_s_rmtree, __pyx_k_rmtree, sizeof(__pyx_k_rmtree), 0, 0, 1, 1}, - {&__pyx_n_s_row_index, __pyx_k_row_index, sizeof(__pyx_k_row_index), 0, 0, 1, 1}, - {&__pyx_n_s_s_array, __pyx_k_s_array, sizeof(__pyx_k_s_array), 0, 0, 1, 1}, - {&__pyx_n_s_sample_d_x, __pyx_k_sample_d_x, sizeof(__pyx_k_sample_d_x), 0, 0, 1, 1}, - {&__pyx_n_s_sample_d_y, __pyx_k_sample_d_y, sizeof(__pyx_k_sample_d_y), 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_shape, __pyx_k_shape, sizeof(__pyx_k_shape), 0, 0, 1, 1}, - {&__pyx_n_s_shutil, __pyx_k_shutil, sizeof(__pyx_k_shutil), 0, 0, 1, 1}, - {&__pyx_n_s_size, __pyx_k_size, sizeof(__pyx_k_size), 0, 0, 1, 1}, - {&__pyx_n_s_slope_array, __pyx_k_slope_array, sizeof(__pyx_k_slope_array), 0, 0, 1, 1}, - {&__pyx_n_s_slope_nodata, __pyx_k_slope_nodata, sizeof(__pyx_k_slope_nodata), 0, 0, 1, 1}, - {&__pyx_n_s_sort, __pyx_k_sort, sizeof(__pyx_k_sort), 0, 0, 1, 1}, - {&__pyx_kp_u_sorting_data_to_heap, __pyx_k_sorting_data_to_heap, sizeof(__pyx_k_sorting_data_to_heap), 0, 1, 0, 0}, - {&__pyx_n_s_sq, __pyx_k_sq, sizeof(__pyx_k_sq), 0, 0, 1, 1}, - {&__pyx_n_s_sqrt, __pyx_k_sqrt, sizeof(__pyx_k_sqrt), 0, 0, 1, 1}, - {&__pyx_kp_s_src_pygeoprocessing_geoprocessin, __pyx_k_src_pygeoprocessing_geoprocessin, sizeof(__pyx_k_src_pygeoprocessing_geoprocessin), 0, 0, 1, 0}, - {&__pyx_n_s_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 0, 1, 1}, - {&__pyx_n_s_stats_work_queue, __pyx_k_stats_work_queue, sizeof(__pyx_k_stats_work_queue), 0, 0, 1, 1}, - {&__pyx_n_s_stats_worker, __pyx_k_stats_worker, sizeof(__pyx_k_stats_worker), 0, 0, 1, 1}, - {&__pyx_kp_u_stats_worker_PID, __pyx_k_stats_worker_PID, sizeof(__pyx_k_stats_worker_PID), 0, 1, 0, 0}, - {&__pyx_n_s_step, __pyx_k_step, sizeof(__pyx_k_step), 0, 0, 1, 1}, - {&__pyx_n_s_step_size, __pyx_k_step_size, sizeof(__pyx_k_step_size), 0, 0, 1, 1}, - {&__pyx_n_s_stop, __pyx_k_stop, sizeof(__pyx_k_stop), 0, 0, 1, 1}, - {&__pyx_kp_s_strided_and_direct, __pyx_k_strided_and_direct, sizeof(__pyx_k_strided_and_direct), 0, 0, 1, 0}, - {&__pyx_kp_s_strided_and_direct_or_indirect, __pyx_k_strided_and_direct_or_indirect, sizeof(__pyx_k_strided_and_direct_or_indirect), 0, 0, 1, 0}, - {&__pyx_kp_s_strided_and_indirect, __pyx_k_strided_and_indirect, sizeof(__pyx_k_strided_and_indirect), 0, 0, 1, 0}, - {&__pyx_kp_s_stringsource, __pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 0, 1, 0}, - {&__pyx_n_s_struct, __pyx_k_struct, sizeof(__pyx_k_struct), 0, 0, 1, 1}, - {&__pyx_n_s_sys, __pyx_k_sys, sizeof(__pyx_k_sys), 0, 0, 1, 1}, - {&__pyx_n_s_t_array, __pyx_k_t_array, sizeof(__pyx_k_t_array), 0, 0, 1, 1}, - {&__pyx_n_s_target_distance_band, __pyx_k_target_distance_band, sizeof(__pyx_k_target_distance_band), 0, 0, 1, 1}, - {&__pyx_n_s_target_distance_raster, __pyx_k_target_distance_raster, sizeof(__pyx_k_target_distance_raster), 0, 0, 1, 1}, - {&__pyx_n_s_target_distance_raster_path, __pyx_k_target_distance_raster_path, sizeof(__pyx_k_target_distance_raster_path), 0, 0, 1, 1}, - {&__pyx_n_s_target_slope_band, __pyx_k_target_slope_band, sizeof(__pyx_k_target_slope_band), 0, 0, 1, 1}, - {&__pyx_n_s_target_slope_path, __pyx_k_target_slope_path, sizeof(__pyx_k_target_slope_path), 0, 0, 1, 1}, - {&__pyx_n_s_target_slope_raster, __pyx_k_target_slope_raster, sizeof(__pyx_k_target_slope_raster), 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_kp_u_total_number_of_pixels_s_s, __pyx_k_total_number_of_pixels_s_s, sizeof(__pyx_k_total_number_of_pixels_s_s), 0, 1, 0, 0}, - {&__pyx_n_s_tq, __pyx_k_tq, sizeof(__pyx_k_tq), 0, 0, 1, 1}, - {&__pyx_n_s_traceback, __pyx_k_traceback, sizeof(__pyx_k_traceback), 0, 0, 1, 1}, - {&__pyx_n_s_u_index, __pyx_k_u_index, sizeof(__pyx_k_u_index), 0, 0, 1, 1}, - {&__pyx_kp_s_unable_to_allocate_array_data, __pyx_k_unable_to_allocate_array_data, sizeof(__pyx_k_unable_to_allocate_array_data), 0, 0, 1, 0}, - {&__pyx_kp_s_unable_to_allocate_shape_and_str, __pyx_k_unable_to_allocate_shape_and_str, sizeof(__pyx_k_unable_to_allocate_shape_and_str), 0, 0, 1, 0}, - {&__pyx_kp_u_unable_to_remove_s, __pyx_k_unable_to_remove_s, sizeof(__pyx_k_unable_to_remove_s), 0, 1, 0, 0}, - {&__pyx_n_s_unpack, __pyx_k_unpack, sizeof(__pyx_k_unpack), 0, 0, 1, 1}, - {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1}, - {&__pyx_kp_u_utf_8, __pyx_k_utf_8, sizeof(__pyx_k_utf_8), 0, 1, 0, 0}, - {&__pyx_n_s_valid_mask, __pyx_k_valid_mask, sizeof(__pyx_k_valid_mask), 0, 0, 1, 1}, - {&__pyx_n_s_w, __pyx_k_w, sizeof(__pyx_k_w), 0, 0, 1, 1}, - {&__pyx_n_s_warning, __pyx_k_warning, sizeof(__pyx_k_warning), 0, 0, 1, 1}, - {&__pyx_n_s_win_xsize, __pyx_k_win_xsize, sizeof(__pyx_k_win_xsize), 0, 0, 1, 1}, - {&__pyx_n_u_win_xsize, __pyx_k_win_xsize, sizeof(__pyx_k_win_xsize), 0, 1, 0, 1}, - {&__pyx_n_s_win_ysize, __pyx_k_win_ysize, sizeof(__pyx_k_win_ysize), 0, 0, 1, 1}, - {&__pyx_n_u_win_ysize, __pyx_k_win_ysize, sizeof(__pyx_k_win_ysize), 0, 1, 0, 1}, - {&__pyx_n_s_working_sort_directory, __pyx_k_working_sort_directory, sizeof(__pyx_k_working_sort_directory), 0, 0, 1, 1}, - {&__pyx_n_s_x, __pyx_k_x, sizeof(__pyx_k_x), 0, 0, 1, 1}, - {&__pyx_n_s_x_cell_size, __pyx_k_x_cell_size, sizeof(__pyx_k_x_cell_size), 0, 0, 1, 1}, - {&__pyx_n_s_x_denom_factor, __pyx_k_x_denom_factor, sizeof(__pyx_k_x_denom_factor), 0, 0, 1, 1}, - {&__pyx_n_s_x_end, __pyx_k_x_end, sizeof(__pyx_k_x_end), 0, 0, 1, 1}, - {&__pyx_n_s_x_start, __pyx_k_x_start, sizeof(__pyx_k_x_start), 0, 0, 1, 1}, - {&__pyx_n_s_xoff, __pyx_k_xoff, sizeof(__pyx_k_xoff), 0, 0, 1, 1}, - {&__pyx_n_u_xoff, __pyx_k_xoff, sizeof(__pyx_k_xoff), 0, 1, 0, 1}, - {&__pyx_n_s_y_cell_size, __pyx_k_y_cell_size, sizeof(__pyx_k_y_cell_size), 0, 0, 1, 1}, - {&__pyx_n_s_y_denom_factor, __pyx_k_y_denom_factor, sizeof(__pyx_k_y_denom_factor), 0, 0, 1, 1}, - {&__pyx_n_s_y_end, __pyx_k_y_end, sizeof(__pyx_k_y_end), 0, 0, 1, 1}, - {&__pyx_n_s_y_start, __pyx_k_y_start, sizeof(__pyx_k_y_start), 0, 0, 1, 1}, - {&__pyx_n_s_yoff, __pyx_k_yoff, sizeof(__pyx_k_yoff), 0, 0, 1, 1}, - {&__pyx_n_u_yoff, __pyx_k_yoff, sizeof(__pyx_k_yoff), 0, 1, 0, 1}, - {&__pyx_n_s_zlib, __pyx_k_zlib, sizeof(__pyx_k_zlib), 0, 0, 1, 1}, - {0, 0, 0, 0, 0, 0, 0} -}; -static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 166, __pyx_L1_error) - __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 668, __pyx_L1_error) - __pyx_builtin_OSError = __Pyx_GetBuiltinName(__pyx_n_s_OSError); if (!__pyx_builtin_OSError) __PYX_ERR(0, 716, __pyx_L1_error) - __pyx_builtin_ImportError = __Pyx_GetBuiltinName(__pyx_n_s_ImportError); if (!__pyx_builtin_ImportError) __PYX_ERR(1, 947, __pyx_L1_error) - __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(2, 148, __pyx_L1_error) - __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(2, 151, __pyx_L1_error) - __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(2, 2, __pyx_L1_error) - __pyx_builtin_Ellipsis = __Pyx_GetBuiltinName(__pyx_n_s_Ellipsis); if (!__pyx_builtin_Ellipsis) __PYX_ERR(2, 404, __pyx_L1_error) - __pyx_builtin_id = __Pyx_GetBuiltinName(__pyx_n_s_id); if (!__pyx_builtin_id) __PYX_ERR(2, 613, __pyx_L1_error) - __pyx_builtin_IndexError = __Pyx_GetBuiltinName(__pyx_n_s_IndexError); if (!__pyx_builtin_IndexError) __PYX_ERR(2, 832, __pyx_L1_error) - return 0; - __pyx_L1_error:; - return -1; -} - -static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - - /* "pygeoprocessing/geoprocessing_core.pyx":165 - * buf_obj=mask_block) - * # base case - * g_block[0, :] = (mask_block[0, :] == 0) * numerical_inf # <<<<<<<<<<<<<< - * for row_index in range(1, n_rows): - * for local_x_index in range(win_xsize): - */ - __pyx_slice_ = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice_)) __PYX_ERR(0, 165, __pyx_L1_error) - __Pyx_GOTREF(__pyx_slice_); - __Pyx_GIVEREF(__pyx_slice_); - __pyx_tuple__2 = PyTuple_Pack(2, __pyx_int_0, __pyx_slice_); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 165, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__2); - __Pyx_GIVEREF(__pyx_tuple__2); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":947 - * __pyx_import_array() - * except Exception: - * raise ImportError("numpy.core.multiarray failed to import") # <<<<<<<<<<<<<< - * - * cdef inline int import_umath() except -1: - */ - __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_u_numpy_core_multiarray_failed_to); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(1, 947, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__4); - __Pyx_GIVEREF(__pyx_tuple__4); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":953 - * _import_umath() - * except Exception: - * raise ImportError("numpy.core.umath failed to import") # <<<<<<<<<<<<<< - * - * cdef inline int import_ufunc() except -1: - */ - __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_u_numpy_core_umath_failed_to_impor); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(1, 953, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__5); - __Pyx_GIVEREF(__pyx_tuple__5); - - /* "View.MemoryView":133 - * - * if not self.ndim: - * raise ValueError("Empty shape tuple for cython.array") # <<<<<<<<<<<<<< - * - * if itemsize <= 0: - */ - __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_s_Empty_shape_tuple_for_cython_arr); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(2, 133, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__6); - __Pyx_GIVEREF(__pyx_tuple__6); - - /* "View.MemoryView":136 - * - * if itemsize <= 0: - * raise ValueError("itemsize <= 0 for cython.array") # <<<<<<<<<<<<<< - * - * if not isinstance(format, bytes): - */ - __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_s_itemsize_0_for_cython_array); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(2, 136, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__7); - __Pyx_GIVEREF(__pyx_tuple__7); - - /* "View.MemoryView":148 - * - * if not self._shape: - * raise MemoryError("unable to allocate shape and strides.") # <<<<<<<<<<<<<< - * - * - */ - __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_s_unable_to_allocate_shape_and_str); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(2, 148, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__8); - __Pyx_GIVEREF(__pyx_tuple__8); - - /* "View.MemoryView":176 - * self.data = malloc(self.len) - * if not self.data: - * raise MemoryError("unable to allocate array data.") # <<<<<<<<<<<<<< - * - * if self.dtype_is_object: - */ - __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_s_unable_to_allocate_array_data); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(2, 176, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__9); - __Pyx_GIVEREF(__pyx_tuple__9); - - /* "View.MemoryView":192 - * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - * if not (flags & bufmode): - * raise ValueError("Can only create a buffer that is contiguous in memory.") # <<<<<<<<<<<<<< - * info.buf = self.data - * info.len = self.len - */ - __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_s_Can_only_create_a_buffer_that_is); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(2, 192, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__10); - __Pyx_GIVEREF(__pyx_tuple__10); - - /* "(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__11 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(2, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__11); - __Pyx_GIVEREF(__pyx_tuple__11); - - /* "(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__12 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(2, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__12); - __Pyx_GIVEREF(__pyx_tuple__12); - - /* "View.MemoryView":418 - * def __setitem__(memoryview self, object index, object value): - * if self.view.readonly: - * raise TypeError("Cannot assign to read-only memoryview") # <<<<<<<<<<<<<< - * - * have_slices, index = _unellipsify(index, self.view.ndim) - */ - __pyx_tuple__13 = PyTuple_Pack(1, __pyx_kp_s_Cannot_assign_to_read_only_memor); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(2, 418, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__13); - __Pyx_GIVEREF(__pyx_tuple__13); - - /* "View.MemoryView":495 - * result = struct.unpack(self.view.format, bytesitem) - * except struct.error: - * raise ValueError("Unable to convert item to object") # <<<<<<<<<<<<<< - * else: - * if len(self.view.format) == 1: - */ - __pyx_tuple__14 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_convert_item_to_object); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(2, 495, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__14); - __Pyx_GIVEREF(__pyx_tuple__14); - - /* "View.MemoryView":520 - * def __getbuffer__(self, Py_buffer *info, int flags): - * if flags & PyBUF_WRITABLE and self.view.readonly: - * raise ValueError("Cannot create writable memory view from read-only memoryview") # <<<<<<<<<<<<<< - * - * if flags & PyBUF_ND: - */ - __pyx_tuple__15 = PyTuple_Pack(1, __pyx_kp_s_Cannot_create_writable_memory_vi); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(2, 520, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__15); - __Pyx_GIVEREF(__pyx_tuple__15); - - /* "View.MemoryView":570 - * if self.view.strides == NULL: - * - * raise ValueError("Buffer view does not expose strides") # <<<<<<<<<<<<<< - * - * return tuple([stride for stride in self.view.strides[:self.view.ndim]]) - */ - __pyx_tuple__16 = PyTuple_Pack(1, __pyx_kp_s_Buffer_view_does_not_expose_stri); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(2, 570, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__16); - __Pyx_GIVEREF(__pyx_tuple__16); - - /* "View.MemoryView":577 - * def suboffsets(self): - * if self.view.suboffsets == NULL: - * return (-1,) * self.view.ndim # <<<<<<<<<<<<<< - * - * return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]]) - */ - __pyx_tuple__17 = PyTuple_New(1); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(2, 577, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__17); - __Pyx_INCREF(__pyx_int_neg_1); - __Pyx_GIVEREF(__pyx_int_neg_1); - PyTuple_SET_ITEM(__pyx_tuple__17, 0, __pyx_int_neg_1); - __Pyx_GIVEREF(__pyx_tuple__17); - - /* "(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__18 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(2, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__18); - __Pyx_GIVEREF(__pyx_tuple__18); - - /* "(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__19 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(2, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__19); - __Pyx_GIVEREF(__pyx_tuple__19); - - /* "View.MemoryView":703 - * for suboffset in suboffsets[:ndim]: - * if suboffset >= 0: - * raise ValueError("Indirect dimensions not supported") # <<<<<<<<<<<<<< - * - * - */ - __pyx_tuple__20 = PyTuple_Pack(1, __pyx_kp_s_Indirect_dimensions_not_supporte); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(2, 703, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__20); - __Pyx_GIVEREF(__pyx_tuple__20); - - /* "(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__21 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(2, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__21); - __Pyx_GIVEREF(__pyx_tuple__21); - - /* "(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__22 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(2, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__22); - __Pyx_GIVEREF(__pyx_tuple__22); - - /* "pygeoprocessing/geoprocessing_core.pyx":32 - * - * DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS = ('GTIFF', ( - * 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', # <<<<<<<<<<<<<< - * 'BLOCKXSIZE=256', 'BLOCKYSIZE=256')) - * - */ - __pyx_tuple__23 = PyTuple_Pack(5, __pyx_kp_u_TILED_YES, __pyx_kp_u_BIGTIFF_YES, __pyx_kp_u_COMPRESS_LZW, __pyx_kp_u_BLOCKXSIZE_256, __pyx_kp_u_BLOCKYSIZE_256); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 32, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__23); - __Pyx_GIVEREF(__pyx_tuple__23); - - /* "pygeoprocessing/geoprocessing_core.pyx":31 - * import pygeoprocessing - * - * DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS = ('GTIFF', ( # <<<<<<<<<<<<<< - * 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', - * 'BLOCKXSIZE=256', 'BLOCKYSIZE=256')) - */ - __pyx_tuple__24 = PyTuple_Pack(2, __pyx_n_u_GTIFF, __pyx_tuple__23); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 31, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__24); - __Pyx_GIVEREF(__pyx_tuple__24); - - /* "pygeoprocessing/geoprocessing_core.pyx":44 - * DEFAULT_OSR_AXIS_MAPPING_STRATEGY = osr.OAMS_TRADITIONAL_GIS_ORDER - * - * LOGGER = logging.getLogger('pygeoprocessing.geoprocessing_core') # <<<<<<<<<<<<<< - * - * cdef float _NODATA = -1.0 - */ - __pyx_tuple__25 = PyTuple_Pack(1, __pyx_kp_u_pygeoprocessing_geoprocessing_co); if (unlikely(!__pyx_tuple__25)) __PYX_ERR(0, 44, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__25); - __Pyx_GIVEREF(__pyx_tuple__25); - - /* "pygeoprocessing/geoprocessing_core.pyx":71 - * @cython.wraparound(False) - * @cython.cdivision(True) - * def _distance_transform_edt( # <<<<<<<<<<<<<< - * region_raster_path, g_raster_path, float sample_d_x, - * float sample_d_y, target_distance_raster_path, - */ - __pyx_tuple__26 = PyTuple_Pack(42, __pyx_n_s_region_raster_path, __pyx_n_s_g_raster_path, __pyx_n_s_sample_d_x, __pyx_n_s_sample_d_y, __pyx_n_s_target_distance_raster_path, __pyx_n_s_raster_driver_creation_tuple, __pyx_n_s_yoff, __pyx_n_s_row_index, __pyx_n_s_block_ysize, __pyx_n_s_win_ysize, __pyx_n_s_n_rows, __pyx_n_s_xoff, __pyx_n_s_block_xsize, __pyx_n_s_win_xsize, __pyx_n_s_n_cols, __pyx_n_s_q_index, __pyx_n_s_local_x_index, __pyx_n_s_local_y_index, __pyx_n_s_u_index, __pyx_n_s_tq, __pyx_n_s_sq, __pyx_n_s_gu, __pyx_n_s_gsq, __pyx_n_s_w, __pyx_n_s_g_block, __pyx_n_s_s_array, __pyx_n_s_t_array, __pyx_n_s_dt, __pyx_n_s_mask_block, __pyx_n_s_mask_raster, __pyx_n_s_mask_band, __pyx_n_s_raster_info, __pyx_n_s_g_raster, __pyx_n_s_g_band, __pyx_n_s_g_band_blocksize, __pyx_n_s_max_sample, __pyx_n_s_numerical_inf, __pyx_n_s_done, __pyx_n_s_distance_nodata, __pyx_n_s_target_distance_raster, __pyx_n_s_target_distance_band, __pyx_n_s_valid_mask); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 71, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__26); - __Pyx_GIVEREF(__pyx_tuple__26); - __pyx_codeobj__27 = (PyObject*)__Pyx_PyCode_New(6, 0, 42, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_geoprocessin, __pyx_n_s_distance_transform_edt, 71, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__27)) __PYX_ERR(0, 71, __pyx_L1_error) - - /* "pygeoprocessing/geoprocessing_core.pyx":287 - * @cython.nonecheck(False) - * @cython.cdivision(True) - * def calculate_slope( # <<<<<<<<<<<<<< - * base_elevation_raster_path_band, target_slope_path, - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): - */ - __pyx_tuple__28 = PyTuple_Pack(43, __pyx_n_s_base_elevation_raster_path_band, __pyx_n_s_target_slope_path, __pyx_n_s_raster_driver_creation_tuple, __pyx_n_s_a, __pyx_n_s_b, __pyx_n_s_c, __pyx_n_s_d, __pyx_n_s_e, __pyx_n_s_f, __pyx_n_s_g, __pyx_n_s_h, __pyx_n_s_i, __pyx_n_s_dem_nodata, __pyx_n_s_x_cell_size, __pyx_n_s_y_cell_size, __pyx_n_s_dzdx_accumulator, __pyx_n_s_dzdy_accumulator, __pyx_n_s_row_index, __pyx_n_s_col_index, __pyx_n_s_n_rows, __pyx_n_s_n_cols, __pyx_n_s_x_denom_factor, __pyx_n_s_y_denom_factor, __pyx_n_s_win_xsize, __pyx_n_s_win_ysize, __pyx_n_s_dem_array, __pyx_n_s_slope_array, __pyx_n_s_dzdx_array, __pyx_n_s_dzdy_array, __pyx_n_s_dem_raster, __pyx_n_s_dem_band, __pyx_n_s_dem_info, __pyx_n_s_raw_nodata, __pyx_n_s_slope_nodata, __pyx_n_s_target_slope_raster, __pyx_n_s_target_slope_band, __pyx_n_s_block_offset, __pyx_n_s_block_offset_copy, __pyx_n_s_x_start, __pyx_n_s_x_end, __pyx_n_s_y_start, __pyx_n_s_y_end, __pyx_n_s_valid_mask); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 287, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__28); - __Pyx_GIVEREF(__pyx_tuple__28); - __pyx_codeobj__29 = (PyObject*)__Pyx_PyCode_New(3, 0, 43, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_geoprocessin, __pyx_n_s_calculate_slope, 287, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__29)) __PYX_ERR(0, 287, __pyx_L1_error) - - /* "pygeoprocessing/geoprocessing_core.pyx":544 - * @cython.boundscheck(False) - * @cython.cdivision(True) - * def stats_worker(stats_work_queue, expected_blocks): # <<<<<<<<<<<<<< - * """Worker to calculate continuous min, max, mean and standard deviation. - * - */ - __pyx_tuple__30 = PyTuple_Pack(18, __pyx_n_s_stats_work_queue, __pyx_n_s_expected_blocks, __pyx_n_s_block, __pyx_n_s_M_local, __pyx_n_s_S_local, __pyx_n_s_min_value, __pyx_n_s_max_value, __pyx_n_s_x, __pyx_n_s_i, __pyx_n_s_n_elements, __pyx_n_s_n, __pyx_n_s_payload, __pyx_n_s_index, __pyx_n_s_existing_shm, __pyx_n_s_shape, __pyx_n_s_dtype, __pyx_n_s_M_last, __pyx_n_s_e); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 544, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__30); - __Pyx_GIVEREF(__pyx_tuple__30); - __pyx_codeobj__31 = (PyObject*)__Pyx_PyCode_New(2, 0, 18, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__30, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_geoprocessin, __pyx_n_s_stats_worker, 544, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__31)) __PYX_ERR(0, 544, __pyx_L1_error) - - /* "pygeoprocessing/geoprocessing_core.pyx":626 - * - * - * def raster_band_percentile( # <<<<<<<<<<<<<< - * base_raster_path_band, working_sort_directory, percentile_list, - * heap_buffer_size=2**28, ffi_buffer_size=2**10): - */ - __pyx_tuple__32 = PyTuple_Pack(6, __pyx_n_s_base_raster_path_band, __pyx_n_s_working_sort_directory, __pyx_n_s_percentile_list, __pyx_n_s_heap_buffer_size, __pyx_n_s_ffi_buffer_size, __pyx_n_s_raster_type); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 626, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__32); - __Pyx_GIVEREF(__pyx_tuple__32); - __pyx_codeobj__33 = (PyObject*)__Pyx_PyCode_New(5, 0, 6, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__32, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_geoprocessin, __pyx_n_s_raster_band_percentile, 626, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__33)) __PYX_ERR(0, 626, __pyx_L1_error) - - /* "pygeoprocessing/geoprocessing_core.pyx":673 - * - * - * def _raster_band_percentile_int( # <<<<<<<<<<<<<< - * base_raster_path_band, working_sort_directory, percentile_list, - * heap_buffer_size, ffi_buffer_size): - */ - __pyx_tuple__35 = PyTuple_Pack(29, __pyx_n_s_base_raster_path_band, __pyx_n_s_working_sort_directory, __pyx_n_s_percentile_list, __pyx_n_s_heap_buffer_size, __pyx_n_s_ffi_buffer_size, __pyx_n_s_fptr, __pyx_n_s_fast_file_iterator, __pyx_n_s_fast_file_iterator_vector, __pyx_n_s_ffiv_iter, __pyx_n_s_percentile_index, __pyx_n_s_i, __pyx_n_s_n_elements, __pyx_n_s_next_val, __pyx_n_s_step_size, __pyx_n_s_current_percentile, __pyx_n_s_current_step, __pyx_n_s_result_list, __pyx_n_s_rm_dir_when_done, __pyx_n_s_buffer_data, __pyx_n_s_heapfile_list, __pyx_n_s_file_index, __pyx_n_s_raster_info, __pyx_n_s_nodata, __pyx_n_s_n_pixels, __pyx_n_s_pixels_processed, __pyx_n_s_last_update, __pyx_n_s__34, __pyx_n_s_block_data, __pyx_n_s_file_path); if (unlikely(!__pyx_tuple__35)) __PYX_ERR(0, 673, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__35); - __Pyx_GIVEREF(__pyx_tuple__35); - __pyx_codeobj__36 = (PyObject*)__Pyx_PyCode_New(5, 0, 29, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__35, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_geoprocessin, __pyx_n_s_raster_band_percentile_int, 673, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__36)) __PYX_ERR(0, 673, __pyx_L1_error) - - /* "pygeoprocessing/geoprocessing_core.pyx":819 - * - * - * def _raster_band_percentile_double( # <<<<<<<<<<<<<< - * base_raster_path_band, working_sort_directory, percentile_list, - * heap_buffer_size, ffi_buffer_size): - */ - __pyx_tuple__37 = PyTuple_Pack(30, __pyx_n_s_base_raster_path_band, __pyx_n_s_working_sort_directory, __pyx_n_s_percentile_list, __pyx_n_s_heap_buffer_size, __pyx_n_s_ffi_buffer_size, __pyx_n_s_fptr, __pyx_n_s_buffer_data, __pyx_n_s_fast_file_iterator, __pyx_n_s_fast_file_iterator_vector, __pyx_n_s_percentile_index, __pyx_n_s_i, __pyx_n_s_n_elements, __pyx_n_s_next_val, __pyx_n_s_current_step, __pyx_n_s_step_size, __pyx_n_s_current_percentile, __pyx_n_s_result_list, __pyx_n_s_rm_dir_when_done, __pyx_n_s_e, __pyx_n_s_file_index, __pyx_n_s_nodata, __pyx_n_s_heapfile_list, __pyx_n_s_raster_info, __pyx_n_s_n_pixels, __pyx_n_s_pixels_processed, __pyx_n_s_last_update, __pyx_n_s__34, __pyx_n_s_block_data, __pyx_n_s_file_path, __pyx_n_s_ffiv_iter); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(0, 819, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__37); - __Pyx_GIVEREF(__pyx_tuple__37); - __pyx_codeobj__38 = (PyObject*)__Pyx_PyCode_New(5, 0, 30, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__37, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_geoprocessin, __pyx_n_s_raster_band_percentile_double, 819, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__38)) __PYX_ERR(0, 819, __pyx_L1_error) - - /* "View.MemoryView":286 - * return self.name - * - * cdef generic = Enum("") # <<<<<<<<<<<<<< - * cdef strided = Enum("") # default - * cdef indirect = Enum("") - */ - __pyx_tuple__39 = PyTuple_Pack(1, __pyx_kp_s_strided_and_direct_or_indirect); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(2, 286, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__39); - __Pyx_GIVEREF(__pyx_tuple__39); - - /* "View.MemoryView":287 - * - * cdef generic = Enum("") - * cdef strided = Enum("") # default # <<<<<<<<<<<<<< - * cdef indirect = Enum("") - * - */ - __pyx_tuple__40 = PyTuple_Pack(1, __pyx_kp_s_strided_and_direct); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(2, 287, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__40); - __Pyx_GIVEREF(__pyx_tuple__40); - - /* "View.MemoryView":288 - * cdef generic = Enum("") - * cdef strided = Enum("") # default - * cdef indirect = Enum("") # <<<<<<<<<<<<<< - * - * - */ - __pyx_tuple__41 = PyTuple_Pack(1, __pyx_kp_s_strided_and_indirect); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(2, 288, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__41); - __Pyx_GIVEREF(__pyx_tuple__41); - - /* "View.MemoryView":291 - * - * - * cdef contiguous = Enum("") # <<<<<<<<<<<<<< - * cdef indirect_contiguous = Enum("") - * - */ - __pyx_tuple__42 = PyTuple_Pack(1, __pyx_kp_s_contiguous_and_direct); if (unlikely(!__pyx_tuple__42)) __PYX_ERR(2, 291, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__42); - __Pyx_GIVEREF(__pyx_tuple__42); - - /* "View.MemoryView":292 - * - * cdef contiguous = Enum("") - * cdef indirect_contiguous = Enum("") # <<<<<<<<<<<<<< - * - * - */ - __pyx_tuple__43 = PyTuple_Pack(1, __pyx_kp_s_contiguous_and_indirect); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(2, 292, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__43); - __Pyx_GIVEREF(__pyx_tuple__43); - - /* "(tree fragment)":1 - * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< - * cdef object __pyx_PickleError - * cdef object __pyx_result - */ - __pyx_tuple__44 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(2, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__44); - __Pyx_GIVEREF(__pyx_tuple__44); - __pyx_codeobj__45 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 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_stringsource, __pyx_n_s_pyx_unpickle_Enum, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__45)) __PYX_ERR(2, 1, __pyx_L1_error) - __Pyx_RefNannyFinishContext(); - return 0; - __pyx_L1_error:; - __Pyx_RefNannyFinishContext(); - return -1; -} - -static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { - if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); - __pyx_float_5_0 = PyFloat_FromDouble(5.0); if (unlikely(!__pyx_float_5_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_1024 = PyInt_FromLong(1024); if (unlikely(!__pyx_int_1024)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_184977713 = PyInt_FromLong(184977713L); if (unlikely(!__pyx_int_184977713)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_268435456 = PyInt_FromLong(268435456L); if (unlikely(!__pyx_int_268435456)) __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 CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/ -static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/ -static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/ -static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/ -static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/ -static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/ -static CYTHON_SMALL_CODE 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 ---*/ - generic = Py_None; Py_INCREF(Py_None); - strided = Py_None; Py_INCREF(Py_None); - indirect = Py_None; Py_INCREF(Py_None); - contiguous = Py_None; Py_INCREF(Py_None); - indirect_contiguous = Py_None; Py_INCREF(Py_None); - __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 - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); - /*--- Type init code ---*/ - __pyx_vtabptr_array = &__pyx_vtable_array; - __pyx_vtable_array.get_memview = (PyObject *(*)(struct __pyx_array_obj *))__pyx_array_get_memview; - if (PyType_Ready(&__pyx_type___pyx_array) < 0) __PYX_ERR(2, 105, __pyx_L1_error) - #if PY_VERSION_HEX < 0x030800B1 - __pyx_type___pyx_array.tp_print = 0; - #endif - if (__Pyx_SetVtable(__pyx_type___pyx_array.tp_dict, __pyx_vtabptr_array) < 0) __PYX_ERR(2, 105, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_array) < 0) __PYX_ERR(2, 105, __pyx_L1_error) - __pyx_array_type = &__pyx_type___pyx_array; - if (PyType_Ready(&__pyx_type___pyx_MemviewEnum) < 0) __PYX_ERR(2, 279, __pyx_L1_error) - #if PY_VERSION_HEX < 0x030800B1 - __pyx_type___pyx_MemviewEnum.tp_print = 0; - #endif - if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type___pyx_MemviewEnum.tp_dictoffset && __pyx_type___pyx_MemviewEnum.tp_getattro == PyObject_GenericGetAttr)) { - __pyx_type___pyx_MemviewEnum.tp_getattro = __Pyx_PyObject_GenericGetAttr; - } - if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_MemviewEnum) < 0) __PYX_ERR(2, 279, __pyx_L1_error) - __pyx_MemviewEnum_type = &__pyx_type___pyx_MemviewEnum; - __pyx_vtabptr_memoryview = &__pyx_vtable_memoryview; - __pyx_vtable_memoryview.get_item_pointer = (char *(*)(struct __pyx_memoryview_obj *, PyObject *))__pyx_memoryview_get_item_pointer; - __pyx_vtable_memoryview.is_slice = (PyObject *(*)(struct __pyx_memoryview_obj *, PyObject *))__pyx_memoryview_is_slice; - __pyx_vtable_memoryview.setitem_slice_assignment = (PyObject *(*)(struct __pyx_memoryview_obj *, PyObject *, PyObject *))__pyx_memoryview_setitem_slice_assignment; - __pyx_vtable_memoryview.setitem_slice_assign_scalar = (PyObject *(*)(struct __pyx_memoryview_obj *, struct __pyx_memoryview_obj *, PyObject *))__pyx_memoryview_setitem_slice_assign_scalar; - __pyx_vtable_memoryview.setitem_indexed = (PyObject *(*)(struct __pyx_memoryview_obj *, PyObject *, PyObject *))__pyx_memoryview_setitem_indexed; - __pyx_vtable_memoryview.convert_item_to_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *))__pyx_memoryview_convert_item_to_object; - __pyx_vtable_memoryview.assign_item_from_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *, PyObject *))__pyx_memoryview_assign_item_from_object; - if (PyType_Ready(&__pyx_type___pyx_memoryview) < 0) __PYX_ERR(2, 330, __pyx_L1_error) - #if PY_VERSION_HEX < 0x030800B1 - __pyx_type___pyx_memoryview.tp_print = 0; - #endif - if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type___pyx_memoryview.tp_dictoffset && __pyx_type___pyx_memoryview.tp_getattro == PyObject_GenericGetAttr)) { - __pyx_type___pyx_memoryview.tp_getattro = __Pyx_PyObject_GenericGetAttr; - } - if (__Pyx_SetVtable(__pyx_type___pyx_memoryview.tp_dict, __pyx_vtabptr_memoryview) < 0) __PYX_ERR(2, 330, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_memoryview) < 0) __PYX_ERR(2, 330, __pyx_L1_error) - __pyx_memoryview_type = &__pyx_type___pyx_memoryview; - __pyx_vtabptr__memoryviewslice = &__pyx_vtable__memoryviewslice; - __pyx_vtable__memoryviewslice.__pyx_base = *__pyx_vtabptr_memoryview; - __pyx_vtable__memoryviewslice.__pyx_base.convert_item_to_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *))__pyx_memoryviewslice_convert_item_to_object; - __pyx_vtable__memoryviewslice.__pyx_base.assign_item_from_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *, PyObject *))__pyx_memoryviewslice_assign_item_from_object; - __pyx_type___pyx_memoryviewslice.tp_base = __pyx_memoryview_type; - if (PyType_Ready(&__pyx_type___pyx_memoryviewslice) < 0) __PYX_ERR(2, 965, __pyx_L1_error) - #if PY_VERSION_HEX < 0x030800B1 - __pyx_type___pyx_memoryviewslice.tp_print = 0; - #endif - if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type___pyx_memoryviewslice.tp_dictoffset && __pyx_type___pyx_memoryviewslice.tp_getattro == PyObject_GenericGetAttr)) { - __pyx_type___pyx_memoryviewslice.tp_getattro = __Pyx_PyObject_GenericGetAttr; - } - if (__Pyx_SetVtable(__pyx_type___pyx_memoryviewslice.tp_dict, __pyx_vtabptr__memoryviewslice) < 0) __PYX_ERR(2, 965, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_memoryviewslice) < 0) __PYX_ERR(2, 965, __pyx_L1_error) - __pyx_memoryviewslice_type = &__pyx_type___pyx_memoryviewslice; - __Pyx_RefNannyFinishContext(); - return 0; - __pyx_L1_error:; - __Pyx_RefNannyFinishContext(); - return -1; -} - -static int __Pyx_modinit_type_import_code(void) { - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); - /*--- Type import code ---*/ - __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 9, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", - #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 - sizeof(PyTypeObject), - #else - sizeof(PyHeapTypeObject), - #endif - __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(3, 9, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyImport_ImportModule("numpy"); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 200, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_ptype_5numpy_dtype = __Pyx_ImportType(__pyx_t_1, "numpy", "dtype", sizeof(PyArray_Descr), __Pyx_ImportType_CheckSize_Ignore); - if (!__pyx_ptype_5numpy_dtype) __PYX_ERR(1, 200, __pyx_L1_error) - __pyx_ptype_5numpy_flatiter = __Pyx_ImportType(__pyx_t_1, "numpy", "flatiter", sizeof(PyArrayIterObject), __Pyx_ImportType_CheckSize_Ignore); - if (!__pyx_ptype_5numpy_flatiter) __PYX_ERR(1, 223, __pyx_L1_error) - __pyx_ptype_5numpy_broadcast = __Pyx_ImportType(__pyx_t_1, "numpy", "broadcast", sizeof(PyArrayMultiIterObject), __Pyx_ImportType_CheckSize_Ignore); - if (!__pyx_ptype_5numpy_broadcast) __PYX_ERR(1, 227, __pyx_L1_error) - __pyx_ptype_5numpy_ndarray = __Pyx_ImportType(__pyx_t_1, "numpy", "ndarray", sizeof(PyArrayObject), __Pyx_ImportType_CheckSize_Ignore); - if (!__pyx_ptype_5numpy_ndarray) __PYX_ERR(1, 239, __pyx_L1_error) - __pyx_ptype_5numpy_generic = __Pyx_ImportType(__pyx_t_1, "numpy", "generic", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_generic) __PYX_ERR(1, 771, __pyx_L1_error) - __pyx_ptype_5numpy_number = __Pyx_ImportType(__pyx_t_1, "numpy", "number", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_number) __PYX_ERR(1, 773, __pyx_L1_error) - __pyx_ptype_5numpy_integer = __Pyx_ImportType(__pyx_t_1, "numpy", "integer", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_integer) __PYX_ERR(1, 775, __pyx_L1_error) - __pyx_ptype_5numpy_signedinteger = __Pyx_ImportType(__pyx_t_1, "numpy", "signedinteger", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_signedinteger) __PYX_ERR(1, 777, __pyx_L1_error) - __pyx_ptype_5numpy_unsignedinteger = __Pyx_ImportType(__pyx_t_1, "numpy", "unsignedinteger", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_unsignedinteger) __PYX_ERR(1, 779, __pyx_L1_error) - __pyx_ptype_5numpy_inexact = __Pyx_ImportType(__pyx_t_1, "numpy", "inexact", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_inexact) __PYX_ERR(1, 781, __pyx_L1_error) - __pyx_ptype_5numpy_floating = __Pyx_ImportType(__pyx_t_1, "numpy", "floating", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_floating) __PYX_ERR(1, 783, __pyx_L1_error) - __pyx_ptype_5numpy_complexfloating = __Pyx_ImportType(__pyx_t_1, "numpy", "complexfloating", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_complexfloating) __PYX_ERR(1, 785, __pyx_L1_error) - __pyx_ptype_5numpy_flexible = __Pyx_ImportType(__pyx_t_1, "numpy", "flexible", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_flexible) __PYX_ERR(1, 787, __pyx_L1_error) - __pyx_ptype_5numpy_character = __Pyx_ImportType(__pyx_t_1, "numpy", "character", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_character) __PYX_ERR(1, 789, __pyx_L1_error) - __pyx_ptype_5numpy_ufunc = __Pyx_ImportType(__pyx_t_1, "numpy", "ufunc", sizeof(PyUFuncObject), __Pyx_ImportType_CheckSize_Ignore); - if (!__pyx_ptype_5numpy_ufunc) __PYX_ERR(1, 827, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_RefNannyFinishContext(); - return 0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __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; -} - - -#ifndef CYTHON_NO_PYINIT_EXPORT -#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC -#elif PY_MAJOR_VERSION < 3 -#ifdef __cplusplus -#define __Pyx_PyMODINIT_FUNC extern "C" void -#else -#define __Pyx_PyMODINIT_FUNC void -#endif -#else -#ifdef __cplusplus -#define __Pyx_PyMODINIT_FUNC extern "C" PyObject * -#else -#define __Pyx_PyMODINIT_FUNC PyObject * -#endif -#endif - - -#if PY_MAJOR_VERSION < 3 -__Pyx_PyMODINIT_FUNC initgeoprocessing_core(void) CYTHON_SMALL_CODE; /*proto*/ -__Pyx_PyMODINIT_FUNC initgeoprocessing_core(void) -#else -__Pyx_PyMODINIT_FUNC PyInit_geoprocessing_core(void) CYTHON_SMALL_CODE; /*proto*/ -__Pyx_PyMODINIT_FUNC PyInit_geoprocessing_core(void) -#if CYTHON_PEP489_MULTI_PHASE_INIT -{ - return PyModuleDef_Init(&__pyx_moduledef); -} -static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) { - #if PY_VERSION_HEX >= 0x030700A1 - static PY_INT64_T main_interpreter_id = -1; - PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp); - if (main_interpreter_id == -1) { - main_interpreter_id = current_id; - return (unlikely(current_id == -1)) ? -1 : 0; - } else if (unlikely(main_interpreter_id != current_id)) - #else - static PyInterpreterState *main_interpreter = NULL; - PyInterpreterState *current_interpreter = PyThreadState_Get()->interp; - if (!main_interpreter) { - main_interpreter = current_interpreter; - } else if (unlikely(main_interpreter != current_interpreter)) - #endif - { - PyErr_SetString( - PyExc_ImportError, - "Interpreter change detected - this module can only be loaded into one interpreter per process."); - return -1; - } - return 0; -} -static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) { - PyObject *value = PyObject_GetAttrString(spec, from_name); - int result = 0; - if (likely(value)) { - if (allow_none || value != Py_None) { - result = PyDict_SetItemString(moddict, to_name, value); - } - Py_DECREF(value); - } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { - PyErr_Clear(); - } else { - result = -1; - } - return result; -} -static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) { - PyObject *module = NULL, *moddict, *modname; - if (__Pyx_check_single_interpreter()) - return NULL; - 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__", 1) < 0)) goto bad; - if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad; - if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad; - if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad; - return module; -bad: - Py_XDECREF(module); - return NULL; -} - - -static CYTHON_SMALL_CODE int __pyx_pymod_exec_geoprocessing_core(PyObject *__pyx_pyinit_module) -#endif -#endif -{ - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - static PyThread_type_lock __pyx_t_3[8]; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannyDeclarations - #if CYTHON_PEP489_MULTI_PHASE_INIT - if (__pyx_m) { - if (__pyx_m == __pyx_pyinit_module) return 0; - PyErr_SetString(PyExc_RuntimeError, "Module 'geoprocessing_core' has already been imported. Re-initialisation is not supported."); - return -1; - } - #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_geoprocessing_core(void)", 0); - if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error) - #ifdef __Pxy_PyFrame_Initialize_Offsets - __Pxy_PyFrame_Initialize_Offsets(); - #endif - __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("geoprocessing_core", __pyx_methods, 0, 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) - Py_INCREF(__pyx_b); - __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) - Py_INCREF(__pyx_cython_runtime); - 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__geoprocessing_core) { - if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name_2, __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.geoprocessing_core")) { - if (unlikely(PyDict_SetItemString(modules, "pygeoprocessing.geoprocessing_core", __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)) __PYX_ERR(0, 1, __pyx_L1_error) - if (unlikely(__Pyx_modinit_type_import_code() < 0)) __PYX_ERR(0, 1, __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/geoprocessing_core.pyx":4 - * # distutils: language=c++ - * # cython: language_level=3 - * import logging # <<<<<<<<<<<<<< - * import multiprocessing - * import os - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_logging, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_logging, __pyx_t_1) < 0) __PYX_ERR(0, 4, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":5 - * # cython: language_level=3 - * import logging - * import multiprocessing # <<<<<<<<<<<<<< - * import os - * import pickle - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_multiprocessing, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_multiprocessing, __pyx_t_1) < 0) __PYX_ERR(0, 5, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":6 - * import logging - * import multiprocessing - * import os # <<<<<<<<<<<<<< - * import pickle - * import shutil - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_os, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_1) < 0) __PYX_ERR(0, 6, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":7 - * import multiprocessing - * import os - * import pickle # <<<<<<<<<<<<<< - * import shutil - * import sys - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_pickle, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 7, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pickle, __pyx_t_1) < 0) __PYX_ERR(0, 7, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":8 - * import os - * import pickle - * import shutil # <<<<<<<<<<<<<< - * import sys - * import tempfile - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_shutil, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_shutil, __pyx_t_1) < 0) __PYX_ERR(0, 8, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":9 - * import pickle - * import shutil - * import sys # <<<<<<<<<<<<<< - * import tempfile - * import time - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_sys, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 9, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) __PYX_ERR(0, 9, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":10 - * import shutil - * import sys - * import tempfile # <<<<<<<<<<<<<< - * import time - * import traceback - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_tempfile, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 10, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_tempfile, __pyx_t_1) < 0) __PYX_ERR(0, 10, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":11 - * import sys - * import tempfile - * import time # <<<<<<<<<<<<<< - * import traceback - * import zlib - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_time, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 11, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_time, __pyx_t_1) < 0) __PYX_ERR(0, 11, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":12 - * import tempfile - * import time - * import traceback # <<<<<<<<<<<<<< - * import zlib - * - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_traceback, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 12, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_traceback, __pyx_t_1) < 0) __PYX_ERR(0, 12, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":13 - * import time - * import traceback - * import zlib # <<<<<<<<<<<<<< - * - * cimport cython - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_zlib, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 13, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_zlib, __pyx_t_1) < 0) __PYX_ERR(0, 13, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":26 - * from libc.stdio cimport fwrite - * from libcpp.vector cimport vector - * from osgeo import gdal # <<<<<<<<<<<<<< - * from osgeo import osr - * import 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, 0); 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/geoprocessing_core.pyx":27 - * from libcpp.vector cimport vector - * from osgeo import gdal - * from osgeo import osr # <<<<<<<<<<<<<< - * import numpy - * import pygeoprocessing - */ - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 27, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_n_s_osr); - __Pyx_GIVEREF(__pyx_n_s_osr); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_osr); - __pyx_t_1 = __Pyx_Import(__pyx_n_s_osgeo, __pyx_t_2, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 27, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_osr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 27, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_osr, __pyx_t_2) < 0) __PYX_ERR(0, 27, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":28 - * from osgeo import gdal - * from osgeo import osr - * import numpy # <<<<<<<<<<<<<< - * import pygeoprocessing - * - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 28, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_numpy, __pyx_t_1) < 0) __PYX_ERR(0, 28, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":29 - * from osgeo import osr - * import numpy - * import pygeoprocessing # <<<<<<<<<<<<<< - * - * DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS = ('GTIFF', ( - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_pygeoprocessing, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 29, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pygeoprocessing, __pyx_t_1) < 0) __PYX_ERR(0, 29, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":31 - * import pygeoprocessing - * - * DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS = ('GTIFF', ( # <<<<<<<<<<<<<< - * 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', - * 'BLOCKXSIZE=256', 'BLOCKYSIZE=256')) - */ - if (PyDict_SetItem(__pyx_d, __pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT, __pyx_tuple__24) < 0) __PYX_ERR(0, 31, __pyx_L1_error) - - /* "pygeoprocessing/geoprocessing_core.pyx":42 - * # axis order, which will use Lon,Lat order for Geographic CRS, but otherwise - * # leaves Projected CRS alone - * DEFAULT_OSR_AXIS_MAPPING_STRATEGY = osr.OAMS_TRADITIONAL_GIS_ORDER # <<<<<<<<<<<<<< - * - * LOGGER = logging.getLogger('pygeoprocessing.geoprocessing_core') - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_osr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 42, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OAMS_TRADITIONAL_GIS_ORDER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 42, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_DEFAULT_OSR_AXIS_MAPPING_STRATEG, __pyx_t_2) < 0) __PYX_ERR(0, 42, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":44 - * DEFAULT_OSR_AXIS_MAPPING_STRATEGY = osr.OAMS_TRADITIONAL_GIS_ORDER - * - * LOGGER = logging.getLogger('pygeoprocessing.geoprocessing_core') # <<<<<<<<<<<<<< - * - * cdef float _NODATA = -1.0 - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_logging); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 44, __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, 44, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 44, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_LOGGER, __pyx_t_2) < 0) __PYX_ERR(0, 44, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":46 - * LOGGER = logging.getLogger('pygeoprocessing.geoprocessing_core') - * - * cdef float _NODATA = -1.0 # <<<<<<<<<<<<<< - * - * cdef extern from "FastFileIterator.h" nogil: - */ - __pyx_v_15pygeoprocessing_18geoprocessing_core__NODATA = -1.0; - - /* "pygeoprocessing/geoprocessing_core.pyx":71 - * @cython.wraparound(False) - * @cython.cdivision(True) - * def _distance_transform_edt( # <<<<<<<<<<<<<< - * region_raster_path, g_raster_path, float sample_d_x, - * float sample_d_y, target_distance_raster_path, - */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_18geoprocessing_core_1_distance_transform_edt, NULL, __pyx_n_s_pygeoprocessing_geoprocessing_co); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 71, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_distance_transform_edt, __pyx_t_2) < 0) __PYX_ERR(0, 71, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":289 - * def calculate_slope( - * base_elevation_raster_path_band, target_slope_path, - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): # <<<<<<<<<<<<<< - * """Create a percent slope raster from DEM raster. - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 289, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_k__3 = __pyx_t_2; - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":287 - * @cython.nonecheck(False) - * @cython.cdivision(True) - * def calculate_slope( # <<<<<<<<<<<<<< - * base_elevation_raster_path_band, target_slope_path, - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): - */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_18geoprocessing_core_3calculate_slope, NULL, __pyx_n_s_pygeoprocessing_geoprocessing_co); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 287, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_calculate_slope, __pyx_t_2) < 0) __PYX_ERR(0, 287, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":544 - * @cython.boundscheck(False) - * @cython.cdivision(True) - * def stats_worker(stats_work_queue, expected_blocks): # <<<<<<<<<<<<<< - * """Worker to calculate continuous min, max, mean and standard deviation. - * - */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_18geoprocessing_core_5stats_worker, NULL, __pyx_n_s_pygeoprocessing_geoprocessing_co); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 544, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_stats_worker, __pyx_t_2) < 0) __PYX_ERR(0, 544, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":626 - * - * - * def raster_band_percentile( # <<<<<<<<<<<<<< - * base_raster_path_band, working_sort_directory, percentile_list, - * heap_buffer_size=2**28, ffi_buffer_size=2**10): - */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_18geoprocessing_core_7raster_band_percentile, NULL, __pyx_n_s_pygeoprocessing_geoprocessing_co); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 626, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_raster_band_percentile, __pyx_t_2) < 0) __PYX_ERR(0, 626, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":673 - * - * - * def _raster_band_percentile_int( # <<<<<<<<<<<<<< - * base_raster_path_band, working_sort_directory, percentile_list, - * heap_buffer_size, ffi_buffer_size): - */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_18geoprocessing_core_9_raster_band_percentile_int, NULL, __pyx_n_s_pygeoprocessing_geoprocessing_co); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 673, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_raster_band_percentile_int, __pyx_t_2) < 0) __PYX_ERR(0, 673, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":819 - * - * - * def _raster_band_percentile_double( # <<<<<<<<<<<<<< - * base_raster_path_band, working_sort_directory, percentile_list, - * heap_buffer_size, ffi_buffer_size): - */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_18geoprocessing_core_11_raster_band_percentile_double, NULL, __pyx_n_s_pygeoprocessing_geoprocessing_co); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 819, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_raster_band_percentile_double, __pyx_t_2) < 0) __PYX_ERR(0, 819, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/geoprocessing_core.pyx":1 - * # coding=UTF-8 # <<<<<<<<<<<<<< - * # distutils: language=c++ - * # cython: language_level=3 - */ - __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "View.MemoryView":209 - * info.obj = self - * - * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)") # <<<<<<<<<<<<<< - * - * def __dealloc__(array self): - */ - __pyx_t_2 = __pyx_capsule_create(((void *)(&__pyx_array_getbuffer)), ((char *)"getbuffer(obj, view, flags)")); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 209, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem((PyObject *)__pyx_array_type->tp_dict, __pyx_n_s_pyx_getbuffer, __pyx_t_2) < 0) __PYX_ERR(2, 209, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - PyType_Modified(__pyx_array_type); - - /* "View.MemoryView":286 - * return self.name - * - * cdef generic = Enum("") # <<<<<<<<<<<<<< - * cdef strided = Enum("") # default - * cdef indirect = Enum("") - */ - __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 286, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_XGOTREF(generic); - __Pyx_DECREF_SET(generic, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - - /* "View.MemoryView":287 - * - * cdef generic = Enum("") - * cdef strided = Enum("") # default # <<<<<<<<<<<<<< - * cdef indirect = Enum("") - * - */ - __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 287, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_XGOTREF(strided); - __Pyx_DECREF_SET(strided, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - - /* "View.MemoryView":288 - * cdef generic = Enum("") - * cdef strided = Enum("") # default - * cdef indirect = Enum("") # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__41, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 288, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_XGOTREF(indirect); - __Pyx_DECREF_SET(indirect, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - - /* "View.MemoryView":291 - * - * - * cdef contiguous = Enum("") # <<<<<<<<<<<<<< - * cdef indirect_contiguous = Enum("") - * - */ - __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__42, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 291, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_XGOTREF(contiguous); - __Pyx_DECREF_SET(contiguous, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - - /* "View.MemoryView":292 - * - * cdef contiguous = Enum("") - * cdef indirect_contiguous = Enum("") # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__43, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 292, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_XGOTREF(indirect_contiguous); - __Pyx_DECREF_SET(indirect_contiguous, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - - /* "View.MemoryView":316 - * - * DEF THREAD_LOCKS_PREALLOCATED = 8 - * cdef int __pyx_memoryview_thread_locks_used = 0 # <<<<<<<<<<<<<< - * cdef PyThread_type_lock[THREAD_LOCKS_PREALLOCATED] __pyx_memoryview_thread_locks = [ - * PyThread_allocate_lock(), - */ - __pyx_memoryview_thread_locks_used = 0; - - /* "View.MemoryView":317 - * DEF THREAD_LOCKS_PREALLOCATED = 8 - * cdef int __pyx_memoryview_thread_locks_used = 0 - * cdef PyThread_type_lock[THREAD_LOCKS_PREALLOCATED] __pyx_memoryview_thread_locks = [ # <<<<<<<<<<<<<< - * PyThread_allocate_lock(), - * PyThread_allocate_lock(), - */ - __pyx_t_3[0] = PyThread_allocate_lock(); - __pyx_t_3[1] = PyThread_allocate_lock(); - __pyx_t_3[2] = PyThread_allocate_lock(); - __pyx_t_3[3] = PyThread_allocate_lock(); - __pyx_t_3[4] = PyThread_allocate_lock(); - __pyx_t_3[5] = PyThread_allocate_lock(); - __pyx_t_3[6] = PyThread_allocate_lock(); - __pyx_t_3[7] = PyThread_allocate_lock(); - memcpy(&(__pyx_memoryview_thread_locks[0]), __pyx_t_3, sizeof(__pyx_memoryview_thread_locks[0]) * (8)); - - /* "View.MemoryView":549 - * info.obj = self - * - * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_2 = __pyx_capsule_create(((void *)(&__pyx_memoryview_getbuffer)), ((char *)"getbuffer(obj, view, flags)")); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 549, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem((PyObject *)__pyx_memoryview_type->tp_dict, __pyx_n_s_pyx_getbuffer, __pyx_t_2) < 0) __PYX_ERR(2, 549, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - PyType_Modified(__pyx_memoryview_type); - - /* "View.MemoryView":995 - * return self.from_object - * - * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_2 = __pyx_capsule_create(((void *)(&__pyx_memoryview_getbuffer)), ((char *)"getbuffer(obj, view, flags)")); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 995, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem((PyObject *)__pyx_memoryviewslice_type->tp_dict, __pyx_n_s_pyx_getbuffer, __pyx_t_2) < 0) __PYX_ERR(2, 995, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - PyType_Modified(__pyx_memoryviewslice_type); - - /* "(tree fragment)":1 - * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< - * cdef object __pyx_PickleError - * cdef object __pyx_result - */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15View_dot_MemoryView_1__pyx_unpickle_Enum, NULL, __pyx_n_s_View_MemoryView); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_Enum, __pyx_t_2) < 0) __PYX_ERR(2, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "(tree fragment)":11 - * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) - * return __pyx_result - * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< - * __pyx_result.name = __pyx_state[0] - * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): - */ - - /*--- Wrapped vars code ---*/ - - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - if (__pyx_m) { - if (__pyx_d) { - __Pyx_AddTraceback("init pygeoprocessing.geoprocessing_core", __pyx_clineno, __pyx_lineno, __pyx_filename); - } - Py_CLEAR(__pyx_m); - } else if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_ImportError, "init pygeoprocessing.geoprocessing_core"); - } - __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(modname); - if (!m) goto end; - p = PyObject_GetAttrString(m, "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_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 - (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(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 - (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(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; -} - -/* PyDictVersioning */ -#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS -static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { - PyObject *dict = Py_TYPE(obj)->tp_dict; - return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0; -} -static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { - PyObject **dictptr = NULL; - Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; - if (offset) { -#if CYTHON_COMPILING_IN_CPYTHON - dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); -#else - dictptr = _PyObject_GetDictPtr(obj); -#endif - } - return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; -} -static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { - PyObject *dict = Py_TYPE(obj)->tp_dict; - if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict))) - return 0; - return obj_dict_version == __Pyx_get_object_dict_version(obj); -} -#endif - -/* GetModuleGlobalName */ -#if CYTHON_USE_DICT_VERSIONS -static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value) -#else -static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name) -#endif -{ - 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); - __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) - if (likely(result)) { - return __Pyx_NewRef(result); - } else if (unlikely(PyErr_Occurred())) { - return NULL; - } -#else - result = PyDict_GetItem(__pyx_d, name); - __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) - if (likely(result)) { - return __Pyx_NewRef(result); - } -#endif -#else - result = PyObject_GetItem(__pyx_d, name); - __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) - if (likely(result)) { - return __Pyx_NewRef(result); - } - PyErr_Clear(); -#endif - return __Pyx_GetBuiltinName(name); -} - -/* PyFunctionFastCall */ -#if CYTHON_FAST_PYCALL -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 = __Pyx_PyFrame_GetLocalsplus(f); - 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, Py_ssize_t 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, (int)nargs, - k, (int)nk, - d, (int)nd, kwdefs, closure); -#else - result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL, - args, (int)nargs, - k, (int)nk, - d, (int)nd, closure); -#endif - Py_XDECREF(kwtuple); -done: - Py_LeaveRecursiveCall(); - return result; -} -#endif -#endif - -/* 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 | METH_STACKLESS))); - 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)(void*)meth)) (self, args, nargs, NULL); - } else { - return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs); - } -} -#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 - -/* PyObjectCall2Args */ -static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) { - PyObject *args, *result = NULL; - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(function)) { - PyObject *args[2] = {arg1, arg2}; - return __Pyx_PyFunction_FastCall(function, args, 2); - } - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(function)) { - PyObject *args[2] = {arg1, arg2}; - return __Pyx_PyCFunction_FastCall(function, args, 2); - } - #endif - args = PyTuple_New(2); - if (unlikely(!args)) goto done; - Py_INCREF(arg1); - PyTuple_SET_ITEM(args, 0, arg1); - Py_INCREF(arg2); - PyTuple_SET_ITEM(args, 1, arg2); - Py_INCREF(function); - result = __Pyx_PyObject_Call(function, args, NULL); - Py_DECREF(args); - Py_DECREF(function); -done: - return result; -} - -/* 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 (__Pyx_PyFastCFunction_Check(func)) { - 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 - -/* 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_CyFunction_Check(func))) -#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 - -/* 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()) { - if (unlikely(PyTuple_Check(key))) { - PyObject* args = PyTuple_Pack(1, key); - if (likely(args)) { - PyErr_SetObject(PyExc_KeyError, args); - Py_DECREF(args); - } - } else { - PyErr_SetObject(PyExc_KeyError, key); - } - } - return NULL; - } - Py_INCREF(value); - return value; -} -#endif - -/* 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(__Pyx_is_valid_index(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(__Pyx_is_valid_index(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(__Pyx_is_valid_index(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(__Pyx_is_valid_index(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)); -} - -/* 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 '?': return "'bool'"; - 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 '?': 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 '?': 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, 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; - ndim = ctx->head->field->type->ndim; - 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 '?': 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->is_valid_array)) { - 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((size_t)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; -} - -/* BufferFallbackError */ - static void __Pyx_RaiseBufferFallbackError(void) { - PyErr_SetString(PyExc_ValueError, - "Buffer acquisition failed on assignment; and then reacquiring the old buffer failed too!"); -} - -/* PyIntCompare */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED long 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))) { - int unequal; - unsigned long uintval; - Py_ssize_t size = Py_SIZE(op1); - const digit* digits = ((PyLongObject*)op1)->ob_digit; - if (intval == 0) { - if (size == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE; - } else if (intval < 0) { - if (size >= 0) - Py_RETURN_FALSE; - intval = -intval; - size = -size; - } else { - if (size <= 0) - Py_RETURN_FALSE; - } - uintval = (unsigned long) intval; -#if PyLong_SHIFT * 4 < SIZEOF_LONG*8 - if (uintval >> (PyLong_SHIFT * 4)) { - unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) - | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); - } else -#endif -#if PyLong_SHIFT * 3 < SIZEOF_LONG*8 - if (uintval >> (PyLong_SHIFT * 3)) { - unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) - | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); - } else -#endif -#if PyLong_SHIFT * 2 < SIZEOF_LONG*8 - if (uintval >> (PyLong_SHIFT * 2)) { - unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) - | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); - } else -#endif -#if PyLong_SHIFT * 1 < SIZEOF_LONG*8 - if (uintval >> (PyLong_SHIFT * 1)) { - unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) - | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); - } else -#endif - unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK)); - if (unequal == 0) 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)); -} - -/* 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 - -/* 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 - -/* 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; -} - -/* PyIntBinop */ - #if !CYTHON_COMPILING_IN_PYPY -static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) { - (void)inplace; - (void)zerodivision_check; - #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, int inplace, int zerodivision_check) { - (void)inplace; - (void)zerodivision_check; - #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 - -/* PyObjectGetMethod */ - static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) { - PyObject *attr; -#if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP - PyTypeObject *tp = Py_TYPE(obj); - PyObject *descr; - descrgetfunc f = NULL; - PyObject **dictptr, *dict; - int meth_found = 0; - assert (*method == NULL); - if (unlikely(tp->tp_getattro != PyObject_GenericGetAttr)) { - attr = __Pyx_PyObject_GetAttrStr(obj, name); - goto try_unpack; - } - if (unlikely(tp->tp_dict == NULL) && unlikely(PyType_Ready(tp) < 0)) { - return 0; - } - descr = _PyType_Lookup(tp, name); - if (likely(descr != NULL)) { - Py_INCREF(descr); -#if PY_MAJOR_VERSION >= 3 - #ifdef __Pyx_CyFunction_USED - if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type) || __Pyx_CyFunction_Check(descr))) - #else - if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type))) - #endif -#else - #ifdef __Pyx_CyFunction_USED - if (likely(PyFunction_Check(descr) || __Pyx_CyFunction_Check(descr))) - #else - if (likely(PyFunction_Check(descr))) - #endif -#endif - { - meth_found = 1; - } else { - f = Py_TYPE(descr)->tp_descr_get; - if (f != NULL && PyDescr_IsData(descr)) { - attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); - Py_DECREF(descr); - goto try_unpack; - } - } - } - dictptr = _PyObject_GetDictPtr(obj); - if (dictptr != NULL && (dict = *dictptr) != NULL) { - Py_INCREF(dict); - attr = __Pyx_PyDict_GetItemStr(dict, name); - if (attr != NULL) { - Py_INCREF(attr); - Py_DECREF(dict); - Py_XDECREF(descr); - goto try_unpack; - } - Py_DECREF(dict); - } - if (meth_found) { - *method = descr; - return 1; - } - if (f != NULL) { - attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); - Py_DECREF(descr); - goto try_unpack; - } - if (descr != NULL) { - *method = descr; - return 0; - } - PyErr_Format(PyExc_AttributeError, -#if PY_MAJOR_VERSION >= 3 - "'%.50s' object has no attribute '%U'", - tp->tp_name, name); -#else - "'%.50s' object has no attribute '%.400s'", - tp->tp_name, PyString_AS_STRING(name)); -#endif - return 0; -#else - attr = __Pyx_PyObject_GetAttrStr(obj, name); - goto try_unpack; -#endif -try_unpack: -#if CYTHON_UNPACK_METHODS - if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) { - PyObject *function = PyMethod_GET_FUNCTION(attr); - Py_INCREF(function); - Py_DECREF(attr); - *method = function; - return 1; - } -#endif - *method = attr; - return 0; -} - -/* PyObjectCallMethod0 */ - static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) { - PyObject *method = NULL, *result = NULL; - int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); - if (likely(is_method)) { - result = __Pyx_PyObject_CallOneArg(method, obj); - Py_DECREF(method); - return result; - } - if (unlikely(!method)) goto bad; - result = __Pyx_PyObject_CallNoArg(method); - Py_DECREF(method); -bad: - return result; -} - -/* RaiseNoneIterError */ - static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); -} - -/* UnpackTupleError */ - static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) { - if (t == Py_None) { - __Pyx_RaiseNoneNotIterableError(); - } else if (PyTuple_GET_SIZE(t) < index) { - __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(t)); - } else { - __Pyx_RaiseTooManyValuesError(index); - } -} - -/* UnpackTuple2 */ - static CYTHON_INLINE int __Pyx_unpack_tuple2_exact( - PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2, int decref_tuple) { - PyObject *value1 = NULL, *value2 = NULL; -#if CYTHON_COMPILING_IN_PYPY - value1 = PySequence_ITEM(tuple, 0); if (unlikely(!value1)) goto bad; - value2 = PySequence_ITEM(tuple, 1); if (unlikely(!value2)) goto bad; -#else - value1 = PyTuple_GET_ITEM(tuple, 0); Py_INCREF(value1); - value2 = PyTuple_GET_ITEM(tuple, 1); Py_INCREF(value2); -#endif - if (decref_tuple) { - Py_DECREF(tuple); - } - *pvalue1 = value1; - *pvalue2 = value2; - return 0; -#if CYTHON_COMPILING_IN_PYPY -bad: - Py_XDECREF(value1); - Py_XDECREF(value2); - if (decref_tuple) { Py_XDECREF(tuple); } - return -1; -#endif -} -static int __Pyx_unpack_tuple2_generic(PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2, - int has_known_size, int decref_tuple) { - Py_ssize_t index; - PyObject *value1 = NULL, *value2 = NULL, *iter = NULL; - iternextfunc iternext; - iter = PyObject_GetIter(tuple); - if (unlikely(!iter)) goto bad; - if (decref_tuple) { Py_DECREF(tuple); tuple = NULL; } - iternext = Py_TYPE(iter)->tp_iternext; - value1 = iternext(iter); if (unlikely(!value1)) { index = 0; goto unpacking_failed; } - value2 = iternext(iter); if (unlikely(!value2)) { index = 1; goto unpacking_failed; } - if (!has_known_size && unlikely(__Pyx_IternextUnpackEndCheck(iternext(iter), 2))) goto bad; - Py_DECREF(iter); - *pvalue1 = value1; - *pvalue2 = value2; - return 0; -unpacking_failed: - if (!has_known_size && __Pyx_IterFinish() == 0) - __Pyx_RaiseNeedMoreValuesError(index); -bad: - Py_XDECREF(iter); - Py_XDECREF(value1); - Py_XDECREF(value2); - if (decref_tuple) { Py_XDECREF(tuple); } - return -1; -} - -/* dict_iter */ - static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_dict, PyObject* method_name, - Py_ssize_t* p_orig_length, int* p_source_is_dict) { - is_dict = is_dict || likely(PyDict_CheckExact(iterable)); - *p_source_is_dict = is_dict; - if (is_dict) { -#if !CYTHON_COMPILING_IN_PYPY - *p_orig_length = PyDict_Size(iterable); - Py_INCREF(iterable); - return iterable; -#elif PY_MAJOR_VERSION >= 3 - static PyObject *py_items = NULL, *py_keys = NULL, *py_values = NULL; - PyObject **pp = NULL; - if (method_name) { - const char *name = PyUnicode_AsUTF8(method_name); - if (strcmp(name, "iteritems") == 0) pp = &py_items; - else if (strcmp(name, "iterkeys") == 0) pp = &py_keys; - else if (strcmp(name, "itervalues") == 0) pp = &py_values; - if (pp) { - if (!*pp) { - *pp = PyUnicode_FromString(name + 4); - if (!*pp) - return NULL; - } - method_name = *pp; - } - } -#endif - } - *p_orig_length = 0; - if (method_name) { - PyObject* iter; - iterable = __Pyx_PyObject_CallMethod0(iterable, method_name); - if (!iterable) - return NULL; -#if !CYTHON_COMPILING_IN_PYPY - if (PyTuple_CheckExact(iterable) || PyList_CheckExact(iterable)) - return iterable; -#endif - iter = PyObject_GetIter(iterable); - Py_DECREF(iterable); - return iter; - } - return PyObject_GetIter(iterable); -} -static CYTHON_INLINE int __Pyx_dict_iter_next( - PyObject* iter_obj, CYTHON_NCP_UNUSED Py_ssize_t orig_length, CYTHON_NCP_UNUSED Py_ssize_t* ppos, - PyObject** pkey, PyObject** pvalue, PyObject** pitem, int source_is_dict) { - PyObject* next_item; -#if !CYTHON_COMPILING_IN_PYPY - if (source_is_dict) { - PyObject *key, *value; - if (unlikely(orig_length != PyDict_Size(iter_obj))) { - PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration"); - return -1; - } - if (unlikely(!PyDict_Next(iter_obj, ppos, &key, &value))) { - return 0; - } - if (pitem) { - PyObject* tuple = PyTuple_New(2); - if (unlikely(!tuple)) { - return -1; - } - Py_INCREF(key); - Py_INCREF(value); - PyTuple_SET_ITEM(tuple, 0, key); - PyTuple_SET_ITEM(tuple, 1, value); - *pitem = tuple; - } else { - if (pkey) { - Py_INCREF(key); - *pkey = key; - } - if (pvalue) { - Py_INCREF(value); - *pvalue = value; - } - } - return 1; - } else if (PyTuple_CheckExact(iter_obj)) { - Py_ssize_t pos = *ppos; - if (unlikely(pos >= PyTuple_GET_SIZE(iter_obj))) return 0; - *ppos = pos + 1; - next_item = PyTuple_GET_ITEM(iter_obj, pos); - Py_INCREF(next_item); - } else if (PyList_CheckExact(iter_obj)) { - Py_ssize_t pos = *ppos; - if (unlikely(pos >= PyList_GET_SIZE(iter_obj))) return 0; - *ppos = pos + 1; - next_item = PyList_GET_ITEM(iter_obj, pos); - Py_INCREF(next_item); - } else -#endif - { - next_item = PyIter_Next(iter_obj); - if (unlikely(!next_item)) { - return __Pyx_IterFinish(); - } - } - if (pitem) { - *pitem = next_item; - } else if (pkey && pvalue) { - if (__Pyx_unpack_tuple2(next_item, pkey, pvalue, source_is_dict, source_is_dict, 1)) - return -1; - } else if (pkey) { - *pkey = next_item; - } else { - *pvalue = next_item; - } - return 1; -} - -/* MergeKeywords */ - static int __Pyx_MergeKeywords(PyObject *kwdict, PyObject *source_mapping) { - PyObject *iter, *key = NULL, *value = NULL; - int source_is_dict, result; - Py_ssize_t orig_length, ppos = 0; - iter = __Pyx_dict_iterator(source_mapping, 0, __pyx_n_s_items, &orig_length, &source_is_dict); - if (unlikely(!iter)) { - PyObject *args; - if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad; - PyErr_Clear(); - args = PyTuple_Pack(1, source_mapping); - if (likely(args)) { - PyObject *fallback = PyObject_Call((PyObject*)&PyDict_Type, args, NULL); - Py_DECREF(args); - if (likely(fallback)) { - iter = __Pyx_dict_iterator(fallback, 1, __pyx_n_s_items, &orig_length, &source_is_dict); - Py_DECREF(fallback); - } - } - if (unlikely(!iter)) goto bad; - } - while (1) { - result = __Pyx_dict_iter_next(iter, orig_length, &ppos, &key, &value, NULL, source_is_dict); - if (unlikely(result < 0)) goto bad; - if (!result) break; - if (unlikely(PyDict_Contains(kwdict, key))) { - __Pyx_RaiseDoubleKeywordsError("function", key); - result = -1; - } else { - result = PyDict_SetItem(kwdict, key, value); - } - Py_DECREF(key); - Py_DECREF(value); - if (unlikely(result < 0)) goto bad; - } - Py_XDECREF(iter); - return 0; -bad: - Py_XDECREF(iter); - return -1; -} - -/* GetTopmostException */ - #if CYTHON_USE_EXC_INFO_STACK -static _PyErr_StackItem * -__Pyx_PyErr_GetTopmostException(PyThreadState *tstate) -{ - _PyErr_StackItem *exc_info = tstate->exc_info; - while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) && - exc_info->previous_item != NULL) - { - exc_info = exc_info->previous_item; - } - return exc_info; -} -#endif - -/* SaveResetException */ - #if CYTHON_FAST_THREAD_STATE -static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { - #if CYTHON_USE_EXC_INFO_STACK - _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate); - *type = exc_info->exc_type; - *value = exc_info->exc_value; - *tb = exc_info->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 CYTHON_USE_EXC_INFO_STACK - _PyErr_StackItem *exc_info = tstate->exc_info; - tmp_type = exc_info->exc_type; - tmp_value = exc_info->exc_value; - tmp_tb = exc_info->exc_traceback; - exc_info->exc_type = type; - exc_info->exc_value = value; - exc_info->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; icurexc_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 - -/* 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 CYTHON_USE_EXC_INFO_STACK - { - _PyErr_StackItem *exc_info = tstate->exc_info; - tmp_type = exc_info->exc_type; - tmp_value = exc_info->exc_value; - tmp_tb = exc_info->exc_traceback; - exc_info->exc_type = local_type; - exc_info->exc_value = local_value; - exc_info->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; -} - -/* SwapException */ - #if CYTHON_FAST_THREAD_STATE -static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { - PyObject *tmp_type, *tmp_value, *tmp_tb; - #if CYTHON_USE_EXC_INFO_STACK - _PyErr_StackItem *exc_info = tstate->exc_info; - tmp_type = exc_info->exc_type; - tmp_value = exc_info->exc_value; - tmp_tb = exc_info->exc_traceback; - exc_info->exc_type = *type; - exc_info->exc_value = *value; - exc_info->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 - *type = tmp_type; - *value = tmp_value; - *tb = tmp_tb; -} -#else -static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) { - PyObject *tmp_type, *tmp_value, *tmp_tb; - PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb); - PyErr_SetExcInfo(*type, *value, *tb); - *type = tmp_type; - *value = tmp_value; - *tb = tmp_tb; -} -#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 - -/* PyObjectFormat */ - #if CYTHON_USE_UNICODE_WRITER -static PyObject* __Pyx_PyObject_Format(PyObject* obj, PyObject* format_spec) { - int ret; - _PyUnicodeWriter writer; - if (likely(PyFloat_CheckExact(obj))) { -#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x03040000 - _PyUnicodeWriter_Init(&writer, 0); -#else - _PyUnicodeWriter_Init(&writer); -#endif - ret = _PyFloat_FormatAdvancedWriter( - &writer, - obj, - format_spec, 0, PyUnicode_GET_LENGTH(format_spec)); - } else if (likely(PyLong_CheckExact(obj))) { -#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x03040000 - _PyUnicodeWriter_Init(&writer, 0); -#else - _PyUnicodeWriter_Init(&writer); -#endif - ret = _PyLong_FormatAdvancedWriter( - &writer, - obj, - format_spec, 0, PyUnicode_GET_LENGTH(format_spec)); - } else { - return PyObject_Format(obj, format_spec); - } - if (unlikely(ret == -1)) { - _PyUnicodeWriter_Dealloc(&writer); - return NULL; - } - return _PyUnicodeWriter_Finish(&writer); -} -#endif - -/* CIntToDigits */ - static const char DIGIT_PAIRS_10[2*10*10+1] = { - "00010203040506070809" - "10111213141516171819" - "20212223242526272829" - "30313233343536373839" - "40414243444546474849" - "50515253545556575859" - "60616263646566676869" - "70717273747576777879" - "80818283848586878889" - "90919293949596979899" -}; -static const char DIGIT_PAIRS_8[2*8*8+1] = { - "0001020304050607" - "1011121314151617" - "2021222324252627" - "3031323334353637" - "4041424344454647" - "5051525354555657" - "6061626364656667" - "7071727374757677" -}; -static const char DIGITS_HEX[2*16+1] = { - "0123456789abcdef" - "0123456789ABCDEF" -}; - -/* BuildPyUnicode */ - static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, char* chars, int clength, - int prepend_sign, char padding_char) { - PyObject *uval; - Py_ssize_t uoffset = ulength - clength; -#if CYTHON_USE_UNICODE_INTERNALS - Py_ssize_t i; -#if CYTHON_PEP393_ENABLED - void *udata; - uval = PyUnicode_New(ulength, 127); - if (unlikely(!uval)) return NULL; - udata = PyUnicode_DATA(uval); -#else - Py_UNICODE *udata; - uval = PyUnicode_FromUnicode(NULL, ulength); - if (unlikely(!uval)) return NULL; - udata = PyUnicode_AS_UNICODE(uval); -#endif - if (uoffset > 0) { - i = 0; - if (prepend_sign) { - __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, 0, '-'); - i++; - } - for (; i < uoffset; i++) { - __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, i, padding_char); - } - } - for (i=0; i < clength; i++) { - __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, uoffset+i, chars[i]); - } -#else - { - PyObject *sign = NULL, *padding = NULL; - uval = NULL; - if (uoffset > 0) { - prepend_sign = !!prepend_sign; - if (uoffset > prepend_sign) { - padding = PyUnicode_FromOrdinal(padding_char); - if (likely(padding) && uoffset > prepend_sign + 1) { - PyObject *tmp; - PyObject *repeat = PyInt_FromSize_t(uoffset - prepend_sign); - if (unlikely(!repeat)) goto done_or_error; - tmp = PyNumber_Multiply(padding, repeat); - Py_DECREF(repeat); - Py_DECREF(padding); - padding = tmp; - } - if (unlikely(!padding)) goto done_or_error; - } - if (prepend_sign) { - sign = PyUnicode_FromOrdinal('-'); - if (unlikely(!sign)) goto done_or_error; - } - } - uval = PyUnicode_DecodeASCII(chars, clength, NULL); - if (likely(uval) && padding) { - PyObject *tmp = PyNumber_Add(padding, uval); - Py_DECREF(uval); - uval = tmp; - } - if (likely(uval) && sign) { - PyObject *tmp = PyNumber_Add(sign, uval); - Py_DECREF(uval); - uval = tmp; - } -done_or_error: - Py_XDECREF(padding); - Py_XDECREF(sign); - } -#endif - return uval; -} - -/* CIntToPyUnicode */ - #ifdef _MSC_VER - #ifndef _MSC_STDINT_H_ - #if _MSC_VER < 1300 - typedef unsigned short uint16_t; - #else - typedef unsigned __int16 uint16_t; - #endif - #endif -#else - #include -#endif -static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_PY_LONG_LONG(PY_LONG_LONG value, Py_ssize_t width, char padding_char, char format_char) { - char digits[sizeof(PY_LONG_LONG)*3+2]; - char *dpos, *end = digits + sizeof(PY_LONG_LONG)*3+2; - const char *hex_digits = DIGITS_HEX; - Py_ssize_t length, ulength; - int prepend_sign, last_one_off; - PY_LONG_LONG remaining; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const PY_LONG_LONG neg_one = (PY_LONG_LONG) -1, const_zero = (PY_LONG_LONG) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - const int is_unsigned = neg_one > const_zero; - if (format_char == 'X') { - hex_digits += 16; - format_char = 'x'; - } - remaining = value; - last_one_off = 0; - dpos = end; - do { - int digit_pos; - switch (format_char) { - case 'o': - digit_pos = abs((int)(remaining % (8*8))); - remaining = (PY_LONG_LONG) (remaining / (8*8)); - dpos -= 2; - *(uint16_t*)dpos = ((const uint16_t*)DIGIT_PAIRS_8)[digit_pos]; - last_one_off = (digit_pos < 8); - break; - case 'd': - digit_pos = abs((int)(remaining % (10*10))); - remaining = (PY_LONG_LONG) (remaining / (10*10)); - dpos -= 2; - *(uint16_t*)dpos = ((const uint16_t*)DIGIT_PAIRS_10)[digit_pos]; - last_one_off = (digit_pos < 10); - break; - case 'x': - *(--dpos) = hex_digits[abs((int)(remaining % 16))]; - remaining = (PY_LONG_LONG) (remaining / 16); - break; - default: - assert(0); - break; - } - } while (unlikely(remaining != 0)); - if (last_one_off) { - assert(*dpos == '0'); - dpos++; - } - length = end - dpos; - ulength = length; - prepend_sign = 0; - if (!is_unsigned && value <= neg_one) { - if (padding_char == ' ' || width <= length + 1) { - *(--dpos) = '-'; - ++length; - } else { - prepend_sign = 1; - } - ++ulength; - } - if (width > ulength) { - ulength = width; - } - if (ulength == 1) { - return PyUnicode_FromOrdinal(*dpos); - } - return __Pyx_PyUnicode_BuildFromAscii(ulength, dpos, (int) length, prepend_sign, padding_char); -} - -/* JoinPyUnicode */ - static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength, - CYTHON_UNUSED Py_UCS4 max_char) { -#if CYTHON_USE_UNICODE_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - PyObject *result_uval; - int result_ukind; - Py_ssize_t i, char_pos; - void *result_udata; -#if CYTHON_PEP393_ENABLED - result_uval = PyUnicode_New(result_ulength, max_char); - if (unlikely(!result_uval)) return NULL; - result_ukind = (max_char <= 255) ? PyUnicode_1BYTE_KIND : (max_char <= 65535) ? PyUnicode_2BYTE_KIND : PyUnicode_4BYTE_KIND; - result_udata = PyUnicode_DATA(result_uval); -#else - result_uval = PyUnicode_FromUnicode(NULL, result_ulength); - if (unlikely(!result_uval)) return NULL; - result_ukind = sizeof(Py_UNICODE); - result_udata = PyUnicode_AS_UNICODE(result_uval); -#endif - char_pos = 0; - for (i=0; i < value_count; i++) { - int ukind; - Py_ssize_t ulength; - void *udata; - PyObject *uval = PyTuple_GET_ITEM(value_tuple, i); - if (unlikely(__Pyx_PyUnicode_READY(uval))) - goto bad; - ulength = __Pyx_PyUnicode_GET_LENGTH(uval); - if (unlikely(!ulength)) - continue; - if (unlikely(char_pos + ulength < 0)) - goto overflow; - ukind = __Pyx_PyUnicode_KIND(uval); - udata = __Pyx_PyUnicode_DATA(uval); - if (!CYTHON_PEP393_ENABLED || ukind == result_ukind) { - memcpy((char *)result_udata + char_pos * result_ukind, udata, (size_t) (ulength * result_ukind)); - } else { - #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030300F0 || defined(_PyUnicode_FastCopyCharacters) - _PyUnicode_FastCopyCharacters(result_uval, char_pos, uval, 0, ulength); - #else - Py_ssize_t j; - for (j=0; j < ulength; j++) { - Py_UCS4 uchar = __Pyx_PyUnicode_READ(ukind, udata, j); - __Pyx_PyUnicode_WRITE(result_ukind, result_udata, char_pos+j, uchar); - } - #endif - } - char_pos += ulength; - } - return result_uval; -overflow: - PyErr_SetString(PyExc_OverflowError, "join() result is too long for a Python string"); -bad: - Py_DECREF(result_uval); - return NULL; -#else - result_ulength++; - value_count++; - return PyUnicode_Join(__pyx_empty_unicode, value_tuple); -#endif -} - -/* MemviewSliceInit */ - static int -__Pyx_init_memviewslice(struct __pyx_memoryview_obj *memview, - int ndim, - __Pyx_memviewslice *memviewslice, - int memview_is_new_reference) -{ - __Pyx_RefNannyDeclarations - int i, retval=-1; - Py_buffer *buf = &memview->view; - __Pyx_RefNannySetupContext("init_memviewslice", 0); - if (unlikely(memviewslice->memview || memviewslice->data)) { - PyErr_SetString(PyExc_ValueError, - "memviewslice is already initialized!"); - goto fail; - } - if (buf->strides) { - for (i = 0; i < ndim; i++) { - memviewslice->strides[i] = buf->strides[i]; - } - } else { - Py_ssize_t stride = buf->itemsize; - for (i = ndim - 1; i >= 0; i--) { - memviewslice->strides[i] = stride; - stride *= buf->shape[i]; - } - } - for (i = 0; i < ndim; i++) { - memviewslice->shape[i] = buf->shape[i]; - if (buf->suboffsets) { - memviewslice->suboffsets[i] = buf->suboffsets[i]; - } else { - memviewslice->suboffsets[i] = -1; - } - } - memviewslice->memview = memview; - memviewslice->data = (char *)buf->buf; - if (__pyx_add_acquisition_count(memview) == 0 && !memview_is_new_reference) { - Py_INCREF(memview); - } - retval = 0; - goto no_fail; -fail: - memviewslice->memview = 0; - memviewslice->data = 0; - retval = -1; -no_fail: - __Pyx_RefNannyFinishContext(); - return retval; -} -#ifndef Py_NO_RETURN -#define Py_NO_RETURN -#endif -static void __pyx_fatalerror(const char *fmt, ...) Py_NO_RETURN { - va_list vargs; - char msg[200]; -#ifdef HAVE_STDARG_PROTOTYPES - va_start(vargs, fmt); -#else - va_start(vargs); -#endif - vsnprintf(msg, 200, fmt, vargs); - va_end(vargs); - Py_FatalError(msg); -} -static CYTHON_INLINE int -__pyx_add_acquisition_count_locked(__pyx_atomic_int *acquisition_count, - PyThread_type_lock lock) -{ - int result; - PyThread_acquire_lock(lock, 1); - result = (*acquisition_count)++; - PyThread_release_lock(lock); - return result; -} -static CYTHON_INLINE int -__pyx_sub_acquisition_count_locked(__pyx_atomic_int *acquisition_count, - PyThread_type_lock lock) -{ - int result; - PyThread_acquire_lock(lock, 1); - result = (*acquisition_count)--; - PyThread_release_lock(lock); - return result; -} -static CYTHON_INLINE void -__Pyx_INC_MEMVIEW(__Pyx_memviewslice *memslice, int have_gil, int lineno) -{ - int first_time; - struct __pyx_memoryview_obj *memview = memslice->memview; - if (unlikely(!memview || (PyObject *) memview == Py_None)) - return; - if (unlikely(__pyx_get_slice_count(memview) < 0)) - __pyx_fatalerror("Acquisition count is %d (line %d)", - __pyx_get_slice_count(memview), lineno); - first_time = __pyx_add_acquisition_count(memview) == 0; - if (unlikely(first_time)) { - if (have_gil) { - Py_INCREF((PyObject *) memview); - } else { - PyGILState_STATE _gilstate = PyGILState_Ensure(); - Py_INCREF((PyObject *) memview); - PyGILState_Release(_gilstate); - } - } -} -static CYTHON_INLINE void __Pyx_XDEC_MEMVIEW(__Pyx_memviewslice *memslice, - int have_gil, int lineno) { - int last_time; - struct __pyx_memoryview_obj *memview = memslice->memview; - if (unlikely(!memview || (PyObject *) memview == Py_None)) { - memslice->memview = NULL; - return; - } - if (unlikely(__pyx_get_slice_count(memview) <= 0)) - __pyx_fatalerror("Acquisition count is %d (line %d)", - __pyx_get_slice_count(memview), lineno); - last_time = __pyx_sub_acquisition_count(memview) == 1; - memslice->data = NULL; - if (unlikely(last_time)) { - if (have_gil) { - Py_CLEAR(memslice->memview); - } else { - PyGILState_STATE _gilstate = PyGILState_Ensure(); - Py_CLEAR(memslice->memview); - PyGILState_Release(_gilstate); - } - } else { - memslice->memview = NULL; - } -} - -/* BufferIndexError */ - static void __Pyx_RaiseBufferIndexError(int axis) { - PyErr_Format(PyExc_IndexError, - "Out of bounds on buffer access (axis %d)", axis); -} - -/* ArgTypeTest */ - static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact) -{ - if (unlikely(!type)) { - PyErr_SetString(PyExc_SystemError, "Missing type object"); - return 0; - } - else if (exact) { - #if PY_MAJOR_VERSION == 2 - if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1; - #endif - } - else { - if (likely(__Pyx_TypeCheck(obj, type))) return 1; - } - PyErr_Format(PyExc_TypeError, - "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)", - name, type->tp_name, Py_TYPE(obj)->tp_name); - return 0; -} - -/* BytesEquals */ - static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) { -#if CYTHON_COMPILING_IN_PYPY - return PyObject_RichCompareBool(s1, s2, equals); -#else - if (s1 == s2) { - return (equals == Py_EQ); - } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) { - const char *ps1, *ps2; - Py_ssize_t length = PyBytes_GET_SIZE(s1); - if (length != PyBytes_GET_SIZE(s2)) - return (equals == Py_NE); - ps1 = PyBytes_AS_STRING(s1); - ps2 = PyBytes_AS_STRING(s2); - if (ps1[0] != ps2[0]) { - return (equals == Py_NE); - } else if (length == 1) { - return (equals == Py_EQ); - } else { - int result; -#if CYTHON_USE_UNICODE_INTERNALS - Py_hash_t hash1, hash2; - hash1 = ((PyBytesObject*)s1)->ob_shash; - hash2 = ((PyBytesObject*)s2)->ob_shash; - if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { - return (equals == Py_NE); - } -#endif - result = memcmp(ps1, ps2, (size_t)length); - return (equals == Py_EQ) ? (result == 0) : (result != 0); - } - } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) { - return (equals == Py_NE); - } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) { - return (equals == Py_NE); - } else { - int result; - PyObject* py_result = PyObject_RichCompare(s1, s2, equals); - if (!py_result) - return -1; - result = __Pyx_PyObject_IsTrue(py_result); - Py_DECREF(py_result); - return result; - } -#endif -} - -/* UnicodeEquals */ - static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) { -#if CYTHON_COMPILING_IN_PYPY - return PyObject_RichCompareBool(s1, s2, equals); -#else -#if PY_MAJOR_VERSION < 3 - PyObject* owned_ref = NULL; -#endif - int s1_is_unicode, s2_is_unicode; - if (s1 == s2) { - goto return_eq; - } - s1_is_unicode = PyUnicode_CheckExact(s1); - s2_is_unicode = PyUnicode_CheckExact(s2); -#if PY_MAJOR_VERSION < 3 - if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) { - owned_ref = PyUnicode_FromObject(s2); - if (unlikely(!owned_ref)) - return -1; - s2 = owned_ref; - s2_is_unicode = 1; - } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) { - owned_ref = PyUnicode_FromObject(s1); - if (unlikely(!owned_ref)) - return -1; - s1 = owned_ref; - s1_is_unicode = 1; - } else if (((!s2_is_unicode) & (!s1_is_unicode))) { - return __Pyx_PyBytes_Equals(s1, s2, equals); - } -#endif - if (s1_is_unicode & s2_is_unicode) { - Py_ssize_t length; - int kind; - void *data1, *data2; - if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0)) - return -1; - length = __Pyx_PyUnicode_GET_LENGTH(s1); - if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) { - goto return_ne; - } -#if CYTHON_USE_UNICODE_INTERNALS - { - Py_hash_t hash1, hash2; - #if CYTHON_PEP393_ENABLED - hash1 = ((PyASCIIObject*)s1)->hash; - hash2 = ((PyASCIIObject*)s2)->hash; - #else - hash1 = ((PyUnicodeObject*)s1)->hash; - hash2 = ((PyUnicodeObject*)s2)->hash; - #endif - if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { - goto return_ne; - } - } -#endif - kind = __Pyx_PyUnicode_KIND(s1); - if (kind != __Pyx_PyUnicode_KIND(s2)) { - goto return_ne; - } - data1 = __Pyx_PyUnicode_DATA(s1); - data2 = __Pyx_PyUnicode_DATA(s2); - if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) { - goto return_ne; - } else if (length == 1) { - goto return_eq; - } else { - int result = memcmp(data1, data2, (size_t)(length * kind)); - #if PY_MAJOR_VERSION < 3 - Py_XDECREF(owned_ref); - #endif - return (equals == Py_EQ) ? (result == 0) : (result != 0); - } - } else if ((s1 == Py_None) & s2_is_unicode) { - goto return_ne; - } else if ((s2 == Py_None) & s1_is_unicode) { - goto return_ne; - } else { - int result; - PyObject* py_result = PyObject_RichCompare(s1, s2, equals); - #if PY_MAJOR_VERSION < 3 - Py_XDECREF(owned_ref); - #endif - if (!py_result) - return -1; - result = __Pyx_PyObject_IsTrue(py_result); - Py_DECREF(py_result); - return result; - } -return_eq: - #if PY_MAJOR_VERSION < 3 - Py_XDECREF(owned_ref); - #endif - return (equals == Py_EQ); -return_ne: - #if PY_MAJOR_VERSION < 3 - Py_XDECREF(owned_ref); - #endif - return (equals == Py_NE); -#endif -} - -/* None */ - static CYTHON_INLINE Py_ssize_t __Pyx_div_Py_ssize_t(Py_ssize_t a, Py_ssize_t b) { - Py_ssize_t q = a / b; - Py_ssize_t r = a - q*b; - q -= ((r != 0) & ((r ^ b) < 0)); - return q; -} - -/* GetAttr */ - static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) { -#if CYTHON_USE_TYPE_SLOTS -#if PY_MAJOR_VERSION >= 3 - if (likely(PyUnicode_Check(n))) -#else - if (likely(PyString_Check(n))) -#endif - return __Pyx_PyObject_GetAttrStr(o, n); -#endif - return PyObject_GetAttr(o, n); -} - -/* decode_c_string */ - static CYTHON_INLINE PyObject* __Pyx_decode_c_string( - const char* cstring, Py_ssize_t start, Py_ssize_t stop, - const char* encoding, const char* errors, - PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) { - Py_ssize_t length; - if (unlikely((start < 0) | (stop < 0))) { - size_t slen = strlen(cstring); - if (unlikely(slen > (size_t) PY_SSIZE_T_MAX)) { - PyErr_SetString(PyExc_OverflowError, - "c-string too long to convert to Python"); - return NULL; - } - length = (Py_ssize_t) slen; - if (start < 0) { - start += length; - if (start < 0) - start = 0; - } - if (stop < 0) - stop += length; - } - if (unlikely(stop <= start)) - return __Pyx_NewRef(__pyx_empty_unicode); - length = stop - start; - cstring += start; - if (decode_func) { - return decode_func(cstring, length, errors); - } else { - return PyUnicode_Decode(cstring, length, encoding, errors); - } -} - -/* GetAttr3 */ - static PyObject *__Pyx_GetAttr3Default(PyObject *d) { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) - return NULL; - __Pyx_PyErr_Clear(); - Py_INCREF(d); - return d; -} -static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject *d) { - PyObject *r = __Pyx_GetAttr(o, n); - return (likely(r)) ? r : __Pyx_GetAttr3Default(d); -} - -/* 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 ((1) && (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, (PyObject *)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; -} - -/* 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 int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { - Py_ssize_t i, n; - assert(PyExceptionClass_Check(exc_type)); - n = PyTuple_GET_SIZE(tuple); -#if PY_MAJOR_VERSION >= 3 - for (i=0; i= 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; -} - -/* PyObjectGetAttrStrNoError */ - static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) - __Pyx_PyErr_Clear(); -} -static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) { - PyObject *result; -#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1 - PyTypeObject* tp = Py_TYPE(obj); - if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) { - return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1); - } -#endif - result = __Pyx_PyObject_GetAttrStr(obj, attr_name); - if (unlikely(!result)) { - __Pyx_PyObject_GetAttrStr_ClearAttributeError(); - } - return result; -} - -/* 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_2); - 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 __PYX_GOOD; -#else - if (PyObject_HasAttr(type_obj, __pyx_n_s_getstate)) goto __PYX_GOOD; -#endif -#if CYTHON_USE_PYTYPE_LOOKUP - object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; -#else - object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; -#endif - reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto __PYX_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 __PYX_BAD; -#else - object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD; -#endif - reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto __PYX_BAD; - if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) { - reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_reduce_cython); - if (likely(reduce_cython)) { - ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; - ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; - } else if (reduce == object_reduce || PyErr_Occurred()) { - goto __PYX_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_GetAttrStrNoError(type_obj, __pyx_n_s_setstate_cython); - if (likely(setstate_cython)) { - ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; - ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; - } else if (!setstate || PyErr_Occurred()) { - goto __PYX_BAD; - } - } - PyType_Modified((PyTypeObject*)type_obj); - } - } - goto __PYX_GOOD; -__PYX_BAD: - if (!PyErr_Occurred()) - PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name); - ret = -1; -__PYX_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; -} - -/* TypeImport */ - #ifndef __PYX_HAVE_RT_ImportType -#define __PYX_HAVE_RT_ImportType -static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name, - size_t size, enum __Pyx_ImportType_CheckSize check_size) -{ - PyObject *result = 0; - char warning[200]; - Py_ssize_t basicsize; -#ifdef Py_LIMITED_API - PyObject *py_basicsize; -#endif - result = PyObject_GetAttrString(module, class_name); - 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 ((size_t)basicsize < size) { - PyErr_Format(PyExc_ValueError, - "%.200s.%.200s size changed, may indicate binary incompatibility. " - "Expected %zd from C header, got %zd from PyObject", - module_name, class_name, size, basicsize); - goto bad; - } - if (check_size == __Pyx_ImportType_CheckSize_Error && (size_t)basicsize != size) { - PyErr_Format(PyExc_ValueError, - "%.200s.%.200s size changed, may indicate binary incompatibility. " - "Expected %zd from C header, got %zd from PyObject", - module_name, class_name, size, basicsize); - goto bad; - } - else if (check_size == __Pyx_ImportType_CheckSize_Warn && (size_t)basicsize > size) { - PyOS_snprintf(warning, sizeof(warning), - "%s.%s size changed, may indicate binary incompatibility. " - "Expected %zd from C header, got %zd from PyObject", - module_name, class_name, size, basicsize); - if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad; - } - return (PyTypeObject *)result; -bad: - Py_XDECREF(result); - return NULL; -} -#endif - -/* CLineInTraceback */ - #ifndef CYTHON_CLINE_IN_TRACEBACK -static int __Pyx_CLineForTraceback(CYTHON_NCP_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)) { - __PYX_PY_DICT_LOOKUP_IF_MODIFIED( - use_cline, *cython_runtime_dict, - __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 (use_cline == Py_False || (use_cline != Py_True && 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_array_type)) return __pyx_array_getbuffer(obj, view, flags); - if (__Pyx_TypeCheck(obj, __pyx_memoryview_type)) return __pyx_memoryview_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)) {} - view->obj = NULL; - Py_DECREF(obj); -} -#endif - - - /* MemviewSliceIsContig */ - static int -__pyx_memviewslice_is_contig(const __Pyx_memviewslice mvs, char order, int ndim) -{ - int i, index, step, start; - Py_ssize_t itemsize = mvs.memview->view.itemsize; - if (order == 'F') { - step = 1; - start = 0; - } else { - step = -1; - start = ndim - 1; - } - for (i = 0; i < ndim; i++) { - index = start + step * i; - if (mvs.suboffsets[index] >= 0 || mvs.strides[index] != itemsize) - return 0; - itemsize *= mvs.shape[index]; - } - return 1; -} - -/* OverlappingSlices */ - static void -__pyx_get_array_memory_extents(__Pyx_memviewslice *slice, - void **out_start, void **out_end, - int ndim, size_t itemsize) -{ - char *start, *end; - int i; - start = end = slice->data; - for (i = 0; i < ndim; i++) { - Py_ssize_t stride = slice->strides[i]; - Py_ssize_t extent = slice->shape[i]; - if (extent == 0) { - *out_start = *out_end = start; - return; - } else { - if (stride > 0) - end += stride * (extent - 1); - else - start += stride * (extent - 1); - } - } - *out_start = start; - *out_end = end + itemsize; -} -static int -__pyx_slices_overlap(__Pyx_memviewslice *slice1, - __Pyx_memviewslice *slice2, - int ndim, size_t itemsize) -{ - void *start1, *end1, *start2, *end2; - __pyx_get_array_memory_extents(slice1, &start1, &end1, ndim, itemsize); - __pyx_get_array_memory_extents(slice2, &start2, &end2, ndim, itemsize); - return (start1 < end2) && (start2 < end1); -} - -/* Capsule */ - static CYTHON_INLINE PyObject * -__pyx_capsule_create(void *p, CYTHON_UNUSED const char *sig) -{ - PyObject *cobj; -#if PY_VERSION_HEX >= 0x02070000 - cobj = PyCapsule_New(p, sig, NULL); -#else - cobj = PyCObject_FromVoidPtr(p, NULL); -#endif - return cobj; -} - -/* 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;\ - } - -/* MemviewDtypeToObject */ - static CYTHON_INLINE PyObject *__pyx_memview_get_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t(const char *itemp) { - return (PyObject *) __Pyx_PyInt_From_PY_LONG_LONG(*(__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t *) itemp); -} -static CYTHON_INLINE int __pyx_memview_set_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t(const char *itemp, PyObject *obj) { - __pyx_t_15pygeoprocessing_18geoprocessing_core_int64t value = __Pyx_PyInt_As_PY_LONG_LONG(obj); - if ((value == (PY_LONG_LONG)-1) && PyErr_Occurred()) - return 0; - *(__pyx_t_15pygeoprocessing_18geoprocessing_core_int64t *) itemp = value; - return 1; -} - -/* MemviewDtypeToObject */ - static CYTHON_INLINE PyObject *__pyx_memview_get_double(const char *itemp) { - return (PyObject *) PyFloat_FromDouble(*(double *) itemp); -} -static CYTHON_INLINE int __pyx_memview_set_double(const char *itemp, PyObject *obj) { - double value = __pyx_PyFloat_AsDouble(obj); - if ((value == (double)-1) && PyErr_Occurred()) - return 0; - *(double *) itemp = value; - return 1; -} - -/* 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 = (float)(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 = (float)(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: - 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.0, -1.0); - } - } 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 = (double)(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 = (double)(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: - 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.0, -1.0); - } - } 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 - -/* MemviewSliceCopyTemplate */ - static __Pyx_memviewslice -__pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, - const char *mode, int ndim, - size_t sizeof_dtype, int contig_flag, - int dtype_is_object) -{ - __Pyx_RefNannyDeclarations - int i; - __Pyx_memviewslice new_mvs = { 0, 0, { 0 }, { 0 }, { 0 } }; - struct __pyx_memoryview_obj *from_memview = from_mvs->memview; - Py_buffer *buf = &from_memview->view; - PyObject *shape_tuple = NULL; - PyObject *temp_int = NULL; - struct __pyx_array_obj *array_obj = NULL; - struct __pyx_memoryview_obj *memview_obj = NULL; - __Pyx_RefNannySetupContext("__pyx_memoryview_copy_new_contig", 0); - for (i = 0; i < ndim; i++) { - if (unlikely(from_mvs->suboffsets[i] >= 0)) { - PyErr_Format(PyExc_ValueError, "Cannot copy memoryview slice with " - "indirect dimensions (axis %d)", i); - goto fail; - } - } - shape_tuple = PyTuple_New(ndim); - if (unlikely(!shape_tuple)) { - goto fail; - } - __Pyx_GOTREF(shape_tuple); - for(i = 0; i < ndim; i++) { - temp_int = PyInt_FromSsize_t(from_mvs->shape[i]); - if(unlikely(!temp_int)) { - goto fail; - } else { - PyTuple_SET_ITEM(shape_tuple, i, temp_int); - temp_int = NULL; - } - } - array_obj = __pyx_array_new(shape_tuple, sizeof_dtype, buf->format, (char *) mode, NULL); - if (unlikely(!array_obj)) { - goto fail; - } - __Pyx_GOTREF(array_obj); - memview_obj = (struct __pyx_memoryview_obj *) __pyx_memoryview_new( - (PyObject *) array_obj, contig_flag, - dtype_is_object, - from_mvs->memview->typeinfo); - if (unlikely(!memview_obj)) - goto fail; - if (unlikely(__Pyx_init_memviewslice(memview_obj, ndim, &new_mvs, 1) < 0)) - goto fail; - if (unlikely(__pyx_memoryview_copy_contents(*from_mvs, new_mvs, ndim, ndim, - dtype_is_object) < 0)) - goto fail; - goto no_fail; -fail: - __Pyx_XDECREF(new_mvs.memview); - new_mvs.memview = NULL; - new_mvs.data = NULL; -no_fail: - __Pyx_XDECREF(shape_tuple); - __Pyx_XDECREF(temp_int); - __Pyx_XDECREF(array_obj); - __Pyx_RefNannyFinishContext(); - return new_mvs; -} - -/* CIntFromPy */ - static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const int neg_one = (int) -1, const_zero = (int) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - 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; -} - -/* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const long neg_one = (long) -1, const_zero = (long) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - 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); - } -} - -/* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const int neg_one = (int) -1, const_zero = (int) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - 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); - } -} - -/* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_PY_LONG_LONG(PY_LONG_LONG value) { -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const PY_LONG_LONG neg_one = (PY_LONG_LONG) -1, const_zero = (PY_LONG_LONG) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - const int is_unsigned = neg_one > const_zero; - if (is_unsigned) { - if (sizeof(PY_LONG_LONG) < sizeof(long)) { - return PyInt_FromLong((long) value); - } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned long)) { - return PyLong_FromUnsignedLong((unsigned long) value); -#ifdef HAVE_LONG_LONG - } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) { - return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); -#endif - } - } else { - if (sizeof(PY_LONG_LONG) <= sizeof(long)) { - return PyInt_FromLong((long) value); -#ifdef HAVE_LONG_LONG - } else if (sizeof(PY_LONG_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(PY_LONG_LONG), - little, !is_unsigned); - } -} - -/* CIntFromPy */ - static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_As_PY_LONG_LONG(PyObject *x) { -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const PY_LONG_LONG neg_one = (PY_LONG_LONG) -1, const_zero = (PY_LONG_LONG) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - const int is_unsigned = neg_one > const_zero; -#if PY_MAJOR_VERSION < 3 - if (likely(PyInt_Check(x))) { - if (sizeof(PY_LONG_LONG) < sizeof(long)) { - __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long, PyInt_AS_LONG(x)) - } else { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - goto raise_neg_overflow; - } - return (PY_LONG_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 (PY_LONG_LONG) 0; - case 1: __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, digit, digits[0]) - case 2: - if (8 * sizeof(PY_LONG_LONG) > 1 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(PY_LONG_LONG) >= 2 * PyLong_SHIFT) { - return (PY_LONG_LONG) (((((PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0])); - } - } - break; - case 3: - if (8 * sizeof(PY_LONG_LONG) > 2 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(PY_LONG_LONG) >= 3 * PyLong_SHIFT) { - return (PY_LONG_LONG) (((((((PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0])); - } - } - break; - case 4: - if (8 * sizeof(PY_LONG_LONG) > 3 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(PY_LONG_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(PY_LONG_LONG) >= 4 * PyLong_SHIFT) { - return (PY_LONG_LONG) (((((((((PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_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 (PY_LONG_LONG) -1; - if (unlikely(result == 1)) - goto raise_neg_overflow; - } -#endif - if (sizeof(PY_LONG_LONG) <= sizeof(unsigned long)) { - __PYX_VERIFY_RETURN_INT_EXC(PY_LONG_LONG, unsigned long, PyLong_AsUnsignedLong(x)) -#ifdef HAVE_LONG_LONG - } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) { - __PYX_VERIFY_RETURN_INT_EXC(PY_LONG_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 (PY_LONG_LONG) 0; - case -1: __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, sdigit, (sdigit) (-(sdigit)digits[0])) - case 1: __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, digit, +digits[0]) - case -2: - if (8 * sizeof(PY_LONG_LONG) - 1 > 1 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { - return (PY_LONG_LONG) (((PY_LONG_LONG)-1)*(((((PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); - } - } - break; - case 2: - if (8 * sizeof(PY_LONG_LONG) > 1 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { - return (PY_LONG_LONG) ((((((PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); - } - } - break; - case -3: - if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { - return (PY_LONG_LONG) (((PY_LONG_LONG)-1)*(((((((PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); - } - } - break; - case 3: - if (8 * sizeof(PY_LONG_LONG) > 2 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { - return (PY_LONG_LONG) ((((((((PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); - } - } - break; - case -4: - if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(PY_LONG_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(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { - return (PY_LONG_LONG) (((PY_LONG_LONG)-1)*(((((((((PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); - } - } - break; - case 4: - if (8 * sizeof(PY_LONG_LONG) > 3 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(PY_LONG_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(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { - return (PY_LONG_LONG) ((((((((((PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); - } - } - break; - } -#endif - if (sizeof(PY_LONG_LONG) <= sizeof(long)) { - __PYX_VERIFY_RETURN_INT_EXC(PY_LONG_LONG, long, PyLong_AsLong(x)) -#ifdef HAVE_LONG_LONG - } else if (sizeof(PY_LONG_LONG) <= sizeof(PY_LONG_LONG)) { - __PYX_VERIFY_RETURN_INT_EXC(PY_LONG_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 - PY_LONG_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 (PY_LONG_LONG) -1; - } - } else { - PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); - if (!tmp) return (PY_LONG_LONG) -1; - val = __Pyx_PyInt_As_PY_LONG_LONG(tmp); - Py_DECREF(tmp); - return val; - } -raise_overflow: - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to PY_LONG_LONG"); - return (PY_LONG_LONG) -1; -raise_neg_overflow: - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to PY_LONG_LONG"); - return (PY_LONG_LONG) -1; -} - -/* CIntFromPy */ - static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *x) { -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const size_t neg_one = (size_t) -1, const_zero = (size_t) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - 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) { -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const long neg_one = (long) -1, const_zero = (long) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - 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; -} - -/* CIntFromPy */ - static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *x) { -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const char neg_one = (char) -1, const_zero = (char) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - const int is_unsigned = neg_one > const_zero; -#if PY_MAJOR_VERSION < 3 - if (likely(PyInt_Check(x))) { - if (sizeof(char) < sizeof(long)) { - __PYX_VERIFY_RETURN_INT(char, long, PyInt_AS_LONG(x)) - } else { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - goto raise_neg_overflow; - } - return (char) 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 (char) 0; - case 1: __PYX_VERIFY_RETURN_INT(char, digit, digits[0]) - case 2: - if (8 * sizeof(char) > 1 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(char) >= 2 * PyLong_SHIFT) { - return (char) (((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0])); - } - } - break; - case 3: - if (8 * sizeof(char) > 2 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(char) >= 3 * PyLong_SHIFT) { - return (char) (((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])); - } - } - break; - case 4: - if (8 * sizeof(char) > 3 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(char, 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(char) >= 4 * PyLong_SHIFT) { - return (char) (((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)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 (char) -1; - if (unlikely(result == 1)) - goto raise_neg_overflow; - } -#endif - if (sizeof(char) <= sizeof(unsigned long)) { - __PYX_VERIFY_RETURN_INT_EXC(char, unsigned long, PyLong_AsUnsignedLong(x)) -#ifdef HAVE_LONG_LONG - } else if (sizeof(char) <= sizeof(unsigned PY_LONG_LONG)) { - __PYX_VERIFY_RETURN_INT_EXC(char, 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 (char) 0; - case -1: __PYX_VERIFY_RETURN_INT(char, sdigit, (sdigit) (-(sdigit)digits[0])) - case 1: __PYX_VERIFY_RETURN_INT(char, digit, +digits[0]) - case -2: - if (8 * sizeof(char) - 1 > 1 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) { - return (char) (((char)-1)*(((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); - } - } - break; - case 2: - if (8 * sizeof(char) > 1 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) { - return (char) ((((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); - } - } - break; - case -3: - if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) { - return (char) (((char)-1)*(((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); - } - } - break; - case 3: - if (8 * sizeof(char) > 2 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) { - return (char) ((((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); - } - } - break; - case -4: - if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(char, 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(char) - 1 > 4 * PyLong_SHIFT) { - return (char) (((char)-1)*(((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); - } - } - break; - case 4: - if (8 * sizeof(char) > 3 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(char, 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(char) - 1 > 4 * PyLong_SHIFT) { - return (char) ((((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); - } - } - break; - } -#endif - if (sizeof(char) <= sizeof(long)) { - __PYX_VERIFY_RETURN_INT_EXC(char, long, PyLong_AsLong(x)) -#ifdef HAVE_LONG_LONG - } else if (sizeof(char) <= sizeof(PY_LONG_LONG)) { - __PYX_VERIFY_RETURN_INT_EXC(char, 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 - char 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 (char) -1; - } - } else { - char val; - PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); - if (!tmp) return (char) -1; - val = __Pyx_PyInt_As_char(tmp); - Py_DECREF(tmp); - return val; - } -raise_overflow: - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to char"); - return (char) -1; -raise_neg_overflow: - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to char"); - return (char) -1; -} - -/* TypeInfoCompare */ - static int -__pyx_typeinfo_cmp(__Pyx_TypeInfo *a, __Pyx_TypeInfo *b) -{ - int i; - if (!a || !b) - return 0; - if (a == b) - return 1; - if (a->size != b->size || a->typegroup != b->typegroup || - a->is_unsigned != b->is_unsigned || a->ndim != b->ndim) { - if (a->typegroup == 'H' || b->typegroup == 'H') { - return a->size == b->size; - } else { - return 0; - } - } - if (a->ndim) { - for (i = 0; i < a->ndim; i++) - if (a->arraysize[i] != b->arraysize[i]) - return 0; - } - if (a->typegroup == 'S') { - if (a->flags != b->flags) - return 0; - if (a->fields || b->fields) { - if (!(a->fields && b->fields)) - return 0; - for (i = 0; a->fields[i].type && b->fields[i].type; i++) { - __Pyx_StructField *field_a = a->fields + i; - __Pyx_StructField *field_b = b->fields + i; - if (field_a->offset != field_b->offset || - !__pyx_typeinfo_cmp(field_a->type, field_b->type)) - return 0; - } - return !a->fields[i].type && !b->fields[i].type; - } - } - return 1; -} - -/* MemviewSliceValidateAndInit */ - static int -__pyx_check_strides(Py_buffer *buf, int dim, int ndim, int spec) -{ - if (buf->shape[dim] <= 1) - return 1; - if (buf->strides) { - if (spec & __Pyx_MEMVIEW_CONTIG) { - if (spec & (__Pyx_MEMVIEW_PTR|__Pyx_MEMVIEW_FULL)) { - if (unlikely(buf->strides[dim] != sizeof(void *))) { - PyErr_Format(PyExc_ValueError, - "Buffer is not indirectly contiguous " - "in dimension %d.", dim); - goto fail; - } - } else if (unlikely(buf->strides[dim] != buf->itemsize)) { - PyErr_SetString(PyExc_ValueError, - "Buffer and memoryview are not contiguous " - "in the same dimension."); - goto fail; - } - } - if (spec & __Pyx_MEMVIEW_FOLLOW) { - Py_ssize_t stride = buf->strides[dim]; - if (stride < 0) - stride = -stride; - if (unlikely(stride < buf->itemsize)) { - PyErr_SetString(PyExc_ValueError, - "Buffer and memoryview are not contiguous " - "in the same dimension."); - goto fail; - } - } - } else { - if (unlikely(spec & __Pyx_MEMVIEW_CONTIG && dim != ndim - 1)) { - PyErr_Format(PyExc_ValueError, - "C-contiguous buffer is not contiguous in " - "dimension %d", dim); - goto fail; - } else if (unlikely(spec & (__Pyx_MEMVIEW_PTR))) { - PyErr_Format(PyExc_ValueError, - "C-contiguous buffer is not indirect in " - "dimension %d", dim); - goto fail; - } else if (unlikely(buf->suboffsets)) { - PyErr_SetString(PyExc_ValueError, - "Buffer exposes suboffsets but no strides"); - goto fail; - } - } - return 1; -fail: - return 0; -} -static int -__pyx_check_suboffsets(Py_buffer *buf, int dim, CYTHON_UNUSED int ndim, int spec) -{ - if (spec & __Pyx_MEMVIEW_DIRECT) { - if (unlikely(buf->suboffsets && buf->suboffsets[dim] >= 0)) { - PyErr_Format(PyExc_ValueError, - "Buffer not compatible with direct access " - "in dimension %d.", dim); - goto fail; - } - } - if (spec & __Pyx_MEMVIEW_PTR) { - if (unlikely(!buf->suboffsets || (buf->suboffsets[dim] < 0))) { - PyErr_Format(PyExc_ValueError, - "Buffer is not indirectly accessible " - "in dimension %d.", dim); - goto fail; - } - } - return 1; -fail: - return 0; -} -static int -__pyx_verify_contig(Py_buffer *buf, int ndim, int c_or_f_flag) -{ - int i; - if (c_or_f_flag & __Pyx_IS_F_CONTIG) { - Py_ssize_t stride = 1; - for (i = 0; i < ndim; i++) { - if (unlikely(stride * buf->itemsize != buf->strides[i] && buf->shape[i] > 1)) { - PyErr_SetString(PyExc_ValueError, - "Buffer not fortran contiguous."); - goto fail; - } - stride = stride * buf->shape[i]; - } - } else if (c_or_f_flag & __Pyx_IS_C_CONTIG) { - Py_ssize_t stride = 1; - for (i = ndim - 1; i >- 1; i--) { - if (unlikely(stride * buf->itemsize != buf->strides[i] && buf->shape[i] > 1)) { - PyErr_SetString(PyExc_ValueError, - "Buffer not C contiguous."); - goto fail; - } - stride = stride * buf->shape[i]; - } - } - return 1; -fail: - return 0; -} -static int __Pyx_ValidateAndInit_memviewslice( - int *axes_specs, - int c_or_f_flag, - int buf_flags, - int ndim, - __Pyx_TypeInfo *dtype, - __Pyx_BufFmt_StackElem stack[], - __Pyx_memviewslice *memviewslice, - PyObject *original_obj) -{ - struct __pyx_memoryview_obj *memview, *new_memview; - __Pyx_RefNannyDeclarations - Py_buffer *buf; - int i, spec = 0, retval = -1; - __Pyx_BufFmt_Context ctx; - int from_memoryview = __pyx_memoryview_check(original_obj); - __Pyx_RefNannySetupContext("ValidateAndInit_memviewslice", 0); - if (from_memoryview && __pyx_typeinfo_cmp(dtype, ((struct __pyx_memoryview_obj *) - original_obj)->typeinfo)) { - memview = (struct __pyx_memoryview_obj *) original_obj; - new_memview = NULL; - } else { - memview = (struct __pyx_memoryview_obj *) __pyx_memoryview_new( - original_obj, buf_flags, 0, dtype); - new_memview = memview; - if (unlikely(!memview)) - goto fail; - } - buf = &memview->view; - if (unlikely(buf->ndim != ndim)) { - PyErr_Format(PyExc_ValueError, - "Buffer has wrong number of dimensions (expected %d, got %d)", - ndim, buf->ndim); - goto fail; - } - if (new_memview) { - __Pyx_BufFmt_Init(&ctx, stack, dtype); - if (unlikely(!__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 "u byte%s) " - "does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "u byte%s)", - buf->itemsize, - (buf->itemsize > 1) ? "s" : "", - dtype->name, - dtype->size, - (dtype->size > 1) ? "s" : ""); - goto fail; - } - if (buf->len > 0) { - for (i = 0; i < ndim; i++) { - spec = axes_specs[i]; - if (unlikely(!__pyx_check_strides(buf, i, ndim, spec))) - goto fail; - if (unlikely(!__pyx_check_suboffsets(buf, i, ndim, spec))) - goto fail; - } - if (unlikely(buf->strides && !__pyx_verify_contig(buf, ndim, c_or_f_flag))) - goto fail; - } - if (unlikely(__Pyx_init_memviewslice(memview, ndim, memviewslice, - new_memview != NULL) == -1)) { - goto fail; - } - retval = 0; - goto no_fail; -fail: - Py_XDECREF(new_memview); - retval = -1; -no_fail: - __Pyx_RefNannyFinishContext(); - return retval; -} - -/* ObjectToMemviewSlice */ - static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t(PyObject *obj, int writable_flag) { - __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } }; - __Pyx_BufFmt_StackElem stack[1]; - int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_STRIDED) }; - int retcode; - if (obj == Py_None) { - result.memview = (struct __pyx_memoryview_obj *) Py_None; - return result; - } - retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, 0, - PyBUF_RECORDS_RO | writable_flag, 1, - &__Pyx_TypeInfo_nn___pyx_t_15pygeoprocessing_18geoprocessing_core_int64t, stack, - &result, obj); - if (unlikely(retcode == -1)) - goto __pyx_fail; - return result; -__pyx_fail: - result.memview = NULL; - result.data = NULL; - return result; -} - -/* ObjectToMemviewSlice */ - static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_double(PyObject *obj, int writable_flag) { - __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } }; - __Pyx_BufFmt_StackElem stack[1]; - int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_STRIDED) }; - int retcode; - if (obj == Py_None) { - result.memview = (struct __pyx_memoryview_obj *) Py_None; - return result; - } - retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, 0, - PyBUF_RECORDS_RO | writable_flag, 1, - &__Pyx_TypeInfo_double, stack, - &result, obj); - if (unlikely(retcode == -1)) - goto __pyx_fail; - return result; -__pyx_fail: - result.memview = NULL; - result.data = NULL; - return result; -} - -/* 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; -} - -/* 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 CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) { - int retval; - if (unlikely(!x)) return -1; - retval = __Pyx_PyObject_IsTrue(x); - Py_DECREF(x); - return retval; -} -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(b); - } -#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 */ diff --git a/src/pygeoprocessing/routing/routing.cpp b/src/pygeoprocessing/routing/routing.cpp deleted file mode 100644 index 73a29134..00000000 --- a/src/pygeoprocessing/routing/routing.cpp +++ /dev/null @@ -1,65695 +0,0 @@ -/* Generated by Cython 0.29.23 */ - -#ifndef PY_SSIZE_T_CLEAN -#define PY_SSIZE_T_CLEAN -#endif /* 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_29_23" -#define CYTHON_HEX_VERSION 0x001D17F0 -#define CYTHON_FUTURE_DIVISION 1 -#include -#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 - #undef CYTHON_USE_DICT_VERSIONS - #define CYTHON_USE_DICT_VERSIONS 0 - #undef CYTHON_USE_EXC_INFO_STACK - #define CYTHON_USE_EXC_INFO_STACK 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 - #undef CYTHON_USE_DICT_VERSIONS - #define CYTHON_USE_DICT_VERSIONS 0 - #undef CYTHON_USE_EXC_INFO_STACK - #define CYTHON_USE_EXC_INFO_STACK 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 (PY_VERSION_HEX >= 0x03050000) - #endif - #ifndef CYTHON_USE_TP_FINALIZE - #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1) - #endif - #ifndef CYTHON_USE_DICT_VERSIONS - #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1) - #endif - #ifndef CYTHON_USE_EXC_INFO_STACK - #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3) - #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 - #ifdef SIZEOF_VOID_P - enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) }; - #endif -#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 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 -#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 -void __Pyx_call_destructor(T& x) { - x.~T(); -} -template -class __Pyx_FakeReference { - public: - __Pyx_FakeReference() : ptr(NULL) { } - __Pyx_FakeReference(const T& ref) : ptr(const_cast(&ref)) { } - T *operator->() { return ptr; } - T *operator&() { return ptr; } - operator T&() { return *ptr; } - template bool operator ==(U other) { return *ptr == other; } - template 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" -#if PY_VERSION_HEX >= 0x030800A4 && PY_VERSION_HEX < 0x030800B2 - #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ - PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) -#else - #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) -#endif - #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 -#ifndef METH_STACKLESS - #define METH_STACKLESS 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 | METH_STACKLESS))))) -#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_CPYTHON && PY_VERSION_HEX < 0x030400A1 - #define PyMem_RawMalloc(n) PyMem_Malloc(n) - #define PyMem_RawRealloc(p, n) PyMem_Realloc(p, n) - #define PyMem_RawFree(p) PyMem_Free(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; -} -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 -#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) - #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE) - #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) - #else - #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) - #endif -#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 || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) -#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? 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 -#ifndef PyObject_Unicode - #define PyObject_Unicode PyObject_Str -#endif -#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 PY_VERSION_HEX >= 0x030900A4 - #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt) - #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size) -#else - #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt) - #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size) -#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) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(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 -#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_MARK_ERR_POS(f_index, lineno) \ - { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; } -#define __PYX_ERR(f_index, lineno, Ln_error) \ - { __PYX_MARK_ERR_POS(f_index, lineno) 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 -#include -#include "numpy/arrayobject.h" -#include "numpy/ndarrayobject.h" -#include "numpy/ndarraytypes.h" -#include "numpy/arrayscalars.h" -#include "numpy/ufuncobject.h" - - /* NumPy API declarations from "numpy/__init__.pxd" */ - -#include -#include -#include "ios" -#include "new" -#include "stdexcept" -#include "typeinfo" -#include -#include -#include - - #if __cplusplus > 199711L - #include - - namespace cython_std { - template typename std::remove_reference::type&& move(T& t) noexcept { return std::move(t); } - template typename std::remove_reference::type&& move(T&& t) noexcept { return std::move(t); } - } - - #endif - -#include -#include -#include -#include -#include "LRUCache.h" -#ifdef _OPENMP -#include -#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_UTF8 0 -#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8) -#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))) ) -static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) { - return (size_t) i < (size_t) limit; -} -#if defined (__cplusplus) && __cplusplus >= 201103L - #include - #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 int __Pyx_PyObject_IsTrueAndDecref(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) + 1); - 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 - #else - #include - #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; - - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":690 - * # 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":691 - * - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":692 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":693 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":697 - * #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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":698 - * - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":699 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":700 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":704 - * #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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":705 - * - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":714 - * # 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":715 - * # 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":716 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":718 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":719 - * - * ctypedef npy_ulong uint_t - * ctypedef npy_ulonglong ulong_t # <<<<<<<<<<<<<< - * ctypedef npy_ulonglong ulonglong_t - * - */ -typedef npy_ulonglong __pyx_t_5numpy_ulong_t; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":720 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":722 - * ctypedef npy_ulonglong ulonglong_t - * - * ctypedef npy_intp intp_t # <<<<<<<<<<<<<< - * ctypedef npy_uintp uintp_t - * - */ -typedef npy_intp __pyx_t_5numpy_intp_t; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":723 - * - * ctypedef npy_intp intp_t - * ctypedef npy_uintp uintp_t # <<<<<<<<<<<<<< - * - * ctypedef npy_double float_t - */ -typedef npy_uintp __pyx_t_5numpy_uintp_t; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":725 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":726 - * - * ctypedef npy_double float_t - * ctypedef npy_double double_t # <<<<<<<<<<<<<< - * ctypedef npy_longdouble longdouble_t - * - */ -typedef npy_double __pyx_t_5numpy_double_t; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":727 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":729 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":730 - * - * ctypedef npy_cfloat cfloat_t - * ctypedef npy_cdouble cdouble_t # <<<<<<<<<<<<<< - * ctypedef npy_clongdouble clongdouble_t - * - */ -typedef npy_cdouble __pyx_t_5numpy_cdouble_t; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":731 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":733 - * 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_StreamConnectivityPoint; -struct __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateType; -struct __pyx_t_15pygeoprocessing_7routing_7routing_FinishType; -struct __pyx_t_15pygeoprocessing_7routing_7routing_GreaterPixel; - -/* "pygeoprocessing/routing/routing.pyx":118 - * - * # 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":126 - * # 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":136 - * # d8 flow direction to walk and the source_id indicates the source stream it - * # spawned from - * cdef struct StreamConnectivityPoint: # <<<<<<<<<<<<<< - * int xi - * int yi - */ -struct __pyx_t_15pygeoprocessing_7routing_7routing_StreamConnectivityPoint { - int xi; - int yi; - int upstream_d8_dir; - int source_id; -}; - -/* "pygeoprocessing/routing/routing.pyx":143 - * - * # 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":148 - * - * - * cdef struct FinishType: # <<<<<<<<<<<<<< - * int xi - * int yi - */ -struct __pyx_t_15pygeoprocessing_7routing_7routing_FinishType { - int xi; - int yi; - int n_pushed; -}; - -/* "pygeoprocessing/routing/routing.pyx":155 - * # 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 __pyx_t_15pygeoprocessing_7routing_7routing_BlockBufferPair; - -/* "pygeoprocessing/routing/routing.pyx":158 - * - * # 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 ,__pyx_t_15pygeoprocessing_7routing_7routing_GreaterPixel> __pyx_t_15pygeoprocessing_7routing_7routing_PitPriorityQueueType; - -/* "pygeoprocessing/routing/routing.pyx":162 - * - * # 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 __pyx_t_15pygeoprocessing_7routing_7routing_IntQueueType; - -/* "pygeoprocessing/routing/routing.pyx":165 - * - * # 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 __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":168 - * - * # 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":184 - * # 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 *lru_cache; - std::set 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); - void (*flush)(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *); -}; -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); - -/* PyDictVersioning.proto */ -#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS -#define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1) -#define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag) -#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\ - (version_var) = __PYX_GET_DICT_VERSION(dict);\ - (cache_var) = (value); -#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\ - static PY_UINT64_T __pyx_dict_version = 0;\ - static PyObject *__pyx_dict_cached_value = NULL;\ - if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\ - (VAR) = __pyx_dict_cached_value;\ - } else {\ - (VAR) = __pyx_dict_cached_value = (LOOKUP);\ - __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\ - }\ -} -static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj); -static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj); -static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version); -#else -#define __PYX_GET_DICT_VERSION(dict) (0) -#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) -#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP); -#endif - -/* GetModuleGlobalName.proto */ -#if CYTHON_USE_DICT_VERSIONS -#define __Pyx_GetModuleGlobalName(var, name) {\ - static PY_UINT64_T __pyx_dict_version = 0;\ - static PyObject *__pyx_dict_cached_value = NULL;\ - (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\ - (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\ - __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ -} -#define __Pyx_GetModuleGlobalNameUncached(var, name) {\ - PY_UINT64_T __pyx_dict_version;\ - PyObject *__pyx_dict_cached_value;\ - (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ -} -static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); -#else -#define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name) -#define __Pyx_GetModuleGlobalNameUncached(var, name) (var) = __Pyx__GetModuleGlobalName(name) -static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name); -#endif - -/* 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, Py_ssize_t nargs, PyObject *kwargs); -#else -#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs) -#endif -#define __Pyx_BUILD_ASSERT_EXPR(cond)\ - (sizeof(char [1 - 2*!(cond)]) - 1) -#ifndef Py_MEMBER_SIZE -#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member) -#endif - static size_t __pyx_pyframe_localsplus_offset = 0; - #include "frameobject.h" - #define __Pxy_PyFrame_Initialize_Offsets()\ - ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\ - (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus))) - #define __Pyx_PyFrame_GetLocalsplus(frame)\ - (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset)) -#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 - -/* PyObjectCall2Args.proto */ -static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2); - -/* 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); - -/* GCCDiagnostics.proto */ -#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) -#define __Pyx_HAS_GCC_DIAGNOSTIC -#endif - -/* BuildPyUnicode.proto */ -static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, char* chars, int clength, - int prepend_sign, char padding_char); - -/* CIntToPyUnicode.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_int(int value, Py_ssize_t width, char padding_char, char format_char); - -/* PyObjectFormatAndDecref.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f); -static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f); - -/* IncludeStringH.proto */ -#include - -/* JoinPyUnicode.proto */ -static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength, - Py_UCS4 max_char); - -/* 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); - -/* PyIntCompare.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, long intval, long inplace); - -/* PyObjectFormatSimple.proto */ -#if CYTHON_COMPILING_IN_PYPY - #define __Pyx_PyObject_FormatSimple(s, f) (\ - likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ - PyObject_Format(s, f)) -#elif PY_MAJOR_VERSION < 3 - #define __Pyx_PyObject_FormatSimple(s, f) (\ - likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ - likely(PyString_CheckExact(s)) ? PyUnicode_FromEncodedObject(s, NULL, "strict") :\ - PyObject_Format(s, f)) -#elif CYTHON_USE_TYPE_SLOTS - #define __Pyx_PyObject_FormatSimple(s, f) (\ - likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ - likely(PyLong_CheckExact(s)) ? PyLong_Type.tp_str(s) :\ - likely(PyFloat_CheckExact(s)) ? PyFloat_Type.tp_str(s) :\ - PyObject_Format(s, f)) -#else - #define __Pyx_PyObject_FormatSimple(s, f) (\ - likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ - PyObject_Format(s, f)) -#endif - -/* PyIntBinop.proto */ -#if !CYTHON_COMPILING_IN_PYPY -static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check); -#else -#define __Pyx_PyInt_SubtractObjC(op1, op2, intval, inplace, zerodivision_check)\ - (inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2)) -#endif - -/* None.proto */ -static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname); - -/* PyIntBinop.proto */ -#if !CYTHON_COMPILING_IN_PYPY -static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check); -#else -#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace, zerodivision_check)\ - (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2)) -#endif - -/* GetTopmostException.proto */ -#if CYTHON_USE_EXC_INFO_STACK -static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate); -#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 - -/* PyIntCompare.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyInt_NeObjC(PyObject *op1, PyObject *op2, long intval, long inplace); - -/* 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 - -/* None.proto */ -static CYTHON_INLINE long __Pyx_mod_long(long, long); - -/* CIntToPyUnicode.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_long(long value, Py_ssize_t width, char padding_char, char format_char); - -/* ListAppend.proto */ -#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS -static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) { - PyListObject* L = (PyListObject*) list; - Py_ssize_t len = Py_SIZE(list); - if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) { - Py_INCREF(x); - PyList_SET_ITEM(list, len, x); - __Pyx_SET_SIZE(list, len + 1); - return 0; - } - return PyList_Append(list, x); -} -#else -#define __Pyx_PyList_Append(L,x) PyList_Append(L,x) -#endif - -/* PyObjectGetMethod.proto */ -static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method); - -/* PyObjectCallMethod1.proto */ -static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg); - -/* append.proto */ -static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x); - -/* ListCompAppend.proto */ -#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS -static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) { - PyListObject* L = (PyListObject*) list; - Py_ssize_t len = Py_SIZE(list); - if (likely(L->allocated > len)) { - Py_INCREF(x); - PyList_SET_ITEM(list, len, x); - __Pyx_SET_SIZE(list, len + 1); - return 0; - } - return PyList_Append(list, x); -} -#else -#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x) -#endif - -/* pop_index.proto */ -static PyObject* __Pyx__PyObject_PopNewIndex(PyObject* L, PyObject* py_ix); -static PyObject* __Pyx__PyObject_PopIndex(PyObject* L, PyObject* py_ix); -#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS -static PyObject* __Pyx__PyList_PopIndex(PyObject* L, PyObject* py_ix, Py_ssize_t ix); -#define __Pyx_PyObject_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) (\ - (likely(PyList_CheckExact(L) && __Pyx_fits_Py_ssize_t(ix, type, is_signed))) ?\ - __Pyx__PyList_PopIndex(L, py_ix, ix) : (\ - (unlikely((py_ix) == Py_None)) ? __Pyx__PyObject_PopNewIndex(L, to_py_func(ix)) :\ - __Pyx__PyObject_PopIndex(L, py_ix))) -#define __Pyx_PyList_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) (\ - __Pyx_fits_Py_ssize_t(ix, type, is_signed) ?\ - __Pyx__PyList_PopIndex(L, py_ix, ix) : (\ - (unlikely((py_ix) == Py_None)) ? __Pyx__PyObject_PopNewIndex(L, to_py_func(ix)) :\ - __Pyx__PyObject_PopIndex(L, py_ix))) -#else -#define __Pyx_PyList_PopIndex(L, py_ix, ix, is_signed, type, to_py_func)\ - __Pyx_PyObject_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) -#define __Pyx_PyObject_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) (\ - (unlikely((py_ix) == Py_None)) ? __Pyx__PyObject_PopNewIndex(L, to_py_func(ix)) :\ - __Pyx__PyObject_PopIndex(L, py_ix)) -#endif - -/* PyDictContains.proto */ -static CYTHON_INLINE int __Pyx_PyDict_ContainsTF(PyObject* item, PyObject* dict, int eq) { - int result = PyDict_Contains(dict, item); - return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); -} - -/* CIntToPyUnicode.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_Py_ssize_t(Py_ssize_t value, Py_ssize_t width, char padding_char, char format_char); - -/* PyObjectCallMethod0.proto */ -static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name); - -/* pop.proto */ -static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L); -#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS -static CYTHON_INLINE PyObject* __Pyx_PyList_Pop(PyObject* L); -#define __Pyx_PyObject_Pop(L) (likely(PyList_CheckExact(L)) ?\ - __Pyx_PyList_Pop(L) : __Pyx__PyObject_Pop(L)) -#else -#define __Pyx_PyList_Pop(L) __Pyx__PyObject_Pop(L) -#define __Pyx_PyObject_Pop(L) __Pyx__PyObject_Pop(L) -#endif - -/* UnpackUnboundCMethod.proto */ -typedef struct { - PyObject *type; - PyObject **method_name; - PyCFunction func; - PyObject *method; - int flag; -} __Pyx_CachedCFunction; - -/* CallUnboundCMethod0.proto */ -static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self); -#if CYTHON_COMPILING_IN_CPYTHON -#define __Pyx_CallUnboundCMethod0(cfunc, self)\ - (likely((cfunc)->func) ?\ - (likely((cfunc)->flag == METH_NOARGS) ? (*((cfunc)->func))(self, NULL) :\ - (PY_VERSION_HEX >= 0x030600B1 && likely((cfunc)->flag == METH_FASTCALL) ?\ - (PY_VERSION_HEX >= 0x030700A0 ?\ - (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)(cfunc)->func)(self, &__pyx_empty_tuple, 0) :\ - (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, &__pyx_empty_tuple, 0, NULL)) :\ - (PY_VERSION_HEX >= 0x030700A0 && (cfunc)->flag == (METH_FASTCALL | METH_KEYWORDS) ?\ - (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, &__pyx_empty_tuple, 0, NULL) :\ - (likely((cfunc)->flag == (METH_VARARGS | METH_KEYWORDS)) ? ((*(PyCFunctionWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, __pyx_empty_tuple, NULL)) :\ - ((cfunc)->flag == METH_VARARGS ? (*((cfunc)->func))(self, __pyx_empty_tuple) :\ - __Pyx__CallUnboundCMethod0(cfunc, self)))))) :\ - __Pyx__CallUnboundCMethod0(cfunc, self)) -#else -#define __Pyx_CallUnboundCMethod0(cfunc, self) __Pyx__CallUnboundCMethod0(cfunc, self) -#endif - -/* ListExtend.proto */ -static CYTHON_INLINE int __Pyx_PyList_Extend(PyObject* L, PyObject* v) { -#if CYTHON_COMPILING_IN_CPYTHON - PyObject* none = _PyList_Extend((PyListObject*)L, v); - if (unlikely(!none)) - return -1; - Py_DECREF(none); - return 0; -#else - return PyList_SetSlice(L, PY_SSIZE_T_MAX, PY_SSIZE_T_MAX, v); -#endif -} - -/* PySequenceContains.proto */ -static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* seq, int eq) { - int result = PySequence_Contains(seq, item); - return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); -} - -/* RaiseNoneIterError.proto */ -static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void); - -/* UnpackTupleError.proto */ -static void __Pyx_UnpackTupleError(PyObject *, Py_ssize_t index); - -/* UnpackTuple2.proto */ -#define __Pyx_unpack_tuple2(tuple, value1, value2, is_tuple, has_known_size, decref_tuple)\ - (likely(is_tuple || PyTuple_Check(tuple)) ?\ - (likely(has_known_size || PyTuple_GET_SIZE(tuple) == 2) ?\ - __Pyx_unpack_tuple2_exact(tuple, value1, value2, decref_tuple) :\ - (__Pyx_UnpackTupleError(tuple, 2), -1)) :\ - __Pyx_unpack_tuple2_generic(tuple, value1, value2, has_known_size, decref_tuple)) -static CYTHON_INLINE int __Pyx_unpack_tuple2_exact( - PyObject* tuple, PyObject** value1, PyObject** value2, int decref_tuple); -static int __Pyx_unpack_tuple2_generic( - PyObject* tuple, PyObject** value1, PyObject** value2, int has_known_size, int decref_tuple); - -/* dict_iter.proto */ -static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* dict, int is_dict, PyObject* method_name, - Py_ssize_t* p_orig_length, int* p_is_dict); -static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* dict_or_iter, Py_ssize_t orig_length, Py_ssize_t* ppos, - PyObject** pkey, PyObject** pvalue, PyObject** pitem, int is_dict); - -/* PyObjectFormat.proto */ -#if CYTHON_USE_UNICODE_WRITER -static PyObject* __Pyx_PyObject_Format(PyObject* s, PyObject* f); -#else -#define __Pyx_PyObject_Format(s, f) PyObject_Format(s, f) -#endif - -/* pyfrozenset_new.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyFrozenSet_New(PyObject* it); - -/* PySetContains.proto */ -static CYTHON_INLINE int __Pyx_PySet_ContainsTF(PyObject* key, PyObject* set, int eq); - -/* BytesEquals.proto */ -static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); - -/* UnicodeEquals.proto */ -static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); - -/* 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); - -/* PyObjectGetAttrStrNoError.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name); - -/* SetupReduce.proto */ -static int __Pyx_setup_reduce(PyObject* type_obj); - -/* TypeImport.proto */ -#ifndef __PYX_HAVE_RT_ImportType_proto -#define __PYX_HAVE_RT_ImportType_proto -enum __Pyx_ImportType_CheckSize { - __Pyx_ImportType_CheckSize_Error = 0, - __Pyx_ImportType_CheckSize_Warn = 1, - __Pyx_ImportType_CheckSize_Ignore = 2 -}; -static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size); -#endif - -/* 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 - -/* 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 - - -/* CppExceptionConversion.proto */ -#ifndef __Pyx_CppExn2PyErr -#include -#include -#include -#include -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_long(long value); - -/* CIntFromPy.proto */ -static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); - -/* CIntFromPy.proto */ -static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); - -/* CIntToPy.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); - -/* CIntFromPy.proto */ -static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *); - -/* CIntToPy.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyInt_From_PY_LONG_LONG(PY_LONG_LONG value); - -/* 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); - -/* 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*/ -static void __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_flush(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_self); /* proto*/ - -/* Module declarations from 'cython' */ - -/* 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_generic = 0; -static PyTypeObject *__pyx_ptype_5numpy_number = 0; -static PyTypeObject *__pyx_ptype_5numpy_integer = 0; -static PyTypeObject *__pyx_ptype_5numpy_signedinteger = 0; -static PyTypeObject *__pyx_ptype_5numpy_unsignedinteger = 0; -static PyTypeObject *__pyx_ptype_5numpy_inexact = 0; -static PyTypeObject *__pyx_ptype_5numpy_floating = 0; -static PyTypeObject *__pyx_ptype_5numpy_complexfloating = 0; -static PyTypeObject *__pyx_ptype_5numpy_flexible = 0; -static PyTypeObject *__pyx_ptype_5numpy_character = 0; -static PyTypeObject *__pyx_ptype_5numpy_ufunc = 0; - -/* Module declarations from 'libc.stddef' */ - -/* Module declarations from 'libc.time' */ - -/* Module declarations from 'libcpp.deque' */ - -/* Module declarations from 'libcpp.list' */ - -/* Module declarations from 'libcpp.utility' */ - -/* Module declarations from 'libcpp.pair' */ - -/* Module declarations from 'libcpp.queue' */ - -/* Module declarations from 'libcpp.set' */ - -/* Module declarations from 'libcpp.stack' */ - -/* Module declarations from 'libcpp.vector' */ - -/* Module declarations from 'pygeoprocessing.routing.routing' */ -static PyTypeObject *__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster = 0; -static float __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD; -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_D8_XOFFSET; -static int *__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET; -static int *__pyx_v_15pygeoprocessing_7routing_7routing_D8_REVERSE_DIRECTION; -static int __pyx_v_15pygeoprocessing_7routing_7routing__MAX_PIXEL_FILL_COUNT; -static int __pyx_f_15pygeoprocessing_7routing_7routing__is_close(double, double, double, double); /*proto*/ -static void __pyx_f_15pygeoprocessing_7routing_7routing__diagonal_fill_step(int, int, int, long, long, struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *, long, PyObject *); /*proto*/ -static int __pyx_f_15pygeoprocessing_7routing_7routing__in_watershed(int, int, int, int, int, int, int, struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *, long); /*proto*/ -static PyObject *__pyx_f_15pygeoprocessing_7routing_7routing__calculate_stream_geometry(int, int, int, PyObject *, int, int, struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *, struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *, int, int, PyObject *); /*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 }; -static __Pyx_TypeInfo __Pyx_TypeInfo_nn_npy_int32 = { "npy_int32", NULL, sizeof(npy_int32), { 0 }, 0, IS_UNSIGNED(npy_int32) ? 'U' : 'I', IS_UNSIGNED(npy_int32), 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_print; -static PyObject *__pyx_builtin_ValueError; -static PyObject *__pyx_builtin_range; -static PyObject *__pyx_builtin_RuntimeError; -static PyObject *__pyx_builtin_TypeError; -static PyObject *__pyx_builtin_OSError; -static PyObject *__pyx_builtin_enumerate; -static PyObject *__pyx_builtin_min; -static PyObject *__pyx_builtin_max; -static PyObject *__pyx_builtin_sorted; -static PyObject *__pyx_builtin_ImportError; -static const char __pyx_k_[] = ", "; -static const char __pyx_k_d[] = "d"; -static const char __pyx_k_i[] = "i"; -static const char __pyx_k_j[] = "j"; -static const char __pyx_k_x[] = "x"; -static const char __pyx_k_1f[] = ".1f"; -static const char __pyx_k_ID[] = "ID"; -static const char __pyx_k_d8[] = "d8"; -static const char __pyx_k_g0[] = "g0"; -static const char __pyx_k_g1[] = "g1"; -static const char __pyx_k_g2[] = "g2"; -static const char __pyx_k_g3[] = "g3"; -static const char __pyx_k_g4[] = "g4"; -static const char __pyx_k_g5[] = "g5"; -static const char __pyx_k_of[] = " of "; -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__34[] = "_"; -static const char __pyx_k_d_n[] = "d_n"; -static const char __pyx_k_dir[] = "dir"; -static const char __pyx_k_fid[] = "fid"; -static const char __pyx_k_i_n[] = "i_n"; -static const char __pyx_k_max[] = "max"; -static const char __pyx_k_mfd[] = "mfd"; -static const char __pyx_k_min[] = "min"; -static const char __pyx_k_ogr[] = "ogr"; -static const char __pyx_k_ops[] = "ops"; -static const char __pyx_k_osr[] = "osr"; -static const char __pyx_k_pop[] = "pop"; -static const char __pyx_k_wkb[] = "wkb"; -static const char __pyx_k_x_f[] = "x_f"; -static const char __pyx_k_x_l[] = "x_l"; -static const char __pyx_k_x_n[] = "x_n"; -static const char __pyx_k_x_p[] = "x_p"; -static const char __pyx_k_x_u[] = "x_u"; -static const char __pyx_k_y_f[] = "y_f"; -static const char __pyx_k_y_l[] = "y_l"; -static const char __pyx_k_y_n[] = "y_n"; -static const char __pyx_k_y_p[] = "y_p"; -static const char __pyx_k_y_u[] = "y_u"; -static const char __pyx_k_GPKG[] = "GPKG"; -static const char __pyx_k_copy[] = "copy"; -static const char __pyx_k_ds_x[] = "ds_x"; -static const char __pyx_k_ds_y[] = "ds_y"; -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_left[] = "left"; -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_us_x[] = "us_x"; -static const char __pyx_k_us_y[] = "us_y"; -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_Union[] = "Union"; -static const char __pyx_k_close[] = "close"; -static const char __pyx_k_debug[] = "debug"; -static const char __pyx_k_ds_fa[] = "ds_fa"; -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_index[] = "index"; -static const char __pyx_k_int32[] = "int32"; -static const char __pyx_k_isnan[] = "isnan"; -static const char __pyx_k_loads[] = "loads"; -static const char __pyx_k_lower[] = "lower"; -static const char __pyx_k_n_dir[] = "n_dir"; -static const char __pyx_k_numpy[] = "numpy"; -static const char __pyx_k_order[] = "order"; -static const char __pyx_k_osgeo[] = "osgeo"; -static const char __pyx_k_p_val[] = "p_val"; -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_right[] = "right"; -static const char __pyx_k_scipy[] = "scipy"; -static const char __pyx_k_sleep[] = "sleep"; -static const char __pyx_k_stats[] = "stats"; -static const char __pyx_k_uint8[] = "uint8"; -static const char __pyx_k_us_fa[] = "us_fa"; -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_Create[] = "Create"; -static const char __pyx_k_GetFID[] = "GetFID"; -static const char __pyx_k_LOGGER[] = "LOGGER"; -static const char __pyx_k_OpenEx[] = "OpenEx"; -static const char __pyx_k_append[] = "append"; -static const char __pyx_k_astype[] = "astype"; -static const char __pyx_k_double[] = "double"; -static const char __pyx_k_ds_x_1[] = "ds_x_1"; -static const char __pyx_k_ds_y_1[] = "ds_y_1"; -static const char __pyx_k_exists[] = "exists"; -static const char __pyx_k_finish[] = "finish"; -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_n_cols[] = "n_cols"; -static const char __pyx_k_n_rows[] = "n_rows"; -static const char __pyx_k_nodata[] = "nodata"; -static const char __pyx_k_outlet[] = "outlet"; -static const char __pyx_k_prefix[] = "prefix"; -static const char __pyx_k_proj_x[] = "proj_x"; -static const char __pyx_k_proj_y[] = "proj_y"; -static const char __pyx_k_raster[] = " raster."; -static const char __pyx_k_reduce[] = "__reduce__"; -static const char __pyx_k_remove[] = "remove"; -static const char __pyx_k_rmtree[] = "rmtree"; -static const char __pyx_k_shutil[] = "shutil"; -static const char __pyx_k_sorted[] = "sorted"; -static const char __pyx_k_suffix[] = "suffix"; -static const char __pyx_k_Feature[] = "Feature"; -static const char __pyx_k_OFTReal[] = "OFTReal"; -static const char __pyx_k_OSError[] = "OSError"; -static const char __pyx_k_bak_tif[] = "_bak.tif"; -static const char __pyx_k_band_id[] = "band_id"; -static const char __pyx_k_delta_x[] = "delta_x"; -static const char __pyx_k_delta_y[] = "delta_y"; -static const char __pyx_k_dirname[] = "dirname"; -static const char __pyx_k_float64[] = "float64"; -static const char __pyx_k_left_in[] = "left_in"; -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_n_steps[] = "n_steps"; -static const char __pyx_k_next_id[] = "next_id"; -static const char __pyx_k_opening[] = "opening "; -static const char __pyx_k_options[] = "options"; -static const char __pyx_k_order_1[] = "\"order\"=1"; -static const char __pyx_k_out_dir[] = "out_dir"; -static const char __pyx_k_payload[] = "payload"; -static const char __pyx_k_reverse[] = "reverse"; -static const char __pyx_k_shapely[] = "shapely"; -static const char __pyx_k_tmp_dir[] = "tmp_dir"; -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_AddPoint[] = "AddPoint"; -static const char __pyx_k_GDT_Byte[] = "GDT_Byte"; -static const char __pyx_k_Geometry[] = "Geometry"; -static const char __pyx_k_GetField[] = "GetField"; -static const char __pyx_k_GetLayer[] = "GetLayer"; -static const char __pyx_k_SetField[] = "SetField"; -static const char __pyx_k_basename[] = "basename"; -static const char __pyx_k_complete[] = "% complete"; -static const char __pyx_k_copyfile[] = "copyfile"; -static const char __pyx_k_datatype[] = "datatype"; -static const char __pyx_k_dem_band[] = "dem_band"; -static const char __pyx_k_edge_dir[] = "edge_dir"; -static const char __pyx_k_flow_dir[] = "flow_dir"; -static const char __pyx_k_getstate[] = "__getstate__"; -static const char __pyx_k_is_drain[] = "is_drain"; -static const char __pyx_k_makedirs[] = "makedirs"; -static const char __pyx_k_n_height[] = "n_height"; -static const char __pyx_k_n_pixels[] = "n_pixels"; -static const char __pyx_k_n_points[] = "n_points"; -static const char __pyx_k_n_pushed[] = "n_pushed"; -static const char __pyx_k_open_set[] = "open_set"; -static const char __pyx_k_outlet_1[] = "\"outlet\"=1"; -static const char __pyx_k_outlet_x[] = "outlet_x"; -static const char __pyx_k_outlet_y[] = "outlet_y"; -static const char __pyx_k_priority[] = "priority"; -static const char __pyx_k_retrying[] = ", retrying..."; -static const char __pyx_k_right_in[] = "right_in"; -static const char __pyx_k_river_id[] = "river_id"; -static const char __pyx_k_setstate[] = "__setstate__"; -static const char __pyx_k_splitext[] = "splitext"; -static const char __pyx_k_strftime[] = "strftime"; -static const char __pyx_k_tempfile[] = "tempfile"; -static const char __pyx_k_test_dir[] = "test_dir"; -static const char __pyx_k_wkbPoint[] = "wkbPoint"; -static const char __pyx_k_FieldDefn[] = "FieldDefn"; -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_OF_VECTOR[] = "OF_VECTOR"; -static const char __pyx_k_TILED_YES[] = "TILED=YES"; -static const char __pyx_k_TypeError[] = "TypeError"; -static const char __pyx_k_discovery[] = "discovery"; -static const char __pyx_k_edge_side[] = "edge_side"; -static const char __pyx_k_enumerate[] = "enumerate"; -static const char __pyx_k_equal_var[] = "equal_var"; -static const char __pyx_k_exception[] = "exception"; -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_linemerge[] = "linemerge"; -static const char __pyx_k_min_p_val[] = "min_p_val"; -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_source_id[] = "source_id"; -static const char __pyx_k_stream_mr[] = "stream_mr"; -static const char __pyx_k_thresh_fa[] = "thresh_fa"; -static const char __pyx_k_ttest_ind[] = "ttest_ind"; -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_GetFeature[] = "GetFeature"; -static const char __pyx_k_OFTInteger[] = "OFTInteger"; -static const char __pyx_k_SetFeature[] = "SetFeature"; -static const char __pyx_k_ValueError[] = "ValueError"; -static const char __pyx_k_WriteArray[] = "WriteArray"; -static const char __pyx_k_block_size[] = "block_size"; -static const char __pyx_k_boundary_x[] = "boundary_x"; -static const char __pyx_k_boundary_y[] = "boundary_y"; -static const char __pyx_k_center_val[] = "center_val"; -static const char __pyx_k_complete_2[] = " complete"; -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_finish_tif[] = "finish.tif"; -static const char __pyx_k_flow_accum[] = "flow_accum"; -static const char __pyx_k_flow_dir_n[] = "flow_dir_n"; -static const char __pyx_k_flow_pixel[] = "flow_pixel"; -static const char __pyx_k_iterblocks[] = "iterblocks"; -static const char __pyx_k_more_times[] = " more times."; -static const char __pyx_k_multi_line[] = "multi_line"; -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_outlet_fid[] = "outlet_fid"; -static const char __pyx_k_pour_point[] = "pour_point"; -static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__"; -static const char __pyx_k_raster_srs[] = "raster_srs"; -static const char __pyx_k_stream_fid[] = "stream_fid"; -static const char __pyx_k_stream_val[] = "stream_val"; -static const char __pyx_k_test_order[] = "test_order"; -static const char __pyx_k_weight_val[] = "weight_val"; -static const char __pyx_k_wkbPolygon[] = "wkbPolygon"; -static const char __pyx_k_write_mode[] = "write_mode"; -static const char __pyx_k_1f_complete[] = "%.1f%% complete"; -static const char __pyx_k_AddGeometry[] = "AddGeometry"; -static const char __pyx_k_BIGTIFF_YES[] = "BIGTIFF=YES"; -static const char __pyx_k_CreateField[] = "CreateField"; -static const char __pyx_k_CreateLayer[] = "CreateLayer"; -static const char __pyx_k_DeleteField[] = "DeleteField"; -static const char __pyx_k_ExportToWkb[] = "ExportToWkb"; -static const char __pyx_k_GDT_Float64[] = "GDT_Float64"; -static const char __pyx_k_GDT_Unknown[] = "GDT_Unknown"; -static const char __pyx_k_ImportError[] = "ImportError"; -static const char __pyx_k_ReadAsArray[] = "ReadAsArray"; -static const char __pyx_k_SetGeometry[] = "SetGeometry"; -static const char __pyx_k_all_defined[] = "all_defined"; -static const char __pyx_k_base_nodata[] = "base_nodata"; -static const char __pyx_k_block_array[] = "block_array"; -static const char __pyx_k_collections[] = "collections"; -static const char __pyx_k_defaultdict[] = "defaultdict"; -static const char __pyx_k_deleted_set[] = "deleted_set"; -static const char __pyx_k_drain_queue[] = "drain_queue"; -static const char __pyx_k_fill_height[] = "fill_height"; -static const char __pyx_k_fill_pits_2[] = "fill_pits"; -static const char __pyx_k_flow_dir_d8[] = "(flow dir d8): "; -static const char __pyx_k_flow_nodata[] = "flow_nodata"; -static const char __pyx_k_for_writing[] = " for writing"; -static const char __pyx_k_gpkg_driver[] = "gpkg_driver"; -static const char __pyx_k_joined_line[] = "joined_line"; -static const char __pyx_k_mask_nodata[] = "mask_nodata"; -static const char __pyx_k_n_processed[] = "n_processed"; -static const char __pyx_k_offset_dict[] = "offset_dict"; -static const char __pyx_k_offset_info[] = "offset_info"; -static const char __pyx_k_offset_only[] = "offset_only"; -static const char __pyx_k_order_count[] = "order_count"; -static const char __pyx_k_outflow_dir[] = "outflow_dir"; -static const char __pyx_k_pixel_count[] = "pixel_count"; -static const char __pyx_k_raster_info[] = "raster_info"; -static const char __pyx_k_raster_path[] = "raster_path"; -static const char __pyx_k_raster_size[] = "raster_size"; -static const char __pyx_k_river_order[] = "river_order"; -static const char __pyx_k_root_height[] = "root_height"; -static const char __pyx_k_scipy_stats[] = "scipy.stats"; -static const char __pyx_k_shapely_ops[] = "shapely.ops"; -static const char __pyx_k_shapely_wkb[] = "shapely.wkb"; -static const char __pyx_k_stream_band[] = "stream_band"; -static const char __pyx_k_stream_line[] = "stream_line"; -static const char __pyx_k_upstream_id[] = "upstream_id"; -static const char __pyx_k_visit_count[] = "visit_count"; -static const char __pyx_k_visited_tif[] = "visited.tif"; -static const char __pyx_k_working_dir[] = "working_dir"; -static const char __pyx_k_working_fid[] = "working_fid"; -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_GetLayerDefn[] = "GetLayerDefn"; -static const char __pyx_k_OFTInteger64[] = "OFTInteger64"; -static const char __pyx_k_ResetReading[] = "ResetReading"; -static const char __pyx_k_RuntimeError[] = "RuntimeError"; -static const char __pyx_k_cell_to_test[] = "cell_to_test"; -static const char __pyx_k_channel_band[] = "channel_band"; -static const char __pyx_k_fid_to_order[] = "fid_to_order"; -static const char __pyx_k_fill_pits__s[] = "fill_pits_%s_"; -static const char __pyx_k_finish_stack[] = "finish_stack"; -static const char __pyx_k_flow_dir_mfd[] = "flow_dir_mfd"; -static const char __pyx_k_flow_dir_srs[] = "flow_dir_srs"; -static const char __pyx_k_geotransform[] = "geotransform"; -static const char __pyx_k_is_a_channel[] = "is_a_channel"; -static const char __pyx_k_mfd_flow_dir[] = "mfd_flow_dir_"; -static const char __pyx_k_n_iterations[] = "n_iterations"; -static const char __pyx_k_outlet_index[] = "outlet_index"; -static const char __pyx_k_outlet_layer[] = "outlet_layer"; -static const char __pyx_k_outlet_point[] = "outlet_point"; -static const char __pyx_k_pit_mask_tif[] = "pit_mask.tif"; -static const char __pyx_k_raster_coord[] = "raster_coord"; -static const char __pyx_k_search_queue[] = "search_queue"; -static const char __pyx_k_search_stack[] = "search_stack"; -static const char __pyx_k_search_steps[] = "search_steps"; -static const char __pyx_k_stream_array[] = "stream_array"; -static const char __pyx_k_stream_layer[] = "stream_layer"; -static const char __pyx_k_stream_order[] = "stream_order"; -static const char __pyx_k_tmp_dir_root[] = "tmp_dir_root"; -static const char __pyx_k_tmp_work_dir[] = "tmp_work_dir"; -static const char __pyx_k_upstream_dem[] = "upstream_dem"; -static const char __pyx_k_upstream_fid[] = "upstream_fid"; -static const char __pyx_k_working_geom[] = "working_geom"; -static const char __pyx_k_x_off_border[] = "x_off_border"; -static const char __pyx_k_y_off_border[] = "y_off_border"; -static const char __pyx_k_CreateFeature[] = "CreateFeature"; -static const char __pyx_k_DeleteFeature[] = "DeleteFeature"; -static const char __pyx_k_GetRasterBand[] = "GetRasterBand"; -static const char __pyx_k_ImportFromWkt[] = "ImportFromWkt"; -static const char __pyx_k_ManagedRaster[] = "_ManagedRaster"; -static const char __pyx_k_backtrace_set[] = "backtrace_set"; -static const char __pyx_k_base_datatype[] = "base_datatype"; -static const char __pyx_k_block_offsets[] = "block_offsets"; -static const char __pyx_k_boundary_list[] = "boundary_list"; -static const char __pyx_k_connected_fid[] = "connected_fid"; -static const char __pyx_k_current_pixel[] = "current_pixel"; -static const char __pyx_k_discovery_srs[] = "discovery_srs"; -static const char __pyx_k_discovery_tif[] = "discovery.tif"; -static const char __pyx_k_drop_distance[] = "drop_distance"; -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_flow_dir_d8_2[] = "flow_dir_d8"; -static const char __pyx_k_flow_dir_info[] = "flow_dir_info"; -static const char __pyx_k_flow_dir_type[] = "flow_dir_type"; -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_outlet_vector[] = "outlet_vector"; -static const char __pyx_k_pit_mask_path[] = "pit_mask_path"; -static const char __pyx_k_raster_driver[] = "raster_driver"; -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_stream_vector[] = "stream_vector"; -static const char __pyx_k_upstream_dirs[] = "upstream_dirs"; -static const char __pyx_k_upstream_fids[] = "upstream_fids"; -static const char __pyx_k_weight_nodata[] = "weight_nodata"; -static const char __pyx_k_weight_raster[] = "weight_raster"; -static const char __pyx_k_wkbLineString[] = "wkbLineString"; -static const char __pyx_k_wkbLinearRing[] = "wkbLinearRing"; -static const char __pyx_k_working_order[] = "working_order"; -static const char __pyx_k_working_stack[] = "working_stack"; -static const char __pyx_k_workspace_dir[] = "workspace_dir"; -static const char __pyx_k_100_0_complete[] = "100.0% complete"; -static const char __pyx_k_FindFieldIndex[] = "FindFieldIndex"; -static const char __pyx_k_GetGeometryRef[] = "GetGeometryRef"; -static const char __pyx_k_SPARSE_OK_TRUE[] = "SPARSE_OK=TRUE"; -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_connected_fids[] = "connected_fids"; -static const char __pyx_k_could_not_open[] = "could not open "; -static const char __pyx_k_delete_feature[] = "_delete_feature"; -static const char __pyx_k_detect_outlets[] = "detect_outlets"; -static const char __pyx_k_discovery_info[] = "discovery_info"; -static const char __pyx_k_downstream_dem[] = "downstream_dem"; -static const char __pyx_k_downstream_fid[] = "downstream_fid"; -static const char __pyx_k_drain_distance[] = "drain_distance"; -static const char __pyx_k_flow_dir_block[] = "flow_dir_block"; -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_outet_basename[] = "outet_basename"; -static const char __pyx_k_outlet_feature[] = "outlet_feature"; -static const char __pyx_k_projection_wkt[] = "projection_wkt"; -static const char __pyx_k_stream_feature[] = "stream_feature"; -static const char __pyx_k_unable_to_open[] = "unable to open "; -static const char __pyx_k_upstream_coord[] = "upstream_coord"; -static const char __pyx_k_upstream_count[] = "upstream_count"; -static const char __pyx_k_upstream_index[] = "upstream_index"; -static const char __pyx_k_upstream_order[] = "upstream_order"; -static const char __pyx_k_upstream_stack[] = "upstream_stack"; -static const char __pyx_k_GetDriverByName[] = "GetDriverByName"; -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_discovery_count[] = "discovery_count"; -static const char __pyx_k_discovery_stack[] = "discovery_stack"; -static const char __pyx_k_distance_nodata[] = "distance_nodata"; -static const char __pyx_k_downstream_geom[] = "downstream_geom"; -static const char __pyx_k_fill_value_list[] = "fill_value_list"; -static const char __pyx_k_filled_dem_band[] = "filled_dem_band"; -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_outlet_fid_list[] = "outlet_fid_list"; -static const char __pyx_k_pixels_complete[] = " pixels complete"; -static const char __pyx_k_processed_nodes[] = "processed_nodes"; -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_starting_search[] = "starting search"; -static const char __pyx_k_stream_basename[] = "stream_basename"; -static const char __pyx_k_upstream_d8_dir[] = "upstream_d8_dir"; -static const char __pyx_k_watershed_layer[] = "watershed_layer"; -static const char __pyx_k_working_feature[] = "working_feature"; -static const char __pyx_k_SpatialReference[] = "SpatialReference"; -static const char __pyx_k_StartTransaction[] = "StartTransaction"; -static const char __pyx_k_d8_flow_dir_mode[] = "d8_flow_dir_mode"; -static const char __pyx_k_dem_buffer_array[] = "dem_buffer_array"; -static const char __pyx_k_discovery_nodata[] = "discovery_nodata"; -static const char __pyx_k_downstream_order[] = "downstream_order"; -static const char __pyx_k_local_flow_accum[] = "local_flow_accum"; -static const char __pyx_k_n_drain_distance[] = "n_drain_distance"; -static const char __pyx_k_out_dir_increase[] = "out_dir_increase"; -static const char __pyx_k_outlet_detection[] = "outlet detection: "; -static const char __pyx_k_outlets_complete[] = " outlets complete"; -static const char __pyx_k_raster_path_band[] = "raster_path_band"; -static const char __pyx_k_streams_by_order[] = "streams_by_order"; -static const char __pyx_k_terminated_early[] = "terminated_early"; -static const char __pyx_k_upstream_feature[] = "upstream_feature"; -static const char __pyx_k_upstream_fid_map[] = "upstream_fid_map"; -static const char __pyx_k_upstream_id_list[] = "upstream_id_list"; -static const char __pyx_k_watershed_vector[] = "watershed_vector"; -static const char __pyx_k_win_xsize_border[] = "win_xsize_border"; -static const char __pyx_k_win_ysize_border[] = "win_ysize_border"; -static const char __pyx_k_working_dir_path[] = "working_dir_path"; -static const char __pyx_k_working_river_id[] = "working_river_id"; -static const char __pyx_k_ApplyGeoTransform[] = "ApplyGeoTransform"; -static const char __pyx_k_CommitTransaction[] = "CommitTransaction"; -static const char __pyx_k_downhill_neighbor[] = "downhill_neighbor"; -static const char __pyx_k_filled_dem_raster[] = "filled_dem_raster"; -static const char __pyx_k_finish_coordinate[] = "finish_coordinate"; -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_out_of_bounds_for[] = " out of bounds for "; -static const char __pyx_k_raw_weight_nodata[] = "raw_weight_nodata"; -static const char __pyx_k_segments_complete[] = " segments complete"; -static const char __pyx_k_stream_order_list[] = "stream_order_list"; -static const char __pyx_k_streams_to_retest[] = "streams_to_retest"; -static const char __pyx_k_upstream_fid_list[] = "upstream_fid_list"; -static const char __pyx_k_upstream_flow_dir[] = "upstream_flow_dir"; -static const char __pyx_k_visit_order_stack[] = "visit_order_stack"; -static const char __pyx_k_watershed_feature[] = "watershed_feature"; -static const char __pyx_k_watershed_polygon[] = "watershed_polygon"; -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_SetAttributeFilter[] = "SetAttributeFilter"; -static const char __pyx_k_base_feature_count[] = "base_feature_count"; -static const char __pyx_k_block_offsets_list[] = "block_offsets_list"; -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_downstream_feature[] = "downstream_feature"; -static const char __pyx_k_drain_search_queue[] = "drain_search_queue"; -static const char __pyx_k_fill_pits_complete[] = "(fill pits): complete"; -static const char __pyx_k_geoprocessing_core[] = "geoprocessing_core"; -static const char __pyx_k_nodata_drain_queue[] = "nodata_drain_queue"; -static const char __pyx_k_processed_segments[] = "processed_segments"; -static const char __pyx_k_source_point_stack[] = "source_point_stack"; -static const char __pyx_k_streams_to_process[] = "streams_to_process"; -static const char __pyx_k_target_offset_dict[] = "target_offset_dict"; -static const char __pyx_k_watershed_basename[] = "watershed_basename"; -static const char __pyx_k_watershed_boundary[] = "watershed_boundary"; -static const char __pyx_k_compressed_flow_dir[] = "compressed_flow_dir"; -static const char __pyx_k_coord_to_stream_ids[] = "coord_to_stream_ids"; -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_segments_to_process[] = "segments_to_process"; -static const char __pyx_k_source_stream_point[] = "source_stream_point"; -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_visited_raster_path[] = "visited_raster_path"; -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_d8_complete[] = "(flow dir d8): complete"; -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_max_pixel_fill_count[] = "max_pixel_fill_count"; -static const char __pyx_k_modified_offset_dict[] = "modified_offset_dict"; -static const char __pyx_k_natural_drain_exists[] = "natural_drain_exists"; -static const char __pyx_k_new_raster_from_base[] = "new_raster_from_base"; -static const char __pyx_k_outlet_at_confluence[] = "outlet_at_confluence"; -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_all_defined[] = "upstream_all_defined"; -static const char __pyx_k_upstream_flow_weight[] = "upstream_flow_weight"; -static const char __pyx_k_CreateGeometryFromWkb[] = "CreateGeometryFromWkb"; -static const char __pyx_k_direction_drain_queue[] = "direction_drain_queue"; -static const char __pyx_k_finish_managed_raster[] = "finish_managed_raster"; -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_outlet_detection_done[] = "outlet detection: done"; -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_SetAxisMappingStrategy[] = "SetAxisMappingStrategy"; -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_in_ManagedRaster_flush[] = " in ManagedRaster.flush"; -static const char __pyx_k_plateu_drain_mask_path[] = "plateu_drain_mask_path"; -static const char __pyx_k_source_points_complete[] = " source points complete"; -static const char __pyx_k_sum_of_downhill_slopes[] = "sum_of_downhill_slopes"; -static const char __pyx_k_visited_managed_raster[] = "visited_managed_raster"; -static const char __pyx_k_compatible_dem_complete[] = "compatible dem complete"; -static const char __pyx_k_connected_upstream_fids[] = "connected_upstream_fids"; -static const char __pyx_k_distance_to_channel_mfd[] = "distance_to_channel_mfd"; -static const char __pyx_k_finish_time_raster_path[] = "finish_time_raster_path"; -static const char __pyx_k_flow_dir_managed_raster[] = "flow_dir_managed_raster"; -static const char __pyx_k_max_steps_per_watershed[] = "max_steps_per_watershed"; -static const char __pyx_k_max_upstream_flow_accum[] = "max_upstream_flow_accum"; -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_quitting_too_many_steps[] = "quitting, too many steps"; -static const char __pyx_k_resulted_in_null_trying[] = " resulted in null, trying "; -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_couldn_t_remove_temp_dir[] = "couldn't remove temp dir"; -static const char __pyx_k_discovery_managed_raster[] = "discovery_managed_raster"; -static const char __pyx_k_drop_distance_collection[] = "drop_distance_collection"; -static const char __pyx_k_min_flow_accum_threshold[] = "min_flow_accum_threshold"; -static const char __pyx_k_sorted_stream_order_list[] = "sorted_stream_order_list"; -static const char __pyx_k_compressed_integer_slopes[] = "compressed_integer_slopes"; -static const char __pyx_k_discovery_time_processing[] = "(discovery time processing): "; -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_osr_axis_mapping_strategy[] = "osr_axis_mapping_strategy"; -static const char __pyx_k_stream_fragments_complete[] = " stream fragments complete"; -static const char __pyx_k_target_finish_raster_path[] = "target_finish_raster_path"; -static const char __pyx_k_target_outlet_vector_path[] = "target_outlet_vector_path"; -static const char __pyx_k_target_stream_raster_path[] = "target_stream_raster_path"; -static const char __pyx_k_target_stream_vector_path[] = "target_stream_vector_path"; -static const char __pyx_k_upstream_to_downstream_id[] = "upstream_to_downstream_id"; -static const char __pyx_k_autotune_flow_accumulation[] = "autotune_flow_accumulation"; -static const char __pyx_k_d8_flow_dir_managed_raster[] = "d8_flow_dir_managed_raster"; -static const char __pyx_k_discovery_time_raster_path[] = "discovery_time_raster_path"; -static const char __pyx_k_downstream_to_upstream_ids[] = "downstream_to_upstream_ids"; -static const char __pyx_k_flow_dir_d8_managed_raster[] = "flow_dir_d8_managed_raster"; -static const char __pyx_k_mfd_flow_accum_1f_complete[] = "mfd flow accum %.1f%% complete"; -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_extract_strahler_streams_d8[] = "extract_strahler_streams_d8"; -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_int_max_steps_per_watershed[] = "_int_max_steps_per_watershed"; -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_outlet_detection_0_complete[] = "outlet detection: 0% complete"; -static const char __pyx_k_strahler_stream_vector_path[] = "strahler_stream_vector_path"; -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_d8_flow_dir_raster_path_band[] = "d8_flow_dir_raster_path_band"; -static const char __pyx_k_dist_to_channel_mfd_work_dir[] = "dist_to_channel_mfd_work_dir"; -static const char __pyx_k_flow_dir_d8_raster_path_band[] = "flow_dir_d8_raster_path_band"; -static const char __pyx_k_raster_driver_creation_tuple[] = "raster_driver_creation_tuple"; -static const char __pyx_k_target_discovery_raster_path[] = "target_discovery_raster_path"; -static const char __pyx_k_working_downhill_slope_array[] = "working_downhill_slope_array"; -static const char __pyx_k_working_flow_accum_threshold[] = "working_flow_accum_threshold"; -static const char __pyx_k_creating_visited_raster_layer[] = "creating visited raster layer"; -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_build_discovery_finish_rasters[] = "_build_discovery_finish_rasters"; -static const char __pyx_k_Error_Block_size_is_not_a_power[] = "Error: Block size is not a power of two: block_xsize: "; -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\n 3 2 1\n 4 x 0\n 5 6 7\n"; -static const char __pyx_k_This_exception_is_happeningin_C[] = ". 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_calculate_subwatershed_boundary[] = "calculate_subwatershed_boundary_workspace_"; -static const char __pyx_k_compatable_dem_raster_path_band[] = "compatable_dem_raster_path_band"; -static const char __pyx_k_exists_removing_before_creating[] = " exists, removing before creating a new one."; -static const char __pyx_k_extract_strahler_streams_d8_all[] = "(extract_strahler_streams_d8): all done"; -static const char __pyx_k_extract_strahler_streams_d8_com[] = "(extract_strahler_streams_d8): commit transaction due to stream joining"; -static const char __pyx_k_extract_strahler_streams_d8_det[] = "(extract_strahler_streams_d8): determining stream order"; -static const char __pyx_k_extract_strahler_streams_d8_dra[] = "(extract_strahler_streams_d8): drain seeding "; -static const char __pyx_k_extract_strahler_streams_d8_fin[] = "(extract_strahler_streams_d8): final pass on stream order and geometry"; -static const char __pyx_k_extract_strahler_streams_d8_flo[] = "(extract_strahler_streams_d8): flow accumulation adjustment "; -static const char __pyx_k_extract_strahler_streams_d8_see[] = "(extract_strahler_streams_d8): seed the drains"; -static const char __pyx_k_extract_strahler_streams_d8_sta[] = "(extract_strahler_streams_d8): starting upstream walk"; -static const char __pyx_k_extract_strahler_streams_d8_str[] = "(extract_strahler_streams_d8): stream segment creation "; -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_DEFAULT_GTIFF_CREATION_TUPLE_OPT[] = "DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS"; -static const char __pyx_k_DEFAULT_OSR_AXIS_MAPPING_STRATEG[] = "DEFAULT_OSR_AXIS_MAPPING_STRATEGY"; -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_creating_target_flow_accum_raste[] = "creating target flow accum raster layer"; -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_expected_flow_dir_type_of_either[] = "expected flow dir type of either d8 or mfd but got "; -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_outlet_detection_100_complete_co[] = "outlet detection: 100% complete -- committing transaction"; -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_target_watershed_boundary_vector[] = "target_watershed_boundary_vector_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_calculate_subwatershed_boundary_2[] = "(calculate_subwatershed_boundary): watershed building "; -static const char __pyx_k_calculate_subwatershed_boundary_3[] = "(calculate_subwatershed_boundary): watershed building 100% complete"; -static const char __pyx_k_calculate_subwatershed_boundary_4[] = "calculate_subwatershed_boundary"; -static const char __pyx_k_extract_strahler_streams_d8_det_2[] = "(extract_strahler_streams_d8): determine rivers"; -static const char __pyx_k_extract_strahler_streams_d8_dra_2[] = "(extract_strahler_streams_d8): drain seeding complete"; -static const char __pyx_k_extract_strahler_streams_d8_fin_2[] = "(extract_strahler_streams_d8): final pass on stream order "; -static const char __pyx_k_extract_strahler_streams_d8_fin_3[] = "(extract_strahler_streams_d8): final pass on stream order complete"; -static const char __pyx_k_extract_strahler_streams_d8_flo_2[] = "(extract_strahler_streams_d8): flow accumulation adjustment complete"; -static const char __pyx_k_extract_strahler_streams_d8_str_2[] = "(extract_strahler_streams_d8): stream segment creation complete"; -static const char __pyx_k_extract_strahler_streams_d8_str_3[] = "(extract_strahler_streams_d8): stream order processing: "; -static const char __pyx_k_extract_strahler_streams_d8_str_4[] = "(extract_strahler_streams_d8): stream order processing complete"; -static PyObject *__pyx_kp_u_; -static PyObject *__pyx_kp_u_100_0_complete; -static PyObject *__pyx_kp_u_1f; -static PyObject *__pyx_kp_u_1f_complete; -static PyObject *__pyx_n_s_AddGeometry; -static PyObject *__pyx_n_s_AddPoint; -static PyObject *__pyx_n_s_ApplyGeoTransform; -static PyObject *__pyx_kp_u_BIGTIFF_YES; -static PyObject *__pyx_kp_u_BLOCKXSIZE_d; -static PyObject *__pyx_kp_u_BLOCKYSIZE_d; -static PyObject *__pyx_kp_u_COMPRESS_LZW; -static PyObject *__pyx_n_s_CommitTransaction; -static PyObject *__pyx_n_s_Create; -static PyObject *__pyx_n_s_CreateCopy; -static PyObject *__pyx_n_s_CreateFeature; -static PyObject *__pyx_n_s_CreateField; -static PyObject *__pyx_n_s_CreateGeometryFromWkb; -static PyObject *__pyx_n_s_CreateLayer; -static PyObject *__pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT; -static PyObject *__pyx_n_s_DEFAULT_OSR_AXIS_MAPPING_STRATEG; -static PyObject *__pyx_n_s_DeleteFeature; -static PyObject *__pyx_n_s_DeleteField; -static PyObject *__pyx_kp_u_Error_Block_size_is_not_a_power; -static PyObject *__pyx_kp_u_Error_band_ID_s_is_not_a_valid_b; -static PyObject *__pyx_n_s_ExportToWkb; -static PyObject *__pyx_n_s_Feature; -static PyObject *__pyx_n_s_FieldDefn; -static PyObject *__pyx_n_s_FindFieldIndex; -static PyObject *__pyx_n_s_FlushCache; -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_GDT_Unknown; -static PyObject *__pyx_n_u_GPKG; -static PyObject *__pyx_n_u_GTiff; -static PyObject *__pyx_n_s_Geometry; -static PyObject *__pyx_n_s_GetDriverByName; -static PyObject *__pyx_n_s_GetFID; -static PyObject *__pyx_n_s_GetFeature; -static PyObject *__pyx_n_s_GetField; -static PyObject *__pyx_n_s_GetGeometryRef; -static PyObject *__pyx_n_s_GetLayer; -static PyObject *__pyx_n_s_GetLayerDefn; -static PyObject *__pyx_n_s_GetRasterBand; -static PyObject *__pyx_n_u_ID; -static PyObject *__pyx_n_s_ImportError; -static PyObject *__pyx_n_s_ImportFromWkt; -static PyObject *__pyx_n_s_LOGGER; -static PyObject *__pyx_n_s_ManagedRaster; -static PyObject *__pyx_n_s_OFTInteger; -static PyObject *__pyx_n_s_OFTInteger64; -static PyObject *__pyx_n_s_OFTReal; -static PyObject *__pyx_n_s_OF_RASTER; -static PyObject *__pyx_n_s_OF_VECTOR; -static PyObject *__pyx_n_s_OSError; -static PyObject *__pyx_n_s_OpenEx; -static PyObject *__pyx_n_s_ReadAsArray; -static PyObject *__pyx_n_s_ResetReading; -static PyObject *__pyx_n_s_RuntimeError; -static PyObject *__pyx_kp_u_SPARSE_OK_TRUE; -static PyObject *__pyx_n_s_SetAttributeFilter; -static PyObject *__pyx_n_s_SetAxisMappingStrategy; -static PyObject *__pyx_n_s_SetFeature; -static PyObject *__pyx_n_s_SetField; -static PyObject *__pyx_n_s_SetGeometry; -static PyObject *__pyx_n_s_SpatialReference; -static PyObject *__pyx_n_s_StartTransaction; -static PyObject *__pyx_kp_u_TILED_YES; -static PyObject *__pyx_kp_u_This_exception_is_happeningin_C; -static PyObject *__pyx_n_s_TypeError; -static PyObject *__pyx_n_s_Union; -static PyObject *__pyx_n_s_ValueError; -static PyObject *__pyx_n_s_WriteArray; -static PyObject *__pyx_kp_u_Y_m_d__H__M__S; -static PyObject *__pyx_n_s__34; -static PyObject *__pyx_n_s_all_defined; -static PyObject *__pyx_n_s_append; -static PyObject *__pyx_n_s_astype; -static PyObject *__pyx_n_s_autotune_flow_accumulation; -static PyObject *__pyx_n_s_backtrace_set; -static PyObject *__pyx_kp_u_bak_tif; -static PyObject *__pyx_n_s_band_id; -static PyObject *__pyx_n_s_base_datatype; -static PyObject *__pyx_n_s_base_feature_count; -static PyObject *__pyx_n_s_base_nodata; -static PyObject *__pyx_n_s_basename; -static PyObject *__pyx_n_s_block_array; -static PyObject *__pyx_n_s_block_offsets; -static PyObject *__pyx_n_s_block_offsets_list; -static PyObject *__pyx_n_u_block_size; -static PyObject *__pyx_n_s_boundary_list; -static PyObject *__pyx_n_s_boundary_x; -static PyObject *__pyx_n_s_boundary_y; -static PyObject *__pyx_n_s_build_discovery_finish_rasters; -static PyObject *__pyx_n_u_calculate_subwatershed_boundary; -static PyObject *__pyx_kp_u_calculate_subwatershed_boundary_2; -static PyObject *__pyx_kp_u_calculate_subwatershed_boundary_3; -static PyObject *__pyx_n_s_calculate_subwatershed_boundary_4; -static PyObject *__pyx_n_s_cell_to_test; -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_collections; -static PyObject *__pyx_n_s_compatable_dem_raster_path_band; -static PyObject *__pyx_kp_u_compatable_dem_tif; -static PyObject *__pyx_kp_u_compatible_dem_complete; -static PyObject *__pyx_kp_u_complete; -static PyObject *__pyx_kp_u_complete_2; -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_connected_fid; -static PyObject *__pyx_n_s_connected_fids; -static PyObject *__pyx_n_s_connected_upstream_fids; -static PyObject *__pyx_n_s_coord_to_stream_ids; -static PyObject *__pyx_n_s_copy; -static PyObject *__pyx_n_s_copyfile; -static PyObject *__pyx_kp_u_could_not_open; -static PyObject *__pyx_kp_u_couldn_t_remove_temp_dir; -static PyObject *__pyx_kp_u_creating_target_flow_accum_raste; -static PyObject *__pyx_kp_u_creating_visited_raster_layer; -static PyObject *__pyx_n_s_current_pixel; -static PyObject *__pyx_n_s_d; -static PyObject *__pyx_n_u_d; -static PyObject *__pyx_n_u_d8; -static PyObject *__pyx_n_s_d8_flow_dir_managed_raster; -static PyObject *__pyx_n_s_d8_flow_dir_mode; -static PyObject *__pyx_n_s_d8_flow_dir_raster_path_band; -static PyObject *__pyx_n_s_d_n; -static PyObject *__pyx_n_u_datatype; -static PyObject *__pyx_n_s_debug; -static PyObject *__pyx_n_s_defaultdict; -static PyObject *__pyx_n_s_delete_feature; -static PyObject *__pyx_n_s_deleted_set; -static PyObject *__pyx_n_s_delta_x; -static PyObject *__pyx_n_s_delta_y; -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_u_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_detect_outlets; -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_dirname; -static PyObject *__pyx_n_s_discovery; -static PyObject *__pyx_n_s_discovery_count; -static PyObject *__pyx_n_s_discovery_info; -static PyObject *__pyx_n_s_discovery_managed_raster; -static PyObject *__pyx_n_s_discovery_nodata; -static PyObject *__pyx_n_s_discovery_srs; -static PyObject *__pyx_n_s_discovery_stack; -static PyObject *__pyx_kp_u_discovery_tif; -static PyObject *__pyx_kp_u_discovery_time_processing; -static PyObject *__pyx_n_s_discovery_time_raster_path; -static PyObject *__pyx_n_u_dist_to_channel_mfd_work_dir; -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_neighbor; -static PyObject *__pyx_n_s_downhill_slope_array; -static PyObject *__pyx_n_s_downstream_dem; -static PyObject *__pyx_n_s_downstream_feature; -static PyObject *__pyx_n_s_downstream_fid; -static PyObject *__pyx_n_s_downstream_geom; -static PyObject *__pyx_n_s_downstream_order; -static PyObject *__pyx_n_s_downstream_to_upstream_ids; -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_drop_distance; -static PyObject *__pyx_n_u_drop_distance; -static PyObject *__pyx_n_s_drop_distance_collection; -static PyObject *__pyx_n_u_ds_fa; -static PyObject *__pyx_n_s_ds_x; -static PyObject *__pyx_n_u_ds_x; -static PyObject *__pyx_n_s_ds_x_1; -static PyObject *__pyx_n_u_ds_x_1; -static PyObject *__pyx_n_s_ds_y; -static PyObject *__pyx_n_u_ds_y; -static PyObject *__pyx_n_s_ds_y_1; -static PyObject *__pyx_n_u_ds_y_1; -static PyObject *__pyx_n_s_dtype; -static PyObject *__pyx_n_s_edge_dir; -static PyObject *__pyx_n_s_edge_side; -static PyObject *__pyx_n_s_empty; -static PyObject *__pyx_n_s_enumerate; -static PyObject *__pyx_n_s_equal_var; -static PyObject *__pyx_n_s_error; -static PyObject *__pyx_n_s_exception; -static PyObject *__pyx_n_s_exists; -static PyObject *__pyx_kp_u_exists_removing_before_creating; -static PyObject *__pyx_kp_u_expected_flow_dir_type_of_either; -static PyObject *__pyx_n_s_extract_strahler_streams_d8; -static PyObject *__pyx_kp_u_extract_strahler_streams_d8_all; -static PyObject *__pyx_kp_u_extract_strahler_streams_d8_com; -static PyObject *__pyx_kp_u_extract_strahler_streams_d8_det; -static PyObject *__pyx_kp_u_extract_strahler_streams_d8_det_2; -static PyObject *__pyx_kp_u_extract_strahler_streams_d8_dra; -static PyObject *__pyx_kp_u_extract_strahler_streams_d8_dra_2; -static PyObject *__pyx_kp_u_extract_strahler_streams_d8_fin; -static PyObject *__pyx_kp_u_extract_strahler_streams_d8_fin_2; -static PyObject *__pyx_kp_u_extract_strahler_streams_d8_fin_3; -static PyObject *__pyx_kp_u_extract_strahler_streams_d8_flo; -static PyObject *__pyx_kp_u_extract_strahler_streams_d8_flo_2; -static PyObject *__pyx_kp_u_extract_strahler_streams_d8_see; -static PyObject *__pyx_kp_u_extract_strahler_streams_d8_sta; -static PyObject *__pyx_kp_u_extract_strahler_streams_d8_str; -static PyObject *__pyx_kp_u_extract_strahler_streams_d8_str_2; -static PyObject *__pyx_kp_u_extract_strahler_streams_d8_str_3; -static PyObject *__pyx_kp_u_extract_strahler_streams_d8_str_4; -static PyObject *__pyx_n_s_extract_streams_mfd; -static PyObject *__pyx_n_s_feature_id; -static PyObject *__pyx_n_s_fid; -static PyObject *__pyx_n_s_fid_to_order; -static PyObject *__pyx_n_s_fill_height; -static PyObject *__pyx_kp_u_fill_pits; -static PyObject *__pyx_n_s_fill_pits_2; -static PyObject *__pyx_kp_u_fill_pits__s; -static PyObject *__pyx_kp_u_fill_pits_complete; -static PyObject *__pyx_n_s_fill_queue; -static PyObject *__pyx_n_s_fill_value_list; -static PyObject *__pyx_n_s_filled_dem_band; -static PyObject *__pyx_n_s_filled_dem_managed_raster; -static PyObject *__pyx_n_s_filled_dem_raster; -static PyObject *__pyx_kp_u_filter_out_incomplete_divergent; -static PyObject *__pyx_n_s_finish; -static PyObject *__pyx_n_s_finish_coordinate; -static PyObject *__pyx_n_s_finish_managed_raster; -static PyObject *__pyx_n_s_finish_stack; -static PyObject *__pyx_kp_u_finish_tif; -static PyObject *__pyx_n_s_finish_time_raster_path; -static PyObject *__pyx_n_s_flat_region_mask_managed_raster; -static PyObject *__pyx_n_s_flat_region_mask_path; -static PyObject *__pyx_kp_u_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_block; -static PyObject *__pyx_n_s_flow_dir_buffer_array; -static PyObject *__pyx_kp_u_flow_dir_d8; -static PyObject *__pyx_n_s_flow_dir_d8_2; -static PyObject *__pyx_kp_u_flow_dir_d8__s; -static PyObject *__pyx_kp_u_flow_dir_d8_complete; -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_info; -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_u_flow_dir_multiple_flow_dir__s; -static PyObject *__pyx_n_s_flow_dir_n; -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_srs; -static PyObject *__pyx_n_s_flow_dir_type; -static PyObject *__pyx_n_s_flow_dir_weight; -static PyObject *__pyx_n_s_flow_nodata; -static PyObject *__pyx_n_s_flow_pixel; -static PyObject *__pyx_n_s_flow_threshold; -static PyObject *__pyx_kp_u_for_writing; -static PyObject *__pyx_n_s_g0; -static PyObject *__pyx_n_s_g1; -static PyObject *__pyx_n_s_g2; -static PyObject *__pyx_n_s_g3; -static PyObject *__pyx_n_s_g4; -static PyObject *__pyx_n_s_g5; -static PyObject *__pyx_n_s_gdal; -static PyObject *__pyx_n_s_generate_read_bounds; -static PyObject *__pyx_n_s_geoprocessing_core; -static PyObject *__pyx_n_s_geotransform; -static PyObject *__pyx_n_u_geotransform; -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_gpkg_driver; -static PyObject *__pyx_n_s_i; -static PyObject *__pyx_n_u_i; -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_kp_u_in_ManagedRaster_flush; -static PyObject *__pyx_n_s_index; -static PyObject *__pyx_n_s_info; -static PyObject *__pyx_n_s_int32; -static PyObject *__pyx_n_s_int8; -static PyObject *__pyx_n_s_int_max_steps_per_watershed; -static PyObject *__pyx_n_s_is_a_channel; -static PyObject *__pyx_n_s_is_drain; -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_isnan; -static PyObject *__pyx_n_s_iterblocks; -static PyObject *__pyx_n_s_j; -static PyObject *__pyx_n_u_j; -static PyObject *__pyx_n_s_join; -static PyObject *__pyx_n_s_joined_line; -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_left; -static PyObject *__pyx_n_s_left_in; -static PyObject *__pyx_n_s_linemerge; -static PyObject *__pyx_n_s_loads; -static PyObject *__pyx_n_s_local_flow_accum; -static PyObject *__pyx_n_s_log2; -static PyObject *__pyx_n_s_logging; -static PyObject *__pyx_n_s_lower; -static PyObject *__pyx_n_s_main; -static PyObject *__pyx_n_s_makedirs; -static PyObject *__pyx_n_s_mask_nodata; -static PyObject *__pyx_n_s_max; -static PyObject *__pyx_n_s_max_pixel_fill_count; -static PyObject *__pyx_n_s_max_steps_per_watershed; -static PyObject *__pyx_n_s_max_upstream_flow_accum; -static PyObject *__pyx_n_u_mfd; -static PyObject *__pyx_kp_u_mfd_flow_accum_1f_complete; -static PyObject *__pyx_n_u_mfd_flow_dir; -static PyObject *__pyx_n_s_min; -static PyObject *__pyx_n_s_min_flow_accum_threshold; -static PyObject *__pyx_n_s_min_p_val; -static PyObject *__pyx_n_s_mkdtemp; -static PyObject *__pyx_n_s_modified_offset_dict; -static PyObject *__pyx_kp_u_more_times; -static PyObject *__pyx_n_s_multi_line; -static PyObject *__pyx_n_u_n_bands; -static PyObject *__pyx_n_s_n_cols; -static PyObject *__pyx_n_s_n_dir; -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_pixels; -static PyObject *__pyx_n_s_n_points; -static PyObject *__pyx_n_s_n_processed; -static PyObject *__pyx_n_s_n_pushed; -static PyObject *__pyx_n_s_n_rows; -static PyObject *__pyx_n_s_n_slope; -static PyObject *__pyx_n_s_n_steps; -static PyObject *__pyx_n_s_n_x_blocks; -static PyObject *__pyx_n_s_name; -static PyObject *__pyx_n_s_natural_drain_exists; -static PyObject *__pyx_n_s_new_raster_from_base; -static PyObject *__pyx_n_s_next_id; -static PyObject *__pyx_kp_s_no_default___reduce___due_to_non; -static PyObject *__pyx_n_u_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_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_u_numpy_core_multiarray_failed_to; -static PyObject *__pyx_kp_u_numpy_core_umath_failed_to_impor; -static PyObject *__pyx_kp_u_of; -static PyObject *__pyx_n_s_offset_dict; -static PyObject *__pyx_n_s_offset_info; -static PyObject *__pyx_n_s_offset_only; -static PyObject *__pyx_n_s_ogr; -static PyObject *__pyx_n_s_open_set; -static PyObject *__pyx_kp_u_opening; -static PyObject *__pyx_n_s_ops; -static PyObject *__pyx_n_s_options; -static PyObject *__pyx_n_s_order; -static PyObject *__pyx_n_u_order; -static PyObject *__pyx_kp_u_order_1; -static PyObject *__pyx_n_s_order_count; -static PyObject *__pyx_n_s_os; -static PyObject *__pyx_n_s_osgeo; -static PyObject *__pyx_n_s_osr; -static PyObject *__pyx_n_s_osr_axis_mapping_strategy; -static PyObject *__pyx_n_s_out_dir; -static PyObject *__pyx_n_s_out_dir_increase; -static PyObject *__pyx_kp_u_out_of_bounds_for; -static PyObject *__pyx_n_s_outet_basename; -static PyObject *__pyx_n_s_outflow_dir; -static PyObject *__pyx_n_u_outlet; -static PyObject *__pyx_kp_u_outlet_1; -static PyObject *__pyx_n_s_outlet_at_confluence; -static PyObject *__pyx_kp_u_outlet_detection; -static PyObject *__pyx_kp_u_outlet_detection_0_complete; -static PyObject *__pyx_kp_u_outlet_detection_100_complete_co; -static PyObject *__pyx_kp_u_outlet_detection_done; -static PyObject *__pyx_n_s_outlet_feature; -static PyObject *__pyx_n_s_outlet_fid; -static PyObject *__pyx_n_s_outlet_fid_list; -static PyObject *__pyx_n_s_outlet_index; -static PyObject *__pyx_n_s_outlet_layer; -static PyObject *__pyx_n_s_outlet_point; -static PyObject *__pyx_n_s_outlet_vector; -static PyObject *__pyx_n_s_outlet_x; -static PyObject *__pyx_n_u_outlet_x; -static PyObject *__pyx_n_s_outlet_y; -static PyObject *__pyx_n_u_outlet_y; -static PyObject *__pyx_kp_u_outlets_complete; -static PyObject *__pyx_n_s_p_val; -static PyObject *__pyx_n_s_path; -static PyObject *__pyx_n_s_payload; -static PyObject *__pyx_n_s_pit_mask_managed_raster; -static PyObject *__pyx_n_s_pit_mask_path; -static PyObject *__pyx_kp_u_pit_mask_tif; -static PyObject *__pyx_n_s_pit_queue; -static PyObject *__pyx_n_s_pixel; -static PyObject *__pyx_n_s_pixel_count; -static PyObject *__pyx_n_s_pixel_val; -static PyObject *__pyx_kp_u_pixels_complete; -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_u_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_u_plateu_drain_mask_tif; -static PyObject *__pyx_n_s_pop; -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_processed_nodes; -static PyObject *__pyx_n_s_processed_segments; -static PyObject *__pyx_n_s_proj_x; -static PyObject *__pyx_n_s_proj_y; -static PyObject *__pyx_n_u_projection_wkt; -static PyObject *__pyx_n_s_pygeoprocessing; -static PyObject *__pyx_n_s_pygeoprocessing_routing_routing; -static PyObject *__pyx_n_s_pyx_vtable; -static PyObject *__pyx_kp_u_quitting_too_many_steps; -static PyObject *__pyx_n_s_range; -static PyObject *__pyx_kp_u_raster; -static PyObject *__pyx_n_s_raster_coord; -static PyObject *__pyx_n_s_raster_driver; -static PyObject *__pyx_n_s_raster_driver_creation_tuple; -static PyObject *__pyx_n_s_raster_info; -static PyObject *__pyx_n_s_raster_path; -static PyObject *__pyx_n_s_raster_path_band; -static PyObject *__pyx_n_u_raster_size; -static PyObject *__pyx_n_s_raster_srs; -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_remove; -static PyObject *__pyx_kp_u_resulted_in_null_trying; -static PyObject *__pyx_kp_u_retrying; -static PyObject *__pyx_n_s_reverse; -static PyObject *__pyx_n_s_right; -static PyObject *__pyx_n_s_right_in; -static PyObject *__pyx_n_u_river_id; -static PyObject *__pyx_n_s_river_order; -static PyObject *__pyx_n_s_rmtree; -static PyObject *__pyx_n_s_root_height; -static PyObject *__pyx_kp_u_s_is_not_a_file; -static PyObject *__pyx_kp_u_s_is_supposed_to_be_a_raster_ba; -static PyObject *__pyx_n_s_scipy; -static PyObject *__pyx_n_s_scipy_stats; -static PyObject *__pyx_n_s_search_queue; -static PyObject *__pyx_n_s_search_stack; -static PyObject *__pyx_n_s_search_steps; -static PyObject *__pyx_kp_u_segments_complete; -static PyObject *__pyx_n_s_segments_to_process; -static PyObject *__pyx_n_s_setstate; -static PyObject *__pyx_n_s_setstate_cython; -static PyObject *__pyx_n_s_shapely; -static PyObject *__pyx_n_s_shapely_ops; -static PyObject *__pyx_n_s_shapely_wkb; -static PyObject *__pyx_n_s_shutil; -static PyObject *__pyx_n_s_sleep; -static PyObject *__pyx_n_s_sorted; -static PyObject *__pyx_n_s_sorted_stream_order_list; -static PyObject *__pyx_n_s_source_id; -static PyObject *__pyx_n_s_source_point_stack; -static PyObject *__pyx_kp_u_source_points_complete; -static PyObject *__pyx_n_s_source_stream_point; -static PyObject *__pyx_n_s_splitext; -static PyObject *__pyx_kp_s_src_pygeoprocessing_routing_rout; -static PyObject *__pyx_kp_u_starting_search; -static PyObject *__pyx_n_s_stats; -static PyObject *__pyx_n_s_strahler_stream_vector_path; -static PyObject *__pyx_n_s_stream_array; -static PyObject *__pyx_n_s_stream_band; -static PyObject *__pyx_n_s_stream_basename; -static PyObject *__pyx_n_s_stream_feature; -static PyObject *__pyx_n_s_stream_fid; -static PyObject *__pyx_n_u_stream_fid; -static PyObject *__pyx_kp_u_stream_fragments_complete; -static PyObject *__pyx_n_s_stream_layer; -static PyObject *__pyx_n_s_stream_line; -static PyObject *__pyx_n_s_stream_mr; -static PyObject *__pyx_n_s_stream_nodata; -static PyObject *__pyx_n_s_stream_order; -static PyObject *__pyx_n_s_stream_order_list; -static PyObject *__pyx_n_s_stream_raster; -static PyObject *__pyx_n_s_stream_val; -static PyObject *__pyx_n_s_stream_vector; -static PyObject *__pyx_n_s_streams_by_order; -static PyObject *__pyx_n_s_streams_to_process; -static PyObject *__pyx_n_s_streams_to_retest; -static PyObject *__pyx_n_s_strftime; -static PyObject *__pyx_n_s_suffix; -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_discovery_raster_path; -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_finish_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_outlet_vector_path; -static PyObject *__pyx_n_s_target_stream_raster_path; -static PyObject *__pyx_n_s_target_stream_vector_path; -static PyObject *__pyx_n_s_target_watershed_boundary_vector; -static PyObject *__pyx_n_s_tempfile; -static PyObject *__pyx_n_s_terminated_early; -static PyObject *__pyx_n_u_terminated_early; -static PyObject *__pyx_n_s_test; -static PyObject *__pyx_n_s_test_dir; -static PyObject *__pyx_n_s_test_order; -static PyObject *__pyx_n_u_thresh_fa; -static PyObject *__pyx_n_s_time; -static PyObject *__pyx_n_s_tmp_dir; -static PyObject *__pyx_n_s_tmp_dir_root; -static PyObject *__pyx_n_s_tmp_flow_dir_nodata; -static PyObject *__pyx_n_s_tmp_work_dir; -static PyObject *__pyx_n_s_trace_flow_threshold; -static PyObject *__pyx_n_s_trace_threshold_proportion; -static PyObject *__pyx_kp_u_trace_threshold_proportion_shoul; -static PyObject *__pyx_n_s_ttest_ind; -static PyObject *__pyx_n_s_uint8; -static PyObject *__pyx_kp_u_unable_to_open; -static PyObject *__pyx_n_s_upstream_all_defined; -static PyObject *__pyx_n_s_upstream_coord; -static PyObject *__pyx_n_s_upstream_count; -static PyObject *__pyx_n_s_upstream_d8_dir; -static PyObject *__pyx_n_u_upstream_d8_dir; -static PyObject *__pyx_n_s_upstream_dem; -static PyObject *__pyx_n_s_upstream_dirs; -static PyObject *__pyx_n_s_upstream_feature; -static PyObject *__pyx_n_s_upstream_fid; -static PyObject *__pyx_n_s_upstream_fid_list; -static PyObject *__pyx_n_s_upstream_fid_map; -static PyObject *__pyx_n_s_upstream_fids; -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_upstream_id; -static PyObject *__pyx_n_s_upstream_id_list; -static PyObject *__pyx_n_s_upstream_index; -static PyObject *__pyx_n_s_upstream_order; -static PyObject *__pyx_n_s_upstream_stack; -static PyObject *__pyx_n_s_upstream_to_downstream_id; -static PyObject *__pyx_n_u_us_fa; -static PyObject *__pyx_n_s_us_x; -static PyObject *__pyx_n_u_us_x; -static PyObject *__pyx_n_s_us_y; -static PyObject *__pyx_n_u_us_y; -static PyObject *__pyx_n_s_value; -static PyObject *__pyx_n_s_visit_count; -static PyObject *__pyx_n_s_visit_order_stack; -static PyObject *__pyx_n_s_visited_managed_raster; -static PyObject *__pyx_n_s_visited_raster_path; -static PyObject *__pyx_kp_u_visited_tif; -static PyObject *__pyx_n_s_warning; -static PyObject *__pyx_n_s_watershed_basename; -static PyObject *__pyx_n_s_watershed_boundary; -static PyObject *__pyx_n_s_watershed_feature; -static PyObject *__pyx_n_s_watershed_layer; -static PyObject *__pyx_n_s_watershed_polygon; -static PyObject *__pyx_n_s_watershed_vector; -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_u_win_xsize; -static PyObject *__pyx_n_s_win_xsize_border; -static PyObject *__pyx_n_s_win_ysize; -static PyObject *__pyx_n_u_win_ysize; -static PyObject *__pyx_n_s_win_ysize_border; -static PyObject *__pyx_n_s_wkb; -static PyObject *__pyx_n_s_wkbLineString; -static PyObject *__pyx_n_s_wkbLinearRing; -static PyObject *__pyx_n_s_wkbPoint; -static PyObject *__pyx_n_s_wkbPolygon; -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_working_feature; -static PyObject *__pyx_n_s_working_fid; -static PyObject *__pyx_n_s_working_flow_accum_threshold; -static PyObject *__pyx_n_s_working_geom; -static PyObject *__pyx_n_s_working_order; -static PyObject *__pyx_n_s_working_river_id; -static PyObject *__pyx_n_s_working_stack; -static PyObject *__pyx_n_s_workspace_dir; -static PyObject *__pyx_n_s_write_mode; -static PyObject *__pyx_n_s_x; -static PyObject *__pyx_n_u_x; -static PyObject *__pyx_n_s_x_f; -static PyObject *__pyx_n_s_x_l; -static PyObject *__pyx_n_s_x_n; -static PyObject *__pyx_n_s_x_off_border; -static PyObject *__pyx_kp_u_x_out_of_bounds_s; -static PyObject *__pyx_n_s_x_p; -static PyObject *__pyx_n_s_x_u; -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_n_u_xoff; -static PyObject *__pyx_n_s_y_f; -static PyObject *__pyx_n_s_y_l; -static PyObject *__pyx_n_s_y_n; -static PyObject *__pyx_n_s_y_off_border; -static PyObject *__pyx_kp_u_y_out_of_bounds_s; -static PyObject *__pyx_n_s_y_p; -static PyObject *__pyx_n_s_y_u; -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 PyObject *__pyx_n_u_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, long __pyx_v_max_pixel_fill_count, PyObject *__pyx_v_raster_driver_creation_tuple); /* 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_raster_driver_creation_tuple); /* 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_raster_driver_creation_tuple); /* 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_raster_driver_creation_tuple); /* 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_raster_driver_creation_tuple); /* 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_raster_driver_creation_tuple); /* 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_raster_driver_creation_tuple); /* 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_raster_driver_creation_tuple); /* 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 PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_20extract_strahler_streams_d8(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_flow_dir_d8_raster_path_band, PyObject *__pyx_v_flow_accum_raster_path_band, PyObject *__pyx_v_dem_raster_path_band, PyObject *__pyx_v_target_stream_vector_path, long __pyx_v_min_flow_accum_threshold, int __pyx_v_river_order, float __pyx_v_min_p_val, PyObject *__pyx_v_autotune_flow_accumulation, PyObject *__pyx_v_osr_axis_mapping_strategy); /* proto */ -static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_22_build_discovery_finish_rasters(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_flow_dir_d8_raster_path_band, PyObject *__pyx_v_target_discovery_raster_path, PyObject *__pyx_v_target_finish_raster_path); /* proto */ -static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_24calculate_subwatershed_boundary(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_d8_flow_dir_raster_path_band, PyObject *__pyx_v_strahler_stream_vector_path, PyObject *__pyx_v_target_watershed_boundary_vector_path, PyObject *__pyx_v_max_steps_per_watershed, PyObject *__pyx_v_outlet_at_confluence); /* proto */ -static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_26detect_outlets(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_flow_dir_raster_path_band, PyObject *__pyx_v_flow_dir_type, PyObject *__pyx_v_target_outlet_vector_path); /* proto */ -static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_28_delete_feature(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_stream_feature, PyObject *__pyx_v_stream_layer, PyObject *__pyx_v_upstream_to_downstream_id, PyObject *__pyx_v_downstream_to_upstream_ids); /* proto */ -static PyObject *__pyx_tp_new_15pygeoprocessing_7routing_7routing__ManagedRaster(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ -static __Pyx_CachedCFunction __pyx_umethod_PyList_Type_pop = {0, &__pyx_n_s_pop, 0, 0, 0}; -static PyObject *__pyx_float_0_2; -static PyObject *__pyx_float_0_5; -static PyObject *__pyx_float_1_25; -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_5; -static PyObject *__pyx_int_100; -static PyObject *__pyx_int_1000000; -static PyObject *__pyx_int_neg_1; -static PyObject *__pyx_k__4; -static long __pyx_k__5; -static PyObject *__pyx_k__6; -static PyObject *__pyx_k__8; -static PyObject *__pyx_k__10; -static PyObject *__pyx_k__11; -static PyObject *__pyx_k__12; -static PyObject *__pyx_k__13; -static PyObject *__pyx_k__14; -static PyObject *__pyx_k__15; -static PyObject *__pyx_slice__7; -static PyObject *__pyx_tuple__2; -static PyObject *__pyx_tuple__3; -static PyObject *__pyx_tuple__9; -static PyObject *__pyx_tuple__16; -static PyObject *__pyx_tuple__17; -static PyObject *__pyx_tuple__18; -static PyObject *__pyx_tuple__19; -static PyObject *__pyx_tuple__20; -static PyObject *__pyx_tuple__21; -static PyObject *__pyx_tuple__22; -static PyObject *__pyx_tuple__23; -static PyObject *__pyx_tuple__24; -static PyObject *__pyx_tuple__25; -static PyObject *__pyx_tuple__26; -static PyObject *__pyx_tuple__28; -static PyObject *__pyx_tuple__30; -static PyObject *__pyx_tuple__32; -static PyObject *__pyx_tuple__35; -static PyObject *__pyx_tuple__37; -static PyObject *__pyx_tuple__39; -static PyObject *__pyx_tuple__41; -static PyObject *__pyx_tuple__43; -static PyObject *__pyx_tuple__45; -static PyObject *__pyx_tuple__47; -static PyObject *__pyx_tuple__49; -static PyObject *__pyx_tuple__51; -static PyObject *__pyx_tuple__53; -static PyObject *__pyx_tuple__55; -static PyObject *__pyx_codeobj__27; -static PyObject *__pyx_codeobj__29; -static PyObject *__pyx_codeobj__31; -static PyObject *__pyx_codeobj__33; -static PyObject *__pyx_codeobj__36; -static PyObject *__pyx_codeobj__38; -static PyObject *__pyx_codeobj__40; -static PyObject *__pyx_codeobj__42; -static PyObject *__pyx_codeobj__44; -static PyObject *__pyx_codeobj__46; -static PyObject *__pyx_codeobj__48; -static PyObject *__pyx_codeobj__50; -static PyObject *__pyx_codeobj__52; -static PyObject *__pyx_codeobj__54; -static PyObject *__pyx_codeobj__56; -/* Late includes */ - -/* "pygeoprocessing/routing/routing.pyx":169 - * # 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":172 - * # 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":173 - * # 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":172 - * # 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":174 - * 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":175 - * 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":176 - * if lhs.value == rhs.value: - * if lhs.priority > rhs.priority: - * return 1 # <<<<<<<<<<<<<< - * return 0 - * - */ - __pyx_r = 1; - goto __pyx_L0; - - /* "pygeoprocessing/routing/routing.pyx":175 - * return 1 - * if lhs.value == rhs.value: - * if lhs.priority > rhs.priority: # <<<<<<<<<<<<<< - * return 1 - * return 0 - */ - } - - /* "pygeoprocessing/routing/routing.pyx":174 - * if lhs.value > rhs.value: - * return 1 - * if lhs.value == rhs.value: # <<<<<<<<<<<<<< - * if lhs.priority > rhs.priority: - * return 1 - */ - } - - /* "pygeoprocessing/routing/routing.pyx":177 - * if lhs.priority > rhs.priority: - * return 1 - * return 0 # <<<<<<<<<<<<<< - * - * cdef int _is_close(double x, double y, double abs_delta, double rel_delta): - */ - __pyx_r = 0; - goto __pyx_L0; - - /* "pygeoprocessing/routing/routing.pyx":169 - * # 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":179 - * return 0 - * - * cdef int _is_close(double x, double y, double abs_delta, double rel_delta): # <<<<<<<<<<<<<< - * return abs(x-y) <= (abs_delta+rel_delta*abs(y)) - * - */ - -static int __pyx_f_15pygeoprocessing_7routing_7routing__is_close(double __pyx_v_x, double __pyx_v_y, double __pyx_v_abs_delta, double __pyx_v_rel_delta) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_is_close", 0); - - /* "pygeoprocessing/routing/routing.pyx":180 - * - * cdef int _is_close(double x, double y, double abs_delta, double rel_delta): - * return abs(x-y) <= (abs_delta+rel_delta*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)) <= (__pyx_v_abs_delta + (__pyx_v_rel_delta * fabs(__pyx_v_y)))); - goto __pyx_L0; - - /* "pygeoprocessing/routing/routing.pyx":179 - * return 0 - * - * cdef int _is_close(double x, double y, double abs_delta, double rel_delta): # <<<<<<<<<<<<<< - * return abs(x-y) <= (abs_delta+rel_delta*abs(y)) - * - */ - - /* function exit code */ - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pygeoprocessing/routing/routing.pyx":202 - * 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_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 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, 202, __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, 202, __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, 202, __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, 202, __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; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - PyObject *(*__pyx_t_8)(PyObject *); - int __pyx_t_9; - Py_ssize_t __pyx_t_10; - Py_UCS4 __pyx_t_11; - long __pyx_t_12; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "pygeoprocessing/routing/routing.pyx":217 - * None. - * """ - * if not os.path.isfile(raster_path): # <<<<<<<<<<<<<< - * LOGGER.error("%s is not a file.", raster_path) - * return - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 217, __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, 217, __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, 217, __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); - } - } - __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_raster_path); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 217, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __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, 217, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_5 = ((!__pyx_t_4) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":218 - * """ - * 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 218, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_error); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 218, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - __pyx_t_6 = 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_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_kp_u_s_is_not_a_file, __pyx_v_raster_path}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 218, __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_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_kp_u_s_is_not_a_file, __pyx_v_raster_path}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 218, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 218, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_2) { - __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2); __pyx_t_2 = NULL; - } - __Pyx_INCREF(__pyx_kp_u_s_is_not_a_file); - __Pyx_GIVEREF(__pyx_kp_u_s_is_not_a_file); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_kp_u_s_is_not_a_file); - __Pyx_INCREF(__pyx_v_raster_path); - __Pyx_GIVEREF(__pyx_v_raster_path); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_raster_path); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 218, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":219 - * 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":217 - * None. - * """ - * if not os.path.isfile(raster_path): # <<<<<<<<<<<<<< - * LOGGER.error("%s is not a file.", raster_path) - * return - */ - } - - /* "pygeoprocessing/routing/routing.pyx":220 - * 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 220, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 220, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __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); - } - } - __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_3, __pyx_v_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_raster_path); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 220, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_raster_info = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":221 - * 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_u_raster_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 221, __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, 221, __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, 221, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 221, __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_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 221, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_2)->tp_iternext; - index = 0; __pyx_t_7 = __pyx_t_8(__pyx_t_2); if (unlikely(!__pyx_t_7)) goto __pyx_L4_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - index = 1; __pyx_t_3 = __pyx_t_8(__pyx_t_2); if (unlikely(!__pyx_t_3)) goto __pyx_L4_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_2), 2) < 0) __PYX_ERR(0, 221, __pyx_L1_error) - __pyx_t_8 = NULL; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L5_unpacking_done; - __pyx_L4_unpacking_failed:; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_8 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 221, __pyx_L1_error) - __pyx_L5_unpacking_done:; - } - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 221, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 221, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_self->raster_x_size = __pyx_t_6; - __pyx_v_self->raster_y_size = __pyx_t_9; - - /* "pygeoprocessing/routing/routing.pyx":222 - * 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_u_block_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 222, __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, 222, __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_7 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_3 = PyList_GET_ITEM(sequence, 0); - __pyx_t_7 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_7); - #else - __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 222, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 222, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - #endif - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 222, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_2)->tp_iternext; - index = 0; __pyx_t_3 = __pyx_t_8(__pyx_t_2); if (unlikely(!__pyx_t_3)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - index = 1; __pyx_t_7 = __pyx_t_8(__pyx_t_2); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_2), 2) < 0) __PYX_ERR(0, 222, __pyx_L1_error) - __pyx_t_8 = NULL; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L7_unpacking_done; - __pyx_L6_unpacking_failed:; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_8 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 222, __pyx_L1_error) - __pyx_L7_unpacking_done:; - } - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 222, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 222, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_self->block_xsize = __pyx_t_9; - __pyx_v_self->block_ysize = __pyx_t_6; - - /* "pygeoprocessing/routing/routing.pyx":223 - * 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":224 - * 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":226 - * 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, 226, __pyx_L1_error) - if (__Pyx_PyObject_IsTrue(__pyx_t_1)) { - __Pyx_DECREF(__pyx_t_1); - __pyx_t_7 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_n_bands); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 226, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_1 = PyObject_RichCompare(__pyx_v_band_id, __pyx_t_7, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 226, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 226, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_4 = ((!__pyx_t_5) != 0); - if (unlikely(__pyx_t_4)) { - - /* "pygeoprocessing/routing/routing.pyx":231 - * "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_PyUnicode_FormatSafe(__pyx_kp_u_Error_band_ID_s_is_not_a_valid_b, __pyx_v_band_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 231, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_err_msg = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":232 - * "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 - */ - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_print, __pyx_v_err_msg); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 232, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":233 - * "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, 233, __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, 233, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":226 - * 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":234 - * print(err_msg) - * raise ValueError(err_msg) - * self.band_id = band_id # <<<<<<<<<<<<<< - * - * if (self.block_xsize & (self.block_xsize - 1) != 0) or ( - */ - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_v_band_id); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 234, __pyx_L1_error) - __pyx_v_self->band_id = __pyx_t_6; - - /* "pygeoprocessing/routing/routing.pyx":236 - * 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_5 = (((__pyx_v_self->block_xsize & (__pyx_v_self->block_xsize - 1)) != 0) != 0); - if (!__pyx_t_5) { - } else { - __pyx_t_4 = __pyx_t_5; - goto __pyx_L10_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":237 - * - * 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_5 = (((__pyx_v_self->block_ysize & (__pyx_v_self->block_ysize - 1)) != 0) != 0); - __pyx_t_4 = __pyx_t_5; - __pyx_L10_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":236 - * 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 (unlikely(__pyx_t_4)) { - - /* "pygeoprocessing/routing/routing.pyx":243 - * # ValueError in here at least for readability. - * err_msg = ( - * "Error: Block size is not a power of two: " # <<<<<<<<<<<<<< - * "block_xsize: %d, %d, %s. This exception is happening" - * "in Cython, so it will cause a hard seg-fault, but it's" - */ - __pyx_t_1 = PyTuple_New(7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 243, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = 0; - __pyx_t_11 = 127; - __Pyx_INCREF(__pyx_kp_u_Error_Block_size_is_not_a_power); - __pyx_t_10 += 54; - __Pyx_GIVEREF(__pyx_kp_u_Error_Block_size_is_not_a_power); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_Error_Block_size_is_not_a_power); - - /* "pygeoprocessing/routing/routing.pyx":247 - * "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_7 = __Pyx_PyUnicode_From_int(__pyx_v_self->block_xsize, 0, ' ', 'd'); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 247, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_10 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_INCREF(__pyx_kp_u_); - __pyx_t_10 += 2; - __Pyx_GIVEREF(__pyx_kp_u_); - PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_); - __pyx_t_7 = __Pyx_PyUnicode_From_int(__pyx_v_self->block_ysize, 0, ' ', 'd'); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 247, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_10 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_INCREF(__pyx_kp_u_); - __pyx_t_10 += 2; - __Pyx_GIVEREF(__pyx_kp_u_); - PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u_); - __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_raster_path), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 247, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_11 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_11) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_11; - __pyx_t_10 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_INCREF(__pyx_kp_u_This_exception_is_happeningin_C); - __pyx_t_10 += 118; - __Pyx_GIVEREF(__pyx_kp_u_This_exception_is_happeningin_C); - PyTuple_SET_ITEM(__pyx_t_1, 6, __pyx_kp_u_This_exception_is_happeningin_C); - - /* "pygeoprocessing/routing/routing.pyx":243 - * # ValueError in here at least for readability. - * err_msg = ( - * "Error: Block size is not a power of two: " # <<<<<<<<<<<<<< - * "block_xsize: %d, %d, %s. This exception is happening" - * "in Cython, so it will cause a hard seg-fault, but it's" - */ - __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_1, 7, __pyx_t_10, __pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 243, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_err_msg = ((PyObject*)__pyx_t_7); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":248 - * "otherwise meant to be a ValueError." % ( - * self.block_xsize, self.block_ysize, raster_path)) - * print(err_msg) # <<<<<<<<<<<<<< - * raise ValueError(err_msg) - * - */ - __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_print, __pyx_v_err_msg); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 248, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":249 - * 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_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_v_err_msg); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 249, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_Raise(__pyx_t_7, 0, 0, 0); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __PYX_ERR(0, 249, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":236 - * 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":251 - * raise ValueError(err_msg) - * - * self.block_xbits = numpy.log2(self.block_xsize) # <<<<<<<<<<<<<< - * self.block_ybits = numpy.log2(self.block_ysize) - * self.block_nx = ( - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 251, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_log2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 251, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->block_xsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 251, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = NULL; - 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_7 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 251, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 251, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_self->block_xbits = __pyx_t_6; - - /* "pygeoprocessing/routing/routing.pyx":252 - * - * 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 252, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_log2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 252, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->block_ysize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 252, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __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); - } - } - __pyx_t_7 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 252, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 252, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_self->block_ybits = __pyx_t_6; - - /* "pygeoprocessing/routing/routing.pyx":254 - * 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_12 = ((__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, 254, __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_12))) { - PyErr_SetString(PyExc_OverflowError, "value too large to perform division"); - __PYX_ERR(0, 254, __pyx_L1_error) - } - - /* "pygeoprocessing/routing/routing.pyx":253 - * 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_12, __pyx_v_self->block_xsize); - - /* "pygeoprocessing/routing/routing.pyx":256 - * 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_12 = ((__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, 256, __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_12))) { - PyErr_SetString(PyExc_OverflowError, "value too large to perform division"); - __PYX_ERR(0, 256, __pyx_L1_error) - } - - /* "pygeoprocessing/routing/routing.pyx":255 - * 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_12, __pyx_v_self->block_ysize); - - /* "pygeoprocessing/routing/routing.pyx":258 - * 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 = raster_path - * self.write_mode = write_mode - */ - __pyx_v_self->lru_cache = new LRUCache (__pyx_v_15pygeoprocessing_7routing_7routing_MANAGED_RASTER_N_BLOCKS); - - /* "pygeoprocessing/routing/routing.pyx":259 - * - * self.lru_cache = new LRUCache[int, double*](MANAGED_RASTER_N_BLOCKS) - * self.raster_path = raster_path # <<<<<<<<<<<<<< - * self.write_mode = write_mode - * self.closed = 0 - */ - __pyx_t_7 = __pyx_v_raster_path; - __Pyx_INCREF(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - __Pyx_GOTREF(__pyx_v_self->raster_path); - __Pyx_DECREF(__pyx_v_self->raster_path); - __pyx_v_self->raster_path = ((PyObject*)__pyx_t_7); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":260 - * self.lru_cache = new LRUCache[int, double*](MANAGED_RASTER_N_BLOCKS) - * self.raster_path = raster_path - * self.write_mode = write_mode # <<<<<<<<<<<<<< - * self.closed = 0 - * - */ - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_v_write_mode); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 260, __pyx_L1_error) - __pyx_v_self->write_mode = __pyx_t_6; - - /* "pygeoprocessing/routing/routing.pyx":261 - * self.raster_path = raster_path - * self.write_mode = write_mode - * self.closed = 0 # <<<<<<<<<<<<<< - * - * def __dealloc__(self): - */ - __pyx_v_self->closed = 0; - - /* "pygeoprocessing/routing/routing.pyx":202 - * 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_7); - __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":263 - * 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__dealloc__", 0); - - /* "pygeoprocessing/routing/routing.pyx":269 - * 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, 269, __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); - } - } - __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 269, __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":263 - * 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":271 - * 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 ::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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __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":280 - * 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":281 - * """ - * 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":280 - * have undefined behavior. - * """ - * if self.closed: # <<<<<<<<<<<<<< - * return - * self.closed = 1 - */ - } - - /* "pygeoprocessing/routing/routing.pyx":282 - * 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":284 - * 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 284, __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, 284, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":285 - * 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, 285, __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, 285, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 285, __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); - } - } - __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_6); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 284, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":284 - * 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, 284, __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, 284, __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":298 - * 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":299 - * - * 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":300 - * 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":301 - * 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":303 - * 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":304 - * # write the changed value back if desired - * PyMem_Free(deref(it).second) - * inc(it) # <<<<<<<<<<<<<< - * return - * - */ - (void)((++__pyx_v_it)); - } - - /* "pygeoprocessing/routing/routing.pyx":305 - * 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":300 - * 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":307 - * return - * - * raster = gdal.OpenEx( # <<<<<<<<<<<<<< - * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) - * raster_band = raster.GetRasterBand(self.band_id) - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 307, __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, 307, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":308 - * - * raster = gdal.OpenEx( - * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) # <<<<<<<<<<<<<< - * raster_band = raster.GetRasterBand(self.band_id) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 308, __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, 308, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 308, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 308, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyNumber_Or(__pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 308, __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_t_3 = NULL; - __pyx_t_8 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(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); - __pyx_t_8 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_self->raster_path, __pyx_t_4}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 307, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 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_6)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_self->raster_path, __pyx_t_4}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 307, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - { - __pyx_t_5 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 307, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_INCREF(__pyx_v_self->raster_path); - __Pyx_GIVEREF(__pyx_v_self->raster_path); - PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_8, __pyx_v_self->raster_path); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_8, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 307, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_raster = __pyx_t_2; - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":309 - * 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_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 309, __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, 309, __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); - } - } - __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 309, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_raster_band = __pyx_t_2; - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":313 - * # 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":314 - * 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":315 - * 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, 315, __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":318 - * - * # 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, 318, __pyx_L1_error) - __pyx_v_dirty_itr = __pyx_v_self->dirty_blocks.find(__pyx_t_8); - - /* "pygeoprocessing/routing/routing.pyx":319 - * # 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":320 - * 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 - */ - (void)(__pyx_v_self->dirty_blocks.erase(__pyx_v_dirty_itr)); - - /* "pygeoprocessing/routing/routing.pyx":321 - * 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, 321, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = PyNumber_Remainder(__pyx_v_block_index, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 321, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 321, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_block_xi = __pyx_t_8; - - /* "pygeoprocessing/routing/routing.pyx":322 - * 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_6 = __Pyx_PyInt_From_int(__pyx_v_self->block_nx); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 322, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_v_block_index, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 322, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 322, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_block_yi = __pyx_t_8; - - /* "pygeoprocessing/routing/routing.pyx":326 - * # 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":327 - * # 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":329 - * 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":330 - * - * 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":333 - * - * # 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":334 - * # 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":333 - * - * # 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":336 - * 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":337 - * 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":336 - * 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":340 - * 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":341 - * - * 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":342 - * 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, 342, __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":345 - * 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, 345, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - - /* "pygeoprocessing/routing/routing.pyx":346 - * (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_6 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 346, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_5 = PySlice_New(__pyx_int_0, __pyx_t_6, Py_None); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 346, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 346, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_4 = PySlice_New(__pyx_int_0, __pyx_t_6, Py_None); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 346, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 346, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_4); - __pyx_t_5 = 0; - __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_block_array), __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 346, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":345 - * 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_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 345, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":347 - * raster_band.WriteArray( - * block_array[0:win_ysize, 0:win_xsize], - * xoff=xoff, yoff=yoff) # <<<<<<<<<<<<<< - * PyMem_Free(double_buffer) - * inc(it) - */ - __pyx_t_4 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 347, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_xoff); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 347, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_xoff, __pyx_t_5) < 0) __PYX_ERR(0, 347, __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, 347, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_yoff, __pyx_t_5) < 0) __PYX_ERR(0, 347, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pygeoprocessing/routing/routing.pyx":345 - * 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_6, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 345, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __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":319 - * # 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":348 - * 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":349 - * xoff=xoff, yoff=yoff) - * PyMem_Free(double_buffer) - * inc(it) # <<<<<<<<<<<<<< - * raster_band.FlushCache() - * raster_band = None - */ - (void)((++__pyx_v_it)); - } - - /* "pygeoprocessing/routing/routing.pyx":350 - * PyMem_Free(double_buffer) - * inc(it) - * raster_band.FlushCache() # <<<<<<<<<<<<<< - * raster_band = None - * raster = None - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster_band, __pyx_n_s_FlushCache); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 350, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - __pyx_t_5 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 350, __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":351 - * 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":352 - * 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":271 - * 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":354 - * 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 ::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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("set", 0); - - /* "pygeoprocessing/routing/routing.pyx":356 - * 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":357 - * """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_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 357, __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, 357, __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, 357, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = PyUnicode_Format(__pyx_kp_u_x_out_of_bounds_s, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 357, __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); - } - } - __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 357, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":356 - * 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":358 - * 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":359 - * 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_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 359, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_error); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 359, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __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, 359, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = PyUnicode_Format(__pyx_kp_u_y_out_of_bounds_s, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 359, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 359, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":358 - * 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":360 - * 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":361 - * 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":363 - * 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":364 - * # 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":365 - * 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, 365, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":364 - * # 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":368 - * 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":370 - * ((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":371 - * (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":372 - * 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":373 - * 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, 373, __pyx_L1_error) - } - - /* "pygeoprocessing/routing/routing.pyx":372 - * 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":370 - * ((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":354 - * 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_WriteUnraisable("pygeoprocessing.routing.routing._ManagedRaster.set", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); - __pyx_L0:; - __Pyx_RefNannyFinishContext(); -} - -/* "pygeoprocessing/routing/routing.pyx":375 - * 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("get", 0); - - /* "pygeoprocessing/routing/routing.pyx":377 - * 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":378 - * """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_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 378, __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, 378, __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, 378, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = PyUnicode_Format(__pyx_kp_u_x_out_of_bounds_s, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 378, __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); - } - } - __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 378, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":377 - * 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":379 - * 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":380 - * 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_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_error); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __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, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = PyUnicode_Format(__pyx_kp_u_y_out_of_bounds_s, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":379 - * 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":381 - * 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":382 - * 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":384 - * 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":385 - * # 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":386 - * 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, 386, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":385 - * # 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":388 - * 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":375 - * 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_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":392 - * (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; - PyObject *__pyx_v_n_attempts = NULL; - std::set ::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; - int __pyx_t_20; - Py_ssize_t __pyx_t_21; - Py_UCS4 __pyx_t_22; - double *__pyx_t_23; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __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":393 - * - * 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, 393, __pyx_L1_error) - } - __pyx_v_block_xi = __Pyx_mod_int(__pyx_v_block_index, __pyx_v_self->block_nx); - - /* "pygeoprocessing/routing/routing.pyx":394 - * 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, 394, __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, 394, __pyx_L1_error) - } - __pyx_v_block_yi = __Pyx_div_int(__pyx_v_block_index, __pyx_v_self->block_nx); - - /* "pygeoprocessing/routing/routing.pyx":397 - * - * # 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":398 - * # 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":409 - * # 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":410 - * # 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":413 - * - * # 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":414 - * # 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":413 - * - * # 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":415 - * 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":416 - * 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":415 - * 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":418 - * 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_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 418, __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, 418, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 418, __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, 418, __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, 418, __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, 418, __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, 418, __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, 418, __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":419 - * - * 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, 419, __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, 419, __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); - } - } - __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_7); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 419, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_raster_band = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":420 - * 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, 420, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - - /* "pygeoprocessing/routing/routing.pyx":421 - * 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_7 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 421, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_xoff); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 421, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_xoff, __pyx_t_6) < 0) __PYX_ERR(0, 421, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_yoff); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 421, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_yoff, __pyx_t_6) < 0) __PYX_ERR(0, 421, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 421, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_win_xsize, __pyx_t_6) < 0) __PYX_ERR(0, 421, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":422 - * 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_6 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 422, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_win_ysize, __pyx_t_6) < 0) __PYX_ERR(0, 421, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":420 - * 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_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_empty_tuple, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 420, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":422 - * 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_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_astype); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 422, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_numpy); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 422, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_float64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 422, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 422, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 422, __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, 420, __pyx_L1_error) - } - __pyx_t_8 = 0; - __pyx_v_block_array = ((PyArrayObject *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":423 - * xoff=xoff, yoff=yoff, win_xsize=win_xsize, - * win_ysize=win_ysize).astype(numpy.float64) - * raster_band = None # <<<<<<<<<<<<<< - * raster = None - * double_buffer = PyMem_Malloc( - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_raster_band, Py_None); - - /* "pygeoprocessing/routing/routing.pyx":424 - * win_ysize=win_ysize).astype(numpy.float64) - * raster_band = None - * raster = None # <<<<<<<<<<<<<< - * double_buffer = 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":425 - * raster_band = None - * raster = None - * double_buffer = 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":427 - * double_buffer = 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":428 - * (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":430 - * 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( - * block_index, 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, 430, __pyx_L1_error) - } - - /* "pygeoprocessing/routing/routing.pyx":429 - * 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":431 - * double_buffer[(yi_copy << self.block_xbits)+xi_copy] = ( - * block_array[yi_copy, xi_copy]) - * self.lru_cache.put( # <<<<<<<<<<<<<< - * block_index, 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":434 - * block_index, double_buffer, removed_value_list) - * - * if self.write_mode: # <<<<<<<<<<<<<< - * n_attempts = 5 - * while True: - */ - __pyx_t_2 = (__pyx_v_self->write_mode != 0); - if (__pyx_t_2) { - - /* "pygeoprocessing/routing/routing.pyx":435 - * - * if self.write_mode: - * n_attempts = 5 # <<<<<<<<<<<<<< - * while True: - * raster = gdal.OpenEx( - */ - __Pyx_INCREF(__pyx_int_5); - __pyx_v_n_attempts = __pyx_int_5; - - /* "pygeoprocessing/routing/routing.pyx":436 - * if self.write_mode: - * n_attempts = 5 - * while True: # <<<<<<<<<<<<<< - * raster = gdal.OpenEx( - * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) - */ - while (1) { - - /* "pygeoprocessing/routing/routing.pyx":437 - * n_attempts = 5 - * while True: - * raster = gdal.OpenEx( # <<<<<<<<<<<<<< - * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) - * if raster is None: - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 437, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 437, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":438 - * while True: - * raster = gdal.OpenEx( - * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) # <<<<<<<<<<<<<< - * if raster is None: - * if n_attempts == 0: - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 438, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_GA_Update); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 438, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 438, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 438, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyNumber_Or(__pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 438, __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_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_7}; - __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, 437, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 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[3] = {__pyx_t_4, __pyx_v_self->raster_path, __pyx_t_7}; - __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, 437, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - { - __pyx_t_6 = PyTuple_New(2+__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 437, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (__pyx_t_4) { - __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 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_6, 0+__pyx_t_1, __pyx_v_self->raster_path); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_1, __pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 437, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF_SET(__pyx_v_raster, __pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":439 - * raster = gdal.OpenEx( - * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) - * if raster is None: # <<<<<<<<<<<<<< - * if n_attempts == 0: - * raise RuntimeError( - */ - __pyx_t_2 = (__pyx_v_raster == Py_None); - __pyx_t_20 = (__pyx_t_2 != 0); - if (__pyx_t_20) { - - /* "pygeoprocessing/routing/routing.pyx":440 - * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) - * if raster is None: - * if n_attempts == 0: # <<<<<<<<<<<<<< - * raise RuntimeError( - * f'could not open {self.raster_path} for writing') - */ - __pyx_t_3 = __Pyx_PyInt_EqObjC(__pyx_v_n_attempts, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 440, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_20 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_20 < 0)) __PYX_ERR(0, 440, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(__pyx_t_20)) { - - /* "pygeoprocessing/routing/routing.pyx":442 - * if n_attempts == 0: - * raise RuntimeError( - * f'could not open {self.raster_path} for writing') # <<<<<<<<<<<<<< - * LOGGER.warning( - * f'opening {self.raster_path} resulted in null, ' - */ - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 442, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_21 = 0; - __pyx_t_22 = 127; - __Pyx_INCREF(__pyx_kp_u_could_not_open); - __pyx_t_21 += 15; - __Pyx_GIVEREF(__pyx_kp_u_could_not_open); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_u_could_not_open); - __pyx_t_5 = __Pyx_PyObject_FormatSimple(__pyx_v_self->raster_path, __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 442, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_22 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_22) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_22; - __pyx_t_21 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_5); - __pyx_t_5 = 0; - __Pyx_INCREF(__pyx_kp_u_for_writing); - __pyx_t_21 += 12; - __Pyx_GIVEREF(__pyx_kp_u_for_writing); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_kp_u_for_writing); - __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_3, 3, __pyx_t_21, __pyx_t_22); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 442, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":441 - * if raster is None: - * if n_attempts == 0: - * raise RuntimeError( # <<<<<<<<<<<<<< - * f'could not open {self.raster_path} for writing') - * LOGGER.warning( - */ - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_RuntimeError, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 441, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 441, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":440 - * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) - * if raster is None: - * if n_attempts == 0: # <<<<<<<<<<<<<< - * raise RuntimeError( - * f'could not open {self.raster_path} for writing') - */ - } - - /* "pygeoprocessing/routing/routing.pyx":443 - * raise RuntimeError( - * f'could not open {self.raster_path} for writing') - * LOGGER.warning( # <<<<<<<<<<<<<< - * f'opening {self.raster_path} resulted in null, ' - * f'trying {n_attempts} more times.') - */ - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 443, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_warning); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 443, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pygeoprocessing/routing/routing.pyx":444 - * f'could not open {self.raster_path} for writing') - * LOGGER.warning( - * f'opening {self.raster_path} resulted in null, ' # <<<<<<<<<<<<<< - * f'trying {n_attempts} more times.') - * n_attempts -= 1 - */ - __pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 444, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_21 = 0; - __pyx_t_22 = 127; - __Pyx_INCREF(__pyx_kp_u_opening); - __pyx_t_21 += 8; - __Pyx_GIVEREF(__pyx_kp_u_opening); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_kp_u_opening); - __pyx_t_7 = __Pyx_PyObject_FormatSimple(__pyx_v_self->raster_path, __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 444, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_22 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_22) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_22; - __pyx_t_21 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_INCREF(__pyx_kp_u_resulted_in_null_trying); - __pyx_t_21 += 26; - __Pyx_GIVEREF(__pyx_kp_u_resulted_in_null_trying); - PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_kp_u_resulted_in_null_trying); - - /* "pygeoprocessing/routing/routing.pyx":445 - * LOGGER.warning( - * f'opening {self.raster_path} resulted in null, ' - * f'trying {n_attempts} more times.') # <<<<<<<<<<<<<< - * n_attempts -= 1 - * time.sleep(0.5) - */ - __pyx_t_7 = __Pyx_PyObject_FormatSimple(__pyx_v_n_attempts, __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 445, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_22 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_22) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_22; - __pyx_t_21 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_INCREF(__pyx_kp_u_more_times); - __pyx_t_21 += 12; - __Pyx_GIVEREF(__pyx_kp_u_more_times); - PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_kp_u_more_times); - - /* "pygeoprocessing/routing/routing.pyx":444 - * f'could not open {self.raster_path} for writing') - * LOGGER.warning( - * f'opening {self.raster_path} resulted in null, ' # <<<<<<<<<<<<<< - * f'trying {n_attempts} more times.') - * n_attempts -= 1 - */ - __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_5, 5, __pyx_t_21, __pyx_t_22); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 444, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 443, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":446 - * f'opening {self.raster_path} resulted in null, ' - * f'trying {n_attempts} more times.') - * n_attempts -= 1 # <<<<<<<<<<<<<< - * time.sleep(0.5) - * raster_band = raster.GetRasterBand(self.band_id) - */ - __pyx_t_3 = __Pyx_PyInt_SubtractObjC(__pyx_v_n_attempts, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 446, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF_SET(__pyx_v_n_attempts, __pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":447 - * f'trying {n_attempts} more times.') - * n_attempts -= 1 - * time.sleep(0.5) # <<<<<<<<<<<<<< - * raster_band = raster.GetRasterBand(self.band_id) - * break - */ - __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_time); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 447, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_sleep); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 447, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_6, __pyx_float_0_5) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_float_0_5); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 447, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":439 - * raster = gdal.OpenEx( - * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) - * if raster is None: # <<<<<<<<<<<<<< - * if n_attempts == 0: - * raise RuntimeError( - */ - } - - /* "pygeoprocessing/routing/routing.pyx":448 - * n_attempts -= 1 - * time.sleep(0.5) - * raster_band = raster.GetRasterBand(self.band_id) # <<<<<<<<<<<<<< - * break - * - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 448, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_self->band_id); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 448, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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); - } - } - __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 448, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF_SET(__pyx_v_raster_band, __pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":449 - * time.sleep(0.5) - * raster_band = raster.GetRasterBand(self.band_id) - * break # <<<<<<<<<<<<<< - * - * block_array = numpy.empty( - */ - goto __pyx_L11_break; - } - __pyx_L11_break:; - - /* "pygeoprocessing/routing/routing.pyx":434 - * block_index, double_buffer, removed_value_list) - * - * if self.write_mode: # <<<<<<<<<<<<<< - * n_attempts = 5 - * while True: - */ - } - - /* "pygeoprocessing/routing/routing.pyx":451 - * break - * - * block_array = numpy.empty( # <<<<<<<<<<<<<< - * (self.block_ysize, self.block_xsize), dtype=numpy.double) - * while not removed_value_list.empty(): - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 451, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 451, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":452 - * - * 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, 452, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_self->block_xsize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 452, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 452, __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_6); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_6); - __pyx_t_3 = 0; - __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":451 - * break - * - * block_array = numpy.empty( # <<<<<<<<<<<<<< - * (self.block_ysize, self.block_xsize), dtype=numpy.double) - * while not removed_value_list.empty(): - */ - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 451, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); - __pyx_t_5 = 0; - - /* "pygeoprocessing/routing/routing.pyx":452 - * - * 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, 452, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 452, __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, 452, __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, 452, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":451 - * break - * - * 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_7, __pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 451, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __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; - if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 451, __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, 451, __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":453 - * 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_20 = ((!(__pyx_v_removed_value_list.empty() != 0)) != 0); - if (!__pyx_t_20) break; - - /* "pygeoprocessing/routing/routing.pyx":455 - * 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_23 = __pyx_v_removed_value_list.front().second; - __pyx_v_double_buffer = __pyx_t_23; - - /* "pygeoprocessing/routing/routing.pyx":457 - * double_buffer = removed_value_list.front().second - * - * if self.write_mode: # <<<<<<<<<<<<<< - * block_index = removed_value_list.front().first - * - */ - __pyx_t_20 = (__pyx_v_self->write_mode != 0); - if (__pyx_t_20) { - - /* "pygeoprocessing/routing/routing.pyx":458 - * - * 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":461 - * - * # 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":462 - * # 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_20 = ((__pyx_v_dirty_itr != __pyx_v_self->dirty_blocks.end()) != 0); - if (__pyx_t_20) { - - /* "pygeoprocessing/routing/routing.pyx":463 - * 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 - */ - (void)(__pyx_v_self->dirty_blocks.erase(__pyx_v_dirty_itr)); - - /* "pygeoprocessing/routing/routing.pyx":465 - * 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, 465, __pyx_L1_error) - } - __pyx_v_block_xi = __Pyx_mod_int(__pyx_v_block_index, __pyx_v_self->block_nx); - - /* "pygeoprocessing/routing/routing.pyx":466 - * - * 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, 466, __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, 466, __pyx_L1_error) - } - __pyx_v_block_yi = __Pyx_div_int(__pyx_v_block_index, __pyx_v_self->block_nx); - - /* "pygeoprocessing/routing/routing.pyx":468 - * 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":469 - * - * 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":471 - * 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":472 - * - * 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":474 - * 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_20 = (((__pyx_v_xoff + __pyx_v_win_xsize) > __pyx_v_self->raster_x_size) != 0); - if (__pyx_t_20) { - - /* "pygeoprocessing/routing/routing.pyx":475 - * - * 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":474 - * 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":477 - * 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_20 = (((__pyx_v_yoff + __pyx_v_win_ysize) > __pyx_v_self->raster_y_size) != 0); - if (__pyx_t_20) { - - /* "pygeoprocessing/routing/routing.pyx":478 - * 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":477 - * 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":481 - * 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":482 - * - * 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":483 - * 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_18 = __pyx_v_yi_copy; - __pyx_t_17 = __pyx_v_xi_copy; - __pyx_t_19 = -1; - if (__pyx_t_18 < 0) { - __pyx_t_18 += __pyx_pybuffernd_block_array.diminfo[0].shape; - if (unlikely(__pyx_t_18 < 0)) __pyx_t_19 = 0; - } else if (unlikely(__pyx_t_18 >= __pyx_pybuffernd_block_array.diminfo[0].shape)) __pyx_t_19 = 0; - if (__pyx_t_17 < 0) { - __pyx_t_17 += __pyx_pybuffernd_block_array.diminfo[1].shape; - if (unlikely(__pyx_t_17 < 0)) __pyx_t_19 = 1; - } else if (unlikely(__pyx_t_17 >= __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, 483, __pyx_L1_error) - } - *__Pyx_BufPtrStrided2d(double *, __pyx_pybuffernd_block_array.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_block_array.diminfo[0].strides, __pyx_t_17, __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":485 - * 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, 485, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - - /* "pygeoprocessing/routing/routing.pyx":486 - * (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, 486, __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, 486, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __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, 486, __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, 486, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 486, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_7); - __pyx_t_6 = 0; - __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_block_array), __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 486, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pygeoprocessing/routing/routing.pyx":485 - * 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, 485, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":487 - * 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_7 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 487, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_xoff); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 487, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_xoff, __pyx_t_6) < 0) __PYX_ERR(0, 487, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_yoff); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 487, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_yoff, __pyx_t_6) < 0) __PYX_ERR(0, 487, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":485 - * 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_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 485, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":462 - * # 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":457 - * double_buffer = removed_value_list.front().second - * - * if self.write_mode: # <<<<<<<<<<<<<< - * block_index = removed_value_list.front().first - * - */ - } - - /* "pygeoprocessing/routing/routing.pyx":488 - * 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":489 - * 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":491 - * removed_value_list.pop_front() - * - * if self.write_mode: # <<<<<<<<<<<<<< - * raster_band = None - * raster = None - */ - __pyx_t_20 = (__pyx_v_self->write_mode != 0); - if (__pyx_t_20) { - - /* "pygeoprocessing/routing/routing.pyx":492 - * - * 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":493 - * if self.write_mode: - * raster_band = None - * raster = None # <<<<<<<<<<<<<< - * - * cdef void flush(self) except *: - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_raster, Py_None); - - /* "pygeoprocessing/routing/routing.pyx":491 - * removed_value_list.pop_front() - * - * if self.write_mode: # <<<<<<<<<<<<<< - * raster_band = None - * raster = None - */ - } - - /* "pygeoprocessing/routing/routing.pyx":392 - * (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_XDECREF(__pyx_v_n_attempts); - __Pyx_RefNannyFinishContext(); -} - -/* "pygeoprocessing/routing/routing.pyx":495 - * raster = None - * - * cdef void flush(self) except *: # <<<<<<<<<<<<<< - * cdef clist[BlockBufferPair] removed_value_list - * cdef double *double_buffer - */ - -static void __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_flush(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_self) { - std::list<__pyx_t_15pygeoprocessing_7routing_7routing_BlockBufferPair> __pyx_v_removed_value_list; - double *__pyx_v_double_buffer; - std::set ::iterator __pyx_v_dirty_itr; - 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_win_xsize; - int __pyx_v_win_ysize; - PyObject *__pyx_v_raster_band = NULL; - PyObject *__pyx_v_max_retries = NULL; - PyObject *__pyx_v_raster = NULL; - PyObject *__pyx_v_block_array = NULL; - PyObject *__pyx_v_xi_copy = NULL; - PyObject *__pyx_v_yi_copy = 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; - int __pyx_t_7; - int __pyx_t_8; - Py_ssize_t __pyx_t_9; - Py_UCS4 __pyx_t_10; - double *__pyx_t_11; - PyObject *(*__pyx_t_12)(PyObject *); - Py_ssize_t __pyx_t_13; - PyObject *(*__pyx_t_14)(PyObject *); - Py_ssize_t __pyx_t_15; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("flush", 0); - - /* "pygeoprocessing/routing/routing.pyx":502 - * cdef int xoff, yoff, win_xsize, win_ysize - * - * self.lru_cache.clean(removed_value_list, self.lru_cache.size()) # <<<<<<<<<<<<<< - * - * raster_band = None - */ - __pyx_v_self->lru_cache->clean(__pyx_v_removed_value_list, __pyx_v_self->lru_cache->size()); - - /* "pygeoprocessing/routing/routing.pyx":504 - * self.lru_cache.clean(removed_value_list, self.lru_cache.size()) - * - * raster_band = None # <<<<<<<<<<<<<< - * if self.write_mode: - * max_retries = 5 - */ - __Pyx_INCREF(Py_None); - __pyx_v_raster_band = Py_None; - - /* "pygeoprocessing/routing/routing.pyx":505 - * - * raster_band = None - * if self.write_mode: # <<<<<<<<<<<<<< - * max_retries = 5 - * while max_retries > 0: - */ - __pyx_t_1 = (__pyx_v_self->write_mode != 0); - if (__pyx_t_1) { - - /* "pygeoprocessing/routing/routing.pyx":506 - * raster_band = None - * if self.write_mode: - * max_retries = 5 # <<<<<<<<<<<<<< - * while max_retries > 0: - * raster = gdal.OpenEx( - */ - __Pyx_INCREF(__pyx_int_5); - __pyx_v_max_retries = __pyx_int_5; - - /* "pygeoprocessing/routing/routing.pyx":507 - * if self.write_mode: - * max_retries = 5 - * while max_retries > 0: # <<<<<<<<<<<<<< - * raster = gdal.OpenEx( - * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) - */ - while (1) { - __pyx_t_2 = PyObject_RichCompare(__pyx_v_max_retries, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 507, __pyx_L1_error) - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 507, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (!__pyx_t_1) break; - - /* "pygeoprocessing/routing/routing.pyx":508 - * max_retries = 5 - * while max_retries > 0: - * raster = gdal.OpenEx( # <<<<<<<<<<<<<< - * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) - * if raster is None: - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 508, __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, 508, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":509 - * while max_retries > 0: - * raster = gdal.OpenEx( - * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) # <<<<<<<<<<<<<< - * if raster is None: - * max_retries -= 1 - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 509, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_GA_Update); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 509, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 509, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 509, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Or(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 509, __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_t_6 = NULL; - __pyx_t_7 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_6); - __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_6, __pyx_v_self->raster_path, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 508, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_2); - __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[3] = {__pyx_t_6, __pyx_v_self->raster_path, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 508, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - { - __pyx_t_5 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 508, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (__pyx_t_6) { - __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6); __pyx_t_6 = NULL; - } - __Pyx_INCREF(__pyx_v_self->raster_path); - __Pyx_GIVEREF(__pyx_v_self->raster_path); - PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_7, __pyx_v_self->raster_path); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_7, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 508, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF_SET(__pyx_v_raster, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":510 - * raster = gdal.OpenEx( - * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) - * if raster is None: # <<<<<<<<<<<<<< - * max_retries -= 1 - * LOGGER.error( - */ - __pyx_t_1 = (__pyx_v_raster == Py_None); - __pyx_t_8 = (__pyx_t_1 != 0); - if (__pyx_t_8) { - - /* "pygeoprocessing/routing/routing.pyx":511 - * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) - * if raster is None: - * max_retries -= 1 # <<<<<<<<<<<<<< - * LOGGER.error( - * f'unable to open {self.raster_path}, retrying...') - */ - __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_v_max_retries, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 511, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF_SET(__pyx_v_max_retries, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":512 - * if raster is None: - * max_retries -= 1 - * LOGGER.error( # <<<<<<<<<<<<<< - * f'unable to open {self.raster_path}, retrying...') - * time.sleep(0.2) - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 512, __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, 512, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":513 - * max_retries -= 1 - * LOGGER.error( - * f'unable to open {self.raster_path}, retrying...') # <<<<<<<<<<<<<< - * time.sleep(0.2) - * continue - */ - __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 513, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_9 = 0; - __pyx_t_10 = 127; - __Pyx_INCREF(__pyx_kp_u_unable_to_open); - __pyx_t_9 += 15; - __Pyx_GIVEREF(__pyx_kp_u_unable_to_open); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_u_unable_to_open); - __pyx_t_3 = __Pyx_PyObject_FormatSimple(__pyx_v_self->raster_path, __pyx_empty_unicode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 513, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_10 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) > __pyx_t_10) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) : __pyx_t_10; - __pyx_t_9 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); - __pyx_t_3 = 0; - __Pyx_INCREF(__pyx_kp_u_retrying); - __pyx_t_9 += 13; - __Pyx_GIVEREF(__pyx_kp_u_retrying); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_kp_u_retrying); - __pyx_t_3 = __Pyx_PyUnicode_Join(__pyx_t_4, 3, __pyx_t_9, __pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 513, __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_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_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 512, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":514 - * LOGGER.error( - * f'unable to open {self.raster_path}, retrying...') - * time.sleep(0.2) # <<<<<<<<<<<<<< - * continue - * break - */ - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 514, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_sleep); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 514, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = NULL; - 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_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_float_0_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_float_0_2); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 514, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":515 - * f'unable to open {self.raster_path}, retrying...') - * time.sleep(0.2) - * continue # <<<<<<<<<<<<<< - * break - * if max_retries == 0: - */ - goto __pyx_L4_continue; - - /* "pygeoprocessing/routing/routing.pyx":510 - * raster = gdal.OpenEx( - * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) - * if raster is None: # <<<<<<<<<<<<<< - * max_retries -= 1 - * LOGGER.error( - */ - } - - /* "pygeoprocessing/routing/routing.pyx":516 - * time.sleep(0.2) - * continue - * break # <<<<<<<<<<<<<< - * if max_retries == 0: - * raise ValueError( - */ - goto __pyx_L5_break; - __pyx_L4_continue:; - } - __pyx_L5_break:; - - /* "pygeoprocessing/routing/routing.pyx":517 - * continue - * break - * if max_retries == 0: # <<<<<<<<<<<<<< - * raise ValueError( - * f'unable to open {self.raster_path} in ' - */ - __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_v_max_retries, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 517, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 517, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(__pyx_t_8)) { - - /* "pygeoprocessing/routing/routing.pyx":519 - * if max_retries == 0: - * raise ValueError( - * f'unable to open {self.raster_path} in ' # <<<<<<<<<<<<<< - * 'ManagedRaster.flush') - * raster_band = raster.GetRasterBand(self.band_id) - */ - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 519, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_9 = 0; - __pyx_t_10 = 127; - __Pyx_INCREF(__pyx_kp_u_unable_to_open); - __pyx_t_9 += 15; - __Pyx_GIVEREF(__pyx_kp_u_unable_to_open); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_u_unable_to_open); - __pyx_t_3 = __Pyx_PyObject_FormatSimple(__pyx_v_self->raster_path, __pyx_empty_unicode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 519, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_10 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) > __pyx_t_10) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) : __pyx_t_10; - __pyx_t_9 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); - __pyx_t_3 = 0; - __Pyx_INCREF(__pyx_kp_u_in_ManagedRaster_flush); - __pyx_t_9 += 23; - __Pyx_GIVEREF(__pyx_kp_u_in_ManagedRaster_flush); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_kp_u_in_ManagedRaster_flush); - __pyx_t_3 = __Pyx_PyUnicode_Join(__pyx_t_2, 3, __pyx_t_9, __pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 519, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":518 - * break - * if max_retries == 0: - * raise ValueError( # <<<<<<<<<<<<<< - * f'unable to open {self.raster_path} in ' - * 'ManagedRaster.flush') - */ - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 518, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 518, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":517 - * continue - * break - * if max_retries == 0: # <<<<<<<<<<<<<< - * raise ValueError( - * f'unable to open {self.raster_path} in ' - */ - } - - /* "pygeoprocessing/routing/routing.pyx":521 - * f'unable to open {self.raster_path} in ' - * 'ManagedRaster.flush') - * raster_band = raster.GetRasterBand(self.band_id) # <<<<<<<<<<<<<< - * - * block_array = numpy.empty( - */ - if (unlikely(!__pyx_v_raster)) { __Pyx_RaiseUnboundLocalError("raster"); __PYX_ERR(0, 521, __pyx_L1_error) } - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 521, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_self->band_id); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 521, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __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); - } - } - __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 521, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF_SET(__pyx_v_raster_band, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":505 - * - * raster_band = None - * if self.write_mode: # <<<<<<<<<<<<<< - * max_retries = 5 - * while max_retries > 0: - */ - } - - /* "pygeoprocessing/routing/routing.pyx":523 - * 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 523, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 523, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":524 - * - * 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_2 = __Pyx_PyInt_From_int(__pyx_v_self->block_ysize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 524, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_self->block_xsize); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 524, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 524, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5); - __pyx_t_2 = 0; - __pyx_t_5 = 0; - - /* "pygeoprocessing/routing/routing.pyx":523 - * 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_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 523, __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 = 0; - - /* "pygeoprocessing/routing/routing.pyx":524 - * - * 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_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 524, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 524, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_double); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 524, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 524, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":523 - * 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_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 523, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_block_array = __pyx_t_6; - __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":525 - * 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_8 = ((!(__pyx_v_removed_value_list.empty() != 0)) != 0); - if (!__pyx_t_8) break; - - /* "pygeoprocessing/routing/routing.pyx":527 - * 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_11 = __pyx_v_removed_value_list.front().second; - __pyx_v_double_buffer = __pyx_t_11; - - /* "pygeoprocessing/routing/routing.pyx":529 - * double_buffer = removed_value_list.front().second - * - * if self.write_mode: # <<<<<<<<<<<<<< - * block_index = removed_value_list.front().first - * - */ - __pyx_t_8 = (__pyx_v_self->write_mode != 0); - if (__pyx_t_8) { - - /* "pygeoprocessing/routing/routing.pyx":530 - * - * if self.write_mode: - * block_index = removed_value_list.front().first # <<<<<<<<<<<<<< - * - * # write back the block if it's dirty - */ - __pyx_t_7 = __pyx_v_removed_value_list.front().first; - __pyx_v_block_index = __pyx_t_7; - - /* "pygeoprocessing/routing/routing.pyx":533 - * - * # 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":534 - * # 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_8 = ((__pyx_v_dirty_itr != __pyx_v_self->dirty_blocks.end()) != 0); - if (__pyx_t_8) { - - /* "pygeoprocessing/routing/routing.pyx":535 - * 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 - */ - (void)(__pyx_v_self->dirty_blocks.erase(__pyx_v_dirty_itr)); - - /* "pygeoprocessing/routing/routing.pyx":537 - * 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, 537, __pyx_L1_error) - } - __pyx_v_block_xi = __Pyx_mod_int(__pyx_v_block_index, __pyx_v_self->block_nx); - - /* "pygeoprocessing/routing/routing.pyx":538 - * - * 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, 538, __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, 538, __pyx_L1_error) - } - __pyx_v_block_yi = __Pyx_div_int(__pyx_v_block_index, __pyx_v_self->block_nx); - - /* "pygeoprocessing/routing/routing.pyx":540 - * 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":541 - * - * 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":543 - * yoff = block_yi << self.block_ybits - * - * win_xsize = self.block_xsize # <<<<<<<<<<<<<< - * win_ysize = self.block_ysize - * - */ - __pyx_t_7 = __pyx_v_self->block_xsize; - __pyx_v_win_xsize = __pyx_t_7; - - /* "pygeoprocessing/routing/routing.pyx":544 - * - * win_xsize = self.block_xsize - * win_ysize = self.block_ysize # <<<<<<<<<<<<<< - * - * if xoff+win_xsize > self.raster_x_size: - */ - __pyx_t_7 = __pyx_v_self->block_ysize; - __pyx_v_win_ysize = __pyx_t_7; - - /* "pygeoprocessing/routing/routing.pyx":546 - * 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_8 = (((__pyx_v_xoff + __pyx_v_win_xsize) > __pyx_v_self->raster_x_size) != 0); - if (__pyx_t_8) { - - /* "pygeoprocessing/routing/routing.pyx":547 - * - * 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":546 - * 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":549 - * 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_8 = (((__pyx_v_yoff + __pyx_v_win_ysize) > __pyx_v_self->raster_y_size) != 0); - if (__pyx_t_8) { - - /* "pygeoprocessing/routing/routing.pyx":550 - * 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":549 - * 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":553 - * 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_6 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 553, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 553, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) { - __pyx_t_6 = __pyx_t_4; __Pyx_INCREF(__pyx_t_6); __pyx_t_9 = 0; - __pyx_t_12 = NULL; - } else { - __pyx_t_9 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 553, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_12 = Py_TYPE(__pyx_t_6)->tp_iternext; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 553, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - for (;;) { - if (likely(!__pyx_t_12)) { - if (likely(PyList_CheckExact(__pyx_t_6))) { - if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_6)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_9); __Pyx_INCREF(__pyx_t_4); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 553, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_6, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 553, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } else { - if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_6)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_9); __Pyx_INCREF(__pyx_t_4); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 553, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_6, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 553, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } - } else { - __pyx_t_4 = __pyx_t_12(__pyx_t_6); - 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, 553, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - __Pyx_XDECREF_SET(__pyx_v_xi_copy, __pyx_t_4); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":554 - * - * 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_4 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 554, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 554, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (likely(PyList_CheckExact(__pyx_t_5)) || PyTuple_CheckExact(__pyx_t_5)) { - __pyx_t_4 = __pyx_t_5; __Pyx_INCREF(__pyx_t_4); __pyx_t_13 = 0; - __pyx_t_14 = NULL; - } else { - __pyx_t_13 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 554, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_14 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 554, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - for (;;) { - if (likely(!__pyx_t_14)) { - if (likely(PyList_CheckExact(__pyx_t_4))) { - if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_13); __Pyx_INCREF(__pyx_t_5); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 554, __pyx_L1_error) - #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_4, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 554, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - } else { - if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_13); __Pyx_INCREF(__pyx_t_5); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 554, __pyx_L1_error) - #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_4, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 554, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - } - } else { - __pyx_t_5 = __pyx_t_14(__pyx_t_4); - 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, 554, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_5); - } - __Pyx_XDECREF_SET(__pyx_v_yi_copy, __pyx_t_5); - __pyx_t_5 = 0; - - /* "pygeoprocessing/routing/routing.pyx":556 - * 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( - * block_array[0:win_ysize, 0:win_xsize], - */ - __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_self->block_xbits); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 556, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyNumber_Lshift(__pyx_v_yi_copy, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 556, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyNumber_Add(__pyx_t_3, __pyx_v_xi_copy); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 556, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_15 = __Pyx_PyIndex_AsSsize_t(__pyx_t_5); if (unlikely((__pyx_t_15 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 556, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pygeoprocessing/routing/routing.pyx":555 - * 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_5 = PyFloat_FromDouble((__pyx_v_double_buffer[__pyx_t_15])); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 555, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 555, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_yi_copy); - __Pyx_GIVEREF(__pyx_v_yi_copy); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_yi_copy); - __Pyx_INCREF(__pyx_v_xi_copy); - __Pyx_GIVEREF(__pyx_v_xi_copy); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_xi_copy); - if (unlikely(PyObject_SetItem(__pyx_v_block_array, __pyx_t_3, __pyx_t_5) < 0)) __PYX_ERR(0, 555, __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":554 - * - * 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_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":553 - * 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_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":557 - * 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_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster_band, __pyx_n_s_WriteArray); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 557, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - - /* "pygeoprocessing/routing/routing.pyx":558 - * (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_4 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 558, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PySlice_New(__pyx_int_0, __pyx_t_4, Py_None); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 558, __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_win_xsize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 558, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PySlice_New(__pyx_int_0, __pyx_t_4, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 558, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 558, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); - __pyx_t_5 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_block_array, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 558, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":557 - * 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 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 557, __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 = 0; - - /* "pygeoprocessing/routing/routing.pyx":559 - * 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_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 559, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_xoff); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 559, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_xoff, __pyx_t_5) < 0) __PYX_ERR(0, 559, __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, 559, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_yoff, __pyx_t_5) < 0) __PYX_ERR(0, 559, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pygeoprocessing/routing/routing.pyx":557 - * 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 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 557, __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_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pygeoprocessing/routing/routing.pyx":534 - * # 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":529 - * double_buffer = removed_value_list.front().second - * - * if self.write_mode: # <<<<<<<<<<<<<< - * block_index = removed_value_list.front().first - * - */ - } - - /* "pygeoprocessing/routing/routing.pyx":560 - * 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":561 - * 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":563 - * removed_value_list.pop_front() - * - * if self.write_mode: # <<<<<<<<<<<<<< - * raster_band = None - * raster = None - */ - __pyx_t_8 = (__pyx_v_self->write_mode != 0); - if (__pyx_t_8) { - - /* "pygeoprocessing/routing/routing.pyx":564 - * - * 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":565 - * if self.write_mode: - * raster_band = None - * raster = None # <<<<<<<<<<<<<< - * - * - */ - __Pyx_INCREF(Py_None); - __Pyx_XDECREF_SET(__pyx_v_raster, Py_None); - - /* "pygeoprocessing/routing/routing.pyx":563 - * removed_value_list.pop_front() - * - * if self.write_mode: # <<<<<<<<<<<<<< - * raster_band = None - * raster = None - */ - } - - /* "pygeoprocessing/routing/routing.pyx":495 - * raster = None - * - * cdef void flush(self) except *: # <<<<<<<<<<<<<< - * cdef clist[BlockBufferPair] removed_value_list - * cdef double *double_buffer - */ - - /* function exit code */ - 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); - __Pyx_AddTraceback("pygeoprocessing.routing.routing._ManagedRaster.flush", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_raster_band); - __Pyx_XDECREF(__pyx_v_max_retries); - __Pyx_XDECREF(__pyx_v_raster); - __Pyx_XDECREF(__pyx_v_block_array); - __Pyx_XDECREF(__pyx_v_xi_copy); - __Pyx_XDECREF(__pyx_v_yi_copy); - __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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __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__2, 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __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__3, 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":568 - * - * - * 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)(void*)(PyCFunctionWithKeywords)__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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 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, 568, __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, 568, __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, 568, __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, 568, __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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("_generate_read_bounds", 0); - - /* "pygeoprocessing/routing/routing.pyx":590 - * 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":591 - * """ - * 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":592 - * 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":593 - * 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":594 - * 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, 594, __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); - } - } - __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 594, __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":595 - * 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_u_xoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 595, __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, 595, __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, 595, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_4) { - - /* "pygeoprocessing/routing/routing.pyx":596 - * 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":597 - * 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_u_xoff); - __pyx_t_5 = __pyx_n_u_xoff; - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_target_offset_dict, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 597, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyInt_SubtractObjC(__pyx_t_2, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 597, __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, 597, __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":598 - * xa = None - * target_offset_dict['xoff'] -= 1 - * target_offset_dict['win_xsize'] += 1 # <<<<<<<<<<<<<< - * if offset_dict['yoff'] > 0: - * ya = None - */ - __Pyx_INCREF(__pyx_n_u_win_xsize); - __pyx_t_5 = __pyx_n_u_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, 598, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 598, __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, 598, __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":595 - * yb = -1 - * target_offset_dict = offset_dict.copy() - * if offset_dict['xoff'] > 0: # <<<<<<<<<<<<<< - * xa = None - * target_offset_dict['xoff'] -= 1 - */ - } - - /* "pygeoprocessing/routing/routing.pyx":599 - * 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_u_yoff); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 599, __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, 599, __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, 599, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_4) { - - /* "pygeoprocessing/routing/routing.pyx":600 - * 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":601 - * 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_u_yoff); - __pyx_t_5 = __pyx_n_u_yoff; - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_target_offset_dict, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 601, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_t_1, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 601, __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, 601, __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":602 - * 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_u_win_ysize); - __pyx_t_5 = __pyx_n_u_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, 602, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 602, __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, 602, __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":599 - * 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":603 - * 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_u_xoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 603, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 603, __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, 603, __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, 603, __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, 603, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_4) { - - /* "pygeoprocessing/routing/routing.pyx":604 - * 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":605 - * 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_u_win_xsize); - __pyx_t_5 = __pyx_n_u_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, 605, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 605, __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, 605, __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":603 - * 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":606 - * 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_u_yoff); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 606, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 606, __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, 606, __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, 606, __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, 606, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_4) { - - /* "pygeoprocessing/routing/routing.pyx":607 - * 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":608 - * 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_u_win_ysize); - __pyx_t_5 = __pyx_n_u_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, 608, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 608, __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, 608, __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":606 - * 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":609 - * 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, 609, __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, 609, __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":568 - * - * - * 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":612 - * - * - * def fill_pits( # <<<<<<<<<<<<<< - * dem_raster_path_band, target_filled_dem_raster_path, - * working_dir=None, long max_pixel_fill_count=_MAX_PIXEL_FILL_COUNT, - */ - -/* 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 (str): path the pit filled dem,\n that's created by a call to this function. It is functionally a\n single band copy of ``dem_raster_path_band`` with the pit pixels\n raised to the pour point. For runtime efficiency, this raster is\n tiled and its blocksize is set to (``1< 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_max_pixel_fill_count); - 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_raster_driver_creation_tuple); - if (value) { values[4] = 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, 612, __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); - 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]; - if (values[3]) { - __pyx_v_max_pixel_fill_count = __Pyx_PyInt_As_long(values[3]); if (unlikely((__pyx_v_max_pixel_fill_count == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 614, __pyx_L3_error) - } else { - __pyx_v_max_pixel_fill_count = __pyx_k__5; - } - __pyx_v_raster_driver_creation_tuple = values[4]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("fill_pits", 0, 2, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 612, __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_max_pixel_fill_count, __pyx_v_raster_driver_creation_tuple); - - /* "pygeoprocessing/routing/routing.pyx":612 - * - * - * def fill_pits( # <<<<<<<<<<<<<< - * dem_raster_path_band, target_filled_dem_raster_path, - * working_dir=None, long max_pixel_fill_count=_MAX_PIXEL_FILL_COUNT, - */ - - /* 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, long __pyx_v_max_pixel_fill_count, PyObject *__pyx_v_raster_driver_creation_tuple) { - 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_natural_drain_exists; - int __pyx_v_search_steps; - std::queue __pyx_v_search_queue; - std::queue __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_base_datatype = NULL; - PyObject *__pyx_v_filled_dem_raster = NULL; - PyObject *__pyx_v_filled_dem_band = NULL; - PyObject *__pyx_v_offset_info = NULL; - PyObject *__pyx_v_block_array = NULL; - struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_filled_dem_managed_raster = NULL; - PyObject *__pyx_v_offset_dict = NULL; - int __pyx_v_current_pixel; - double __pyx_v_n_height; - long __pyx_v_pour_point; - 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; - double __pyx_t_7; - PyObject *(*__pyx_t_8)(PyObject *); - int __pyx_t_9; - int __pyx_t_10; - PyObject *__pyx_t_11 = NULL; - 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 *); - Py_ssize_t __pyx_t_19; - Py_UCS4 __pyx_t_20; - long __pyx_t_21; - long __pyx_t_22; - long __pyx_t_23; - long __pyx_t_24; - int __pyx_t_25; - struct __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateType __pyx_t_26; - struct __pyx_t_15pygeoprocessing_7routing_7routing_PixelType __pyx_t_27; - __pyx_t_15pygeoprocessing_7routing_7routing_PitPriorityQueueType __pyx_t_28; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("fill_pits", 0); - - /* "pygeoprocessing/routing/routing.pyx":701 - * # 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":705 - * # 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 705, __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, 705, __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, 705, __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); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 705, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __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":706 - * # 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_u_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 706, __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, 706, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_t_3, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 706, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 706, __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_v_base_nodata = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":707 - * 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_5 = (__pyx_v_base_nodata != Py_None); - __pyx_t_6 = (__pyx_t_5 != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/routing/routing.pyx":709 - * 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 709, __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, 709, __pyx_L1_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); - } - } - __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_v_base_nodata) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_base_nodata); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 709, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_7 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 709, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_dem_nodata = __pyx_t_7; - - /* "pygeoprocessing/routing/routing.pyx":707 - * 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":712 - * 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":715 - * - * # 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_u_raster_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 715, __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, 715, __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, 715, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 715, __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_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 715, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_4)->tp_iternext; - index = 0; __pyx_t_1 = __pyx_t_8(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - 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, 715, __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, 715, __pyx_L1_error) - __pyx_L5_unpacking_done:; - } - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 715, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 715, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_raster_x_size = __pyx_t_9; - __pyx_v_raster_y_size = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":718 - * - * # 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":721 - * - * # 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_11, &__pyx_t_12, &__pyx_t_13); - __Pyx_XGOTREF(__pyx_t_11); - __Pyx_XGOTREF(__pyx_t_12); - __Pyx_XGOTREF(__pyx_t_13); - /*try:*/ { - - /* "pygeoprocessing/routing/routing.pyx":722 - * # set up the working dir for the mask rasters - * try: - * if working_dir is not None: # <<<<<<<<<<<<<< - * os.makedirs(working_dir) - * except OSError: - */ - __pyx_t_6 = (__pyx_v_working_dir != Py_None); - __pyx_t_5 = (__pyx_t_6 != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":723 - * try: - * if working_dir is not None: - * os.makedirs(working_dir) # <<<<<<<<<<<<<< - * except OSError: - * pass - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 723, __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, 723, __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); - } - } - __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_v_working_dir) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_working_dir); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 723, __pyx_L6_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":722 - * # 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":721 - * - * # set up the working dir for the mask rasters - * try: # <<<<<<<<<<<<<< - * if working_dir is not None: - * os.makedirs(working_dir) - */ - } - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - goto __pyx_L11_try_end; - __pyx_L6_error:; - __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; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":724 - * if working_dir is not None: - * os.makedirs(working_dir) - * except OSError: # <<<<<<<<<<<<<< - * pass - * working_dir_path = tempfile.mkdtemp( - */ - __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OSError); - if (__pyx_t_10) { - __Pyx_ErrRestore(0,0,0); - goto __pyx_L7_exception_handled; - } - goto __pyx_L8_except_error; - __pyx_L8_except_error:; - - /* "pygeoprocessing/routing/routing.pyx":721 - * - * # set up the working dir for the mask rasters - * try: # <<<<<<<<<<<<<< - * if working_dir is not None: - * os.makedirs(working_dir) - */ - __Pyx_XGIVEREF(__pyx_t_11); - __Pyx_XGIVEREF(__pyx_t_12); - __Pyx_XGIVEREF(__pyx_t_13); - __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13); - goto __pyx_L1_error; - __pyx_L7_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_11); - __Pyx_XGIVEREF(__pyx_t_12); - __Pyx_XGIVEREF(__pyx_t_13); - __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13); - __pyx_L11_try_end:; - } - - /* "pygeoprocessing/routing/routing.pyx":726 - * 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_tempfile); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 726, __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, 726, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":727 - * 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, 727, __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, 727, __pyx_L1_error) - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_time); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 727, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_strftime); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 727, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":728 - * 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_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_time); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 728, __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, 728, __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); - } - } - __pyx_t_4 = (__pyx_t_15) ? __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_t_15) : __Pyx_PyObject_CallNoArg(__pyx_t_16); - __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 728, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_16 = NULL; - __pyx_t_10 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { - __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_16)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_16); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - __pyx_t_10 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_14)) { - PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_kp_u_Y_m_d__H__M__S, __pyx_t_4}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 727, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 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_14)) { - PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_kp_u_Y_m_d__H__M__S, __pyx_t_4}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 727, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - { - __pyx_t_15 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 727, __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_u_Y_m_d__H__M__S); - __Pyx_GIVEREF(__pyx_kp_u_Y_m_d__H__M__S); - PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_10, __pyx_kp_u_Y_m_d__H__M__S); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_10, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_15, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 727, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - } - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":727 - * 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_14 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_fill_pits__s, __pyx_t_2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 727, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_prefix, __pyx_t_14) < 0) __PYX_ERR(0, 727, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":726 - * 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_14 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 726, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __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_14; - __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":733 - * # 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 733, __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, 733, __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, 733, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":734 - * # 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_10 = 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_10 = 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_u_flat_region_mask_tif}; - __pyx_t_14 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 733, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_14); - } 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_u_flat_region_mask_tif}; - __pyx_t_14 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 733, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_14); - } else - #endif - { - __pyx_t_2 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 733, __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_v_working_dir_path); - __Pyx_GIVEREF(__pyx_v_working_dir_path); - PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_10, __pyx_v_working_dir_path); - __Pyx_INCREF(__pyx_kp_u_flat_region_mask_tif); - __Pyx_GIVEREF(__pyx_kp_u_flat_region_mask_tif); - PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_10, __pyx_kp_u_flat_region_mask_tif); - __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 733, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_flat_region_mask_path = __pyx_t_14; - __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":735 - * 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":737 - * 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], - */ - __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 737, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 737, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":738 - * - * pygeoprocessing.new_raster_from_base( - * dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte, # <<<<<<<<<<<<<< - * [mask_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - */ - __pyx_t_14 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 738, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 738, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 738, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":739 - * pygeoprocessing.new_raster_from_base( - * dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte, - * [mask_nodata], # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * flat_region_mask_managed_raster = _ManagedRaster( - */ - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_mask_nodata); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 739, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_15 = PyList_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 739, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_GIVEREF(__pyx_t_2); - PyList_SET_ITEM(__pyx_t_15, 0, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":737 - * 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], - */ - __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 737, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_14); - __Pyx_INCREF(__pyx_v_flat_region_mask_path); - __Pyx_GIVEREF(__pyx_v_flat_region_mask_path); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_flat_region_mask_path); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_15); - PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_15); - __pyx_t_14 = 0; - __pyx_t_1 = 0; - __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":740 - * dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte, - * [mask_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< - * flat_region_mask_managed_raster = _ManagedRaster( - * flat_region_mask_path, 1, 1) - */ - __pyx_t_15 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 740, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 740, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":737 - * 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], - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 737, __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_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":741 - * [mask_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * flat_region_mask_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< - * flat_region_mask_path, 1, 1) - * - */ - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 741, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_flat_region_mask_path); - __Pyx_GIVEREF(__pyx_v_flat_region_mask_path); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_flat_region_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_15 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_1, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 741, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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":747 - * # 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_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 747, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_path); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 747, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_join); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 747, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - __pyx_t_10 = 0; - if (CYTHON_UNPACK_METHODS && likely(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_10 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_working_dir_path, __pyx_kp_u_pit_mask_tif}; - __pyx_t_15 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 747, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_15); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_working_dir_path, __pyx_kp_u_pit_mask_tif}; - __pyx_t_15 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 747, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_15); - } else - #endif - { - __pyx_t_3 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 747, __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_v_working_dir_path); - __Pyx_GIVEREF(__pyx_v_working_dir_path); - PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_10, __pyx_v_working_dir_path); - __Pyx_INCREF(__pyx_kp_u_pit_mask_tif); - __Pyx_GIVEREF(__pyx_kp_u_pit_mask_tif); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_10, __pyx_kp_u_pit_mask_tif); - __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 747, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_pit_mask_path = __pyx_t_15; - __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":748 - * # `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], - */ - __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 748, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 748, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":749 - * 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], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - */ - __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, 749, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 749, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_GDT_Int32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 749, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":750 - * pygeoprocessing.new_raster_from_base( - * dem_raster_path_band[0], pit_mask_path, gdal.GDT_Int32, - * [mask_nodata], # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * pit_mask_managed_raster = _ManagedRaster( - */ - __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_mask_nodata); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 750, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_14 = PyList_New(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 750, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_GIVEREF(__pyx_t_3); - PyList_SET_ITEM(__pyx_t_14, 0, __pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":748 - * # `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], - */ - __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 748, __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_2); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_14); - __pyx_t_15 = 0; - __pyx_t_2 = 0; - __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":751 - * dem_raster_path_band[0], pit_mask_path, gdal.GDT_Int32, - * [mask_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< - * pit_mask_managed_raster = _ManagedRaster( - * pit_mask_path, 1, 1) - */ - __pyx_t_14 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 751, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 751, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":748 - * # `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], - */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_t_14); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 748, __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_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":752 - * [mask_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * pit_mask_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< - * pit_mask_path, 1, 1) - * - */ - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 752, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_pit_mask_path); - __Pyx_GIVEREF(__pyx_v_pit_mask_path); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_pit_mask_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_14 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_2, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 752, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_pit_mask_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_14); - __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":756 - * - * # copy the base DEM to the target and set up for writing - * base_datatype = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< - * dem_raster_path_band[0])['datatype'] - * pygeoprocessing.new_raster_from_base( - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 756, __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, 756, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":757 - * # copy the base DEM to the target and set up for writing - * base_datatype = pygeoprocessing.get_raster_info( - * dem_raster_path_band[0])['datatype'] # <<<<<<<<<<<<<< - * pygeoprocessing.new_raster_from_base( - * dem_raster_path_band[0], target_filled_dem_raster_path, - */ - __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, 757, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = NULL; - 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_14 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_1, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 756, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_t_14, __pyx_n_u_datatype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 757, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_v_base_datatype = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":758 - * base_datatype = pygeoprocessing.get_raster_info( - * dem_raster_path_band[0])['datatype'] - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * dem_raster_path_band[0], target_filled_dem_raster_path, - * base_datatype, [dem_nodata], - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 758, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 758, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":759 - * dem_raster_path_band[0])['datatype'] - * pygeoprocessing.new_raster_from_base( - * dem_raster_path_band[0], target_filled_dem_raster_path, # <<<<<<<<<<<<<< - * base_datatype, [dem_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - */ - __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, 759, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pygeoprocessing/routing/routing.pyx":760 - * pygeoprocessing.new_raster_from_base( - * dem_raster_path_band[0], target_filled_dem_raster_path, - * base_datatype, [dem_nodata], # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * filled_dem_raster = gdal.OpenEx( - */ - __pyx_t_2 = PyFloat_FromDouble(__pyx_v_dem_nodata); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 760, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 760, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":758 - * base_datatype = pygeoprocessing.get_raster_info( - * dem_raster_path_band[0])['datatype'] - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * dem_raster_path_band[0], target_filled_dem_raster_path, - * base_datatype, [dem_nodata], - */ - __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 758, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_2, 0, __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_2, 1, __pyx_v_target_filled_dem_raster_path); - __Pyx_INCREF(__pyx_v_base_datatype); - __Pyx_GIVEREF(__pyx_v_base_datatype); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_base_datatype); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_1); - __pyx_t_3 = 0; - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":761 - * dem_raster_path_band[0], target_filled_dem_raster_path, - * base_datatype, [dem_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< - * filled_dem_raster = gdal.OpenEx( - * target_filled_dem_raster_path, gdal.OF_RASTER | gdal.GA_Update) - */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 761, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 761, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":758 - * base_datatype = pygeoprocessing.get_raster_info( - * dem_raster_path_band[0])['datatype'] - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * dem_raster_path_band[0], target_filled_dem_raster_path, - * base_datatype, [dem_nodata], - */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 758, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":762 - * base_datatype, [dem_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * filled_dem_raster = gdal.OpenEx( # <<<<<<<<<<<<<< - * target_filled_dem_raster_path, gdal.OF_RASTER | gdal.GA_Update) - * filled_dem_band = filled_dem_raster.GetRasterBand(1) - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 762, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 762, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":763 - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * filled_dem_raster = gdal.OpenEx( - * target_filled_dem_raster_path, gdal.OF_RASTER | gdal.GA_Update) # <<<<<<<<<<<<<< - * filled_dem_band = filled_dem_raster.GetRasterBand(1) - * for offset_info, block_array in pygeoprocessing.iterblocks( - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 763, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 763, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 763, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GA_Update); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 763, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Or(__pyx_t_14, __pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 763, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_15 = NULL; - __pyx_t_10 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_15)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_15); - __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_15, __pyx_v_target_filled_dem_raster_path, __pyx_t_1}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 762, __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_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_v_target_filled_dem_raster_path, __pyx_t_1}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 762, __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_14 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 762, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - if (__pyx_t_15) { - __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_15); __pyx_t_15 = NULL; - } - __Pyx_INCREF(__pyx_v_target_filled_dem_raster_path); - __Pyx_GIVEREF(__pyx_v_target_filled_dem_raster_path); - PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_10, __pyx_v_target_filled_dem_raster_path); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_10, __pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_14, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 762, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_filled_dem_raster = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":764 - * filled_dem_raster = gdal.OpenEx( - * target_filled_dem_raster_path, gdal.OF_RASTER | gdal.GA_Update) - * filled_dem_band = filled_dem_raster.GetRasterBand(1) # <<<<<<<<<<<<<< - * for offset_info, block_array in pygeoprocessing.iterblocks( - * dem_raster_path_band): - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_filled_dem_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 764, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_14 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_14)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_14); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_3 = (__pyx_t_14) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_14, __pyx_int_1) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_int_1); - __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 764, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_filled_dem_band = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":765 - * target_filled_dem_raster_path, gdal.OF_RASTER | gdal.GA_Update) - * filled_dem_band = filled_dem_raster.GetRasterBand(1) - * for offset_info, block_array in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * dem_raster_path_band): - * filled_dem_band.WriteArray( - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 765, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 765, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":766 - * filled_dem_band = filled_dem_raster.GetRasterBand(1) - * for offset_info, block_array in pygeoprocessing.iterblocks( - * dem_raster_path_band): # <<<<<<<<<<<<<< - * filled_dem_band.WriteArray( - * block_array, xoff=offset_info['xoff'], yoff=offset_info['yoff']) - */ - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - } - } - __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_2, __pyx_v_dem_raster_path_band) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_v_dem_raster_path_band); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 765, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":765 - * target_filled_dem_raster_path, gdal.OF_RASTER | gdal.GA_Update) - * filled_dem_band = filled_dem_raster.GetRasterBand(1) - * for offset_info, block_array in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * dem_raster_path_band): - * filled_dem_band.WriteArray( - */ - if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) { - __pyx_t_14 = __pyx_t_3; __Pyx_INCREF(__pyx_t_14); __pyx_t_17 = 0; - __pyx_t_18 = NULL; - } else { - __pyx_t_17 = -1; __pyx_t_14 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 765, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_18 = Py_TYPE(__pyx_t_14)->tp_iternext; if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 765, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - for (;;) { - if (likely(!__pyx_t_18)) { - if (likely(PyList_CheckExact(__pyx_t_14))) { - if (__pyx_t_17 >= PyList_GET_SIZE(__pyx_t_14)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_14, __pyx_t_17); __Pyx_INCREF(__pyx_t_3); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 765, __pyx_L1_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_14, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 765, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - } else { - if (__pyx_t_17 >= PyTuple_GET_SIZE(__pyx_t_14)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_14, __pyx_t_17); __Pyx_INCREF(__pyx_t_3); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 765, __pyx_L1_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_14, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 765, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - } - } else { - __pyx_t_3 = __pyx_t_18(__pyx_t_14); - 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, 765, __pyx_L1_error) - } - break; - } - __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, 765, __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_1 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_2 = PyList_GET_ITEM(sequence, 0); - __pyx_t_1 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_1); - #else - __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 765, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 765, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_15 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 765, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_15)->tp_iternext; - index = 0; __pyx_t_2 = __pyx_t_8(__pyx_t_15); if (unlikely(!__pyx_t_2)) goto __pyx_L15_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - index = 1; __pyx_t_1 = __pyx_t_8(__pyx_t_15); if (unlikely(!__pyx_t_1)) goto __pyx_L15_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_15), 2) < 0) __PYX_ERR(0, 765, __pyx_L1_error) - __pyx_t_8 = NULL; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - goto __pyx_L16_unpacking_done; - __pyx_L15_unpacking_failed:; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_8 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 765, __pyx_L1_error) - __pyx_L16_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v_offset_info, __pyx_t_2); - __pyx_t_2 = 0; - __Pyx_XDECREF_SET(__pyx_v_block_array, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":767 - * for offset_info, block_array in pygeoprocessing.iterblocks( - * dem_raster_path_band): - * filled_dem_band.WriteArray( # <<<<<<<<<<<<<< - * block_array, xoff=offset_info['xoff'], yoff=offset_info['yoff']) - * filled_dem_band.FlushCache() - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_filled_dem_band, __pyx_n_s_WriteArray); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 767, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pygeoprocessing/routing/routing.pyx":768 - * dem_raster_path_band): - * filled_dem_band.WriteArray( - * block_array, xoff=offset_info['xoff'], yoff=offset_info['yoff']) # <<<<<<<<<<<<<< - * filled_dem_band.FlushCache() - * filled_dem_raster.FlushCache() - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 767, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_block_array); - __Pyx_GIVEREF(__pyx_v_block_array); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_block_array); - __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 768, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_15 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_info, __pyx_n_u_xoff); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 768, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_xoff, __pyx_t_15) < 0) __PYX_ERR(0, 768, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_15 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_info, __pyx_n_u_yoff); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 768, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_yoff, __pyx_t_15) < 0) __PYX_ERR(0, 768, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":767 - * for offset_info, block_array in pygeoprocessing.iterblocks( - * dem_raster_path_band): - * filled_dem_band.WriteArray( # <<<<<<<<<<<<<< - * block_array, xoff=offset_info['xoff'], yoff=offset_info['yoff']) - * filled_dem_band.FlushCache() - */ - __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 767, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":765 - * target_filled_dem_raster_path, gdal.OF_RASTER | gdal.GA_Update) - * filled_dem_band = filled_dem_raster.GetRasterBand(1) - * for offset_info, block_array in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * dem_raster_path_band): - * filled_dem_band.WriteArray( - */ - } - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":769 - * filled_dem_band.WriteArray( - * block_array, xoff=offset_info['xoff'], yoff=offset_info['yoff']) - * filled_dem_band.FlushCache() # <<<<<<<<<<<<<< - * filled_dem_raster.FlushCache() - * filled_dem_band = None - */ - __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_v_filled_dem_band, __pyx_n_s_FlushCache); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 769, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_14 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_15); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 769, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":770 - * block_array, xoff=offset_info['xoff'], yoff=offset_info['yoff']) - * filled_dem_band.FlushCache() - * filled_dem_raster.FlushCache() # <<<<<<<<<<<<<< - * filled_dem_band = None - * filled_dem_raster = None - */ - __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_v_filled_dem_raster, __pyx_n_s_FlushCache); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 770, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_14 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_15); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 770, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":771 - * filled_dem_band.FlushCache() - * filled_dem_raster.FlushCache() - * filled_dem_band = None # <<<<<<<<<<<<<< - * filled_dem_raster = None - * filled_dem_managed_raster = _ManagedRaster( - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_filled_dem_band, Py_None); - - /* "pygeoprocessing/routing/routing.pyx":772 - * filled_dem_raster.FlushCache() - * filled_dem_band = None - * filled_dem_raster = None # <<<<<<<<<<<<<< - * filled_dem_managed_raster = _ManagedRaster( - * target_filled_dem_raster_path, 1, 1) - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_filled_dem_raster, Py_None); - - /* "pygeoprocessing/routing/routing.pyx":773 - * filled_dem_band = None - * filled_dem_raster = None - * filled_dem_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< - * target_filled_dem_raster_path, 1, 1) - * - */ - __pyx_t_14 = PyTuple_New(3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 773, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_INCREF(__pyx_v_target_filled_dem_raster_path); - __Pyx_GIVEREF(__pyx_v_target_filled_dem_raster_path); - PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_v_target_filled_dem_raster_path); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_int_1); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_14, 2, __pyx_int_1); - __pyx_t_15 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_14, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 773, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_v_filled_dem_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_15); - __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":777 - * - * # 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":780 - * - * # this outer loop searches for a pixel that is locally undrained - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * dem_raster_path_band, offset_only=True, largest_block=0): - * win_xsize = offset_dict['win_xsize'] - */ - __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 780, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 780, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":781 - * # this outer loop searches for a pixel that is locally undrained - * for offset_dict in pygeoprocessing.iterblocks( - * dem_raster_path_band, offset_only=True, largest_block=0): # <<<<<<<<<<<<<< - * win_xsize = offset_dict['win_xsize'] - * win_ysize = offset_dict['win_ysize'] - */ - __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 780, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_INCREF(__pyx_v_dem_raster_path_band); - __Pyx_GIVEREF(__pyx_v_dem_raster_path_band); - PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_v_dem_raster_path_band); - __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 781, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 781, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_largest_block, __pyx_int_0) < 0) __PYX_ERR(0, 781, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":780 - * - * # this outer loop searches for a pixel that is locally undrained - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * dem_raster_path_band, offset_only=True, largest_block=0): - * win_xsize = offset_dict['win_xsize'] - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_15, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 780, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { - __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_17 = 0; - __pyx_t_18 = NULL; - } else { - __pyx_t_17 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 780, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_18 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 780, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - for (;;) { - if (likely(!__pyx_t_18)) { - if (likely(PyList_CheckExact(__pyx_t_2))) { - if (__pyx_t_17 >= PyList_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_17); __Pyx_INCREF(__pyx_t_1); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 780, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 780, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } else { - if (__pyx_t_17 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_17); __Pyx_INCREF(__pyx_t_1); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 780, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 780, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } - } else { - __pyx_t_1 = __pyx_t_18(__pyx_t_2); - 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, 780, __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":782 - * for offset_dict in pygeoprocessing.iterblocks( - * dem_raster_path_band, 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_u_win_xsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 782, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 782, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_win_xsize = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":783 - * dem_raster_path_band, 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_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 783, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 783, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_win_ysize = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":784 - * 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_u_xoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 784, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 784, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_xoff = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":785 - * win_ysize = offset_dict['win_ysize'] - * xoff = offset_dict['xoff'] - * yoff = offset_dict['yoff'] # <<<<<<<<<<<<<< - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - */ - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_yoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 785, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 785, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_yoff = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":787 - * yoff = offset_dict['yoff'] - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - */ - __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":788 - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info( - */ - __pyx_v_last_log_time = time(NULL); - - /* "pygeoprocessing/routing/routing.pyx":789 - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size # <<<<<<<<<<<<<< - * LOGGER.info( - * '(fill pits): ' - */ - __pyx_v_current_pixel = (__pyx_v_xoff + (__pyx_v_yoff * __pyx_v_raster_x_size)); - - /* "pygeoprocessing/routing/routing.pyx":790 - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info( # <<<<<<<<<<<<<< - * '(fill pits): ' - * f'{current_pixel} of {raster_x_size * raster_y_size} ' - */ - __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 790, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_info); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 790, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":791 - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info( - * '(fill pits): ' # <<<<<<<<<<<<<< - * f'{current_pixel} of {raster_x_size * raster_y_size} ' - * 'pixels complete') - */ - __pyx_t_15 = PyTuple_New(5); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 791, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_19 = 0; - __pyx_t_20 = 127; - __Pyx_INCREF(__pyx_kp_u_fill_pits); - __pyx_t_19 += 13; - __Pyx_GIVEREF(__pyx_kp_u_fill_pits); - PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_kp_u_fill_pits); - - /* "pygeoprocessing/routing/routing.pyx":792 - * LOGGER.info( - * '(fill pits): ' - * f'{current_pixel} of {raster_x_size * raster_y_size} ' # <<<<<<<<<<<<<< - * 'pixels complete') - * - */ - __pyx_t_3 = __Pyx_PyUnicode_From_int(__pyx_v_current_pixel, 0, ' ', 'd'); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 792, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_19 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_3); - __pyx_t_3 = 0; - __Pyx_INCREF(__pyx_kp_u_of); - __pyx_t_19 += 4; - __Pyx_GIVEREF(__pyx_kp_u_of); - PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_kp_u_of); - __pyx_t_3 = __Pyx_PyUnicode_From_int((__pyx_v_raster_x_size * __pyx_v_raster_y_size), 0, ' ', 'd'); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 792, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_19 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_15, 3, __pyx_t_3); - __pyx_t_3 = 0; - __Pyx_INCREF(__pyx_kp_u_pixels_complete); - __pyx_t_19 += 16; - __Pyx_GIVEREF(__pyx_kp_u_pixels_complete); - PyTuple_SET_ITEM(__pyx_t_15, 4, __pyx_kp_u_pixels_complete); - - /* "pygeoprocessing/routing/routing.pyx":791 - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info( - * '(fill pits): ' # <<<<<<<<<<<<<< - * f'{current_pixel} of {raster_x_size * raster_y_size} ' - * 'pixels complete') - */ - __pyx_t_3 = __Pyx_PyUnicode_Join(__pyx_t_15, 5, __pyx_t_19, __pyx_t_20); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 791, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_15 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { - __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_15)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_15); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - } - } - __pyx_t_1 = (__pyx_t_15) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_15, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_t_3); - __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 790, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":787 - * yoff = offset_dict['yoff'] - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - */ - } - - /* "pygeoprocessing/routing/routing.pyx":796 - * - * # search block for locally undrained pixels - * for yi in range(1, win_ysize+1): # <<<<<<<<<<<<<< - * yi_root = yi-1+yoff - * for xi in range(1, win_xsize+1): - */ - __pyx_t_21 = (__pyx_v_win_ysize + 1); - __pyx_t_22 = __pyx_t_21; - for (__pyx_t_10 = 1; __pyx_t_10 < __pyx_t_22; __pyx_t_10+=1) { - __pyx_v_yi = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":797 - * # search block for locally undrained pixels - * for yi in range(1, win_ysize+1): - * yi_root = yi-1+yoff # <<<<<<<<<<<<<< - * for xi in range(1, win_xsize+1): - * xi_root = xi-1+xoff - */ - __pyx_v_yi_root = ((__pyx_v_yi - 1) + __pyx_v_yoff); - - /* "pygeoprocessing/routing/routing.pyx":798 - * for yi in range(1, win_ysize+1): - * yi_root = yi-1+yoff - * for xi in range(1, win_xsize+1): # <<<<<<<<<<<<<< - * xi_root = xi-1+xoff - * # this value is set in case it turns out to be the root of a - */ - __pyx_t_23 = (__pyx_v_win_xsize + 1); - __pyx_t_24 = __pyx_t_23; - for (__pyx_t_9 = 1; __pyx_t_9 < __pyx_t_24; __pyx_t_9+=1) { - __pyx_v_xi = __pyx_t_9; - - /* "pygeoprocessing/routing/routing.pyx":799 - * yi_root = yi-1+yoff - * for xi in range(1, win_xsize+1): - * xi_root = xi-1+xoff # <<<<<<<<<<<<<< - * # this value is set in case it turns out to be the root of a - * # pit, we'll start the fill from this pixel in the last phase - */ - __pyx_v_xi_root = ((__pyx_v_xi - 1) + __pyx_v_xoff); - - /* "pygeoprocessing/routing/routing.pyx":803 - * # pit, we'll start the fill from this pixel in the last phase - * # of the algorithm - * center_val = filled_dem_managed_raster.get(xi_root, yi_root) # <<<<<<<<<<<<<< - * if _is_close(center_val, dem_nodata, 1e-8, 1e-5): - * continue - */ - __pyx_v_center_val = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_filled_dem_managed_raster, __pyx_v_xi_root, __pyx_v_yi_root); - - /* "pygeoprocessing/routing/routing.pyx":804 - * # of the algorithm - * center_val = filled_dem_managed_raster.get(xi_root, yi_root) - * if _is_close(center_val, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_center_val, __pyx_v_dem_nodata, 1e-8, 1e-5) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":805 - * center_val = filled_dem_managed_raster.get(xi_root, yi_root) - * if _is_close(center_val, dem_nodata, 1e-8, 1e-5): - * continue # <<<<<<<<<<<<<< - * - * if flat_region_mask_managed_raster.get( - */ - goto __pyx_L22_continue; - - /* "pygeoprocessing/routing/routing.pyx":804 - * # of the algorithm - * center_val = filled_dem_managed_raster.get(xi_root, yi_root) - * if _is_close(center_val, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * continue - * - */ - } - - /* "pygeoprocessing/routing/routing.pyx":808 - * - * if flat_region_mask_managed_raster.get( - * xi_root, yi_root) != mask_nodata: # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_5 = ((__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":807 - * continue - * - * if flat_region_mask_managed_raster.get( # <<<<<<<<<<<<<< - * xi_root, yi_root) != mask_nodata: - * continue - */ - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":809 - * if flat_region_mask_managed_raster.get( - * xi_root, yi_root) != mask_nodata: - * continue # <<<<<<<<<<<<<< - * - * # search neighbors for downhill or nodata - */ - goto __pyx_L22_continue; - - /* "pygeoprocessing/routing/routing.pyx":807 - * continue - * - * if flat_region_mask_managed_raster.get( # <<<<<<<<<<<<<< - * xi_root, yi_root) != mask_nodata: - * continue - */ - } - - /* "pygeoprocessing/routing/routing.pyx":812 - * - * # search neighbors for downhill or nodata - * downhill_neighbor = 0 # <<<<<<<<<<<<<< - * nodata_neighbor = 0 - * for i_n in range(8): - */ - __pyx_v_downhill_neighbor = 0; - - /* "pygeoprocessing/routing/routing.pyx":813 - * # search neighbors for downhill or nodata - * downhill_neighbor = 0 - * nodata_neighbor = 0 # <<<<<<<<<<<<<< - * for i_n in range(8): - * xi_n = xi_root+D8_XOFFSET[i_n] - */ - __pyx_v_nodata_neighbor = 0; - - /* "pygeoprocessing/routing/routing.pyx":814 - * downhill_neighbor = 0 - * nodata_neighbor = 0 - * for i_n in range(8): # <<<<<<<<<<<<<< - * xi_n = xi_root+D8_XOFFSET[i_n] - * yi_n = yi_root+D8_YOFFSET[i_n] - */ - for (__pyx_t_25 = 0; __pyx_t_25 < 8; __pyx_t_25+=1) { - __pyx_v_i_n = __pyx_t_25; - - /* "pygeoprocessing/routing/routing.pyx":815 - * nodata_neighbor = 0 - * for i_n in range(8): - * xi_n = xi_root+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< - * yi_n = yi_root+D8_YOFFSET[i_n] - * if (xi_n < 0 or xi_n >= raster_x_size or - */ - __pyx_v_xi_n = (__pyx_v_xi_root + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":816 - * for i_n in range(8): - * xi_n = xi_root+D8_XOFFSET[i_n] - * yi_n = yi_root+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< - * 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_D8_YOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":817 - * xi_n = xi_root+D8_XOFFSET[i_n] - * yi_n = yi_root+D8_YOFFSET[i_n] - * 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_6 = ((__pyx_v_xi_n < 0) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L29_bool_binop_done; - } - __pyx_t_6 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L29_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":818 - * yi_n = yi_root+D8_YOFFSET[i_n] - * 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_6 = ((__pyx_v_yi_n < 0) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L29_bool_binop_done; - } - __pyx_t_6 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L29_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":817 - * xi_n = xi_root+D8_XOFFSET[i_n] - * yi_n = yi_root+D8_YOFFSET[i_n] - * 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_5) { - - /* "pygeoprocessing/routing/routing.pyx":820 - * 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":821 - * # 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, 1e-8, 1e-5): - */ - goto __pyx_L27_break; - - /* "pygeoprocessing/routing/routing.pyx":817 - * xi_n = xi_root+D8_XOFFSET[i_n] - * yi_n = yi_root+D8_YOFFSET[i_n] - * 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":822 - * nodata_neighbor = 1 - * break - * n_height = filled_dem_managed_raster.get(xi_n, yi_n) # <<<<<<<<<<<<<< - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): - * # 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":823 - * break - * n_height = filled_dem_managed_raster.get(xi_n, yi_n) - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * # it'll drain to nodata - * nodata_neighbor = 1 - */ - __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_n_height, __pyx_v_dem_nodata, 1e-8, 1e-5) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":825 - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): - * # it'll drain to nodata - * nodata_neighbor = 1 # <<<<<<<<<<<<<< - * break - * if n_height < center_val: - */ - __pyx_v_nodata_neighbor = 1; - - /* "pygeoprocessing/routing/routing.pyx":826 - * # 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":823 - * break - * n_height = filled_dem_managed_raster.get(xi_n, yi_n) - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * # it'll drain to nodata - * nodata_neighbor = 1 - */ - } - - /* "pygeoprocessing/routing/routing.pyx":827 - * nodata_neighbor = 1 - * break - * if n_height < center_val: # <<<<<<<<<<<<<< - * # it'll drain downhill - * downhill_neighbor = 1 - */ - __pyx_t_5 = ((__pyx_v_n_height < __pyx_v_center_val) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":829 - * if n_height < center_val: - * # it'll drain downhill - * downhill_neighbor = 1 # <<<<<<<<<<<<<< - * break - * - */ - __pyx_v_downhill_neighbor = 1; - - /* "pygeoprocessing/routing/routing.pyx":830 - * # it'll drain downhill - * downhill_neighbor = 1 - * break # <<<<<<<<<<<<<< - * - * if downhill_neighbor or nodata_neighbor: - */ - goto __pyx_L27_break; - - /* "pygeoprocessing/routing/routing.pyx":827 - * nodata_neighbor = 1 - * break - * if n_height < center_val: # <<<<<<<<<<<<<< - * # it'll drain downhill - * downhill_neighbor = 1 - */ - } - } - __pyx_L27_break:; - - /* "pygeoprocessing/routing/routing.pyx":832 - * break - * - * if downhill_neighbor or nodata_neighbor: # <<<<<<<<<<<<<< - * # it drains, so skip - * continue - */ - __pyx_t_6 = (__pyx_v_downhill_neighbor != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L36_bool_binop_done; - } - __pyx_t_6 = (__pyx_v_nodata_neighbor != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L36_bool_binop_done:; - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":834 - * 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":832 - * break - * - * if downhill_neighbor or nodata_neighbor: # <<<<<<<<<<<<<< - * # it drains, so skip - * continue - */ - } - - /* "pygeoprocessing/routing/routing.pyx":838 - * # 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) - * natural_drain_exists = 0 - */ - __pyx_t_26.xi = __pyx_v_xi_root; - __pyx_t_26.yi = __pyx_v_yi_root; - __pyx_v_search_queue.push(__pyx_t_26); - - /* "pygeoprocessing/routing/routing.pyx":839 - * # 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) # <<<<<<<<<<<<<< - * natural_drain_exists = 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":840 - * search_queue.push(CoordinateType(xi_root, yi_root)) - * flat_region_mask_managed_raster.set(xi_root, yi_root, 1) - * natural_drain_exists = 0 # <<<<<<<<<<<<<< - * - * # this loop does a BFS starting at this pixel to all pixels - */ - __pyx_v_natural_drain_exists = 0; - - /* "pygeoprocessing/routing/routing.pyx":848 - * # it can be entirely marked as processed and not re-accessed - * # on later iterations - * search_steps = 0 # <<<<<<<<<<<<<< - * while not search_queue.empty(): - * xi_q = search_queue.front().xi - */ - __pyx_v_search_steps = 0; - - /* "pygeoprocessing/routing/routing.pyx":849 - * # on later iterations - * search_steps = 0 - * while not search_queue.empty(): # <<<<<<<<<<<<<< - * xi_q = search_queue.front().xi - * yi_q = search_queue.front().yi - */ - while (1) { - __pyx_t_5 = ((!(__pyx_v_search_queue.empty() != 0)) != 0); - if (!__pyx_t_5) break; - - /* "pygeoprocessing/routing/routing.pyx":850 - * search_steps = 0 - * while not search_queue.empty(): - * xi_q = search_queue.front().xi # <<<<<<<<<<<<<< - * yi_q = search_queue.front().yi - * search_queue.pop() - */ - __pyx_t_25 = __pyx_v_search_queue.front().xi; - __pyx_v_xi_q = __pyx_t_25; - - /* "pygeoprocessing/routing/routing.pyx":851 - * while not search_queue.empty(): - * xi_q = search_queue.front().xi - * yi_q = search_queue.front().yi # <<<<<<<<<<<<<< - * search_queue.pop() - * if search_steps > max_pixel_fill_count: - */ - __pyx_t_25 = __pyx_v_search_queue.front().yi; - __pyx_v_yi_q = __pyx_t_25; - - /* "pygeoprocessing/routing/routing.pyx":852 - * xi_q = search_queue.front().xi - * yi_q = search_queue.front().yi - * search_queue.pop() # <<<<<<<<<<<<<< - * if search_steps > max_pixel_fill_count: - * # clear the search queue and quit - */ - __pyx_v_search_queue.pop(); - - /* "pygeoprocessing/routing/routing.pyx":853 - * yi_q = search_queue.front().yi - * search_queue.pop() - * if search_steps > max_pixel_fill_count: # <<<<<<<<<<<<<< - * # clear the search queue and quit - * while not search_queue.empty(): - */ - __pyx_t_5 = ((__pyx_v_search_steps > __pyx_v_max_pixel_fill_count) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":855 - * if search_steps > max_pixel_fill_count: - * # clear the search queue and quit - * while not search_queue.empty(): # <<<<<<<<<<<<<< - * search_queue.pop() - * natural_drain_exists = 1 - */ - while (1) { - __pyx_t_5 = ((!(__pyx_v_search_queue.empty() != 0)) != 0); - if (!__pyx_t_5) break; - - /* "pygeoprocessing/routing/routing.pyx":856 - * # clear the search queue and quit - * while not search_queue.empty(): - * search_queue.pop() # <<<<<<<<<<<<<< - * natural_drain_exists = 1 - * break - */ - __pyx_v_search_queue.pop(); - } - - /* "pygeoprocessing/routing/routing.pyx":857 - * while not search_queue.empty(): - * search_queue.pop() - * natural_drain_exists = 1 # <<<<<<<<<<<<<< - * break - * search_steps += 1 - */ - __pyx_v_natural_drain_exists = 1; - - /* "pygeoprocessing/routing/routing.pyx":858 - * search_queue.pop() - * natural_drain_exists = 1 - * break # <<<<<<<<<<<<<< - * search_steps += 1 - * - */ - goto __pyx_L39_break; - - /* "pygeoprocessing/routing/routing.pyx":853 - * yi_q = search_queue.front().yi - * search_queue.pop() - * if search_steps > max_pixel_fill_count: # <<<<<<<<<<<<<< - * # clear the search queue and quit - * while not search_queue.empty(): - */ - } - - /* "pygeoprocessing/routing/routing.pyx":859 - * natural_drain_exists = 1 - * break - * search_steps += 1 # <<<<<<<<<<<<<< - * - * for i_n in range(8): - */ - __pyx_v_search_steps = (__pyx_v_search_steps + 1); - - /* "pygeoprocessing/routing/routing.pyx":861 - * search_steps += 1 - * - * for i_n in range(8): # <<<<<<<<<<<<<< - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] - */ - for (__pyx_t_25 = 0; __pyx_t_25 < 8; __pyx_t_25+=1) { - __pyx_v_i_n = __pyx_t_25; - - /* "pygeoprocessing/routing/routing.pyx":862 - * - * for i_n in range(8): - * xi_n = xi_q+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< - * yi_n = yi_q+D8_YOFFSET[i_n] - * if (xi_n < 0 or xi_n >= raster_x_size or - */ - __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":863 - * for i_n in range(8): - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< - * 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_D8_YOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":864 - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] - * if (xi_n < 0 or xi_n >= raster_x_size or # <<<<<<<<<<<<<< - * yi_n < 0 or yi_n >= raster_y_size): - * natural_drain_exists = 1 - */ - __pyx_t_6 = ((__pyx_v_xi_n < 0) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L46_bool_binop_done; - } - __pyx_t_6 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L46_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":865 - * yi_n = yi_q+D8_YOFFSET[i_n] - * if (xi_n < 0 or xi_n >= raster_x_size or - * yi_n < 0 or yi_n >= raster_y_size): # <<<<<<<<<<<<<< - * natural_drain_exists = 1 - * continue - */ - __pyx_t_6 = ((__pyx_v_yi_n < 0) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L46_bool_binop_done; - } - __pyx_t_6 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L46_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":864 - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] - * if (xi_n < 0 or xi_n >= raster_x_size or # <<<<<<<<<<<<<< - * yi_n < 0 or yi_n >= raster_y_size): - * natural_drain_exists = 1 - */ - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":866 - * if (xi_n < 0 or xi_n >= raster_x_size or - * yi_n < 0 or yi_n >= raster_y_size): - * natural_drain_exists = 1 # <<<<<<<<<<<<<< - * continue - * n_height = filled_dem_managed_raster.get( - */ - __pyx_v_natural_drain_exists = 1; - - /* "pygeoprocessing/routing/routing.pyx":867 - * yi_n < 0 or yi_n >= raster_y_size): - * natural_drain_exists = 1 - * continue # <<<<<<<<<<<<<< - * n_height = filled_dem_managed_raster.get( - * xi_n, yi_n) - */ - goto __pyx_L43_continue; - - /* "pygeoprocessing/routing/routing.pyx":864 - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] - * if (xi_n < 0 or xi_n >= raster_x_size or # <<<<<<<<<<<<<< - * yi_n < 0 or yi_n >= raster_y_size): - * natural_drain_exists = 1 - */ - } - - /* "pygeoprocessing/routing/routing.pyx":868 - * natural_drain_exists = 1 - * continue - * n_height = filled_dem_managed_raster.get( # <<<<<<<<<<<<<< - * xi_n, yi_n) - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): - */ - __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":870 - * n_height = filled_dem_managed_raster.get( - * xi_n, yi_n) - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * natural_drain_exists = 1 - * continue - */ - __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_n_height, __pyx_v_dem_nodata, 1e-8, 1e-5) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":871 - * xi_n, yi_n) - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): - * natural_drain_exists = 1 # <<<<<<<<<<<<<< - * continue - * if n_height < center_val: - */ - __pyx_v_natural_drain_exists = 1; - - /* "pygeoprocessing/routing/routing.pyx":872 - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): - * natural_drain_exists = 1 - * continue # <<<<<<<<<<<<<< - * if n_height < center_val: - * natural_drain_exists = 1 - */ - goto __pyx_L43_continue; - - /* "pygeoprocessing/routing/routing.pyx":870 - * n_height = filled_dem_managed_raster.get( - * xi_n, yi_n) - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * natural_drain_exists = 1 - * continue - */ - } - - /* "pygeoprocessing/routing/routing.pyx":873 - * natural_drain_exists = 1 - * continue - * if n_height < center_val: # <<<<<<<<<<<<<< - * natural_drain_exists = 1 - * continue - */ - __pyx_t_5 = ((__pyx_v_n_height < __pyx_v_center_val) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":874 - * continue - * if n_height < center_val: - * natural_drain_exists = 1 # <<<<<<<<<<<<<< - * continue - * if flat_region_mask_managed_raster.get( - */ - __pyx_v_natural_drain_exists = 1; - - /* "pygeoprocessing/routing/routing.pyx":875 - * if n_height < center_val: - * natural_drain_exists = 1 - * continue # <<<<<<<<<<<<<< - * if flat_region_mask_managed_raster.get( - * xi_n, yi_n) == 1: - */ - goto __pyx_L43_continue; - - /* "pygeoprocessing/routing/routing.pyx":873 - * natural_drain_exists = 1 - * continue - * if n_height < center_val: # <<<<<<<<<<<<<< - * natural_drain_exists = 1 - * continue - */ - } - - /* "pygeoprocessing/routing/routing.pyx":877 - * continue - * if flat_region_mask_managed_raster.get( - * xi_n, yi_n) == 1: # <<<<<<<<<<<<<< - * # been set before on a previous iteration, skip - * continue - */ - __pyx_t_5 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flat_region_mask_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n) == 1.0) != 0); - - /* "pygeoprocessing/routing/routing.pyx":876 - * natural_drain_exists = 1 - * continue - * if flat_region_mask_managed_raster.get( # <<<<<<<<<<<<<< - * xi_n, yi_n) == 1: - * # been set before on a previous iteration, skip - */ - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":879 - * xi_n, yi_n) == 1: - * # been set before on a previous iteration, skip - * continue # <<<<<<<<<<<<<< - * if n_height == center_val: - * # only grow if it's at the same level and not - */ - goto __pyx_L43_continue; - - /* "pygeoprocessing/routing/routing.pyx":876 - * natural_drain_exists = 1 - * continue - * if flat_region_mask_managed_raster.get( # <<<<<<<<<<<<<< - * xi_n, yi_n) == 1: - * # been set before on a previous iteration, skip - */ - } - - /* "pygeoprocessing/routing/routing.pyx":880 - * # been set before on a previous iteration, skip - * continue - * if n_height == center_val: # <<<<<<<<<<<<<< - * # only grow if it's at the same level and not - * # previously visited - */ - __pyx_t_5 = ((__pyx_v_n_height == __pyx_v_center_val) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":884 - * # previously visited - * search_queue.push( - * CoordinateType(xi_n, yi_n)) # <<<<<<<<<<<<<< - * flat_region_mask_managed_raster.set( - * xi_n, yi_n, 1) - */ - __pyx_t_26.xi = __pyx_v_xi_n; - __pyx_t_26.yi = __pyx_v_yi_n; - - /* "pygeoprocessing/routing/routing.pyx":883 - * # 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_26); - - /* "pygeoprocessing/routing/routing.pyx":885 - * 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":880 - * # been set before on a previous iteration, skip - * continue - * if n_height == center_val: # <<<<<<<<<<<<<< - * # only grow if it's at the same level and not - * # previously visited - */ - } - __pyx_L43_continue:; - } - } - __pyx_L39_break:; - - /* "pygeoprocessing/routing/routing.pyx":888 - * xi_n, yi_n, 1) - * - * if not natural_drain_exists: # <<<<<<<<<<<<<< - * # this space does not naturally drain, so fill it - * pixel = PixelType( - */ - __pyx_t_5 = ((!(__pyx_v_natural_drain_exists != 0)) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":891 - * # this space does not naturally drain, so fill it - * pixel = PixelType( - * center_val, xi_root, yi_root, ( # <<<<<<<<<<<<<< - * n_x_blocks * (yi_root >> BLOCK_BITS) + - * xi_root >> BLOCK_BITS)) - */ - __pyx_t_27.value = __pyx_v_center_val; - __pyx_t_27.xi = __pyx_v_xi_root; - __pyx_t_27.yi = __pyx_v_yi_root; - - /* "pygeoprocessing/routing/routing.pyx":893 - * 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_27.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_27; - - /* "pygeoprocessing/routing/routing.pyx":894 - * 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":895 - * 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":897 - * 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":888 - * xi_n, yi_n, 1) - * - * if not natural_drain_exists: # <<<<<<<<<<<<<< - * # this space does not naturally drain, so fill it - * pixel = PixelType( - */ - } - - /* "pygeoprocessing/routing/routing.pyx":902 - * # first non-processed pixel that's < pixel.height or nodata - * # will be the lowest pour point - * pour_point = 0 # <<<<<<<<<<<<<< - * fill_height = dem_nodata - * search_steps = 0 - */ - __pyx_v_pour_point = 0; - - /* "pygeoprocessing/routing/routing.pyx":903 - * # will be the lowest pour point - * pour_point = 0 - * fill_height = dem_nodata # <<<<<<<<<<<<<< - * search_steps = 0 - * while not pit_queue.empty(): - */ - __pyx_v_fill_height = __pyx_v_dem_nodata; - - /* "pygeoprocessing/routing/routing.pyx":904 - * pour_point = 0 - * fill_height = dem_nodata - * search_steps = 0 # <<<<<<<<<<<<<< - * while not pit_queue.empty(): - * pixel = pit_queue.top() - */ - __pyx_v_search_steps = 0; - - /* "pygeoprocessing/routing/routing.pyx":905 - * fill_height = dem_nodata - * search_steps = 0 - * while not pit_queue.empty(): # <<<<<<<<<<<<<< - * pixel = pit_queue.top() - * pit_queue.pop() - */ - while (1) { - __pyx_t_5 = ((!(__pyx_v_pit_queue.empty() != 0)) != 0); - if (!__pyx_t_5) break; - - /* "pygeoprocessing/routing/routing.pyx":906 - * search_steps = 0 - * 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":907 - * 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":908 - * pixel = pit_queue.top() - * pit_queue.pop() - * xi_q = pixel.xi # <<<<<<<<<<<<<< - * yi_q = pixel.yi - * - */ - __pyx_t_25 = __pyx_v_pixel.xi; - __pyx_v_xi_q = __pyx_t_25; - - /* "pygeoprocessing/routing/routing.pyx":909 - * pit_queue.pop() - * xi_q = pixel.xi - * yi_q = pixel.yi # <<<<<<<<<<<<<< - * - * # search to see if the fill has gone on too long - */ - __pyx_t_25 = __pyx_v_pixel.yi; - __pyx_v_yi_q = __pyx_t_25; - - /* "pygeoprocessing/routing/routing.pyx":912 - * - * # search to see if the fill has gone on too long - * if search_steps > max_pixel_fill_count: # <<<<<<<<<<<<<< - * # clear pit_queue and quit - * pit_queue = PitPriorityQueueType() - */ - __pyx_t_5 = ((__pyx_v_search_steps > __pyx_v_max_pixel_fill_count) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":914 - * if search_steps > max_pixel_fill_count: - * # clear pit_queue and quit - * pit_queue = PitPriorityQueueType() # <<<<<<<<<<<<<< - * natural_drain_exists = 1 - * break - */ - try { - __pyx_t_28 = __pyx_t_15pygeoprocessing_7routing_7routing_PitPriorityQueueType(); - } catch(...) { - __Pyx_CppExn2PyErr(); - __PYX_ERR(0, 914, __pyx_L1_error) - } - __pyx_v_pit_queue = __pyx_t_28; - - /* "pygeoprocessing/routing/routing.pyx":915 - * # clear pit_queue and quit - * pit_queue = PitPriorityQueueType() - * natural_drain_exists = 1 # <<<<<<<<<<<<<< - * break - * search_steps += 1 - */ - __pyx_v_natural_drain_exists = 1; - - /* "pygeoprocessing/routing/routing.pyx":916 - * pit_queue = PitPriorityQueueType() - * natural_drain_exists = 1 - * break # <<<<<<<<<<<<<< - * search_steps += 1 - * - */ - goto __pyx_L56_break; - - /* "pygeoprocessing/routing/routing.pyx":912 - * - * # search to see if the fill has gone on too long - * if search_steps > max_pixel_fill_count: # <<<<<<<<<<<<<< - * # clear pit_queue and quit - * pit_queue = PitPriorityQueueType() - */ - } - - /* "pygeoprocessing/routing/routing.pyx":917 - * natural_drain_exists = 1 - * break - * search_steps += 1 # <<<<<<<<<<<<<< - * - * # this is the potential fill height if pixel is pour point - */ - __pyx_v_search_steps = (__pyx_v_search_steps + 1); - - /* "pygeoprocessing/routing/routing.pyx":920 - * - * # this is the potential fill height if pixel is pour point - * fill_height = pixel.value # <<<<<<<<<<<<<< - * - * for i_n in range(8): - */ - __pyx_t_7 = __pyx_v_pixel.value; - __pyx_v_fill_height = __pyx_t_7; - - /* "pygeoprocessing/routing/routing.pyx":922 - * fill_height = pixel.value - * - * for i_n in range(8): # <<<<<<<<<<<<<< - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] - */ - for (__pyx_t_25 = 0; __pyx_t_25 < 8; __pyx_t_25+=1) { - __pyx_v_i_n = __pyx_t_25; - - /* "pygeoprocessing/routing/routing.pyx":923 - * - * for i_n in range(8): - * xi_n = xi_q+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< - * yi_n = yi_q+D8_YOFFSET[i_n] - * if (xi_n < 0 or xi_n >= raster_x_size or - */ - __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":924 - * for i_n in range(8): - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< - * 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_D8_YOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":925 - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] - * 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_6 = ((__pyx_v_xi_n < 0) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L61_bool_binop_done; - } - __pyx_t_6 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L61_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":926 - * yi_n = yi_q+D8_YOFFSET[i_n] - * 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_6 = ((__pyx_v_yi_n < 0) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L61_bool_binop_done; - } - __pyx_t_6 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L61_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":925 - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] - * 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_5) { - - /* "pygeoprocessing/routing/routing.pyx":928 - * 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":929 - * # drain off the edge of the raster - * pour_point = 1 - * break # <<<<<<<<<<<<<< - * - * if pit_mask_managed_raster.get( - */ - goto __pyx_L59_break; - - /* "pygeoprocessing/routing/routing.pyx":925 - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] - * 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":932 - * - * if pit_mask_managed_raster.get( - * xi_n, yi_n) == feature_id: # <<<<<<<<<<<<<< - * # this cell has already been processed - * continue - */ - __pyx_t_5 = ((__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":931 - * break - * - * if pit_mask_managed_raster.get( # <<<<<<<<<<<<<< - * xi_n, yi_n) == feature_id: - * # this cell has already been processed - */ - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":934 - * xi_n, yi_n) == feature_id: - * # this cell has already been processed - * continue # <<<<<<<<<<<<<< - * - * # mark as visited in the search for pour point - */ - goto __pyx_L58_continue; - - /* "pygeoprocessing/routing/routing.pyx":931 - * break - * - * if pit_mask_managed_raster.get( # <<<<<<<<<<<<<< - * xi_n, yi_n) == feature_id: - * # this cell has already been processed - */ - } - - /* "pygeoprocessing/routing/routing.pyx":937 - * - * # mark as visited in the search for pour point - * pit_mask_managed_raster.set(xi_n, yi_n, feature_id) # <<<<<<<<<<<<<< - * - * n_height = filled_dem_managed_raster.get(xi_n, yi_n) - */ - __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":939 - * pit_mask_managed_raster.set(xi_n, yi_n, feature_id) - * - * n_height = filled_dem_managed_raster.get(xi_n, yi_n) # <<<<<<<<<<<<<< - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5) 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":940 - * - * n_height = filled_dem_managed_raster.get(xi_n, yi_n) - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5) or ( # <<<<<<<<<<<<<< - * n_height < fill_height): - * # we encounter a neighbor not processed that is - */ - __pyx_t_6 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_n_height, __pyx_v_dem_nodata, 1e-8, 1e-5) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L67_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":941 - * n_height = filled_dem_managed_raster.get(xi_n, yi_n) - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5) or ( - * n_height < fill_height): # <<<<<<<<<<<<<< - * # we encounter a neighbor not processed that is - * # lower than the current pixel or nodata - */ - __pyx_t_6 = ((__pyx_v_n_height < __pyx_v_fill_height) != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L67_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":940 - * - * n_height = filled_dem_managed_raster.get(xi_n, yi_n) - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5) or ( # <<<<<<<<<<<<<< - * n_height < fill_height): - * # we encounter a neighbor not processed that is - */ - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":944 - * # 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":945 - * # lower than the current pixel or nodata - * pour_point = 1 - * break # <<<<<<<<<<<<<< - * - * # push onto queue, set the priority to be the block - */ - goto __pyx_L59_break; - - /* "pygeoprocessing/routing/routing.pyx":940 - * - * n_height = filled_dem_managed_raster.get(xi_n, yi_n) - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5) or ( # <<<<<<<<<<<<<< - * n_height < fill_height): - * # we encounter a neighbor not processed that is - */ - } - - /* "pygeoprocessing/routing/routing.pyx":950 - * # index - * pixel = PixelType( - * n_height, xi_n, yi_n, ( # <<<<<<<<<<<<<< - * n_x_blocks * (yi_n >> BLOCK_BITS) + - * xi_n >> BLOCK_BITS)) - */ - __pyx_t_27.value = __pyx_v_n_height; - __pyx_t_27.xi = __pyx_v_xi_n; - __pyx_t_27.yi = __pyx_v_yi_n; - - /* "pygeoprocessing/routing/routing.pyx":952 - * n_height, xi_n, yi_n, ( - * n_x_blocks * (yi_n >> BLOCK_BITS) + - * xi_n >> BLOCK_BITS)) # <<<<<<<<<<<<<< - * pit_queue.push(pixel) - * - */ - __pyx_t_27.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_27; - - /* "pygeoprocessing/routing/routing.pyx":953 - * 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_L58_continue:; - } - __pyx_L59_break:; - - /* "pygeoprocessing/routing/routing.pyx":955 - * pit_queue.push(pixel) - * - * if pour_point: # <<<<<<<<<<<<<< - * # found a pour point, clear the queue - * pit_queue = PitPriorityQueueType() - */ - __pyx_t_5 = (__pyx_v_pour_point != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":957 - * 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_28 = __pyx_t_15pygeoprocessing_7routing_7routing_PitPriorityQueueType(); - } catch(...) { - __Pyx_CppExn2PyErr(); - __PYX_ERR(0, 957, __pyx_L1_error) - } - __pyx_v_pit_queue = __pyx_t_28; - - /* "pygeoprocessing/routing/routing.pyx":965 - * # 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_26.xi = __pyx_v_xi_root; - __pyx_t_26.yi = __pyx_v_yi_root; - __pyx_v_fill_queue.push(__pyx_t_26); - - /* "pygeoprocessing/routing/routing.pyx":966 - * # 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":955 - * pit_queue.push(pixel) - * - * if pour_point: # <<<<<<<<<<<<<< - * # found a pour point, clear the queue - * pit_queue = PitPriorityQueueType() - */ - } - } - __pyx_L56_break:; - - /* "pygeoprocessing/routing/routing.pyx":970 - * - * # 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_5 = ((!(__pyx_v_fill_queue.empty() != 0)) != 0); - if (!__pyx_t_5) break; - - /* "pygeoprocessing/routing/routing.pyx":971 - * # 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_25 = __pyx_v_fill_queue.front().xi; - __pyx_v_xi_q = __pyx_t_25; - - /* "pygeoprocessing/routing/routing.pyx":972 - * while not fill_queue.empty(): - * xi_q = fill_queue.front().xi - * yi_q = fill_queue.front().yi # <<<<<<<<<<<<<< - * fill_queue.pop() - * - */ - __pyx_t_25 = __pyx_v_fill_queue.front().yi; - __pyx_v_yi_q = __pyx_t_25; - - /* "pygeoprocessing/routing/routing.pyx":973 - * 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":975 - * fill_queue.pop() - * - * for i_n in range(8): # <<<<<<<<<<<<<< - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] - */ - for (__pyx_t_25 = 0; __pyx_t_25 < 8; __pyx_t_25+=1) { - __pyx_v_i_n = __pyx_t_25; - - /* "pygeoprocessing/routing/routing.pyx":976 - * - * for i_n in range(8): - * xi_n = xi_q+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< - * yi_n = yi_q+D8_YOFFSET[i_n] - * if (xi_n < 0 or xi_n >= raster_x_size or - */ - __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":977 - * for i_n in range(8): - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< - * 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_D8_YOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":978 - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] - * if (xi_n < 0 or xi_n >= raster_x_size or # <<<<<<<<<<<<<< - * yi_n < 0 or yi_n >= raster_y_size): - * continue - */ - __pyx_t_6 = ((__pyx_v_xi_n < 0) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L75_bool_binop_done; - } - __pyx_t_6 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L75_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":979 - * yi_n = yi_q+D8_YOFFSET[i_n] - * if (xi_n < 0 or xi_n >= raster_x_size or - * yi_n < 0 or yi_n >= raster_y_size): # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_6 = ((__pyx_v_yi_n < 0) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L75_bool_binop_done; - } - __pyx_t_6 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L75_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":978 - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] - * 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":980 - * 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_L72_continue; - - /* "pygeoprocessing/routing/routing.pyx":978 - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] - * 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":983 - * - * 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_5 = ((__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":982 - * continue - * - * if filled_dem_managed_raster.get( # <<<<<<<<<<<<<< - * xi_n, yi_n) < fill_height: - * filled_dem_managed_raster.set( - */ - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":984 - * 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":986 - * 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_26.xi = __pyx_v_xi_n; - __pyx_t_26.yi = __pyx_v_yi_n; - __pyx_v_fill_queue.push(__pyx_t_26); - - /* "pygeoprocessing/routing/routing.pyx":982 - * continue - * - * if filled_dem_managed_raster.get( # <<<<<<<<<<<<<< - * xi_n, yi_n) < fill_height: - * filled_dem_managed_raster.set( - */ - } - __pyx_L72_continue:; - } - } - __pyx_L22_continue:; - } - } - - /* "pygeoprocessing/routing/routing.pyx":780 - * - * # this outer loop searches for a pixel that is locally undrained - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * dem_raster_path_band, offset_only=True, largest_block=0): - * win_xsize = offset_dict['win_xsize'] - */ - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":988 - * 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, 988, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_14 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_14)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_14); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_2 = (__pyx_t_14) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_14) : __Pyx_PyObject_CallNoArg(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 988, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":989 - * - * pit_mask_managed_raster.close() - * flat_region_mask_managed_raster.close() # <<<<<<<<<<<<<< - * shutil.rmtree(working_dir_path) - * LOGGER.info('(fill pits): complete') - */ - __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, 989, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_14 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_14)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_14); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_2 = (__pyx_t_14) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_14) : __Pyx_PyObject_CallNoArg(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 989, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":990 - * pit_mask_managed_raster.close() - * flat_region_mask_managed_raster.close() - * shutil.rmtree(working_dir_path) # <<<<<<<<<<<<<< - * LOGGER.info('(fill pits): complete') - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_shutil); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 990, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_rmtree); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 990, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - } - } - __pyx_t_2 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_1, __pyx_v_working_dir_path) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_v_working_dir_path); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 990, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":991 - * flat_region_mask_managed_raster.close() - * shutil.rmtree(working_dir_path) - * LOGGER.info('(fill pits): complete') # <<<<<<<<<<<<<< - * - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 991, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 991, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_14 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_14)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_14); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_2 = (__pyx_t_14) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_14, __pyx_kp_u_fill_pits_complete) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_kp_u_fill_pits_complete); - __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 991, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":612 - * - * - * def fill_pits( # <<<<<<<<<<<<<< - * dem_raster_path_band, target_filled_dem_raster_path, - * working_dir=None, long max_pixel_fill_count=_MAX_PIXEL_FILL_COUNT, - */ - - /* 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_14); - __Pyx_XDECREF(__pyx_t_15); - __Pyx_XDECREF(__pyx_t_16); - __Pyx_AddTraceback("pygeoprocessing.routing.routing.fill_pits", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __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_base_datatype); - __Pyx_XDECREF(__pyx_v_filled_dem_raster); - __Pyx_XDECREF(__pyx_v_filled_dem_band); - __Pyx_XDECREF(__pyx_v_offset_info); - __Pyx_XDECREF(__pyx_v_block_array); - __Pyx_XDECREF((PyObject *)__pyx_v_filled_dem_managed_raster); - __Pyx_XDECREF(__pyx_v_offset_dict); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pygeoprocessing/routing/routing.pyx":994 - * - * - * 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 (str): 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 3 2 1\n 4 x 0\n 5 6 7\n\n working_dir (str): 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 raster_driver_creation_tuple (tuple): a tuple containing a GDAL driver\n name string as the first element and a GDAL creation options\n tuple/list as the second. Defaults to a GTiff driver tuple\n defined at geoprocessing.DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS.\n\n Returns:\n None.\n "; -static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_5flow_dir_d8 = {"flow_dir_d8", (PyCFunction)(void*)(PyCFunctionWithKeywords)__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_raster_driver_creation_tuple = 0; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 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_raster_driver_creation_tuple,0}; - PyObject* values[4] = {0,0,0,0}; - - /* "pygeoprocessing/routing/routing.pyx":996 - * def flow_dir_d8( - * dem_raster_path_band, target_flow_dir_path, - * working_dir=None, # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): - * """D8 flow direction. - */ - values[2] = ((PyObject *)Py_None); - values[3] = __pyx_k__6; - 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, 994, __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_raster_driver_creation_tuple); - 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, 994, __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_raster_driver_creation_tuple = 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, 994, __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_raster_driver_creation_tuple); - - /* "pygeoprocessing/routing/routing.pyx":994 - * - * - * 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_raster_driver_creation_tuple) { - 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 __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 __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_raster_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; - int __pyx_v_current_pixel; - 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; - int __pyx_t_5; - int __pyx_t_6; - double __pyx_t_7; - PyObject *(*__pyx_t_8)(PyObject *); - int __pyx_t_9; - int __pyx_t_10; - PyObject *__pyx_t_11 = NULL; - 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 *); - Py_ssize_t __pyx_t_19; - Py_UCS4 __pyx_t_20; - PyArrayObject *__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; - 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __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":1070 - * # 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":1074 - * # 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1074, __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, 1074, __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, 1074, __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); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1074, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __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":1075 - * # 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_u_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1075, __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, 1075, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_t_3, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1075, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1075, __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_v_base_nodata = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1076 - * 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_5 = (__pyx_v_base_nodata != Py_None); - __pyx_t_6 = (__pyx_t_5 != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/routing/routing.pyx":1078 - * 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1078, __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, 1078, __pyx_L1_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); - } - } - __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_v_base_nodata) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_base_nodata); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1078, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_7 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 1078, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_dem_nodata = __pyx_t_7; - - /* "pygeoprocessing/routing/routing.pyx":1076 - * 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":1081 - * 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":1084 - * - * # 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_u_raster_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1084, __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, 1084, __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, 1084, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1084, __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_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1084, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_4)->tp_iternext; - index = 0; __pyx_t_1 = __pyx_t_8(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - 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, 1084, __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, 1084, __pyx_L1_error) - __pyx_L5_unpacking_done:; - } - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1084, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1084, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_raster_x_size = __pyx_t_9; - __pyx_v_raster_y_size = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":1087 - * - * # 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":1090 - * - * # 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_11, &__pyx_t_12, &__pyx_t_13); - __Pyx_XGOTREF(__pyx_t_11); - __Pyx_XGOTREF(__pyx_t_12); - __Pyx_XGOTREF(__pyx_t_13); - /*try:*/ { - - /* "pygeoprocessing/routing/routing.pyx":1091 - * # set up the working dir for the mask rasters - * try: - * if working_dir is not None: # <<<<<<<<<<<<<< - * os.makedirs(working_dir) - * except OSError: - */ - __pyx_t_6 = (__pyx_v_working_dir != Py_None); - __pyx_t_5 = (__pyx_t_6 != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1092 - * try: - * if working_dir is not None: - * os.makedirs(working_dir) # <<<<<<<<<<<<<< - * except OSError: - * pass - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1092, __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, 1092, __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); - } - } - __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_v_working_dir) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_working_dir); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1092, __pyx_L6_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1091 - * # 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":1090 - * - * # set up the working dir for the mask rasters - * try: # <<<<<<<<<<<<<< - * if working_dir is not None: - * os.makedirs(working_dir) - */ - } - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - goto __pyx_L11_try_end; - __pyx_L6_error:; - __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; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1093 - * if working_dir is not None: - * os.makedirs(working_dir) - * except OSError: # <<<<<<<<<<<<<< - * pass - * working_dir_path = tempfile.mkdtemp( - */ - __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OSError); - if (__pyx_t_10) { - __Pyx_ErrRestore(0,0,0); - goto __pyx_L7_exception_handled; - } - goto __pyx_L8_except_error; - __pyx_L8_except_error:; - - /* "pygeoprocessing/routing/routing.pyx":1090 - * - * # set up the working dir for the mask rasters - * try: # <<<<<<<<<<<<<< - * if working_dir is not None: - * os.makedirs(working_dir) - */ - __Pyx_XGIVEREF(__pyx_t_11); - __Pyx_XGIVEREF(__pyx_t_12); - __Pyx_XGIVEREF(__pyx_t_13); - __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13); - goto __pyx_L1_error; - __pyx_L7_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_11); - __Pyx_XGIVEREF(__pyx_t_12); - __Pyx_XGIVEREF(__pyx_t_13); - __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13); - __pyx_L11_try_end:; - } - - /* "pygeoprocessing/routing/routing.pyx":1095 - * 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_tempfile); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1095, __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, 1095, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1096 - * 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, 1096, __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, 1096, __pyx_L1_error) - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_time); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1096, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_strftime); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1096, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1097 - * 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_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_time); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1097, __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, 1097, __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); - } - } - __pyx_t_4 = (__pyx_t_15) ? __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_t_15) : __Pyx_PyObject_CallNoArg(__pyx_t_16); - __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1097, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_16 = NULL; - __pyx_t_10 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { - __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_16)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_16); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - __pyx_t_10 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_14)) { - PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_kp_u_Y_m_d__H__M__S, __pyx_t_4}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1096, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 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_14)) { - PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_kp_u_Y_m_d__H__M__S, __pyx_t_4}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1096, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - { - __pyx_t_15 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1096, __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_u_Y_m_d__H__M__S); - __Pyx_GIVEREF(__pyx_kp_u_Y_m_d__H__M__S); - PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_10, __pyx_kp_u_Y_m_d__H__M__S); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_10, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_15, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1096, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - } - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1096 - * 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_14 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_flow_dir_d8__s, __pyx_t_2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1096, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_prefix, __pyx_t_14) < 0) __PYX_ERR(0, 1096, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1095 - * 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_14 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1095, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __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_14; - __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1102 - * # 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1102, __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, 1102, __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, 1102, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1103 - * # 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_10 = 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_10 = 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_u_flat_region_mask_tif}; - __pyx_t_14 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1102, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_14); - } 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_u_flat_region_mask_tif}; - __pyx_t_14 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1102, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_14); - } else - #endif - { - __pyx_t_2 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1102, __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_v_working_dir_path); - __Pyx_GIVEREF(__pyx_v_working_dir_path); - PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_10, __pyx_v_working_dir_path); - __Pyx_INCREF(__pyx_kp_u_flat_region_mask_tif); - __Pyx_GIVEREF(__pyx_kp_u_flat_region_mask_tif); - PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_10, __pyx_kp_u_flat_region_mask_tif); - __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1102, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_flat_region_mask_path = __pyx_t_14; - __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1104 - * 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], - */ - __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1104, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1104, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1105 - * 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], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - */ - __pyx_t_14 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1105, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1105, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1105, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1106 - * pygeoprocessing.new_raster_from_base( - * dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte, - * [mask_nodata], # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * flat_region_mask_managed_raster = _ManagedRaster( - */ - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_mask_nodata); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1106, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_15 = PyList_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1106, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_GIVEREF(__pyx_t_2); - PyList_SET_ITEM(__pyx_t_15, 0, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1104 - * 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], - */ - __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1104, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_14); - __Pyx_INCREF(__pyx_v_flat_region_mask_path); - __Pyx_GIVEREF(__pyx_v_flat_region_mask_path); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_flat_region_mask_path); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_15); - PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_15); - __pyx_t_14 = 0; - __pyx_t_1 = 0; - __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1107 - * dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte, - * [mask_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< - * flat_region_mask_managed_raster = _ManagedRaster( - * flat_region_mask_path, 1, 1) - */ - __pyx_t_15 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1107, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 1107, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":1104 - * 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], - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1104, __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_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1108 - * [mask_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * flat_region_mask_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< - * flat_region_mask_path, 1, 1) - * - */ - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1108, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_flat_region_mask_path); - __Pyx_GIVEREF(__pyx_v_flat_region_mask_path); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_flat_region_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_15 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_1, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1108, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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":1111 - * 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":1112 - * - * flow_dir_nodata = 128 - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Byte, - * [flow_dir_nodata], - */ - __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1112, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1112, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1113 - * flow_dir_nodata = 128 - * pygeoprocessing.new_raster_from_base( - * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Byte, # <<<<<<<<<<<<<< - * [flow_dir_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - */ - __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, 1113, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1113, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1113, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1114 - * pygeoprocessing.new_raster_from_base( - * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Byte, - * [flow_dir_nodata], # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * flow_dir_managed_raster = _ManagedRaster(target_flow_dir_path, 1, 1) - */ - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_flow_dir_nodata); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1114, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_14 = PyList_New(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1114, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_GIVEREF(__pyx_t_2); - PyList_SET_ITEM(__pyx_t_14, 0, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1112 - * - * flow_dir_nodata = 128 - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Byte, - * [flow_dir_nodata], - */ - __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1112, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_15); - PyTuple_SET_ITEM(__pyx_t_2, 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_2, 1, __pyx_v_target_flow_dir_path); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_14); - __pyx_t_15 = 0; - __pyx_t_3 = 0; - __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1115 - * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Byte, - * [flow_dir_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< - * flow_dir_managed_raster = _ManagedRaster(target_flow_dir_path, 1, 1) - * - */ - __pyx_t_14 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1115, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 1115, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":1112 - * - * flow_dir_nodata = 128 - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Byte, - * [flow_dir_nodata], - */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_14); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1112, __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_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1116 - * [flow_dir_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * 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_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1116, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_target_flow_dir_path); - __Pyx_GIVEREF(__pyx_v_target_flow_dir_path); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_target_flow_dir_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_14 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_3, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1116, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_flow_dir_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_14); - __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1122 - * # 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1122, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_path); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1122, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_join); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1122, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1123 - * # 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_2 = NULL; - __pyx_t_10 = 0; - if (CYTHON_UNPACK_METHODS && likely(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_10 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_working_dir_path, __pyx_kp_u_plateau_distance_tif}; - __pyx_t_14 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1122, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_14); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_working_dir_path, __pyx_kp_u_plateau_distance_tif}; - __pyx_t_14 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1122, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_14); - } else - #endif - { - __pyx_t_1 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1122, __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_v_working_dir_path); - __Pyx_GIVEREF(__pyx_v_working_dir_path); - PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_10, __pyx_v_working_dir_path); - __Pyx_INCREF(__pyx_kp_u_plateau_distance_tif); - __Pyx_GIVEREF(__pyx_kp_u_plateau_distance_tif); - PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_10, __pyx_kp_u_plateau_distance_tif); - __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1122, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_plateau_distance_path = __pyx_t_14; - __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1124 - * 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_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1124, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1124, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1125 - * 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], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - */ - __pyx_t_14 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1125, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1125, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1125, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1126 - * 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], # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * plateau_distance_managed_raster = _ManagedRaster( - */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1126, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_int_neg_1); - __Pyx_GIVEREF(__pyx_int_neg_1); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_int_neg_1); - - /* "pygeoprocessing/routing/routing.pyx":1124 - * 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_15 = PyTuple_New(4); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1124, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_14); - __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_2); - PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_15, 3, __pyx_t_1); - __pyx_t_14 = 0; - __pyx_t_2 = 0; - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1126 - * 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], # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * plateau_distance_managed_raster = _ManagedRaster( - */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1126, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_From_int((__pyx_v_raster_x_size * __pyx_v_raster_y_size)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1126, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_14 = PyList_New(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1126, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_GIVEREF(__pyx_t_2); - PyList_SET_ITEM(__pyx_t_14, 0, __pyx_t_2); - __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_fill_value_list, __pyx_t_14) < 0) __PYX_ERR(0, 1126, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1127 - * dem_raster_path_band[0], plateau_distance_path, gdal.GDT_Float64, - * [-1], fill_value_list=[raster_x_size * raster_y_size], - * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< - * plateau_distance_managed_raster = _ManagedRaster( - * plateau_distance_path, 1, 1) - */ - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 1126, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":1124 - * 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_14 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_15, __pyx_t_1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1124, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1128 - * [-1], fill_value_list=[raster_x_size * raster_y_size], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * plateau_distance_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< - * plateau_distance_path, 1, 1) - * - */ - __pyx_t_14 = PyTuple_New(3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1128, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_INCREF(__pyx_v_plateau_distance_path); - __Pyx_GIVEREF(__pyx_v_plateau_distance_path); - PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_v_plateau_distance_path); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_int_1); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_14, 2, __pyx_int_1); - __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_14, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1128, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_v_plateau_distance_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1133 - * # 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":1134 - * - * 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_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_dem_raster_info, __pyx_n_u_block_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1134, __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, 1134, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_14 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_15 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_14 = PyList_GET_ITEM(sequence, 0); - __pyx_t_15 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_14); - __Pyx_INCREF(__pyx_t_15); - #else - __pyx_t_14 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1134, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_15 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1134, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - #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, 1134, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_3)->tp_iternext; - index = 0; __pyx_t_14 = __pyx_t_8(__pyx_t_3); if (unlikely(!__pyx_t_14)) goto __pyx_L13_unpacking_failed; - __Pyx_GOTREF(__pyx_t_14); - index = 1; __pyx_t_15 = __pyx_t_8(__pyx_t_3); if (unlikely(!__pyx_t_15)) goto __pyx_L13_unpacking_failed; - __Pyx_GOTREF(__pyx_t_15); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_3), 2) < 0) __PYX_ERR(0, 1134, __pyx_L1_error) - __pyx_t_8 = NULL; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L14_unpacking_done; - __pyx_L13_unpacking_failed:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_8 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 1134, __pyx_L1_error) - __pyx_L14_unpacking_done:; - } - __pyx_v_dem_block_xsize = __pyx_t_14; - __pyx_t_14 = 0; - __pyx_v_dem_block_ysize = __pyx_t_15; - __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1135 - * 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_1 = __Pyx_PyInt_SubtractObjC(__pyx_v_dem_block_xsize, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1135, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_15 = PyNumber_And(__pyx_v_dem_block_xsize, __pyx_t_1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1135, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_NeObjC(__pyx_t_15, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1135, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1135, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L16_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":1136 - * 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_1 = __Pyx_PyInt_SubtractObjC(__pyx_v_dem_block_ysize, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1136, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_15 = PyNumber_And(__pyx_v_dem_block_ysize, __pyx_t_1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1136, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_NeObjC(__pyx_t_15, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1136, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1136, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_5 = __pyx_t_6; - __pyx_L16_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":1135 - * 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_5) { - - /* "pygeoprocessing/routing/routing.pyx":1137 - * 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_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1137, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_warning); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1137, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_15 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { - __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_15)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_15); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - } - } - __pyx_t_1 = (__pyx_t_15) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_15, __pyx_kp_u_dem_is_not_a_power_of_2_creating) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_kp_u_dem_is_not_a_power_of_2_creating); - __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1137, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1139 - * 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]) - * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) - */ - __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_os); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1139, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_path); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1139, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_join); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1139, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_15 = NULL; - __pyx_t_10 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) { - __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_15)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_15); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - __pyx_t_10 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_14)) { - PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_v_working_dir_path, __pyx_kp_u_compatable_dem_tif}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1139, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) { - PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_v_working_dir_path, __pyx_kp_u_compatable_dem_tif}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1139, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_3 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1139, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (__pyx_t_15) { - __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_3, 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_3, 0+__pyx_t_10, __pyx_v_working_dir_path); - __Pyx_INCREF(__pyx_kp_u_compatable_dem_tif); - __Pyx_GIVEREF(__pyx_kp_u_compatable_dem_tif); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_10, __pyx_kp_u_compatable_dem_tif); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1139, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1140 - * compatable_dem_raster_path_band = ( - * os.path.join(working_dir_path, 'compatable_dem.tif'), - * dem_raster_path_band[1]) # <<<<<<<<<<<<<< - * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) - * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) - */ - __pyx_t_14 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1140, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - - /* "pygeoprocessing/routing/routing.pyx":1139 - * 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]) - * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) - */ - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1139, __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_14); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_14); - __pyx_t_1 = 0; - __pyx_t_14 = 0; - __Pyx_DECREF_SET(__pyx_v_compatable_dem_raster_path_band, __pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1141 - * os.path.join(working_dir_path, 'compatable_dem.tif'), - * dem_raster_path_band[1]) - * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) # <<<<<<<<<<<<<< - * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) - * raster_driver.CreateCopy( - */ - __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_gdal); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1141, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_GetDriverByName); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1141, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_14 = __Pyx_GetItemInt(__pyx_v_raster_driver_creation_tuple, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1141, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_15 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_15)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_15); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_3 = (__pyx_t_15) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_15, __pyx_t_14) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_14); - __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1141, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_raster_driver = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1142 - * dem_raster_path_band[1]) - * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) - * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) # <<<<<<<<<<<<<< - * raster_driver.CreateCopy( - * compatable_dem_raster_path_band[0], dem_raster, - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1142, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1142, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __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, 1142, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_gdal); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1142, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1142, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_15 = NULL; - __pyx_t_10 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { - __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_15)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_15); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - __pyx_t_10 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_14)) { - PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_t_1, __pyx_t_2}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1142, __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; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) { - PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_t_1, __pyx_t_2}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1142, __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; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else - #endif - { - __pyx_t_4 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1142, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (__pyx_t_15) { - __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_15); __pyx_t_15 = NULL; - } - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_10, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_10, __pyx_t_2); - __pyx_t_1 = 0; - __pyx_t_2 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1142, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_v_dem_raster = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1143 - * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) - * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) - * raster_driver.CreateCopy( # <<<<<<<<<<<<<< - * compatable_dem_raster_path_band[0], dem_raster, - * options=raster_driver_creation_tuple[1]) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster_driver, __pyx_n_s_CreateCopy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1143, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pygeoprocessing/routing/routing.pyx":1144 - * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) - * raster_driver.CreateCopy( - * compatable_dem_raster_path_band[0], dem_raster, # <<<<<<<<<<<<<< - * options=raster_driver_creation_tuple[1]) - * dem_raster = None - */ - __pyx_t_14 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1144, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - - /* "pygeoprocessing/routing/routing.pyx":1143 - * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) - * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) - * raster_driver.CreateCopy( # <<<<<<<<<<<<<< - * compatable_dem_raster_path_band[0], dem_raster, - * options=raster_driver_creation_tuple[1]) - */ - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1143, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_14); - __Pyx_INCREF(__pyx_v_dem_raster); - __Pyx_GIVEREF(__pyx_v_dem_raster); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_dem_raster); - __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1145 - * raster_driver.CreateCopy( - * compatable_dem_raster_path_band[0], dem_raster, - * options=raster_driver_creation_tuple[1]) # <<<<<<<<<<<<<< - * dem_raster = None - * LOGGER.info("compatible dem complete") - */ - __pyx_t_14 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1145, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_raster_driver_creation_tuple, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1145, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_options, __pyx_t_2) < 0) __PYX_ERR(0, 1145, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1143 - * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) - * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) - * raster_driver.CreateCopy( # <<<<<<<<<<<<<< - * compatable_dem_raster_path_band[0], dem_raster, - * options=raster_driver_creation_tuple[1]) - */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_14); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1143, __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; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1146 - * compatable_dem_raster_path_band[0], dem_raster, - * options=raster_driver_creation_tuple[1]) - * 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":1147 - * options=raster_driver_creation_tuple[1]) - * dem_raster = None - * LOGGER.info("compatible dem complete") # <<<<<<<<<<<<<< - * else: - * compatable_dem_raster_path_band = dem_raster_path_band - */ - __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1147, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_info); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1147, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_14 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_14)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_14); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - __pyx_t_2 = (__pyx_t_14) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_14, __pyx_kp_u_compatible_dem_complete) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_compatible_dem_complete); - __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1147, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1135 - * 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":1149 - * 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":1151 - * 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 = __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, 1151, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - - /* "pygeoprocessing/routing/routing.pyx":1152 - * 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, 1152, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - - /* "pygeoprocessing/routing/routing.pyx":1150 - * 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_14 = PyTuple_New(3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1150, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_t_4); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_14, 2, __pyx_int_0); - __pyx_t_2 = 0; - __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_14, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1150, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_v_dem_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_4); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1155 - * - * # 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_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_gdal); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1155, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1155, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1156 - * # 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_14 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1156, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1156, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1156, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - __pyx_t_10 = 0; - 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); - __pyx_t_10 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_t_14, __pyx_t_1}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1155, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_t_14, __pyx_t_1}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1155, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - { - __pyx_t_15 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1155, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_10, __pyx_t_14); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_10, __pyx_t_1); - __pyx_t_14 = 0; - __pyx_t_1 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_15, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1155, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF_SET(__pyx_v_dem_raster, __pyx_t_4); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1157 - * 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_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_dem_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1157, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_15 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1157, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_4 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_1, __pyx_t_15) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_15); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1157, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_dem_band = __pyx_t_4; - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1160 - * - * # this outer loop searches for a pixel that is locally undrained - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * compatable_dem_raster_path_band, offset_only=True, - * largest_block=0): - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1160, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1160, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1161 - * # this outer loop searches for a pixel that is locally undrained - * for offset_dict in pygeoprocessing.iterblocks( - * compatable_dem_raster_path_band, offset_only=True, # <<<<<<<<<<<<<< - * largest_block=0): - * win_xsize = offset_dict['win_xsize'] - */ - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1160, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_v_compatable_dem_raster_path_band); - __Pyx_GIVEREF(__pyx_v_compatable_dem_raster_path_band); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_compatable_dem_raster_path_band); - __pyx_t_15 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1161, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 1161, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_largest_block, __pyx_int_0) < 0) __PYX_ERR(0, 1161, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":1160 - * - * # this outer loop searches for a pixel that is locally undrained - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * compatable_dem_raster_path_band, offset_only=True, - * largest_block=0): - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, __pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1160, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { - __pyx_t_15 = __pyx_t_1; __Pyx_INCREF(__pyx_t_15); __pyx_t_17 = 0; - __pyx_t_18 = NULL; - } else { - __pyx_t_17 = -1; __pyx_t_15 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1160, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_18 = Py_TYPE(__pyx_t_15)->tp_iternext; if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 1160, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - for (;;) { - if (likely(!__pyx_t_18)) { - if (likely(PyList_CheckExact(__pyx_t_15))) { - if (__pyx_t_17 >= PyList_GET_SIZE(__pyx_t_15)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_15, __pyx_t_17); __Pyx_INCREF(__pyx_t_1); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 1160, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_15, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1160, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } else { - if (__pyx_t_17 >= PyTuple_GET_SIZE(__pyx_t_15)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_15, __pyx_t_17); __Pyx_INCREF(__pyx_t_1); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 1160, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_15, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1160, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } - } else { - __pyx_t_1 = __pyx_t_18(__pyx_t_15); - 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, 1160, __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":1163 - * compatable_dem_raster_path_band, 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_u_win_xsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1163, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1163, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_win_xsize = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":1164 - * 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_u_win_ysize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1164, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1164, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_win_ysize = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":1165 - * 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_u_xoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1165, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1165, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_xoff = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":1166 - * win_ysize = offset_dict['win_ysize'] - * xoff = offset_dict['xoff'] - * yoff = offset_dict['yoff'] # <<<<<<<<<<<<<< - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - */ - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_yoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1166, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1166, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_yoff = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":1168 - * yoff = offset_dict['yoff'] - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - */ - __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1169 - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info( - */ - __pyx_v_last_log_time = time(NULL); - - /* "pygeoprocessing/routing/routing.pyx":1170 - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size # <<<<<<<<<<<<<< - * LOGGER.info( - * '(flow dir d8): ' - */ - __pyx_v_current_pixel = (__pyx_v_xoff + (__pyx_v_yoff * __pyx_v_raster_x_size)); - - /* "pygeoprocessing/routing/routing.pyx":1171 - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info( # <<<<<<<<<<<<<< - * '(flow dir d8): ' - * f'{current_pixel} of {raster_x_size*raster_y_size} ' - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1171, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1171, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1172 - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info( - * '(flow dir d8): ' # <<<<<<<<<<<<<< - * f'{current_pixel} of {raster_x_size*raster_y_size} ' - * f'pixels complete') - */ - __pyx_t_4 = PyTuple_New(5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1172, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_19 = 0; - __pyx_t_20 = 127; - __Pyx_INCREF(__pyx_kp_u_flow_dir_d8); - __pyx_t_19 += 15; - __Pyx_GIVEREF(__pyx_kp_u_flow_dir_d8); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_u_flow_dir_d8); - - /* "pygeoprocessing/routing/routing.pyx":1173 - * LOGGER.info( - * '(flow dir d8): ' - * f'{current_pixel} of {raster_x_size*raster_y_size} ' # <<<<<<<<<<<<<< - * f'pixels complete') - * - */ - __pyx_t_14 = __Pyx_PyUnicode_From_int(__pyx_v_current_pixel, 0, ' ', 'd'); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1173, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_19 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_14); - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_14); - __pyx_t_14 = 0; - __Pyx_INCREF(__pyx_kp_u_of); - __pyx_t_19 += 4; - __Pyx_GIVEREF(__pyx_kp_u_of); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_kp_u_of); - __pyx_t_14 = __Pyx_PyUnicode_From_int((__pyx_v_raster_x_size * __pyx_v_raster_y_size), 0, ' ', 'd'); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1173, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_19 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_14); - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_14); - __pyx_t_14 = 0; - __Pyx_INCREF(__pyx_kp_u_pixels_complete); - __pyx_t_19 += 16; - __Pyx_GIVEREF(__pyx_kp_u_pixels_complete); - PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_kp_u_pixels_complete); - - /* "pygeoprocessing/routing/routing.pyx":1172 - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info( - * '(flow dir d8): ' # <<<<<<<<<<<<<< - * f'{current_pixel} of {raster_x_size*raster_y_size} ' - * f'pixels complete') - */ - __pyx_t_14 = __Pyx_PyUnicode_Join(__pyx_t_4, 5, __pyx_t_19, __pyx_t_20); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1172, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_14) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_14); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1171, __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":1168 - * yoff = offset_dict['yoff'] - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - */ - } - - /* "pygeoprocessing/routing/routing.pyx":1177 - * - * # 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_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1177, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1177, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1178 - * # 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_u_win_ysize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1178, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_14 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1178, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1178, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1178, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1178, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_14); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_4); - __pyx_t_14 = 0; - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1177 - * - * # 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, 1177, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1179 - * 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, 1179, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_numpy); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1179, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_float64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1179, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 1179, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1177 - * - * # 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_2, __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1177, __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_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, 1177, __pyx_L1_error) - __pyx_t_21 = ((PyArrayObject *)__pyx_t_3); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer); - __pyx_t_10 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_21, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); - if (unlikely(__pyx_t_10 < 0)) { - PyErr_Fetch(&__pyx_t_13, &__pyx_t_12, &__pyx_t_11); - 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_13); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_11); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_13, __pyx_t_12, __pyx_t_11); - } - __pyx_t_13 = __pyx_t_12 = __pyx_t_11 = 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_10 < 0)) __PYX_ERR(0, 1177, __pyx_L1_error) - } - __pyx_t_21 = 0; - __Pyx_XDECREF_SET(__pyx_v_dem_buffer_array, ((PyArrayObject *)__pyx_t_3)); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1180 - * (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, 1180, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_dem_buffer_array), __pyx_slice__7, __pyx_t_3) < 0)) __PYX_ERR(0, 1180, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1183 - * - * # 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_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_generate_read_bounds); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1183, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":1184 - * # 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_4 = __Pyx_PyInt_From_int(__pyx_v_raster_x_size); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1184, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_raster_y_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1184, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_14 = NULL; - __pyx_t_10 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_14)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_14); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - __pyx_t_10 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[4] = {__pyx_t_14, __pyx_v_offset_dict, __pyx_t_4, __pyx_t_2}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1183, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __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[4] = {__pyx_t_14, __pyx_v_offset_dict, __pyx_t_4, __pyx_t_2}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1183, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else - #endif - { - __pyx_t_16 = PyTuple_New(3+__pyx_t_10); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1183, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - if (__pyx_t_14) { - __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_14); __pyx_t_14 = NULL; - } - __Pyx_INCREF(__pyx_v_offset_dict); - __Pyx_GIVEREF(__pyx_v_offset_dict); - PyTuple_SET_ITEM(__pyx_t_16, 0+__pyx_t_10, __pyx_v_offset_dict); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_16, 1+__pyx_t_10, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_16, 2+__pyx_t_10, __pyx_t_2); - __pyx_t_4 = 0; - __pyx_t_2 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_16, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1183, __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, 1183, __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, 1183, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_16 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1183, __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_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1183, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_2)->tp_iternext; - index = 0; __pyx_t_1 = __pyx_t_8(__pyx_t_2); if (unlikely(!__pyx_t_1)) goto __pyx_L21_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - index = 1; __pyx_t_16 = __pyx_t_8(__pyx_t_2); if (unlikely(!__pyx_t_16)) goto __pyx_L21_unpacking_failed; - __Pyx_GOTREF(__pyx_t_16); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_2), 2) < 0) __PYX_ERR(0, 1183, __pyx_L1_error) - __pyx_t_8 = NULL; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L22_unpacking_done; - __pyx_L21_unpacking_failed:; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_8 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 1183, __pyx_L1_error) - __pyx_L22_unpacking_done:; - } - - /* "pygeoprocessing/routing/routing.pyx":1183 - * - * # 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, 1183, __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_4 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_14 = PyTuple_GET_ITEM(sequence, 2); - __pyx_t_22 = PyTuple_GET_ITEM(sequence, 3); - } else { - __pyx_t_2 = PyList_GET_ITEM(sequence, 0); - __pyx_t_4 = PyList_GET_ITEM(sequence, 1); - __pyx_t_14 = PyList_GET_ITEM(sequence, 2); - __pyx_t_22 = PyList_GET_ITEM(sequence, 3); - } - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_14); - __Pyx_INCREF(__pyx_t_22); - #else - { - Py_ssize_t i; - PyObject** temps[4] = {&__pyx_t_2,&__pyx_t_4,&__pyx_t_14,&__pyx_t_22}; - for (i=0; i < 4; i++) { - PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 1183, __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_2,&__pyx_t_4,&__pyx_t_14,&__pyx_t_22}; - __pyx_t_23 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 1183, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_23); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_23)->tp_iternext; - for (index=0; index < 4; index++) { - PyObject* item = __pyx_t_8(__pyx_t_23); if (unlikely(!item)) goto __pyx_L23_unpacking_failed; - __Pyx_GOTREF(item); - *(temps[index]) = item; - } - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_23), 4) < 0) __PYX_ERR(0, 1183, __pyx_L1_error) - __pyx_t_8 = NULL; - __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; - goto __pyx_L24_unpacking_done; - __pyx_L23_unpacking_failed:; - __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; - __pyx_t_8 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 1183, __pyx_L1_error) - __pyx_L24_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v_xa, __pyx_t_2); - __pyx_t_2 = 0; - __Pyx_XDECREF_SET(__pyx_v_xb, __pyx_t_4); - __pyx_t_4 = 0; - __Pyx_XDECREF_SET(__pyx_v_ya, __pyx_t_14); - __pyx_t_14 = 0; - __Pyx_XDECREF_SET(__pyx_v_yb, __pyx_t_22); - __pyx_t_22 = 0; - __Pyx_XDECREF_SET(__pyx_v_modified_offset_dict, __pyx_t_16); - __pyx_t_16 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1185 - * (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, 1185, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - - /* "pygeoprocessing/routing/routing.pyx":1186 - * 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, 1186, __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, 1186, __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, 1185, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - } - - /* "pygeoprocessing/routing/routing.pyx":1185 - * (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_22 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 1185, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_22); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1186 - * 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_22, __pyx_n_s_astype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_22, __pyx_n_s_numpy); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 1186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_22); - __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_22, __pyx_n_s_float64); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; - __pyx_t_22 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_22 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_22)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_22); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_3 = (__pyx_t_22) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_22, __pyx_t_16) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_16); - __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1185 - * (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, 1185, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_16 = PySlice_New(__pyx_v_xa, __pyx_v_xb, Py_None); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1185, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_22 = PyTuple_New(2); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 1185, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_22); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_22, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_16); - PyTuple_SET_ITEM(__pyx_t_22, 1, __pyx_t_16); - __pyx_t_1 = 0; - __pyx_t_16 = 0; - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_dem_buffer_array), __pyx_t_22, __pyx_t_3) < 0)) __PYX_ERR(0, 1185, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1189 - * - * # ensure these are set for the complier - * xi_n = -1 # <<<<<<<<<<<<<< - * yi_n = -1 - * - */ - __pyx_v_xi_n = -1; - - /* "pygeoprocessing/routing/routing.pyx":1190 - * # 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":1193 - * - * # 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_24 = (__pyx_v_win_ysize + 1); - __pyx_t_25 = __pyx_t_24; - for (__pyx_t_10 = 1; __pyx_t_10 < __pyx_t_25; __pyx_t_10+=1) { - __pyx_v_yi = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":1194 - * # 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, 1e-8, 1e-5): - */ - __pyx_t_26 = (__pyx_v_win_xsize + 1); - __pyx_t_27 = __pyx_t_26; - for (__pyx_t_9 = 1; __pyx_t_9 < __pyx_t_27; __pyx_t_9+=1) { - __pyx_v_xi = __pyx_t_9; - - /* "pygeoprocessing/routing/routing.pyx":1195 - * 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, 1e-8, 1e-5): - * continue - */ - __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_dem_buffer_array.diminfo[0].shape; - if (unlikely(__pyx_t_28 < 0)) __pyx_t_30 = 0; - } else if (unlikely(__pyx_t_28 >= __pyx_pybuffernd_dem_buffer_array.diminfo[0].shape)) __pyx_t_30 = 0; - if (__pyx_t_29 < 0) { - __pyx_t_29 += __pyx_pybuffernd_dem_buffer_array.diminfo[1].shape; - if (unlikely(__pyx_t_29 < 0)) __pyx_t_30 = 1; - } else if (unlikely(__pyx_t_29 >= __pyx_pybuffernd_dem_buffer_array.diminfo[1].shape)) __pyx_t_30 = 1; - if (unlikely(__pyx_t_30 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_30); - __PYX_ERR(0, 1195, __pyx_L1_error) - } - __pyx_v_root_height = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer.buf, __pyx_t_28, __pyx_pybuffernd_dem_buffer_array.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_dem_buffer_array.diminfo[1].strides)); - - /* "pygeoprocessing/routing/routing.pyx":1196 - * for xi in range(1, win_xsize+1): - * root_height = dem_buffer_array[yi, xi] - * if _is_close(root_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_root_height, __pyx_v_dem_nodata, 1e-8, 1e-5) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1197 - * root_height = dem_buffer_array[yi, xi] - * if _is_close(root_height, dem_nodata, 1e-8, 1e-5): - * continue # <<<<<<<<<<<<<< - * - * # this value is set in case it turns out to be the root of a - */ - goto __pyx_L27_continue; - - /* "pygeoprocessing/routing/routing.pyx":1196 - * for xi in range(1, win_xsize+1): - * root_height = dem_buffer_array[yi, xi] - * if _is_close(root_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * continue - * - */ - } - - /* "pygeoprocessing/routing/routing.pyx":1202 - * # 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":1203 - * # 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":1206 - * - * if flow_dir_managed_raster.get( - * xi_root, yi_root) != flow_dir_nodata: # <<<<<<<<<<<<<< - * # already been defined - * continue - */ - __pyx_t_5 = ((__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":1205 - * yi_root = yi-1+yoff - * - * if flow_dir_managed_raster.get( # <<<<<<<<<<<<<< - * xi_root, yi_root) != flow_dir_nodata: - * # already been defined - */ - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1208 - * 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":1205 - * 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":1213 - * # 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":1214 - * # 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":1216 - * largest_slope = 0.0 - * - * for i_n in range(8): # <<<<<<<<<<<<<< - * xi_n = xi+D8_XOFFSET[i_n] - * yi_n = yi+D8_YOFFSET[i_n] - */ - for (__pyx_t_30 = 0; __pyx_t_30 < 8; __pyx_t_30+=1) { - __pyx_v_i_n = __pyx_t_30; - - /* "pygeoprocessing/routing/routing.pyx":1217 - * - * for i_n in range(8): - * xi_n = xi+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< - * yi_n = yi+D8_YOFFSET[i_n] - * n_height = dem_buffer_array[yi_n, xi_n] - */ - __pyx_v_xi_n = (__pyx_v_xi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":1218 - * for i_n in range(8): - * xi_n = xi+D8_XOFFSET[i_n] - * yi_n = yi+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< - * n_height = dem_buffer_array[yi_n, xi_n] - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): - */ - __pyx_v_yi_n = (__pyx_v_yi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":1219 - * xi_n = xi+D8_XOFFSET[i_n] - * yi_n = yi+D8_YOFFSET[i_n] - * n_height = dem_buffer_array[yi_n, xi_n] # <<<<<<<<<<<<<< - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): - * continue - */ - __pyx_t_29 = __pyx_v_yi_n; - __pyx_t_28 = __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_28 < 0) { - __pyx_t_28 += __pyx_pybuffernd_dem_buffer_array.diminfo[1].shape; - if (unlikely(__pyx_t_28 < 0)) __pyx_t_31 = 1; - } else if (unlikely(__pyx_t_28 >= __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, 1219, __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_28, __pyx_pybuffernd_dem_buffer_array.diminfo[1].strides)); - - /* "pygeoprocessing/routing/routing.pyx":1220 - * yi_n = yi+D8_YOFFSET[i_n] - * n_height = dem_buffer_array[yi_n, xi_n] - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * continue - * n_slope = root_height - n_height - */ - __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_n_height, __pyx_v_dem_nodata, 1e-8, 1e-5) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1221 - * n_height = dem_buffer_array[yi_n, xi_n] - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): - * continue # <<<<<<<<<<<<<< - * n_slope = root_height - n_height - * if i_n & 1: - */ - goto __pyx_L31_continue; - - /* "pygeoprocessing/routing/routing.pyx":1220 - * yi_n = yi+D8_YOFFSET[i_n] - * n_height = dem_buffer_array[yi_n, xi_n] - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * continue - * n_slope = root_height - n_height - */ - } - - /* "pygeoprocessing/routing/routing.pyx":1222 - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): - * 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":1223 - * continue - * n_slope = root_height - n_height - * if i_n & 1: # <<<<<<<<<<<<<< - * # if diagonal, adjust the slope - * n_slope *= SQRT2_INV - */ - __pyx_t_5 = ((__pyx_v_i_n & 1) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1225 - * 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":1223 - * continue - * n_slope = root_height - n_height - * if i_n & 1: # <<<<<<<<<<<<<< - * # if diagonal, adjust the slope - * n_slope *= SQRT2_INV - */ - } - - /* "pygeoprocessing/routing/routing.pyx":1226 - * # 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_5 = ((__pyx_v_n_slope > __pyx_v_largest_slope) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1227 - * 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":1228 - * 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":1226 - * # 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":1230 - * largest_slope = n_slope - * - * if largest_slope_dir >= 0: # <<<<<<<<<<<<<< - * # define flow dir and move on - * flow_dir_managed_raster.set( - */ - __pyx_t_5 = ((__pyx_v_largest_slope_dir >= 0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1232 - * 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":1234 - * 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":1230 - * largest_slope = n_slope - * - * if largest_slope_dir >= 0: # <<<<<<<<<<<<<< - * # define flow dir and move on - * flow_dir_managed_raster.set( - */ - } - - /* "pygeoprocessing/routing/routing.pyx":1238 - * # 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":1239 - * # 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":1245 - * # 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_5 = ((!(__pyx_v_search_queue.empty() != 0)) != 0); - if (!__pyx_t_5) break; - - /* "pygeoprocessing/routing/routing.pyx":1246 - * - * while not search_queue.empty(): - * xi_q = search_queue.front().xi # <<<<<<<<<<<<<< - * yi_q = search_queue.front().yi - * search_queue.pop() - */ - __pyx_t_30 = __pyx_v_search_queue.front().xi; - __pyx_v_xi_q = __pyx_t_30; - - /* "pygeoprocessing/routing/routing.pyx":1247 - * while not search_queue.empty(): - * xi_q = search_queue.front().xi - * yi_q = search_queue.front().yi # <<<<<<<<<<<<<< - * search_queue.pop() - * - */ - __pyx_t_30 = __pyx_v_search_queue.front().yi; - __pyx_v_yi_q = __pyx_t_30; - - /* "pygeoprocessing/routing/routing.pyx":1248 - * 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":1250 - * search_queue.pop() - * - * largest_slope_dir = -1 # <<<<<<<<<<<<<< - * largest_slope = 0.0 - * diagonal_nodata = 1 - */ - __pyx_v_largest_slope_dir = -1L; - - /* "pygeoprocessing/routing/routing.pyx":1251 - * - * 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":1252 - * largest_slope_dir = -1 - * largest_slope = 0.0 - * diagonal_nodata = 1 # <<<<<<<<<<<<<< - * for i_n in range(8): - * xi_n = xi_q+D8_XOFFSET[i_n] - */ - __pyx_v_diagonal_nodata = 1; - - /* "pygeoprocessing/routing/routing.pyx":1253 - * largest_slope = 0.0 - * diagonal_nodata = 1 - * for i_n in range(8): # <<<<<<<<<<<<<< - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] - */ - for (__pyx_t_30 = 0; __pyx_t_30 < 8; __pyx_t_30+=1) { - __pyx_v_i_n = __pyx_t_30; - - /* "pygeoprocessing/routing/routing.pyx":1254 - * diagonal_nodata = 1 - * for i_n in range(8): - * xi_n = xi_q+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< - * yi_n = yi_q+D8_YOFFSET[i_n] - * - */ - __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":1255 - * for i_n in range(8): - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< - * - * if (xi_n < 0 or xi_n >= raster_x_size or - */ - __pyx_v_yi_n = (__pyx_v_yi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":1257 - * yi_n = yi_q+D8_YOFFSET[i_n] - * - * 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_6 = ((__pyx_v_xi_n < 0) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L42_bool_binop_done; - } - __pyx_t_6 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L42_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":1258 - * - * 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_6 = ((__pyx_v_yi_n < 0) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L42_bool_binop_done; - } - __pyx_t_6 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L42_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":1257 - * yi_n = yi_q+D8_YOFFSET[i_n] - * - * 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_5) { - - /* "pygeoprocessing/routing/routing.pyx":1259 - * 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":1257 - * yi_n = yi_q+D8_YOFFSET[i_n] - * - * 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":1261 - * n_height = dem_nodata - * else: - * n_height = dem_managed_raster.get(xi_n, yi_n) # <<<<<<<<<<<<<< - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): - * 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":1262 - * else: - * n_height = dem_managed_raster.get(xi_n, yi_n) - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * if diagonal_nodata and largest_slope == 0.0: - * largest_slope_dir = i_n - */ - __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_n_height, __pyx_v_dem_nodata, 1e-8, 1e-5) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1263 - * n_height = dem_managed_raster.get(xi_n, yi_n) - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): - * if diagonal_nodata and largest_slope == 0.0: # <<<<<<<<<<<<<< - * largest_slope_dir = i_n - * diagonal_nodata = i_n & 1 - */ - __pyx_t_6 = (__pyx_v_diagonal_nodata != 0); - if (__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L48_bool_binop_done; - } - __pyx_t_6 = ((__pyx_v_largest_slope == 0.0) != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L48_bool_binop_done:; - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1264 - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): - * 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":1265 - * 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":1263 - * n_height = dem_managed_raster.get(xi_n, yi_n) - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): - * if diagonal_nodata and largest_slope == 0.0: # <<<<<<<<<<<<<< - * largest_slope_dir = i_n - * diagonal_nodata = i_n & 1 - */ - } - - /* "pygeoprocessing/routing/routing.pyx":1266 - * 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":1262 - * else: - * n_height = dem_managed_raster.get(xi_n, yi_n) - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * if diagonal_nodata and largest_slope == 0.0: - * largest_slope_dir = i_n - */ - } - - /* "pygeoprocessing/routing/routing.pyx":1267 - * 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":1268 - * continue - * n_slope = root_height - n_height - * if n_slope < 0: # <<<<<<<<<<<<<< - * continue - * if n_slope == 0.0: - */ - __pyx_t_5 = ((__pyx_v_n_slope < 0.0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1269 - * 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":1268 - * continue - * n_slope = root_height - n_height - * if n_slope < 0: # <<<<<<<<<<<<<< - * continue - * if n_slope == 0.0: - */ - } - - /* "pygeoprocessing/routing/routing.pyx":1270 - * 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_5 = ((__pyx_v_n_slope == 0.0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1272 - * 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_5 = ((__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":1271 - * 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_5) { - - /* "pygeoprocessing/routing/routing.pyx":1275 - * # 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":1276 - * # 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":1271 - * 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":1278 - * 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":1270 - * 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":1279 - * xi_n, yi_n, 1) - * continue - * if i_n & 1: # <<<<<<<<<<<<<< - * n_slope *= SQRT2_INV - * if n_slope > largest_slope: - */ - __pyx_t_5 = ((__pyx_v_i_n & 1) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1280 - * 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":1279 - * xi_n, yi_n, 1) - * continue - * if i_n & 1: # <<<<<<<<<<<<<< - * n_slope *= SQRT2_INV - * if n_slope > largest_slope: - */ - } - - /* "pygeoprocessing/routing/routing.pyx":1281 - * if i_n & 1: - * n_slope *= SQRT2_INV - * if n_slope > largest_slope: # <<<<<<<<<<<<<< - * largest_slope = n_slope - * largest_slope_dir = i_n - */ - __pyx_t_5 = ((__pyx_v_n_slope > __pyx_v_largest_slope) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1282 - * 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":1283 - * 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":1281 - * 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":1285 - * largest_slope_dir = i_n - * - * if largest_slope_dir >= 0: # <<<<<<<<<<<<<< - * if largest_slope > 0.0: - * # regular downhill pixel - */ - __pyx_t_5 = ((__pyx_v_largest_slope_dir >= 0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1286 - * - * if largest_slope_dir >= 0: - * if largest_slope > 0.0: # <<<<<<<<<<<<<< - * # regular downhill pixel - * flow_dir_managed_raster.set( - */ - __pyx_t_5 = ((__pyx_v_largest_slope > 0.0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1288 - * 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":1290 - * 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":1292 - * 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":1286 - * - * 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":1295 - * 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":1296 - * # 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":1295 - * 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":1297 - * 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":1285 - * largest_slope_dir = i_n - * - * if largest_slope_dir >= 0: # <<<<<<<<<<<<<< - * if largest_slope > 0.0: - * # regular downhill pixel - */ - } - } - - /* "pygeoprocessing/routing/routing.pyx":1300 - * - * # 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_5 = (__pyx_v_drain_queue.empty() != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1304 - * # 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_5 = ((!(__pyx_v_nodata_drain_queue.empty() != 0)) != 0); - if (!__pyx_t_5) break; - - /* "pygeoprocessing/routing/routing.pyx":1305 - * # 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_30 = __pyx_v_nodata_drain_queue.front().xi; - __pyx_v_xi_q = __pyx_t_30; - - /* "pygeoprocessing/routing/routing.pyx":1306 - * 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_30 = __pyx_v_nodata_drain_queue.front().yi; - __pyx_v_yi_q = __pyx_t_30; - - /* "pygeoprocessing/routing/routing.pyx":1307 - * 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":1309 - * 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":1310 - * 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":1311 - * 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":1312 - * 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":1300 - * - * # 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":1315 - * 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, 1315, __pyx_L1_error) - } - __pyx_v_nodata_flow_dir_queue = __pyx_t_33; - - /* "pygeoprocessing/routing/routing.pyx":1316 - * # 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, 1316, __pyx_L1_error) - } - __pyx_v_nodata_drain_queue = __pyx_t_34; - } - __pyx_L57:; - - /* "pygeoprocessing/routing/routing.pyx":1320 - * # 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_5 = ((!(__pyx_v_drain_queue.empty() != 0)) != 0); - if (!__pyx_t_5) break; - - /* "pygeoprocessing/routing/routing.pyx":1321 - * # 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_30 = __pyx_v_drain_queue.front().xi; - __pyx_v_xi_q = __pyx_t_30; - - /* "pygeoprocessing/routing/routing.pyx":1322 - * while not drain_queue.empty(): - * xi_q = drain_queue.front().xi - * yi_q = drain_queue.front().yi # <<<<<<<<<<<<<< - * drain_queue.pop() - * - */ - __pyx_t_30 = __pyx_v_drain_queue.front().yi; - __pyx_v_yi_q = __pyx_t_30; - - /* "pygeoprocessing/routing/routing.pyx":1323 - * 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":1325 - * 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":1328 - * xi_q, yi_q) - * - * for i_n in range(8): # <<<<<<<<<<<<<< - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] - */ - for (__pyx_t_30 = 0; __pyx_t_30 < 8; __pyx_t_30+=1) { - __pyx_v_i_n = __pyx_t_30; - - /* "pygeoprocessing/routing/routing.pyx":1329 - * - * for i_n in range(8): - * xi_n = xi_q+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< - * yi_n = yi_q+D8_YOFFSET[i_n] - * if (xi_n < 0 or xi_n >= raster_x_size or - */ - __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":1330 - * for i_n in range(8): - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< - * 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_D8_YOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":1331 - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] - * if (xi_n < 0 or xi_n >= raster_x_size or # <<<<<<<<<<<<<< - * yi_n < 0 or yi_n >= raster_y_size): - * continue - */ - __pyx_t_6 = ((__pyx_v_xi_n < 0) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L65_bool_binop_done; - } - __pyx_t_6 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L65_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":1332 - * yi_n = yi_q+D8_YOFFSET[i_n] - * if (xi_n < 0 or xi_n >= raster_x_size or - * yi_n < 0 or yi_n >= raster_y_size): # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_6 = ((__pyx_v_yi_n < 0) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L65_bool_binop_done; - } - __pyx_t_6 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L65_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":1331 - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] - * 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":1333 - * 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":1331 - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] - * 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":1336 - * - * 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_7 = __pyx_v_15pygeoprocessing_7routing_7routing_SQRT2; - } else { - __pyx_t_7 = 1.0; - } - - /* "pygeoprocessing/routing/routing.pyx":1335 - * 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_7); - - /* "pygeoprocessing/routing/routing.pyx":1339 - * - * 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_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) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L70_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":1341 - * 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_6 = ((__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_5 = __pyx_t_6; - __pyx_L70_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":1338 - * 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_5) { - - /* "pygeoprocessing/routing/routing.pyx":1344 - * # 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":1346 - * 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":1348 - * 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":1338 - * 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":1160 - * - * # this outer loop searches for a pixel that is locally undrained - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * compatable_dem_raster_path_band, offset_only=True, - * largest_block=0): - */ - } - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1349 - * 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":1350 - * 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":1351 - * 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, 1351, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_22 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_22 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_22)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_22); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_15 = (__pyx_t_22) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_22) : __Pyx_PyObject_CallNoArg(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; - if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1351, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1352 - * 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, 1352, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_22 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_22 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_22)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_22); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_15 = (__pyx_t_22) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_22) : __Pyx_PyObject_CallNoArg(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; - if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1352, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1353 - * 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, 1353, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_22 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_22 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_22)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_22); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_15 = (__pyx_t_22) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_22) : __Pyx_PyObject_CallNoArg(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; - if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1353, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1354 - * flat_region_mask_managed_raster.close() - * dem_managed_raster.close() - * plateau_distance_managed_raster.close() # <<<<<<<<<<<<<< - * shutil.rmtree(working_dir_path) - * LOGGER.info('(flow dir d8): complete') - */ - __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, 1354, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_22 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_22 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_22)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_22); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_15 = (__pyx_t_22) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_22) : __Pyx_PyObject_CallNoArg(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; - if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1354, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1355 - * dem_managed_raster.close() - * plateau_distance_managed_raster.close() - * shutil.rmtree(working_dir_path) # <<<<<<<<<<<<<< - * LOGGER.info('(flow dir d8): complete') - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_shutil); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1355, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_22 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_rmtree); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 1355, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_22); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_22))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_22); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_22); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_22, function); - } - } - __pyx_t_15 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_22, __pyx_t_3, __pyx_v_working_dir_path) : __Pyx_PyObject_CallOneArg(__pyx_t_22, __pyx_v_working_dir_path); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1355, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1356 - * plateau_distance_managed_raster.close() - * shutil.rmtree(working_dir_path) - * LOGGER.info('(flow dir d8): complete') # <<<<<<<<<<<<<< - * - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_22, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 1356, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_22); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_22, __pyx_n_s_info); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1356, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; - __pyx_t_22 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_22 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_22)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_22); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_15 = (__pyx_t_22) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_22, __pyx_kp_u_flow_dir_d8_complete) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_flow_dir_d8_complete); - __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; - if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1356, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":994 - * - * - * 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_14); - __Pyx_XDECREF(__pyx_t_15); - __Pyx_XDECREF(__pyx_t_16); - __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_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_raster_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_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":1359 - * - * - * 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\n 3 2 1\n 4 x 0\n 5 6 7\n\n target_flow_accum_raster_path (str): 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 raster_driver_creation_tuple (tuple): a tuple containing a GDAL driver\n name string as the first element and a GDAL creation options\n tuple/list as the second. Defaults to a GTiff driver tuple\n defined at geoprocessing.DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS.\n\n Returns:\n None.\n "; -static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_7flow_accumulation_d8 = {"flow_accumulation_d8", (PyCFunction)(void*)(PyCFunctionWithKeywords)__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_raster_driver_creation_tuple = 0; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 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_raster_driver_creation_tuple,0}; - PyObject* values[4] = {0,0,0,0}; - - /* "pygeoprocessing/routing/routing.pyx":1361 - * def flow_accumulation_d8( - * flow_dir_raster_path_band, target_flow_accum_raster_path, - * weight_raster_path_band=None, # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): - * """D8 flow accumulation. - */ - values[2] = ((PyObject *)Py_None); - values[3] = __pyx_k__8; - 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, 1359, __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_raster_driver_creation_tuple); - 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, 1359, __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_raster_driver_creation_tuple = 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, 1359, __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_raster_driver_creation_tuple); - - /* "pygeoprocessing/routing/routing.pyx":1359 - * - * - * 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_raster_driver_creation_tuple) { - 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 __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; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - 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; - struct __pyx_t_15pygeoprocessing_7routing_7routing_FlowPixelType __pyx_t_30; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __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":1420 - * # 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":1432 - * # 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":1434 - * 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_is_raster_path_band_formatted); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1434, __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); - } - } - __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_flow_dir_raster_path_band) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_flow_dir_raster_path_band); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1434, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __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, 1434, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_5 = ((!__pyx_t_4) != 0); - if (unlikely(__pyx_t_5)) { - - /* "pygeoprocessing/routing/routing.pyx":1436 - * 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_PyUnicode_FormatSafe(__pyx_kp_u_s_is_supposed_to_be_a_raster_ba, __pyx_v_flow_dir_raster_path_band); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1436, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":1435 - * - * 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, 1435, __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, 1435, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":1434 - * 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":1438 - * "%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_4 = __Pyx_PyObject_IsTrue(__pyx_v_weight_raster_path_band); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1438, __pyx_L1_error) - if (__pyx_t_4) { - } else { - __pyx_t_5 = __pyx_t_4; - goto __pyx_L5_bool_binop_done; - } - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_is_raster_path_band_formatted); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1438, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":1439 - * 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_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); - } - } - __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_3, __pyx_v_weight_raster_path_band) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_weight_raster_path_band); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1438, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1438 - * "%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_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1438, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_6 = ((!__pyx_t_4) != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L5_bool_binop_done:; - if (unlikely(__pyx_t_5)) { - - /* "pygeoprocessing/routing/routing.pyx":1441 - * 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_PyUnicode_FormatSafe(__pyx_kp_u_s_is_supposed_to_be_a_raster_ba, __pyx_v_weight_raster_path_band); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1441, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - - /* "pygeoprocessing/routing/routing.pyx":1440 - * 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, 1440, __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, 1440, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":1438 - * "%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":1444 - * 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":1445 - * - * 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_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1445, __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, 1445, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1446 - * 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], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - */ - __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, 1446, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":1447 - * pygeoprocessing.new_raster_from_base( - * flow_dir_raster_path_band[0], target_flow_accum_raster_path, - * gdal.GDT_Float64, [flow_accum_nodata], # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * flow_accum_managed_raster = _ManagedRaster( - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1447, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1447, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __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, 1447, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_8 = PyList_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1447, __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":1445 - * - * 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, 1445, __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_7); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_8); - __pyx_t_1 = 0; - __pyx_t_7 = 0; - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1448 - * flow_dir_raster_path_band[0], target_flow_accum_raster_path, - * gdal.GDT_Float64, [flow_accum_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< - * flow_accum_managed_raster = _ManagedRaster( - * target_flow_accum_raster_path, 1, 1) - */ - __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1448, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 1448, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":1445 - * - * 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_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1445, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __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_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1449 - * gdal.GDT_Float64, [flow_accum_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * flow_accum_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< - * target_flow_accum_raster_path, 1, 1) - * - */ - __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1449, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_INCREF(__pyx_v_target_flow_accum_raster_path); - __Pyx_GIVEREF(__pyx_v_target_flow_accum_raster_path); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_target_flow_accum_raster_path); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_int_1); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_int_1); - __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1449, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 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":1453 - * - * 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, 1453, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_flow_dir_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1453, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - - /* "pygeoprocessing/routing/routing.pyx":1452 - * 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, 1452, __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_7); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_7); - __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_7 = 0; - __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_3, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1452, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_flow_dir_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_7); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1454 - * 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1454, __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, 1454, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1455 - * 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, 1455, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1455, __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, 1455, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __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_1}; - __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1454, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __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[3] = {__pyx_t_2, __pyx_t_3, __pyx_t_1}; - __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1454, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - { - __pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1454, __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_1); - PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_t_1); - __pyx_t_3 = 0; - __pyx_t_1 = 0; - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_10, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1454, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __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_7; - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1456 - * 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, 1456, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - - /* "pygeoprocessing/routing/routing.pyx":1457 - * 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, 1457, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - } - } - __pyx_t_7 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_1, __pyx_t_10) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_10); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1456, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_flow_dir_band = __pyx_t_7; - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1459 - * 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":1460 - * - * 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_5 = __Pyx_PyObject_IsTrue(__pyx_v_weight_raster_path_band); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1460, __pyx_L1_error) - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1462 - * 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_7 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1462, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __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, 1462, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - - /* "pygeoprocessing/routing/routing.pyx":1461 - * 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_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1461, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_8); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_int_0); - __pyx_t_7 = 0; - __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_10, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1461, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 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":1463 - * 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_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1463, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1463, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1464 - * 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_10 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1464, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_8 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_1, __pyx_t_10) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_10); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1463, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyObject_Dict_GetItem(__pyx_t_8, __pyx_n_u_nodata); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1464, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1465 - * 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, 1465, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_10 = __Pyx_PyInt_SubtractObjC(__pyx_t_8, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1465, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1464 - * 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_7, __pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1464, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_v_raw_weight_nodata = __pyx_t_8; - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1466 - * 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_5 = (__pyx_v_raw_weight_nodata != Py_None); - __pyx_t_6 = (__pyx_t_5 != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/routing/routing.pyx":1467 - * 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, 1467, __pyx_L1_error) - __pyx_v_weight_nodata = __pyx_t_11; - - /* "pygeoprocessing/routing/routing.pyx":1466 - * 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":1460 - * - * 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":1469 - * 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_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1469, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1469, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1470 - * - * 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_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, 1470, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_8 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_1, __pyx_t_10) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_10); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1469, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_flow_dir_raster_info = __pyx_t_8; - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1471 - * 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_u_raster_size); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1471, __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, 1471, __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_10 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_7 = PyList_GET_ITEM(sequence, 0); - __pyx_t_10 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(__pyx_t_10); - #else - __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1471, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1471, __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_1 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1471, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_12 = Py_TYPE(__pyx_t_1)->tp_iternext; - index = 0; __pyx_t_7 = __pyx_t_12(__pyx_t_1); if (unlikely(!__pyx_t_7)) goto __pyx_L9_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_1); if (unlikely(!__pyx_t_10)) goto __pyx_L9_unpacking_failed; - __Pyx_GOTREF(__pyx_t_10); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_1), 2) < 0) __PYX_ERR(0, 1471, __pyx_L1_error) - __pyx_t_12 = NULL; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L10_unpacking_done; - __pyx_L9_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, 1471, __pyx_L1_error) - __pyx_L10_unpacking_done:; - } - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1471, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_10); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1471, __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":1473 - * 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_u_nodata); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1473, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - - /* "pygeoprocessing/routing/routing.pyx":1474 - * - * 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, 1474, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_7 = __Pyx_PyInt_SubtractObjC(__pyx_t_10, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1474, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1473 - * 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_7); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1473, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_tmp_flow_dir_nodata = __pyx_t_10; - __pyx_t_10 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1475 - * 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_6 = (__pyx_v_tmp_flow_dir_nodata == Py_None); - __pyx_t_5 = (__pyx_t_6 != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1476 - * 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":1475 - * 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":1478 - * 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, 1478, __pyx_L1_error) - __pyx_v_flow_dir_nodata = __pyx_t_13; - } - __pyx_L11:; - - /* "pygeoprocessing/routing/routing.pyx":1481 - * - * # this outer loop searches for a pixel that is locally undrained - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * flow_dir_raster_path_band, offset_only=True, largest_block=0): - * win_xsize = offset_dict['win_xsize'] - */ - __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1481, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1481, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1482 - * # this outer loop searches for a pixel that is locally undrained - * for offset_dict in pygeoprocessing.iterblocks( - * flow_dir_raster_path_band, offset_only=True, largest_block=0): # <<<<<<<<<<<<<< - * win_xsize = offset_dict['win_xsize'] - * win_ysize = offset_dict['win_ysize'] - */ - __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1481, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(__pyx_v_flow_dir_raster_path_band); - __Pyx_GIVEREF(__pyx_v_flow_dir_raster_path_band); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_flow_dir_raster_path_band); - __pyx_t_8 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1482, __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, 1482, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_largest_block, __pyx_int_0) < 0) __PYX_ERR(0, 1482, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":1481 - * - * # this outer loop searches for a pixel that is locally undrained - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * flow_dir_raster_path_band, offset_only=True, largest_block=0): - * win_xsize = offset_dict['win_xsize'] - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_10, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1481, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { - __pyx_t_8 = __pyx_t_1; __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_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1481, __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, 1481, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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_1 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_14); __Pyx_INCREF(__pyx_t_1); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 1481, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_8, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1481, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } else { - if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_8)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_14); __Pyx_INCREF(__pyx_t_1); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 1481, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_8, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1481, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } - } else { - __pyx_t_1 = __pyx_t_15(__pyx_t_8); - 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, 1481, __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":1483 - * for offset_dict in pygeoprocessing.iterblocks( - * flow_dir_raster_path_band, 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_u_win_xsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1483, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1483, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_win_xsize = __pyx_t_13; - - /* "pygeoprocessing/routing/routing.pyx":1484 - * flow_dir_raster_path_band, 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_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1484, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1484, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_win_ysize = __pyx_t_13; - - /* "pygeoprocessing/routing/routing.pyx":1485 - * 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_u_xoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1485, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1485, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_xoff = __pyx_t_13; - - /* "pygeoprocessing/routing/routing.pyx":1486 - * win_ysize = offset_dict['win_ysize'] - * xoff = offset_dict['xoff'] - * yoff = offset_dict['yoff'] # <<<<<<<<<<<<<< - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - */ - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_yoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1486, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1486, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_yoff = __pyx_t_13; - - /* "pygeoprocessing/routing/routing.pyx":1488 - * yoff = offset_dict['yoff'] - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - */ - __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1489 - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( - */ - __pyx_v_last_log_time = time(NULL); - - /* "pygeoprocessing/routing/routing.pyx":1490 - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size # <<<<<<<<<<<<<< - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( - * 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, 1490, __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":1491 - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< - * raster_x_size * raster_y_size)) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1491, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1491, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = PyNumber_Multiply(__pyx_float_100_0, __pyx_v_current_pixel); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1491, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - - /* "pygeoprocessing/routing/routing.pyx":1492 - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( - * 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, 1491, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pygeoprocessing/routing/routing.pyx":1491 - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< - * raster_x_size * raster_y_size)) - * - */ - __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_t_10, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1491, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 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_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); - __pyx_t_13 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_kp_u_1f_complete, __pyx_t_2}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1491, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 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_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_kp_u_1f_complete, __pyx_t_2}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1491, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else - #endif - { - __pyx_t_10 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1491, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_INCREF(__pyx_kp_u_1f_complete); - __Pyx_GIVEREF(__pyx_kp_u_1f_complete); - PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_13, __pyx_kp_u_1f_complete); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_13, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1491, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1488 - * yoff = offset_dict['yoff'] - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - */ - } - - /* "pygeoprocessing/routing/routing.pyx":1495 - * - * # 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_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1495, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1495, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1496 - * # 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_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1496, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1496, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1496, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1496, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1496, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2); - __pyx_t_10 = 0; - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1495 - * - * # 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, 1495, __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 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1497 - * 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_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1497, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_numpy); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1497, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_uint8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1497, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 1497, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1495 - * - * # 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_7, __pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1495, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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, 1495, __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, 1495, __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":1498 - * (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, 1498, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_buffer_array), __pyx_slice__7, __pyx_t_3) < 0)) __PYX_ERR(0, 1498, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1501 - * - * # 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_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_generate_read_bounds); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1501, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":1502 - * # 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, 1502, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_raster_y_size); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1502, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_10 = NULL; - __pyx_t_13 = 0; - 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); - __pyx_t_13 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[4] = {__pyx_t_10, __pyx_v_offset_dict, __pyx_t_2, __pyx_t_7}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_13, 3+__pyx_t_13); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1501, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_3); - __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_1)) { - PyObject *__pyx_temp[4] = {__pyx_t_10, __pyx_v_offset_dict, __pyx_t_2, __pyx_t_7}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_13, 3+__pyx_t_13); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1501, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - { - __pyx_t_20 = PyTuple_New(3+__pyx_t_13); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1501, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - if (__pyx_t_10) { - __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_10); __pyx_t_10 = 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_7); - PyTuple_SET_ITEM(__pyx_t_20, 2+__pyx_t_13, __pyx_t_7); - __pyx_t_2 = 0; - __pyx_t_7 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_20, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1501, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 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, 1501, __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_20 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_1 = PyList_GET_ITEM(sequence, 0); - __pyx_t_20 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_20); - #else - __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1501, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_20 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1501, __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_7 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1501, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_12 = Py_TYPE(__pyx_t_7)->tp_iternext; - index = 0; __pyx_t_1 = __pyx_t_12(__pyx_t_7); if (unlikely(!__pyx_t_1)) goto __pyx_L15_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - index = 1; __pyx_t_20 = __pyx_t_12(__pyx_t_7); if (unlikely(!__pyx_t_20)) goto __pyx_L15_unpacking_failed; - __Pyx_GOTREF(__pyx_t_20); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_7), 2) < 0) __PYX_ERR(0, 1501, __pyx_L1_error) - __pyx_t_12 = 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_12 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 1501, __pyx_L1_error) - __pyx_L16_unpacking_done:; - } - - /* "pygeoprocessing/routing/routing.pyx":1501 - * - * # 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_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, 1501, __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_2 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_10 = PyTuple_GET_ITEM(sequence, 2); - __pyx_t_21 = PyTuple_GET_ITEM(sequence, 3); - } else { - __pyx_t_7 = PyList_GET_ITEM(sequence, 0); - __pyx_t_2 = PyList_GET_ITEM(sequence, 1); - __pyx_t_10 = PyList_GET_ITEM(sequence, 2); - __pyx_t_21 = PyList_GET_ITEM(sequence, 3); - } - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(__pyx_t_21); - #else - { - Py_ssize_t i; - PyObject** temps[4] = {&__pyx_t_7,&__pyx_t_2,&__pyx_t_10,&__pyx_t_21}; - for (i=0; i < 4; i++) { - PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 1501, __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_7,&__pyx_t_2,&__pyx_t_10,&__pyx_t_21}; - __pyx_t_22 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 1501, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_22); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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, 1501, __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, 1501, __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_2); - __pyx_t_2 = 0; - __Pyx_XDECREF_SET(__pyx_v_ya, __pyx_t_10); - __pyx_t_10 = 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":1503 - * (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, 1503, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - - /* "pygeoprocessing/routing/routing.pyx":1504 - * 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, 1504, __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, 1504, __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, 1503, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - } - - /* "pygeoprocessing/routing/routing.pyx":1503 - * (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_1); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 1503, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_21); - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1504 - * 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_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_21, __pyx_n_s_astype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1504, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_21, __pyx_n_s_numpy); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 1504, __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, 1504, __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_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); - } - } - __pyx_t_3 = (__pyx_t_21) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_21, __pyx_t_20) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_20); - __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1504, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1503 - * (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_1 = PySlice_New(__pyx_v_ya, __pyx_v_yb, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1503, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_20 = PySlice_New(__pyx_v_xa, __pyx_v_xb, Py_None); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1503, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __pyx_t_21 = PyTuple_New(2); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 1503, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_21); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_21, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_20); - PyTuple_SET_ITEM(__pyx_t_21, 1, __pyx_t_20); - __pyx_t_1 = 0; - __pyx_t_20 = 0; - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_buffer_array), __pyx_t_21, __pyx_t_3) < 0)) __PYX_ERR(0, 1503, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1507 - * - * # ensure these are set for the complier - * xi_n = -1 # <<<<<<<<<<<<<< - * yi_n = -1 - * - */ - __pyx_v_xi_n = -1; - - /* "pygeoprocessing/routing/routing.pyx":1508 - * # 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":1511 - * - * # 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":1512 - * # 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":1513 - * 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, 1513, __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":1514 - * 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_5 = ((__pyx_v_flow_dir == __pyx_v_flow_dir_nodata) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1515 - * flow_dir = flow_dir_buffer_array[yi, xi] - * if flow_dir == flow_dir_nodata: - * continue # <<<<<<<<<<<<<< - * - * xi_n = xi+D8_XOFFSET[flow_dir] - */ - goto __pyx_L21_continue; - - /* "pygeoprocessing/routing/routing.pyx":1514 - * 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":1517 - * continue - * - * xi_n = xi+D8_XOFFSET[flow_dir] # <<<<<<<<<<<<<< - * yi_n = yi+D8_YOFFSET[flow_dir] - * - */ - __pyx_v_xi_n = (__pyx_v_xi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_flow_dir])); - - /* "pygeoprocessing/routing/routing.pyx":1518 - * - * xi_n = xi+D8_XOFFSET[flow_dir] - * yi_n = yi+D8_YOFFSET[flow_dir] # <<<<<<<<<<<<<< - * - * if flow_dir_buffer_array[yi_n, xi_n] == flow_dir_nodata: - */ - __pyx_v_yi_n = (__pyx_v_yi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_flow_dir])); - - /* "pygeoprocessing/routing/routing.pyx":1520 - * yi_n = yi+D8_YOFFSET[flow_dir] - * - * if flow_dir_buffer_array[yi_n, xi_n] == flow_dir_nodata: # <<<<<<<<<<<<<< - * xi_root = xi-1+xoff - * yi_root = yi-1+yoff - */ - __pyx_t_28 = __pyx_v_yi_n; - __pyx_t_27 = __pyx_v_xi_n; - __pyx_t_29 = -1; - if (__pyx_t_28 < 0) { - __pyx_t_28 += __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].shape; - if (unlikely(__pyx_t_28 < 0)) __pyx_t_29 = 0; - } else if (unlikely(__pyx_t_28 >= __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].shape)) __pyx_t_29 = 0; - if (__pyx_t_27 < 0) { - __pyx_t_27 += __pyx_pybuffernd_flow_dir_buffer_array.diminfo[1].shape; - if (unlikely(__pyx_t_27 < 0)) __pyx_t_29 = 1; - } else if (unlikely(__pyx_t_27 >= __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, 1520, __pyx_L1_error) - } - __pyx_t_5 = (((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer.buf, __pyx_t_28, __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].strides, __pyx_t_27, __pyx_pybuffernd_flow_dir_buffer_array.diminfo[1].strides)) == __pyx_v_flow_dir_nodata) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1521 - * - * 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":1522 - * 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":1524 - * yi_root = yi-1+yoff - * - * if weight_raster is not None: # <<<<<<<<<<<<<< - * weight_val = weight_raster.get( - * xi_root, yi_root) - */ - __pyx_t_5 = (((PyObject *)__pyx_v_weight_raster) != Py_None); - __pyx_t_6 = (__pyx_t_5 != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/routing/routing.pyx":1525 - * - * if weight_raster is not None: - * weight_val = weight_raster.get( # <<<<<<<<<<<<<< - * xi_root, yi_root) - * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): - */ - __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":1527 - * weight_val = weight_raster.get( - * xi_root, yi_root) - * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * weight_val = 0.0 - * else: - */ - __pyx_t_6 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_weight_val, __pyx_v_weight_nodata, 1e-8, 1e-5) != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/routing/routing.pyx":1528 - * xi_root, yi_root) - * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): - * weight_val = 0.0 # <<<<<<<<<<<<<< - * else: - * weight_val = 1.0 - */ - __pyx_v_weight_val = 0.0; - - /* "pygeoprocessing/routing/routing.pyx":1527 - * weight_val = weight_raster.get( - * xi_root, yi_root) - * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * weight_val = 0.0 - * else: - */ - } - - /* "pygeoprocessing/routing/routing.pyx":1524 - * yi_root = yi-1+yoff - * - * if weight_raster is not None: # <<<<<<<<<<<<<< - * weight_val = weight_raster.get( - * xi_root, yi_root) - */ - goto __pyx_L25; - } - - /* "pygeoprocessing/routing/routing.pyx":1530 - * 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":1532 - * weight_val = 1.0 - * search_stack.push( - * FlowPixelType(xi_root, yi_root, 0, weight_val)) # <<<<<<<<<<<<<< - * - * while not search_stack.empty(): - */ - __pyx_t_30.xi = __pyx_v_xi_root; - __pyx_t_30.yi = __pyx_v_yi_root; - __pyx_t_30.last_flow_dir = 0; - __pyx_t_30.value = __pyx_v_weight_val; - - /* "pygeoprocessing/routing/routing.pyx":1531 - * else: - * weight_val = 1.0 - * search_stack.push( # <<<<<<<<<<<<<< - * FlowPixelType(xi_root, yi_root, 0, weight_val)) - * - */ - __pyx_v_search_stack.push(__pyx_t_30); - - /* "pygeoprocessing/routing/routing.pyx":1520 - * yi_n = yi+D8_YOFFSET[flow_dir] - * - * 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":1534 - * 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_6 = ((!(__pyx_v_search_stack.empty() != 0)) != 0); - if (!__pyx_t_6) break; - - /* "pygeoprocessing/routing/routing.pyx":1535 - * - * 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":1536 - * while not search_stack.empty(): - * flow_pixel = search_stack.top() - * search_stack.pop() # <<<<<<<<<<<<<< - * - * preempted = 0 - */ - __pyx_v_search_stack.pop(); - - /* "pygeoprocessing/routing/routing.pyx":1538 - * search_stack.pop() - * - * preempted = 0 # <<<<<<<<<<<<<< - * for i_n in range(flow_pixel.last_flow_dir, 8): - * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] - */ - __pyx_v_preempted = 0; - - /* "pygeoprocessing/routing/routing.pyx":1539 - * - * preempted = 0 - * for i_n in range(flow_pixel.last_flow_dir, 8): # <<<<<<<<<<<<<< - * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] - * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] - */ - 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":1540 - * preempted = 0 - * for i_n in range(flow_pixel.last_flow_dir, 8): - * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< - * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] - * 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_D8_XOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":1541 - * for i_n in range(flow_pixel.last_flow_dir, 8): - * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] - * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< - * 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_D8_YOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":1542 - * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] - * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] - * 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_5 = ((__pyx_v_xi_n < 0) != 0); - if (!__pyx_t_5) { - } else { - __pyx_t_6 = __pyx_t_5; - goto __pyx_L32_bool_binop_done; - } - __pyx_t_5 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0); - if (!__pyx_t_5) { - } else { - __pyx_t_6 = __pyx_t_5; - goto __pyx_L32_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":1543 - * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] - * 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_5 = ((__pyx_v_yi_n < 0) != 0); - if (!__pyx_t_5) { - } else { - __pyx_t_6 = __pyx_t_5; - goto __pyx_L32_bool_binop_done; - } - __pyx_t_5 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0); - __pyx_t_6 = __pyx_t_5; - __pyx_L32_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":1542 - * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] - * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] - * 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":1545 - * yi_n < 0 or yi_n >= raster_y_size): - * # no upstream here - * continue # <<<<<<<<<<<<<< - * upstream_flow_dir = flow_dir_managed_raster.get( - * xi_n, yi_n) - */ - goto __pyx_L29_continue; - - /* "pygeoprocessing/routing/routing.pyx":1542 - * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] - * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] - * 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":1546 - * # no upstream here - * continue - * upstream_flow_dir = 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":1548 - * upstream_flow_dir = 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_5 = ((__pyx_v_upstream_flow_dir == __pyx_v_flow_dir_nodata) != 0); - if (!__pyx_t_5) { - } else { - __pyx_t_6 = __pyx_t_5; - goto __pyx_L37_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":1549 - * 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_5 = ((__pyx_v_upstream_flow_dir != (__pyx_v_15pygeoprocessing_7routing_7routing_D8_REVERSE_DIRECTION[__pyx_v_i_n])) != 0); - __pyx_t_6 = __pyx_t_5; - __pyx_L37_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":1548 - * upstream_flow_dir = 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_6) { - - /* "pygeoprocessing/routing/routing.pyx":1552 - * D8_REVERSE_DIRECTION[i_n]): - * # no upstream here - * continue # <<<<<<<<<<<<<< - * upstream_flow_accum = ( - * flow_accum_managed_raster.get(xi_n, yi_n)) - */ - goto __pyx_L29_continue; - - /* "pygeoprocessing/routing/routing.pyx":1548 - * upstream_flow_dir = 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":1553 - * # no upstream here - * continue - * upstream_flow_accum = ( # <<<<<<<<<<<<<< - * flow_accum_managed_raster.get(xi_n, yi_n)) - * if _is_close(upstream_flow_accum, flow_accum_nodata, 1e-8, 1e-5): - */ - __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":1555 - * upstream_flow_accum = ( - * flow_accum_managed_raster.get(xi_n, yi_n)) - * if _is_close(upstream_flow_accum, flow_accum_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * # 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, 1e-8, 1e-5) != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/routing/routing.pyx":1557 - * if _is_close(upstream_flow_accum, flow_accum_nodata, 1e-8, 1e-5): - * # 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":1558 - * # 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 = weight_raster.get( - */ - __pyx_v_search_stack.push(__pyx_v_flow_pixel); - - /* "pygeoprocessing/routing/routing.pyx":1559 - * flow_pixel.last_flow_dir = i_n - * search_stack.push(flow_pixel) - * if weight_raster is not None: # <<<<<<<<<<<<<< - * weight_val = weight_raster.get( - * xi_n, yi_n) - */ - __pyx_t_6 = (((PyObject *)__pyx_v_weight_raster) != Py_None); - __pyx_t_5 = (__pyx_t_6 != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1560 - * search_stack.push(flow_pixel) - * if weight_raster is not None: - * weight_val = weight_raster.get( # <<<<<<<<<<<<<< - * xi_n, yi_n) - * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): - */ - __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":1562 - * weight_val = weight_raster.get( - * xi_n, yi_n) - * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * weight_val = 0.0 - * else: - */ - __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_weight_val, __pyx_v_weight_nodata, 1e-8, 1e-5) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1563 - * xi_n, yi_n) - * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): - * weight_val = 0.0 # <<<<<<<<<<<<<< - * else: - * weight_val = 1.0 - */ - __pyx_v_weight_val = 0.0; - - /* "pygeoprocessing/routing/routing.pyx":1562 - * weight_val = weight_raster.get( - * xi_n, yi_n) - * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * weight_val = 0.0 - * else: - */ - } - - /* "pygeoprocessing/routing/routing.pyx":1559 - * flow_pixel.last_flow_dir = i_n - * search_stack.push(flow_pixel) - * if weight_raster is not None: # <<<<<<<<<<<<<< - * weight_val = weight_raster.get( - * xi_n, yi_n) - */ - goto __pyx_L40; - } - - /* "pygeoprocessing/routing/routing.pyx":1565 - * 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":1567 - * weight_val = 1.0 - * search_stack.push( - * FlowPixelType(xi_n, yi_n, 0, weight_val)) # <<<<<<<<<<<<<< - * preempted = 1 - * break - */ - __pyx_t_30.xi = __pyx_v_xi_n; - __pyx_t_30.yi = __pyx_v_yi_n; - __pyx_t_30.last_flow_dir = 0; - __pyx_t_30.value = __pyx_v_weight_val; - - /* "pygeoprocessing/routing/routing.pyx":1566 - * 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_30); - - /* "pygeoprocessing/routing/routing.pyx":1568 - * 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":1569 - * 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":1555 - * upstream_flow_accum = ( - * flow_accum_managed_raster.get(xi_n, yi_n)) - * if _is_close(upstream_flow_accum, flow_accum_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * # process upstream before this one - * flow_pixel.last_flow_dir = i_n - */ - } - - /* "pygeoprocessing/routing/routing.pyx":1570 - * 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":1571 - * break - * flow_pixel.value += upstream_flow_accum - * if not preempted: # <<<<<<<<<<<<<< - * flow_accum_managed_raster.set( - * flow_pixel.xi, flow_pixel.yi, - */ - __pyx_t_5 = ((!(__pyx_v_preempted != 0)) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1572 - * 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":1571 - * 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":1481 - * - * # this outer loop searches for a pixel that is locally undrained - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * flow_dir_raster_path_band, offset_only=True, largest_block=0): - * win_xsize = offset_dict['win_xsize'] - */ - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1575 - * 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, 1575, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_21 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_21)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_21); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_8 = (__pyx_t_21) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_21) : __Pyx_PyObject_CallNoArg(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1575, __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":1576 - * 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, 1576, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_21 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_21)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_21); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_8 = (__pyx_t_21) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_21) : __Pyx_PyObject_CallNoArg(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1576, __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":1577 - * 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_5 = (((PyObject *)__pyx_v_weight_raster) != Py_None); - __pyx_t_6 = (__pyx_t_5 != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/routing/routing.pyx":1578 - * 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, 1578, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_21 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_21)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_21); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_8 = (__pyx_t_21) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_21) : __Pyx_PyObject_CallNoArg(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1578, __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":1577 - * 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":1579 - * if weight_raster is not None: - * weight_raster.close() - * LOGGER.info('%.1f%% complete', 100.0) # <<<<<<<<<<<<<< - * - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1579, __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, 1579, __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__9, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1579, __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":1359 - * - * - * 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_7); - __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":1582 - * - * - * def flow_dir_mfd( # <<<<<<<<<<<<<< - * dem_raster_path_band, target_flow_dir_path, working_dir=None, - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_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 (str): 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 3 2 1\n 4 x 0\n 5 6 7\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``\n is one of the 8 directions indicated above.\n working_dir (str): 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 raster_driver_creation_tuple (tuple): a tuple containing a GDAL driver\n name string as the first element and a GDAL creation options\n tuple/list as the second. Defaults to a GTiff driver tuple\n defined at geoprocessing.DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS.\n\n Returns:\n None.\n "; -static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_9flow_dir_mfd = {"flow_dir_mfd", (PyCFunction)(void*)(PyCFunctionWithKeywords)__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_raster_driver_creation_tuple = 0; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 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_raster_driver_creation_tuple,0}; - PyObject* values[4] = {0,0,0,0}; - - /* "pygeoprocessing/routing/routing.pyx":1583 - * - * def flow_dir_mfd( - * dem_raster_path_band, target_flow_dir_path, working_dir=None, # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): - * """Multiple flow direction. - */ - values[2] = ((PyObject *)Py_None); - values[3] = __pyx_k__10; - 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, 1582, __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_raster_driver_creation_tuple); - 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, 1582, __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_raster_driver_creation_tuple = 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, 1582, __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_raster_driver_creation_tuple); - - /* "pygeoprocessing/routing/routing.pyx":1582 - * - * - * def flow_dir_mfd( # <<<<<<<<<<<<<< - * dem_raster_path_band, target_flow_dir_path, working_dir=None, - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_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_raster_driver_creation_tuple) { - 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 __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 __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_raster_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; - int __pyx_t_5; - int __pyx_t_6; - double __pyx_t_7; - PyObject *(*__pyx_t_8)(PyObject *); - int __pyx_t_9; - int __pyx_t_10; - PyObject *__pyx_t_11 = NULL; - 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; - int __pyx_t_29; - struct __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateType __pyx_t_30; - __pyx_t_15pygeoprocessing_7routing_7routing_IntQueueType __pyx_t_31; - __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateQueueType __pyx_t_32; - size_t __pyx_t_33; - size_t __pyx_t_34; - size_t __pyx_t_35; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __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":1680 - * # 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":1684 - * # 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1684, __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, 1684, __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, 1684, __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); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1684, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __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":1685 - * # 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_u_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1685, __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, 1685, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_t_3, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1685, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1685, __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_v_base_nodata = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1686 - * 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_5 = (__pyx_v_base_nodata != Py_None); - __pyx_t_6 = (__pyx_t_5 != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/routing/routing.pyx":1688 - * 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1688, __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, 1688, __pyx_L1_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); - } - } - __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_v_base_nodata) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_base_nodata); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1688, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_7 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 1688, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_dem_nodata = __pyx_t_7; - - /* "pygeoprocessing/routing/routing.pyx":1686 - * 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":1691 - * 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":1694 - * - * # 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_u_raster_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1694, __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, 1694, __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, 1694, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1694, __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_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1694, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_4)->tp_iternext; - index = 0; __pyx_t_1 = __pyx_t_8(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - 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, 1694, __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, 1694, __pyx_L1_error) - __pyx_L5_unpacking_done:; - } - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1694, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1694, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_raster_x_size = __pyx_t_9; - __pyx_v_raster_y_size = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":1697 - * - * # 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":1700 - * - * # 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_11, &__pyx_t_12, &__pyx_t_13); - __Pyx_XGOTREF(__pyx_t_11); - __Pyx_XGOTREF(__pyx_t_12); - __Pyx_XGOTREF(__pyx_t_13); - /*try:*/ { - - /* "pygeoprocessing/routing/routing.pyx":1701 - * # set up the working dir for the mask rasters - * try: - * if working_dir is not None: # <<<<<<<<<<<<<< - * os.makedirs(working_dir) - * except OSError: - */ - __pyx_t_6 = (__pyx_v_working_dir != Py_None); - __pyx_t_5 = (__pyx_t_6 != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1702 - * try: - * if working_dir is not None: - * os.makedirs(working_dir) # <<<<<<<<<<<<<< - * except OSError: - * pass - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1702, __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, 1702, __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); - } - } - __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_v_working_dir) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_working_dir); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1702, __pyx_L6_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1701 - * # 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":1700 - * - * # set up the working dir for the mask rasters - * try: # <<<<<<<<<<<<<< - * if working_dir is not None: - * os.makedirs(working_dir) - */ - } - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - goto __pyx_L11_try_end; - __pyx_L6_error:; - __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; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1703 - * if working_dir is not None: - * os.makedirs(working_dir) - * except OSError: # <<<<<<<<<<<<<< - * pass - * working_dir_path = tempfile.mkdtemp( - */ - __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OSError); - if (__pyx_t_10) { - __Pyx_ErrRestore(0,0,0); - goto __pyx_L7_exception_handled; - } - goto __pyx_L8_except_error; - __pyx_L8_except_error:; - - /* "pygeoprocessing/routing/routing.pyx":1700 - * - * # set up the working dir for the mask rasters - * try: # <<<<<<<<<<<<<< - * if working_dir is not None: - * os.makedirs(working_dir) - */ - __Pyx_XGIVEREF(__pyx_t_11); - __Pyx_XGIVEREF(__pyx_t_12); - __Pyx_XGIVEREF(__pyx_t_13); - __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13); - goto __pyx_L1_error; - __pyx_L7_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_11); - __Pyx_XGIVEREF(__pyx_t_12); - __Pyx_XGIVEREF(__pyx_t_13); - __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13); - __pyx_L11_try_end:; - } - - /* "pygeoprocessing/routing/routing.pyx":1705 - * except OSError: - * pass - * working_dir_path = tempfile.mkdtemp( # <<<<<<<<<<<<<< - * dir=working_dir, - * prefix='flow_dir_multiple_flow_dir_%s_' % time.strftime( - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_tempfile); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1705, __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, 1705, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1706 - * 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, 1706, __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, 1706, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":1707 - * 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_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_time); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1707, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_strftime); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1707, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1708 - * 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_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_time); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1708, __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, 1708, __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); - } - } - __pyx_t_4 = (__pyx_t_15) ? __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_t_15) : __Pyx_PyObject_CallNoArg(__pyx_t_16); - __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1708, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_16 = NULL; - __pyx_t_10 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { - __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_16)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_16); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - __pyx_t_10 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_14)) { - PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_kp_u_Y_m_d__H__M__S, __pyx_t_4}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1707, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 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_14)) { - PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_kp_u_Y_m_d__H__M__S, __pyx_t_4}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1707, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - { - __pyx_t_15 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1707, __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_u_Y_m_d__H__M__S); - __Pyx_GIVEREF(__pyx_kp_u_Y_m_d__H__M__S); - PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_10, __pyx_kp_u_Y_m_d__H__M__S); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_10, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_15, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1707, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - } - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1707 - * 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_14 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_flow_dir_multiple_flow_dir__s, __pyx_t_2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1707, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_prefix, __pyx_t_14) < 0) __PYX_ERR(0, 1706, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1705 - * except OSError: - * pass - * working_dir_path = tempfile.mkdtemp( # <<<<<<<<<<<<<< - * dir=working_dir, - * prefix='flow_dir_multiple_flow_dir_%s_' % time.strftime( - */ - __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1705, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __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_14; - __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1713 - * # 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1713, __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, 1713, __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, 1713, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1714 - * # 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_10 = 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_10 = 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_u_flat_region_mask_tif}; - __pyx_t_14 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1713, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_14); - } 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_u_flat_region_mask_tif}; - __pyx_t_14 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1713, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_14); - } else - #endif - { - __pyx_t_2 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1713, __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_v_working_dir_path); - __Pyx_GIVEREF(__pyx_v_working_dir_path); - PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_10, __pyx_v_working_dir_path); - __Pyx_INCREF(__pyx_kp_u_flat_region_mask_tif); - __Pyx_GIVEREF(__pyx_kp_u_flat_region_mask_tif); - PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_10, __pyx_kp_u_flat_region_mask_tif); - __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1713, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_flat_region_mask_path = __pyx_t_14; - __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1715 - * 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], - */ - __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1715, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1715, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1716 - * 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], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - */ - __pyx_t_14 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1716, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1716, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1716, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1717 - * pygeoprocessing.new_raster_from_base( - * dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte, - * [mask_nodata], # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * flat_region_mask_managed_raster = _ManagedRaster( - */ - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_mask_nodata); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1717, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_15 = PyList_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1717, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_GIVEREF(__pyx_t_2); - PyList_SET_ITEM(__pyx_t_15, 0, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1715 - * 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], - */ - __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1715, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_14); - __Pyx_INCREF(__pyx_v_flat_region_mask_path); - __Pyx_GIVEREF(__pyx_v_flat_region_mask_path); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_flat_region_mask_path); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_15); - PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_15); - __pyx_t_14 = 0; - __pyx_t_1 = 0; - __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1718 - * dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte, - * [mask_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< - * flat_region_mask_managed_raster = _ManagedRaster( - * flat_region_mask_path, 1, 1) - */ - __pyx_t_15 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1718, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 1718, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":1715 - * 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], - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1715, __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_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1719 - * [mask_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * flat_region_mask_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< - * flat_region_mask_path, 1, 1) - * - */ - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1719, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_flat_region_mask_path); - __Pyx_GIVEREF(__pyx_v_flat_region_mask_path); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_flat_region_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_15 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_1, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1719, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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":1722 - * 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":1723 - * - * flow_dir_nodata = 0 - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Int32, - * [flow_dir_nodata], - */ - __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1723, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1723, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1724 - * flow_dir_nodata = 0 - * pygeoprocessing.new_raster_from_base( - * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Int32, # <<<<<<<<<<<<<< - * [flow_dir_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - */ - __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, 1724, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1724, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_GDT_Int32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1724, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1725 - * pygeoprocessing.new_raster_from_base( - * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Int32, - * [flow_dir_nodata], # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * flow_dir_managed_raster = _ManagedRaster(target_flow_dir_path, 1, 1) - */ - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_flow_dir_nodata); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1725, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_14 = PyList_New(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1725, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_GIVEREF(__pyx_t_2); - PyList_SET_ITEM(__pyx_t_14, 0, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1723 - * - * flow_dir_nodata = 0 - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Int32, - * [flow_dir_nodata], - */ - __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1723, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_15); - PyTuple_SET_ITEM(__pyx_t_2, 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_2, 1, __pyx_v_target_flow_dir_path); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_14); - __pyx_t_15 = 0; - __pyx_t_3 = 0; - __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1726 - * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Int32, - * [flow_dir_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< - * flow_dir_managed_raster = _ManagedRaster(target_flow_dir_path, 1, 1) - * - */ - __pyx_t_14 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1726, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 1726, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":1723 - * - * flow_dir_nodata = 0 - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Int32, - * [flow_dir_nodata], - */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_14); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1723, __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_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1727 - * [flow_dir_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * flow_dir_managed_raster = _ManagedRaster(target_flow_dir_path, 1, 1) # <<<<<<<<<<<<<< - * - * plateu_drain_mask_path = os.path.join( - */ - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1727, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_target_flow_dir_path); - __Pyx_GIVEREF(__pyx_v_target_flow_dir_path); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_target_flow_dir_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_14 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_3, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1727, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_flow_dir_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_14); - __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1729 - * 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1729, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_path); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1729, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_join); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1729, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1730 - * - * 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_2 = NULL; - __pyx_t_10 = 0; - if (CYTHON_UNPACK_METHODS && likely(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_10 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_working_dir_path, __pyx_kp_u_plateu_drain_mask_tif}; - __pyx_t_14 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1729, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_14); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_working_dir_path, __pyx_kp_u_plateu_drain_mask_tif}; - __pyx_t_14 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1729, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_14); - } else - #endif - { - __pyx_t_1 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1729, __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_v_working_dir_path); - __Pyx_GIVEREF(__pyx_v_working_dir_path); - PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_10, __pyx_v_working_dir_path); - __Pyx_INCREF(__pyx_kp_u_plateu_drain_mask_tif); - __Pyx_GIVEREF(__pyx_kp_u_plateu_drain_mask_tif); - PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_10, __pyx_kp_u_plateu_drain_mask_tif); - __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1729, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_plateu_drain_mask_path = __pyx_t_14; - __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1731 - * 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], - */ - __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1731, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1731, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1732 - * 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], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - */ - __pyx_t_14 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1732, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1732, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1732, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1733 - * pygeoprocessing.new_raster_from_base( - * dem_raster_path_band[0], plateu_drain_mask_path, gdal.GDT_Byte, - * [mask_nodata], # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * plateau_drain_mask_managed_raster = _ManagedRaster( - */ - __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_mask_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1733, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_15 = PyList_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1733, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_GIVEREF(__pyx_t_1); - PyList_SET_ITEM(__pyx_t_15, 0, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1731 - * 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], - */ - __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1731, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_14); - __Pyx_INCREF(__pyx_v_plateu_drain_mask_path); - __Pyx_GIVEREF(__pyx_v_plateu_drain_mask_path); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_plateu_drain_mask_path); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_15); - PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_15); - __pyx_t_14 = 0; - __pyx_t_2 = 0; - __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1734 - * dem_raster_path_band[0], plateu_drain_mask_path, gdal.GDT_Byte, - * [mask_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< - * plateau_drain_mask_managed_raster = _ManagedRaster( - * plateu_drain_mask_path, 1, 1) - */ - __pyx_t_15 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1734, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 1734, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":1731 - * 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], - */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, __pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1731, __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; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1735 - * [mask_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * plateau_drain_mask_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< - * plateu_drain_mask_path, 1, 1) - * - */ - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1735, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_plateu_drain_mask_path); - __Pyx_GIVEREF(__pyx_v_plateu_drain_mask_path); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_plateu_drain_mask_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_15 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_2, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1735, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_plateau_drain_mask_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_15); - __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1742 - * # 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1742, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1742, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_join); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1742, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1743 - * # 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_1 = NULL; - __pyx_t_10 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_1); - __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_1, __pyx_v_working_dir_path, __pyx_kp_u_plateau_distance_tif}; - __pyx_t_15 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1742, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_15); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_working_dir_path, __pyx_kp_u_plateau_distance_tif}; - __pyx_t_15 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1742, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_15); - } else - #endif - { - __pyx_t_3 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1742, __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_INCREF(__pyx_v_working_dir_path); - __Pyx_GIVEREF(__pyx_v_working_dir_path); - PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_10, __pyx_v_working_dir_path); - __Pyx_INCREF(__pyx_kp_u_plateau_distance_tif); - __Pyx_GIVEREF(__pyx_kp_u_plateau_distance_tif); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_10, __pyx_kp_u_plateau_distance_tif); - __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1742, __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_v_plateau_distance_path = __pyx_t_15; - __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1744 - * 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":1745 - * 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_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1745, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1745, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1746 - * 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_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, 1746, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1746, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1746, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1747 - * 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], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - */ - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_plateau_distance_nodata); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1747, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_14 = PyList_New(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1747, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_GIVEREF(__pyx_t_3); - PyList_SET_ITEM(__pyx_t_14, 0, __pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1745 - * 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 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1745, __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_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_1); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_14); - __pyx_t_15 = 0; - __pyx_t_1 = 0; - __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1747 - * 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], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - */ - __pyx_t_14 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1747, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - - /* "pygeoprocessing/routing/routing.pyx":1748 - * dem_raster_path_band[0], plateau_distance_path, gdal.GDT_Float64, - * [plateau_distance_nodata], fill_value_list=[ - * raster_x_size * raster_y_size], # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * plateau_distance_managed_raster = _ManagedRaster( - */ - __pyx_t_1 = __Pyx_PyInt_From_int((__pyx_v_raster_x_size * __pyx_v_raster_y_size)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1748, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":1747 - * 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], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - */ - __pyx_t_15 = PyList_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1747, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_GIVEREF(__pyx_t_1); - PyList_SET_ITEM(__pyx_t_15, 0, __pyx_t_1); - __pyx_t_1 = 0; - if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_fill_value_list, __pyx_t_15) < 0) __PYX_ERR(0, 1747, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1749 - * [plateau_distance_nodata], fill_value_list=[ - * raster_x_size * raster_y_size], - * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< - * plateau_distance_managed_raster = _ManagedRaster( - * plateau_distance_path, 1, 1) - */ - if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 1747, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":1745 - * 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 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_14); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1745, __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_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1750 - * raster_x_size * raster_y_size], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * plateau_distance_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< - * plateau_distance_path, 1, 1) - * - */ - __pyx_t_15 = PyTuple_New(3); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1750, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_INCREF(__pyx_v_plateau_distance_path); - __Pyx_GIVEREF(__pyx_v_plateau_distance_path); - PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_v_plateau_distance_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_14 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_15, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1750, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_v_plateau_distance_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_14); - __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1754 - * - * # 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":1755 - * # 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_14 = __Pyx_PyObject_Dict_GetItem(__pyx_v_dem_raster_info, __pyx_n_u_block_size); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1755, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - if ((likely(PyTuple_CheckExact(__pyx_t_14))) || (PyList_CheckExact(__pyx_t_14))) { - PyObject* sequence = __pyx_t_14; - 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, 1755, __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_3 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_15 = PyList_GET_ITEM(sequence, 0); - __pyx_t_3 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_15); - __Pyx_INCREF(__pyx_t_3); - #else - __pyx_t_15 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1755, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1755, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_2 = PyObject_GetIter(__pyx_t_14); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1755, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_2)->tp_iternext; - index = 0; __pyx_t_15 = __pyx_t_8(__pyx_t_2); if (unlikely(!__pyx_t_15)) goto __pyx_L13_unpacking_failed; - __Pyx_GOTREF(__pyx_t_15); - index = 1; __pyx_t_3 = __pyx_t_8(__pyx_t_2); if (unlikely(!__pyx_t_3)) goto __pyx_L13_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_2), 2) < 0) __PYX_ERR(0, 1755, __pyx_L1_error) - __pyx_t_8 = NULL; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L14_unpacking_done; - __pyx_L13_unpacking_failed:; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_8 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 1755, __pyx_L1_error) - __pyx_L14_unpacking_done:; - } - __pyx_v_dem_block_xsize = __pyx_t_15; - __pyx_t_15 = 0; - __pyx_v_dem_block_ysize = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1756 - * 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_14 = __Pyx_PyInt_SubtractObjC(__pyx_v_dem_block_xsize, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1756, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_3 = PyNumber_And(__pyx_v_dem_block_xsize, __pyx_t_14); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1756, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_14 = __Pyx_PyInt_NeObjC(__pyx_t_3, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1756, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1756, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L16_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":1757 - * 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_14 = __Pyx_PyInt_SubtractObjC(__pyx_v_dem_block_ysize, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1757, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_3 = PyNumber_And(__pyx_v_dem_block_ysize, __pyx_t_14); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1757, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_14 = __Pyx_PyInt_NeObjC(__pyx_t_3, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1757, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1757, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_5 = __pyx_t_6; - __pyx_L16_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":1756 - * 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_5) { - - /* "pygeoprocessing/routing/routing.pyx":1758 - * 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_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1758, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_warning); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1758, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(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_14 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_15, __pyx_t_3, __pyx_kp_u_dem_is_not_a_power_of_2_creating) : __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_kp_u_dem_is_not_a_power_of_2_creating); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1758, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1760 - * 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]) - * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) - */ - __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_os); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1760, __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, 1760, __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, 1760, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - __pyx_t_10 = 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_10 = 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_u_compatable_dem_tif}; - __pyx_t_14 = __Pyx_PyFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1760, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_14); - } 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_u_compatable_dem_tif}; - __pyx_t_14 = __Pyx_PyCFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1760, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_14); - } else - #endif - { - __pyx_t_2 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1760, __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_v_working_dir_path); - __Pyx_GIVEREF(__pyx_v_working_dir_path); - PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_10, __pyx_v_working_dir_path); - __Pyx_INCREF(__pyx_kp_u_compatable_dem_tif); - __Pyx_GIVEREF(__pyx_kp_u_compatable_dem_tif); - PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_10, __pyx_kp_u_compatable_dem_tif); - __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_2, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1760, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1761 - * compatable_dem_raster_path_band = ( - * os.path.join(working_dir_path, 'compatable_dem.tif'), - * dem_raster_path_band[1]) # <<<<<<<<<<<<<< - * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) - * 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, 1761, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - - /* "pygeoprocessing/routing/routing.pyx":1760 - * 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]) - * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) - */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1760, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_14); - __Pyx_GIVEREF(__pyx_t_15); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_15); - __pyx_t_14 = 0; - __pyx_t_15 = 0; - __Pyx_DECREF_SET(__pyx_v_compatable_dem_raster_path_band, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1762 - * os.path.join(working_dir_path, 'compatable_dem.tif'), - * dem_raster_path_band[1]) - * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) # <<<<<<<<<<<<<< - * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) - * raster_driver.CreateCopy( - */ - __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_gdal); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1762, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_GetDriverByName); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1762, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_15 = __Pyx_GetItemInt(__pyx_v_raster_driver_creation_tuple, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1762, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - } - } - __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_3, __pyx_t_15) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_t_15); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1762, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_v_raster_driver = __pyx_t_2; - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1763 - * dem_raster_path_band[1]) - * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) - * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) # <<<<<<<<<<<<<< - * raster_driver.CreateCopy( - * compatable_dem_raster_path_band[0], dem_raster, - */ - __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_gdal); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1763, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1763, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_14 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1763, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1763, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1763, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - __pyx_t_10 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(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_10 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_15)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_t_14, __pyx_t_1}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1763, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_15)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_t_14, __pyx_t_1}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1763, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - { - __pyx_t_4 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1763, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_10, __pyx_t_14); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_10, __pyx_t_1); - __pyx_t_14 = 0; - __pyx_t_1 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1763, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_v_dem_raster = __pyx_t_2; - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1764 - * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) - * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) - * raster_driver.CreateCopy( # <<<<<<<<<<<<<< - * compatable_dem_raster_path_band[0], dem_raster, - * options=raster_driver_creation_tuple[1]) - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster_driver, __pyx_n_s_CreateCopy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1764, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - - /* "pygeoprocessing/routing/routing.pyx":1765 - * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) - * raster_driver.CreateCopy( - * compatable_dem_raster_path_band[0], dem_raster, # <<<<<<<<<<<<<< - * options=raster_driver_creation_tuple[1]) - * dem_raster = None - */ - __pyx_t_15 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1765, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - - /* "pygeoprocessing/routing/routing.pyx":1764 - * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) - * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) - * raster_driver.CreateCopy( # <<<<<<<<<<<<<< - * compatable_dem_raster_path_band[0], dem_raster, - * options=raster_driver_creation_tuple[1]) - */ - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1764, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_15); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_15); - __Pyx_INCREF(__pyx_v_dem_raster); - __Pyx_GIVEREF(__pyx_v_dem_raster); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_dem_raster); - __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1766 - * raster_driver.CreateCopy( - * compatable_dem_raster_path_band[0], dem_raster, - * options=raster_driver_creation_tuple[1]) # <<<<<<<<<<<<<< - * dem_raster = None - * LOGGER.info("compatible dem complete") - */ - __pyx_t_15 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1766, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_raster_driver_creation_tuple, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1766, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_options, __pyx_t_1) < 0) __PYX_ERR(0, 1766, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1764 - * raster_driver = gdal.GetDriverByName(raster_driver_creation_tuple[0]) - * dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER) - * raster_driver.CreateCopy( # <<<<<<<<<<<<<< - * compatable_dem_raster_path_band[0], dem_raster, - * options=raster_driver_creation_tuple[1]) - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, __pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1764, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1767 - * compatable_dem_raster_path_band[0], dem_raster, - * options=raster_driver_creation_tuple[1]) - * 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":1768 - * options=raster_driver_creation_tuple[1]) - * dem_raster = None - * LOGGER.info("compatible dem complete") # <<<<<<<<<<<<<< - * else: - * compatable_dem_raster_path_band = dem_raster_path_band - */ - __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1768, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_info); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1768, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_15 = NULL; - 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_1 = (__pyx_t_15) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_15, __pyx_kp_u_compatible_dem_complete) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_compatible_dem_complete); - __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1768, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1756 - * 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":1770 - * 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":1772 - * 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_1 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1772, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":1773 - * 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, 1773, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - - /* "pygeoprocessing/routing/routing.pyx":1771 - * 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_15 = PyTuple_New(3); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1771, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_4); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_int_0); - __pyx_t_1 = 0; - __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_15, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1771, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_v_dem_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_4); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1776 - * - * # 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_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_gdal); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1776, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1776, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1777 - * # 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_15 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1777, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1777, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1777, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - __pyx_t_10 = 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_10 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_15, __pyx_t_14}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1776, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_15, __pyx_t_14}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1776, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - } else - #endif - { - __pyx_t_3 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1776, __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_GIVEREF(__pyx_t_15); - PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_10, __pyx_t_15); - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_10, __pyx_t_14); - __pyx_t_15 = 0; - __pyx_t_14 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1776, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF_SET(__pyx_v_dem_raster, __pyx_t_4); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1778 - * 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_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_dem_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1778, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":1779 - * 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, 1779, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_14 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_14)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_14); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_4 = (__pyx_t_14) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_14, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3); - __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1778, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_dem_band = __pyx_t_4; - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1782 - * - * # this outer loop searches for a pixel that is locally undrained - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * compatable_dem_raster_path_band, offset_only=True, - * largest_block=0): - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1782, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1782, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1783 - * # this outer loop searches for a pixel that is locally undrained - * for offset_dict in pygeoprocessing.iterblocks( - * compatable_dem_raster_path_band, offset_only=True, # <<<<<<<<<<<<<< - * largest_block=0): - * win_xsize = offset_dict['win_xsize'] - */ - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1782, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_v_compatable_dem_raster_path_band); - __Pyx_GIVEREF(__pyx_v_compatable_dem_raster_path_band); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_compatable_dem_raster_path_band); - __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1783, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 1783, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_largest_block, __pyx_int_0) < 0) __PYX_ERR(0, 1783, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":1782 - * - * # this outer loop searches for a pixel that is locally undrained - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * compatable_dem_raster_path_band, offset_only=True, - * largest_block=0): - */ - __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1782, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (likely(PyList_CheckExact(__pyx_t_14)) || PyTuple_CheckExact(__pyx_t_14)) { - __pyx_t_3 = __pyx_t_14; __Pyx_INCREF(__pyx_t_3); __pyx_t_17 = 0; - __pyx_t_18 = NULL; - } else { - __pyx_t_17 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_14); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1782, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_18 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 1782, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - for (;;) { - if (likely(!__pyx_t_18)) { - if (likely(PyList_CheckExact(__pyx_t_3))) { - if (__pyx_t_17 >= PyList_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_14 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_17); __Pyx_INCREF(__pyx_t_14); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 1782, __pyx_L1_error) - #else - __pyx_t_14 = PySequence_ITEM(__pyx_t_3, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1782, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - #endif - } else { - if (__pyx_t_17 >= PyTuple_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_14 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_17); __Pyx_INCREF(__pyx_t_14); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 1782, __pyx_L1_error) - #else - __pyx_t_14 = PySequence_ITEM(__pyx_t_3, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1782, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - #endif - } - } else { - __pyx_t_14 = __pyx_t_18(__pyx_t_3); - if (unlikely(!__pyx_t_14)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1782, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_14); - } - __Pyx_XDECREF_SET(__pyx_v_offset_dict, __pyx_t_14); - __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1785 - * compatable_dem_raster_path_band, offset_only=True, - * largest_block=0): - * win_xsize = offset_dict['win_xsize'] # <<<<<<<<<<<<<< - * win_ysize = offset_dict['win_ysize'] - * xoff = offset_dict['xoff'] - */ - __pyx_t_14 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1785, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_14); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1785, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_v_win_xsize = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":1786 - * 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_14 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1786, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_14); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1786, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_v_win_ysize = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":1787 - * win_xsize = offset_dict['win_xsize'] - * win_ysize = offset_dict['win_ysize'] - * xoff = offset_dict['xoff'] # <<<<<<<<<<<<<< - * yoff = offset_dict['yoff'] - * - */ - __pyx_t_14 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_xoff); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1787, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_14); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1787, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_v_xoff = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":1788 - * win_ysize = offset_dict['win_ysize'] - * xoff = offset_dict['xoff'] - * yoff = offset_dict['yoff'] # <<<<<<<<<<<<<< - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - */ - __pyx_t_14 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_yoff); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1788, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_14); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1788, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_v_yoff = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":1790 - * yoff = offset_dict['yoff'] - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - */ - __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1791 - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( - */ - __pyx_v_last_log_time = time(NULL); - - /* "pygeoprocessing/routing/routing.pyx":1792 - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size # <<<<<<<<<<<<<< - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( - * raster_x_size * raster_y_size)) - */ - __pyx_t_14 = __Pyx_PyInt_From_int((__pyx_v_xoff + (__pyx_v_yoff * __pyx_v_raster_x_size))); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1792, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_XDECREF_SET(__pyx_v_current_pixel, __pyx_t_14); - __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1793 - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< - * raster_x_size * raster_y_size)) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1793, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1793, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyNumber_Multiply(__pyx_float_100_0, __pyx_v_current_pixel); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1793, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - - /* "pygeoprocessing/routing/routing.pyx":1794 - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( - * 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, 1793, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - - /* "pygeoprocessing/routing/routing.pyx":1793 - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< - * raster_x_size * raster_y_size)) - * - */ - __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_t_4, __pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1793, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_15 = NULL; - __pyx_t_10 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_15)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_15); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - __pyx_t_10 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_kp_u_1f_complete, __pyx_t_2}; - __pyx_t_14 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1793, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_GOTREF(__pyx_t_14); - __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_15, __pyx_kp_u_1f_complete, __pyx_t_2}; - __pyx_t_14 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1793, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else - #endif - { - __pyx_t_4 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1793, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (__pyx_t_15) { - __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_15); __pyx_t_15 = NULL; - } - __Pyx_INCREF(__pyx_kp_u_1f_complete); - __Pyx_GIVEREF(__pyx_kp_u_1f_complete); - PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_10, __pyx_kp_u_1f_complete); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_10, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1793, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1790 - * yoff = offset_dict['yoff'] - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - */ - } - - /* "pygeoprocessing/routing/routing.pyx":1797 - * - * # 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_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_numpy); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1797, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1797, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1798 - * # 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_14 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1798, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_t_14, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1798, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_14 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1798, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_14, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1798, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_14 = PyTuple_New(2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1798, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_t_2); - __pyx_t_4 = 0; - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1797 - * - * # 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_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1797, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_14); - __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1799 - * 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_14 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1799, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_numpy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1799, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float64); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1799, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_dtype, __pyx_t_15) < 0) __PYX_ERR(0, 1799, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1797 - * - * # 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_1, __pyx_t_2, __pyx_t_14); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1797, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - if (!(likely(((__pyx_t_15) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_15, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1797, __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_10 = __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_10 < 0)) { - PyErr_Fetch(&__pyx_t_13, &__pyx_t_12, &__pyx_t_11); - 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_13); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_11); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_13, __pyx_t_12, __pyx_t_11); - } - __pyx_t_13 = __pyx_t_12 = __pyx_t_11 = 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_10 < 0)) __PYX_ERR(0, 1797, __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":1800 - * (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, 1800, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_dem_buffer_array), __pyx_slice__7, __pyx_t_15) < 0)) __PYX_ERR(0, 1800, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1804 - * # 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_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_generate_read_bounds); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1804, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - - /* "pygeoprocessing/routing/routing.pyx":1805 - * # 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_2 = __Pyx_PyInt_From_int(__pyx_v_raster_x_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1805, __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, 1805, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = NULL; - __pyx_t_10 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - __pyx_t_10 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_14)) { - PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_offset_dict, __pyx_t_2, __pyx_t_1}; - __pyx_t_15 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1804, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_15); - __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_14)) { - PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_offset_dict, __pyx_t_2, __pyx_t_1}; - __pyx_t_15 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1804, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - { - __pyx_t_16 = PyTuple_New(3+__pyx_t_10); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1804, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - if (__pyx_t_4) { - __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_4); __pyx_t_4 = NULL; - } - __Pyx_INCREF(__pyx_v_offset_dict); - __Pyx_GIVEREF(__pyx_v_offset_dict); - PyTuple_SET_ITEM(__pyx_t_16, 0+__pyx_t_10, __pyx_v_offset_dict); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_16, 1+__pyx_t_10, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_16, 2+__pyx_t_10, __pyx_t_1); - __pyx_t_2 = 0; - __pyx_t_1 = 0; - __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_16, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1804, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - } - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 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, 1804, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_14 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_16 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_14 = PyList_GET_ITEM(sequence, 0); - __pyx_t_16 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_14); - __Pyx_INCREF(__pyx_t_16); - #else - __pyx_t_14 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1804, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_16 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1804, __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_1 = PyObject_GetIter(__pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1804, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_1)->tp_iternext; - index = 0; __pyx_t_14 = __pyx_t_8(__pyx_t_1); if (unlikely(!__pyx_t_14)) goto __pyx_L21_unpacking_failed; - __Pyx_GOTREF(__pyx_t_14); - index = 1; __pyx_t_16 = __pyx_t_8(__pyx_t_1); if (unlikely(!__pyx_t_16)) goto __pyx_L21_unpacking_failed; - __Pyx_GOTREF(__pyx_t_16); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_1), 2) < 0) __PYX_ERR(0, 1804, __pyx_L1_error) - __pyx_t_8 = NULL; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L22_unpacking_done; - __pyx_L21_unpacking_failed:; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_8 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 1804, __pyx_L1_error) - __pyx_L22_unpacking_done:; - } - - /* "pygeoprocessing/routing/routing.pyx":1804 - * # 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_14))) || (PyList_CheckExact(__pyx_t_14))) { - PyObject* sequence = __pyx_t_14; - 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, 1804, __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_4 = PyTuple_GET_ITEM(sequence, 2); - __pyx_t_20 = PyTuple_GET_ITEM(sequence, 3); - } else { - __pyx_t_1 = PyList_GET_ITEM(sequence, 0); - __pyx_t_2 = PyList_GET_ITEM(sequence, 1); - __pyx_t_4 = PyList_GET_ITEM(sequence, 2); - __pyx_t_20 = PyList_GET_ITEM(sequence, 3); - } - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_20); - #else - { - Py_ssize_t i; - PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_2,&__pyx_t_4,&__pyx_t_20}; - for (i=0; i < 4; i++) { - PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 1804, __pyx_L1_error) - __Pyx_GOTREF(item); - *(temps[i]) = item; - } - } - #endif - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - } else { - Py_ssize_t index = -1; - PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_2,&__pyx_t_4,&__pyx_t_20}; - __pyx_t_21 = PyObject_GetIter(__pyx_t_14); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 1804, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_21); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_21)->tp_iternext; - for (index=0; index < 4; index++) { - PyObject* item = __pyx_t_8(__pyx_t_21); if (unlikely(!item)) goto __pyx_L23_unpacking_failed; - __Pyx_GOTREF(item); - *(temps[index]) = item; - } - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_21), 4) < 0) __PYX_ERR(0, 1804, __pyx_L1_error) - __pyx_t_8 = 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_8 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 1804, __pyx_L1_error) - __pyx_L24_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_4); - __pyx_t_4 = 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":1806 - * (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, 1806, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - - /* "pygeoprocessing/routing/routing.pyx":1807 - * 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, 1807, __pyx_L1_error) - } - if (likely(PyDict_CheckExact(__pyx_v_modified_offset_dict))) { - __pyx_t_14 = PyDict_Copy(__pyx_v_modified_offset_dict); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1807, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - } else { - __pyx_t_14 = PyObject_CallFunctionObjArgs((PyObject*)&PyDict_Type, __pyx_v_modified_offset_dict, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1806, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - } - - /* "pygeoprocessing/routing/routing.pyx":1806 - * (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_14); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1806, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1807 - * 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_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_20, __pyx_n_s_astype); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1807, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_20, __pyx_n_s_numpy); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1807, __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, 1807, __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_14))) { - __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_20)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_20); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - } - } - __pyx_t_15 = (__pyx_t_20) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_20, __pyx_t_16) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_t_16); - __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1807, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1806 - * (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_14 = PySlice_New(__pyx_v_ya, __pyx_v_yb, Py_None); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1806, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_16 = PySlice_New(__pyx_v_xa, __pyx_v_xb, Py_None); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1806, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_20 = PyTuple_New(2); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1806, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_14); - __Pyx_GIVEREF(__pyx_t_16); - PyTuple_SET_ITEM(__pyx_t_20, 1, __pyx_t_16); - __pyx_t_14 = 0; - __pyx_t_16 = 0; - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_dem_buffer_array), __pyx_t_20, __pyx_t_15) < 0)) __PYX_ERR(0, 1806, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1810 - * - * # ensure these are set for the complier - * xi_n = -1 # <<<<<<<<<<<<<< - * yi_n = -1 - * - */ - __pyx_v_xi_n = -1; - - /* "pygeoprocessing/routing/routing.pyx":1811 - * # 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":1814 - * - * # 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_10 = 1; __pyx_t_10 < __pyx_t_23; __pyx_t_10+=1) { - __pyx_v_yi = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":1815 - * # 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, 1e-8, 1e-5): - */ - __pyx_t_24 = (__pyx_v_win_xsize + 1); - __pyx_t_25 = __pyx_t_24; - for (__pyx_t_9 = 1; __pyx_t_9 < __pyx_t_25; __pyx_t_9+=1) { - __pyx_v_xi = __pyx_t_9; - - /* "pygeoprocessing/routing/routing.pyx":1816 - * 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, 1e-8, 1e-5): - * 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, 1816, __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":1817 - * for xi in range(1, win_xsize+1): - * root_height = dem_buffer_array[yi, xi] - * if _is_close(root_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_root_height, __pyx_v_dem_nodata, 1e-8, 1e-5) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1818 - * root_height = dem_buffer_array[yi, xi] - * if _is_close(root_height, dem_nodata, 1e-8, 1e-5): - * continue # <<<<<<<<<<<<<< - * - * # this value is set in case it turns out to be the root of a - */ - goto __pyx_L27_continue; - - /* "pygeoprocessing/routing/routing.pyx":1817 - * for xi in range(1, win_xsize+1): - * root_height = dem_buffer_array[yi, xi] - * if _is_close(root_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * continue - * - */ - } - - /* "pygeoprocessing/routing/routing.pyx":1823 - * # 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":1824 - * # 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":1827 - * - * if flow_dir_managed_raster.get( - * xi_root, yi_root) != flow_dir_nodata: # <<<<<<<<<<<<<< - * # already been defined - * continue - */ - __pyx_t_5 = ((__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":1826 - * yi_root = yi-1+yoff - * - * if flow_dir_managed_raster.get( # <<<<<<<<<<<<<< - * xi_root, yi_root) != flow_dir_nodata: - * # already been defined - */ - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1829 - * 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":1826 - * 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":1835 - * # 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":1836 - * # 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":1838 - * for i_n in range(8): - * # initialize downhill slopes to 0.0 - * downhill_slope_array[i_n] = 0.0 # <<<<<<<<<<<<<< - * xi_n = xi+D8_XOFFSET[i_n] - * yi_n = yi+D8_YOFFSET[i_n] - */ - (__pyx_v_downhill_slope_array[__pyx_v_i_n]) = 0.0; - - /* "pygeoprocessing/routing/routing.pyx":1839 - * # initialize downhill slopes to 0.0 - * downhill_slope_array[i_n] = 0.0 - * xi_n = xi+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< - * yi_n = yi+D8_YOFFSET[i_n] - * n_height = dem_buffer_array[yi_n, xi_n] - */ - __pyx_v_xi_n = (__pyx_v_xi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":1840 - * downhill_slope_array[i_n] = 0.0 - * xi_n = xi+D8_XOFFSET[i_n] - * yi_n = yi+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< - * n_height = dem_buffer_array[yi_n, xi_n] - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): - */ - __pyx_v_yi_n = (__pyx_v_yi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":1841 - * xi_n = xi+D8_XOFFSET[i_n] - * yi_n = yi+D8_YOFFSET[i_n] - * n_height = dem_buffer_array[yi_n, xi_n] # <<<<<<<<<<<<<< - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): - * continue - */ - __pyx_t_27 = __pyx_v_yi_n; - __pyx_t_26 = __pyx_v_xi_n; - __pyx_t_29 = -1; - if (__pyx_t_27 < 0) { - __pyx_t_27 += __pyx_pybuffernd_dem_buffer_array.diminfo[0].shape; - if (unlikely(__pyx_t_27 < 0)) __pyx_t_29 = 0; - } else if (unlikely(__pyx_t_27 >= __pyx_pybuffernd_dem_buffer_array.diminfo[0].shape)) __pyx_t_29 = 0; - if (__pyx_t_26 < 0) { - __pyx_t_26 += __pyx_pybuffernd_dem_buffer_array.diminfo[1].shape; - if (unlikely(__pyx_t_26 < 0)) __pyx_t_29 = 1; - } else if (unlikely(__pyx_t_26 >= __pyx_pybuffernd_dem_buffer_array.diminfo[1].shape)) __pyx_t_29 = 1; - if (unlikely(__pyx_t_29 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_29); - __PYX_ERR(0, 1841, __pyx_L1_error) - } - __pyx_v_n_height = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_dem_buffer_array.diminfo[0].strides, __pyx_t_26, __pyx_pybuffernd_dem_buffer_array.diminfo[1].strides)); - - /* "pygeoprocessing/routing/routing.pyx":1842 - * yi_n = yi+D8_YOFFSET[i_n] - * n_height = dem_buffer_array[yi_n, xi_n] - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * continue - * n_slope = root_height - n_height - */ - __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_n_height, __pyx_v_dem_nodata, 1e-8, 1e-5) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1843 - * n_height = dem_buffer_array[yi_n, xi_n] - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): - * continue # <<<<<<<<<<<<<< - * n_slope = root_height - n_height - * if n_slope > 0.0: - */ - goto __pyx_L31_continue; - - /* "pygeoprocessing/routing/routing.pyx":1842 - * yi_n = yi+D8_YOFFSET[i_n] - * n_height = dem_buffer_array[yi_n, xi_n] - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * continue - * n_slope = root_height - n_height - */ - } - - /* "pygeoprocessing/routing/routing.pyx":1844 - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): - * 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":1845 - * continue - * n_slope = root_height - n_height - * if n_slope > 0.0: # <<<<<<<<<<<<<< - * if i_n & 1: - * # if diagonal, adjust the slope - */ - __pyx_t_5 = ((__pyx_v_n_slope > 0.0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1846 - * 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_5 = ((__pyx_v_i_n & 1) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1848 - * 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":1846 - * 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":1849 - * # 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":1850 - * 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":1845 - * 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":1852 - * 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_5 = ((__pyx_v_sum_of_downhill_slopes > 0.0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1853 - * - * if sum_of_downhill_slopes > 0.0: - * compressed_integer_slopes = 0 # <<<<<<<<<<<<<< - * for i_n in range(8): - * compressed_integer_slopes |= (( - */ - __pyx_v_compressed_integer_slopes = 0; - - /* "pygeoprocessing/routing/routing.pyx":1854 - * if sum_of_downhill_slopes > 0.0: - * compressed_integer_slopes = 0 - * for i_n in range(8): # <<<<<<<<<<<<<< - * compressed_integer_slopes |= (( - * 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":1856 - * for i_n in range(8): - * compressed_integer_slopes |= (( - * 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, 1856, __pyx_L1_error) - } - - /* "pygeoprocessing/routing/routing.pyx":1855 - * compressed_integer_slopes = 0 - * for i_n in range(8): - * compressed_integer_slopes |= (( # <<<<<<<<<<<<<< - * 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":1859 - * 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":1861 - * 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":1852 - * 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":1869 - * # 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_30.xi = __pyx_v_xi_root; - __pyx_t_30.yi = __pyx_v_yi_root; - __pyx_v_drain_search_queue.push(__pyx_t_30); - - /* "pygeoprocessing/routing/routing.pyx":1870 - * # 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":1875 - * # 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_5 = ((!(__pyx_v_drain_search_queue.empty() != 0)) != 0); - if (!__pyx_t_5) break; - - /* "pygeoprocessing/routing/routing.pyx":1876 - * # 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":1877 - * 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":1878 - * 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":1880 - * 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":1881 - * - * 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":1882 - * 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":1884 - * 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+D8_XOFFSET[i_n] - */ - (__pyx_v_downhill_slope_array[__pyx_v_i_n]) = 0.0; - - /* "pygeoprocessing/routing/routing.pyx":1885 - * # 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+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] - */ - (__pyx_v_nodata_downhill_slope_array[__pyx_v_i_n]) = 0.0; - - /* "pygeoprocessing/routing/routing.pyx":1886 - * downhill_slope_array[i_n] = 0.0 - * nodata_downhill_slope_array[i_n] = 0.0 - * xi_n = xi_q+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< - * yi_n = yi_q+D8_YOFFSET[i_n] - * - */ - __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":1887 - * nodata_downhill_slope_array[i_n] = 0.0 - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< - * - * if (xi_n < 0 or xi_n >= raster_x_size or - */ - __pyx_v_yi_n = (__pyx_v_yi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":1889 - * yi_n = yi_q+D8_YOFFSET[i_n] - * - * 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_6 = ((__pyx_v_xi_n < 0) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L44_bool_binop_done; - } - __pyx_t_6 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L44_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":1890 - * - * 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_6 = ((__pyx_v_yi_n < 0) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L44_bool_binop_done; - } - __pyx_t_6 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L44_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":1889 - * yi_n = yi_q+D8_YOFFSET[i_n] - * - * 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_5) { - - /* "pygeoprocessing/routing/routing.pyx":1891 - * 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":1889 - * yi_n = yi_q+D8_YOFFSET[i_n] - * - * 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":1893 - * n_height = dem_nodata - * else: - * n_height = dem_managed_raster.get(xi_n, yi_n) # <<<<<<<<<<<<<< - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): - * 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":1894 - * else: - * n_height = dem_managed_raster.get(xi_n, yi_n) - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * n_slope = SQRT2_INV if i_n & 1 else 1.0 - * sum_of_nodata_slope_weights += n_slope - */ - __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_n_height, __pyx_v_dem_nodata, 1e-8, 1e-5) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1895 - * n_height = dem_managed_raster.get(xi_n, yi_n) - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): - * 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_7 = __pyx_v_15pygeoprocessing_7routing_7routing_SQRT2_INV; - } else { - __pyx_t_7 = 1.0; - } - __pyx_v_n_slope = __pyx_t_7; - - /* "pygeoprocessing/routing/routing.pyx":1896 - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): - * 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":1897 - * 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":1898 - * 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":1894 - * else: - * n_height = dem_managed_raster.get(xi_n, yi_n) - * if _is_close(n_height, dem_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * n_slope = SQRT2_INV if i_n & 1 else 1.0 - * sum_of_nodata_slope_weights += n_slope - */ - } - - /* "pygeoprocessing/routing/routing.pyx":1899 - * 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":1900 - * continue - * n_slope = root_height - n_height - * if n_slope < 0: # <<<<<<<<<<<<<< - * continue - * if n_slope == 0.0: - */ - __pyx_t_5 = ((__pyx_v_n_slope < 0.0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1901 - * 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":1900 - * continue - * n_slope = root_height - n_height - * if n_slope < 0: # <<<<<<<<<<<<<< - * continue - * if n_slope == 0.0: - */ - } - - /* "pygeoprocessing/routing/routing.pyx":1902 - * 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_5 = ((__pyx_v_n_slope == 0.0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1904 - * 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_5 = ((__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":1903 - * 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_5) { - - /* "pygeoprocessing/routing/routing.pyx":1908 - * # previously visited - * drain_search_queue.push( - * CoordinateType(xi_n, yi_n)) # <<<<<<<<<<<<<< - * flat_region_mask_managed_raster.set( - * xi_n, yi_n, 1) - */ - __pyx_t_30.xi = __pyx_v_xi_n; - __pyx_t_30.yi = __pyx_v_yi_n; - - /* "pygeoprocessing/routing/routing.pyx":1907 - * # 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_30); - - /* "pygeoprocessing/routing/routing.pyx":1909 - * 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":1903 - * 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":1911 - * 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":1902 - * 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":1912 - * xi_n, yi_n, 1) - * continue - * if i_n & 1: # <<<<<<<<<<<<<< - * n_slope *= SQRT2_INV - * downhill_slope_array[i_n] = n_slope - */ - __pyx_t_5 = ((__pyx_v_i_n & 1) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1913 - * 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":1912 - * 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":1914 - * 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":1915 - * 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":1917 - * 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":1918 - * - * 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":1919 - * 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_5 = ((__pyx_v_sum_of_slope_weights > 0.0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1920 - * 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":1921 - * 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":1919 - * 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":1922 - * 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_5 = ((__pyx_v_sum_of_nodata_slope_weights > 0.0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1924 - * 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":1926 - * 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":1922 - * 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":1928 - * sum_of_nodata_slope_weights) - * - * if working_downhill_slope_sum > 0.0: # <<<<<<<<<<<<<< - * compressed_integer_slopes = 0 - * for i_n in range(8): - */ - __pyx_t_5 = ((__pyx_v_working_downhill_slope_sum > 0.0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1929 - * - * if working_downhill_slope_sum > 0.0: - * compressed_integer_slopes = 0 # <<<<<<<<<<<<<< - * for i_n in range(8): - * compressed_integer_slopes |= (( - */ - __pyx_v_compressed_integer_slopes = 0; - - /* "pygeoprocessing/routing/routing.pyx":1930 - * if working_downhill_slope_sum > 0.0: - * compressed_integer_slopes = 0 - * for i_n in range(8): # <<<<<<<<<<<<<< - * compressed_integer_slopes |= (( - * 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":1932 - * for i_n in range(8): - * compressed_integer_slopes |= (( - * 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, 1932, __pyx_L1_error) - } - - /* "pygeoprocessing/routing/routing.pyx":1931 - * compressed_integer_slopes = 0 - * for i_n in range(8): - * compressed_integer_slopes |= (( # <<<<<<<<<<<<<< - * 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":1935 - * 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_5 = ((__pyx_v_sum_of_slope_weights > 0.0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1937 - * 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":1939 - * 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":1941 - * 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":1944 - * xi_q, yi_q, 1) - * distance_drain_queue.push( - * CoordinateType(xi_q, yi_q)) # <<<<<<<<<<<<<< - * else: - * nodata_distance_drain_queue.push( - */ - __pyx_t_30.xi = __pyx_v_xi_q; - __pyx_t_30.yi = __pyx_v_yi_q; - - /* "pygeoprocessing/routing/routing.pyx":1943 - * 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_30); - - /* "pygeoprocessing/routing/routing.pyx":1935 - * 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":1946 - * 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":1947 - * else: - * nodata_distance_drain_queue.push( - * CoordinateType(xi_q, yi_q)) # <<<<<<<<<<<<<< - * nodata_flow_dir_queue.push( - * compressed_integer_slopes) - */ - __pyx_t_30.xi = __pyx_v_xi_q; - __pyx_t_30.yi = __pyx_v_yi_q; - - /* "pygeoprocessing/routing/routing.pyx":1946 - * 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_30); - - /* "pygeoprocessing/routing/routing.pyx":1948 - * 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":1928 - * 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":1952 - * - * # 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_5 = (__pyx_v_distance_drain_queue.empty() != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":1956 - * # 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_5 = ((!(__pyx_v_nodata_distance_drain_queue.empty() != 0)) != 0); - if (!__pyx_t_5) break; - - /* "pygeoprocessing/routing/routing.pyx":1957 - * # 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":1958 - * 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":1959 - * 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":1961 - * 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":1962 - * 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":1963 - * 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":1965 - * 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":1966 - * 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":1952 - * - * # 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":1969 - * else: - * # clear the nodata drain queues - * nodata_flow_dir_queue = IntQueueType() # <<<<<<<<<<<<<< - * nodata_distance_drain_queue = CoordinateQueueType() - * - */ - /*else*/ { - try { - __pyx_t_31 = __pyx_t_15pygeoprocessing_7routing_7routing_IntQueueType(); - } catch(...) { - __Pyx_CppExn2PyErr(); - __PYX_ERR(0, 1969, __pyx_L1_error) - } - __pyx_v_nodata_flow_dir_queue = __pyx_t_31; - - /* "pygeoprocessing/routing/routing.pyx":1970 - * # 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_32 = __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateQueueType(); - } catch(...) { - __Pyx_CppExn2PyErr(); - __PYX_ERR(0, 1970, __pyx_L1_error) - } - __pyx_v_nodata_distance_drain_queue = __pyx_t_32; - } - __pyx_L58:; - - /* "pygeoprocessing/routing/routing.pyx":1973 - * - * # copy the drain queue to another queue - * for _ in range(distance_drain_queue.size()): # <<<<<<<<<<<<<< - * distance_drain_queue.push( - * distance_drain_queue.front()) - */ - __pyx_t_33 = __pyx_v_distance_drain_queue.size(); - __pyx_t_34 = __pyx_t_33; - for (__pyx_t_35 = 0; __pyx_t_35 < __pyx_t_34; __pyx_t_35+=1) { - __pyx_v__ = __pyx_t_35; - - /* "pygeoprocessing/routing/routing.pyx":1974 - * # 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":1976 - * 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":1977 - * 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":1985 - * # 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_5 = ((!(__pyx_v_distance_drain_queue.empty() != 0)) != 0); - if (!__pyx_t_5) break; - - /* "pygeoprocessing/routing/routing.pyx":1986 - * # 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":1987 - * 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":1988 - * 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":1990 - * 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":1993 - * xi_q, yi_q) - * - * for i_n in range(8): # <<<<<<<<<<<<<< - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[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":1994 - * - * for i_n in range(8): - * xi_n = xi_q+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< - * yi_n = yi_q+D8_YOFFSET[i_n] - * if (xi_n < 0 or xi_n >= raster_x_size or - */ - __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":1995 - * for i_n in range(8): - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< - * 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_D8_YOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":1996 - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] - * if (xi_n < 0 or xi_n >= raster_x_size or # <<<<<<<<<<<<<< - * yi_n < 0 or yi_n >= raster_y_size): - * continue - */ - __pyx_t_6 = ((__pyx_v_xi_n < 0) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L68_bool_binop_done; - } - __pyx_t_6 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L68_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":1997 - * yi_n = yi_q+D8_YOFFSET[i_n] - * if (xi_n < 0 or xi_n >= raster_x_size or - * yi_n < 0 or yi_n >= raster_y_size): # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_6 = ((__pyx_v_yi_n < 0) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L68_bool_binop_done; - } - __pyx_t_6 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L68_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":1996 - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] - * 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":1998 - * 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":1996 - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] - * 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":2001 - * - * 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_7 = __pyx_v_15pygeoprocessing_7routing_7routing_SQRT2; - } else { - __pyx_t_7 = 1.0; - } - - /* "pygeoprocessing/routing/routing.pyx":2000 - * 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_7); - - /* "pygeoprocessing/routing/routing.pyx":2004 - * - * 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_6 = ((((double)__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) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L73_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":2006 - * 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_6 = ((__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_5 = __pyx_t_6; - __pyx_L73_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":2003 - * 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_5) { - - /* "pygeoprocessing/routing/routing.pyx":2009 - * # 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":2012 - * 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_30.xi = __pyx_v_xi_n; - __pyx_t_30.yi = __pyx_v_yi_n; - - /* "pygeoprocessing/routing/routing.pyx":2011 - * 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_30); - - /* "pygeoprocessing/routing/routing.pyx":2003 - * 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_L65_continue:; - } - } - - /* "pygeoprocessing/routing/routing.pyx":2016 - * # 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_5 = ((!(__pyx_v_direction_drain_queue.empty() != 0)) != 0); - if (!__pyx_t_5) break; - - /* "pygeoprocessing/routing/routing.pyx":2017 - * # 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":2018 - * 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":2019 - * 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":2021 - * 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":2024 - * xi_q, yi_q) - * - * sum_of_slope_weights = 0.0 # <<<<<<<<<<<<<< - * for i_n in range(8): - * xi_n = xi_q+D8_XOFFSET[i_n] - */ - __pyx_v_sum_of_slope_weights = 0.0; - - /* "pygeoprocessing/routing/routing.pyx":2025 - * - * sum_of_slope_weights = 0.0 - * for i_n in range(8): # <<<<<<<<<<<<<< - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[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":2026 - * sum_of_slope_weights = 0.0 - * for i_n in range(8): - * xi_n = xi_q+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< - * yi_n = yi_q+D8_YOFFSET[i_n] - * downhill_slope_array[i_n] = 0.0 - */ - __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":2027 - * for i_n in range(8): - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< - * downhill_slope_array[i_n] = 0.0 - * - */ - __pyx_v_yi_n = (__pyx_v_yi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":2028 - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] - * 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":2030 - * 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_6 = ((__pyx_v_xi_n < 0) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L80_bool_binop_done; - } - __pyx_t_6 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L80_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":2031 - * - * if (xi_n < 0 or xi_n >= raster_x_size or - * yi_n < 0 or yi_n >= raster_y_size): # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_6 = ((__pyx_v_yi_n < 0) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L80_bool_binop_done; - } - __pyx_t_6 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L80_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":2030 - * 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_5) { - - /* "pygeoprocessing/routing/routing.pyx":2032 - * 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":2030 - * 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":2034 - * continue - * - * if dem_managed_raster.get(xi_n, yi_n) != root_height: # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_5 = ((__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_5) { - - /* "pygeoprocessing/routing/routing.pyx":2035 - * - * 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":2034 - * continue - * - * if dem_managed_raster.get(xi_n, yi_n) != root_height: # <<<<<<<<<<<<<< - * continue - * - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2037 - * 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":2039 - * 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_5 = ((__pyx_v_n_distance == __pyx_v_plateau_distance_nodata) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":2040 - * 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":2039 - * 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":2041 - * 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_5 = ((__pyx_v_n_distance < __pyx_v_drain_distance) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":2042 - * 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_7 = __pyx_v_15pygeoprocessing_7routing_7routing_SQRT2_INV; - } else { - __pyx_t_7 = 1.0; - } - __pyx_v_n_slope = __pyx_t_7; - - /* "pygeoprocessing/routing/routing.pyx":2043 - * 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":2044 - * 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":2041 - * 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":2045 - * 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_5 = ((!(__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_5) { - - /* "pygeoprocessing/routing/routing.pyx":2048 - * 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_30.xi = __pyx_v_xi_n; - __pyx_t_30.yi = __pyx_v_yi_n; - - /* "pygeoprocessing/routing/routing.pyx":2047 - * 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_30); - - /* "pygeoprocessing/routing/routing.pyx":2049 - * 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":2045 - * 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":2052 - * xi_n, yi_n, 1) - * - * if sum_of_slope_weights == 0: # <<<<<<<<<<<<<< - * continue - * compressed_integer_slopes = 0 - */ - __pyx_t_5 = ((__pyx_v_sum_of_slope_weights == 0.0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":2053 - * - * 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":2052 - * xi_n, yi_n, 1) - * - * if sum_of_slope_weights == 0: # <<<<<<<<<<<<<< - * continue - * compressed_integer_slopes = 0 - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2054 - * if sum_of_slope_weights == 0: - * continue - * compressed_integer_slopes = 0 # <<<<<<<<<<<<<< - * for i_n in range(8): - * compressed_integer_slopes |= (( - */ - __pyx_v_compressed_integer_slopes = 0; - - /* "pygeoprocessing/routing/routing.pyx":2055 - * continue - * compressed_integer_slopes = 0 - * for i_n in range(8): # <<<<<<<<<<<<<< - * compressed_integer_slopes |= (( - * 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":2057 - * for i_n in range(8): - * compressed_integer_slopes |= (( - * 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, 2057, __pyx_L1_error) - } - - /* "pygeoprocessing/routing/routing.pyx":2056 - * compressed_integer_slopes = 0 - * for i_n in range(8): - * compressed_integer_slopes |= (( # <<<<<<<<<<<<<< - * 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":2059 - * 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":1782 - * - * # this outer loop searches for a pixel that is locally undrained - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * compatable_dem_raster_path_band, offset_only=True, - * largest_block=0): - */ - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2062 - * 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":2063 - * - * 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":2064 - * 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, 2064, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __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); - } - } - __pyx_t_3 = (__pyx_t_20) ? __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_20) : __Pyx_PyObject_CallNoArg(__pyx_t_15); - __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2064, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2065 - * 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, 2065, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __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); - } - } - __pyx_t_3 = (__pyx_t_20) ? __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_20) : __Pyx_PyObject_CallNoArg(__pyx_t_15); - __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2065, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2066 - * 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, 2066, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __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); - } - } - __pyx_t_3 = (__pyx_t_20) ? __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_20) : __Pyx_PyObject_CallNoArg(__pyx_t_15); - __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2066, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2067 - * 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, 2067, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __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); - } - } - __pyx_t_3 = (__pyx_t_20) ? __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_20) : __Pyx_PyObject_CallNoArg(__pyx_t_15); - __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2067, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2068 - * 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, 2068, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __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); - } - } - __pyx_t_3 = (__pyx_t_20) ? __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_20) : __Pyx_PyObject_CallNoArg(__pyx_t_15); - __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2068, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2069 - * dem_managed_raster.close() - * plateau_distance_managed_raster.close() - * shutil.rmtree(working_dir_path) # <<<<<<<<<<<<<< - * LOGGER.info('%.1f%% complete', 100.0) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_shutil); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2069, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_rmtree); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2069, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_15 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_20))) { - __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_20); - if (likely(__pyx_t_15)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_20); - __Pyx_INCREF(__pyx_t_15); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_20, function); - } - } - __pyx_t_3 = (__pyx_t_15) ? __Pyx_PyObject_Call2Args(__pyx_t_20, __pyx_t_15, __pyx_v_working_dir_path) : __Pyx_PyObject_CallOneArg(__pyx_t_20, __pyx_v_working_dir_path); - __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2069, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2070 - * plateau_distance_managed_raster.close() - * shutil.rmtree(working_dir_path) - * LOGGER.info('%.1f%% complete', 100.0) # <<<<<<<<<<<<<< - * - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2070, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_info); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2070, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_20, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2070, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1582 - * - * - * def flow_dir_mfd( # <<<<<<<<<<<<<< - * dem_raster_path_band, target_flow_dir_path, working_dir=None, - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_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_14); - __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_raster_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":2073 - * - * - * 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 (str): 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 raster_driver_creation_tuple (tuple): a tuple containing a GDAL driver\n name string as the first element and a GDAL creation options\n tuple/list as the second. Defaults to a GTiff driver tuple\n defined at geoprocessing.DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS.\n\n Returns:\n None.\n\n "; -static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_11flow_accumulation_mfd = {"flow_accumulation_mfd", (PyCFunction)(void*)(PyCFunctionWithKeywords)__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_raster_driver_creation_tuple = 0; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 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_raster_driver_creation_tuple,0}; - PyObject* values[4] = {0,0,0,0}; - - /* "pygeoprocessing/routing/routing.pyx":2075 - * def flow_accumulation_mfd( - * flow_dir_mfd_raster_path_band, target_flow_accum_raster_path, - * weight_raster_path_band=None, # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): - * """Multiple flow direction accumulation. - */ - values[2] = ((PyObject *)Py_None); - values[3] = __pyx_k__11; - 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, 2073, __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_raster_driver_creation_tuple); - 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, 2073, __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_raster_driver_creation_tuple = 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, 2073, __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_raster_driver_creation_tuple); - - /* "pygeoprocessing/routing/routing.pyx":2073 - * - * - * 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_raster_driver_creation_tuple) { - 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; - PY_LONG_LONG __pyx_v_visit_count; - PY_LONG_LONG __pyx_v_pixel_count; - 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 __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; - PyObject *__pyx_v_tmp_dir_root = NULL; - PyObject *__pyx_v_tmp_dir = NULL; - PyObject *__pyx_v_visited_raster_path = NULL; - struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_visited_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; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - 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; - int __pyx_t_30; - struct __pyx_t_15pygeoprocessing_7routing_7routing_FlowPixelType __pyx_t_31; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __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":2139 - * 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":2140 - * - * 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":2157 - * # 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":2159 - * 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_is_raster_path_band_formatted); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2159, __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); - } - } - __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_flow_dir_mfd_raster_path_band) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_flow_dir_mfd_raster_path_band); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2159, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __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, 2159, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_5 = ((!__pyx_t_4) != 0); - if (unlikely(__pyx_t_5)) { - - /* "pygeoprocessing/routing/routing.pyx":2161 - * 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_PyUnicode_FormatSafe(__pyx_kp_u_s_is_supposed_to_be_a_raster_ba, __pyx_v_flow_dir_mfd_raster_path_band); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2161, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":2160 - * - * 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, 2160, __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, 2160, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2159 - * 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":2163 - * "%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_4 = __Pyx_PyObject_IsTrue(__pyx_v_weight_raster_path_band); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2163, __pyx_L1_error) - if (__pyx_t_4) { - } else { - __pyx_t_5 = __pyx_t_4; - goto __pyx_L5_bool_binop_done; - } - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_is_raster_path_band_formatted); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2163, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":2164 - * 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_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); - } - } - __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_3, __pyx_v_weight_raster_path_band) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_weight_raster_path_band); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2163, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2163 - * "%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_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2163, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_6 = ((!__pyx_t_4) != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L5_bool_binop_done:; - if (unlikely(__pyx_t_5)) { - - /* "pygeoprocessing/routing/routing.pyx":2166 - * 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_PyUnicode_FormatSafe(__pyx_kp_u_s_is_supposed_to_be_a_raster_ba, __pyx_v_weight_raster_path_band); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2166, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - - /* "pygeoprocessing/routing/routing.pyx":2165 - * 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, 2165, __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, 2165, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2163 - * "%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":2169 - * weight_raster_path_band)) - * - * LOGGER.debug('creating target flow accum raster layer') # <<<<<<<<<<<<<< - * pygeoprocessing.new_raster_from_base( - * flow_dir_mfd_raster_path_band[0], target_flow_accum_raster_path, - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2169, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_debug); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2169, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - 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_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_kp_u_creating_target_flow_accum_raste) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_creating_target_flow_accum_raste); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2169, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2170 - * - * LOGGER.debug('creating target flow accum raster layer') - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * flow_dir_mfd_raster_path_band[0], target_flow_accum_raster_path, - * gdal.GDT_Float64, [flow_accum_nodata], - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2170, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2170, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2171 - * LOGGER.debug('creating target flow accum raster layer') - * pygeoprocessing.new_raster_from_base( - * flow_dir_mfd_raster_path_band[0], target_flow_accum_raster_path, # <<<<<<<<<<<<<< - * gdal.GDT_Float64, [flow_accum_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - */ - __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, 2171, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":2172 - * pygeoprocessing.new_raster_from_base( - * flow_dir_mfd_raster_path_band[0], target_flow_accum_raster_path, - * gdal.GDT_Float64, [flow_accum_nodata], # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2172, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2172, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyFloat_FromDouble(__pyx_v_flow_accum_nodata); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2172, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_8 = PyList_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2172, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_2); - PyList_SET_ITEM(__pyx_t_8, 0, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2170 - * - * LOGGER.debug('creating target flow accum raster layer') - * 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_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2170, __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_flow_accum_raster_path); - __Pyx_GIVEREF(__pyx_v_target_flow_accum_raster_path); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_target_flow_accum_raster_path); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_8); - __pyx_t_1 = 0; - __pyx_t_7 = 0; - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2173 - * flow_dir_mfd_raster_path_band[0], target_flow_accum_raster_path, - * gdal.GDT_Float64, [flow_accum_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< - * - * flow_accum_managed_raster = _ManagedRaster( - */ - __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2173, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 2173, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2170 - * - * LOGGER.debug('creating target flow accum raster layer') - * 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_7 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2170, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2175 - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * - * flow_accum_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< - * target_flow_accum_raster_path, 1, 1) - * - */ - __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2175, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_INCREF(__pyx_v_target_flow_accum_raster_path); - __Pyx_GIVEREF(__pyx_v_target_flow_accum_raster_path); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_target_flow_accum_raster_path); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_int_1); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_int_1); - __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2175, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 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":2179 - * - * # make a temporary raster to mark where we have visisted - * LOGGER.debug('creating visited raster layer') # <<<<<<<<<<<<<< - * tmp_dir_root = os.path.dirname(target_flow_accum_raster_path) - * tmp_dir = tempfile.mkdtemp(dir=tmp_dir_root, prefix='mfd_flow_dir_') - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2179, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_debug); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2179, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - 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_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_7, __pyx_kp_u_creating_visited_raster_layer) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_kp_u_creating_visited_raster_layer); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2179, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2180 - * # make a temporary raster to mark where we have visisted - * LOGGER.debug('creating visited raster layer') - * tmp_dir_root = os.path.dirname(target_flow_accum_raster_path) # <<<<<<<<<<<<<< - * tmp_dir = tempfile.mkdtemp(dir=tmp_dir_root, prefix='mfd_flow_dir_') - * visited_raster_path = os.path.join(tmp_dir, 'visited.tif') - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2180, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_path); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2180, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_dirname); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2180, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_7, __pyx_v_target_flow_accum_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_target_flow_accum_raster_path); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2180, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_tmp_dir_root = __pyx_t_8; - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2181 - * LOGGER.debug('creating visited raster layer') - * tmp_dir_root = os.path.dirname(target_flow_accum_raster_path) - * tmp_dir = tempfile.mkdtemp(dir=tmp_dir_root, prefix='mfd_flow_dir_') # <<<<<<<<<<<<<< - * visited_raster_path = os.path.join(tmp_dir, 'visited.tif') - * pygeoprocessing.new_raster_from_base( - */ - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_tempfile); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2181, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_mkdtemp); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2181, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2181, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_dir, __pyx_v_tmp_dir_root) < 0) __PYX_ERR(0, 2181, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_prefix, __pyx_n_u_mfd_flow_dir) < 0) __PYX_ERR(0, 2181, __pyx_L1_error) - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2181, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_tmp_dir = __pyx_t_7; - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2182 - * tmp_dir_root = os.path.dirname(target_flow_accum_raster_path) - * tmp_dir = tempfile.mkdtemp(dir=tmp_dir_root, prefix='mfd_flow_dir_') - * visited_raster_path = os.path.join(tmp_dir, 'visited.tif') # <<<<<<<<<<<<<< - * pygeoprocessing.new_raster_from_base( - * flow_dir_mfd_raster_path_band[0], visited_raster_path, - */ - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_os); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2182, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_path); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2182, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_join); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2182, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && likely(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_v_tmp_dir, __pyx_kp_u_visited_tif}; - __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2182, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_7); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_tmp_dir, __pyx_kp_u_visited_tif}; - __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2182, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_7); - } else - #endif - { - __pyx_t_3 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2182, __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_v_tmp_dir); - __Pyx_GIVEREF(__pyx_v_tmp_dir); - PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_9, __pyx_v_tmp_dir); - __Pyx_INCREF(__pyx_kp_u_visited_tif); - __Pyx_GIVEREF(__pyx_kp_u_visited_tif); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_9, __pyx_kp_u_visited_tif); - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_3, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2182, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_visited_raster_path = __pyx_t_7; - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2183 - * tmp_dir = tempfile.mkdtemp(dir=tmp_dir_root, prefix='mfd_flow_dir_') - * visited_raster_path = os.path.join(tmp_dir, 'visited.tif') - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * flow_dir_mfd_raster_path_band[0], visited_raster_path, - * gdal.GDT_Byte, [0], - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2183, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2183, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2184 - * visited_raster_path = os.path.join(tmp_dir, 'visited.tif') - * pygeoprocessing.new_raster_from_base( - * flow_dir_mfd_raster_path_band[0], visited_raster_path, # <<<<<<<<<<<<<< - * gdal.GDT_Byte, [0], - * raster_driver_creation_tuple=('GTiff', ( - */ - __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2184, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - - /* "pygeoprocessing/routing/routing.pyx":2185 - * pygeoprocessing.new_raster_from_base( - * flow_dir_mfd_raster_path_band[0], visited_raster_path, - * gdal.GDT_Byte, [0], # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=('GTiff', ( - * 'SPARSE_OK=TRUE', 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2185, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2185, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2185, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyList_SET_ITEM(__pyx_t_3, 0, __pyx_int_0); - - /* "pygeoprocessing/routing/routing.pyx":2183 - * tmp_dir = tempfile.mkdtemp(dir=tmp_dir_root, prefix='mfd_flow_dir_') - * visited_raster_path = os.path.join(tmp_dir, 'visited.tif') - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * flow_dir_mfd_raster_path_band[0], visited_raster_path, - * gdal.GDT_Byte, [0], - */ - __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2183, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7); - __Pyx_INCREF(__pyx_v_visited_raster_path); - __Pyx_GIVEREF(__pyx_v_visited_raster_path); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_visited_raster_path); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_3); - __pyx_t_7 = 0; - __pyx_t_2 = 0; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2186 - * flow_dir_mfd_raster_path_band[0], visited_raster_path, - * gdal.GDT_Byte, [0], - * raster_driver_creation_tuple=('GTiff', ( # <<<<<<<<<<<<<< - * 'SPARSE_OK=TRUE', 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', - * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), - */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pygeoprocessing/routing/routing.pyx":2188 - * raster_driver_creation_tuple=('GTiff', ( - * 'SPARSE_OK=TRUE', 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', - * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), # <<<<<<<<<<<<<< - * 'BLOCKYSIZE=%d' % (1 << BLOCK_BITS)))) - * visited_managed_raster = _ManagedRaster(visited_raster_path, 1, 1) - */ - __pyx_t_2 = __Pyx_PyInt_From_long((1 << __pyx_v_15pygeoprocessing_7routing_7routing_BLOCK_BITS)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2188, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = PyUnicode_Format(__pyx_kp_u_BLOCKXSIZE_d, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2188, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2189 - * 'SPARSE_OK=TRUE', 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', - * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), - * 'BLOCKYSIZE=%d' % (1 << BLOCK_BITS)))) # <<<<<<<<<<<<<< - * visited_managed_raster = _ManagedRaster(visited_raster_path, 1, 1) - * - */ - __pyx_t_2 = __Pyx_PyInt_From_long((1 << __pyx_v_15pygeoprocessing_7routing_7routing_BLOCK_BITS)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2189, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_10 = PyUnicode_Format(__pyx_kp_u_BLOCKYSIZE_d, __pyx_t_2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2189, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2187 - * gdal.GDT_Byte, [0], - * raster_driver_creation_tuple=('GTiff', ( - * 'SPARSE_OK=TRUE', 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', # <<<<<<<<<<<<<< - * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), - * 'BLOCKYSIZE=%d' % (1 << BLOCK_BITS)))) - */ - __pyx_t_2 = PyTuple_New(6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2187, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_kp_u_SPARSE_OK_TRUE); - __Pyx_GIVEREF(__pyx_kp_u_SPARSE_OK_TRUE); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_u_SPARSE_OK_TRUE); - __Pyx_INCREF(__pyx_kp_u_TILED_YES); - __Pyx_GIVEREF(__pyx_kp_u_TILED_YES); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_kp_u_TILED_YES); - __Pyx_INCREF(__pyx_kp_u_BIGTIFF_YES); - __Pyx_GIVEREF(__pyx_kp_u_BIGTIFF_YES); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_kp_u_BIGTIFF_YES); - __Pyx_INCREF(__pyx_kp_u_COMPRESS_LZW); - __Pyx_GIVEREF(__pyx_kp_u_COMPRESS_LZW); - PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_kp_u_COMPRESS_LZW); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_2, 4, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_2, 5, __pyx_t_10); - __pyx_t_7 = 0; - __pyx_t_10 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2186 - * flow_dir_mfd_raster_path_band[0], visited_raster_path, - * gdal.GDT_Byte, [0], - * raster_driver_creation_tuple=('GTiff', ( # <<<<<<<<<<<<<< - * 'SPARSE_OK=TRUE', 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', - * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), - */ - __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(__pyx_n_u_GTiff); - __Pyx_GIVEREF(__pyx_n_u_GTiff); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_n_u_GTiff); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_2); - __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_raster_driver_creation_tuple, __pyx_t_10) < 0) __PYX_ERR(0, 2186, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2183 - * tmp_dir = tempfile.mkdtemp(dir=tmp_dir_root, prefix='mfd_flow_dir_') - * visited_raster_path = os.path.join(tmp_dir, 'visited.tif') - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * flow_dir_mfd_raster_path_band[0], visited_raster_path, - * gdal.GDT_Byte, [0], - */ - __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2183, __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_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2190 - * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), - * 'BLOCKYSIZE=%d' % (1 << BLOCK_BITS)))) - * visited_managed_raster = _ManagedRaster(visited_raster_path, 1, 1) # <<<<<<<<<<<<<< - * - * flow_dir_managed_raster = _ManagedRaster( - */ - __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2190, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(__pyx_v_visited_raster_path); - __Pyx_GIVEREF(__pyx_v_visited_raster_path); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_visited_raster_path); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_int_1); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_int_1); - __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2190, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_v_visited_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2193 - * - * 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_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, 2193, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __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, 2193, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - - /* "pygeoprocessing/routing/routing.pyx":2192 - * visited_managed_raster = _ManagedRaster(visited_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_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2192, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_10); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_int_0); - __pyx_t_3 = 0; - __pyx_t_10 = 0; - __pyx_t_10 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_1, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2192, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_flow_dir_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_10); - __pyx_t_10 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2194 - * 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_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2194, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2194, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2195 - * 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_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, 2195, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_gdal); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2195, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2195, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_1, __pyx_t_2}; - __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2194, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __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[3] = {__pyx_t_8, __pyx_t_1, __pyx_t_2}; - __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2194, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2194, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_8) { - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8); __pyx_t_8 = NULL; - } - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_9, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_9, __pyx_t_2); - __pyx_t_1 = 0; - __pyx_t_2 = 0; - __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2194, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_flow_dir_raster = __pyx_t_10; - __pyx_t_10 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2196 - * 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_PyObject_GetAttrStr(__pyx_v_flow_dir_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2196, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pygeoprocessing/routing/routing.pyx":2197 - * 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_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, 2197, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_10 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_7); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2196, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_flow_dir_band = __pyx_t_10; - __pyx_t_10 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2199 - * 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":2200 - * - * 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_5 = __Pyx_PyObject_IsTrue(__pyx_v_weight_raster_path_band); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2200, __pyx_L1_error) - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":2202 - * 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_10 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2202, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2202, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pygeoprocessing/routing/routing.pyx":2201 - * 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_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2201, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_3); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_int_0); - __pyx_t_10 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2201, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF_SET(__pyx_v_weight_raster, ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_3)); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2203 - * 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_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2203, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2203, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2204 - * 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_7 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2204, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __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); - } - } - __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_2, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_7); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2203, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = __Pyx_PyObject_Dict_GetItem(__pyx_t_3, __pyx_n_u_nodata); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2204, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2205 - * 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_3 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2205, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = __Pyx_PyInt_SubtractObjC(__pyx_t_3, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2205, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2204 - * 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_PyObject_GetItem(__pyx_t_10, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2204, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_raw_weight_nodata = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2206 - * 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_5 = (__pyx_v_raw_weight_nodata != Py_None); - __pyx_t_6 = (__pyx_t_5 != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/routing/routing.pyx":2207 - * 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, 2207, __pyx_L1_error) - __pyx_v_weight_nodata = __pyx_t_11; - - /* "pygeoprocessing/routing/routing.pyx":2206 - * 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":2200 - * - * 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":2209 - * 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_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2209, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2209, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2210 - * - * 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'] - * pixel_count = raster_x_size * raster_y_size - */ - __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2210, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __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); - } - } - __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_2, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_7); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2209, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_v_flow_dir_raster_info = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2211 - * 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'] # <<<<<<<<<<<<<< - * pixel_count = raster_x_size * raster_y_size - * visit_count = 0 - */ - __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_raster_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2211, __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, 2211, __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_7 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_10 = PyList_GET_ITEM(sequence, 0); - __pyx_t_7 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(__pyx_t_7); - #else - __pyx_t_10 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2211, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2211, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - #endif - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2211, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_12 = Py_TYPE(__pyx_t_2)->tp_iternext; - index = 0; __pyx_t_10 = __pyx_t_12(__pyx_t_2); if (unlikely(!__pyx_t_10)) goto __pyx_L9_unpacking_failed; - __Pyx_GOTREF(__pyx_t_10); - index = 1; __pyx_t_7 = __pyx_t_12(__pyx_t_2); if (unlikely(!__pyx_t_7)) goto __pyx_L9_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_2), 2) < 0) __PYX_ERR(0, 2211, __pyx_L1_error) - __pyx_t_12 = NULL; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L10_unpacking_done; - __pyx_L9_unpacking_failed:; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_12 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 2211, __pyx_L1_error) - __pyx_L10_unpacking_done:; - } - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_10); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2211, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2211, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_raster_x_size = __pyx_t_9; - __pyx_v_raster_y_size = __pyx_t_13; - - /* "pygeoprocessing/routing/routing.pyx":2212 - * flow_dir_mfd_raster_path_band[0]) - * raster_x_size, raster_y_size = flow_dir_raster_info['raster_size'] - * pixel_count = raster_x_size * raster_y_size # <<<<<<<<<<<<<< - * visit_count = 0 - * - */ - __pyx_v_pixel_count = (__pyx_v_raster_x_size * __pyx_v_raster_y_size); - - /* "pygeoprocessing/routing/routing.pyx":2213 - * raster_x_size, raster_y_size = flow_dir_raster_info['raster_size'] - * pixel_count = raster_x_size * raster_y_size - * visit_count = 0 # <<<<<<<<<<<<<< - * - * LOGGER.debug('starting search') - */ - __pyx_v_visit_count = 0; - - /* "pygeoprocessing/routing/routing.pyx":2215 - * visit_count = 0 - * - * LOGGER.debug('starting search') # <<<<<<<<<<<<<< - * # this outer loop searches for a pixel that is locally undrained - * for offset_dict in pygeoprocessing.iterblocks( - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2215, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_debug); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2215, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_10); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_10, function); - } - } - __pyx_t_3 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_7, __pyx_kp_u_starting_search) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_kp_u_starting_search); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2215, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2217 - * LOGGER.debug('starting search') - * # this outer loop searches for a pixel that is locally undrained - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * flow_dir_mfd_raster_path_band, offset_only=True, - * largest_block=0): - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2217, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2217, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2218 - * # this outer loop searches for a pixel that is locally undrained - * for offset_dict in pygeoprocessing.iterblocks( - * flow_dir_mfd_raster_path_band, offset_only=True, # <<<<<<<<<<<<<< - * largest_block=0): - * win_xsize = offset_dict['win_xsize'] - */ - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2217, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __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_3, 0, __pyx_v_flow_dir_mfd_raster_path_band); - __pyx_t_7 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2218, __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, 2218, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_largest_block, __pyx_int_0) < 0) __PYX_ERR(0, 2218, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2217 - * LOGGER.debug('starting search') - * # this outer loop searches for a pixel that is locally undrained - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * flow_dir_mfd_raster_path_band, offset_only=True, - * largest_block=0): - */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_3, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2217, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { - __pyx_t_7 = __pyx_t_2; __Pyx_INCREF(__pyx_t_7); __pyx_t_14 = 0; - __pyx_t_15 = NULL; - } else { - __pyx_t_14 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2217, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_15 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2217, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - for (;;) { - if (likely(!__pyx_t_15)) { - if (likely(PyList_CheckExact(__pyx_t_7))) { - if (__pyx_t_14 >= PyList_GET_SIZE(__pyx_t_7)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_14); __Pyx_INCREF(__pyx_t_2); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 2217, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_7, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2217, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } else { - if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_7)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_14); __Pyx_INCREF(__pyx_t_2); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 2217, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_7, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2217, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } - } else { - __pyx_t_2 = __pyx_t_15(__pyx_t_7); - if (unlikely(!__pyx_t_2)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 2217, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XDECREF_SET(__pyx_v_offset_dict, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2220 - * flow_dir_mfd_raster_path_band, offset_only=True, - * largest_block=0): - * win_xsize = offset_dict['win_xsize'] # <<<<<<<<<<<<<< - * win_ysize = offset_dict['win_ysize'] - * xoff = offset_dict['xoff'] - */ - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2220, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2220, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_win_xsize = __pyx_t_13; - - /* "pygeoprocessing/routing/routing.pyx":2221 - * 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_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2221, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2221, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_win_ysize = __pyx_t_13; - - /* "pygeoprocessing/routing/routing.pyx":2222 - * win_xsize = offset_dict['win_xsize'] - * win_ysize = offset_dict['win_ysize'] - * xoff = offset_dict['xoff'] # <<<<<<<<<<<<<< - * yoff = offset_dict['yoff'] - * - */ - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_xoff); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2222, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2222, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_xoff = __pyx_t_13; - - /* "pygeoprocessing/routing/routing.pyx":2223 - * win_ysize = offset_dict['win_ysize'] - * xoff = offset_dict['xoff'] - * yoff = offset_dict['yoff'] # <<<<<<<<<<<<<< - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - */ - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_yoff); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2223, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2223, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_yoff = __pyx_t_13; - - /* "pygeoprocessing/routing/routing.pyx":2225 - * yoff = offset_dict['yoff'] - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - */ - __pyx_t_6 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/routing/routing.pyx":2226 - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( - */ - __pyx_v_last_log_time = time(NULL); - - /* "pygeoprocessing/routing/routing.pyx":2227 - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size # <<<<<<<<<<<<<< - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( - * raster_x_size * raster_y_size)) - */ - __pyx_t_2 = __Pyx_PyInt_From_int((__pyx_v_xoff + (__pyx_v_yoff * __pyx_v_raster_x_size))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2227, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_XDECREF_SET(__pyx_v_current_pixel, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2228 - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< - * raster_x_size * raster_y_size)) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2228, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_info); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2228, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Multiply(__pyx_float_100_0, __pyx_v_current_pixel); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2228, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pygeoprocessing/routing/routing.pyx":2229 - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( - * 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, 2228, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":2228 - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< - * raster_x_size * raster_y_size)) - * - */ - __pyx_t_8 = __Pyx_PyNumber_Divide(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2228, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - __pyx_t_13 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_10); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); - __Pyx_INCREF(__pyx_t_1); - __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_1, __pyx_kp_u_1f_complete, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2228, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_kp_u_1f_complete, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2228, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - { - __pyx_t_3 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2228, __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_INCREF(__pyx_kp_u_1f_complete); - __Pyx_GIVEREF(__pyx_kp_u_1f_complete); - PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_13, __pyx_kp_u_1f_complete); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_13, __pyx_t_8); - __pyx_t_8 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2228, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2225 - * yoff = offset_dict['yoff'] - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2232 - * - * # 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2232, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2232, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2233 - * # 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_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2233, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2233, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2233, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_8 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2233, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2233, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_8); - __pyx_t_3 = 0; - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2232 - * - * # 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_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2232, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2234 - * 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_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2234, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2234, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2234, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 2234, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2232 - * - * # 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_1 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_8, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2232, __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_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, 2232, __pyx_L1_error) - __pyx_t_16 = ((PyArrayObject *)__pyx_t_1); - { - __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, 2232, __pyx_L1_error) - } - __pyx_t_16 = 0; - __Pyx_XDECREF_SET(__pyx_v_flow_dir_mfd_buffer_array, ((PyArrayObject *)__pyx_t_1)); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2235 - * (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__7, __pyx_int_0) < 0)) __PYX_ERR(0, 2235, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2239 - * # 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_generate_read_bounds); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2239, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - - /* "pygeoprocessing/routing/routing.pyx":2240 - * # 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_8 = __Pyx_PyInt_From_int(__pyx_v_raster_x_size); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2240, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_10 = __Pyx_PyInt_From_int(__pyx_v_raster_y_size); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2240, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_3 = NULL; - __pyx_t_13 = 0; - 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); - __pyx_t_13 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_offset_dict, __pyx_t_8, __pyx_t_10}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_13, 3+__pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2239, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_offset_dict, __pyx_t_8, __pyx_t_10}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_13, 3+__pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2239, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 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, 2239, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_3); __pyx_t_3 = 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_8); - PyTuple_SET_ITEM(__pyx_t_20, 1+__pyx_t_13, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_20, 2+__pyx_t_13, __pyx_t_10); - __pyx_t_8 = 0; - __pyx_t_10 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_20, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2239, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 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, 2239, __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_20 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_2 = PyList_GET_ITEM(sequence, 0); - __pyx_t_20 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_20); - #else - __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2239, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_20 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2239, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - #endif - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_10 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2239, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_12 = Py_TYPE(__pyx_t_10)->tp_iternext; - index = 0; __pyx_t_2 = __pyx_t_12(__pyx_t_10); if (unlikely(!__pyx_t_2)) goto __pyx_L14_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - 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, 2239, __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, 2239, __pyx_L1_error) - __pyx_L15_unpacking_done:; - } - - /* "pygeoprocessing/routing/routing.pyx":2239 - * # 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_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, 2239, __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_8 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 2); - __pyx_t_21 = PyTuple_GET_ITEM(sequence, 3); - } else { - __pyx_t_10 = PyList_GET_ITEM(sequence, 0); - __pyx_t_8 = PyList_GET_ITEM(sequence, 1); - __pyx_t_3 = PyList_GET_ITEM(sequence, 2); - __pyx_t_21 = PyList_GET_ITEM(sequence, 3); - } - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_21); - #else - { - Py_ssize_t i; - PyObject** temps[4] = {&__pyx_t_10,&__pyx_t_8,&__pyx_t_3,&__pyx_t_21}; - for (i=0; i < 4; i++) { - PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 2239, __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_10,&__pyx_t_8,&__pyx_t_3,&__pyx_t_21}; - __pyx_t_22 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2239, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_22); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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, 2239, __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, 2239, __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_8); - __pyx_t_8 = 0; - __Pyx_XDECREF_SET(__pyx_v_ya, __pyx_t_3); - __pyx_t_3 = 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":2241 - * (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, 2241, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - - /* "pygeoprocessing/routing/routing.pyx":2242 - * 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, 2242, __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, 2242, __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, 2241, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - } - - /* "pygeoprocessing/routing/routing.pyx":2241 - * (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_2); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2241, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_21); - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2242 - * 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_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_21, __pyx_n_s_astype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2242, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_21, __pyx_n_s_numpy); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2242, __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, 2242, __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_2))) { - __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_21)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_21); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_1 = (__pyx_t_21) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_21, __pyx_t_20) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_20); - __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2242, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2241 - * (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 = PySlice_New(__pyx_v_ya, __pyx_v_yb, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2241, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_20 = PySlice_New(__pyx_v_xa, __pyx_v_xb, Py_None); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2241, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __pyx_t_21 = PyTuple_New(2); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2241, __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_20); - PyTuple_SET_ITEM(__pyx_t_21, 1, __pyx_t_20); - __pyx_t_2 = 0; - __pyx_t_20 = 0; - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_mfd_buffer_array), __pyx_t_21, __pyx_t_1) < 0)) __PYX_ERR(0, 2241, __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":2245 - * - * # ensure these are set for the complier - * xi_n = -1 # <<<<<<<<<<<<<< - * yi_n = -1 - * - */ - __pyx_v_xi_n = -1; - - /* "pygeoprocessing/routing/routing.pyx":2246 - * # 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":2249 - * - * # 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":2250 - * # 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":2251 - * 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, 2251, __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":2252 - * 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_6 = ((__pyx_v_flow_dir_mfd == 0) != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/routing/routing.pyx":2254 - * 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":2252 - * 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":2256 - * 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":2257 - * - * for i_n in range(8): - * if ((flow_dir_mfd >> (i_n * 4)) & 0xF) == 0: # <<<<<<<<<<<<<< - * # no flow in that direction - * continue - */ - __pyx_t_6 = ((((__pyx_v_flow_dir_mfd >> (__pyx_v_i_n * 4)) & 0xF) == 0) != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/routing/routing.pyx":2259 - * if ((flow_dir_mfd >> (i_n * 4)) & 0xF) == 0: - * # no flow in that direction - * continue # <<<<<<<<<<<<<< - * xi_n = xi+D8_XOFFSET[i_n] - * yi_n = yi+D8_YOFFSET[i_n] - */ - goto __pyx_L23_continue; - - /* "pygeoprocessing/routing/routing.pyx":2257 - * - * 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":2260 - * # no flow in that direction - * continue - * xi_n = xi+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< - * yi_n = yi+D8_YOFFSET[i_n] - * - */ - __pyx_v_xi_n = (__pyx_v_xi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":2261 - * continue - * xi_n = xi+D8_XOFFSET[i_n] - * yi_n = yi+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< - * - * if flow_dir_mfd_buffer_array[yi_n, xi_n] == 0: - */ - __pyx_v_yi_n = (__pyx_v_yi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":2263 - * yi_n = yi+D8_YOFFSET[i_n] - * - * 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_28 = __pyx_v_yi_n; - __pyx_t_27 = __pyx_v_xi_n; - __pyx_t_30 = -1; - if (__pyx_t_28 < 0) { - __pyx_t_28 += __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[0].shape; - if (unlikely(__pyx_t_28 < 0)) __pyx_t_30 = 0; - } else if (unlikely(__pyx_t_28 >= __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[0].shape)) __pyx_t_30 = 0; - if (__pyx_t_27 < 0) { - __pyx_t_27 += __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[1].shape; - if (unlikely(__pyx_t_27 < 0)) __pyx_t_30 = 1; - } else if (unlikely(__pyx_t_27 >= __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[1].shape)) __pyx_t_30 = 1; - if (unlikely(__pyx_t_30 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_30); - __PYX_ERR(0, 2263, __pyx_L1_error) - } - __pyx_t_6 = (((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_flow_dir_mfd_buffer_array.rcbuffer->pybuffer.buf, __pyx_t_28, __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[0].strides, __pyx_t_27, __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[1].strides)) == 0) != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/routing/routing.pyx":2267 - * # 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":2268 - * # root must be a drain - * xi_root = xi-1+xoff - * yi_root = yi-1+yoff # <<<<<<<<<<<<<< - * if weight_raster is not None: - * weight_val = weight_raster.get( - */ - __pyx_v_yi_root = ((__pyx_v_yi - 1) + __pyx_v_yoff); - - /* "pygeoprocessing/routing/routing.pyx":2269 - * xi_root = xi-1+xoff - * yi_root = yi-1+yoff - * if weight_raster is not None: # <<<<<<<<<<<<<< - * weight_val = weight_raster.get( - * xi_root, yi_root) - */ - __pyx_t_6 = (((PyObject *)__pyx_v_weight_raster) != Py_None); - __pyx_t_5 = (__pyx_t_6 != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":2270 - * yi_root = yi-1+yoff - * if weight_raster is not None: - * weight_val = weight_raster.get( # <<<<<<<<<<<<<< - * xi_root, yi_root) - * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): - */ - __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":2272 - * weight_val = weight_raster.get( - * xi_root, yi_root) - * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * weight_val = 0.0 - * else: - */ - __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_weight_val, __pyx_v_weight_nodata, 1e-8, 1e-5) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":2273 - * xi_root, yi_root) - * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): - * weight_val = 0.0 # <<<<<<<<<<<<<< - * else: - * weight_val = 1.0 - */ - __pyx_v_weight_val = 0.0; - - /* "pygeoprocessing/routing/routing.pyx":2272 - * weight_val = weight_raster.get( - * xi_root, yi_root) - * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * weight_val = 0.0 - * else: - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2269 - * xi_root = xi-1+xoff - * yi_root = yi-1+yoff - * if weight_raster is not None: # <<<<<<<<<<<<<< - * weight_val = weight_raster.get( - * xi_root, yi_root) - */ - goto __pyx_L27; - } - - /* "pygeoprocessing/routing/routing.pyx":2275 - * 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":2277 - * weight_val = 1.0 - * search_stack.push( - * FlowPixelType(xi_root, yi_root, 0, weight_val)) # <<<<<<<<<<<<<< - * visited_managed_raster.set(xi_root, yi_root, 1) - * visit_count += 1 - */ - __pyx_t_31.xi = __pyx_v_xi_root; - __pyx_t_31.yi = __pyx_v_yi_root; - __pyx_t_31.last_flow_dir = 0; - __pyx_t_31.value = __pyx_v_weight_val; - - /* "pygeoprocessing/routing/routing.pyx":2276 - * else: - * weight_val = 1.0 - * search_stack.push( # <<<<<<<<<<<<<< - * FlowPixelType(xi_root, yi_root, 0, weight_val)) - * visited_managed_raster.set(xi_root, yi_root, 1) - */ - __pyx_v_search_stack.push(__pyx_t_31); - - /* "pygeoprocessing/routing/routing.pyx":2278 - * search_stack.push( - * FlowPixelType(xi_root, yi_root, 0, weight_val)) - * visited_managed_raster.set(xi_root, yi_root, 1) # <<<<<<<<<<<<<< - * visit_count += 1 - * break - */ - __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_visited_managed_raster, __pyx_v_xi_root, __pyx_v_yi_root, 1.0); - - /* "pygeoprocessing/routing/routing.pyx":2279 - * FlowPixelType(xi_root, yi_root, 0, weight_val)) - * visited_managed_raster.set(xi_root, yi_root, 1) - * visit_count += 1 # <<<<<<<<<<<<<< - * break - * - */ - __pyx_v_visit_count = (__pyx_v_visit_count + 1); - - /* "pygeoprocessing/routing/routing.pyx":2280 - * visited_managed_raster.set(xi_root, yi_root, 1) - * visit_count += 1 - * break # <<<<<<<<<<<<<< - * - * while not search_stack.empty(): - */ - goto __pyx_L24_break; - - /* "pygeoprocessing/routing/routing.pyx":2263 - * yi_n = yi+D8_YOFFSET[i_n] - * - * 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":2282 - * break - * - * while not search_stack.empty(): # <<<<<<<<<<<<<< - * flow_pixel = search_stack.top() - * search_stack.pop() - */ - while (1) { - __pyx_t_5 = ((!(__pyx_v_search_stack.empty() != 0)) != 0); - if (!__pyx_t_5) break; - - /* "pygeoprocessing/routing/routing.pyx":2283 - * - * 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":2284 - * while not search_stack.empty(): - * flow_pixel = search_stack.top() - * search_stack.pop() # <<<<<<<<<<<<<< - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - */ - __pyx_v_search_stack.pop(); - - /* "pygeoprocessing/routing/routing.pyx":2286 - * search_stack.pop() - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * LOGGER.info( - */ - __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":2287 - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< - * LOGGER.info( - * 'mfd flow accum %.1f%% complete', - */ - __pyx_v_last_log_time = time(NULL); - - /* "pygeoprocessing/routing/routing.pyx":2288 - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * last_log_time = ctime(NULL) - * LOGGER.info( # <<<<<<<<<<<<<< - * 'mfd flow accum %.1f%% complete', - * 100.0 * visit_count / float(pixel_count)) - */ - __Pyx_GetModuleGlobalName(__pyx_t_21, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2288, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_21); - __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_21, __pyx_n_s_info); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2288, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2290 - * LOGGER.info( - * 'mfd flow accum %.1f%% complete', - * 100.0 * visit_count / float(pixel_count)) # <<<<<<<<<<<<<< - * - * preempted = 0 - */ - __pyx_t_11 = (100.0 * __pyx_v_visit_count); - if (unlikely(((double)__pyx_v_pixel_count) == 0)) { - PyErr_SetString(PyExc_ZeroDivisionError, "float division"); - __PYX_ERR(0, 2290, __pyx_L1_error) - } - __pyx_t_21 = PyFloat_FromDouble((__pyx_t_11 / ((double)__pyx_v_pixel_count))); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2290, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_21); - __pyx_t_2 = NULL; - __pyx_t_29 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_20))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_20); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_20); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_20, function); - __pyx_t_29 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_20)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_kp_u_mfd_flow_accum_1f_complete, __pyx_t_21}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_20, __pyx_temp+1-__pyx_t_29, 2+__pyx_t_29); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2288, __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_20)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_kp_u_mfd_flow_accum_1f_complete, __pyx_t_21}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_20, __pyx_temp+1-__pyx_t_29, 2+__pyx_t_29); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2288, __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_3 = PyTuple_New(2+__pyx_t_29); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2288, __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_u_mfd_flow_accum_1f_complete); - __Pyx_GIVEREF(__pyx_kp_u_mfd_flow_accum_1f_complete); - PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_29, __pyx_kp_u_mfd_flow_accum_1f_complete); - __Pyx_GIVEREF(__pyx_t_21); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_29, __pyx_t_21); - __pyx_t_21 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_20, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2288, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2286 - * search_stack.pop() - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * LOGGER.info( - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2292 - * 100.0 * visit_count / float(pixel_count)) - * - * preempted = 0 # <<<<<<<<<<<<<< - * for i_n in range(flow_pixel.last_flow_dir, 8): - * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] - */ - __pyx_v_preempted = 0; - - /* "pygeoprocessing/routing/routing.pyx":2293 - * - * preempted = 0 - * for i_n in range(flow_pixel.last_flow_dir, 8): # <<<<<<<<<<<<<< - * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] - * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] - */ - 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":2294 - * preempted = 0 - * for i_n in range(flow_pixel.last_flow_dir, 8): - * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< - * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] - * 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_D8_XOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":2295 - * for i_n in range(flow_pixel.last_flow_dir, 8): - * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] - * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< - * 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_D8_YOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":2296 - * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] - * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] - * 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_5 = __pyx_t_6; - goto __pyx_L35_bool_binop_done; - } - __pyx_t_6 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L35_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":2297 - * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] - * 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_5 = __pyx_t_6; - goto __pyx_L35_bool_binop_done; - } - __pyx_t_6 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L35_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":2296 - * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] - * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] - * 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_5) { - - /* "pygeoprocessing/routing/routing.pyx":2299 - * yi_n < 0 or yi_n >= raster_y_size): - * # no upstream here - * continue # <<<<<<<<<<<<<< - * compressed_upstream_flow_dir = ( - * flow_dir_managed_raster.get(xi_n, yi_n)) - */ - goto __pyx_L32_continue; - - /* "pygeoprocessing/routing/routing.pyx":2296 - * xi_n = flow_pixel.xi+D8_XOFFSET[i_n] - * yi_n = flow_pixel.yi+D8_YOFFSET[i_n] - * 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":2301 - * continue - * compressed_upstream_flow_dir = ( - * 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":2304 - * 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":2305 - * 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_5 = ((__pyx_v_upstream_flow_weight == 0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":2307 - * 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_L32_continue; - - /* "pygeoprocessing/routing/routing.pyx":2305 - * 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":2309 - * continue - * upstream_flow_accum = ( - * flow_accum_managed_raster.get(xi_n, yi_n)) # <<<<<<<<<<<<<< - * if (_is_close(upstream_flow_accum, flow_accum_nodata, 1e-8, 1e-5) - * and not visited_managed_raster.get( - */ - __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":2310 - * upstream_flow_accum = ( - * flow_accum_managed_raster.get(xi_n, yi_n)) - * if (_is_close(upstream_flow_accum, flow_accum_nodata, 1e-8, 1e-5) # <<<<<<<<<<<<<< - * and not visited_managed_raster.get( - * xi_n, yi_n)): - */ - __pyx_t_6 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_upstream_flow_accum, __pyx_v_flow_accum_nodata, 1e-8, 1e-5) != 0); - if (__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L41_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":2311 - * flow_accum_managed_raster.get(xi_n, yi_n)) - * if (_is_close(upstream_flow_accum, flow_accum_nodata, 1e-8, 1e-5) - * and not visited_managed_raster.get( # <<<<<<<<<<<<<< - * xi_n, yi_n)): - * # process upstream before this one - */ - __pyx_t_6 = ((!(__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_visited_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n) != 0)) != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L41_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":2310 - * upstream_flow_accum = ( - * flow_accum_managed_raster.get(xi_n, yi_n)) - * if (_is_close(upstream_flow_accum, flow_accum_nodata, 1e-8, 1e-5) # <<<<<<<<<<<<<< - * and not visited_managed_raster.get( - * xi_n, yi_n)): - */ - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":2314 - * xi_n, yi_n)): - * # 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":2315 - * # 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 = weight_raster.get( - */ - __pyx_v_search_stack.push(__pyx_v_flow_pixel); - - /* "pygeoprocessing/routing/routing.pyx":2316 - * flow_pixel.last_flow_dir = i_n - * search_stack.push(flow_pixel) - * if weight_raster is not None: # <<<<<<<<<<<<<< - * weight_val = weight_raster.get( - * xi_n, yi_n) - */ - __pyx_t_5 = (((PyObject *)__pyx_v_weight_raster) != Py_None); - __pyx_t_6 = (__pyx_t_5 != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/routing/routing.pyx":2317 - * search_stack.push(flow_pixel) - * if weight_raster is not None: - * weight_val = weight_raster.get( # <<<<<<<<<<<<<< - * xi_n, yi_n) - * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): - */ - __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":2319 - * weight_val = weight_raster.get( - * xi_n, yi_n) - * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * weight_val = 0.0 - * else: - */ - __pyx_t_6 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_weight_val, __pyx_v_weight_nodata, 1e-8, 1e-5) != 0); - if (__pyx_t_6) { - - /* "pygeoprocessing/routing/routing.pyx":2320 - * xi_n, yi_n) - * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): - * weight_val = 0.0 # <<<<<<<<<<<<<< - * else: - * weight_val = 1.0 - */ - __pyx_v_weight_val = 0.0; - - /* "pygeoprocessing/routing/routing.pyx":2319 - * weight_val = weight_raster.get( - * xi_n, yi_n) - * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * weight_val = 0.0 - * else: - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2316 - * flow_pixel.last_flow_dir = i_n - * search_stack.push(flow_pixel) - * if weight_raster is not None: # <<<<<<<<<<<<<< - * weight_val = weight_raster.get( - * xi_n, yi_n) - */ - goto __pyx_L43; - } - - /* "pygeoprocessing/routing/routing.pyx":2322 - * 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_L43:; - - /* "pygeoprocessing/routing/routing.pyx":2324 - * weight_val = 1.0 - * search_stack.push( - * FlowPixelType(xi_n, yi_n, 0, weight_val)) # <<<<<<<<<<<<<< - * visited_managed_raster.set(xi_n, yi_n, 1) - * visit_count += 1 - */ - __pyx_t_31.xi = __pyx_v_xi_n; - __pyx_t_31.yi = __pyx_v_yi_n; - __pyx_t_31.last_flow_dir = 0; - __pyx_t_31.value = __pyx_v_weight_val; - - /* "pygeoprocessing/routing/routing.pyx":2323 - * else: - * weight_val = 1.0 - * search_stack.push( # <<<<<<<<<<<<<< - * FlowPixelType(xi_n, yi_n, 0, weight_val)) - * visited_managed_raster.set(xi_n, yi_n, 1) - */ - __pyx_v_search_stack.push(__pyx_t_31); - - /* "pygeoprocessing/routing/routing.pyx":2325 - * search_stack.push( - * FlowPixelType(xi_n, yi_n, 0, weight_val)) - * visited_managed_raster.set(xi_n, yi_n, 1) # <<<<<<<<<<<<<< - * visit_count += 1 - * preempted = 1 - */ - __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_visited_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n, 1.0); - - /* "pygeoprocessing/routing/routing.pyx":2326 - * FlowPixelType(xi_n, yi_n, 0, weight_val)) - * visited_managed_raster.set(xi_n, yi_n, 1) - * visit_count += 1 # <<<<<<<<<<<<<< - * preempted = 1 - * break - */ - __pyx_v_visit_count = (__pyx_v_visit_count + 1); - - /* "pygeoprocessing/routing/routing.pyx":2327 - * visited_managed_raster.set(xi_n, yi_n, 1) - * visit_count += 1 - * preempted = 1 # <<<<<<<<<<<<<< - * break - * upstream_flow_dir_sum = 0 - */ - __pyx_v_preempted = 1; - - /* "pygeoprocessing/routing/routing.pyx":2328 - * visit_count += 1 - * preempted = 1 - * break # <<<<<<<<<<<<<< - * upstream_flow_dir_sum = 0 - * for i_upstream_flow in range(8): - */ - goto __pyx_L33_break; - - /* "pygeoprocessing/routing/routing.pyx":2310 - * upstream_flow_accum = ( - * flow_accum_managed_raster.get(xi_n, yi_n)) - * if (_is_close(upstream_flow_accum, flow_accum_nodata, 1e-8, 1e-5) # <<<<<<<<<<<<<< - * and not visited_managed_raster.get( - * xi_n, yi_n)): - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2329 - * 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":2330 - * break - * upstream_flow_dir_sum = 0 - * for i_upstream_flow in range(8): # <<<<<<<<<<<<<< - * upstream_flow_dir_sum += ( - * compressed_upstream_flow_dir >> ( - */ - for (__pyx_t_30 = 0; __pyx_t_30 < 8; __pyx_t_30+=1) { - __pyx_v_i_upstream_flow = __pyx_t_30; - - /* "pygeoprocessing/routing/routing.pyx":2331 - * 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":2336 - * - * flow_pixel.value += ( - * upstream_flow_accum * upstream_flow_weight / # <<<<<<<<<<<<<< - * upstream_flow_dir_sum) - * if not preempted: - */ - __pyx_t_11 = (__pyx_v_upstream_flow_accum * __pyx_v_upstream_flow_weight); - - /* "pygeoprocessing/routing/routing.pyx":2337 - * flow_pixel.value += ( - * upstream_flow_accum * upstream_flow_weight / - * 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, 2336, __pyx_L1_error) - } - - /* "pygeoprocessing/routing/routing.pyx":2335 - * i_upstream_flow * 4)) & 0xF - * - * flow_pixel.value += ( # <<<<<<<<<<<<<< - * upstream_flow_accum * upstream_flow_weight / - * upstream_flow_dir_sum) - */ - __pyx_v_flow_pixel.value = (__pyx_v_flow_pixel.value + (__pyx_t_11 / ((double)((float)__pyx_v_upstream_flow_dir_sum)))); - __pyx_L32_continue:; - } - __pyx_L33_break:; - - /* "pygeoprocessing/routing/routing.pyx":2338 - * upstream_flow_accum * upstream_flow_weight / - * upstream_flow_dir_sum) - * 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":2339 - * 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":2338 - * upstream_flow_accum * upstream_flow_weight / - * 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":2217 - * LOGGER.debug('starting search') - * # this outer loop searches for a pixel that is locally undrained - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * flow_dir_mfd_raster_path_band, offset_only=True, - * largest_block=0): - */ - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2342 - * 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_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_flow_accum_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2342, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __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); - } - } - __pyx_t_7 = (__pyx_t_20) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_20) : __Pyx_PyObject_CallNoArg(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2342, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2343 - * flow_pixel.value) - * flow_accum_managed_raster.close() - * flow_dir_managed_raster.close() # <<<<<<<<<<<<<< - * if weight_raster is not None: - * weight_raster.close() - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_flow_dir_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2343, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __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); - } - } - __pyx_t_7 = (__pyx_t_20) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_20) : __Pyx_PyObject_CallNoArg(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2343, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2344 - * flow_accum_managed_raster.close() - * flow_dir_managed_raster.close() - * if weight_raster is not None: # <<<<<<<<<<<<<< - * weight_raster.close() - * visited_managed_raster.close() - */ - __pyx_t_6 = (((PyObject *)__pyx_v_weight_raster) != Py_None); - __pyx_t_5 = (__pyx_t_6 != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":2345 - * flow_dir_managed_raster.close() - * if weight_raster is not None: - * weight_raster.close() # <<<<<<<<<<<<<< - * visited_managed_raster.close() - * try: - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_weight_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2345, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __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); - } - } - __pyx_t_7 = (__pyx_t_20) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_20) : __Pyx_PyObject_CallNoArg(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2345, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2344 - * flow_accum_managed_raster.close() - * flow_dir_managed_raster.close() - * if weight_raster is not None: # <<<<<<<<<<<<<< - * weight_raster.close() - * visited_managed_raster.close() - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2346 - * if weight_raster is not None: - * weight_raster.close() - * visited_managed_raster.close() # <<<<<<<<<<<<<< - * try: - * shutil.rmtree(tmp_dir) - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_visited_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2346, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __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); - } - } - __pyx_t_7 = (__pyx_t_20) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_20) : __Pyx_PyObject_CallNoArg(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2346, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2347 - * weight_raster.close() - * visited_managed_raster.close() - * try: # <<<<<<<<<<<<<< - * shutil.rmtree(tmp_dir) - * except OSError: - */ - { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __Pyx_ExceptionSave(&__pyx_t_19, &__pyx_t_18, &__pyx_t_17); - __Pyx_XGOTREF(__pyx_t_19); - __Pyx_XGOTREF(__pyx_t_18); - __Pyx_XGOTREF(__pyx_t_17); - /*try:*/ { - - /* "pygeoprocessing/routing/routing.pyx":2348 - * visited_managed_raster.close() - * try: - * shutil.rmtree(tmp_dir) # <<<<<<<<<<<<<< - * except OSError: - * LOGGER.exception("couldn't remove temp dir") - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_shutil); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2348, __pyx_L49_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_rmtree); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2348, __pyx_L49_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_20))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_20); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_20); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_20, function); - } - } - __pyx_t_7 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_20, __pyx_t_1, __pyx_v_tmp_dir) : __Pyx_PyObject_CallOneArg(__pyx_t_20, __pyx_v_tmp_dir); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2348, __pyx_L49_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2347 - * weight_raster.close() - * visited_managed_raster.close() - * try: # <<<<<<<<<<<<<< - * shutil.rmtree(tmp_dir) - * except OSError: - */ - } - __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; - __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; - __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; - goto __pyx_L54_try_end; - __pyx_L49_error:; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; - __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; - __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2349 - * try: - * shutil.rmtree(tmp_dir) - * except OSError: # <<<<<<<<<<<<<< - * LOGGER.exception("couldn't remove temp dir") - * LOGGER.info('%.1f%% complete', 100.0) - */ - __pyx_t_13 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OSError); - if (__pyx_t_13) { - __Pyx_AddTraceback("pygeoprocessing.routing.routing.flow_accumulation_mfd", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_20, &__pyx_t_1) < 0) __PYX_ERR(0, 2349, __pyx_L51_except_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_GOTREF(__pyx_t_20); - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":2350 - * shutil.rmtree(tmp_dir) - * except OSError: - * LOGGER.exception("couldn't remove temp dir") # <<<<<<<<<<<<<< - * LOGGER.info('%.1f%% complete', 100.0) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_21, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2350, __pyx_L51_except_error) - __Pyx_GOTREF(__pyx_t_21); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_21, __pyx_n_s_exception); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2350, __pyx_L51_except_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - __pyx_t_21 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_21)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_21); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_3 = (__pyx_t_21) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_21, __pyx_kp_u_couldn_t_remove_temp_dir) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_kp_u_couldn_t_remove_temp_dir); - __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2350, __pyx_L51_except_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L50_exception_handled; - } - goto __pyx_L51_except_error; - __pyx_L51_except_error:; - - /* "pygeoprocessing/routing/routing.pyx":2347 - * weight_raster.close() - * visited_managed_raster.close() - * try: # <<<<<<<<<<<<<< - * shutil.rmtree(tmp_dir) - * except OSError: - */ - __Pyx_XGIVEREF(__pyx_t_19); - __Pyx_XGIVEREF(__pyx_t_18); - __Pyx_XGIVEREF(__pyx_t_17); - __Pyx_ExceptionReset(__pyx_t_19, __pyx_t_18, __pyx_t_17); - goto __pyx_L1_error; - __pyx_L50_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_19); - __Pyx_XGIVEREF(__pyx_t_18); - __Pyx_XGIVEREF(__pyx_t_17); - __Pyx_ExceptionReset(__pyx_t_19, __pyx_t_18, __pyx_t_17); - __pyx_L54_try_end:; - } - - /* "pygeoprocessing/routing/routing.pyx":2351 - * except OSError: - * LOGGER.exception("couldn't remove temp dir") - * LOGGER.info('%.1f%% complete', 100.0) # <<<<<<<<<<<<<< - * - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2351, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_info); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2351, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_20, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2351, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2073 - * - * - * 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_7); - __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(__pyx_v_tmp_dir_root); - __Pyx_XDECREF(__pyx_v_tmp_dir); - __Pyx_XDECREF(__pyx_v_visited_raster_path); - __Pyx_XDECREF((PyObject *)__pyx_v_visited_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":2354 - * - * - * 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\n 3 2 1\n 4 x 0\n 5 6 7\n\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 (str): 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 raster_driver_creation_tuple (tuple): a tuple containing a GDAL driver\n name string as the first element and a GDAL creation options\n tuple/list as the second. Defaults to a GTiff driver tuple\n defined at geoprocessing.DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS.\n\n Returns:\n None.\n "; -static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_13distance_to_channel_d8 = {"distance_to_channel_d8", (PyCFunction)(void*)(PyCFunctionWithKeywords)__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_raster_driver_creation_tuple = 0; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 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_raster_driver_creation_tuple,0}; - PyObject* values[5] = {0,0,0,0,0}; - - /* "pygeoprocessing/routing/routing.pyx":2357 - * flow_dir_d8_raster_path_band, channel_raster_path_band, - * target_distance_to_channel_raster_path, - * weight_raster_path_band=None, # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): - * """Calculate distance to channel with D8 flow. - */ - values[3] = ((PyObject *)Py_None); - values[4] = __pyx_k__12; - 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, 2354, __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, 2354, __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_raster_driver_creation_tuple); - 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, 2354, __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_raster_driver_creation_tuple = 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, 2354, __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_raster_driver_creation_tuple); - - /* "pygeoprocessing/routing/routing.pyx":2354 - * - * - * 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_raster_driver_creation_tuple) { - 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 __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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __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":2411 - * # 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":2415 - * # 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":2418 - * - * 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, 2418, __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":2417 - * 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, 2417, __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, 2417, __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":2420 - * 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_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_is_raster_path_band_formatted); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2420, __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); - } - } - __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_v_path) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_path); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2420, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __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, 2420, __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":2422 - * 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_PyUnicode_FormatSafe(__pyx_kp_u_s_is_supposed_to_be_a_raster_ba, __pyx_v_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2422, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":2421 - * 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, 2421, __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, 2421, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2420 - * 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":2417 - * 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":2425 - * 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":2426 - * - * distance_nodata = -1 - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band[0], - * target_distance_to_channel_raster_path, - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2426, __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, 2426, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2427 - * 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, 2427, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - - /* "pygeoprocessing/routing/routing.pyx":2429 - * flow_dir_d8_raster_path_band[0], - * target_distance_to_channel_raster_path, - * gdal.GDT_Float64, [distance_nodata], # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * distance_to_channel_managed_raster = _ManagedRaster( - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2429, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2429, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __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, 2429, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = PyList_New(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2429, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_GIVEREF(__pyx_t_1); - PyList_SET_ITEM(__pyx_t_9, 0, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2426 - * - * 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, 2426, __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_8); - PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_9); - __pyx_t_2 = 0; - __pyx_t_8 = 0; - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2430 - * target_distance_to_channel_raster_path, - * gdal.GDT_Float64, [distance_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< - * distance_to_channel_managed_raster = _ManagedRaster( - * target_distance_to_channel_raster_path, 1, 1) - */ - __pyx_t_9 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2430, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 2430, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2426 - * - * distance_nodata = -1 - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band[0], - * target_distance_to_channel_raster_path, - */ - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_1, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2426, __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_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2431 - * gdal.GDT_Float64, [distance_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * distance_to_channel_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< - * target_distance_to_channel_raster_path, 1, 1) - * - */ - __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2431, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __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_8, 0, __pyx_v_target_distance_to_channel_raster_path); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_int_1); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_int_1); - __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, 2431, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_distance_to_channel_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_9); - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2434 - * 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":2435 - * - * 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, 2435, __pyx_L1_error) - if (__pyx_t_4) { - - /* "pygeoprocessing/routing/routing.pyx":2437 - * 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_9 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2437, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __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, 2437, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - - /* "pygeoprocessing/routing/routing.pyx":2436 - * 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, 2436, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_8); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_1, 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_1, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2436, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __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_8)); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2438 - * 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_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2438, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2438, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2439 - * 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, 2439, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(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); - } - } - __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_7, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_1); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2438, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = __Pyx_PyObject_Dict_GetItem(__pyx_t_8, __pyx_n_u_nodata); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2439, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2440 - * 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, 2440, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = __Pyx_PyInt_SubtractObjC(__pyx_t_8, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2440, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2439 - * 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_9, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2439, __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_v_raw_weight_nodata = __pyx_t_8; - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2441 - * 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":2442 - * 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, 2442, __pyx_L1_error) - __pyx_v_weight_nodata = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":2441 - * 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":2435 - * - * 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":2445 - * - * channel_managed_raster = _ManagedRaster( - * channel_raster_path_band[0], channel_raster_path_band[1], 0) # <<<<<<<<<<<<<< - * - * flow_dir_d8_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, 2445, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_channel_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2445, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":2444 - * weight_nodata = raw_weight_nodata - * - * channel_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< - * channel_raster_path_band[0], channel_raster_path_band[1], 0) - * - */ - __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2444, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_1); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_9, 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_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2444, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_v_channel_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2448 - * - * 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_1 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2448, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2448, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - - /* "pygeoprocessing/routing/routing.pyx":2447 - * 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_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2447, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1); - __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_1 = 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, 2447, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_flow_dir_d8_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_9); - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2449 - * 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_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_gdal); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2449, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2449, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __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, 2449, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2449, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2449, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - __pyx_t_11 = 0; - 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); - __pyx_t_11 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_8, __pyx_t_2}; - __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2449, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __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_7, __pyx_t_8, __pyx_t_2}; - __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2449, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else - #endif - { - __pyx_t_12 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2449, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - if (__pyx_t_7) { - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_7); __pyx_t_7 = NULL; - } - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_11, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_11, __pyx_t_2); - __pyx_t_8 = 0; - __pyx_t_2 = 0; - __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_12, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2449, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_channel_raster = __pyx_t_9; - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2450 - * 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_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_channel_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2450, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __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, 2450, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_9 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_t_12) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_12); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2450, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_channel_band = __pyx_t_9; - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2452 - * 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_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2452, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2452, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2453 - * - * 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_1 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 0, 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); - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - } - } - __pyx_t_9 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_2, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2452, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_v_flow_dir_raster_info = __pyx_t_9; - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2454 - * 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_9 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_raster_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2454, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - 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 != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 2454, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_12 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_12 = PyList_GET_ITEM(sequence, 0); - __pyx_t_1 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_12); - __Pyx_INCREF(__pyx_t_1); - #else - __pyx_t_12 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2454, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2454, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_2 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2454, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_13 = Py_TYPE(__pyx_t_2)->tp_iternext; - index = 0; __pyx_t_12 = __pyx_t_13(__pyx_t_2); if (unlikely(!__pyx_t_12)) goto __pyx_L10_unpacking_failed; - __Pyx_GOTREF(__pyx_t_12); - index = 1; __pyx_t_1 = __pyx_t_13(__pyx_t_2); if (unlikely(!__pyx_t_1)) goto __pyx_L10_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_2), 2) < 0) __PYX_ERR(0, 2454, __pyx_L1_error) - __pyx_t_13 = NULL; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L11_unpacking_done; - __pyx_L10_unpacking_failed:; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_13 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 2454, __pyx_L1_error) - __pyx_L11_unpacking_done:; - } - __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_12); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2454, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2454, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_raster_x_size = __pyx_t_11; - __pyx_v_raster_y_size = __pyx_t_14; - - /* "pygeoprocessing/routing/routing.pyx":2457 - * - * # this outer loop searches for undefined channels - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * channel_raster_path_band, offset_only=True, largest_block=0): - * win_xsize = offset_dict['win_xsize'] - */ - __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2457, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2457, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2458 - * # this outer loop searches for undefined channels - * for offset_dict in pygeoprocessing.iterblocks( - * channel_raster_path_band, offset_only=True, largest_block=0): # <<<<<<<<<<<<<< - * win_xsize = offset_dict['win_xsize'] - * win_ysize = offset_dict['win_ysize'] - */ - __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2457, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_INCREF(__pyx_v_channel_raster_path_band); - __Pyx_GIVEREF(__pyx_v_channel_raster_path_band); - PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_channel_raster_path_band); - __pyx_t_12 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2458, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 2458, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_largest_block, __pyx_int_0) < 0) __PYX_ERR(0, 2458, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2457 - * - * # this outer loop searches for undefined channels - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * channel_raster_path_band, offset_only=True, largest_block=0): - * win_xsize = offset_dict['win_xsize'] - */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, __pyx_t_12); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2457, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { - __pyx_t_12 = __pyx_t_2; __Pyx_INCREF(__pyx_t_12); __pyx_t_3 = 0; - __pyx_t_15 = NULL; - } else { - __pyx_t_3 = -1; __pyx_t_12 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2457, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_15 = Py_TYPE(__pyx_t_12)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2457, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - for (;;) { - if (likely(!__pyx_t_15)) { - if (likely(PyList_CheckExact(__pyx_t_12))) { - if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_12)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_12, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 2457, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_12, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2457, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } else { - if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_12)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_12, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 2457, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_12, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2457, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } - } else { - __pyx_t_2 = __pyx_t_15(__pyx_t_12); - if (unlikely(!__pyx_t_2)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 2457, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XDECREF_SET(__pyx_v_offset_dict, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2459 - * for offset_dict in pygeoprocessing.iterblocks( - * channel_raster_path_band, offset_only=True, largest_block=0): - * win_xsize = offset_dict['win_xsize'] # <<<<<<<<<<<<<< - * win_ysize = offset_dict['win_ysize'] - * xoff = offset_dict['xoff'] - */ - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2459, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2459, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_win_xsize = __pyx_t_14; - - /* "pygeoprocessing/routing/routing.pyx":2460 - * channel_raster_path_band, 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_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2460, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2460, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_win_ysize = __pyx_t_14; - - /* "pygeoprocessing/routing/routing.pyx":2461 - * win_xsize = offset_dict['win_xsize'] - * win_ysize = offset_dict['win_ysize'] - * xoff = offset_dict['xoff'] # <<<<<<<<<<<<<< - * yoff = offset_dict['yoff'] - * - */ - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_xoff); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2461, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2461, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_xoff = __pyx_t_14; - - /* "pygeoprocessing/routing/routing.pyx":2462 - * win_ysize = offset_dict['win_ysize'] - * xoff = offset_dict['xoff'] - * yoff = offset_dict['yoff'] # <<<<<<<<<<<<<< - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - */ - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_yoff); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2462, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2462, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_yoff = __pyx_t_14; - - /* "pygeoprocessing/routing/routing.pyx":2464 - * yoff = offset_dict['yoff'] - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - */ - __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":2465 - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( - */ - __pyx_v_last_log_time = time(NULL); - - /* "pygeoprocessing/routing/routing.pyx":2466 - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size # <<<<<<<<<<<<<< - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( - * raster_x_size * raster_y_size)) - */ - __pyx_t_2 = __Pyx_PyInt_From_int((__pyx_v_xoff + (__pyx_v_yoff * __pyx_v_raster_x_size))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2466, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_XDECREF_SET(__pyx_v_current_pixel, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2467 - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< - * raster_x_size * raster_y_size)) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2467, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2467, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = PyNumber_Multiply(__pyx_float_100_0, __pyx_v_current_pixel); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2467, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - - /* "pygeoprocessing/routing/routing.pyx":2468 - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( - * raster_x_size * raster_y_size)) # <<<<<<<<<<<<<< - * - * # make a buffer big enough to capture block and boundaries around it - */ - __pyx_t_8 = PyFloat_FromDouble(((float)(__pyx_v_raster_x_size * __pyx_v_raster_y_size))); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2467, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - - /* "pygeoprocessing/routing/routing.pyx":2467 - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< - * raster_x_size * raster_y_size)) - * - */ - __pyx_t_7 = __Pyx_PyNumber_Divide(__pyx_t_9, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2467, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = NULL; - __pyx_t_14 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - __pyx_t_14 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_kp_u_1f_complete, __pyx_t_7}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2467, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_kp_u_1f_complete, __pyx_t_7}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2467, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - { - __pyx_t_9 = PyTuple_New(2+__pyx_t_14); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2467, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - if (__pyx_t_8) { - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; - } - __Pyx_INCREF(__pyx_kp_u_1f_complete); - __Pyx_GIVEREF(__pyx_kp_u_1f_complete); - PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_14, __pyx_kp_u_1f_complete); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_14, __pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2467, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2464 - * yoff = offset_dict['yoff'] - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2471 - * - * # 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2471, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2471, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2472 - * # 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_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2472, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_9 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2472, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2472, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2472, __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, 2472, __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_7); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_7); - __pyx_t_9 = 0; - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2471 - * - * # 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_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2471, __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":2473 - * 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_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2473, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_numpy); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2473, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_uint8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2473, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 2473, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2471 - * - * # 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_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2471, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2471, __pyx_L1_error) - __pyx_t_16 = ((PyArrayObject *)__pyx_t_8); - { - __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, 2471, __pyx_L1_error) - } - __pyx_t_16 = 0; - __Pyx_XDECREF_SET(__pyx_v_channel_buffer_array, ((PyArrayObject *)__pyx_t_8)); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2474 - * (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__7, __pyx_int_0) < 0)) __PYX_ERR(0, 2474, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2478 - * # 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_generate_read_bounds); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2478, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - - /* "pygeoprocessing/routing/routing.pyx":2479 - * # 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, 2479, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_raster_y_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2479, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = NULL; - __pyx_t_14 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(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); - __pyx_t_14 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[4] = {__pyx_t_9, __pyx_v_offset_dict, __pyx_t_7, __pyx_t_1}; - __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_14, 3+__pyx_t_14); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2478, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[4] = {__pyx_t_9, __pyx_v_offset_dict, __pyx_t_7, __pyx_t_1}; - __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_14, 3+__pyx_t_14); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2478, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - { - __pyx_t_20 = PyTuple_New(3+__pyx_t_14); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2478, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - if (__pyx_t_9) { - __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_9); __pyx_t_9 = 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_7); - PyTuple_SET_ITEM(__pyx_t_20, 1+__pyx_t_14, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_20, 2+__pyx_t_14, __pyx_t_1); - __pyx_t_7 = 0; - __pyx_t_1 = 0; - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_20, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2478, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - 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, 2478, __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_20 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_2 = PyList_GET_ITEM(sequence, 0); - __pyx_t_20 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_20); - #else - __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2478, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_20 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2478, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - #endif - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_1 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2478, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_13 = Py_TYPE(__pyx_t_1)->tp_iternext; - index = 0; __pyx_t_2 = __pyx_t_13(__pyx_t_1); if (unlikely(!__pyx_t_2)) goto __pyx_L15_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - index = 1; __pyx_t_20 = __pyx_t_13(__pyx_t_1); if (unlikely(!__pyx_t_20)) goto __pyx_L15_unpacking_failed; - __Pyx_GOTREF(__pyx_t_20); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_1), 2) < 0) __PYX_ERR(0, 2478, __pyx_L1_error) - __pyx_t_13 = 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_13 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 2478, __pyx_L1_error) - __pyx_L16_unpacking_done:; - } - - /* "pygeoprocessing/routing/routing.pyx":2478 - * # 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, 2478, __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); - __pyx_t_9 = PyTuple_GET_ITEM(sequence, 2); - __pyx_t_21 = PyTuple_GET_ITEM(sequence, 3); - } else { - __pyx_t_1 = PyList_GET_ITEM(sequence, 0); - __pyx_t_7 = PyList_GET_ITEM(sequence, 1); - __pyx_t_9 = PyList_GET_ITEM(sequence, 2); - __pyx_t_21 = PyList_GET_ITEM(sequence, 3); - } - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(__pyx_t_21); - #else - { - Py_ssize_t i; - PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_7,&__pyx_t_9,&__pyx_t_21}; - for (i=0; i < 4; i++) { - PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 2478, __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_1,&__pyx_t_7,&__pyx_t_9,&__pyx_t_21}; - __pyx_t_22 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2478, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_22); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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, 2478, __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, 2478, __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_7); - __pyx_t_7 = 0; - __Pyx_XDECREF_SET(__pyx_v_ya, __pyx_t_9); - __pyx_t_9 = 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":2480 - * (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, 2480, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - - /* "pygeoprocessing/routing/routing.pyx":2481 - * 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, 2481, __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, 2481, __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, 2480, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - } - - /* "pygeoprocessing/routing/routing.pyx":2480 - * (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_2); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2480, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_21); - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2481 - * 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_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_21, __pyx_n_s_astype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2481, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_21, __pyx_n_s_numpy); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2481, __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, 2481, __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_2))) { - __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_21)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_21); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_8 = (__pyx_t_21) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_21, __pyx_t_20) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_20); - __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2481, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2480 - * (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, 2480, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_20 = PySlice_New(__pyx_v_xa, __pyx_v_xb, Py_None); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2480, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __pyx_t_21 = PyTuple_New(2); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2480, __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_20); - PyTuple_SET_ITEM(__pyx_t_21, 1, __pyx_t_20); - __pyx_t_2 = 0; - __pyx_t_20 = 0; - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_channel_buffer_array), __pyx_t_21, __pyx_t_8) < 0)) __PYX_ERR(0, 2480, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2484 - * - * # ensure these are set for the complier - * xi_n = -1 # <<<<<<<<<<<<<< - * yi_n = -1 - * - */ - __pyx_v_xi_n = -1; - - /* "pygeoprocessing/routing/routing.pyx":2485 - * # 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":2488 - * - * # 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":2489 - * # 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":2490 - * 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, 2490, __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":2492 - * if channel_buffer_array[yi, xi] != 1: - * # no channel seed - * continue # <<<<<<<<<<<<<< - * - * distance_to_channel_stack.push( - */ - goto __pyx_L21_continue; - - /* "pygeoprocessing/routing/routing.pyx":2490 - * 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":2495 - * - * 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":2494 - * 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":2497 - * 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":2498 - * - * 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":2499 - * 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":2500 - * 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":2501 - * 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":2503 - * 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":2506 - * xi_q, yi_q, pixel_val) - * - * for i_n in range(8): # <<<<<<<<<<<<<< - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] - */ - for (__pyx_t_29 = 0; __pyx_t_29 < 8; __pyx_t_29+=1) { - __pyx_v_i_n = __pyx_t_29; - - /* "pygeoprocessing/routing/routing.pyx":2507 - * - * for i_n in range(8): - * xi_n = xi_q+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< - * yi_n = yi_q+D8_YOFFSET[i_n] - * - */ - __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":2508 - * for i_n in range(8): - * xi_n = xi_q+D8_XOFFSET[i_n] - * yi_n = yi_q+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< - * - * if (xi_n < 0 or xi_n >= raster_x_size or - */ - __pyx_v_yi_n = (__pyx_v_yi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":2510 - * yi_n = yi_q+D8_YOFFSET[i_n] - * - * 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":2511 - * - * 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":2510 - * yi_n = yi_q+D8_YOFFSET[i_n] - * - * 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":2512 - * 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":2510 - * yi_n = yi_q+D8_YOFFSET[i_n] - * - * 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":2514 - * 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":2517 - * # 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":2514 - * 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":2519 - * 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":2526 - * # 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, 1e-8, 1e-5): - */ - __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":2527 - * # 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, 1e-8, 1e-5): - * 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":2528 - * if weight_raster is not None: - * weight_val = weight_raster.get(xi_n, yi_n) - * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * weight_val = 0.0 - * else: - */ - __pyx_t_4 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_weight_val, __pyx_v_weight_nodata, 1e-8, 1e-5) != 0); - if (__pyx_t_4) { - - /* "pygeoprocessing/routing/routing.pyx":2529 - * weight_val = weight_raster.get(xi_n, yi_n) - * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): - * weight_val = 0.0 # <<<<<<<<<<<<<< - * else: - * weight_val = (SQRT2 if i_n % 2 else 1) - */ - __pyx_v_weight_val = 0.0; - - /* "pygeoprocessing/routing/routing.pyx":2528 - * if weight_raster is not None: - * weight_val = weight_raster.get(xi_n, yi_n) - * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * weight_val = 0.0 - * else: - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2526 - * # 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, 1e-8, 1e-5): - */ - goto __pyx_L35; - } - - /* "pygeoprocessing/routing/routing.pyx":2531 - * 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":2535 - * 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":2533 - * 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":2519 - * 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":2457 - * - * # this outer loop searches for undefined channels - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * channel_raster_path_band, offset_only=True, largest_block=0): - * win_xsize = offset_dict['win_xsize'] - */ - } - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2537 - * 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_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_distance_to_channel_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2537, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_21 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_21)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_21); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - } - } - __pyx_t_12 = (__pyx_t_21) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_21) : __Pyx_PyObject_CallNoArg(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; - if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2537, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2538 - * - * distance_to_channel_managed_raster.close() - * flow_dir_d8_managed_raster.close() # <<<<<<<<<<<<<< - * channel_managed_raster.close() - * if weight_raster is not None: - */ - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_flow_dir_d8_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2538, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_21 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_21)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_21); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - } - } - __pyx_t_12 = (__pyx_t_21) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_21) : __Pyx_PyObject_CallNoArg(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; - if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2538, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2539 - * 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_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_channel_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2539, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_21 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_21)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_21); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - } - } - __pyx_t_12 = (__pyx_t_21) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_21) : __Pyx_PyObject_CallNoArg(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; - if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2539, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2540 - * 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":2541 - * channel_managed_raster.close() - * if weight_raster is not None: - * weight_raster.close() # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_weight_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2541, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_21 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_21)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_21); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - } - } - __pyx_t_12 = (__pyx_t_21) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_21) : __Pyx_PyObject_CallNoArg(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; - if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2541, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2540 - * flow_dir_d8_managed_raster.close() - * channel_managed_raster.close() - * if weight_raster is not None: # <<<<<<<<<<<<<< - * weight_raster.close() - * - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2354 - * - * - * 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":2544 - * - * - * 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 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 (str): 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 raster_driver_creation_tuple (tuple): a tuple containing a GDAL driver\n name string as the first element and a GDAL creation options\n tuple/list as the second. Defaults to a GTiff driver tuple\n defined at ``geoprocessing.DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS``.\n\n Returns:\n None.\n "; -static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_15distance_to_channel_mfd = {"distance_to_channel_mfd", (PyCFunction)(void*)(PyCFunctionWithKeywords)__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_raster_driver_creation_tuple = 0; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 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_raster_driver_creation_tuple,0}; - PyObject* values[5] = {0,0,0,0,0}; - - /* "pygeoprocessing/routing/routing.pyx":2546 - * 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, # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): - * """Calculate distance to channel with multiple flow direction. - */ - values[3] = ((PyObject *)Py_None); - values[4] = __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 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, 2544, __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, 2544, __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_raster_driver_creation_tuple); - 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, 2544, __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_raster_driver_creation_tuple = 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, 2544, __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_raster_driver_creation_tuple); - - /* "pygeoprocessing/routing/routing.pyx":2544 - * - * - * 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_raster_driver_creation_tuple) { - 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 __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; - 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_channel_managed_raster = NULL; - PyObject *__pyx_v_tmp_work_dir = NULL; - PyObject *__pyx_v_visited_raster_path = NULL; - struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_visited_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; - struct __pyx_t_15pygeoprocessing_7routing_7routing_FlowPixelType __pyx_t_31; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __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":2600 - * # 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":2604 - * # 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":2607 - * - * 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, 2607, __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":2606 - * 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, 2606, __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, 2606, __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":2609 - * 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_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_is_raster_path_band_formatted); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2609, __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); - } - } - __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_v_path) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_path); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2609, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __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, 2609, __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":2611 - * 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_PyUnicode_FormatSafe(__pyx_kp_u_s_is_supposed_to_be_a_raster_ba, __pyx_v_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2611, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":2610 - * 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, 2610, __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, 2610, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2609 - * 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":2606 - * 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":2614 - * path)) - * - * distance_nodata = -1 # <<<<<<<<<<<<<< - * pygeoprocessing.new_raster_from_base( - * flow_dir_mfd_raster_path_band[0], - */ - __pyx_v_distance_nodata = -1L; - - /* "pygeoprocessing/routing/routing.pyx":2615 - * - * distance_nodata = -1 - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * flow_dir_mfd_raster_path_band[0], - * target_distance_to_channel_raster_path, - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2615, __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, 2615, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2616 - * distance_nodata = -1 - * 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, 2616, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - - /* "pygeoprocessing/routing/routing.pyx":2618 - * flow_dir_mfd_raster_path_band[0], - * target_distance_to_channel_raster_path, - * gdal.GDT_Float64, [distance_nodata], # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * distance_to_channel_managed_raster = _ManagedRaster( - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2618, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2618, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __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, 2618, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = PyList_New(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2618, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_GIVEREF(__pyx_t_1); - PyList_SET_ITEM(__pyx_t_9, 0, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2615 - * - * distance_nodata = -1 - * 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, 2615, __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_8); - PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_9); - __pyx_t_2 = 0; - __pyx_t_8 = 0; - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2619 - * target_distance_to_channel_raster_path, - * gdal.GDT_Float64, [distance_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< - * distance_to_channel_managed_raster = _ManagedRaster( - * target_distance_to_channel_raster_path, 1, 1) - */ - __pyx_t_9 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2619, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 2619, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2615 - * - * distance_nodata = -1 - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * flow_dir_mfd_raster_path_band[0], - * target_distance_to_channel_raster_path, - */ - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_1, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2615, __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_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2620 - * gdal.GDT_Float64, [distance_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * distance_to_channel_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< - * target_distance_to_channel_raster_path, 1, 1) - * channel_managed_raster = _ManagedRaster( - */ - __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2620, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __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_8, 0, __pyx_v_target_distance_to_channel_raster_path); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_int_1); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_int_1); - __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, 2620, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_distance_to_channel_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_9); - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2623 - * target_distance_to_channel_raster_path, 1, 1) - * channel_managed_raster = _ManagedRaster( - * channel_raster_path_band[0], channel_raster_path_band[1], 0) # <<<<<<<<<<<<<< - * - * tmp_work_dir = tempfile.mkdtemp( - */ - __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_channel_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2623, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_channel_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2623, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - - /* "pygeoprocessing/routing/routing.pyx":2622 - * distance_to_channel_managed_raster = _ManagedRaster( - * 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, 2622, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_8); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_1, 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_1, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2622, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_channel_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2625 - * channel_raster_path_band[0], channel_raster_path_band[1], 0) - * - * tmp_work_dir = tempfile.mkdtemp( # <<<<<<<<<<<<<< - * suffix=None, prefix='dist_to_channel_mfd_work_dir', - * dir=os.path.dirname(target_distance_to_channel_raster_path)) - */ - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_tempfile); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2625, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_mkdtemp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2625, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2626 - * - * tmp_work_dir = tempfile.mkdtemp( - * suffix=None, prefix='dist_to_channel_mfd_work_dir', # <<<<<<<<<<<<<< - * dir=os.path.dirname(target_distance_to_channel_raster_path)) - * visited_raster_path = os.path.join(tmp_work_dir, 'visited.tif') - */ - __pyx_t_8 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2626, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_suffix, Py_None) < 0) __PYX_ERR(0, 2626, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_prefix, __pyx_n_u_dist_to_channel_mfd_work_dir) < 0) __PYX_ERR(0, 2626, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2627 - * tmp_work_dir = tempfile.mkdtemp( - * suffix=None, prefix='dist_to_channel_mfd_work_dir', - * dir=os.path.dirname(target_distance_to_channel_raster_path)) # <<<<<<<<<<<<<< - * visited_raster_path = os.path.join(tmp_work_dir, 'visited.tif') - * pygeoprocessing.new_raster_from_base( - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_os); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2627, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_path); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2627, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_dirname); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2627, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_9 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_2, __pyx_v_target_distance_to_channel_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_target_distance_to_channel_raster_path); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2627, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_dir, __pyx_t_9) < 0) __PYX_ERR(0, 2626, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2625 - * channel_raster_path_band[0], channel_raster_path_band[1], 0) - * - * tmp_work_dir = tempfile.mkdtemp( # <<<<<<<<<<<<<< - * suffix=None, prefix='dist_to_channel_mfd_work_dir', - * dir=os.path.dirname(target_distance_to_channel_raster_path)) - */ - __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2625, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_tmp_work_dir = __pyx_t_9; - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2628 - * suffix=None, prefix='dist_to_channel_mfd_work_dir', - * dir=os.path.dirname(target_distance_to_channel_raster_path)) - * visited_raster_path = os.path.join(tmp_work_dir, 'visited.tif') # <<<<<<<<<<<<<< - * pygeoprocessing.new_raster_from_base( - * flow_dir_mfd_raster_path_band[0], - */ - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_os); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2628, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2628, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_join); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2628, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - __pyx_t_10 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_1); - __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_1, __pyx_v_tmp_work_dir, __pyx_kp_u_visited_tif}; - __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2628, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_9); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_tmp_work_dir, __pyx_kp_u_visited_tif}; - __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2628, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_9); - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2628, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_1) { - __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1); __pyx_t_1 = NULL; - } - __Pyx_INCREF(__pyx_v_tmp_work_dir); - __Pyx_GIVEREF(__pyx_v_tmp_work_dir); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_10, __pyx_v_tmp_work_dir); - __Pyx_INCREF(__pyx_kp_u_visited_tif); - __Pyx_GIVEREF(__pyx_kp_u_visited_tif); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_10, __pyx_kp_u_visited_tif); - __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_7, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2628, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_visited_raster_path = __pyx_t_9; - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2629 - * dir=os.path.dirname(target_distance_to_channel_raster_path)) - * visited_raster_path = os.path.join(tmp_work_dir, 'visited.tif') - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * flow_dir_mfd_raster_path_band[0], - * visited_raster_path, - */ - __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2629, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2629, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2630 - * visited_raster_path = os.path.join(tmp_work_dir, 'visited.tif') - * pygeoprocessing.new_raster_from_base( - * flow_dir_mfd_raster_path_band[0], # <<<<<<<<<<<<<< - * visited_raster_path, - * gdal.GDT_Byte, [0], - */ - __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, 2630, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - - /* "pygeoprocessing/routing/routing.pyx":2632 - * flow_dir_mfd_raster_path_band[0], - * visited_raster_path, - * gdal.GDT_Byte, [0], # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * visited_managed_raster = _ManagedRaster(visited_raster_path, 1, 1) - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2632, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2632, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyList_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2632, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyList_SET_ITEM(__pyx_t_7, 0, __pyx_int_0); - - /* "pygeoprocessing/routing/routing.pyx":2629 - * dir=os.path.dirname(target_distance_to_channel_raster_path)) - * visited_raster_path = os.path.join(tmp_work_dir, 'visited.tif') - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * flow_dir_mfd_raster_path_band[0], - * visited_raster_path, - */ - __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2629, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_9); - __Pyx_INCREF(__pyx_v_visited_raster_path); - __Pyx_GIVEREF(__pyx_v_visited_raster_path); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_visited_raster_path); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_7); - __pyx_t_9 = 0; - __pyx_t_1 = 0; - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2633 - * visited_raster_path, - * gdal.GDT_Byte, [0], - * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< - * visited_managed_raster = _ManagedRaster(visited_raster_path, 1, 1) - * - */ - __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2633, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 2633, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2629 - * dir=os.path.dirname(target_distance_to_channel_raster_path)) - * visited_raster_path = os.path.join(tmp_work_dir, 'visited.tif') - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * flow_dir_mfd_raster_path_band[0], - * visited_raster_path, - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_2, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2629, __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_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2634 - * gdal.GDT_Byte, [0], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * visited_managed_raster = _ManagedRaster(visited_raster_path, 1, 1) # <<<<<<<<<<<<<< - * - * flow_dir_mfd_managed_raster = _ManagedRaster( - */ - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2634, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_visited_raster_path); - __Pyx_GIVEREF(__pyx_v_visited_raster_path); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_visited_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_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_1, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2634, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_visited_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_7); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2637 - * - * 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_7 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2637, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __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, 2637, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":2636 - * visited_managed_raster = _ManagedRaster(visited_raster_path, 1, 1) - * - * 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_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2636, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_int_0); - __pyx_t_7 = 0; - __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2636, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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":2638 - * 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2638, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2638, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __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, 2638, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_gdal); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2638, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2638, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = NULL; - __pyx_t_10 = 0; - 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); - __pyx_t_10 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_2, __pyx_t_9}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2638, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 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_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_2, __pyx_t_9}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2638, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 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_11 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2638, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - if (__pyx_t_8) { - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_8); __pyx_t_8 = NULL; - } - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_t_9); - __pyx_t_2 = 0; - __pyx_t_9 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_11, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2638, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_channel_raster = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2639 - * 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_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_channel_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2639, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __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, 2639, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_9, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_11); - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2639, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_channel_band = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2641 - * 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_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2641, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2641, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2642 - * - * 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_7 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2642, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_gdal); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2642, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2642, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = NULL; - __pyx_t_10 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - __pyx_t_10 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_11)) { - PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_7, __pyx_t_2}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2641, __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; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { - PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_7, __pyx_t_2}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2641, __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; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else - #endif - { - __pyx_t_8 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2641, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - if (__pyx_t_9) { - __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_9); __pyx_t_9 = NULL; - } - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_10, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_10, __pyx_t_2); - __pyx_t_7 = 0; - __pyx_t_2 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2641, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_v_flow_dir_mfd_raster = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2643 - * 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_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_mfd_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2643, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - - /* "pygeoprocessing/routing/routing.pyx":2644 - * 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_8 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2644, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __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); - } - } - __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_2, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_8); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2643, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_v_flow_dir_mfd_band = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2646 - * 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":2647 - * - * 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, 2647, __pyx_L1_error) - if (__pyx_t_4) { - - /* "pygeoprocessing/routing/routing.pyx":2649 - * 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, 2649, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2649, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - - /* "pygeoprocessing/routing/routing.pyx":2648 - * 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_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2648, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_11); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_int_0); - __pyx_t_1 = 0; - __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_8, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2648, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF_SET(__pyx_v_weight_raster, ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_11)); - __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2650 - * 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_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2650, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2650, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2651 - * 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_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, 2651, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __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); - } - } - __pyx_t_11 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_8); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2650, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_t_11, __pyx_n_u_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2651, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2652 - * 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_11 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2652, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_8 = __Pyx_PyInt_SubtractObjC(__pyx_t_11, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2652, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2651 - * 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_11 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_8); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2651, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_raw_weight_nodata = __pyx_t_11; - __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2653 - * 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":2654 - * 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, 2654, __pyx_L1_error) - __pyx_v_weight_nodata = __pyx_t_12; - - /* "pygeoprocessing/routing/routing.pyx":2653 - * 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":2656 - * 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":2647 - * - * 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":2658 - * 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_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2658, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2658, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2659 - * - * 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_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, 2659, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __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); - } - } - __pyx_t_11 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_8); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2658, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_flow_dir_raster_info = __pyx_t_11; - __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2660 - * 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_11 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_raster_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2660, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - if ((likely(PyTuple_CheckExact(__pyx_t_11))) || (PyList_CheckExact(__pyx_t_11))) { - PyObject* sequence = __pyx_t_11; - 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, 2660, __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_8 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_1 = PyList_GET_ITEM(sequence, 0); - __pyx_t_8 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_8); - #else - __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2660, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2660, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - #endif - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_2 = PyObject_GetIter(__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2660, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_13 = Py_TYPE(__pyx_t_2)->tp_iternext; - index = 0; __pyx_t_1 = __pyx_t_13(__pyx_t_2); if (unlikely(!__pyx_t_1)) goto __pyx_L10_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - index = 1; __pyx_t_8 = __pyx_t_13(__pyx_t_2); if (unlikely(!__pyx_t_8)) goto __pyx_L10_unpacking_failed; - __Pyx_GOTREF(__pyx_t_8); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_2), 2) < 0) __PYX_ERR(0, 2660, __pyx_L1_error) - __pyx_t_13 = NULL; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L11_unpacking_done; - __pyx_L10_unpacking_failed:; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_13 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 2660, __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, 2660, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_8); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2660, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_raster_x_size = __pyx_t_10; - __pyx_v_raster_y_size = __pyx_t_14; - - /* "pygeoprocessing/routing/routing.pyx":2663 - * - * # this outer loop searches for undefined channels - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * channel_raster_path_band, offset_only=True, largest_block=0): - * win_xsize = offset_dict['win_xsize'] - */ - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2663, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2663, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2664 - * # this outer loop searches for undefined channels - * for offset_dict in pygeoprocessing.iterblocks( - * channel_raster_path_band, offset_only=True, largest_block=0): # <<<<<<<<<<<<<< - * win_xsize = offset_dict['win_xsize'] - * win_ysize = offset_dict['win_ysize'] - */ - __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2663, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_INCREF(__pyx_v_channel_raster_path_band); - __Pyx_GIVEREF(__pyx_v_channel_raster_path_band); - PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_channel_raster_path_band); - __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2664, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 2664, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_largest_block, __pyx_int_0) < 0) __PYX_ERR(0, 2664, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2663 - * - * # this outer loop searches for undefined channels - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * channel_raster_path_band, offset_only=True, largest_block=0): - * win_xsize = offset_dict['win_xsize'] - */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_11, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2663, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { - __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0; - __pyx_t_15 = NULL; - } else { - __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2663, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_15 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2663, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - for (;;) { - if (likely(!__pyx_t_15)) { - if (likely(PyList_CheckExact(__pyx_t_1))) { - if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 2663, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2663, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } else { - if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 2663, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2663, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } - } else { - __pyx_t_2 = __pyx_t_15(__pyx_t_1); - if (unlikely(!__pyx_t_2)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 2663, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XDECREF_SET(__pyx_v_offset_dict, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2665 - * for offset_dict in pygeoprocessing.iterblocks( - * channel_raster_path_band, offset_only=True, largest_block=0): - * win_xsize = offset_dict['win_xsize'] # <<<<<<<<<<<<<< - * win_ysize = offset_dict['win_ysize'] - * xoff = offset_dict['xoff'] - */ - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2665, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2665, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_win_xsize = __pyx_t_14; - - /* "pygeoprocessing/routing/routing.pyx":2666 - * channel_raster_path_band, 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_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2666, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2666, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_win_ysize = __pyx_t_14; - - /* "pygeoprocessing/routing/routing.pyx":2667 - * win_xsize = offset_dict['win_xsize'] - * win_ysize = offset_dict['win_ysize'] - * xoff = offset_dict['xoff'] # <<<<<<<<<<<<<< - * yoff = offset_dict['yoff'] - * - */ - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_xoff); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2667, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2667, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_xoff = __pyx_t_14; - - /* "pygeoprocessing/routing/routing.pyx":2668 - * win_ysize = offset_dict['win_ysize'] - * xoff = offset_dict['xoff'] - * yoff = offset_dict['yoff'] # <<<<<<<<<<<<<< - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - */ - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_yoff); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2668, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2668, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_yoff = __pyx_t_14; - - /* "pygeoprocessing/routing/routing.pyx":2670 - * yoff = offset_dict['yoff'] - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - */ - __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":2671 - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( - */ - __pyx_v_last_log_time = time(NULL); - - /* "pygeoprocessing/routing/routing.pyx":2672 - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size # <<<<<<<<<<<<<< - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( - * raster_x_size * raster_y_size)) - */ - __pyx_t_2 = __Pyx_PyInt_From_int((__pyx_v_xoff + (__pyx_v_yoff * __pyx_v_raster_x_size))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2672, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_XDECREF_SET(__pyx_v_current_pixel, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2673 - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< - * raster_x_size * raster_y_size)) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2673, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_info); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2673, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = PyNumber_Multiply(__pyx_float_100_0, __pyx_v_current_pixel); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2673, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - - /* "pygeoprocessing/routing/routing.pyx":2674 - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( - * raster_x_size * raster_y_size)) # <<<<<<<<<<<<<< - * - * # make a buffer big enough to capture block and boundaries around it - */ - __pyx_t_7 = PyFloat_FromDouble(((float)(__pyx_v_raster_x_size * __pyx_v_raster_y_size))); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2673, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - - /* "pygeoprocessing/routing/routing.pyx":2673 - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< - * raster_x_size * raster_y_size)) - * - */ - __pyx_t_9 = __Pyx_PyNumber_Divide(__pyx_t_11, __pyx_t_7); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2673, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - __pyx_t_14 = 0; - 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); - __pyx_t_14 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_kp_u_1f_complete, __pyx_t_9}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2673, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_2); - __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_7, __pyx_kp_u_1f_complete, __pyx_t_9}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2673, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } else - #endif - { - __pyx_t_11 = PyTuple_New(2+__pyx_t_14); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2673, __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_INCREF(__pyx_kp_u_1f_complete); - __Pyx_GIVEREF(__pyx_kp_u_1f_complete); - PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_14, __pyx_kp_u_1f_complete); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_14, __pyx_t_9); - __pyx_t_9 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_11, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2673, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2670 - * yoff = offset_dict['yoff'] - * - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2677 - * - * # 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2677, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2677, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2678 - * # 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_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2678, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2678, __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_u_win_xsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2678, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_9 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2678, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2678, __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_9); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_9); - __pyx_t_11 = 0; - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2677 - * - * # 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 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2677, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2679 - * 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_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2679, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_numpy); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2679, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_uint8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2679, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 2679, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2677 - * - * # 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_7 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_9, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2677, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2677, __pyx_L1_error) - __pyx_t_16 = ((PyArrayObject *)__pyx_t_7); - { - __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, 2677, __pyx_L1_error) - } - __pyx_t_16 = 0; - __Pyx_XDECREF_SET(__pyx_v_channel_buffer_array, ((PyArrayObject *)__pyx_t_7)); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2680 - * (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_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_numpy); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2680, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2680, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2681 - * 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_7 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2681, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_9 = __Pyx_PyInt_AddObjC(__pyx_t_7, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2681, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2681, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyInt_AddObjC(__pyx_t_7, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2681, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2681, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_8); - __pyx_t_9 = 0; - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2680 - * (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_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2680, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2682 - * 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_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2682, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_numpy); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2682, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_int32); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2682, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_11) < 0) __PYX_ERR(0, 2682, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2680 - * (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_11 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2680, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2680, __pyx_L1_error) - __pyx_t_20 = ((PyArrayObject *)__pyx_t_11); - { - __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, 2680, __pyx_L1_error) - } - __pyx_t_20 = 0; - __Pyx_XDECREF_SET(__pyx_v_flow_dir_buffer_array, ((PyArrayObject *)__pyx_t_11)); - __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2683 - * (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__7, __pyx_int_0) < 0)) __PYX_ERR(0, 2683, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2684 - * 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__7, __pyx_int_0) < 0)) __PYX_ERR(0, 2684, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2688 - * # 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_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_generate_read_bounds); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2688, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - - /* "pygeoprocessing/routing/routing.pyx":2689 - * # 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_8 = __Pyx_PyInt_From_int(__pyx_v_raster_x_size); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2689, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_raster_y_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2689, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_9 = NULL; - __pyx_t_14 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_9); - __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[4] = {__pyx_t_9, __pyx_v_offset_dict, __pyx_t_8, __pyx_t_2}; - __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_14, 3+__pyx_t_14); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2688, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[4] = {__pyx_t_9, __pyx_v_offset_dict, __pyx_t_8, __pyx_t_2}; - __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_14, 3+__pyx_t_14); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2688, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else - #endif - { - __pyx_t_21 = PyTuple_New(3+__pyx_t_14); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2688, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_21); - if (__pyx_t_9) { - __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_21, 0, __pyx_t_9); __pyx_t_9 = 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_8); - PyTuple_SET_ITEM(__pyx_t_21, 1+__pyx_t_14, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_21, 2+__pyx_t_14, __pyx_t_2); - __pyx_t_8 = 0; - __pyx_t_2 = 0; - __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_21, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2688, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_11))) || (PyList_CheckExact(__pyx_t_11))) { - PyObject* sequence = __pyx_t_11; - 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, 2688, __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_21 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_7 = PyList_GET_ITEM(sequence, 0); - __pyx_t_21 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(__pyx_t_21); - #else - __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2688, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_21 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2688, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_21); - #endif - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_2 = PyObject_GetIter(__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2688, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_13 = Py_TYPE(__pyx_t_2)->tp_iternext; - index = 0; __pyx_t_7 = __pyx_t_13(__pyx_t_2); if (unlikely(!__pyx_t_7)) goto __pyx_L15_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - index = 1; __pyx_t_21 = __pyx_t_13(__pyx_t_2); if (unlikely(!__pyx_t_21)) goto __pyx_L15_unpacking_failed; - __Pyx_GOTREF(__pyx_t_21); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_2), 2) < 0) __PYX_ERR(0, 2688, __pyx_L1_error) - __pyx_t_13 = NULL; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L16_unpacking_done; - __pyx_L15_unpacking_failed:; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_13 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 2688, __pyx_L1_error) - __pyx_L16_unpacking_done:; - } - - /* "pygeoprocessing/routing/routing.pyx":2688 - * # 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_7))) || (PyList_CheckExact(__pyx_t_7))) { - PyObject* sequence = __pyx_t_7; - 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, 2688, __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_8 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_9 = PyTuple_GET_ITEM(sequence, 2); - __pyx_t_22 = PyTuple_GET_ITEM(sequence, 3); - } else { - __pyx_t_2 = PyList_GET_ITEM(sequence, 0); - __pyx_t_8 = PyList_GET_ITEM(sequence, 1); - __pyx_t_9 = PyList_GET_ITEM(sequence, 2); - __pyx_t_22 = PyList_GET_ITEM(sequence, 3); - } - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(__pyx_t_22); - #else - { - Py_ssize_t i; - PyObject** temps[4] = {&__pyx_t_2,&__pyx_t_8,&__pyx_t_9,&__pyx_t_22}; - for (i=0; i < 4; i++) { - PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 2688, __pyx_L1_error) - __Pyx_GOTREF(item); - *(temps[i]) = item; - } - } - #endif - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else { - Py_ssize_t index = -1; - PyObject** temps[4] = {&__pyx_t_2,&__pyx_t_8,&__pyx_t_9,&__pyx_t_22}; - __pyx_t_23 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 2688, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_23); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 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, 2688, __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, 2688, __pyx_L1_error) - __pyx_L18_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v_xa, __pyx_t_2); - __pyx_t_2 = 0; - __Pyx_XDECREF_SET(__pyx_v_xb, __pyx_t_8); - __pyx_t_8 = 0; - __Pyx_XDECREF_SET(__pyx_v_ya, __pyx_t_9); - __pyx_t_9 = 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":2690 - * (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, 2690, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_21); - - /* "pygeoprocessing/routing/routing.pyx":2691 - * 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, 2691, __pyx_L1_error) - } - if (likely(PyDict_CheckExact(__pyx_v_modified_offset_dict))) { - __pyx_t_7 = PyDict_Copy(__pyx_v_modified_offset_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2691, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - } else { - __pyx_t_7 = PyObject_CallFunctionObjArgs((PyObject*)&PyDict_Type, __pyx_v_modified_offset_dict, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2690, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - } - - /* "pygeoprocessing/routing/routing.pyx":2690 - * (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_7); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2690, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_22); - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2691 - * 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_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_22, __pyx_n_s_astype); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2691, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_22, __pyx_n_s_numpy); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2691, __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, 2691, __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_7))) { - __pyx_t_22 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_22)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_22); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_11 = (__pyx_t_22) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_22, __pyx_t_21) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_21); - __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2691, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2690 - * (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 = PySlice_New(__pyx_v_ya, __pyx_v_yb, Py_None); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2690, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_21 = PySlice_New(__pyx_v_xa, __pyx_v_xb, Py_None); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2690, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_21); - __pyx_t_22 = PyTuple_New(2); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2690, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_22); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_22, 0, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_21); - PyTuple_SET_ITEM(__pyx_t_22, 1, __pyx_t_21); - __pyx_t_7 = 0; - __pyx_t_21 = 0; - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_channel_buffer_array), __pyx_t_22, __pyx_t_11) < 0)) __PYX_ERR(0, 2690, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2693 - * **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_22 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_mfd_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2693, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_22); - - /* "pygeoprocessing/routing/routing.pyx":2694 - * - * 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, 2694, __pyx_L1_error) - } - if (likely(PyDict_CheckExact(__pyx_v_modified_offset_dict))) { - __pyx_t_21 = PyDict_Copy(__pyx_v_modified_offset_dict); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2694, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_21); - } else { - __pyx_t_21 = PyObject_CallFunctionObjArgs((PyObject*)&PyDict_Type, __pyx_v_modified_offset_dict, NULL); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2693, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_21); - } - - /* "pygeoprocessing/routing/routing.pyx":2693 - * **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_7 = __Pyx_PyObject_Call(__pyx_t_22, __pyx_empty_tuple, __pyx_t_21); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2693, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2694 - * - * 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_21 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_astype); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2694, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_21); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_numpy); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2694, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_22 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_int32); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2694, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_22); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_21))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_21); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_21); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_21, function); - } - } - __pyx_t_11 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_21, __pyx_t_7, __pyx_t_22) : __Pyx_PyObject_CallOneArg(__pyx_t_21, __pyx_t_22); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; - if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2694, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2693 - * **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 = PySlice_New(__pyx_v_ya, __pyx_v_yb, Py_None); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2693, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_21); - __pyx_t_22 = PySlice_New(__pyx_v_xa, __pyx_v_xb, Py_None); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2693, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_22); - __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2693, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_21); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_21); - __Pyx_GIVEREF(__pyx_t_22); - PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_22); - __pyx_t_21 = 0; - __pyx_t_22 = 0; - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_buffer_array), __pyx_t_7, __pyx_t_11) < 0)) __PYX_ERR(0, 2693, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2697 - * - * # ensure these are set for the complier - * xi_n = -1 # <<<<<<<<<<<<<< - * yi_n = -1 - * - */ - __pyx_v_xi_n = -1; - - /* "pygeoprocessing/routing/routing.pyx":2698 - * # 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":2701 - * - * # 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":2702 - * # 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":2703 - * 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":2704 - * 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":2706 - * 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, 2706, __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":2707 - * - * 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":2709 - * 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":2706 - * 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":2711 - * continue - * - * if flow_dir_buffer_array[yi, xi] == 0: # <<<<<<<<<<<<<< - * # nodata flow, so we skip - * continue - */ - __pyx_t_29 = __pyx_v_yi; - __pyx_t_28 = __pyx_v_xi; - __pyx_t_30 = -1; - if (__pyx_t_29 < 0) { - __pyx_t_29 += __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].shape; - if (unlikely(__pyx_t_29 < 0)) __pyx_t_30 = 0; - } else if (unlikely(__pyx_t_29 >= __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].shape)) __pyx_t_30 = 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_30 = 1; - } else if (unlikely(__pyx_t_28 >= __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, 2711, __pyx_L1_error) - } - __pyx_t_5 = (((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].strides, __pyx_t_28, __pyx_pybuffernd_flow_dir_buffer_array.diminfo[1].strides)) == 0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":2713 - * if flow_dir_buffer_array[yi, xi] == 0: - * # nodata flow, so we skip - * continue # <<<<<<<<<<<<<< - * - * if visited_managed_raster.get(xi_root, yi_root) == 0: - */ - goto __pyx_L21_continue; - - /* "pygeoprocessing/routing/routing.pyx":2711 - * continue - * - * if flow_dir_buffer_array[yi, xi] == 0: # <<<<<<<<<<<<<< - * # nodata flow, so we skip - * continue - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2715 - * continue - * - * if visited_managed_raster.get(xi_root, yi_root) == 0: # <<<<<<<<<<<<<< - * visited_managed_raster.set(xi_root, yi_root, 1) - * # arguments are x,y position of pixel, then last D8 flow - */ - __pyx_t_5 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_visited_managed_raster, __pyx_v_xi_root, __pyx_v_yi_root) == 0.0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":2716 - * - * if visited_managed_raster.get(xi_root, yi_root) == 0: - * visited_managed_raster.set(xi_root, yi_root, 1) # <<<<<<<<<<<<<< - * # arguments are x,y position of pixel, then last D8 flow - * # direction processed (0-7), and last is the running - */ - __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_visited_managed_raster, __pyx_v_xi_root, __pyx_v_yi_root, 1.0); - - /* "pygeoprocessing/routing/routing.pyx":2722 - * # initialized to nodata - * distance_to_channel_stack.push( - * FlowPixelType(xi_root, yi_root, 0, distance_nodata)) # <<<<<<<<<<<<<< - * - * while not distance_to_channel_stack.empty(): - */ - __pyx_t_31.xi = __pyx_v_xi_root; - __pyx_t_31.yi = __pyx_v_yi_root; - __pyx_t_31.last_flow_dir = 0; - __pyx_t_31.value = __pyx_v_distance_nodata; - - /* "pygeoprocessing/routing/routing.pyx":2721 - * # accumulation distance accumulated by this pixel so far - * # initialized to nodata - * distance_to_channel_stack.push( # <<<<<<<<<<<<<< - * FlowPixelType(xi_root, yi_root, 0, distance_nodata)) - * - */ - __pyx_v_distance_to_channel_stack.push(__pyx_t_31); - - /* "pygeoprocessing/routing/routing.pyx":2715 - * continue - * - * if visited_managed_raster.get(xi_root, yi_root) == 0: # <<<<<<<<<<<<<< - * visited_managed_raster.set(xi_root, yi_root, 1) - * # arguments are x,y position of pixel, then last D8 flow - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2724 - * FlowPixelType(xi_root, yi_root, 0, distance_nodata)) - * - * 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":2725 - * - * 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":2726 - * 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":2728 - * 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":2729 - * 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":2730 - * 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":2732 - * distance_to_channel_managed_raster.set( - * pixel.xi, pixel.yi, 0) - * continue # <<<<<<<<<<<<<< - * - * compressed_flow_dir = ( - */ - goto __pyx_L26_continue; - - /* "pygeoprocessing/routing/routing.pyx":2729 - * 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":2735 - * - * compressed_flow_dir = ( - * 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":2738 - * 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":2739 - * - * 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":2740 - * 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":2742 - * 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":2743 - * compressed_flow_dir >> (i_n * 4)) - * if flow_dir_weight == 0: - * continue # <<<<<<<<<<<<<< - * - * xi_n = pixel.xi+D8_XOFFSET[i_n] - */ - goto __pyx_L29_continue; - - /* "pygeoprocessing/routing/routing.pyx":2742 - * flow_dir_weight = 0xF & ( - * compressed_flow_dir >> (i_n * 4)) - * if flow_dir_weight == 0: # <<<<<<<<<<<<<< - * continue - * - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2745 - * continue - * - * xi_n = pixel.xi+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< - * yi_n = pixel.yi+D8_YOFFSET[i_n] - * - */ - __pyx_v_xi_n = (__pyx_v_pixel.xi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":2746 - * - * xi_n = pixel.xi+D8_XOFFSET[i_n] - * yi_n = pixel.yi+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< - * - * if (xi_n < 0 or xi_n >= raster_x_size or - */ - __pyx_v_yi_n = (__pyx_v_pixel.yi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":2748 - * yi_n = pixel.yi+D8_YOFFSET[i_n] - * - * 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":2749 - * - * 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":2748 - * yi_n = pixel.yi+D8_YOFFSET[i_n] - * - * 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":2750 - * if (xi_n < 0 or xi_n >= raster_x_size or - * yi_n < 0 or yi_n >= raster_y_size): - * continue # <<<<<<<<<<<<<< - * - * - */ - goto __pyx_L29_continue; - - /* "pygeoprocessing/routing/routing.pyx":2748 - * yi_n = pixel.yi+D8_YOFFSET[i_n] - * - * 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":2753 - * - * - * if visited_managed_raster.get(xi_n, yi_n) == 0: # <<<<<<<<<<<<<< - * visited_managed_raster.set(xi_n, yi_n, 1) - * preempted = 1 - */ - __pyx_t_5 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_visited_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n) == 0.0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":2754 - * - * if visited_managed_raster.get(xi_n, yi_n) == 0: - * visited_managed_raster.set(xi_n, yi_n, 1) # <<<<<<<<<<<<<< - * preempted = 1 - * pixel.last_flow_dir = i_n - */ - __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_visited_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n, 1.0); - - /* "pygeoprocessing/routing/routing.pyx":2755 - * if visited_managed_raster.get(xi_n, yi_n) == 0: - * visited_managed_raster.set(xi_n, yi_n, 1) - * preempted = 1 # <<<<<<<<<<<<<< - * pixel.last_flow_dir = i_n - * distance_to_channel_stack.push(pixel) - */ - __pyx_v_preempted = 1; - - /* "pygeoprocessing/routing/routing.pyx":2756 - * visited_managed_raster.set(xi_n, yi_n, 1) - * 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":2757 - * 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, distance_nodata)) - */ - __pyx_v_distance_to_channel_stack.push(__pyx_v_pixel); - - /* "pygeoprocessing/routing/routing.pyx":2759 - * distance_to_channel_stack.push(pixel) - * distance_to_channel_stack.push( - * FlowPixelType(xi_n, yi_n, 0, distance_nodata)) # <<<<<<<<<<<<<< - * break - * - */ - __pyx_t_31.xi = __pyx_v_xi_n; - __pyx_t_31.yi = __pyx_v_yi_n; - __pyx_t_31.last_flow_dir = 0; - __pyx_t_31.value = __pyx_v_distance_nodata; - - /* "pygeoprocessing/routing/routing.pyx":2758 - * pixel.last_flow_dir = i_n - * distance_to_channel_stack.push(pixel) - * distance_to_channel_stack.push( # <<<<<<<<<<<<<< - * FlowPixelType(xi_n, yi_n, 0, distance_nodata)) - * break - */ - __pyx_v_distance_to_channel_stack.push(__pyx_t_31); - - /* "pygeoprocessing/routing/routing.pyx":2760 - * distance_to_channel_stack.push( - * FlowPixelType(xi_n, yi_n, 0, distance_nodata)) - * break # <<<<<<<<<<<<<< - * - * n_distance = distance_to_channel_managed_raster.get( - */ - goto __pyx_L30_break; - - /* "pygeoprocessing/routing/routing.pyx":2753 - * - * - * if visited_managed_raster.get(xi_n, yi_n) == 0: # <<<<<<<<<<<<<< - * visited_managed_raster.set(xi_n, yi_n, 1) - * preempted = 1 - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2762 - * break - * - * 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":2765 - * xi_n, yi_n) - * - * if n_distance == distance_nodata: # <<<<<<<<<<<<<< - * # a channel was never found - * continue - */ - __pyx_t_5 = ((__pyx_v_n_distance == __pyx_v_distance_nodata) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":2767 - * if n_distance == distance_nodata: - * # a channel was never found - * continue # <<<<<<<<<<<<<< - * - * # if a weight is passed we use it directly and do - */ - goto __pyx_L29_continue; - - /* "pygeoprocessing/routing/routing.pyx":2765 - * xi_n, yi_n) - * - * if n_distance == distance_nodata: # <<<<<<<<<<<<<< - * # a channel was never found - * continue - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2774 - * # 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, 1e-8, 1e-5): - */ - __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":2775 - * # 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, 1e-8, 1e-5): - * 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":2776 - * if weight_raster is not None: - * weight_val = weight_raster.get(xi_n, yi_n) - * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * weight_val = 0.0 - * else: - */ - __pyx_t_4 = (__pyx_f_15pygeoprocessing_7routing_7routing__is_close(__pyx_v_weight_val, __pyx_v_weight_nodata, 1e-8, 1e-5) != 0); - if (__pyx_t_4) { - - /* "pygeoprocessing/routing/routing.pyx":2777 - * weight_val = weight_raster.get(xi_n, yi_n) - * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): - * weight_val = 0.0 # <<<<<<<<<<<<<< - * else: - * weight_val = (SQRT2 if i_n % 2 else 1) - */ - __pyx_v_weight_val = 0.0; - - /* "pygeoprocessing/routing/routing.pyx":2776 - * if weight_raster is not None: - * weight_val = weight_raster.get(xi_n, yi_n) - * if _is_close(weight_val, weight_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * weight_val = 0.0 - * else: - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2774 - * # 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, 1e-8, 1e-5): - */ - goto __pyx_L39; - } - - /* "pygeoprocessing/routing/routing.pyx":2779 - * weight_val = 0.0 - * else: - * weight_val = (SQRT2 if i_n % 2 else 1) # <<<<<<<<<<<<<< - * - * if pixel.value == distance_nodata: - */ - /*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_L39:; - - /* "pygeoprocessing/routing/routing.pyx":2781 - * weight_val = (SQRT2 if i_n % 2 else 1) - * - * if pixel.value == distance_nodata: # <<<<<<<<<<<<<< - * pixel.value = 0 - * pixel.value += flow_dir_weight * ( - */ - __pyx_t_4 = ((__pyx_v_pixel.value == __pyx_v_distance_nodata) != 0); - if (__pyx_t_4) { - - /* "pygeoprocessing/routing/routing.pyx":2782 - * - * if pixel.value == distance_nodata: - * pixel.value = 0 # <<<<<<<<<<<<<< - * pixel.value += flow_dir_weight * ( - * weight_val + n_distance) - */ - __pyx_v_pixel.value = 0.0; - - /* "pygeoprocessing/routing/routing.pyx":2781 - * weight_val = (SQRT2 if i_n % 2 else 1) - * - * if pixel.value == distance_nodata: # <<<<<<<<<<<<<< - * pixel.value = 0 - * pixel.value += flow_dir_weight * ( - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2783 - * if pixel.value == distance_nodata: - * pixel.value = 0 - * 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":2786 - * weight_val + n_distance) - * - * if preempted: # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_4 = (__pyx_v_preempted != 0); - if (__pyx_t_4) { - - /* "pygeoprocessing/routing/routing.pyx":2787 - * - * if preempted: - * continue # <<<<<<<<<<<<<< - * - * sum_of_flow_weights = 0 - */ - goto __pyx_L26_continue; - - /* "pygeoprocessing/routing/routing.pyx":2786 - * weight_val + n_distance) - * - * if preempted: # <<<<<<<<<<<<<< - * continue - * - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2789 - * 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":2790 - * - * 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":2791 - * 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":2794 - * 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":2795 - * - * 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, 2795, __pyx_L1_error) - } - __pyx_v_pixel.value = (__pyx_v_pixel.value / ((double)__pyx_v_sum_of_flow_weights)); - - /* "pygeoprocessing/routing/routing.pyx":2794 - * compressed_flow_dir >> (i_n * 4)) - * - * if sum_of_flow_weights != 0: # <<<<<<<<<<<<<< - * pixel.value = pixel.value / sum_of_flow_weights - * else: - */ - goto __pyx_L45; - } - - /* "pygeoprocessing/routing/routing.pyx":2797 - * 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_L45:; - - /* "pygeoprocessing/routing/routing.pyx":2798 - * 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":2663 - * - * # this outer loop searches for undefined channels - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * channel_raster_path_band, offset_only=True, largest_block=0): - * win_xsize = offset_dict['win_xsize'] - */ - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2801 - * pixel.xi, pixel.yi, pixel.value) - * - * distance_to_channel_managed_raster.close() # <<<<<<<<<<<<<< - * channel_managed_raster.close() - * flow_dir_mfd_managed_raster.close() - */ - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_distance_to_channel_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2801, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - } - } - __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2801, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2802 - * - * distance_to_channel_managed_raster.close() - * channel_managed_raster.close() # <<<<<<<<<<<<<< - * flow_dir_mfd_managed_raster.close() - * if weight_raster is not None: - */ - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_channel_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2802, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - } - } - __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2802, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2803 - * 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_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_flow_dir_mfd_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2803, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - } - } - __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2803, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2804 - * channel_managed_raster.close() - * flow_dir_mfd_managed_raster.close() - * if weight_raster is not None: # <<<<<<<<<<<<<< - * weight_raster.close() - * visited_managed_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":2805 - * flow_dir_mfd_managed_raster.close() - * if weight_raster is not None: - * weight_raster.close() # <<<<<<<<<<<<<< - * visited_managed_raster.close() - * shutil.rmtree(tmp_work_dir) - */ - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_weight_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2805, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - } - } - __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2805, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2804 - * channel_managed_raster.close() - * flow_dir_mfd_managed_raster.close() - * if weight_raster is not None: # <<<<<<<<<<<<<< - * weight_raster.close() - * visited_managed_raster.close() - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2806 - * if weight_raster is not None: - * weight_raster.close() - * visited_managed_raster.close() # <<<<<<<<<<<<<< - * shutil.rmtree(tmp_work_dir) - * LOGGER.info('%.1f%% complete', 100.0) - */ - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_visited_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2806, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - } - } - __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2806, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2807 - * weight_raster.close() - * visited_managed_raster.close() - * shutil.rmtree(tmp_work_dir) # <<<<<<<<<<<<<< - * LOGGER.info('%.1f%% complete', 100.0) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_shutil); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2807, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_rmtree); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2807, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_1 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_11, __pyx_v_tmp_work_dir) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_tmp_work_dir); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2807, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2808 - * visited_managed_raster.close() - * shutil.rmtree(tmp_work_dir) - * LOGGER.info('%.1f%% complete', 100.0) # <<<<<<<<<<<<<< - * - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2808, __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, 2808, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2808, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2544 - * - * - * 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(__pyx_v_tmp_work_dir); - __Pyx_XDECREF(__pyx_v_visited_raster_path); - __Pyx_XDECREF((PyObject *)__pyx_v_visited_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":2811 - * - * - * def extract_streams_mfd( # <<<<<<<<<<<<<< - * flow_accum_raster_path_band, flow_dir_mfd_path_band, - * double flow_threshold, target_stream_raster_path, - */ - -/* 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 raster_driver_creation_tuple (tuple): a tuple containing a GDAL driver\n name string as the first element and a GDAL creation options\n tuple/list as the second. Defaults to a GTiff driver tuple\n defined at geoprocessing.DEFAULT_GTIFF_CREATION_TUPLE_OPTION""S.\n\n Returns:\n None.\n "; -static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_17extract_streams_mfd = {"extract_streams_mfd", (PyCFunction)(void*)(PyCFunctionWithKeywords)__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_raster_driver_creation_tuple = 0; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 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_raster_driver_creation_tuple,0}; - PyObject* values[6] = {0,0,0,0,0,0}; - values[5] = __pyx_k__14; - 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, 2811, __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, 2811, __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, 2811, __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_raster_driver_creation_tuple); - 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, 2811, __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, 2813, __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, 2814, __pyx_L3_error) - } else { - __pyx_v_trace_threshold_proportion = ((double)1.0); - } - __pyx_v_raster_driver_creation_tuple = 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, 2811, __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_raster_driver_creation_tuple); - - /* 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_raster_driver_creation_tuple) { - 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_block_offsets_list = 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; - double __pyx_t_7; - PyObject *(*__pyx_t_8)(PyObject *); - int __pyx_t_9; - int __pyx_t_10; - PyObject *__pyx_t_11 = NULL; - 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("extract_streams_mfd", 0); - - /* "pygeoprocessing/routing/routing.pyx":2852 - * 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":2855 - * 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, 2855, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyUnicode_Format(__pyx_kp_u_trace_threshold_proportion_shoul, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2855, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2853 - * """ - * 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, 2853, __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, 2853, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2852 - * 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":2857 - * "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_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2857, __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, 2857, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2858 - * - * 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, 2858, __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); - } - } - __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2857, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __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":2859 - * 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_u_nodata); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2859, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pygeoprocessing/routing/routing.pyx":2860 - * 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, 2860, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = __Pyx_PyInt_SubtractObjC(__pyx_t_5, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2860, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2859 - * 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_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2859, __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_t_7 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_7 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 2859, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_flow_accum_nodata = __pyx_t_7; - - /* "pygeoprocessing/routing/routing.pyx":2861 - * 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":2864 - * - * 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_u_raster_size); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2864, __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, 2864, __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_3 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_4 = PyList_GET_ITEM(sequence, 0); - __pyx_t_3 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_3); - #else - __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2864, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2864, __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_6 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2864, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_6)->tp_iternext; - index = 0; __pyx_t_4 = __pyx_t_8(__pyx_t_6); if (unlikely(!__pyx_t_4)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_4); - index = 1; __pyx_t_3 = __pyx_t_8(__pyx_t_6); if (unlikely(!__pyx_t_3)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_6), 2) < 0) __PYX_ERR(0, 2864, __pyx_L1_error) - __pyx_t_8 = NULL; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - goto __pyx_L7_unpacking_done; - __pyx_L6_unpacking_failed:; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_8 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 2864, __pyx_L1_error) - __pyx_L7_unpacking_done:; - } - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2864, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2864, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_raster_x_size = __pyx_t_9; - __pyx_v_raster_y_size = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":2866 - * 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], - */ - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2866, __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, 2866, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2867 - * - * pygeoprocessing.new_raster_from_base( - * flow_accum_raster_path_band[0], target_stream_raster_path, # <<<<<<<<<<<<<< - * gdal.GDT_Byte, [stream_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) - */ - __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, 2867, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - - /* "pygeoprocessing/routing/routing.pyx":2868 - * pygeoprocessing.new_raster_from_base( - * flow_accum_raster_path_band[0], target_stream_raster_path, - * gdal.GDT_Byte, [stream_nodata], # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2868, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2868, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_v_stream_nodata); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2868, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_11 = PyList_New(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2868, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_GIVEREF(__pyx_t_4); - PyList_SET_ITEM(__pyx_t_11, 0, __pyx_t_4); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2866 - * 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], - */ - __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2866, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_4, 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_4, 1, __pyx_v_target_stream_raster_path); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_11); - __pyx_t_5 = 0; - __pyx_t_6 = 0; - __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2869 - * flow_accum_raster_path_band[0], target_stream_raster_path, - * gdal.GDT_Byte, [stream_nodata], - * raster_driver_creation_tuple=raster_driver_creation_tuple) # <<<<<<<<<<<<<< - * - * cdef _ManagedRaster flow_accum_mr = _ManagedRaster( - */ - __pyx_t_11 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2869, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_raster_driver_creation_tuple, __pyx_v_raster_driver_creation_tuple) < 0) __PYX_ERR(0, 2869, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2866 - * 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], - */ - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2866, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2872 - * - * 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_6 = __Pyx_GetItemInt(__pyx_v_flow_accum_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2872, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_flow_accum_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2872, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - - /* "pygeoprocessing/routing/routing.pyx":2871 - * raster_driver_creation_tuple=raster_driver_creation_tuple) - * - * 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_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2871, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_11); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_int_0); - __pyx_t_6 = 0; - __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_4, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2871, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_flow_accum_mr = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_11); - __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2873 - * 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_11 = PyTuple_New(3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2873, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_INCREF(__pyx_v_target_stream_raster_path); - __Pyx_GIVEREF(__pyx_v_target_stream_raster_path); - PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_target_stream_raster_path); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_int_1); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_11, 2, __pyx_int_1); - __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_11, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2873, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_v_stream_mr = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_4); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2876 - * 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_4 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2876, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2876, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - - /* "pygeoprocessing/routing/routing.pyx":2875 - * 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_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2875, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_11); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_int_0); - __pyx_t_4 = 0; - __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_6, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2875, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_flow_dir_mfd_mr = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_11); - __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2883 - * 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":2884 - * 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":2887 - * 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_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2887, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2887, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2888 - * - * 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_6 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2888, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_3 = NULL; - 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_11 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_6); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2887, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_t_11, __pyx_n_u_nodata); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2888, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2888, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_6 = __Pyx_PyInt_SubtractObjC(__pyx_t_11, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2888, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_PyObject_GetItem(__pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2888, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_11); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2888, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_v_flow_dir_nodata = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":2895 - * 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":2897 - * cdef time_t last_log_time = ctime(NULL) - * - * for block_offsets in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * (target_stream_raster_path, 1), offset_only=True): - * xoff = block_offsets['xoff'] - */ - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2897, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2897, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2898 - * - * for block_offsets in pygeoprocessing.iterblocks( - * (target_stream_raster_path, 1), offset_only=True): # <<<<<<<<<<<<<< - * xoff = block_offsets['xoff'] - * yoff = block_offsets['yoff'] - */ - __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2898, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_INCREF(__pyx_v_target_stream_raster_path); - __Pyx_GIVEREF(__pyx_v_target_stream_raster_path); - PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_target_stream_raster_path); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_int_1); - - /* "pygeoprocessing/routing/routing.pyx":2897 - * cdef time_t last_log_time = ctime(NULL) - * - * for block_offsets in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * (target_stream_raster_path, 1), offset_only=True): - * xoff = block_offsets['xoff'] - */ - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2897, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_11); - __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2898 - * - * for block_offsets in pygeoprocessing.iterblocks( - * (target_stream_raster_path, 1), offset_only=True): # <<<<<<<<<<<<<< - * xoff = block_offsets['xoff'] - * yoff = block_offsets['yoff'] - */ - __pyx_t_11 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2898, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 2898, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2897 - * cdef time_t last_log_time = ctime(NULL) - * - * for block_offsets in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * (target_stream_raster_path, 1), offset_only=True): - * xoff = block_offsets['xoff'] - */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, __pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2897, __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; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) { - __pyx_t_11 = __pyx_t_3; __Pyx_INCREF(__pyx_t_11); __pyx_t_12 = 0; - __pyx_t_13 = NULL; - } else { - __pyx_t_12 = -1; __pyx_t_11 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2897, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_13 = Py_TYPE(__pyx_t_11)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 2897, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - for (;;) { - if (likely(!__pyx_t_13)) { - if (likely(PyList_CheckExact(__pyx_t_11))) { - if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_11)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_11, __pyx_t_12); __Pyx_INCREF(__pyx_t_3); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 2897, __pyx_L1_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_11, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2897, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - } else { - if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_11)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_11, __pyx_t_12); __Pyx_INCREF(__pyx_t_3); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 2897, __pyx_L1_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_11, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2897, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - } - } else { - __pyx_t_3 = __pyx_t_13(__pyx_t_11); - 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, 2897, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_XDECREF_SET(__pyx_v_block_offsets, __pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2899 - * for block_offsets in pygeoprocessing.iterblocks( - * (target_stream_raster_path, 1), offset_only=True): - * xoff = block_offsets['xoff'] # <<<<<<<<<<<<<< - * yoff = block_offsets['yoff'] - * win_xsize = block_offsets['win_xsize'] - */ - __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_u_xoff); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2899, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2899, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_xoff = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":2900 - * (target_stream_raster_path, 1), 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_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_u_yoff); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2900, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2900, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_yoff = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":2901 - * 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_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2901, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2901, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_win_xsize = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":2902 - * 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_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2902, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2902, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_win_ysize = __pyx_t_10; - - /* "pygeoprocessing/routing/routing.pyx":2903 - * 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 > _LOGGING_PERIOD: - */ - __pyx_t_10 = __pyx_v_win_ysize; - __pyx_t_9 = __pyx_t_10; - for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_9; __pyx_t_14+=1) { - __pyx_v_yi = __pyx_t_14; - - /* "pygeoprocessing/routing/routing.pyx":2904 - * win_ysize = block_offsets['win_ysize'] - * for yi in range(win_ysize): - * yi_root = yi+yoff # <<<<<<<<<<<<<< - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * last_log_time = ctime(NULL) - */ - __pyx_v_yi_root = (__pyx_v_yi + __pyx_v_yoff); - - /* "pygeoprocessing/routing/routing.pyx":2905 - * for yi in range(win_ysize): - * yi_root = yi+yoff - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - */ - __pyx_t_1 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); - if (__pyx_t_1) { - - /* "pygeoprocessing/routing/routing.pyx":2906 - * yi_root = yi+yoff - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( - */ - __pyx_v_last_log_time = time(NULL); - - /* "pygeoprocessing/routing/routing.pyx":2907 - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size # <<<<<<<<<<<<<< - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( - * 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, 2907, __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":2908 - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< - * raster_x_size * raster_y_size)) - * for xi in range(win_xsize): - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2908, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_info); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2908, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyNumber_Multiply(__pyx_float_100_0, __pyx_v_current_pixel); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2908, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - - /* "pygeoprocessing/routing/routing.pyx":2909 - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( - * raster_x_size * raster_y_size)) # <<<<<<<<<<<<<< - * for xi in range(win_xsize): - * xi_root = xi+xoff - */ - __pyx_t_5 = PyFloat_FromDouble(((float)(__pyx_v_raster_x_size * __pyx_v_raster_y_size))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2908, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - - /* "pygeoprocessing/routing/routing.pyx":2908 - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( # <<<<<<<<<<<<<< - * raster_x_size * raster_y_size)) - * for xi in range(win_xsize): - */ - __pyx_t_15 = __Pyx_PyNumber_Divide(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2908, __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_t_5 = NULL; - __pyx_t_16 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - __pyx_t_16 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_kp_u_1f_complete, __pyx_t_15}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_16, 2+__pyx_t_16); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2908, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_kp_u_1f_complete, __pyx_t_15}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_16, 2+__pyx_t_16); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2908, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - } else - #endif - { - __pyx_t_4 = PyTuple_New(2+__pyx_t_16); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2908, __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_kp_u_1f_complete); - __Pyx_GIVEREF(__pyx_kp_u_1f_complete); - PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_16, __pyx_kp_u_1f_complete); - __Pyx_GIVEREF(__pyx_t_15); - PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_16, __pyx_t_15); - __pyx_t_15 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2908, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2905 - * for yi in range(win_ysize): - * yi_root = yi+yoff - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2910 - * LOGGER.info('%.1f%% complete', 100.0 * current_pixel / ( - * 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":2911 - * 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, 1e-8, 1e-5): - */ - __pyx_v_xi_root = (__pyx_v_xi + __pyx_v_xoff); - - /* "pygeoprocessing/routing/routing.pyx":2912 - * 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, 1e-8, 1e-5): - * 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":2913 - * xi_root = xi+xoff - * flow_accum = flow_accum_mr.get(xi_root, yi_root) - * if _is_close(flow_accum, flow_accum_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * 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, 1e-8, 1e-5) != 0); - if (__pyx_t_1) { - - /* "pygeoprocessing/routing/routing.pyx":2914 - * flow_accum = flow_accum_mr.get(xi_root, yi_root) - * if _is_close(flow_accum, flow_accum_nodata, 1e-8, 1e-5): - * continue # <<<<<<<<<<<<<< - * if stream_mr.get(xi_root, yi_root) != stream_nodata: - * continue - */ - goto __pyx_L13_continue; - - /* "pygeoprocessing/routing/routing.pyx":2913 - * xi_root = xi+xoff - * flow_accum = flow_accum_mr.get(xi_root, yi_root) - * if _is_close(flow_accum, flow_accum_nodata, 1e-8, 1e-5): # <<<<<<<<<<<<<< - * continue - * if stream_mr.get(xi_root, yi_root) != stream_nodata: - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2915 - * if _is_close(flow_accum, flow_accum_nodata, 1e-8, 1e-5): - * 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":2916 - * 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":2915 - * if _is_close(flow_accum, flow_accum_nodata, 1e-8, 1e-5): - * continue - * if stream_mr.get(xi_root, yi_root) != stream_nodata: # <<<<<<<<<<<<<< - * continue - * stream_mr.set(xi_root, yi_root, 0) - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2917 - * 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":2918 - * 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":2919 - * stream_mr.set(xi_root, yi_root, 0) - * if flow_accum < flow_threshold: - * continue # <<<<<<<<<<<<<< - * - * flow_dir_mfd = flow_dir_mfd_mr.get(xi_root, yi_root) - */ - goto __pyx_L13_continue; - - /* "pygeoprocessing/routing/routing.pyx":2918 - * continue - * stream_mr.set(xi_root, yi_root, 0) - * if flow_accum < flow_threshold: # <<<<<<<<<<<<<< - * continue - * - */ - } - - /* "pygeoprocessing/routing/routing.pyx":2921 - * continue - * - * flow_dir_mfd = 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":2922 - * - * flow_dir_mfd = 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":2923 - * flow_dir_mfd = 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":2924 - * 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":2926 - * if ((flow_dir_mfd >> (i_n * 4)) & 0xF) == 0: - * # no flow in that direction - * continue # <<<<<<<<<<<<<< - * xi_n = xi_root+D8_XOFFSET[i_n] - * yi_n = yi_root+D8_YOFFSET[i_n] - */ - goto __pyx_L18_continue; - - /* "pygeoprocessing/routing/routing.pyx":2924 - * 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":2927 - * # no flow in that direction - * continue - * xi_n = xi_root+D8_XOFFSET[i_n] # <<<<<<<<<<<<<< - * yi_n = yi_root+D8_YOFFSET[i_n] - * if (xi_n < 0 or xi_n >= raster_x_size or - */ - __pyx_v_xi_n = (__pyx_v_xi_root + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":2928 - * continue - * xi_n = xi_root+D8_XOFFSET[i_n] - * yi_n = yi_root+D8_YOFFSET[i_n] # <<<<<<<<<<<<<< - * 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_D8_YOFFSET[__pyx_v_i_n])); - - /* "pygeoprocessing/routing/routing.pyx":2929 - * xi_n = xi_root+D8_XOFFSET[i_n] - * yi_n = yi_root+D8_YOFFSET[i_n] - * 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":2930 - * yi_n = yi_root+D8_YOFFSET[i_n] - * 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":2929 - * xi_n = xi_root+D8_XOFFSET[i_n] - * yi_n = yi_root+D8_YOFFSET[i_n] - * 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":2932 - * 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":2933 - * # 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":2929 - * xi_n = xi_root+D8_XOFFSET[i_n] - * yi_n = yi_root+D8_YOFFSET[i_n] - * 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":2934 - * 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":2935 - * 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":2936 - * 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":2934 - * 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":2937 - * 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":2938 - * 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":2939 - * 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":2937 - * 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":2941 - * 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":2942 - * - * 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":2943 - * 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":2944 - * 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":2945 - * 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":2946 - * yi_n = open_set.front().yi - * open_set.pop() - * n_iterations += 1 # <<<<<<<<<<<<<< - * for i_sn in range(8): - * xi_sn = xi_n+D8_XOFFSET[i_sn] - */ - __pyx_v_n_iterations = (__pyx_v_n_iterations + 1); - - /* "pygeoprocessing/routing/routing.pyx":2947 - * open_set.pop() - * n_iterations += 1 - * for i_sn in range(8): # <<<<<<<<<<<<<< - * xi_sn = xi_n+D8_XOFFSET[i_sn] - * yi_sn = yi_n+D8_YOFFSET[i_sn] - */ - for (__pyx_t_19 = 0; __pyx_t_19 < 8; __pyx_t_19+=1) { - __pyx_v_i_sn = __pyx_t_19; - - /* "pygeoprocessing/routing/routing.pyx":2948 - * n_iterations += 1 - * for i_sn in range(8): - * xi_sn = xi_n+D8_XOFFSET[i_sn] # <<<<<<<<<<<<<< - * yi_sn = yi_n+D8_YOFFSET[i_sn] - * if (xi_sn < 0 or xi_sn >= raster_x_size or - */ - __pyx_v_xi_sn = (__pyx_v_xi_n + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_sn])); - - /* "pygeoprocessing/routing/routing.pyx":2949 - * for i_sn in range(8): - * xi_sn = xi_n+D8_XOFFSET[i_sn] - * yi_sn = yi_n+D8_YOFFSET[i_sn] # <<<<<<<<<<<<<< - * 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_D8_YOFFSET[__pyx_v_i_sn])); - - /* "pygeoprocessing/routing/routing.pyx":2950 - * xi_sn = xi_n+D8_XOFFSET[i_sn] - * yi_sn = yi_n+D8_YOFFSET[i_sn] - * 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":2951 - * yi_sn = yi_n+D8_YOFFSET[i_sn] - * if (xi_sn < 0 or xi_sn >= raster_x_size or - * yi_sn < 0 or yi_sn >= raster_y_size): # <<<<<<<<<<<<<< - * continue - * flow_dir_mfd = 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":2950 - * xi_sn = xi_n+D8_XOFFSET[i_sn] - * yi_sn = yi_n+D8_YOFFSET[i_sn] - * 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":2952 - * if (xi_sn < 0 or xi_sn >= raster_x_size or - * yi_sn < 0 or yi_sn >= raster_y_size): - * continue # <<<<<<<<<<<<<< - * flow_dir_mfd = flow_dir_mfd_mr.get(xi_sn, yi_sn) - * if flow_dir_mfd == flow_dir_nodata: - */ - goto __pyx_L30_continue; - - /* "pygeoprocessing/routing/routing.pyx":2950 - * xi_sn = xi_n+D8_XOFFSET[i_sn] - * yi_sn = yi_n+D8_YOFFSET[i_sn] - * 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":2953 - * yi_sn < 0 or yi_sn >= raster_y_size): - * continue - * flow_dir_mfd = 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":2954 - * continue - * flow_dir_mfd = 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":2955 - * flow_dir_mfd = 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":2954 - * continue - * flow_dir_mfd = 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":2957 - * continue - * if ((flow_dir_mfd >> - * (D8_REVERSE_DIRECTION[i_sn] * 4)) & 0xF) > 0: # <<<<<<<<<<<<<< - * # upstream pixel flows into this one - * stream_val = 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":2956 - * 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":2959 - * (D8_REVERSE_DIRECTION[i_sn] * 4)) & 0xF) > 0: - * # upstream pixel flows into this one - * stream_val = 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":2960 - * # upstream pixel flows into this one - * stream_val = 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":2961 - * stream_val = 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":2963 - * 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":2964 - * 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":2966 - * 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":2965 - * 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":2970 - * # 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":2969 - * # 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":2971 - * 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":2972 - * 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":2973 - * while backtrace_set.size() > 0: - * xi_bn = backtrace_set.front().xi - * yi_bn = backtrace_set.front().yi # <<<<<<<<<<<<<< - * backtrace_set.pop() - * flow_dir_mfd = ( - */ - __pyx_t_21 = __pyx_v_backtrace_set.front().yi; - __pyx_v_yi_bn = __pyx_t_21; - - /* "pygeoprocessing/routing/routing.pyx":2974 - * xi_bn = backtrace_set.front().xi - * yi_bn = backtrace_set.front().yi - * backtrace_set.pop() # <<<<<<<<<<<<<< - * flow_dir_mfd = ( - * flow_dir_mfd_mr.get(xi_bn, yi_bn)) - */ - __pyx_v_backtrace_set.pop(); - - /* "pygeoprocessing/routing/routing.pyx":2975 - * yi_bn = backtrace_set.front().yi - * backtrace_set.pop() - * flow_dir_mfd = ( # <<<<<<<<<<<<<< - * 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":2977 - * flow_dir_mfd = ( - * 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+D8_XOFFSET[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":2978 - * 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+D8_XOFFSET[i_sn] - * yi_sn = yi_bn+D8_YOFFSET[i_sn] - */ - __pyx_t_1 = ((((__pyx_v_flow_dir_mfd >> (__pyx_v_i_sn * 4)) & 0xF) > 0) != 0); - if (__pyx_t_1) { - - /* "pygeoprocessing/routing/routing.pyx":2979 - * for i_sn in range(8): - * if (flow_dir_mfd >> (i_sn*4)) & 0xF > 0: - * xi_sn = xi_bn+D8_XOFFSET[i_sn] # <<<<<<<<<<<<<< - * yi_sn = yi_bn+D8_YOFFSET[i_sn] - * if (xi_sn < 0 or xi_sn >= raster_x_size or - */ - __pyx_v_xi_sn = (__pyx_v_xi_bn + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_i_sn])); - - /* "pygeoprocessing/routing/routing.pyx":2980 - * if (flow_dir_mfd >> (i_sn*4)) & 0xF > 0: - * xi_sn = xi_bn+D8_XOFFSET[i_sn] - * yi_sn = yi_bn+D8_YOFFSET[i_sn] # <<<<<<<<<<<<<< - * 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_D8_YOFFSET[__pyx_v_i_sn])); - - /* "pygeoprocessing/routing/routing.pyx":2981 - * xi_sn = xi_bn+D8_XOFFSET[i_sn] - * yi_sn = yi_bn+D8_YOFFSET[i_sn] - * 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":2982 - * yi_sn = yi_bn+D8_YOFFSET[i_sn] - * 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":2981 - * xi_sn = xi_bn+D8_XOFFSET[i_sn] - * yi_sn = yi_bn+D8_YOFFSET[i_sn] - * 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":2983 - * 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":2981 - * xi_sn = xi_bn+D8_XOFFSET[i_sn] - * yi_sn = yi_bn+D8_YOFFSET[i_sn] - * 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":2984 - * 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":2985 - * 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":2987 - * 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":2986 - * 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":2984 - * 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":2978 - * 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+D8_XOFFSET[i_sn] - * yi_sn = yi_bn+D8_YOFFSET[i_sn] - */ - } - __pyx_L43_continue:; - } - } - - /* "pygeoprocessing/routing/routing.pyx":2963 - * 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":2988 - * 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":2989 - * 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":2991 - * 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":2990 - * 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":2988 - * 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":2960 - * # upstream pixel flows into this one - * stream_val = 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":2956 - * 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":2897 - * cdef time_t last_log_time = ctime(NULL) - * - * for block_offsets in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * (target_stream_raster_path, 1), offset_only=True): - * xoff = block_offsets['xoff'] - */ - } - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2993 - * CoordinateType(xi_sn, yi_sn)) - * - * stream_mr.close() # <<<<<<<<<<<<<< - * LOGGER.info('filter out incomplete divergent streams') - * block_offsets_list = list(pygeoprocessing.iterblocks( - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_stream_mr), __pyx_n_s_close); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2993, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_11 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2993, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2994 - * - * stream_mr.close() - * LOGGER.info('filter out incomplete divergent streams') # <<<<<<<<<<<<<< - * block_offsets_list = list(pygeoprocessing.iterblocks( - * (target_stream_raster_path, 1), offset_only=True)) - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2994, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_info); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2994, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(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); - } - } - __pyx_t_11 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_3, __pyx_kp_u_filter_out_incomplete_divergent) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_kp_u_filter_out_incomplete_divergent); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2994, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2995 - * stream_mr.close() - * LOGGER.info('filter out incomplete divergent streams') - * block_offsets_list = list(pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * (target_stream_raster_path, 1), offset_only=True)) - * stream_raster = gdal.OpenEx( - */ - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2995, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2995, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2996 - * LOGGER.info('filter out incomplete divergent streams') - * block_offsets_list = list(pygeoprocessing.iterblocks( - * (target_stream_raster_path, 1), offset_only=True)) # <<<<<<<<<<<<<< - * stream_raster = gdal.OpenEx( - * target_stream_raster_path, gdal.OF_RASTER | gdal.GA_Update) - */ - __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2996, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_INCREF(__pyx_v_target_stream_raster_path); - __Pyx_GIVEREF(__pyx_v_target_stream_raster_path); - PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_target_stream_raster_path); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_int_1); - - /* "pygeoprocessing/routing/routing.pyx":2995 - * stream_mr.close() - * LOGGER.info('filter out incomplete divergent streams') - * block_offsets_list = list(pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * (target_stream_raster_path, 1), offset_only=True)) - * stream_raster = gdal.OpenEx( - */ - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2995, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_11); - __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2996 - * LOGGER.info('filter out incomplete divergent streams') - * block_offsets_list = list(pygeoprocessing.iterblocks( - * (target_stream_raster_path, 1), offset_only=True)) # <<<<<<<<<<<<<< - * stream_raster = gdal.OpenEx( - * target_stream_raster_path, gdal.OF_RASTER | gdal.GA_Update) - */ - __pyx_t_11 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2996, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 2996, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2995 - * stream_mr.close() - * LOGGER.info('filter out incomplete divergent streams') - * block_offsets_list = list(pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * (target_stream_raster_path, 1), offset_only=True)) - * stream_raster = gdal.OpenEx( - */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_3, __pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2995, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = PySequence_List(__pyx_t_4); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2995, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_block_offsets_list = ((PyObject*)__pyx_t_11); - __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2997 - * block_offsets_list = list(pygeoprocessing.iterblocks( - * (target_stream_raster_path, 1), offset_only=True)) - * stream_raster = gdal.OpenEx( # <<<<<<<<<<<<<< - * target_stream_raster_path, gdal.OF_RASTER | gdal.GA_Update) - * stream_band = stream_raster.GetRasterBand(1) - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2997, __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, 2997, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2998 - * (target_stream_raster_path, 1), offset_only=True)) - * stream_raster = gdal.OpenEx( - * target_stream_raster_path, gdal.OF_RASTER | gdal.GA_Update) # <<<<<<<<<<<<<< - * stream_band = stream_raster.GetRasterBand(1) - * for block_offsets in block_offsets_list: - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2998, __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, 2998, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2998, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_GA_Update); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2998, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyNumber_Or(__pyx_t_6, __pyx_t_15); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2998, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_15 = NULL; - __pyx_t_10 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_15)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_15); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - __pyx_t_10 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_v_target_stream_raster_path, __pyx_t_4}; - __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2997, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_GOTREF(__pyx_t_11); - __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_15, __pyx_v_target_stream_raster_path, __pyx_t_4}; - __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2997, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - { - __pyx_t_6 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2997, __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_10, __pyx_v_target_stream_raster_path); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_10, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2997, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_stream_raster = __pyx_t_11; - __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2999 - * stream_raster = gdal.OpenEx( - * target_stream_raster_path, gdal.OF_RASTER | gdal.GA_Update) - * stream_band = stream_raster.GetRasterBand(1) # <<<<<<<<<<<<<< - * for block_offsets in block_offsets_list: - * stream_array = stream_band.ReadAsArray(**block_offsets) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2999, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_11 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_6, __pyx_int_1) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_int_1); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2999, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_stream_band = __pyx_t_11; - __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3000 - * target_stream_raster_path, gdal.OF_RASTER | gdal.GA_Update) - * stream_band = stream_raster.GetRasterBand(1) - * for block_offsets in block_offsets_list: # <<<<<<<<<<<<<< - * stream_array = stream_band.ReadAsArray(**block_offsets) - * stream_array[stream_array == 2] = 0 - */ - __pyx_t_11 = __pyx_v_block_offsets_list; __Pyx_INCREF(__pyx_t_11); __pyx_t_12 = 0; - for (;;) { - if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_11)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_11, __pyx_t_12); __Pyx_INCREF(__pyx_t_3); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 3000, __pyx_L1_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_11, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3000, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - __Pyx_XDECREF_SET(__pyx_v_block_offsets, __pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3001 - * stream_band = stream_raster.GetRasterBand(1) - * for block_offsets in block_offsets_list: - * stream_array = stream_band.ReadAsArray(**block_offsets) # <<<<<<<<<<<<<< - * stream_array[stream_array == 2] = 0 - * stream_band.WriteArray( - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3001, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (unlikely(__pyx_v_block_offsets == Py_None)) { - PyErr_SetString(PyExc_TypeError, "argument after ** must be a mapping, not NoneType"); - __PYX_ERR(0, 3001, __pyx_L1_error) - } - if (likely(PyDict_CheckExact(__pyx_v_block_offsets))) { - __pyx_t_6 = PyDict_Copy(__pyx_v_block_offsets); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3001, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - } else { - __pyx_t_6 = PyObject_CallFunctionObjArgs((PyObject*)&PyDict_Type, __pyx_v_block_offsets, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3001, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - } - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_empty_tuple, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3001, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF_SET(__pyx_v_stream_array, __pyx_t_4); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3002 - * for block_offsets in block_offsets_list: - * stream_array = stream_band.ReadAsArray(**block_offsets) - * stream_array[stream_array == 2] = 0 # <<<<<<<<<<<<<< - * stream_band.WriteArray( - * stream_array, xoff=block_offsets['xoff'], - */ - __pyx_t_4 = __Pyx_PyInt_EqObjC(__pyx_v_stream_array, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3002, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (unlikely(PyObject_SetItem(__pyx_v_stream_array, __pyx_t_4, __pyx_int_0) < 0)) __PYX_ERR(0, 3002, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3003 - * 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_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_band, __pyx_n_s_WriteArray); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3003, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - - /* "pygeoprocessing/routing/routing.pyx":3004 - * stream_array[stream_array == 2] = 0 - * stream_band.WriteArray( - * stream_array, xoff=block_offsets['xoff'], # <<<<<<<<<<<<<< - * yoff=block_offsets['yoff']) - * stream_band = None - */ - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3003, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_INCREF(__pyx_v_stream_array); - __Pyx_GIVEREF(__pyx_v_stream_array); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_stream_array); - __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3004, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_15 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_u_xoff); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3004, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_xoff, __pyx_t_15) < 0) __PYX_ERR(0, 3004, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3005 - * 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_u_yoff); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3005, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_yoff, __pyx_t_15) < 0) __PYX_ERR(0, 3004, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3003 - * 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_4, __pyx_t_6, __pyx_t_3); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3003, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3000 - * target_stream_raster_path, gdal.OF_RASTER | gdal.GA_Update) - * stream_band = stream_raster.GetRasterBand(1) - * for block_offsets in block_offsets_list: # <<<<<<<<<<<<<< - * stream_array = stream_band.ReadAsArray(**block_offsets) - * stream_array[stream_array == 2] = 0 - */ - } - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3006 - * 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":3007 - * 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":3008 - * stream_band = None - * stream_raster = None - * LOGGER.info('100.0% complete') # <<<<<<<<<<<<<< - * - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3008, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_info); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3008, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_15 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_15)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_15); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_11 = (__pyx_t_15) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_15, __pyx_kp_u_100_0_complete) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_100_0_complete); - __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; - if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 3008, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2811 - * - * - * def extract_streams_mfd( # <<<<<<<<<<<<<< - * flow_accum_raster_path_band, flow_dir_mfd_path_band, - * double flow_threshold, target_stream_raster_path, - */ - - /* 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_11); - __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_block_offsets_list); - __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":3011 - * - * - * 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("_is_raster_path_band_formatted", 0); - - /* "pygeoprocessing/routing/routing.pyx":3013 - * 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":3014 - * """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":3013 - * 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":3015 - * 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, 3015, __pyx_L1_error) - __pyx_t_2 = ((__pyx_t_4 != 2) != 0); - if (__pyx_t_2) { - - /* "pygeoprocessing/routing/routing.pyx":3016 - * 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":3015 - * 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":3017 - * 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, 3017, __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":3018 - * 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":3017 - * 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":3019 - * 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, 3019, __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":3020 - * 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":3019 - * 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":3022 - * 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":3011 - * - * - * 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; -} - -/* "pygeoprocessing/routing/routing.pyx":3025 - * - * - * def extract_strahler_streams_d8( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band, flow_accum_raster_path_band, - * dem_raster_path_band, - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_21extract_strahler_streams_d8(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_15pygeoprocessing_7routing_7routing_20extract_strahler_streams_d8[] = "Extract Strahler order stream geometry from flow accumulation.\n\n Creates a Strahler ordered stream vector containing line segments\n representing each separate stream fragment. The final vector contains\n at least the fields:\n\n * \"order\" (int): an integer representing the stream order\n * \"river_id\" (int): unique ID used by all stream segments that\n connect to the same outlet.\n * \"drop_distance\" (float): this is the drop distance in DEM units\n from the upstream to downstream component of this stream\n segment.\n * \"outlet\" (int): 1 if this segment is an outlet, 0 if not.\n * \"river_id\": unique ID among all stream segments which are\n hydrologically connected.\n * \"us_fa\" (int): flow accumulation value at the upstream end of\n the stream segment.\n * \"ds_fa\" (int): flow accumulation value at the downstream end of\n the stream segment\n * \"thresh_fa\" (int): the final threshold flow accumulation value\n used to determine the river segments.\n * \"upstream_d8_dir\" (int): a bookkeeping parameter from stream\n calculations that is left in due to the overhead\n of deleting a field.\n * \"ds_x\" (int): the raster x coordinate for the outlet.\n * \"ds_y\" (int): the raster y coordinate for the outlet.\n * \"ds_x_1\" (int): the x raster space coordinate that is 1 pixel\n upstream from the outlet.\n * \"ds_y_1\" (int): the y raster space coordinate that is 1 pixel\n upstream from the outlet.\n * \"us_x\" (int): the raster x coordinate for the upstream inlet.\n * \"us_y\" (int): the raster y coordinate for the upstream inlet.\n\n Args:\n flow_dir_d8_raster_path_band (tuple): a path/band representing the D8\n flow direction raster.\n flow_accum_raster_path_band (tuple): a path/band representing th""e D8\n flow accumulation raster represented by\n ``flow_dir_d8_raster_path_band``.\n dem_raster_path_band (tuple): a path/band representing the DEM used to\n derive flow dir.\n target_stream_vector_path (tuple): a single layer line vector created\n by this function representing the stream segments extracted from\n the above arguments. Contains the fields \"order\" and \"parent\" as\n described above.\n min_flow_accum_threshold (int): minimum number of upstream pixels\n required to create a stream. If ``autotune_flow_accumulation``\n is True, then the final value may be adjusted based on\n significant differences in 1st and 2nd order streams.\n river_order (int): what stream order to define as a river in terms of\n automatically determining flow accumulation threshold for that\n stream collection.\n min_p_val (float): minimum p_value test for significance\n autotune_flow_accumulation (bool): If true, uses a t-test to test for\n significant distances in order 1 and order 2 streams. If it is\n significant the flow accumulation parameter is adjusted upwards\n until the drop distances are insignificant.\n osr_axis_mapping_strategy (int): OSR axis mapping strategy for\n ``SpatialReference`` objects. Defaults to\n ``geoprocessing.DEFAULT_OSR_AXIS_MAPPING_STRATEGY``. This parameter\n should not be changed unless you know what you are doing.\n\n Returns:\n None.\n "; -static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_21extract_strahler_streams_d8 = {"extract_strahler_streams_d8", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_7routing_7routing_21extract_strahler_streams_d8, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_7routing_7routing_20extract_strahler_streams_d8}; -static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_21extract_strahler_streams_d8(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_flow_dir_d8_raster_path_band = 0; - PyObject *__pyx_v_flow_accum_raster_path_band = 0; - PyObject *__pyx_v_dem_raster_path_band = 0; - PyObject *__pyx_v_target_stream_vector_path = 0; - long __pyx_v_min_flow_accum_threshold; - int __pyx_v_river_order; - float __pyx_v_min_p_val; - PyObject *__pyx_v_autotune_flow_accumulation = 0; - PyObject *__pyx_v_osr_axis_mapping_strategy = 0; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("extract_strahler_streams_d8 (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_flow_dir_d8_raster_path_band,&__pyx_n_s_flow_accum_raster_path_band,&__pyx_n_s_dem_raster_path_band,&__pyx_n_s_target_stream_vector_path,&__pyx_n_s_min_flow_accum_threshold,&__pyx_n_s_river_order,&__pyx_n_s_min_p_val,&__pyx_n_s_autotune_flow_accumulation,&__pyx_n_s_osr_axis_mapping_strategy,0}; - PyObject* values[9] = {0,0,0,0,0,0,0,0,0}; - - /* "pygeoprocessing/routing/routing.pyx":3032 - * int river_order=5, - * float min_p_val=0.05, - * autotune_flow_accumulation=False, # <<<<<<<<<<<<<< - * osr_axis_mapping_strategy=DEFAULT_OSR_AXIS_MAPPING_STRATEGY): - * """Extract Strahler order stream geometry from flow accumulation. - */ - values[7] = ((PyObject *)Py_False); - values[8] = __pyx_k__15; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - CYTHON_FALLTHROUGH; - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - CYTHON_FALLTHROUGH; - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - CYTHON_FALLTHROUGH; - 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_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_flow_accum_raster_path_band)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("extract_strahler_streams_d8", 0, 4, 9, 1); __PYX_ERR(0, 3025, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dem_raster_path_band)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("extract_strahler_streams_d8", 0, 4, 9, 2); __PYX_ERR(0, 3025, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_stream_vector_path)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("extract_strahler_streams_d8", 0, 4, 9, 3); __PYX_ERR(0, 3025, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 4: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_min_flow_accum_threshold); - 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_river_order); - if (value) { values[5] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 6: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_min_p_val); - if (value) { values[6] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 7: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_autotune_flow_accumulation); - if (value) { values[7] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 8: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_osr_axis_mapping_strategy); - if (value) { values[8] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "extract_strahler_streams_d8") < 0)) __PYX_ERR(0, 3025, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - CYTHON_FALLTHROUGH; - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - CYTHON_FALLTHROUGH; - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - CYTHON_FALLTHROUGH; - 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_dir_d8_raster_path_band = values[0]; - __pyx_v_flow_accum_raster_path_band = values[1]; - __pyx_v_dem_raster_path_band = values[2]; - __pyx_v_target_stream_vector_path = values[3]; - if (values[4]) { - __pyx_v_min_flow_accum_threshold = __Pyx_PyInt_As_long(values[4]); if (unlikely((__pyx_v_min_flow_accum_threshold == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 3029, __pyx_L3_error) - } else { - __pyx_v_min_flow_accum_threshold = ((long)0x64); - } - if (values[5]) { - __pyx_v_river_order = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_river_order == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3030, __pyx_L3_error) - } else { - __pyx_v_river_order = ((int)5); - } - if (values[6]) { - __pyx_v_min_p_val = __pyx_PyFloat_AsFloat(values[6]); if (unlikely((__pyx_v_min_p_val == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 3031, __pyx_L3_error) - } else { - __pyx_v_min_p_val = ((float)0.05); - } - __pyx_v_autotune_flow_accumulation = values[7]; - __pyx_v_osr_axis_mapping_strategy = values[8]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("extract_strahler_streams_d8", 0, 4, 9, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3025, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pygeoprocessing.routing.routing.extract_strahler_streams_d8", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing_20extract_strahler_streams_d8(__pyx_self, __pyx_v_flow_dir_d8_raster_path_band, __pyx_v_flow_accum_raster_path_band, __pyx_v_dem_raster_path_band, __pyx_v_target_stream_vector_path, __pyx_v_min_flow_accum_threshold, __pyx_v_river_order, __pyx_v_min_p_val, __pyx_v_autotune_flow_accumulation, __pyx_v_osr_axis_mapping_strategy); - - /* "pygeoprocessing/routing/routing.pyx":3025 - * - * - * def extract_strahler_streams_d8( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band, flow_accum_raster_path_band, - * dem_raster_path_band, - */ - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_20extract_strahler_streams_d8(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_flow_dir_d8_raster_path_band, PyObject *__pyx_v_flow_accum_raster_path_band, PyObject *__pyx_v_dem_raster_path_band, PyObject *__pyx_v_target_stream_vector_path, long __pyx_v_min_flow_accum_threshold, int __pyx_v_river_order, float __pyx_v_min_p_val, PyObject *__pyx_v_autotune_flow_accumulation, PyObject *__pyx_v_osr_axis_mapping_strategy) { - PyObject *__pyx_v_flow_dir_info = NULL; - PyObject *__pyx_v_flow_dir_srs = NULL; - PyObject *__pyx_v_gpkg_driver = NULL; - PyObject *__pyx_v_stream_vector = NULL; - PyObject *__pyx_v_stream_basename = NULL; - PyObject *__pyx_v_stream_layer = NULL; - struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_flow_dir_managed_raster = NULL; - struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_flow_accum_managed_raster = NULL; - struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_dem_managed_raster = NULL; - int __pyx_v_flow_nodata; - int __pyx_v_xoff; - int __pyx_v_yoff; - int __pyx_v_i; - int __pyx_v_j; - int __pyx_v_d; - int __pyx_v_d_n; - int __pyx_v_n_cols; - int __pyx_v_n_rows; - int __pyx_v_win_xsize; - int __pyx_v_win_ysize; - long __pyx_v_n_pixels; - long __pyx_v_n_processed; - time_t __pyx_v_last_log_time; - std::stack __pyx_v_source_point_stack; - struct __pyx_t_15pygeoprocessing_7routing_7routing_StreamConnectivityPoint __pyx_v_source_stream_point; - int __pyx_v_x_l; - int __pyx_v_y_l; - int __pyx_v_x_n; - int __pyx_v_y_n; - int __pyx_v_upstream_count; - int __pyx_v_upstream_index; - int *__pyx_v_upstream_dirs; - long __pyx_v_local_flow_accum; - int __pyx_v_is_drain; - PyObject *__pyx_v_coord_to_stream_ids = NULL; - PyObject *__pyx_v_offset_dict = NULL; - PyObject *__pyx_v_stream_feature = NULL; - PyObject *__pyx_v_stream_fid = NULL; - PyObject *__pyx_v_n_points = NULL; - PyObject *__pyx_v_downstream_to_upstream_ids = NULL; - PyObject *__pyx_v_upstream_to_downstream_id = NULL; - PyObject *__pyx_v_payload = NULL; - PyObject *__pyx_v_x_u = NULL; - PyObject *__pyx_v_y_u = NULL; - PyObject *__pyx_v_ds_x_1 = NULL; - PyObject *__pyx_v_ds_y_1 = NULL; - PyObject *__pyx_v_upstream_id_list = NULL; - PyObject *__pyx_v_stream_line = NULL; - double __pyx_v_downstream_dem; - PyObject *__pyx_v_upstream_id = NULL; - double __pyx_v_upstream_dem; - double __pyx_v_drop_distance; - PyObject *__pyx_v_streams_to_process = NULL; - PyObject *__pyx_v_base_feature_count = NULL; - PyObject *__pyx_v_outlet_fid_list = NULL; - PyObject *__pyx_v_downstream_fid = NULL; - PyObject *__pyx_v_downstream_feature = NULL; - PyObject *__pyx_v_connected_upstream_fids = NULL; - PyObject *__pyx_v_stream_order_list = NULL; - int __pyx_v_all_defined; - PyObject *__pyx_v_upstream_fid = NULL; - PyObject *__pyx_v_upstream_feature = NULL; - PyObject *__pyx_v_upstream_order = NULL; - PyObject *__pyx_v_sorted_stream_order_list = NULL; - PyObject *__pyx_v_downstream_order = NULL; - PyObject *__pyx_v_working_river_id = NULL; - PyObject *__pyx_v_outlet_index = NULL; - PyObject *__pyx_v_outlet_fid = NULL; - PyObject *__pyx_v_search_stack = NULL; - PyObject *__pyx_v_feature_id = NULL; - PyObject *__pyx_v_stream_order = NULL; - PyObject *__pyx_v_upstream_stack = NULL; - PyObject *__pyx_v_streams_by_order = NULL; - PyObject *__pyx_v_drop_distance_collection = NULL; - PyObject *__pyx_v_max_upstream_flow_accum = NULL; - PyObject *__pyx_v_order = NULL; - PyObject *__pyx_v_working_flow_accum_threshold = NULL; - PyObject *__pyx_v_test_order = NULL; - CYTHON_UNUSED PyObject *__pyx_v__ = NULL; - PyObject *__pyx_v_p_val = NULL; - PyObject *__pyx_v_streams_to_retest = NULL; - PyObject *__pyx_v_ds_x = NULL; - PyObject *__pyx_v_ds_y = NULL; - PyObject *__pyx_v_upstream_d8_dir = NULL; - PyObject *__pyx_v_working_stack = NULL; - PyObject *__pyx_v_fid_to_order = NULL; - PyObject *__pyx_v_processed_segments = NULL; - Py_ssize_t __pyx_v_segments_to_process; - PyObject *__pyx_v_deleted_set = NULL; - PyObject *__pyx_v_working_fid = NULL; - PyObject *__pyx_v_upstream_fid_list = NULL; - PyObject *__pyx_v_order_count = NULL; - PyObject *__pyx_v_working_order = NULL; - PyObject *__pyx_v_working_feature = NULL; - PyObject *__pyx_v_connected_fids = NULL; - PyObject *__pyx_v_downstream_geom = NULL; - PyObject *__pyx_v_working_geom = NULL; - PyObject *__pyx_v_multi_line = NULL; - PyObject *__pyx_v_joined_line = NULL; - int __pyx_v_upstream_all_defined; - PyObject *__pyx_v_connected_fid = NULL; - PyObject *__pyx_7genexpr__pyx_v_stream_feature = NULL; - PyObject *__pyx_8genexpr1__pyx_v_fid = NULL; - 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; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *(*__pyx_t_10)(PyObject *); - int __pyx_t_11; - int __pyx_t_12[8]; - Py_ssize_t __pyx_t_13; - PyObject *(*__pyx_t_14)(PyObject *); - Py_ssize_t __pyx_t_15; - Py_UCS4 __pyx_t_16; - int __pyx_t_17; - int __pyx_t_18; - int __pyx_t_19; - int __pyx_t_20; - int __pyx_t_21; - int __pyx_t_22; - int __pyx_t_23; - int __pyx_t_24; - struct __pyx_t_15pygeoprocessing_7routing_7routing_StreamConnectivityPoint __pyx_t_25; - int __pyx_t_26; - int __pyx_t_27; - Py_ssize_t __pyx_t_28; - int __pyx_t_29; - PyObject *__pyx_t_30 = NULL; - PyObject *__pyx_t_31 = NULL; - PyObject *__pyx_t_32 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("extract_strahler_streams_d8", 0); - - /* "pygeoprocessing/routing/routing.pyx":3099 - * None. - * """ - * flow_dir_info = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band[0]) - * if flow_dir_info['projection_wkt']: - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3099, __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, 3099, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3100 - * """ - * flow_dir_info = pygeoprocessing.get_raster_info( - * flow_dir_d8_raster_path_band[0]) # <<<<<<<<<<<<<< - * if flow_dir_info['projection_wkt']: - * flow_dir_srs = osr.SpatialReference() - */ - __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, 3100, __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); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3099, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_flow_dir_info = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3101 - * flow_dir_info = pygeoprocessing.get_raster_info( - * flow_dir_d8_raster_path_band[0]) - * if flow_dir_info['projection_wkt']: # <<<<<<<<<<<<<< - * flow_dir_srs = osr.SpatialReference() - * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) - */ - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_projection_wkt); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3101, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 3101, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":3102 - * flow_dir_d8_raster_path_band[0]) - * if flow_dir_info['projection_wkt']: - * flow_dir_srs = osr.SpatialReference() # <<<<<<<<<<<<<< - * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) - * flow_dir_srs.SetAxisMappingStrategy(osr_axis_mapping_strategy) - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_osr); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3102, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_SpatialReference); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3102, __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 && 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); - } - } - __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3102, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_flow_dir_srs = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3103 - * if flow_dir_info['projection_wkt']: - * flow_dir_srs = osr.SpatialReference() - * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) # <<<<<<<<<<<<<< - * flow_dir_srs.SetAxisMappingStrategy(osr_axis_mapping_strategy) - * else: - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_srs, __pyx_n_s_ImportFromWkt); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3103, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_projection_wkt); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3103, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3103, __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":3104 - * flow_dir_srs = osr.SpatialReference() - * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) - * flow_dir_srs.SetAxisMappingStrategy(osr_axis_mapping_strategy) # <<<<<<<<<<<<<< - * else: - * flow_dir_srs = None - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_srs, __pyx_n_s_SetAxisMappingStrategy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3104, __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); - } - } - __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_osr_axis_mapping_strategy) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_osr_axis_mapping_strategy); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3104, __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":3101 - * flow_dir_info = pygeoprocessing.get_raster_info( - * flow_dir_d8_raster_path_band[0]) - * if flow_dir_info['projection_wkt']: # <<<<<<<<<<<<<< - * flow_dir_srs = osr.SpatialReference() - * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) - */ - goto __pyx_L3; - } - - /* "pygeoprocessing/routing/routing.pyx":3106 - * flow_dir_srs.SetAxisMappingStrategy(osr_axis_mapping_strategy) - * else: - * flow_dir_srs = None # <<<<<<<<<<<<<< - * gpkg_driver = gdal.GetDriverByName('GPKG') - * - */ - /*else*/ { - __Pyx_INCREF(Py_None); - __pyx_v_flow_dir_srs = Py_None; - } - __pyx_L3:; - - /* "pygeoprocessing/routing/routing.pyx":3107 - * else: - * flow_dir_srs = None - * gpkg_driver = gdal.GetDriverByName('GPKG') # <<<<<<<<<<<<<< - * - * stream_vector = gpkg_driver.Create( - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3107, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_GetDriverByName); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3107, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - 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_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_n_u_GPKG) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_n_u_GPKG); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3107, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_gpkg_driver = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3109 - * gpkg_driver = gdal.GetDriverByName('GPKG') - * - * stream_vector = gpkg_driver.Create( # <<<<<<<<<<<<<< - * target_stream_vector_path, 0, 0, 0, gdal.GDT_Unknown) - * stream_basename = os.path.basename( - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_gpkg_driver, __pyx_n_s_Create); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3109, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pygeoprocessing/routing/routing.pyx":3110 - * - * stream_vector = gpkg_driver.Create( - * target_stream_vector_path, 0, 0, 0, gdal.GDT_Unknown) # <<<<<<<<<<<<<< - * stream_basename = os.path.basename( - * os.path.splitext(target_stream_vector_path)[0]) - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3110, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_GDT_Unknown); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3110, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && likely(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_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[6] = {__pyx_t_2, __pyx_v_target_stream_vector_path, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_t_4}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 5+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3109, __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; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[6] = {__pyx_t_2, __pyx_v_target_stream_vector_path, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_t_4}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 5+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3109, __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; - } else - #endif - { - __pyx_t_7 = PyTuple_New(5+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3109, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_2) { - __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2); __pyx_t_2 = NULL; - } - __Pyx_INCREF(__pyx_v_target_stream_vector_path); - __Pyx_GIVEREF(__pyx_v_target_stream_vector_path); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_target_stream_vector_path); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_int_0); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_6, __pyx_int_0); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_7, 3+__pyx_t_6, __pyx_int_0); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_7, 4+__pyx_t_6, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3109, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_stream_vector = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3111 - * stream_vector = gpkg_driver.Create( - * target_stream_vector_path, 0, 0, 0, gdal.GDT_Unknown) - * stream_basename = os.path.basename( # <<<<<<<<<<<<<< - * os.path.splitext(target_stream_vector_path)[0]) - * stream_layer = stream_vector.CreateLayer( - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3111, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_path); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3111, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_basename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3111, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3112 - * target_stream_vector_path, 0, 0, 0, gdal.GDT_Unknown) - * stream_basename = os.path.basename( - * os.path.splitext(target_stream_vector_path)[0]) # <<<<<<<<<<<<<< - * stream_layer = stream_vector.CreateLayer( - * stream_basename, flow_dir_srs, ogr.wkbLineString) - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_os); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3112, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_path); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3112, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_splitext); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3112, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_2, __pyx_v_target_stream_vector_path) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_target_stream_vector_path); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3112, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_7, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3112, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_7, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3111, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_stream_basename = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3113 - * stream_basename = os.path.basename( - * os.path.splitext(target_stream_vector_path)[0]) - * stream_layer = stream_vector.CreateLayer( # <<<<<<<<<<<<<< - * stream_basename, flow_dir_srs, ogr.wkbLineString) - * stream_layer.CreateField(ogr.FieldDefn('order', ogr.OFTInteger)) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_vector, __pyx_n_s_CreateLayer); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3113, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pygeoprocessing/routing/routing.pyx":3114 - * os.path.splitext(target_stream_vector_path)[0]) - * stream_layer = stream_vector.CreateLayer( - * stream_basename, flow_dir_srs, ogr.wkbLineString) # <<<<<<<<<<<<<< - * stream_layer.CreateField(ogr.FieldDefn('order', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('drop_distance', ogr.OFTReal)) - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ogr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3114, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_wkbLineString); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3114, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = NULL; - __pyx_t_6 = 0; - 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); - __pyx_t_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_stream_basename, __pyx_v_flow_dir_srs, __pyx_t_7}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3113, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 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_3)) { - PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_stream_basename, __pyx_v_flow_dir_srs, __pyx_t_7}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3113, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - { - __pyx_t_2 = PyTuple_New(3+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3113, __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_INCREF(__pyx_v_stream_basename); - __Pyx_GIVEREF(__pyx_v_stream_basename); - PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_6, __pyx_v_stream_basename); - __Pyx_INCREF(__pyx_v_flow_dir_srs); - __Pyx_GIVEREF(__pyx_v_flow_dir_srs); - PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_6, __pyx_v_flow_dir_srs); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_2, 2+__pyx_t_6, __pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3113, __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_stream_layer = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3115 - * stream_layer = stream_vector.CreateLayer( - * stream_basename, flow_dir_srs, ogr.wkbLineString) - * stream_layer.CreateField(ogr.FieldDefn('order', ogr.OFTInteger)) # <<<<<<<<<<<<<< - * stream_layer.CreateField(ogr.FieldDefn('drop_distance', ogr.OFTReal)) - * stream_layer.CreateField(ogr.FieldDefn('outlet', ogr.OFTInteger)) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3115, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3115, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3115, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3115, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3115, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(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); - __pyx_t_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_order, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3115, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_order, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3115, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - { - __pyx_t_9 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3115, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - if (__pyx_t_7) { - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL; - } - __Pyx_INCREF(__pyx_n_u_order); - __Pyx_GIVEREF(__pyx_n_u_order); - PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_6, __pyx_n_u_order); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_6, __pyx_t_8); - __pyx_t_8 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3115, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __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); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3115, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3116 - * stream_basename, flow_dir_srs, ogr.wkbLineString) - * stream_layer.CreateField(ogr.FieldDefn('order', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('drop_distance', ogr.OFTReal)) # <<<<<<<<<<<<<< - * stream_layer.CreateField(ogr.FieldDefn('outlet', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('river_id', ogr.OFTInteger)) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3116, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ogr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3116, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3116, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ogr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3116, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OFTReal); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3116, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = NULL; - __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_9); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_9, function); - __pyx_t_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_drop_distance, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3116, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_drop_distance, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3116, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3116, __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_n_u_drop_distance); - __Pyx_GIVEREF(__pyx_n_u_drop_distance); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_n_u_drop_distance); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_8); - __pyx_t_8 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3116, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_9, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3116, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3117 - * stream_layer.CreateField(ogr.FieldDefn('order', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('drop_distance', ogr.OFTReal)) - * stream_layer.CreateField(ogr.FieldDefn('outlet', ogr.OFTInteger)) # <<<<<<<<<<<<<< - * stream_layer.CreateField(ogr.FieldDefn('river_id', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('us_fa', ogr.OFTInteger64)) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3117, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_ogr); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3117, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3117, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_ogr); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3117, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3117, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = NULL; - __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - __pyx_t_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_outlet, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3117, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_outlet, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3117, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - { - __pyx_t_4 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3117, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (__pyx_t_9) { - __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_9); __pyx_t_9 = NULL; - } - __Pyx_INCREF(__pyx_n_u_outlet); - __Pyx_GIVEREF(__pyx_n_u_outlet); - PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_6, __pyx_n_u_outlet); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_6, __pyx_t_8); - __pyx_t_8 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3117, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_7, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3117, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3118 - * stream_layer.CreateField(ogr.FieldDefn('drop_distance', ogr.OFTReal)) - * stream_layer.CreateField(ogr.FieldDefn('outlet', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('river_id', ogr.OFTInteger)) # <<<<<<<<<<<<<< - * stream_layer.CreateField(ogr.FieldDefn('us_fa', ogr.OFTInteger64)) - * stream_layer.CreateField(ogr.FieldDefn('ds_fa', ogr.OFTInteger64)) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3118, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3118, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3118, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3118, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3118, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(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); - __pyx_t_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_river_id, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3118, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_river_id, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3118, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - { - __pyx_t_9 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3118, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - if (__pyx_t_7) { - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL; - } - __Pyx_INCREF(__pyx_n_u_river_id); - __Pyx_GIVEREF(__pyx_n_u_river_id); - PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_6, __pyx_n_u_river_id); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_6, __pyx_t_8); - __pyx_t_8 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3118, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __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); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3118, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3119 - * stream_layer.CreateField(ogr.FieldDefn('outlet', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('river_id', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('us_fa', ogr.OFTInteger64)) # <<<<<<<<<<<<<< - * stream_layer.CreateField(ogr.FieldDefn('ds_fa', ogr.OFTInteger64)) - * stream_layer.CreateField(ogr.FieldDefn('thresh_fa', ogr.OFTInteger64)) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3119, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ogr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3119, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3119, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ogr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3119, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OFTInteger64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3119, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = NULL; - __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_9); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_9, function); - __pyx_t_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_us_fa, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3119, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_us_fa, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3119, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3119, __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_n_u_us_fa); - __Pyx_GIVEREF(__pyx_n_u_us_fa); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_n_u_us_fa); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_8); - __pyx_t_8 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3119, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_9, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3119, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3120 - * stream_layer.CreateField(ogr.FieldDefn('river_id', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('us_fa', ogr.OFTInteger64)) - * stream_layer.CreateField(ogr.FieldDefn('ds_fa', ogr.OFTInteger64)) # <<<<<<<<<<<<<< - * stream_layer.CreateField(ogr.FieldDefn('thresh_fa', ogr.OFTInteger64)) - * stream_layer.CreateField(ogr.FieldDefn('upstream_d8_dir', ogr.OFTInteger)) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3120, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_ogr); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3120, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3120, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_ogr); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3120, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_OFTInteger64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3120, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = NULL; - __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - __pyx_t_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_ds_fa, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3120, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_ds_fa, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3120, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - { - __pyx_t_4 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3120, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (__pyx_t_9) { - __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_9); __pyx_t_9 = NULL; - } - __Pyx_INCREF(__pyx_n_u_ds_fa); - __Pyx_GIVEREF(__pyx_n_u_ds_fa); - PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_6, __pyx_n_u_ds_fa); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_6, __pyx_t_8); - __pyx_t_8 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3120, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_7, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3120, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3121 - * stream_layer.CreateField(ogr.FieldDefn('us_fa', ogr.OFTInteger64)) - * stream_layer.CreateField(ogr.FieldDefn('ds_fa', ogr.OFTInteger64)) - * stream_layer.CreateField(ogr.FieldDefn('thresh_fa', ogr.OFTInteger64)) # <<<<<<<<<<<<<< - * stream_layer.CreateField(ogr.FieldDefn('upstream_d8_dir', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('ds_x', ogr.OFTInteger)) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3121, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3121, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3121, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3121, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OFTInteger64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3121, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(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); - __pyx_t_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_thresh_fa, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3121, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_thresh_fa, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3121, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - { - __pyx_t_9 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3121, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - if (__pyx_t_7) { - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL; - } - __Pyx_INCREF(__pyx_n_u_thresh_fa); - __Pyx_GIVEREF(__pyx_n_u_thresh_fa); - PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_6, __pyx_n_u_thresh_fa); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_6, __pyx_t_8); - __pyx_t_8 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3121, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __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); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3121, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3122 - * stream_layer.CreateField(ogr.FieldDefn('ds_fa', ogr.OFTInteger64)) - * stream_layer.CreateField(ogr.FieldDefn('thresh_fa', ogr.OFTInteger64)) - * stream_layer.CreateField(ogr.FieldDefn('upstream_d8_dir', ogr.OFTInteger)) # <<<<<<<<<<<<<< - * stream_layer.CreateField(ogr.FieldDefn('ds_x', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('ds_y', ogr.OFTInteger)) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3122, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ogr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3122, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3122, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ogr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3122, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3122, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = NULL; - __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_9); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_9, function); - __pyx_t_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_upstream_d8_dir, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3122, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_upstream_d8_dir, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3122, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3122, __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_n_u_upstream_d8_dir); - __Pyx_GIVEREF(__pyx_n_u_upstream_d8_dir); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_n_u_upstream_d8_dir); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_8); - __pyx_t_8 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3122, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_9, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3122, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3123 - * stream_layer.CreateField(ogr.FieldDefn('thresh_fa', ogr.OFTInteger64)) - * stream_layer.CreateField(ogr.FieldDefn('upstream_d8_dir', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('ds_x', ogr.OFTInteger)) # <<<<<<<<<<<<<< - * stream_layer.CreateField(ogr.FieldDefn('ds_y', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('ds_x_1', ogr.OFTInteger)) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3123, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_ogr); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3123, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3123, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_ogr); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3123, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3123, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = NULL; - __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - __pyx_t_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_ds_x, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3123, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_ds_x, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3123, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - { - __pyx_t_4 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3123, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (__pyx_t_9) { - __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_9); __pyx_t_9 = NULL; - } - __Pyx_INCREF(__pyx_n_u_ds_x); - __Pyx_GIVEREF(__pyx_n_u_ds_x); - PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_6, __pyx_n_u_ds_x); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_6, __pyx_t_8); - __pyx_t_8 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3123, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_7, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3123, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3124 - * stream_layer.CreateField(ogr.FieldDefn('upstream_d8_dir', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('ds_x', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('ds_y', ogr.OFTInteger)) # <<<<<<<<<<<<<< - * stream_layer.CreateField(ogr.FieldDefn('ds_x_1', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('ds_y_1', ogr.OFTInteger)) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3124, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3124, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3124, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3124, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3124, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(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); - __pyx_t_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_ds_y, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3124, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_ds_y, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3124, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - { - __pyx_t_9 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3124, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - if (__pyx_t_7) { - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL; - } - __Pyx_INCREF(__pyx_n_u_ds_y); - __Pyx_GIVEREF(__pyx_n_u_ds_y); - PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_6, __pyx_n_u_ds_y); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_6, __pyx_t_8); - __pyx_t_8 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3124, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __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); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3124, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3125 - * stream_layer.CreateField(ogr.FieldDefn('ds_x', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('ds_y', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('ds_x_1', ogr.OFTInteger)) # <<<<<<<<<<<<<< - * stream_layer.CreateField(ogr.FieldDefn('ds_y_1', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('us_x', ogr.OFTInteger)) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3125, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ogr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3125, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3125, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ogr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3125, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3125, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = NULL; - __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_9); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_9, function); - __pyx_t_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_ds_x_1, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3125, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_ds_x_1, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3125, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3125, __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_n_u_ds_x_1); - __Pyx_GIVEREF(__pyx_n_u_ds_x_1); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_n_u_ds_x_1); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_8); - __pyx_t_8 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3125, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_9, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3125, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3126 - * stream_layer.CreateField(ogr.FieldDefn('ds_y', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('ds_x_1', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('ds_y_1', ogr.OFTInteger)) # <<<<<<<<<<<<<< - * stream_layer.CreateField(ogr.FieldDefn('us_x', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('us_y', ogr.OFTInteger)) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3126, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_ogr); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3126, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3126, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_ogr); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3126, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3126, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = NULL; - __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - __pyx_t_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_ds_y_1, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3126, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_ds_y_1, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3126, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - { - __pyx_t_4 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3126, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (__pyx_t_9) { - __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_9); __pyx_t_9 = NULL; - } - __Pyx_INCREF(__pyx_n_u_ds_y_1); - __Pyx_GIVEREF(__pyx_n_u_ds_y_1); - PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_6, __pyx_n_u_ds_y_1); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_6, __pyx_t_8); - __pyx_t_8 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3126, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_7, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3126, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3127 - * stream_layer.CreateField(ogr.FieldDefn('ds_x_1', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('ds_y_1', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('us_x', ogr.OFTInteger)) # <<<<<<<<<<<<<< - * stream_layer.CreateField(ogr.FieldDefn('us_y', ogr.OFTInteger)) - * flow_dir_managed_raster = _ManagedRaster( - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3127, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3127, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3127, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3127, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3127, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(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); - __pyx_t_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_us_x, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3127, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_us_x, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3127, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - { - __pyx_t_9 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3127, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - if (__pyx_t_7) { - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL; - } - __Pyx_INCREF(__pyx_n_u_us_x); - __Pyx_GIVEREF(__pyx_n_u_us_x); - PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_6, __pyx_n_u_us_x); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_6, __pyx_t_8); - __pyx_t_8 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3127, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __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); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3127, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3128 - * stream_layer.CreateField(ogr.FieldDefn('ds_y_1', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('us_x', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('us_y', ogr.OFTInteger)) # <<<<<<<<<<<<<< - * flow_dir_managed_raster = _ManagedRaster( - * flow_dir_d8_raster_path_band[0], flow_dir_d8_raster_path_band[1], 0) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3128, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ogr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3128, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3128, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ogr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3128, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3128, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = NULL; - __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_9); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_9, function); - __pyx_t_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_us_y, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3128, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_us_y, __pyx_t_8}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3128, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3128, __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_n_u_us_y); - __Pyx_GIVEREF(__pyx_n_u_us_y); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_n_u_us_y); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_8); - __pyx_t_8 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3128, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_9, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3128, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3130 - * stream_layer.CreateField(ogr.FieldDefn('us_y', ogr.OFTInteger)) - * flow_dir_managed_raster = _ManagedRaster( - * flow_dir_d8_raster_path_band[0], flow_dir_d8_raster_path_band[1], 0) # <<<<<<<<<<<<<< - * - * flow_accum_managed_raster = _ManagedRaster( - */ - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3130, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3130, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pygeoprocessing/routing/routing.pyx":3129 - * stream_layer.CreateField(ogr.FieldDefn('us_x', ogr.OFTInteger)) - * stream_layer.CreateField(ogr.FieldDefn('us_y', ogr.OFTInteger)) - * flow_dir_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band[0], flow_dir_d8_raster_path_band[1], 0) - * - */ - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3129, __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_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_int_0); - __pyx_t_1 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3129, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_flow_dir_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3133 - * - * flow_accum_managed_raster = _ManagedRaster( - * flow_accum_raster_path_band[0], flow_accum_raster_path_band[1], 0) # <<<<<<<<<<<<<< - * - * dem_managed_raster = _ManagedRaster( - */ - __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_flow_accum_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3133, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_flow_accum_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3133, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - - /* "pygeoprocessing/routing/routing.pyx":3132 - * flow_dir_d8_raster_path_band[0], flow_dir_d8_raster_path_band[1], 0) - * - * flow_accum_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< - * flow_accum_raster_path_band[0], flow_accum_raster_path_band[1], 0) - * - */ - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3132, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); - __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_3 = 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, 3132, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_flow_accum_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3136 - * - * dem_managed_raster = _ManagedRaster( - * dem_raster_path_band[0], dem_raster_path_band[1], 0) # <<<<<<<<<<<<<< - * - * cdef int flow_nodata = pygeoprocessing.get_raster_info( - */ - __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, 3136, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3136, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":3135 - * flow_accum_raster_path_band[0], flow_accum_raster_path_band[1], 0) - * - * dem_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< - * dem_raster_path_band[0], dem_raster_path_band[1], 0) - * - */ - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3135, __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_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_3, 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_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3135, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_dem_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3138 - * dem_raster_path_band[0], dem_raster_path_band[1], 0) - * - * cdef int flow_nodata = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band[0])['nodata'][ - * flow_dir_d8_raster_path_band[1]-1] - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3138, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3138, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3139 - * - * cdef int flow_nodata = pygeoprocessing.get_raster_info( - * flow_dir_d8_raster_path_band[0])['nodata'][ # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band[1]-1] - * - */ - __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3139, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(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); - } - } - __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_9, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3138, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_t_1, __pyx_n_u_nodata); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3139, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3140 - * cdef int flow_nodata = pygeoprocessing.get_raster_info( - * flow_dir_d8_raster_path_band[0])['nodata'][ - * flow_dir_d8_raster_path_band[1]-1] # <<<<<<<<<<<<<< - * - * # D8 flow directions encoded as - */ - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3140, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyInt_SubtractObjC(__pyx_t_1, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3140, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3139 - * - * cdef int flow_nodata = pygeoprocessing.get_raster_info( - * flow_dir_d8_raster_path_band[0])['nodata'][ # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band[1]-1] - * - */ - __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3139, __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_t_6 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3139, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_flow_nodata = __pyx_t_6; - - /* "pygeoprocessing/routing/routing.pyx":3149 - * cdef int win_xsize, win_ysize - * - * n_cols, n_rows = flow_dir_info['raster_size'] # <<<<<<<<<<<<<< - * - * LOGGER.info('(extract_strahler_streams_d8): seed the drains') - */ - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3149, __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, 3149, __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, 3149, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3149, __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_9 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3149, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext; - index = 0; __pyx_t_3 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_3)) goto __pyx_L4_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - index = 1; __pyx_t_2 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 2) < 0) __PYX_ERR(0, 3149, __pyx_L1_error) - __pyx_t_10 = NULL; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - goto __pyx_L5_unpacking_done; - __pyx_L4_unpacking_failed:; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_10 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 3149, __pyx_L1_error) - __pyx_L5_unpacking_done:; - } - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3149, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3149, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_n_cols = __pyx_t_6; - __pyx_v_n_rows = __pyx_t_11; - - /* "pygeoprocessing/routing/routing.pyx":3151 - * n_cols, n_rows = flow_dir_info['raster_size'] - * - * LOGGER.info('(extract_strahler_streams_d8): seed the drains') # <<<<<<<<<<<<<< - * cdef long n_pixels = n_cols * n_rows - * cdef long n_processed = 0 - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3151, __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, 3151, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - 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_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_kp_u_extract_strahler_streams_d8_see) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_extract_strahler_streams_d8_see); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3151, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3152 - * - * LOGGER.info('(extract_strahler_streams_d8): seed the drains') - * cdef long n_pixels = n_cols * n_rows # <<<<<<<<<<<<<< - * cdef long n_processed = 0 - * cdef time_t last_log_time - */ - __pyx_v_n_pixels = (__pyx_v_n_cols * __pyx_v_n_rows); - - /* "pygeoprocessing/routing/routing.pyx":3153 - * LOGGER.info('(extract_strahler_streams_d8): seed the drains') - * cdef long n_pixels = n_cols * n_rows - * cdef long n_processed = 0 # <<<<<<<<<<<<<< - * cdef time_t last_log_time - * last_log_time = ctime(NULL) - */ - __pyx_v_n_processed = 0; - - /* "pygeoprocessing/routing/routing.pyx":3155 - * cdef long n_processed = 0 - * cdef time_t last_log_time - * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< - * cdef stack[StreamConnectivityPoint] source_point_stack - * cdef StreamConnectivityPoint source_stream_point - */ - __pyx_v_last_log_time = time(NULL); - - /* "pygeoprocessing/routing/routing.pyx":3159 - * cdef StreamConnectivityPoint source_stream_point - * - * cdef int x_l=-1, y_l=-1 # the _l is for "local" aka "current" pixel # <<<<<<<<<<<<<< - * - * # D8 backflow directions encoded as - */ - __pyx_v_x_l = -1; - __pyx_v_y_l = -1; - - /* "pygeoprocessing/routing/routing.pyx":3166 - * # 123 - * cdef int x_n, y_n # the _n is for "neighbor" - * cdef int upstream_count=0, upstream_index # <<<<<<<<<<<<<< - * # this array is filled out as upstream directions are calculated and - * # indexed by `upstream_count` - */ - __pyx_v_upstream_count = 0; - - /* "pygeoprocessing/routing/routing.pyx":3169 - * # this array is filled out as upstream directions are calculated and - * # indexed by `upstream_count` - * cdef int *upstream_dirs = [0, 0, 0, 0, 0, 0, 0, 0] # <<<<<<<<<<<<<< - * cdef long local_flow_accum - * # used to determine if source is a drain and should be tracked - */ - __pyx_t_12[0] = 0; - __pyx_t_12[1] = 0; - __pyx_t_12[2] = 0; - __pyx_t_12[3] = 0; - __pyx_t_12[4] = 0; - __pyx_t_12[5] = 0; - __pyx_t_12[6] = 0; - __pyx_t_12[7] = 0; - __pyx_v_upstream_dirs = __pyx_t_12; - - /* "pygeoprocessing/routing/routing.pyx":3176 - * # map x/y tuple to list of streams originating from that point - * # 2 tuple -> list of int - * coord_to_stream_ids = collections.defaultdict(list) # <<<<<<<<<<<<<< - * - * # First pass - search for bifurcating stream points - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_collections); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3176, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3176, __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 && 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); - } - } - __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, ((PyObject *)(&PyList_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)(&PyList_Type))); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3176, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_coord_to_stream_ids = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3185 - * # * drains to edge or nodata pixel - * # record a seed point for that bifurcation for later processing. - * stream_layer.StartTransaction() # <<<<<<<<<<<<<< - * for offset_dict in pygeoprocessing.iterblocks( - * flow_dir_d8_raster_path_band, offset_only=True): - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_StartTransaction); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3185, __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); - } - } - __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3185, __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":3186 - * # record a seed point for that bifurcation for later processing. - * stream_layer.StartTransaction() - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band, offset_only=True): - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3187 - * stream_layer.StartTransaction() - * for offset_dict in pygeoprocessing.iterblocks( - * flow_dir_d8_raster_path_band, offset_only=True): # <<<<<<<<<<<<<< - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: - * LOGGER.info( - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3186, __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_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3187, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 3187, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3186 - * # record a seed point for that bifurcation for later processing. - * stream_layer.StartTransaction() - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band, offset_only=True): - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: - */ - __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (likely(PyList_CheckExact(__pyx_t_9)) || PyTuple_CheckExact(__pyx_t_9)) { - __pyx_t_3 = __pyx_t_9; __Pyx_INCREF(__pyx_t_3); __pyx_t_13 = 0; - __pyx_t_14 = NULL; - } else { - __pyx_t_13 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_14 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 3186, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - for (;;) { - if (likely(!__pyx_t_14)) { - if (likely(PyList_CheckExact(__pyx_t_3))) { - if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_9 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_13); __Pyx_INCREF(__pyx_t_9); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 3186, __pyx_L1_error) - #else - __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - #endif - } else { - if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_13); __Pyx_INCREF(__pyx_t_9); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 3186, __pyx_L1_error) - #else - __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - #endif - } - } else { - __pyx_t_9 = __pyx_t_14(__pyx_t_3); - 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, 3186, __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":3188 - * for offset_dict in pygeoprocessing.iterblocks( - * flow_dir_d8_raster_path_band, offset_only=True): - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * LOGGER.info( - * '(extract_strahler_streams_d8): drain seeding ' - */ - __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":3189 - * flow_dir_d8_raster_path_band, offset_only=True): - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: - * LOGGER.info( # <<<<<<<<<<<<<< - * '(extract_strahler_streams_d8): drain seeding ' - * f'{n_processed} of {n_pixels} pixels complete') - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3189, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3189, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3190 - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: - * LOGGER.info( - * '(extract_strahler_streams_d8): drain seeding ' # <<<<<<<<<<<<<< - * f'{n_processed} of {n_pixels} pixels complete') - * last_log_time = ctime(NULL) - */ - __pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3190, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_15 = 0; - __pyx_t_16 = 127; - __Pyx_INCREF(__pyx_kp_u_extract_strahler_streams_d8_dra); - __pyx_t_15 += 45; - __Pyx_GIVEREF(__pyx_kp_u_extract_strahler_streams_d8_dra); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_extract_strahler_streams_d8_dra); - - /* "pygeoprocessing/routing/routing.pyx":3191 - * LOGGER.info( - * '(extract_strahler_streams_d8): drain seeding ' - * f'{n_processed} of {n_pixels} pixels complete') # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * xoff = offset_dict['xoff'] - */ - __pyx_t_7 = __Pyx_PyUnicode_From_long(__pyx_v_n_processed, 0, ' ', 'd'); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3191, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_15 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_INCREF(__pyx_kp_u_of); - __pyx_t_15 += 4; - __Pyx_GIVEREF(__pyx_kp_u_of); - PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_of); - __pyx_t_7 = __Pyx_PyUnicode_From_long(__pyx_v_n_pixels, 0, ' ', 'd'); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3191, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_15 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_INCREF(__pyx_kp_u_pixels_complete); - __pyx_t_15 += 16; - __Pyx_GIVEREF(__pyx_kp_u_pixels_complete); - PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u_pixels_complete); - - /* "pygeoprocessing/routing/routing.pyx":3190 - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: - * LOGGER.info( - * '(extract_strahler_streams_d8): drain seeding ' # <<<<<<<<<<<<<< - * f'{n_processed} of {n_pixels} pixels complete') - * last_log_time = ctime(NULL) - */ - __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_1, 5, __pyx_t_15, __pyx_t_16); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3190, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_9 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_1, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_7); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3189, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3192 - * '(extract_strahler_streams_d8): drain seeding ' - * f'{n_processed} of {n_pixels} pixels complete') - * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< - * xoff = offset_dict['xoff'] - * yoff = offset_dict['yoff'] - */ - __pyx_v_last_log_time = time(NULL); - - /* "pygeoprocessing/routing/routing.pyx":3188 - * for offset_dict in pygeoprocessing.iterblocks( - * flow_dir_d8_raster_path_band, offset_only=True): - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * LOGGER.info( - * '(extract_strahler_streams_d8): drain seeding ' - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3193 - * f'{n_processed} of {n_pixels} pixels complete') - * last_log_time = ctime(NULL) - * xoff = offset_dict['xoff'] # <<<<<<<<<<<<<< - * yoff = offset_dict['yoff'] - * win_xsize = offset_dict['win_xsize'] - */ - __pyx_t_9 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_xoff); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3193, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3193, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_v_xoff = __pyx_t_11; - - /* "pygeoprocessing/routing/routing.pyx":3194 - * last_log_time = ctime(NULL) - * xoff = offset_dict['xoff'] - * yoff = offset_dict['yoff'] # <<<<<<<<<<<<<< - * win_xsize = offset_dict['win_xsize'] - * win_ysize = offset_dict['win_ysize'] - */ - __pyx_t_9 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_yoff); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3194, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3194, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_v_yoff = __pyx_t_11; - - /* "pygeoprocessing/routing/routing.pyx":3195 - * xoff = offset_dict['xoff'] - * yoff = offset_dict['yoff'] - * win_xsize = offset_dict['win_xsize'] # <<<<<<<<<<<<<< - * win_ysize = offset_dict['win_ysize'] - * n_processed += win_xsize * win_ysize - */ - __pyx_t_9 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3195, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3195, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_v_win_xsize = __pyx_t_11; - - /* "pygeoprocessing/routing/routing.pyx":3196 - * yoff = offset_dict['yoff'] - * win_xsize = offset_dict['win_xsize'] - * win_ysize = offset_dict['win_ysize'] # <<<<<<<<<<<<<< - * n_processed += win_xsize * win_ysize - * - */ - __pyx_t_9 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3196, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3196, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_v_win_ysize = __pyx_t_11; - - /* "pygeoprocessing/routing/routing.pyx":3197 - * win_xsize = offset_dict['win_xsize'] - * win_ysize = offset_dict['win_ysize'] - * n_processed += win_xsize * win_ysize # <<<<<<<<<<<<<< - * - * for i in range(win_xsize): - */ - __pyx_v_n_processed = (__pyx_v_n_processed + (__pyx_v_win_xsize * __pyx_v_win_ysize)); - - /* "pygeoprocessing/routing/routing.pyx":3199 - * n_processed += win_xsize * win_ysize - * - * for i in range(win_xsize): # <<<<<<<<<<<<<< - * for j in range(win_ysize): - * is_drain = 0 - */ - __pyx_t_11 = __pyx_v_win_xsize; - __pyx_t_6 = __pyx_t_11; - for (__pyx_t_17 = 0; __pyx_t_17 < __pyx_t_6; __pyx_t_17+=1) { - __pyx_v_i = __pyx_t_17; - - /* "pygeoprocessing/routing/routing.pyx":3200 - * - * for i in range(win_xsize): - * for j in range(win_ysize): # <<<<<<<<<<<<<< - * is_drain = 0 - * x_l = xoff + i - */ - __pyx_t_18 = __pyx_v_win_ysize; - __pyx_t_19 = __pyx_t_18; - for (__pyx_t_20 = 0; __pyx_t_20 < __pyx_t_19; __pyx_t_20+=1) { - __pyx_v_j = __pyx_t_20; - - /* "pygeoprocessing/routing/routing.pyx":3201 - * for i in range(win_xsize): - * for j in range(win_ysize): - * is_drain = 0 # <<<<<<<<<<<<<< - * x_l = xoff + i - * y_l = yoff + j - */ - __pyx_v_is_drain = 0; - - /* "pygeoprocessing/routing/routing.pyx":3202 - * for j in range(win_ysize): - * is_drain = 0 - * x_l = xoff + i # <<<<<<<<<<<<<< - * y_l = yoff + j - * local_flow_accum = flow_accum_managed_raster.get( - */ - __pyx_v_x_l = (__pyx_v_xoff + __pyx_v_i); - - /* "pygeoprocessing/routing/routing.pyx":3203 - * is_drain = 0 - * x_l = xoff + i - * y_l = yoff + j # <<<<<<<<<<<<<< - * local_flow_accum = flow_accum_managed_raster.get( - * x_l, y_l) - */ - __pyx_v_y_l = (__pyx_v_yoff + __pyx_v_j); - - /* "pygeoprocessing/routing/routing.pyx":3204 - * x_l = xoff + i - * y_l = yoff + j - * local_flow_accum = flow_accum_managed_raster.get( # <<<<<<<<<<<<<< - * x_l, y_l) - * if local_flow_accum < min_flow_accum_threshold: - */ - __pyx_v_local_flow_accum = ((long)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_accum_managed_raster, __pyx_v_x_l, __pyx_v_y_l)); - - /* "pygeoprocessing/routing/routing.pyx":3206 - * local_flow_accum = flow_accum_managed_raster.get( - * x_l, y_l) - * if local_flow_accum < min_flow_accum_threshold: # <<<<<<<<<<<<<< - * continue - * # check to see if it's a drain - */ - __pyx_t_5 = ((__pyx_v_local_flow_accum < __pyx_v_min_flow_accum_threshold) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":3207 - * x_l, y_l) - * if local_flow_accum < min_flow_accum_threshold: - * continue # <<<<<<<<<<<<<< - * # check to see if it's a drain - * d_n = flow_dir_managed_raster.get(x_l, y_l) - */ - goto __pyx_L11_continue; - - /* "pygeoprocessing/routing/routing.pyx":3206 - * local_flow_accum = flow_accum_managed_raster.get( - * x_l, y_l) - * if local_flow_accum < min_flow_accum_threshold: # <<<<<<<<<<<<<< - * continue - * # check to see if it's a drain - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3209 - * continue - * # check to see if it's a drain - * d_n = flow_dir_managed_raster.get(x_l, y_l) # <<<<<<<<<<<<<< - * x_n = x_l + D8_XOFFSET[d_n] - * y_n = y_l + D8_YOFFSET[d_n] - */ - __pyx_v_d_n = ((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_dir_managed_raster, __pyx_v_x_l, __pyx_v_y_l)); - - /* "pygeoprocessing/routing/routing.pyx":3210 - * # check to see if it's a drain - * d_n = flow_dir_managed_raster.get(x_l, y_l) - * x_n = x_l + D8_XOFFSET[d_n] # <<<<<<<<<<<<<< - * y_n = y_l + D8_YOFFSET[d_n] - * - */ - __pyx_v_x_n = (__pyx_v_x_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_d_n])); - - /* "pygeoprocessing/routing/routing.pyx":3211 - * d_n = flow_dir_managed_raster.get(x_l, y_l) - * x_n = x_l + D8_XOFFSET[d_n] - * y_n = y_l + D8_YOFFSET[d_n] # <<<<<<<<<<<<<< - * - * if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_cols or - */ - __pyx_v_y_n = (__pyx_v_y_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_d_n])); - - /* "pygeoprocessing/routing/routing.pyx":3213 - * y_n = y_l + D8_YOFFSET[d_n] - * - * if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_cols or # <<<<<<<<<<<<<< - * flow_dir_managed_raster.get( - * x_n, y_n) == flow_nodata): - */ - __pyx_t_21 = ((__pyx_v_x_n < 0) != 0); - if (!__pyx_t_21) { - } else { - __pyx_t_5 = __pyx_t_21; - goto __pyx_L15_bool_binop_done; - } - __pyx_t_21 = ((__pyx_v_y_n < 0) != 0); - if (!__pyx_t_21) { - } else { - __pyx_t_5 = __pyx_t_21; - goto __pyx_L15_bool_binop_done; - } - __pyx_t_21 = ((__pyx_v_x_n >= __pyx_v_n_cols) != 0); - if (!__pyx_t_21) { - } else { - __pyx_t_5 = __pyx_t_21; - goto __pyx_L15_bool_binop_done; - } - __pyx_t_21 = ((__pyx_v_y_n >= __pyx_v_n_cols) != 0); - if (!__pyx_t_21) { - } else { - __pyx_t_5 = __pyx_t_21; - goto __pyx_L15_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":3215 - * if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_cols or - * flow_dir_managed_raster.get( - * x_n, y_n) == flow_nodata): # <<<<<<<<<<<<<< - * is_drain = 1 - * - */ - __pyx_t_21 = ((((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_dir_managed_raster, __pyx_v_x_n, __pyx_v_y_n)) == __pyx_v_flow_nodata) != 0); - __pyx_t_5 = __pyx_t_21; - __pyx_L15_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":3213 - * y_n = y_l + D8_YOFFSET[d_n] - * - * if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_cols or # <<<<<<<<<<<<<< - * flow_dir_managed_raster.get( - * x_n, y_n) == flow_nodata): - */ - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":3216 - * flow_dir_managed_raster.get( - * x_n, y_n) == flow_nodata): - * is_drain = 1 # <<<<<<<<<<<<<< - * - * if not is_drain and ( - */ - __pyx_v_is_drain = 1; - - /* "pygeoprocessing/routing/routing.pyx":3213 - * y_n = y_l + D8_YOFFSET[d_n] - * - * if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_cols or # <<<<<<<<<<<<<< - * flow_dir_managed_raster.get( - * x_n, y_n) == flow_nodata): - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3218 - * is_drain = 1 - * - * if not is_drain and ( # <<<<<<<<<<<<<< - * local_flow_accum < 2*min_flow_accum_threshold): - * # if current pixel is < 2*flow threshold then it can't - */ - __pyx_t_21 = ((!(__pyx_v_is_drain != 0)) != 0); - if (__pyx_t_21) { - } else { - __pyx_t_5 = __pyx_t_21; - goto __pyx_L21_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":3219 - * - * if not is_drain and ( - * local_flow_accum < 2*min_flow_accum_threshold): # <<<<<<<<<<<<<< - * # if current pixel is < 2*flow threshold then it can't - * # bifurcate into two pixels == flow threshold - */ - __pyx_t_21 = ((__pyx_v_local_flow_accum < (2 * __pyx_v_min_flow_accum_threshold)) != 0); - __pyx_t_5 = __pyx_t_21; - __pyx_L21_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":3218 - * is_drain = 1 - * - * if not is_drain and ( # <<<<<<<<<<<<<< - * local_flow_accum < 2*min_flow_accum_threshold): - * # if current pixel is < 2*flow threshold then it can't - */ - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":3222 - * # if current pixel is < 2*flow threshold then it can't - * # bifurcate into two pixels == flow threshold - * continue # <<<<<<<<<<<<<< - * - * upstream_count = 0 - */ - goto __pyx_L11_continue; - - /* "pygeoprocessing/routing/routing.pyx":3218 - * is_drain = 1 - * - * if not is_drain and ( # <<<<<<<<<<<<<< - * local_flow_accum < 2*min_flow_accum_threshold): - * # if current pixel is < 2*flow threshold then it can't - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3224 - * continue - * - * upstream_count = 0 # <<<<<<<<<<<<<< - * for d in range(8): - * x_n = x_l + D8_XOFFSET[d] - */ - __pyx_v_upstream_count = 0; - - /* "pygeoprocessing/routing/routing.pyx":3225 - * - * upstream_count = 0 - * for d in range(8): # <<<<<<<<<<<<<< - * x_n = x_l + D8_XOFFSET[d] - * y_n = y_l + D8_YOFFSET[d] - */ - for (__pyx_t_22 = 0; __pyx_t_22 < 8; __pyx_t_22+=1) { - __pyx_v_d = __pyx_t_22; - - /* "pygeoprocessing/routing/routing.pyx":3226 - * upstream_count = 0 - * for d in range(8): - * x_n = x_l + D8_XOFFSET[d] # <<<<<<<<<<<<<< - * y_n = y_l + D8_YOFFSET[d] - * # check if on border - */ - __pyx_v_x_n = (__pyx_v_x_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_d])); - - /* "pygeoprocessing/routing/routing.pyx":3227 - * for d in range(8): - * x_n = x_l + D8_XOFFSET[d] - * y_n = y_l + D8_YOFFSET[d] # <<<<<<<<<<<<<< - * # check if on border - * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: - */ - __pyx_v_y_n = (__pyx_v_y_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_d])); - - /* "pygeoprocessing/routing/routing.pyx":3229 - * y_n = y_l + D8_YOFFSET[d] - * # check if on border - * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: # <<<<<<<<<<<<<< - * continue - * d_n = flow_dir_managed_raster.get(x_n, y_n) - */ - __pyx_t_21 = ((__pyx_v_x_n < 0) != 0); - if (!__pyx_t_21) { - } else { - __pyx_t_5 = __pyx_t_21; - goto __pyx_L26_bool_binop_done; - } - __pyx_t_21 = ((__pyx_v_y_n < 0) != 0); - if (!__pyx_t_21) { - } else { - __pyx_t_5 = __pyx_t_21; - goto __pyx_L26_bool_binop_done; - } - __pyx_t_21 = ((__pyx_v_x_n >= __pyx_v_n_cols) != 0); - if (!__pyx_t_21) { - } else { - __pyx_t_5 = __pyx_t_21; - goto __pyx_L26_bool_binop_done; - } - __pyx_t_21 = ((__pyx_v_y_n >= __pyx_v_n_rows) != 0); - __pyx_t_5 = __pyx_t_21; - __pyx_L26_bool_binop_done:; - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":3230 - * # check if on border - * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: - * continue # <<<<<<<<<<<<<< - * d_n = flow_dir_managed_raster.get(x_n, y_n) - * if d_n == flow_nodata: - */ - goto __pyx_L23_continue; - - /* "pygeoprocessing/routing/routing.pyx":3229 - * y_n = y_l + D8_YOFFSET[d] - * # check if on border - * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: # <<<<<<<<<<<<<< - * continue - * d_n = flow_dir_managed_raster.get(x_n, y_n) - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3231 - * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: - * continue - * d_n = flow_dir_managed_raster.get(x_n, y_n) # <<<<<<<<<<<<<< - * if d_n == flow_nodata: - * continue - */ - __pyx_v_d_n = ((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_dir_managed_raster, __pyx_v_x_n, __pyx_v_y_n)); - - /* "pygeoprocessing/routing/routing.pyx":3232 - * continue - * d_n = flow_dir_managed_raster.get(x_n, y_n) - * if d_n == flow_nodata: # <<<<<<<<<<<<<< - * continue - * if (D8_REVERSE_DIRECTION[d] == d_n and - */ - __pyx_t_5 = ((__pyx_v_d_n == __pyx_v_flow_nodata) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":3233 - * d_n = flow_dir_managed_raster.get(x_n, y_n) - * if d_n == flow_nodata: - * continue # <<<<<<<<<<<<<< - * if (D8_REVERSE_DIRECTION[d] == d_n and - * flow_accum_managed_raster.get( - */ - goto __pyx_L23_continue; - - /* "pygeoprocessing/routing/routing.pyx":3232 - * continue - * d_n = flow_dir_managed_raster.get(x_n, y_n) - * if d_n == flow_nodata: # <<<<<<<<<<<<<< - * continue - * if (D8_REVERSE_DIRECTION[d] == d_n and - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3234 - * if d_n == flow_nodata: - * continue - * if (D8_REVERSE_DIRECTION[d] == d_n and # <<<<<<<<<<<<<< - * flow_accum_managed_raster.get( - * x_n, y_n) >= min_flow_accum_threshold): - */ - __pyx_t_21 = (((__pyx_v_15pygeoprocessing_7routing_7routing_D8_REVERSE_DIRECTION[__pyx_v_d]) == __pyx_v_d_n) != 0); - if (__pyx_t_21) { - } else { - __pyx_t_5 = __pyx_t_21; - goto __pyx_L32_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":3236 - * if (D8_REVERSE_DIRECTION[d] == d_n and - * flow_accum_managed_raster.get( - * x_n, y_n) >= min_flow_accum_threshold): # <<<<<<<<<<<<<< - * upstream_dirs[upstream_count] = d - * upstream_count += 1 - */ - __pyx_t_21 = ((((long)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_accum_managed_raster, __pyx_v_x_n, __pyx_v_y_n)) >= __pyx_v_min_flow_accum_threshold) != 0); - __pyx_t_5 = __pyx_t_21; - __pyx_L32_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":3234 - * if d_n == flow_nodata: - * continue - * if (D8_REVERSE_DIRECTION[d] == d_n and # <<<<<<<<<<<<<< - * flow_accum_managed_raster.get( - * x_n, y_n) >= min_flow_accum_threshold): - */ - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":3237 - * flow_accum_managed_raster.get( - * x_n, y_n) >= min_flow_accum_threshold): - * upstream_dirs[upstream_count] = d # <<<<<<<<<<<<<< - * upstream_count += 1 - * if upstream_count <= 1 and not is_drain: - */ - (__pyx_v_upstream_dirs[__pyx_v_upstream_count]) = __pyx_v_d; - - /* "pygeoprocessing/routing/routing.pyx":3238 - * x_n, y_n) >= min_flow_accum_threshold): - * upstream_dirs[upstream_count] = d - * upstream_count += 1 # <<<<<<<<<<<<<< - * if upstream_count <= 1 and not is_drain: - * continue - */ - __pyx_v_upstream_count = (__pyx_v_upstream_count + 1); - - /* "pygeoprocessing/routing/routing.pyx":3234 - * if d_n == flow_nodata: - * continue - * if (D8_REVERSE_DIRECTION[d] == d_n and # <<<<<<<<<<<<<< - * flow_accum_managed_raster.get( - * x_n, y_n) >= min_flow_accum_threshold): - */ - } - __pyx_L23_continue:; - } - - /* "pygeoprocessing/routing/routing.pyx":3239 - * upstream_dirs[upstream_count] = d - * upstream_count += 1 - * if upstream_count <= 1 and not is_drain: # <<<<<<<<<<<<<< - * continue - * for upstream_index in range(upstream_count): - */ - __pyx_t_21 = ((__pyx_v_upstream_count <= 1) != 0); - if (__pyx_t_21) { - } else { - __pyx_t_5 = __pyx_t_21; - goto __pyx_L35_bool_binop_done; - } - __pyx_t_21 = ((!(__pyx_v_is_drain != 0)) != 0); - __pyx_t_5 = __pyx_t_21; - __pyx_L35_bool_binop_done:; - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":3240 - * upstream_count += 1 - * if upstream_count <= 1 and not is_drain: - * continue # <<<<<<<<<<<<<< - * for upstream_index in range(upstream_count): - * # hit a branch! - */ - goto __pyx_L11_continue; - - /* "pygeoprocessing/routing/routing.pyx":3239 - * upstream_dirs[upstream_count] = d - * upstream_count += 1 - * if upstream_count <= 1 and not is_drain: # <<<<<<<<<<<<<< - * continue - * for upstream_index in range(upstream_count): - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3241 - * if upstream_count <= 1 and not is_drain: - * continue - * for upstream_index in range(upstream_count): # <<<<<<<<<<<<<< - * # hit a branch! - * stream_feature = ogr.Feature( - */ - __pyx_t_22 = __pyx_v_upstream_count; - __pyx_t_23 = __pyx_t_22; - for (__pyx_t_24 = 0; __pyx_t_24 < __pyx_t_23; __pyx_t_24+=1) { - __pyx_v_upstream_index = __pyx_t_24; - - /* "pygeoprocessing/routing/routing.pyx":3243 - * for upstream_index in range(upstream_count): - * # hit a branch! - * stream_feature = ogr.Feature( # <<<<<<<<<<<<<< - * stream_layer.GetLayerDefn()) - * stream_feature.SetField('outlet', 0) - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_ogr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3243, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_Feature); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3243, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3244 - * # hit a branch! - * stream_feature = ogr.Feature( - * stream_layer.GetLayerDefn()) # <<<<<<<<<<<<<< - * stream_feature.SetField('outlet', 0) - * stream_layer.CreateFeature(stream_feature) - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_GetLayerDefn); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3244, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_2 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3244, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_9 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_1, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3243, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF_SET(__pyx_v_stream_feature, __pyx_t_9); - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3245 - * stream_feature = ogr.Feature( - * stream_layer.GetLayerDefn()) - * stream_feature.SetField('outlet', 0) # <<<<<<<<<<<<<< - * stream_layer.CreateFeature(stream_feature) - * stream_fid = stream_feature.GetFID() - */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3245, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3245, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3246 - * stream_layer.GetLayerDefn()) - * stream_feature.SetField('outlet', 0) - * stream_layer.CreateFeature(stream_feature) # <<<<<<<<<<<<<< - * stream_fid = stream_feature.GetFID() - * source_point_stack.push(StreamConnectivityPoint( - */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CreateFeature); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3246, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_7 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_2, __pyx_v_stream_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_stream_feature); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3246, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3247 - * stream_feature.SetField('outlet', 0) - * stream_layer.CreateFeature(stream_feature) - * stream_fid = stream_feature.GetFID() # <<<<<<<<<<<<<< - * source_point_stack.push(StreamConnectivityPoint( - * x_l, y_l, upstream_dirs[upstream_index], stream_fid)) - */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetFID); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3247, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_7 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3247, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_XDECREF_SET(__pyx_v_stream_fid, __pyx_t_7); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3249 - * stream_fid = stream_feature.GetFID() - * source_point_stack.push(StreamConnectivityPoint( - * x_l, y_l, upstream_dirs[upstream_index], stream_fid)) # <<<<<<<<<<<<<< - * coord_to_stream_ids[(x_l, y_l)].append(stream_fid) - * LOGGER.info( - */ - __pyx_t_25.xi = __pyx_v_x_l; - __pyx_t_25.yi = __pyx_v_y_l; - __pyx_t_25.upstream_d8_dir = (__pyx_v_upstream_dirs[__pyx_v_upstream_index]); - __pyx_t_26 = __Pyx_PyInt_As_int(__pyx_v_stream_fid); if (unlikely((__pyx_t_26 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3249, __pyx_L1_error) - __pyx_t_25.source_id = __pyx_t_26; - - /* "pygeoprocessing/routing/routing.pyx":3248 - * stream_layer.CreateFeature(stream_feature) - * stream_fid = stream_feature.GetFID() - * source_point_stack.push(StreamConnectivityPoint( # <<<<<<<<<<<<<< - * x_l, y_l, upstream_dirs[upstream_index], stream_fid)) - * coord_to_stream_ids[(x_l, y_l)].append(stream_fid) - */ - __pyx_v_source_point_stack.push(__pyx_t_25); - - /* "pygeoprocessing/routing/routing.pyx":3250 - * source_point_stack.push(StreamConnectivityPoint( - * x_l, y_l, upstream_dirs[upstream_index], stream_fid)) - * coord_to_stream_ids[(x_l, y_l)].append(stream_fid) # <<<<<<<<<<<<<< - * LOGGER.info( - * '(extract_strahler_streams_d8): ' - */ - __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_x_l); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_9 = __Pyx_PyInt_From_int(__pyx_v_y_l); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_9); - __pyx_t_7 = 0; - __pyx_t_9 = 0; - __pyx_t_9 = __Pyx_PyObject_GetItem(__pyx_v_coord_to_stream_ids, __pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_27 = __Pyx_PyObject_Append(__pyx_t_9, __pyx_v_stream_fid); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3250, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } - __pyx_L11_continue:; - } - } - - /* "pygeoprocessing/routing/routing.pyx":3186 - * # record a seed point for that bifurcation for later processing. - * stream_layer.StartTransaction() - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band, offset_only=True): - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: - */ - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3251 - * x_l, y_l, upstream_dirs[upstream_index], stream_fid)) - * coord_to_stream_ids[(x_l, y_l)].append(stream_fid) - * LOGGER.info( # <<<<<<<<<<<<<< - * '(extract_strahler_streams_d8): ' - * f'drain seeding complete') - */ - __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3251, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3251, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(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); - } - } - __pyx_t_3 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_9, __pyx_kp_u_extract_strahler_streams_d8_dra_2) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_kp_u_extract_strahler_streams_d8_dra_2); - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3251, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3254 - * '(extract_strahler_streams_d8): ' - * f'drain seeding complete') - * LOGGER.info('(extract_strahler_streams_d8): starting upstream walk') # <<<<<<<<<<<<<< - * n_points = source_point_stack.size() - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3254, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_info); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3254, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - 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_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_2, __pyx_kp_u_extract_strahler_streams_d8_sta) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_kp_u_extract_strahler_streams_d8_sta); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3254, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3255 - * f'drain seeding complete') - * LOGGER.info('(extract_strahler_streams_d8): starting upstream walk') - * n_points = source_point_stack.size() # <<<<<<<<<<<<<< - * - * # map downstream ids to list of upstream connected streams - */ - __pyx_t_3 = __Pyx_PyInt_FromSize_t(__pyx_v_source_point_stack.size()); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3255, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_n_points = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3259 - * # map downstream ids to list of upstream connected streams - * # id -> list of ids - * downstream_to_upstream_ids = {} # <<<<<<<<<<<<<< - * - * # map upstream id to downstream connected stream id -> id - */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3259, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_downstream_to_upstream_ids = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3262 - * - * # map upstream id to downstream connected stream id -> id - * upstream_to_downstream_id = {} # <<<<<<<<<<<<<< - * - * while not source_point_stack.empty(): - */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3262, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_upstream_to_downstream_id = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3264 - * upstream_to_downstream_id = {} - * - * while not source_point_stack.empty(): # <<<<<<<<<<<<<< - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: - * LOGGER.info( - */ - while (1) { - __pyx_t_5 = ((!(__pyx_v_source_point_stack.empty() != 0)) != 0); - if (!__pyx_t_5) break; - - /* "pygeoprocessing/routing/routing.pyx":3265 - * - * while not source_point_stack.empty(): - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * LOGGER.info( - * '(extract_strahler_streams_d8): ' - */ - __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":3266 - * while not source_point_stack.empty(): - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: - * LOGGER.info( # <<<<<<<<<<<<<< - * '(extract_strahler_streams_d8): ' - * 'stream segment creation ' - */ - __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3266, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3266, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3267 - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: - * LOGGER.info( - * '(extract_strahler_streams_d8): ' # <<<<<<<<<<<<<< - * 'stream segment creation ' - * f'{n_points-source_point_stack.size()} of {n_points} ' - */ - __pyx_t_9 = PyTuple_New(5); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3267, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_13 = 0; - __pyx_t_16 = 127; - __Pyx_INCREF(__pyx_kp_u_extract_strahler_streams_d8_str); - __pyx_t_13 += 55; - __Pyx_GIVEREF(__pyx_kp_u_extract_strahler_streams_d8_str); - PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_kp_u_extract_strahler_streams_d8_str); - - /* "pygeoprocessing/routing/routing.pyx":3269 - * '(extract_strahler_streams_d8): ' - * 'stream segment creation ' - * f'{n_points-source_point_stack.size()} of {n_points} ' # <<<<<<<<<<<<<< - * 'source points complete') - * last_log_time = ctime(NULL) - */ - __pyx_t_7 = __Pyx_PyInt_FromSize_t(__pyx_v_source_point_stack.size()); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3269, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_1 = PyNumber_Subtract(__pyx_v_n_points, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3269, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyObject_FormatSimple(__pyx_t_1, __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3269, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_16 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_16) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_16; - __pyx_t_13 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_INCREF(__pyx_kp_u_of); - __pyx_t_13 += 4; - __Pyx_GIVEREF(__pyx_kp_u_of); - PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_kp_u_of); - __pyx_t_7 = __Pyx_PyObject_FormatSimple(__pyx_v_n_points, __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3269, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_16 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_16) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_16; - __pyx_t_13 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_INCREF(__pyx_kp_u_source_points_complete); - __pyx_t_13 += 23; - __Pyx_GIVEREF(__pyx_kp_u_source_points_complete); - PyTuple_SET_ITEM(__pyx_t_9, 4, __pyx_kp_u_source_points_complete); - - /* "pygeoprocessing/routing/routing.pyx":3267 - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: - * LOGGER.info( - * '(extract_strahler_streams_d8): ' # <<<<<<<<<<<<<< - * 'stream segment creation ' - * f'{n_points-source_point_stack.size()} of {n_points} ' - */ - __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_9, 5, __pyx_t_13, __pyx_t_16); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3267, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(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); - } - } - __pyx_t_3 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_9, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_7); - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3266, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3271 - * f'{n_points-source_point_stack.size()} of {n_points} ' - * 'source points complete') - * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< - * - * # This coordinate is the downstream end of the stream - */ - __pyx_v_last_log_time = time(NULL); - - /* "pygeoprocessing/routing/routing.pyx":3265 - * - * while not source_point_stack.empty(): - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * LOGGER.info( - * '(extract_strahler_streams_d8): ' - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3274 - * - * # This coordinate is the downstream end of the stream - * source_stream_point = source_point_stack.top() # <<<<<<<<<<<<<< - * source_point_stack.pop() - * - */ - __pyx_v_source_stream_point = __pyx_v_source_point_stack.top(); - - /* "pygeoprocessing/routing/routing.pyx":3275 - * # This coordinate is the downstream end of the stream - * source_stream_point = source_point_stack.top() - * source_point_stack.pop() # <<<<<<<<<<<<<< - * - * payload = _calculate_stream_geometry( - */ - __pyx_v_source_point_stack.pop(); - - /* "pygeoprocessing/routing/routing.pyx":3280 - * source_stream_point.xi, source_stream_point.yi, - * source_stream_point.upstream_d8_dir, - * flow_dir_info['geotransform'], n_cols, n_rows, # <<<<<<<<<<<<<< - * flow_accum_managed_raster, flow_dir_managed_raster, flow_nodata, - * min_flow_accum_threshold, coord_to_stream_ids) - */ - __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_geotransform); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3280, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pygeoprocessing/routing/routing.pyx":3277 - * source_point_stack.pop() - * - * payload = _calculate_stream_geometry( # <<<<<<<<<<<<<< - * source_stream_point.xi, source_stream_point.yi, - * source_stream_point.upstream_d8_dir, - */ - __pyx_t_2 = __pyx_f_15pygeoprocessing_7routing_7routing__calculate_stream_geometry(__pyx_v_source_stream_point.xi, __pyx_v_source_stream_point.yi, __pyx_v_source_stream_point.upstream_d8_dir, __pyx_t_3, __pyx_v_n_cols, __pyx_v_n_rows, __pyx_v_flow_accum_managed_raster, __pyx_v_flow_dir_managed_raster, __pyx_v_flow_nodata, __pyx_v_min_flow_accum_threshold, __pyx_v_coord_to_stream_ids); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3277, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF_SET(__pyx_v_payload, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3283 - * flow_accum_managed_raster, flow_dir_managed_raster, flow_nodata, - * min_flow_accum_threshold, coord_to_stream_ids) - * if payload is None: # <<<<<<<<<<<<<< - * continue - * x_u, y_u, ds_x_1, ds_y_1, upstream_id_list, stream_line = payload - */ - __pyx_t_5 = (__pyx_v_payload == Py_None); - __pyx_t_21 = (__pyx_t_5 != 0); - if (__pyx_t_21) { - - /* "pygeoprocessing/routing/routing.pyx":3284 - * min_flow_accum_threshold, coord_to_stream_ids) - * if payload is None: - * continue # <<<<<<<<<<<<<< - * x_u, y_u, ds_x_1, ds_y_1, upstream_id_list, stream_line = payload - * - */ - goto __pyx_L39_continue; - - /* "pygeoprocessing/routing/routing.pyx":3283 - * flow_accum_managed_raster, flow_dir_managed_raster, flow_nodata, - * min_flow_accum_threshold, coord_to_stream_ids) - * if payload is None: # <<<<<<<<<<<<<< - * continue - * x_u, y_u, ds_x_1, ds_y_1, upstream_id_list, stream_line = payload - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3285 - * if payload is None: - * continue - * x_u, y_u, ds_x_1, ds_y_1, upstream_id_list, stream_line = payload # <<<<<<<<<<<<<< - * - * downstream_dem = dem_managed_raster.get( - */ - if ((likely(PyTuple_CheckExact(__pyx_v_payload))) || (PyList_CheckExact(__pyx_v_payload))) { - PyObject* sequence = __pyx_v_payload; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 6)) { - if (size > 6) __Pyx_RaiseTooManyValuesError(6); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 3285, __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); - __pyx_t_7 = PyTuple_GET_ITEM(sequence, 2); - __pyx_t_9 = PyTuple_GET_ITEM(sequence, 3); - __pyx_t_1 = PyTuple_GET_ITEM(sequence, 4); - __pyx_t_8 = PyTuple_GET_ITEM(sequence, 5); - } else { - __pyx_t_2 = PyList_GET_ITEM(sequence, 0); - __pyx_t_3 = PyList_GET_ITEM(sequence, 1); - __pyx_t_7 = PyList_GET_ITEM(sequence, 2); - __pyx_t_9 = PyList_GET_ITEM(sequence, 3); - __pyx_t_1 = PyList_GET_ITEM(sequence, 4); - __pyx_t_8 = PyList_GET_ITEM(sequence, 5); - } - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_8); - #else - { - Py_ssize_t i; - PyObject** temps[6] = {&__pyx_t_2,&__pyx_t_3,&__pyx_t_7,&__pyx_t_9,&__pyx_t_1,&__pyx_t_8}; - for (i=0; i < 6; i++) { - PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 3285, __pyx_L1_error) - __Pyx_GOTREF(item); - *(temps[i]) = item; - } - } - #endif - } else { - Py_ssize_t index = -1; - PyObject** temps[6] = {&__pyx_t_2,&__pyx_t_3,&__pyx_t_7,&__pyx_t_9,&__pyx_t_1,&__pyx_t_8}; - __pyx_t_4 = PyObject_GetIter(__pyx_v_payload); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3285, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_10 = Py_TYPE(__pyx_t_4)->tp_iternext; - for (index=0; index < 6; index++) { - PyObject* item = __pyx_t_10(__pyx_t_4); if (unlikely(!item)) goto __pyx_L43_unpacking_failed; - __Pyx_GOTREF(item); - *(temps[index]) = item; - } - if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_4), 6) < 0) __PYX_ERR(0, 3285, __pyx_L1_error) - __pyx_t_10 = NULL; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L44_unpacking_done; - __pyx_L43_unpacking_failed:; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_10 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 3285, __pyx_L1_error) - __pyx_L44_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v_x_u, __pyx_t_2); - __pyx_t_2 = 0; - __Pyx_XDECREF_SET(__pyx_v_y_u, __pyx_t_3); - __pyx_t_3 = 0; - __Pyx_XDECREF_SET(__pyx_v_ds_x_1, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_XDECREF_SET(__pyx_v_ds_y_1, __pyx_t_9); - __pyx_t_9 = 0; - __Pyx_XDECREF_SET(__pyx_v_upstream_id_list, __pyx_t_1); - __pyx_t_1 = 0; - __Pyx_XDECREF_SET(__pyx_v_stream_line, __pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3287 - * x_u, y_u, ds_x_1, ds_y_1, upstream_id_list, stream_line = payload - * - * downstream_dem = dem_managed_raster.get( # <<<<<<<<<<<<<< - * source_stream_point.xi, source_stream_point.yi) - * - */ - __pyx_v_downstream_dem = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_dem_managed_raster, __pyx_v_source_stream_point.xi, __pyx_v_source_stream_point.yi); - - /* "pygeoprocessing/routing/routing.pyx":3290 - * source_stream_point.xi, source_stream_point.yi) - * - * stream_feature = stream_layer.GetFeature( # <<<<<<<<<<<<<< - * source_stream_point.source_id) - * stream_feature.SetField( - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3290, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":3291 - * - * stream_feature = stream_layer.GetFeature( - * source_stream_point.source_id) # <<<<<<<<<<<<<< - * stream_feature.SetField( - * 'ds_fa', flow_accum_managed_raster.get( - */ - __pyx_t_9 = __Pyx_PyInt_From_int(__pyx_v_source_stream_point.source_id); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3291, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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); - } - } - __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_7, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_9); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3290, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF_SET(__pyx_v_stream_feature, __pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3292 - * stream_feature = stream_layer.GetFeature( - * source_stream_point.source_id) - * stream_feature.SetField( # <<<<<<<<<<<<<< - * 'ds_fa', flow_accum_managed_raster.get( - * source_stream_point.xi, source_stream_point.yi)) - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3292, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":3293 - * source_stream_point.source_id) - * stream_feature.SetField( - * 'ds_fa', flow_accum_managed_raster.get( # <<<<<<<<<<<<<< - * source_stream_point.xi, source_stream_point.yi)) - * stream_feature.SetField('ds_x', source_stream_point.xi) - */ - __pyx_t_9 = PyFloat_FromDouble(__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_accum_managed_raster, __pyx_v_source_stream_point.xi, __pyx_v_source_stream_point.yi)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3293, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_7 = NULL; - __pyx_t_11 = 0; - if (CYTHON_UNPACK_METHODS && likely(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); - __pyx_t_11 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_ds_fa, __pyx_t_9}; - __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3292, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 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[3] = {__pyx_t_7, __pyx_n_u_ds_fa, __pyx_t_9}; - __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3292, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } else - #endif - { - __pyx_t_3 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3292, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (__pyx_t_7) { - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_7); __pyx_t_7 = NULL; - } - __Pyx_INCREF(__pyx_n_u_ds_fa); - __Pyx_GIVEREF(__pyx_n_u_ds_fa); - PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_11, __pyx_n_u_ds_fa); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_11, __pyx_t_9); - __pyx_t_9 = 0; - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3292, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3295 - * 'ds_fa', flow_accum_managed_raster.get( - * source_stream_point.xi, source_stream_point.yi)) - * stream_feature.SetField('ds_x', source_stream_point.xi) # <<<<<<<<<<<<<< - * stream_feature.SetField('ds_y', source_stream_point.yi) - * stream_feature.SetField('ds_x_1', ds_x_1) - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3295, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_source_stream_point.xi); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3295, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_9 = NULL; - __pyx_t_11 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_9); - __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_9, __pyx_n_u_ds_x, __pyx_t_3}; - __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3295, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 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[3] = {__pyx_t_9, __pyx_n_u_ds_x, __pyx_t_3}; - __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3295, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3295, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_9) { - __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_9); __pyx_t_9 = NULL; - } - __Pyx_INCREF(__pyx_n_u_ds_x); - __Pyx_GIVEREF(__pyx_n_u_ds_x); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_11, __pyx_n_u_ds_x); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_11, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3295, __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_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3296 - * source_stream_point.xi, source_stream_point.yi)) - * stream_feature.SetField('ds_x', source_stream_point.xi) - * stream_feature.SetField('ds_y', source_stream_point.yi) # <<<<<<<<<<<<<< - * stream_feature.SetField('ds_x_1', ds_x_1) - * stream_feature.SetField('ds_y_1', ds_y_1) - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3296, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_source_stream_point.yi); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3296, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_3 = NULL; - __pyx_t_11 = 0; - if (CYTHON_UNPACK_METHODS && likely(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_11 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_ds_y, __pyx_t_7}; - __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3296, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_ds_y, __pyx_t_7}; - __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3296, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - { - __pyx_t_9 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3296, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_INCREF(__pyx_n_u_ds_y); - __Pyx_GIVEREF(__pyx_n_u_ds_y); - PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_11, __pyx_n_u_ds_y); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_11, __pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3296, __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_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3297 - * stream_feature.SetField('ds_x', source_stream_point.xi) - * stream_feature.SetField('ds_y', source_stream_point.yi) - * stream_feature.SetField('ds_x_1', ds_x_1) # <<<<<<<<<<<<<< - * stream_feature.SetField('ds_y_1', ds_y_1) - * stream_feature.SetField('us_x', x_u) - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3297, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = NULL; - __pyx_t_11 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_9); - __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_9, __pyx_n_u_ds_x_1, __pyx_v_ds_x_1}; - __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3297, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_8); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_ds_x_1, __pyx_v_ds_x_1}; - __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3297, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_8); - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3297, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_9) { - __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_9); __pyx_t_9 = NULL; - } - __Pyx_INCREF(__pyx_n_u_ds_x_1); - __Pyx_GIVEREF(__pyx_n_u_ds_x_1); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_11, __pyx_n_u_ds_x_1); - __Pyx_INCREF(__pyx_v_ds_x_1); - __Pyx_GIVEREF(__pyx_v_ds_x_1); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_11, __pyx_v_ds_x_1); - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3297, __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_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3298 - * stream_feature.SetField('ds_y', source_stream_point.yi) - * stream_feature.SetField('ds_x_1', ds_x_1) - * stream_feature.SetField('ds_y_1', ds_y_1) # <<<<<<<<<<<<<< - * stream_feature.SetField('us_x', x_u) - * stream_feature.SetField('us_y', y_u) - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3298, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = NULL; - __pyx_t_11 = 0; - if (CYTHON_UNPACK_METHODS && likely(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); - __pyx_t_11 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_ds_y_1, __pyx_v_ds_y_1}; - __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3298, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_8); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_ds_y_1, __pyx_v_ds_y_1}; - __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3298, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_8); - } else - #endif - { - __pyx_t_9 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3298, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - if (__pyx_t_7) { - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL; - } - __Pyx_INCREF(__pyx_n_u_ds_y_1); - __Pyx_GIVEREF(__pyx_n_u_ds_y_1); - PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_11, __pyx_n_u_ds_y_1); - __Pyx_INCREF(__pyx_v_ds_y_1); - __Pyx_GIVEREF(__pyx_v_ds_y_1); - PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_11, __pyx_v_ds_y_1); - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3298, __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_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3299 - * stream_feature.SetField('ds_x_1', ds_x_1) - * stream_feature.SetField('ds_y_1', ds_y_1) - * stream_feature.SetField('us_x', x_u) # <<<<<<<<<<<<<< - * stream_feature.SetField('us_y', y_u) - * stream_feature.SetField( - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3299, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = NULL; - __pyx_t_11 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_9); - __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_9, __pyx_n_u_us_x, __pyx_v_x_u}; - __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3299, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_8); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_us_x, __pyx_v_x_u}; - __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3299, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_8); - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3299, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_9) { - __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_9); __pyx_t_9 = NULL; - } - __Pyx_INCREF(__pyx_n_u_us_x); - __Pyx_GIVEREF(__pyx_n_u_us_x); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_11, __pyx_n_u_us_x); - __Pyx_INCREF(__pyx_v_x_u); - __Pyx_GIVEREF(__pyx_v_x_u); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_11, __pyx_v_x_u); - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3299, __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_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3300 - * stream_feature.SetField('ds_y_1', ds_y_1) - * stream_feature.SetField('us_x', x_u) - * stream_feature.SetField('us_y', y_u) # <<<<<<<<<<<<<< - * stream_feature.SetField( - * 'upstream_d8_dir', source_stream_point.upstream_d8_dir) - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3300, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = NULL; - __pyx_t_11 = 0; - if (CYTHON_UNPACK_METHODS && likely(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); - __pyx_t_11 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_us_y, __pyx_v_y_u}; - __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3300, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_8); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_us_y, __pyx_v_y_u}; - __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3300, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_8); - } else - #endif - { - __pyx_t_9 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3300, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - if (__pyx_t_7) { - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL; - } - __Pyx_INCREF(__pyx_n_u_us_y); - __Pyx_GIVEREF(__pyx_n_u_us_y); - PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_11, __pyx_n_u_us_y); - __Pyx_INCREF(__pyx_v_y_u); - __Pyx_GIVEREF(__pyx_v_y_u); - PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_11, __pyx_v_y_u); - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3300, __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_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3301 - * stream_feature.SetField('us_x', x_u) - * stream_feature.SetField('us_y', y_u) - * stream_feature.SetField( # <<<<<<<<<<<<<< - * 'upstream_d8_dir', source_stream_point.upstream_d8_dir) - * - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3301, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":3302 - * stream_feature.SetField('us_y', y_u) - * stream_feature.SetField( - * 'upstream_d8_dir', source_stream_point.upstream_d8_dir) # <<<<<<<<<<<<<< - * - * # record the downstream connected component for all the upstream - */ - __pyx_t_9 = __Pyx_PyInt_From_int(__pyx_v_source_stream_point.upstream_d8_dir); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3302, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_7 = NULL; - __pyx_t_11 = 0; - if (CYTHON_UNPACK_METHODS && likely(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); - __pyx_t_11 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_upstream_d8_dir, __pyx_t_9}; - __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3301, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 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[3] = {__pyx_t_7, __pyx_n_u_upstream_d8_dir, __pyx_t_9}; - __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3301, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } else - #endif - { - __pyx_t_3 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3301, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (__pyx_t_7) { - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_7); __pyx_t_7 = NULL; - } - __Pyx_INCREF(__pyx_n_u_upstream_d8_dir); - __Pyx_GIVEREF(__pyx_n_u_upstream_d8_dir); - PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_11, __pyx_n_u_upstream_d8_dir); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_11, __pyx_t_9); - __pyx_t_9 = 0; - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3301, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3306 - * # record the downstream connected component for all the upstream - * # connected components - * for upstream_id in upstream_id_list: # <<<<<<<<<<<<<< - * upstream_to_downstream_id[upstream_id] = ( - * source_stream_point.source_id) - */ - if (likely(PyList_CheckExact(__pyx_v_upstream_id_list)) || PyTuple_CheckExact(__pyx_v_upstream_id_list)) { - __pyx_t_8 = __pyx_v_upstream_id_list; __Pyx_INCREF(__pyx_t_8); __pyx_t_13 = 0; - __pyx_t_14 = NULL; - } else { - __pyx_t_13 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_upstream_id_list); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3306, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_14 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 3306, __pyx_L1_error) - } - for (;;) { - if (likely(!__pyx_t_14)) { - if (likely(PyList_CheckExact(__pyx_t_8))) { - if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_8)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_13); __Pyx_INCREF(__pyx_t_1); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 3306, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_8, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3306, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } else { - if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_8)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_13); __Pyx_INCREF(__pyx_t_1); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 3306, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_8, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3306, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } - } else { - __pyx_t_1 = __pyx_t_14(__pyx_t_8); - 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, 3306, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - __Pyx_XDECREF_SET(__pyx_v_upstream_id, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3308 - * for upstream_id in upstream_id_list: - * upstream_to_downstream_id[upstream_id] = ( - * source_stream_point.source_id) # <<<<<<<<<<<<<< - * - * # record the upstream connected components for the downstream component - */ - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_source_stream_point.source_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3308, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":3307 - * # connected components - * for upstream_id in upstream_id_list: - * upstream_to_downstream_id[upstream_id] = ( # <<<<<<<<<<<<<< - * source_stream_point.source_id) - * - */ - if (unlikely(PyDict_SetItem(__pyx_v_upstream_to_downstream_id, __pyx_v_upstream_id, __pyx_t_1) < 0)) __PYX_ERR(0, 3307, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3306 - * # record the downstream connected component for all the upstream - * # connected components - * for upstream_id in upstream_id_list: # <<<<<<<<<<<<<< - * upstream_to_downstream_id[upstream_id] = ( - * source_stream_point.source_id) - */ - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3311 - * - * # record the upstream connected components for the downstream component - * downstream_to_upstream_ids[source_stream_point.source_id] = ( # <<<<<<<<<<<<<< - * upstream_id_list) - * - */ - __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_source_stream_point.source_id); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3311, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - if (unlikely(PyDict_SetItem(__pyx_v_downstream_to_upstream_ids, __pyx_t_8, __pyx_v_upstream_id_list) < 0)) __PYX_ERR(0, 3311, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3315 - * - * # if no upstream it means it is an order 1 source stream - * if not upstream_id_list: # <<<<<<<<<<<<<< - * stream_feature.SetField('order', 1) - * stream_feature.SetGeometry(stream_line) - */ - __pyx_t_21 = __Pyx_PyObject_IsTrue(__pyx_v_upstream_id_list); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3315, __pyx_L1_error) - __pyx_t_5 = ((!__pyx_t_21) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":3316 - * # if no upstream it means it is an order 1 source stream - * if not upstream_id_list: - * stream_feature.SetField('order', 1) # <<<<<<<<<<<<<< - * stream_feature.SetGeometry(stream_line) - * - */ - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3316, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3316, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3315 - * - * # if no upstream it means it is an order 1 source stream - * if not upstream_id_list: # <<<<<<<<<<<<<< - * stream_feature.SetField('order', 1) - * stream_feature.SetGeometry(stream_line) - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3317 - * if not upstream_id_list: - * stream_feature.SetField('order', 1) - * stream_feature.SetGeometry(stream_line) # <<<<<<<<<<<<<< - * - * # calculate the drop distance - */ - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetGeometry); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3317, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - } - } - __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_3, __pyx_v_stream_line) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_stream_line); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3317, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3320 - * - * # calculate the drop distance - * upstream_dem = dem_managed_raster.get(x_u, y_u) # <<<<<<<<<<<<<< - * drop_distance = upstream_dem - downstream_dem - * stream_feature.SetField('drop_distance', drop_distance) - */ - __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_v_x_u); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3320, __pyx_L1_error) - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_v_y_u); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3320, __pyx_L1_error) - __pyx_v_upstream_dem = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_dem_managed_raster, __pyx_t_11, __pyx_t_6); - - /* "pygeoprocessing/routing/routing.pyx":3321 - * # calculate the drop distance - * upstream_dem = dem_managed_raster.get(x_u, y_u) - * drop_distance = upstream_dem - downstream_dem # <<<<<<<<<<<<<< - * stream_feature.SetField('drop_distance', drop_distance) - * stream_feature.SetField( - */ - __pyx_v_drop_distance = (__pyx_v_upstream_dem - __pyx_v_downstream_dem); - - /* "pygeoprocessing/routing/routing.pyx":3322 - * upstream_dem = dem_managed_raster.get(x_u, y_u) - * drop_distance = upstream_dem - downstream_dem - * stream_feature.SetField('drop_distance', drop_distance) # <<<<<<<<<<<<<< - * stream_feature.SetField( - * 'us_fa', flow_accum_managed_raster.get(x_u, y_u)) - */ - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3322, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_3 = PyFloat_FromDouble(__pyx_v_drop_distance); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3322, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_9 = NULL; - __pyx_t_6 = 0; - 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); - __pyx_t_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_drop_distance, __pyx_t_3}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3322, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_u_drop_distance, __pyx_t_3}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3322, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3322, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_9) { - __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_9); __pyx_t_9 = NULL; - } - __Pyx_INCREF(__pyx_n_u_drop_distance); - __Pyx_GIVEREF(__pyx_n_u_drop_distance); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_n_u_drop_distance); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3322, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3323 - * drop_distance = upstream_dem - downstream_dem - * stream_feature.SetField('drop_distance', drop_distance) - * stream_feature.SetField( # <<<<<<<<<<<<<< - * 'us_fa', flow_accum_managed_raster.get(x_u, y_u)) - * stream_feature.SetField('thresh_fa', min_flow_accum_threshold) - */ - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3323, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - - /* "pygeoprocessing/routing/routing.pyx":3324 - * stream_feature.SetField('drop_distance', drop_distance) - * stream_feature.SetField( - * 'us_fa', flow_accum_managed_raster.get(x_u, y_u)) # <<<<<<<<<<<<<< - * stream_feature.SetField('thresh_fa', min_flow_accum_threshold) - * stream_layer.SetFeature(stream_feature) - */ - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_v_x_u); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3324, __pyx_L1_error) - __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_v_y_u); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3324, __pyx_L1_error) - __pyx_t_7 = PyFloat_FromDouble(__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_accum_managed_raster, __pyx_t_6, __pyx_t_11)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3324, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_3 = NULL; - __pyx_t_11 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - __pyx_t_11 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_us_fa, __pyx_t_7}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3323, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 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[3] = {__pyx_t_3, __pyx_n_u_us_fa, __pyx_t_7}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3323, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - { - __pyx_t_9 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3323, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_INCREF(__pyx_n_u_us_fa); - __Pyx_GIVEREF(__pyx_n_u_us_fa); - PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_11, __pyx_n_u_us_fa); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_11, __pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3323, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3325 - * stream_feature.SetField( - * 'us_fa', flow_accum_managed_raster.get(x_u, y_u)) - * stream_feature.SetField('thresh_fa', min_flow_accum_threshold) # <<<<<<<<<<<<<< - * stream_layer.SetFeature(stream_feature) - * - */ - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3325, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_9 = __Pyx_PyInt_From_long(__pyx_v_min_flow_accum_threshold); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3325, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_7 = NULL; - __pyx_t_11 = 0; - if (CYTHON_UNPACK_METHODS && likely(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); - __pyx_t_11 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_thresh_fa, __pyx_t_9}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3325, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_1); - __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_7, __pyx_n_u_thresh_fa, __pyx_t_9}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3325, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } else - #endif - { - __pyx_t_3 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3325, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (__pyx_t_7) { - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_7); __pyx_t_7 = NULL; - } - __Pyx_INCREF(__pyx_n_u_thresh_fa); - __Pyx_GIVEREF(__pyx_n_u_thresh_fa); - PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_11, __pyx_n_u_thresh_fa); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_11, __pyx_t_9); - __pyx_t_9 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3325, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3326 - * 'us_fa', flow_accum_managed_raster.get(x_u, y_u)) - * stream_feature.SetField('thresh_fa', min_flow_accum_threshold) - * stream_layer.SetFeature(stream_feature) # <<<<<<<<<<<<<< - * - * LOGGER.info( - */ - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_SetFeature); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3326, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - } - } - __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_3, __pyx_v_stream_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_stream_feature); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3326, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_L39_continue:; - } - - /* "pygeoprocessing/routing/routing.pyx":3328 - * stream_layer.SetFeature(stream_feature) - * - * LOGGER.info( # <<<<<<<<<<<<<< - * '(extract_strahler_streams_d8): stream segment creation complete') - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3328, __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, 3328, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_8, __pyx_kp_u_extract_strahler_streams_d8_str_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_extract_strahler_streams_d8_str_2); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3328, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3331 - * '(extract_strahler_streams_d8): stream segment creation complete') - * - * LOGGER.info('(extract_strahler_streams_d8): determining stream order') # <<<<<<<<<<<<<< - * # seed the list with all order 1 streams - * stream_layer.SetAttributeFilter('"order"=1') - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3331, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_info); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3331, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - } - } - __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_3, __pyx_kp_u_extract_strahler_streams_d8_det) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_kp_u_extract_strahler_streams_d8_det); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3331, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3333 - * LOGGER.info('(extract_strahler_streams_d8): determining stream order') - * # seed the list with all order 1 streams - * stream_layer.SetAttributeFilter('"order"=1') # <<<<<<<<<<<<<< - * streams_to_process = [stream_feature for stream_feature in stream_layer] - * base_feature_count = len(streams_to_process) - */ - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_SetAttributeFilter); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3333, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - } - } - __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_3, __pyx_kp_u_order_1) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_kp_u_order_1); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3333, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3334 - * # seed the list with all order 1 streams - * stream_layer.SetAttributeFilter('"order"=1') - * streams_to_process = [stream_feature for stream_feature in stream_layer] # <<<<<<<<<<<<<< - * base_feature_count = len(streams_to_process) - * outlet_fid_list = [] - */ - { /* enter inner scope */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3334, __pyx_L50_error) - __Pyx_GOTREF(__pyx_t_1); - if (likely(PyList_CheckExact(__pyx_v_stream_layer)) || PyTuple_CheckExact(__pyx_v_stream_layer)) { - __pyx_t_8 = __pyx_v_stream_layer; __Pyx_INCREF(__pyx_t_8); __pyx_t_13 = 0; - __pyx_t_14 = NULL; - } else { - __pyx_t_13 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_stream_layer); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3334, __pyx_L50_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_14 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 3334, __pyx_L50_error) - } - for (;;) { - if (likely(!__pyx_t_14)) { - if (likely(PyList_CheckExact(__pyx_t_8))) { - if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_8)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_13); __Pyx_INCREF(__pyx_t_3); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 3334, __pyx_L50_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_8, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3334, __pyx_L50_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - } else { - if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_8)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_13); __Pyx_INCREF(__pyx_t_3); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 3334, __pyx_L50_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_8, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3334, __pyx_L50_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - } - } else { - __pyx_t_3 = __pyx_t_14(__pyx_t_8); - 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, 3334, __pyx_L50_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_XDECREF_SET(__pyx_7genexpr__pyx_v_stream_feature, __pyx_t_3); - __pyx_t_3 = 0; - if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_7genexpr__pyx_v_stream_feature))) __PYX_ERR(0, 3334, __pyx_L50_error) - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_XDECREF(__pyx_7genexpr__pyx_v_stream_feature); __pyx_7genexpr__pyx_v_stream_feature = 0; - goto __pyx_L53_exit_scope; - __pyx_L50_error:; - __Pyx_XDECREF(__pyx_7genexpr__pyx_v_stream_feature); __pyx_7genexpr__pyx_v_stream_feature = 0; - goto __pyx_L1_error; - __pyx_L53_exit_scope:; - } /* exit inner scope */ - __pyx_v_streams_to_process = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3335 - * stream_layer.SetAttributeFilter('"order"=1') - * streams_to_process = [stream_feature for stream_feature in stream_layer] - * base_feature_count = len(streams_to_process) # <<<<<<<<<<<<<< - * outlet_fid_list = [] - * while streams_to_process: - */ - __pyx_t_13 = PyList_GET_SIZE(__pyx_v_streams_to_process); if (unlikely(__pyx_t_13 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3335, __pyx_L1_error) - __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3335, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_base_feature_count = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3336 - * streams_to_process = [stream_feature for stream_feature in stream_layer] - * base_feature_count = len(streams_to_process) - * outlet_fid_list = [] # <<<<<<<<<<<<<< - * while streams_to_process: - * if ctime(NULL)-last_log_time > 2.0: - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3336, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_outlet_fid_list = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3337 - * base_feature_count = len(streams_to_process) - * outlet_fid_list = [] - * while streams_to_process: # <<<<<<<<<<<<<< - * if ctime(NULL)-last_log_time > 2.0: - * LOGGER.info( - */ - while (1) { - __pyx_t_5 = (PyList_GET_SIZE(__pyx_v_streams_to_process) != 0); - if (!__pyx_t_5) break; - - /* "pygeoprocessing/routing/routing.pyx":3338 - * outlet_fid_list = [] - * while streams_to_process: - * if ctime(NULL)-last_log_time > 2.0: # <<<<<<<<<<<<<< - * LOGGER.info( - * '(extract_strahler_streams_d8): ' - */ - __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > 2.0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":3339 - * while streams_to_process: - * if ctime(NULL)-last_log_time > 2.0: - * LOGGER.info( # <<<<<<<<<<<<<< - * '(extract_strahler_streams_d8): ' - * 'stream order processing: ' - */ - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3339, __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, 3339, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3340 - * if ctime(NULL)-last_log_time > 2.0: - * LOGGER.info( - * '(extract_strahler_streams_d8): ' # <<<<<<<<<<<<<< - * 'stream order processing: ' - * f'{base_feature_count-len(streams_to_process)} of ' - */ - __pyx_t_8 = PyTuple_New(5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3340, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_13 = 0; - __pyx_t_16 = 127; - __Pyx_INCREF(__pyx_kp_u_extract_strahler_streams_d8_str_3); - __pyx_t_13 += 56; - __Pyx_GIVEREF(__pyx_kp_u_extract_strahler_streams_d8_str_3); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_kp_u_extract_strahler_streams_d8_str_3); - - /* "pygeoprocessing/routing/routing.pyx":3342 - * '(extract_strahler_streams_d8): ' - * 'stream order processing: ' - * f'{base_feature_count-len(streams_to_process)} of ' # <<<<<<<<<<<<<< - * f'{base_feature_count} stream fragments complete') - * last_log_time = ctime(NULL) - */ - __pyx_t_15 = PyList_GET_SIZE(__pyx_v_streams_to_process); if (unlikely(__pyx_t_15 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3342, __pyx_L1_error) - __pyx_t_9 = PyInt_FromSsize_t(__pyx_t_15); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3342, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_7 = PyNumber_Subtract(__pyx_v_base_feature_count, __pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3342, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = __Pyx_PyObject_FormatSimple(__pyx_t_7, __pyx_empty_unicode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3342, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_16 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9) > __pyx_t_16) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9) : __pyx_t_16; - __pyx_t_13 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_9); - __pyx_t_9 = 0; - __Pyx_INCREF(__pyx_kp_u_of); - __pyx_t_13 += 4; - __Pyx_GIVEREF(__pyx_kp_u_of); - PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_kp_u_of); - - /* "pygeoprocessing/routing/routing.pyx":3343 - * 'stream order processing: ' - * f'{base_feature_count-len(streams_to_process)} of ' - * f'{base_feature_count} stream fragments complete') # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * # fetch the downstream and connected upstream ids - */ - __pyx_t_9 = __Pyx_PyObject_FormatSimple(__pyx_v_base_feature_count, __pyx_empty_unicode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3343, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_16 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9) > __pyx_t_16) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9) : __pyx_t_16; - __pyx_t_13 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_9); - __pyx_t_9 = 0; - __Pyx_INCREF(__pyx_kp_u_stream_fragments_complete); - __pyx_t_13 += 26; - __Pyx_GIVEREF(__pyx_kp_u_stream_fragments_complete); - PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_kp_u_stream_fragments_complete); - - /* "pygeoprocessing/routing/routing.pyx":3340 - * if ctime(NULL)-last_log_time > 2.0: - * LOGGER.info( - * '(extract_strahler_streams_d8): ' # <<<<<<<<<<<<<< - * 'stream order processing: ' - * f'{base_feature_count-len(streams_to_process)} of ' - */ - __pyx_t_9 = __Pyx_PyUnicode_Join(__pyx_t_8, 5, __pyx_t_13, __pyx_t_16); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3340, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_8, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_9); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3339, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3344 - * f'{base_feature_count-len(streams_to_process)} of ' - * f'{base_feature_count} stream fragments complete') - * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< - * # fetch the downstream and connected upstream ids - * stream_feature = streams_to_process.pop(0) - */ - __pyx_v_last_log_time = time(NULL); - - /* "pygeoprocessing/routing/routing.pyx":3338 - * outlet_fid_list = [] - * while streams_to_process: - * if ctime(NULL)-last_log_time > 2.0: # <<<<<<<<<<<<<< - * LOGGER.info( - * '(extract_strahler_streams_d8): ' - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3346 - * last_log_time = ctime(NULL) - * # fetch the downstream and connected upstream ids - * stream_feature = streams_to_process.pop(0) # <<<<<<<<<<<<<< - * stream_fid = stream_feature.GetFID() - * if stream_fid not in upstream_to_downstream_id: - */ - __pyx_t_1 = __Pyx_PyList_PopIndex(__pyx_v_streams_to_process, __pyx_int_0, 0, 1, Py_ssize_t, PyInt_FromSsize_t); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3346, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_XDECREF_SET(__pyx_v_stream_feature, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3347 - * # fetch the downstream and connected upstream ids - * stream_feature = streams_to_process.pop(0) - * stream_fid = stream_feature.GetFID() # <<<<<<<<<<<<<< - * if stream_fid not in upstream_to_downstream_id: - * # it's an outlet so no downstream to process - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetFID); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3347, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_9) : __Pyx_PyObject_CallNoArg(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3347, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF_SET(__pyx_v_stream_fid, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3348 - * stream_feature = streams_to_process.pop(0) - * stream_fid = stream_feature.GetFID() - * if stream_fid not in upstream_to_downstream_id: # <<<<<<<<<<<<<< - * # it's an outlet so no downstream to process - * stream_feature.SetField('outlet', 1) - */ - __pyx_t_5 = (__Pyx_PyDict_ContainsTF(__pyx_v_stream_fid, __pyx_v_upstream_to_downstream_id, Py_NE)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 3348, __pyx_L1_error) - __pyx_t_21 = (__pyx_t_5 != 0); - if (__pyx_t_21) { - - /* "pygeoprocessing/routing/routing.pyx":3350 - * if stream_fid not in upstream_to_downstream_id: - * # it's an outlet so no downstream to process - * stream_feature.SetField('outlet', 1) # <<<<<<<<<<<<<< - * stream_layer.SetFeature(stream_feature) - * outlet_fid_list.append(stream_feature.GetFID()) - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3350, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3350, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3351 - * # it's an outlet so no downstream to process - * stream_feature.SetField('outlet', 1) - * stream_layer.SetFeature(stream_feature) # <<<<<<<<<<<<<< - * outlet_fid_list.append(stream_feature.GetFID()) - * stream_feature = None - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_SetFeature); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3351, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_3 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_9, __pyx_v_stream_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_stream_feature); - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3351, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3352 - * stream_feature.SetField('outlet', 1) - * stream_layer.SetFeature(stream_feature) - * outlet_fid_list.append(stream_feature.GetFID()) # <<<<<<<<<<<<<< - * stream_feature = None - * continue - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetFID); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3352, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_3 = (__pyx_t_9) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_9) : __Pyx_PyObject_CallNoArg(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3352, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_27 = __Pyx_PyList_Append(__pyx_v_outlet_fid_list, __pyx_t_3); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3352, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3353 - * stream_layer.SetFeature(stream_feature) - * outlet_fid_list.append(stream_feature.GetFID()) - * stream_feature = None # <<<<<<<<<<<<<< - * continue - * downstream_fid = upstream_to_downstream_id[stream_fid] - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_stream_feature, Py_None); - - /* "pygeoprocessing/routing/routing.pyx":3354 - * outlet_fid_list.append(stream_feature.GetFID()) - * stream_feature = None - * continue # <<<<<<<<<<<<<< - * downstream_fid = upstream_to_downstream_id[stream_fid] - * downstream_feature = stream_layer.GetFeature(downstream_fid) - */ - goto __pyx_L54_continue; - - /* "pygeoprocessing/routing/routing.pyx":3348 - * stream_feature = streams_to_process.pop(0) - * stream_fid = stream_feature.GetFID() - * if stream_fid not in upstream_to_downstream_id: # <<<<<<<<<<<<<< - * # it's an outlet so no downstream to process - * stream_feature.SetField('outlet', 1) - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3355 - * stream_feature = None - * continue - * downstream_fid = upstream_to_downstream_id[stream_fid] # <<<<<<<<<<<<<< - * downstream_feature = stream_layer.GetFeature(downstream_fid) - * if downstream_feature.GetField('order') is not None: - */ - __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_upstream_to_downstream_id, __pyx_v_stream_fid); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3355, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XDECREF_SET(__pyx_v_downstream_fid, __pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3356 - * continue - * downstream_fid = upstream_to_downstream_id[stream_fid] - * downstream_feature = stream_layer.GetFeature(downstream_fid) # <<<<<<<<<<<<<< - * if downstream_feature.GetField('order') is not None: - * # downstream component already processed - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3356, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_3 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_9, __pyx_v_downstream_fid) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_downstream_fid); - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3356, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF_SET(__pyx_v_downstream_feature, __pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3357 - * downstream_fid = upstream_to_downstream_id[stream_fid] - * downstream_feature = stream_layer.GetFeature(downstream_fid) - * if downstream_feature.GetField('order') is not None: # <<<<<<<<<<<<<< - * # downstream component already processed - * downstream_feature = None - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_downstream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3357, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_3 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_9, __pyx_n_u_order) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_n_u_order); - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3357, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_21 = (__pyx_t_3 != Py_None); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_5 = (__pyx_t_21 != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":3359 - * if downstream_feature.GetField('order') is not None: - * # downstream component already processed - * downstream_feature = None # <<<<<<<<<<<<<< - * continue - * connected_upstream_fids = downstream_to_upstream_ids[downstream_fid] - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_downstream_feature, Py_None); - - /* "pygeoprocessing/routing/routing.pyx":3360 - * # downstream component already processed - * downstream_feature = None - * continue # <<<<<<<<<<<<<< - * connected_upstream_fids = downstream_to_upstream_ids[downstream_fid] - * # check that all upstream IDs are defined and construct stream order - */ - goto __pyx_L54_continue; - - /* "pygeoprocessing/routing/routing.pyx":3357 - * downstream_fid = upstream_to_downstream_id[stream_fid] - * downstream_feature = stream_layer.GetFeature(downstream_fid) - * if downstream_feature.GetField('order') is not None: # <<<<<<<<<<<<<< - * # downstream component already processed - * downstream_feature = None - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3361 - * downstream_feature = None - * continue - * connected_upstream_fids = downstream_to_upstream_ids[downstream_fid] # <<<<<<<<<<<<<< - * # check that all upstream IDs are defined and construct stream order - * # list - */ - __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_downstream_to_upstream_ids, __pyx_v_downstream_fid); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3361, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XDECREF_SET(__pyx_v_connected_upstream_fids, __pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3364 - * # check that all upstream IDs are defined and construct stream order - * # list - * stream_order_list = [] # <<<<<<<<<<<<<< - * all_defined = True - * for upstream_fid in connected_upstream_fids: - */ - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3364, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XDECREF_SET(__pyx_v_stream_order_list, ((PyObject*)__pyx_t_3)); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3365 - * # list - * stream_order_list = [] - * all_defined = True # <<<<<<<<<<<<<< - * for upstream_fid in connected_upstream_fids: - * upstream_feature = stream_layer.GetFeature(upstream_fid) - */ - __pyx_v_all_defined = 1; - - /* "pygeoprocessing/routing/routing.pyx":3366 - * stream_order_list = [] - * all_defined = True - * for upstream_fid in connected_upstream_fids: # <<<<<<<<<<<<<< - * upstream_feature = stream_layer.GetFeature(upstream_fid) - * upstream_order = upstream_feature.GetField('order') - */ - if (likely(PyList_CheckExact(__pyx_v_connected_upstream_fids)) || PyTuple_CheckExact(__pyx_v_connected_upstream_fids)) { - __pyx_t_3 = __pyx_v_connected_upstream_fids; __Pyx_INCREF(__pyx_t_3); __pyx_t_13 = 0; - __pyx_t_14 = NULL; - } else { - __pyx_t_13 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_connected_upstream_fids); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3366, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_14 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 3366, __pyx_L1_error) - } - for (;;) { - if (likely(!__pyx_t_14)) { - if (likely(PyList_CheckExact(__pyx_t_3))) { - if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_13); __Pyx_INCREF(__pyx_t_1); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 3366, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3366, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } else { - if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_13); __Pyx_INCREF(__pyx_t_1); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 3366, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3366, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } - } else { - __pyx_t_1 = __pyx_t_14(__pyx_t_3); - 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, 3366, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - __Pyx_XDECREF_SET(__pyx_v_upstream_fid, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3367 - * all_defined = True - * for upstream_fid in connected_upstream_fids: - * upstream_feature = stream_layer.GetFeature(upstream_fid) # <<<<<<<<<<<<<< - * upstream_order = upstream_feature.GetField('order') - * if upstream_order is not None: - */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3367, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_9, function); - } - } - __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_8, __pyx_v_upstream_fid) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_upstream_fid); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3367, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_XDECREF_SET(__pyx_v_upstream_feature, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3368 - * for upstream_fid in connected_upstream_fids: - * upstream_feature = stream_layer.GetFeature(upstream_fid) - * upstream_order = upstream_feature.GetField('order') # <<<<<<<<<<<<<< - * if upstream_order is not None: - * stream_order_list.append(upstream_order) - */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_upstream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3368, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_9, function); - } - } - __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_8, __pyx_n_u_order) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_n_u_order); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3368, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_XDECREF_SET(__pyx_v_upstream_order, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3369 - * upstream_feature = stream_layer.GetFeature(upstream_fid) - * upstream_order = upstream_feature.GetField('order') - * if upstream_order is not None: # <<<<<<<<<<<<<< - * stream_order_list.append(upstream_order) - * else: - */ - __pyx_t_5 = (__pyx_v_upstream_order != Py_None); - __pyx_t_21 = (__pyx_t_5 != 0); - if (__pyx_t_21) { - - /* "pygeoprocessing/routing/routing.pyx":3370 - * upstream_order = upstream_feature.GetField('order') - * if upstream_order is not None: - * stream_order_list.append(upstream_order) # <<<<<<<<<<<<<< - * else: - * # found an upstream not defined, that means it'll be processed - */ - __pyx_t_27 = __Pyx_PyList_Append(__pyx_v_stream_order_list, __pyx_v_upstream_order); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3370, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3369 - * upstream_feature = stream_layer.GetFeature(upstream_fid) - * upstream_order = upstream_feature.GetField('order') - * if upstream_order is not None: # <<<<<<<<<<<<<< - * stream_order_list.append(upstream_order) - * else: - */ - goto __pyx_L61; - } - - /* "pygeoprocessing/routing/routing.pyx":3374 - * # found an upstream not defined, that means it'll be processed - * # later - * all_defined = False # <<<<<<<<<<<<<< - * break - * if not all_defined: - */ - /*else*/ { - __pyx_v_all_defined = 0; - - /* "pygeoprocessing/routing/routing.pyx":3375 - * # later - * all_defined = False - * break # <<<<<<<<<<<<<< - * if not all_defined: - * # we'll revisit this stream later when the other connected - */ - goto __pyx_L60_break; - } - __pyx_L61:; - - /* "pygeoprocessing/routing/routing.pyx":3366 - * stream_order_list = [] - * all_defined = True - * for upstream_fid in connected_upstream_fids: # <<<<<<<<<<<<<< - * upstream_feature = stream_layer.GetFeature(upstream_fid) - * upstream_order = upstream_feature.GetField('order') - */ - } - __pyx_L60_break:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3376 - * all_defined = False - * break - * if not all_defined: # <<<<<<<<<<<<<< - * # we'll revisit this stream later when the other connected - * # components are processed - */ - __pyx_t_21 = ((!(__pyx_v_all_defined != 0)) != 0); - if (__pyx_t_21) { - - /* "pygeoprocessing/routing/routing.pyx":3379 - * # we'll revisit this stream later when the other connected - * # components are processed - * continue # <<<<<<<<<<<<<< - * sorted_stream_order_list = sorted(stream_order_list) - * downstream_order = sorted_stream_order_list[-1] - */ - goto __pyx_L54_continue; - - /* "pygeoprocessing/routing/routing.pyx":3376 - * all_defined = False - * break - * if not all_defined: # <<<<<<<<<<<<<< - * # we'll revisit this stream later when the other connected - * # components are processed - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3380 - * # components are processed - * continue - * sorted_stream_order_list = sorted(stream_order_list) # <<<<<<<<<<<<<< - * downstream_order = sorted_stream_order_list[-1] - * if len(sorted_stream_order_list) > 1 and ( - */ - __pyx_t_1 = PySequence_List(__pyx_v_stream_order_list); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_27 = PyList_Sort(__pyx_t_3); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3380, __pyx_L1_error) - __Pyx_XDECREF_SET(__pyx_v_sorted_stream_order_list, ((PyObject*)__pyx_t_3)); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3381 - * continue - * sorted_stream_order_list = sorted(stream_order_list) - * downstream_order = sorted_stream_order_list[-1] # <<<<<<<<<<<<<< - * if len(sorted_stream_order_list) > 1 and ( - * sorted_stream_order_list[-1] == - */ - if (unlikely(__pyx_v_sorted_stream_order_list == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 3381, __pyx_L1_error) - } - __pyx_t_3 = __Pyx_GetItemInt_List(__pyx_v_sorted_stream_order_list, -1L, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3381, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XDECREF_SET(__pyx_v_downstream_order, __pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3382 - * sorted_stream_order_list = sorted(stream_order_list) - * downstream_order = sorted_stream_order_list[-1] - * if len(sorted_stream_order_list) > 1 and ( # <<<<<<<<<<<<<< - * sorted_stream_order_list[-1] == - * sorted_stream_order_list[-2]): - */ - if (unlikely(__pyx_v_sorted_stream_order_list == Py_None)) { - PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(0, 3382, __pyx_L1_error) - } - __pyx_t_13 = PyList_GET_SIZE(__pyx_v_sorted_stream_order_list); if (unlikely(__pyx_t_13 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3382, __pyx_L1_error) - __pyx_t_5 = ((__pyx_t_13 > 1) != 0); - if (__pyx_t_5) { - } else { - __pyx_t_21 = __pyx_t_5; - goto __pyx_L64_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":3383 - * downstream_order = sorted_stream_order_list[-1] - * if len(sorted_stream_order_list) > 1 and ( - * sorted_stream_order_list[-1] == # <<<<<<<<<<<<<< - * sorted_stream_order_list[-2]): - * # if there are at least two equal order streams feeding in, - */ - if (unlikely(__pyx_v_sorted_stream_order_list == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 3383, __pyx_L1_error) - } - __pyx_t_3 = __Pyx_GetItemInt_List(__pyx_v_sorted_stream_order_list, -1L, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3383, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pygeoprocessing/routing/routing.pyx":3384 - * if len(sorted_stream_order_list) > 1 and ( - * sorted_stream_order_list[-1] == - * sorted_stream_order_list[-2]): # <<<<<<<<<<<<<< - * # if there are at least two equal order streams feeding in, - * # we go up one order - */ - if (unlikely(__pyx_v_sorted_stream_order_list == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 3384, __pyx_L1_error) - } - __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_sorted_stream_order_list, -2L, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3384, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = PyObject_RichCompare(__pyx_t_3, __pyx_t_1, Py_EQ); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3383, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3383 - * downstream_order = sorted_stream_order_list[-1] - * if len(sorted_stream_order_list) > 1 and ( - * sorted_stream_order_list[-1] == # <<<<<<<<<<<<<< - * sorted_stream_order_list[-2]): - * # if there are at least two equal order streams feeding in, - */ - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 3383, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_21 = __pyx_t_5; - __pyx_L64_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":3382 - * sorted_stream_order_list = sorted(stream_order_list) - * downstream_order = sorted_stream_order_list[-1] - * if len(sorted_stream_order_list) > 1 and ( # <<<<<<<<<<<<<< - * sorted_stream_order_list[-1] == - * sorted_stream_order_list[-2]): - */ - if (__pyx_t_21) { - - /* "pygeoprocessing/routing/routing.pyx":3387 - * # if there are at least two equal order streams feeding in, - * # we go up one order - * downstream_order += 1 # <<<<<<<<<<<<<< - * downstream_feature.SetField('order', downstream_order) - * stream_layer.SetFeature(downstream_feature) - */ - __pyx_t_9 = __Pyx_PyInt_AddObjC(__pyx_v_downstream_order, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3387, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF_SET(__pyx_v_downstream_order, __pyx_t_9); - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3382 - * sorted_stream_order_list = sorted(stream_order_list) - * downstream_order = sorted_stream_order_list[-1] - * if len(sorted_stream_order_list) > 1 and ( # <<<<<<<<<<<<<< - * sorted_stream_order_list[-1] == - * sorted_stream_order_list[-2]): - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3388 - * # we go up one order - * downstream_order += 1 - * downstream_feature.SetField('order', downstream_order) # <<<<<<<<<<<<<< - * stream_layer.SetFeature(downstream_feature) - * streams_to_process.append(downstream_feature) - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_downstream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3388, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = NULL; - __pyx_t_11 = 0; - if (CYTHON_UNPACK_METHODS && likely(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_11 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_order, __pyx_v_downstream_order}; - __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3388, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_9); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_order, __pyx_v_downstream_order}; - __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3388, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_9); - } else - #endif - { - __pyx_t_8 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3388, __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_n_u_order); - __Pyx_GIVEREF(__pyx_n_u_order); - PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_11, __pyx_n_u_order); - __Pyx_INCREF(__pyx_v_downstream_order); - __Pyx_GIVEREF(__pyx_v_downstream_order); - PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_11, __pyx_v_downstream_order); - __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3388, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3389 - * downstream_order += 1 - * downstream_feature.SetField('order', downstream_order) - * stream_layer.SetFeature(downstream_feature) # <<<<<<<<<<<<<< - * streams_to_process.append(downstream_feature) - * downstream_feature = None - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_SetFeature); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3389, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_9 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_8, __pyx_v_downstream_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_downstream_feature); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3389, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3390 - * downstream_feature.SetField('order', downstream_order) - * stream_layer.SetFeature(downstream_feature) - * streams_to_process.append(downstream_feature) # <<<<<<<<<<<<<< - * downstream_feature = None - * LOGGER.info( - */ - __pyx_t_27 = __Pyx_PyList_Append(__pyx_v_streams_to_process, __pyx_v_downstream_feature); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3390, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3391 - * stream_layer.SetFeature(downstream_feature) - * streams_to_process.append(downstream_feature) - * downstream_feature = None # <<<<<<<<<<<<<< - * LOGGER.info( - * '(extract_strahler_streams_d8): stream order processing complete') - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_downstream_feature, Py_None); - __pyx_L54_continue:; - } - - /* "pygeoprocessing/routing/routing.pyx":3392 - * streams_to_process.append(downstream_feature) - * downstream_feature = None - * LOGGER.info( # <<<<<<<<<<<<<< - * '(extract_strahler_streams_d8): stream order processing complete') - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3392, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_info); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3392, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - } - } - __pyx_t_9 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_1, __pyx_kp_u_extract_strahler_streams_d8_str_4) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_kp_u_extract_strahler_streams_d8_str_4); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3392, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3395 - * '(extract_strahler_streams_d8): stream order processing complete') - * - * LOGGER.info( # <<<<<<<<<<<<<< - * '(extract_strahler_streams_d8): determine rivers') - * working_river_id = 0 - */ - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3395, __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, 3395, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_9 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_8, __pyx_kp_u_extract_strahler_streams_d8_det_2) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_kp_u_extract_strahler_streams_d8_det_2); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3395, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3397 - * LOGGER.info( - * '(extract_strahler_streams_d8): determine rivers') - * working_river_id = 0 # <<<<<<<<<<<<<< - * for outlet_index, outlet_fid in enumerate(outlet_fid_list): - * # walk upstream starting from this outlet to search for rivers - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_v_working_river_id = __pyx_int_0; - - /* "pygeoprocessing/routing/routing.pyx":3398 - * '(extract_strahler_streams_d8): determine rivers') - * working_river_id = 0 - * for outlet_index, outlet_fid in enumerate(outlet_fid_list): # <<<<<<<<<<<<<< - * # walk upstream starting from this outlet to search for rivers - * # defined as stream segments whose order is <= river_order. Note it - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_t_9 = __pyx_int_0; - __pyx_t_1 = __pyx_v_outlet_fid_list; __Pyx_INCREF(__pyx_t_1); __pyx_t_13 = 0; - for (;;) { - if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_8 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_13); __Pyx_INCREF(__pyx_t_8); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 3398, __pyx_L1_error) - #else - __pyx_t_8 = PySequence_ITEM(__pyx_t_1, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3398, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - #endif - __Pyx_XDECREF_SET(__pyx_v_outlet_fid, __pyx_t_8); - __pyx_t_8 = 0; - __Pyx_INCREF(__pyx_t_9); - __Pyx_XDECREF_SET(__pyx_v_outlet_index, __pyx_t_9); - __pyx_t_8 = __Pyx_PyInt_AddObjC(__pyx_t_9, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3398, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_9); - __pyx_t_9 = __pyx_t_8; - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3403 - * # can be < river_order because we may have some streams that have - * # outlets for shorter rivers that can't get to river_order. - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * LOGGER.info( - * '(extract_strahler_streams_d8): ' - */ - __pyx_t_21 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); - if (__pyx_t_21) { - - /* "pygeoprocessing/routing/routing.pyx":3404 - * # outlets for shorter rivers that can't get to river_order. - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: - * LOGGER.info( # <<<<<<<<<<<<<< - * '(extract_strahler_streams_d8): ' - * 'flow accumulation adjustment ' - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3404, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3404, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3405 - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: - * LOGGER.info( - * '(extract_strahler_streams_d8): ' # <<<<<<<<<<<<<< - * 'flow accumulation adjustment ' - * f'{outlet_index+1} of {len(outlet_fid_list)} ' - */ - __pyx_t_3 = PyTuple_New(5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3405, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_15 = 0; - __pyx_t_16 = 127; - __Pyx_INCREF(__pyx_kp_u_extract_strahler_streams_d8_flo); - __pyx_t_15 += 60; - __Pyx_GIVEREF(__pyx_kp_u_extract_strahler_streams_d8_flo); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_u_extract_strahler_streams_d8_flo); - - /* "pygeoprocessing/routing/routing.pyx":3407 - * '(extract_strahler_streams_d8): ' - * 'flow accumulation adjustment ' - * f'{outlet_index+1} of {len(outlet_fid_list)} ' # <<<<<<<<<<<<<< - * 'outlets complete') - * last_log_time = ctime(NULL) - */ - __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_v_outlet_index, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3407, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyObject_FormatSimple(__pyx_t_2, __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3407, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_16 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_16) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_16; - __pyx_t_15 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4); - __pyx_t_4 = 0; - __Pyx_INCREF(__pyx_kp_u_of); - __pyx_t_15 += 4; - __Pyx_GIVEREF(__pyx_kp_u_of); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_kp_u_of); - __pyx_t_28 = PyList_GET_SIZE(__pyx_v_outlet_fid_list); if (unlikely(__pyx_t_28 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3407, __pyx_L1_error) - __pyx_t_4 = __Pyx_PyUnicode_From_Py_ssize_t(__pyx_t_28, 0, ' ', 'd'); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3407, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_15 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_4); - __pyx_t_4 = 0; - __Pyx_INCREF(__pyx_kp_u_outlets_complete); - __pyx_t_15 += 17; - __Pyx_GIVEREF(__pyx_kp_u_outlets_complete); - PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_kp_u_outlets_complete); - - /* "pygeoprocessing/routing/routing.pyx":3405 - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: - * LOGGER.info( - * '(extract_strahler_streams_d8): ' # <<<<<<<<<<<<<< - * 'flow accumulation adjustment ' - * f'{outlet_index+1} of {len(outlet_fid_list)} ' - */ - __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_3, 5, __pyx_t_15, __pyx_t_16); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3405, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __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); - } - } - __pyx_t_8 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_4); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3404, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3409 - * f'{outlet_index+1} of {len(outlet_fid_list)} ' - * 'outlets complete') - * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< - * search_stack = [outlet_fid] - * while search_stack: - */ - __pyx_v_last_log_time = time(NULL); - - /* "pygeoprocessing/routing/routing.pyx":3403 - * # can be < river_order because we may have some streams that have - * # outlets for shorter rivers that can't get to river_order. - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * LOGGER.info( - * '(extract_strahler_streams_d8): ' - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3410 - * 'outlets complete') - * last_log_time = ctime(NULL) - * search_stack = [outlet_fid] # <<<<<<<<<<<<<< - * while search_stack: - * stream_layer.CommitTransaction() - */ - __pyx_t_8 = PyList_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3410, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(__pyx_v_outlet_fid); - __Pyx_GIVEREF(__pyx_v_outlet_fid); - PyList_SET_ITEM(__pyx_t_8, 0, __pyx_v_outlet_fid); - __Pyx_XDECREF_SET(__pyx_v_search_stack, ((PyObject*)__pyx_t_8)); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3411 - * last_log_time = ctime(NULL) - * search_stack = [outlet_fid] - * while search_stack: # <<<<<<<<<<<<<< - * stream_layer.CommitTransaction() - * stream_layer.StartTransaction() - */ - while (1) { - __pyx_t_21 = (PyList_GET_SIZE(__pyx_v_search_stack) != 0); - if (!__pyx_t_21) break; - - /* "pygeoprocessing/routing/routing.pyx":3412 - * search_stack = [outlet_fid] - * while search_stack: - * stream_layer.CommitTransaction() # <<<<<<<<<<<<<< - * stream_layer.StartTransaction() - * feature_id = search_stack.pop() - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CommitTransaction); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3412, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_8 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3412, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3413 - * while search_stack: - * stream_layer.CommitTransaction() - * stream_layer.StartTransaction() # <<<<<<<<<<<<<< - * feature_id = search_stack.pop() - * stream_feature = stream_layer.GetFeature(feature_id) - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_StartTransaction); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3413, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_8 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3413, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3414 - * stream_layer.CommitTransaction() - * stream_layer.StartTransaction() - * feature_id = search_stack.pop() # <<<<<<<<<<<<<< - * stream_feature = stream_layer.GetFeature(feature_id) - * stream_order = stream_feature.GetField('order') - */ - __pyx_t_8 = __Pyx_PyList_Pop(__pyx_v_search_stack); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3414, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_XDECREF_SET(__pyx_v_feature_id, __pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3415 - * stream_layer.StartTransaction() - * feature_id = search_stack.pop() - * stream_feature = stream_layer.GetFeature(feature_id) # <<<<<<<<<<<<<< - * stream_order = stream_feature.GetField('order') - * - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3415, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_8 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_4, __pyx_v_feature_id) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_feature_id); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3415, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF_SET(__pyx_v_stream_feature, __pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3416 - * feature_id = search_stack.pop() - * stream_feature = stream_layer.GetFeature(feature_id) - * stream_order = stream_feature.GetField('order') # <<<<<<<<<<<<<< - * - * if (stream_order > river_order or - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3416, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_8 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_4, __pyx_n_u_order) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_n_u_order); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3416, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF_SET(__pyx_v_stream_order, __pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3418 - * stream_order = stream_feature.GetField('order') - * - * if (stream_order > river_order or # <<<<<<<<<<<<<< - * stream_feature.GetField('river_id') is not None): - * # keep walking upstream until there's an order <= river_order - */ - __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_river_order); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3418, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_7 = PyObject_RichCompare(__pyx_v_stream_order, __pyx_t_8, Py_GT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3418, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 3418, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (!__pyx_t_5) { - } else { - __pyx_t_21 = __pyx_t_5; - goto __pyx_L72_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":3419 - * - * if (stream_order > river_order or - * stream_feature.GetField('river_id') is not None): # <<<<<<<<<<<<<< - * # keep walking upstream until there's an order <= river_order - * search_stack.extend( - */ - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3419, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __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); - } - } - __pyx_t_7 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_4, __pyx_n_u_river_id) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_n_u_river_id); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3419, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_5 = (__pyx_t_7 != Py_None); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_29 = (__pyx_t_5 != 0); - __pyx_t_21 = __pyx_t_29; - __pyx_L72_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":3418 - * stream_order = stream_feature.GetField('order') - * - * if (stream_order > river_order or # <<<<<<<<<<<<<< - * stream_feature.GetField('river_id') is not None): - * # keep walking upstream until there's an order <= river_order - */ - if (__pyx_t_21) { - - /* "pygeoprocessing/routing/routing.pyx":3422 - * # keep walking upstream until there's an order <= river_order - * search_stack.extend( - * downstream_to_upstream_ids[feature_id]) # <<<<<<<<<<<<<< - * else: - * # walk up the stream setting every upstream segment's - */ - __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_downstream_to_upstream_ids, __pyx_v_feature_id); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3422, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - - /* "pygeoprocessing/routing/routing.pyx":3421 - * stream_feature.GetField('river_id') is not None): - * # keep walking upstream until there's an order <= river_order - * search_stack.extend( # <<<<<<<<<<<<<< - * downstream_to_upstream_ids[feature_id]) - * else: - */ - __pyx_t_27 = __Pyx_PyList_Extend(__pyx_v_search_stack, __pyx_t_7); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3421, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3418 - * stream_order = stream_feature.GetField('order') - * - * if (stream_order > river_order or # <<<<<<<<<<<<<< - * stream_feature.GetField('river_id') is not None): - * # keep walking upstream until there's an order <= river_order - */ - goto __pyx_L71; - } - - /* "pygeoprocessing/routing/routing.pyx":3426 - * # walk up the stream setting every upstream segment's - * # river_id to working_river_id - * stream_layer.SetFeature(stream_feature) # <<<<<<<<<<<<<< - * upstream_stack = [feature_id] - * - */ - /*else*/ { - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_SetFeature); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3426, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __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); - } - } - __pyx_t_7 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_4, __pyx_v_stream_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_stream_feature); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3426, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3427 - * # river_id to working_river_id - * stream_layer.SetFeature(stream_feature) - * upstream_stack = [feature_id] # <<<<<<<<<<<<<< - * - * streams_by_order = collections.defaultdict(list) - */ - __pyx_t_7 = PyList_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3427, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_INCREF(__pyx_v_feature_id); - __Pyx_GIVEREF(__pyx_v_feature_id); - PyList_SET_ITEM(__pyx_t_7, 0, __pyx_v_feature_id); - __Pyx_XDECREF_SET(__pyx_v_upstream_stack, ((PyObject*)__pyx_t_7)); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3429 - * upstream_stack = [feature_id] - * - * streams_by_order = collections.defaultdict(list) # <<<<<<<<<<<<<< - * drop_distance_collection = collections.defaultdict(list) - * max_upstream_flow_accum = collections.defaultdict(int) - */ - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_collections); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3429, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3429, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = NULL; - 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_7 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_8, ((PyObject *)(&PyList_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_4, ((PyObject *)(&PyList_Type))); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3429, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF_SET(__pyx_v_streams_by_order, __pyx_t_7); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3430 - * - * streams_by_order = collections.defaultdict(list) - * drop_distance_collection = collections.defaultdict(list) # <<<<<<<<<<<<<< - * max_upstream_flow_accum = collections.defaultdict(int) - * while upstream_stack: - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_collections); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3430, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3430, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(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); - } - } - __pyx_t_7 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_4, ((PyObject *)(&PyList_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_8, ((PyObject *)(&PyList_Type))); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3430, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_XDECREF_SET(__pyx_v_drop_distance_collection, __pyx_t_7); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3431 - * streams_by_order = collections.defaultdict(list) - * drop_distance_collection = collections.defaultdict(list) - * max_upstream_flow_accum = collections.defaultdict(int) # <<<<<<<<<<<<<< - * while upstream_stack: - * feature_id = upstream_stack.pop() - */ - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_collections); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3431, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3431, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = NULL; - 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_7 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_8, ((PyObject *)(&PyInt_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_4, ((PyObject *)(&PyInt_Type))); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3431, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF_SET(__pyx_v_max_upstream_flow_accum, __pyx_t_7); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3432 - * drop_distance_collection = collections.defaultdict(list) - * max_upstream_flow_accum = collections.defaultdict(int) - * while upstream_stack: # <<<<<<<<<<<<<< - * feature_id = upstream_stack.pop() - * stream_feature = stream_layer.GetFeature(feature_id) - */ - while (1) { - __pyx_t_21 = (PyList_GET_SIZE(__pyx_v_upstream_stack) != 0); - if (!__pyx_t_21) break; - - /* "pygeoprocessing/routing/routing.pyx":3433 - * max_upstream_flow_accum = collections.defaultdict(int) - * while upstream_stack: - * feature_id = upstream_stack.pop() # <<<<<<<<<<<<<< - * stream_feature = stream_layer.GetFeature(feature_id) - * stream_feature.SetField('river_id', working_river_id) - */ - __pyx_t_7 = __Pyx_PyList_Pop(__pyx_v_upstream_stack); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3433, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF_SET(__pyx_v_feature_id, __pyx_t_7); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3434 - * while upstream_stack: - * feature_id = upstream_stack.pop() - * stream_feature = stream_layer.GetFeature(feature_id) # <<<<<<<<<<<<<< - * stream_feature.SetField('river_id', working_river_id) - * stream_layer.SetFeature(stream_feature) - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3434, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_7 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_8, __pyx_v_feature_id) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_feature_id); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3434, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF_SET(__pyx_v_stream_feature, __pyx_t_7); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3435 - * feature_id = upstream_stack.pop() - * stream_feature = stream_layer.GetFeature(feature_id) - * stream_feature.SetField('river_id', working_river_id) # <<<<<<<<<<<<<< - * stream_layer.SetFeature(stream_feature) - * order = stream_feature.GetField('order') - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3435, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = NULL; - __pyx_t_11 = 0; - if (CYTHON_UNPACK_METHODS && likely(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_11 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_n_u_river_id, __pyx_v_working_river_id}; - __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, 3435, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_7); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_n_u_river_id, __pyx_v_working_river_id}; - __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, 3435, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_7); - } else - #endif - { - __pyx_t_3 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3435, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (__pyx_t_8) { - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8); __pyx_t_8 = NULL; - } - __Pyx_INCREF(__pyx_n_u_river_id); - __Pyx_GIVEREF(__pyx_n_u_river_id); - PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_11, __pyx_n_u_river_id); - __Pyx_INCREF(__pyx_v_working_river_id); - __Pyx_GIVEREF(__pyx_v_working_river_id); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_11, __pyx_v_working_river_id); - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3435, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3436 - * stream_feature = stream_layer.GetFeature(feature_id) - * stream_feature.SetField('river_id', working_river_id) - * stream_layer.SetFeature(stream_feature) # <<<<<<<<<<<<<< - * order = stream_feature.GetField('order') - * streams_by_order[order].append(stream_feature) - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_SetFeature); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3436, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_7 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_v_stream_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_stream_feature); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3436, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3437 - * stream_feature.SetField('river_id', working_river_id) - * stream_layer.SetFeature(stream_feature) - * order = stream_feature.GetField('order') # <<<<<<<<<<<<<< - * streams_by_order[order].append(stream_feature) - * drop_distance_collection[order].append( - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3437, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_7 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_n_u_order) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_n_u_order); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3437, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF_SET(__pyx_v_order, __pyx_t_7); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3438 - * stream_layer.SetFeature(stream_feature) - * order = stream_feature.GetField('order') - * streams_by_order[order].append(stream_feature) # <<<<<<<<<<<<<< - * drop_distance_collection[order].append( - * stream_feature.GetField('drop_distance')) - */ - __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_streams_by_order, __pyx_v_order); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3438, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_27 = __Pyx_PyObject_Append(__pyx_t_7, __pyx_v_stream_feature); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3438, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3439 - * order = stream_feature.GetField('order') - * streams_by_order[order].append(stream_feature) - * drop_distance_collection[order].append( # <<<<<<<<<<<<<< - * stream_feature.GetField('drop_distance')) - * max_upstream_flow_accum[order] = max( - */ - __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_drop_distance_collection, __pyx_v_order); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3439, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - - /* "pygeoprocessing/routing/routing.pyx":3440 - * streams_by_order[order].append(stream_feature) - * drop_distance_collection[order].append( - * stream_feature.GetField('drop_distance')) # <<<<<<<<<<<<<< - * max_upstream_flow_accum[order] = max( - * max_upstream_flow_accum[order], - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3440, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_4 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_8, __pyx_n_u_drop_distance) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_n_u_drop_distance); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3440, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3439 - * order = stream_feature.GetField('order') - * streams_by_order[order].append(stream_feature) - * drop_distance_collection[order].append( # <<<<<<<<<<<<<< - * stream_feature.GetField('drop_distance')) - * max_upstream_flow_accum[order] = max( - */ - __pyx_t_27 = __Pyx_PyObject_Append(__pyx_t_7, __pyx_t_4); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3439, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3443 - * max_upstream_flow_accum[order] = max( - * max_upstream_flow_accum[order], - * stream_feature.GetField('us_fa')) # <<<<<<<<<<<<<< - * stream_feature = None - * upstream_stack.extend( - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3443, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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); - } - } - __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_3, __pyx_n_u_us_fa) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_n_u_us_fa); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3443, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3442 - * stream_feature.GetField('drop_distance')) - * max_upstream_flow_accum[order] = max( - * max_upstream_flow_accum[order], # <<<<<<<<<<<<<< - * stream_feature.GetField('us_fa')) - * stream_feature = None - */ - __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_max_upstream_flow_accum, __pyx_v_order); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3442, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - - /* "pygeoprocessing/routing/routing.pyx":3443 - * max_upstream_flow_accum[order] = max( - * max_upstream_flow_accum[order], - * stream_feature.GetField('us_fa')) # <<<<<<<<<<<<<< - * stream_feature = None - * upstream_stack.extend( - */ - __pyx_t_8 = PyObject_RichCompare(__pyx_t_4, __pyx_t_7, Py_GT); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3443, __pyx_L1_error) - __pyx_t_21 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3443, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (__pyx_t_21) { - __Pyx_INCREF(__pyx_t_4); - __pyx_t_3 = __pyx_t_4; - } else { - __Pyx_INCREF(__pyx_t_7); - __pyx_t_3 = __pyx_t_7; - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __pyx_t_3; - __Pyx_INCREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3441 - * drop_distance_collection[order].append( - * stream_feature.GetField('drop_distance')) - * max_upstream_flow_accum[order] = max( # <<<<<<<<<<<<<< - * max_upstream_flow_accum[order], - * stream_feature.GetField('us_fa')) - */ - if (unlikely(PyObject_SetItem(__pyx_v_max_upstream_flow_accum, __pyx_v_order, __pyx_t_4) < 0)) __PYX_ERR(0, 3441, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3444 - * max_upstream_flow_accum[order], - * stream_feature.GetField('us_fa')) - * stream_feature = None # <<<<<<<<<<<<<< - * upstream_stack.extend( - * downstream_to_upstream_ids[feature_id]) - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_stream_feature, Py_None); - - /* "pygeoprocessing/routing/routing.pyx":3446 - * stream_feature = None - * upstream_stack.extend( - * downstream_to_upstream_ids[feature_id]) # <<<<<<<<<<<<<< - * - * working_flow_accum_threshold = min_flow_accum_threshold - */ - __pyx_t_4 = __Pyx_PyDict_GetItem(__pyx_v_downstream_to_upstream_ids, __pyx_v_feature_id); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3446, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - - /* "pygeoprocessing/routing/routing.pyx":3445 - * stream_feature.GetField('us_fa')) - * stream_feature = None - * upstream_stack.extend( # <<<<<<<<<<<<<< - * downstream_to_upstream_ids[feature_id]) - * - */ - __pyx_t_27 = __Pyx_PyList_Extend(__pyx_v_upstream_stack, __pyx_t_4); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3445, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - - /* "pygeoprocessing/routing/routing.pyx":3448 - * downstream_to_upstream_ids[feature_id]) - * - * working_flow_accum_threshold = min_flow_accum_threshold # <<<<<<<<<<<<<< - * while drop_distance_collection and autotune_flow_accumulation: - * stream_layer.CommitTransaction() - */ - __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_v_min_flow_accum_threshold); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3448, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_XDECREF_SET(__pyx_v_working_flow_accum_threshold, __pyx_t_4); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3449 - * - * working_flow_accum_threshold = min_flow_accum_threshold - * while drop_distance_collection and autotune_flow_accumulation: # <<<<<<<<<<<<<< - * stream_layer.CommitTransaction() - * stream_layer.StartTransaction() - */ - while (1) { - __pyx_t_29 = __Pyx_PyObject_IsTrue(__pyx_v_drop_distance_collection); if (unlikely(__pyx_t_29 < 0)) __PYX_ERR(0, 3449, __pyx_L1_error) - if (__pyx_t_29) { - } else { - __pyx_t_21 = __pyx_t_29; - goto __pyx_L78_bool_binop_done; - } - __pyx_t_29 = __Pyx_PyObject_IsTrue(__pyx_v_autotune_flow_accumulation); if (unlikely(__pyx_t_29 < 0)) __PYX_ERR(0, 3449, __pyx_L1_error) - __pyx_t_21 = __pyx_t_29; - __pyx_L78_bool_binop_done:; - if (!__pyx_t_21) break; - - /* "pygeoprocessing/routing/routing.pyx":3450 - * working_flow_accum_threshold = min_flow_accum_threshold - * while drop_distance_collection and autotune_flow_accumulation: - * stream_layer.CommitTransaction() # <<<<<<<<<<<<<< - * stream_layer.StartTransaction() - * # decide how much bigger to make the flow_accum - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CommitTransaction); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3450, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3450, __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":3451 - * while drop_distance_collection and autotune_flow_accumulation: - * stream_layer.CommitTransaction() - * stream_layer.StartTransaction() # <<<<<<<<<<<<<< - * # decide how much bigger to make the flow_accum - * # find a test_order that tests p_val > 0.5 then retest - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_StartTransaction); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3451, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3451, __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":3454 - * # decide how much bigger to make the flow_accum - * # find a test_order that tests p_val > 0.5 then retest - * test_order = min(drop_distance_collection) # <<<<<<<<<<<<<< - * while test_order+1 <= max(drop_distance_collection): - * if (len(drop_distance_collection[test_order]) < 3 or - */ - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_min, __pyx_v_drop_distance_collection); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3454, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_XDECREF_SET(__pyx_v_test_order, __pyx_t_4); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3455 - * # find a test_order that tests p_val > 0.5 then retest - * test_order = min(drop_distance_collection) - * while test_order+1 <= max(drop_distance_collection): # <<<<<<<<<<<<<< - * if (len(drop_distance_collection[test_order]) < 3 or - * len(drop_distance_collection[ - */ - while (1) { - __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_v_test_order, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3455, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_max, __pyx_v_drop_distance_collection); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3455, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_LE); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3455, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_21 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3455, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (!__pyx_t_21) break; - - /* "pygeoprocessing/routing/routing.pyx":3456 - * test_order = min(drop_distance_collection) - * while test_order+1 <= max(drop_distance_collection): - * if (len(drop_distance_collection[test_order]) < 3 or # <<<<<<<<<<<<<< - * len(drop_distance_collection[ - * test_order+1]) < 3): - */ - __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_drop_distance_collection, __pyx_v_test_order); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3456, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_15 = PyObject_Length(__pyx_t_7); if (unlikely(__pyx_t_15 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3456, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_29 = ((__pyx_t_15 < 3) != 0); - if (!__pyx_t_29) { - } else { - __pyx_t_21 = __pyx_t_29; - goto __pyx_L83_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":3458 - * if (len(drop_distance_collection[test_order]) < 3 or - * len(drop_distance_collection[ - * test_order+1]) < 3): # <<<<<<<<<<<<<< - * # too small to test so it's not significant - * break - */ - __pyx_t_7 = __Pyx_PyInt_AddObjC(__pyx_v_test_order, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3458, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - - /* "pygeoprocessing/routing/routing.pyx":3457 - * while test_order+1 <= max(drop_distance_collection): - * if (len(drop_distance_collection[test_order]) < 3 or - * len(drop_distance_collection[ # <<<<<<<<<<<<<< - * test_order+1]) < 3): - * # too small to test so it's not significant - */ - __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_drop_distance_collection, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3457, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_15 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_15 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3457, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3458 - * if (len(drop_distance_collection[test_order]) < 3 or - * len(drop_distance_collection[ - * test_order+1]) < 3): # <<<<<<<<<<<<<< - * # too small to test so it's not significant - * break - */ - __pyx_t_29 = ((__pyx_t_15 < 3) != 0); - __pyx_t_21 = __pyx_t_29; - __pyx_L83_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":3456 - * test_order = min(drop_distance_collection) - * while test_order+1 <= max(drop_distance_collection): - * if (len(drop_distance_collection[test_order]) < 3 or # <<<<<<<<<<<<<< - * len(drop_distance_collection[ - * test_order+1]) < 3): - */ - if (__pyx_t_21) { - - /* "pygeoprocessing/routing/routing.pyx":3460 - * test_order+1]) < 3): - * # too small to test so it's not significant - * break # <<<<<<<<<<<<<< - * _, p_val = scipy.stats.ttest_ind( - * drop_distance_collection[test_order], - */ - goto __pyx_L81_break; - - /* "pygeoprocessing/routing/routing.pyx":3456 - * test_order = min(drop_distance_collection) - * while test_order+1 <= max(drop_distance_collection): - * if (len(drop_distance_collection[test_order]) < 3 or # <<<<<<<<<<<<<< - * len(drop_distance_collection[ - * test_order+1]) < 3): - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3461 - * # too small to test so it's not significant - * break - * _, p_val = scipy.stats.ttest_ind( # <<<<<<<<<<<<<< - * drop_distance_collection[test_order], - * drop_distance_collection[test_order+1], - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_scipy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3461, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_stats); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3461, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_ttest_ind); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3461, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3462 - * break - * _, p_val = scipy.stats.ttest_ind( - * drop_distance_collection[test_order], # <<<<<<<<<<<<<< - * drop_distance_collection[test_order+1], - * equal_var=True) - */ - __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_drop_distance_collection, __pyx_v_test_order); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3462, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - - /* "pygeoprocessing/routing/routing.pyx":3463 - * _, p_val = scipy.stats.ttest_ind( - * drop_distance_collection[test_order], - * drop_distance_collection[test_order+1], # <<<<<<<<<<<<<< - * equal_var=True) - * if p_val > min_p_val or numpy.isnan(p_val): - */ - __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_v_test_order, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3463, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_drop_distance_collection, __pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3463, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3461 - * # too small to test so it's not significant - * break - * _, p_val = scipy.stats.ttest_ind( # <<<<<<<<<<<<<< - * drop_distance_collection[test_order], - * drop_distance_collection[test_order+1], - */ - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3461, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_8); - __pyx_t_7 = 0; - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3464 - * drop_distance_collection[test_order], - * drop_distance_collection[test_order+1], - * equal_var=True) # <<<<<<<<<<<<<< - * if p_val > min_p_val or numpy.isnan(p_val): - * # not too big or just too few elements - */ - __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3464, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_equal_var, Py_True) < 0) __PYX_ERR(0, 3464, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3461 - * # too small to test so it's not significant - * break - * _, p_val = scipy.stats.ttest_ind( # <<<<<<<<<<<<<< - * drop_distance_collection[test_order], - * drop_distance_collection[test_order+1], - */ - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3461, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) { - PyObject* sequence = __pyx_t_7; - 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, 3461, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_8 = PyList_GET_ITEM(sequence, 0); - __pyx_t_4 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(__pyx_t_4); - #else - __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3461, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3461, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_3 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3461, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_10 = Py_TYPE(__pyx_t_3)->tp_iternext; - index = 0; __pyx_t_8 = __pyx_t_10(__pyx_t_3); if (unlikely(!__pyx_t_8)) goto __pyx_L85_unpacking_failed; - __Pyx_GOTREF(__pyx_t_8); - index = 1; __pyx_t_4 = __pyx_t_10(__pyx_t_3); if (unlikely(!__pyx_t_4)) goto __pyx_L85_unpacking_failed; - __Pyx_GOTREF(__pyx_t_4); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_3), 2) < 0) __PYX_ERR(0, 3461, __pyx_L1_error) - __pyx_t_10 = NULL; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L86_unpacking_done; - __pyx_L85_unpacking_failed:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_10 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 3461, __pyx_L1_error) - __pyx_L86_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_8); - __pyx_t_8 = 0; - __Pyx_XDECREF_SET(__pyx_v_p_val, __pyx_t_4); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3465 - * drop_distance_collection[test_order+1], - * equal_var=True) - * if p_val > min_p_val or numpy.isnan(p_val): # <<<<<<<<<<<<<< - * # not too big or just too few elements - * break - */ - __pyx_t_7 = PyFloat_FromDouble(__pyx_v_min_p_val); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3465, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_4 = PyObject_RichCompare(__pyx_v_p_val, __pyx_t_7, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3465, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_29 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_29 < 0)) __PYX_ERR(0, 3465, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (!__pyx_t_29) { - } else { - __pyx_t_21 = __pyx_t_29; - goto __pyx_L88_bool_binop_done; - } - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_numpy); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3465, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_isnan); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3465, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __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); - } - } - __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_7, __pyx_v_p_val) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_p_val); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3465, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_29 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_29 < 0)) __PYX_ERR(0, 3465, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_21 = __pyx_t_29; - __pyx_L88_bool_binop_done:; - if (__pyx_t_21) { - - /* "pygeoprocessing/routing/routing.pyx":3467 - * if p_val > min_p_val or numpy.isnan(p_val): - * # not too big or just too few elements - * break # <<<<<<<<<<<<<< - * test_order += 1 - * if test_order == min(drop_distance_collection): - */ - goto __pyx_L81_break; - - /* "pygeoprocessing/routing/routing.pyx":3465 - * drop_distance_collection[test_order+1], - * equal_var=True) - * if p_val > min_p_val or numpy.isnan(p_val): # <<<<<<<<<<<<<< - * # not too big or just too few elements - * break - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3468 - * # not too big or just too few elements - * break - * test_order += 1 # <<<<<<<<<<<<<< - * if test_order == min(drop_distance_collection): - * # order 1/2 streams are not statistically different - */ - __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_v_test_order, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3468, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF_SET(__pyx_v_test_order, __pyx_t_4); - __pyx_t_4 = 0; - } - __pyx_L81_break:; - - /* "pygeoprocessing/routing/routing.pyx":3469 - * break - * test_order += 1 - * if test_order == min(drop_distance_collection): # <<<<<<<<<<<<<< - * # order 1/2 streams are not statistically different - * break - */ - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_min, __pyx_v_drop_distance_collection); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3469, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = PyObject_RichCompare(__pyx_v_test_order, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3469, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_21 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3469, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (__pyx_t_21) { - - /* "pygeoprocessing/routing/routing.pyx":3471 - * if test_order == min(drop_distance_collection): - * # order 1/2 streams are not statistically different - * break # <<<<<<<<<<<<<< - * # try to make a reasonable estimate for flow accum - * working_flow_accum_threshold *= 1.25 - */ - goto __pyx_L77_break; - - /* "pygeoprocessing/routing/routing.pyx":3469 - * break - * test_order += 1 - * if test_order == min(drop_distance_collection): # <<<<<<<<<<<<<< - * # order 1/2 streams are not statistically different - * break - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3473 - * break - * # try to make a reasonable estimate for flow accum - * working_flow_accum_threshold *= 1.25 # <<<<<<<<<<<<<< - * # reconstruct stream segments of <= test_order - * for order in range(1, test_order+1): - */ - __pyx_t_8 = PyNumber_InPlaceMultiply(__pyx_v_working_flow_accum_threshold, __pyx_float_1_25); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3473, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF_SET(__pyx_v_working_flow_accum_threshold, __pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3475 - * working_flow_accum_threshold *= 1.25 - * # reconstruct stream segments of <= test_order - * for order in range(1, test_order+1): # <<<<<<<<<<<<<< - * # This will build up a list of kept or reconstructed - * # streams. Other streams will be deleted. - */ - __pyx_t_8 = __Pyx_PyInt_AddObjC(__pyx_v_test_order, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3475, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3475, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_1); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_8); - __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_4, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3475, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (likely(PyList_CheckExact(__pyx_t_8)) || PyTuple_CheckExact(__pyx_t_8)) { - __pyx_t_4 = __pyx_t_8; __Pyx_INCREF(__pyx_t_4); __pyx_t_15 = 0; - __pyx_t_14 = NULL; - } else { - __pyx_t_15 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3475, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_14 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 3475, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - for (;;) { - if (likely(!__pyx_t_14)) { - if (likely(PyList_CheckExact(__pyx_t_4))) { - if (__pyx_t_15 >= PyList_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_8 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_15); __Pyx_INCREF(__pyx_t_8); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 3475, __pyx_L1_error) - #else - __pyx_t_8 = PySequence_ITEM(__pyx_t_4, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3475, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - #endif - } else { - if (__pyx_t_15 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_15); __Pyx_INCREF(__pyx_t_8); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 3475, __pyx_L1_error) - #else - __pyx_t_8 = PySequence_ITEM(__pyx_t_4, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3475, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - #endif - } - } else { - __pyx_t_8 = __pyx_t_14(__pyx_t_4); - if (unlikely(!__pyx_t_8)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 3475, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_8); - } - __Pyx_XDECREF_SET(__pyx_v_order, __pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3478 - * # This will build up a list of kept or reconstructed - * # streams. Other streams will be deleted. - * streams_to_retest = [] # <<<<<<<<<<<<<< - * # The drop distance set will be recalculated - * # dynamically for the next loop - */ - __pyx_t_8 = PyList_New(0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3478, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_XDECREF_SET(__pyx_v_streams_to_retest, ((PyObject*)__pyx_t_8)); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3481 - * # The drop distance set will be recalculated - * # dynamically for the next loop - * if order in max_upstream_flow_accum: # <<<<<<<<<<<<<< - * del max_upstream_flow_accum[order] - * if order in drop_distance_collection: - */ - __pyx_t_21 = (__Pyx_PySequence_ContainsTF(__pyx_v_order, __pyx_v_max_upstream_flow_accum, Py_EQ)); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3481, __pyx_L1_error) - __pyx_t_29 = (__pyx_t_21 != 0); - if (__pyx_t_29) { - - /* "pygeoprocessing/routing/routing.pyx":3482 - * # dynamically for the next loop - * if order in max_upstream_flow_accum: - * del max_upstream_flow_accum[order] # <<<<<<<<<<<<<< - * if order in drop_distance_collection: - * del drop_distance_collection[order] - */ - if (unlikely(PyObject_DelItem(__pyx_v_max_upstream_flow_accum, __pyx_v_order) < 0)) __PYX_ERR(0, 3482, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3481 - * # The drop distance set will be recalculated - * # dynamically for the next loop - * if order in max_upstream_flow_accum: # <<<<<<<<<<<<<< - * del max_upstream_flow_accum[order] - * if order in drop_distance_collection: - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3483 - * if order in max_upstream_flow_accum: - * del max_upstream_flow_accum[order] - * if order in drop_distance_collection: # <<<<<<<<<<<<<< - * del drop_distance_collection[order] - * while streams_by_order[order]: - */ - __pyx_t_29 = (__Pyx_PySequence_ContainsTF(__pyx_v_order, __pyx_v_drop_distance_collection, Py_EQ)); if (unlikely(__pyx_t_29 < 0)) __PYX_ERR(0, 3483, __pyx_L1_error) - __pyx_t_21 = (__pyx_t_29 != 0); - if (__pyx_t_21) { - - /* "pygeoprocessing/routing/routing.pyx":3484 - * del max_upstream_flow_accum[order] - * if order in drop_distance_collection: - * del drop_distance_collection[order] # <<<<<<<<<<<<<< - * while streams_by_order[order]: - * stream_feature = streams_by_order[order].pop() - */ - if (unlikely(PyObject_DelItem(__pyx_v_drop_distance_collection, __pyx_v_order) < 0)) __PYX_ERR(0, 3484, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3483 - * if order in max_upstream_flow_accum: - * del max_upstream_flow_accum[order] - * if order in drop_distance_collection: # <<<<<<<<<<<<<< - * del drop_distance_collection[order] - * while streams_by_order[order]: - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3485 - * if order in drop_distance_collection: - * del drop_distance_collection[order] - * while streams_by_order[order]: # <<<<<<<<<<<<<< - * stream_feature = streams_by_order[order].pop() - * if (stream_feature.GetField('ds_fa') < - */ - while (1) { - __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_streams_by_order, __pyx_v_order); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3485, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_21 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3485, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (!__pyx_t_21) break; - - /* "pygeoprocessing/routing/routing.pyx":3486 - * del drop_distance_collection[order] - * while streams_by_order[order]: - * stream_feature = streams_by_order[order].pop() # <<<<<<<<<<<<<< - * if (stream_feature.GetField('ds_fa') < - * working_flow_accum_threshold): - */ - __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_streams_by_order, __pyx_v_order); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3486, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_7 = __Pyx_PyObject_Pop(__pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3486, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF_SET(__pyx_v_stream_feature, __pyx_t_7); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3487 - * while streams_by_order[order]: - * stream_feature = streams_by_order[order].pop() - * if (stream_feature.GetField('ds_fa') < # <<<<<<<<<<<<<< - * working_flow_accum_threshold): - * # this flow accumulation is too small, it's - */ - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3487, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - } - } - __pyx_t_7 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_3, __pyx_n_u_ds_fa) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_n_u_ds_fa); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3487, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3488 - * stream_feature = streams_by_order[order].pop() - * if (stream_feature.GetField('ds_fa') < - * working_flow_accum_threshold): # <<<<<<<<<<<<<< - * # this flow accumulation is too small, it's - * # not relevant anymore - */ - __pyx_t_8 = PyObject_RichCompare(__pyx_t_7, __pyx_v_working_flow_accum_threshold, Py_LT); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3487, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3487 - * while streams_by_order[order]: - * stream_feature = streams_by_order[order].pop() - * if (stream_feature.GetField('ds_fa') < # <<<<<<<<<<<<<< - * working_flow_accum_threshold): - * # this flow accumulation is too small, it's - */ - __pyx_t_21 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3487, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (__pyx_t_21) { - - /* "pygeoprocessing/routing/routing.pyx":3492 - * # not relevant anymore - * # remove from connectivity and delete - * _delete_feature( # <<<<<<<<<<<<<< - * stream_feature, stream_layer, - * upstream_to_downstream_id, - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_delete_feature); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3492, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - - /* "pygeoprocessing/routing/routing.pyx":3495 - * stream_feature, stream_layer, - * upstream_to_downstream_id, - * downstream_to_upstream_ids) # <<<<<<<<<<<<<< - * continue - * if (stream_feature.GetField('us_fa') >= - */ - __pyx_t_3 = NULL; - __pyx_t_11 = 0; - 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); - __pyx_t_11 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[5] = {__pyx_t_3, __pyx_v_stream_feature, __pyx_v_stream_layer, __pyx_v_upstream_to_downstream_id, __pyx_v_downstream_to_upstream_ids}; - __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 4+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3492, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_8); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[5] = {__pyx_t_3, __pyx_v_stream_feature, __pyx_v_stream_layer, __pyx_v_upstream_to_downstream_id, __pyx_v_downstream_to_upstream_ids}; - __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 4+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3492, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_8); - } else - #endif - { - __pyx_t_2 = PyTuple_New(4+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3492, __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_v_stream_feature); - __Pyx_GIVEREF(__pyx_v_stream_feature); - PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_11, __pyx_v_stream_feature); - __Pyx_INCREF(__pyx_v_stream_layer); - __Pyx_GIVEREF(__pyx_v_stream_layer); - PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_11, __pyx_v_stream_layer); - __Pyx_INCREF(__pyx_v_upstream_to_downstream_id); - __Pyx_GIVEREF(__pyx_v_upstream_to_downstream_id); - PyTuple_SET_ITEM(__pyx_t_2, 2+__pyx_t_11, __pyx_v_upstream_to_downstream_id); - __Pyx_INCREF(__pyx_v_downstream_to_upstream_ids); - __Pyx_GIVEREF(__pyx_v_downstream_to_upstream_ids); - PyTuple_SET_ITEM(__pyx_t_2, 3+__pyx_t_11, __pyx_v_downstream_to_upstream_ids); - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_2, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3492, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3496 - * upstream_to_downstream_id, - * downstream_to_upstream_ids) - * continue # <<<<<<<<<<<<<< - * if (stream_feature.GetField('us_fa') >= - * working_flow_accum_threshold): - */ - goto __pyx_L95_continue; - - /* "pygeoprocessing/routing/routing.pyx":3487 - * while streams_by_order[order]: - * stream_feature = streams_by_order[order].pop() - * if (stream_feature.GetField('ds_fa') < # <<<<<<<<<<<<<< - * working_flow_accum_threshold): - * # this flow accumulation is too small, it's - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3497 - * downstream_to_upstream_ids) - * continue - * if (stream_feature.GetField('us_fa') >= # <<<<<<<<<<<<<< - * working_flow_accum_threshold): - * # this whole stream still fits in the - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3497, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_8 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_2, __pyx_n_u_us_fa) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_n_u_us_fa); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3497, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3498 - * continue - * if (stream_feature.GetField('us_fa') >= - * working_flow_accum_threshold): # <<<<<<<<<<<<<< - * # this whole stream still fits in the - * # threshold so keep it - */ - __pyx_t_7 = PyObject_RichCompare(__pyx_t_8, __pyx_v_working_flow_accum_threshold, Py_GE); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3497, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3497 - * downstream_to_upstream_ids) - * continue - * if (stream_feature.GetField('us_fa') >= # <<<<<<<<<<<<<< - * working_flow_accum_threshold): - * # this whole stream still fits in the - */ - __pyx_t_21 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3497, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (__pyx_t_21) { - - /* "pygeoprocessing/routing/routing.pyx":3502 - * # threshold so keep it - * # add drop distance to working set - * drop_distance_collection[order].append( # <<<<<<<<<<<<<< - * stream_feature.GetField('drop_distance')) - * max_upstream_flow_accum[order] = max( - */ - __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_drop_distance_collection, __pyx_v_order); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3502, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - - /* "pygeoprocessing/routing/routing.pyx":3503 - * # add drop distance to working set - * drop_distance_collection[order].append( - * stream_feature.GetField('drop_distance')) # <<<<<<<<<<<<<< - * max_upstream_flow_accum[order] = max( - * max_upstream_flow_accum[order], - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3503, __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); - } - } - __pyx_t_8 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_n_u_drop_distance) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_n_u_drop_distance); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3503, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3502 - * # threshold so keep it - * # add drop distance to working set - * drop_distance_collection[order].append( # <<<<<<<<<<<<<< - * stream_feature.GetField('drop_distance')) - * max_upstream_flow_accum[order] = max( - */ - __pyx_t_27 = __Pyx_PyObject_Append(__pyx_t_7, __pyx_t_8); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3502, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3506 - * max_upstream_flow_accum[order] = max( - * max_upstream_flow_accum[order], - * stream_feature.GetField('us_fa')) # <<<<<<<<<<<<<< - * stream_layer.SetFeature(stream_feature) - * streams_to_retest.append(stream_feature) - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3506, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_8 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_2, __pyx_n_u_us_fa) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_n_u_us_fa); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3506, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3505 - * stream_feature.GetField('drop_distance')) - * max_upstream_flow_accum[order] = max( - * max_upstream_flow_accum[order], # <<<<<<<<<<<<<< - * stream_feature.GetField('us_fa')) - * stream_layer.SetFeature(stream_feature) - */ - __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_max_upstream_flow_accum, __pyx_v_order); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3505, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - - /* "pygeoprocessing/routing/routing.pyx":3506 - * max_upstream_flow_accum[order] = max( - * max_upstream_flow_accum[order], - * stream_feature.GetField('us_fa')) # <<<<<<<<<<<<<< - * stream_layer.SetFeature(stream_feature) - * streams_to_retest.append(stream_feature) - */ - __pyx_t_3 = PyObject_RichCompare(__pyx_t_8, __pyx_t_7, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3506, __pyx_L1_error) - __pyx_t_21 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3506, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_21) { - __Pyx_INCREF(__pyx_t_8); - __pyx_t_2 = __pyx_t_8; - } else { - __Pyx_INCREF(__pyx_t_7); - __pyx_t_2 = __pyx_t_7; - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __pyx_t_2; - __Pyx_INCREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3504 - * drop_distance_collection[order].append( - * stream_feature.GetField('drop_distance')) - * max_upstream_flow_accum[order] = max( # <<<<<<<<<<<<<< - * max_upstream_flow_accum[order], - * stream_feature.GetField('us_fa')) - */ - if (unlikely(PyObject_SetItem(__pyx_v_max_upstream_flow_accum, __pyx_v_order, __pyx_t_8) < 0)) __PYX_ERR(0, 3504, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3507 - * max_upstream_flow_accum[order], - * stream_feature.GetField('us_fa')) - * stream_layer.SetFeature(stream_feature) # <<<<<<<<<<<<<< - * streams_to_retest.append(stream_feature) - * continue - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_SetFeature); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3507, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_7, __pyx_v_stream_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_stream_feature); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3507, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3508 - * stream_feature.GetField('us_fa')) - * stream_layer.SetFeature(stream_feature) - * streams_to_retest.append(stream_feature) # <<<<<<<<<<<<<< - * continue - * # recalculate stream geometry - */ - __pyx_t_27 = __Pyx_PyList_Append(__pyx_v_streams_to_retest, __pyx_v_stream_feature); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3508, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3509 - * stream_layer.SetFeature(stream_feature) - * streams_to_retest.append(stream_feature) - * continue # <<<<<<<<<<<<<< - * # recalculate stream geometry - * ds_x = stream_feature.GetField('ds_x') - */ - goto __pyx_L95_continue; - - /* "pygeoprocessing/routing/routing.pyx":3497 - * downstream_to_upstream_ids) - * continue - * if (stream_feature.GetField('us_fa') >= # <<<<<<<<<<<<<< - * working_flow_accum_threshold): - * # this whole stream still fits in the - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3511 - * continue - * # recalculate stream geometry - * ds_x = stream_feature.GetField('ds_x') # <<<<<<<<<<<<<< - * ds_y = stream_feature.GetField('ds_y') - * upstream_d8_dir = stream_feature.GetField( - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3511, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_7, __pyx_n_u_ds_x) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_n_u_ds_x); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3511, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF_SET(__pyx_v_ds_x, __pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3512 - * # recalculate stream geometry - * ds_x = stream_feature.GetField('ds_x') - * ds_y = stream_feature.GetField('ds_y') # <<<<<<<<<<<<<< - * upstream_d8_dir = stream_feature.GetField( - * 'upstream_d8_dir') - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3512, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_7, __pyx_n_u_ds_y) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_n_u_ds_y); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3512, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF_SET(__pyx_v_ds_y, __pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3513 - * ds_x = stream_feature.GetField('ds_x') - * ds_y = stream_feature.GetField('ds_y') - * upstream_d8_dir = stream_feature.GetField( # <<<<<<<<<<<<<< - * 'upstream_d8_dir') - * payload = _calculate_stream_geometry( - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3513, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_7, __pyx_n_u_upstream_d8_dir) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_n_u_upstream_d8_dir); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3513, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF_SET(__pyx_v_upstream_d8_dir, __pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3516 - * 'upstream_d8_dir') - * payload = _calculate_stream_geometry( - * ds_x, ds_y, upstream_d8_dir, # <<<<<<<<<<<<<< - * flow_dir_info['geotransform'], n_cols, n_rows, - * flow_accum_managed_raster, - */ - __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_v_ds_x); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3516, __pyx_L1_error) - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_v_ds_y); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3516, __pyx_L1_error) - __pyx_t_17 = __Pyx_PyInt_As_int(__pyx_v_upstream_d8_dir); if (unlikely((__pyx_t_17 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3516, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3517 - * payload = _calculate_stream_geometry( - * ds_x, ds_y, upstream_d8_dir, - * flow_dir_info['geotransform'], n_cols, n_rows, # <<<<<<<<<<<<<< - * flow_accum_managed_raster, - * flow_dir_managed_raster, flow_nodata, - */ - __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_geotransform); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3517, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - - /* "pygeoprocessing/routing/routing.pyx":3520 - * flow_accum_managed_raster, - * flow_dir_managed_raster, flow_nodata, - * working_flow_accum_threshold, # <<<<<<<<<<<<<< - * coord_to_stream_ids) - * if payload is None: - */ - __pyx_t_18 = __Pyx_PyInt_As_int(__pyx_v_working_flow_accum_threshold); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3520, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3515 - * upstream_d8_dir = stream_feature.GetField( - * 'upstream_d8_dir') - * payload = _calculate_stream_geometry( # <<<<<<<<<<<<<< - * ds_x, ds_y, upstream_d8_dir, - * flow_dir_info['geotransform'], n_cols, n_rows, - */ - __pyx_t_2 = __pyx_f_15pygeoprocessing_7routing_7routing__calculate_stream_geometry(__pyx_t_11, __pyx_t_6, __pyx_t_17, __pyx_t_8, __pyx_v_n_cols, __pyx_v_n_rows, __pyx_v_flow_accum_managed_raster, __pyx_v_flow_dir_managed_raster, __pyx_v_flow_nodata, __pyx_t_18, __pyx_v_coord_to_stream_ids); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3515, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_XDECREF_SET(__pyx_v_payload, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3522 - * working_flow_accum_threshold, - * coord_to_stream_ids) - * if payload is None: # <<<<<<<<<<<<<< - * _delete_feature( - * stream_feature, stream_layer, - */ - __pyx_t_21 = (__pyx_v_payload == Py_None); - __pyx_t_29 = (__pyx_t_21 != 0); - if (__pyx_t_29) { - - /* "pygeoprocessing/routing/routing.pyx":3523 - * coord_to_stream_ids) - * if payload is None: - * _delete_feature( # <<<<<<<<<<<<<< - * stream_feature, stream_layer, - * upstream_to_downstream_id, - */ - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_delete_feature); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3523, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - - /* "pygeoprocessing/routing/routing.pyx":3526 - * stream_feature, stream_layer, - * upstream_to_downstream_id, - * downstream_to_upstream_ids) # <<<<<<<<<<<<<< - * continue - * (x_u, y_u, ds_x_1, ds_y_1, upstream_id_list, - */ - __pyx_t_7 = NULL; - __pyx_t_18 = 0; - 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); - __pyx_t_18 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[5] = {__pyx_t_7, __pyx_v_stream_feature, __pyx_v_stream_layer, __pyx_v_upstream_to_downstream_id, __pyx_v_downstream_to_upstream_ids}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_18, 4+__pyx_t_18); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3523, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[5] = {__pyx_t_7, __pyx_v_stream_feature, __pyx_v_stream_layer, __pyx_v_upstream_to_downstream_id, __pyx_v_downstream_to_upstream_ids}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_18, 4+__pyx_t_18); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3523, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - { - __pyx_t_3 = PyTuple_New(4+__pyx_t_18); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3523, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (__pyx_t_7) { - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_7); __pyx_t_7 = NULL; - } - __Pyx_INCREF(__pyx_v_stream_feature); - __Pyx_GIVEREF(__pyx_v_stream_feature); - PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_18, __pyx_v_stream_feature); - __Pyx_INCREF(__pyx_v_stream_layer); - __Pyx_GIVEREF(__pyx_v_stream_layer); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_18, __pyx_v_stream_layer); - __Pyx_INCREF(__pyx_v_upstream_to_downstream_id); - __Pyx_GIVEREF(__pyx_v_upstream_to_downstream_id); - PyTuple_SET_ITEM(__pyx_t_3, 2+__pyx_t_18, __pyx_v_upstream_to_downstream_id); - __Pyx_INCREF(__pyx_v_downstream_to_upstream_ids); - __Pyx_GIVEREF(__pyx_v_downstream_to_upstream_ids); - PyTuple_SET_ITEM(__pyx_t_3, 3+__pyx_t_18, __pyx_v_downstream_to_upstream_ids); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3523, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3527 - * upstream_to_downstream_id, - * downstream_to_upstream_ids) - * continue # <<<<<<<<<<<<<< - * (x_u, y_u, ds_x_1, ds_y_1, upstream_id_list, - * stream_line) = payload - */ - goto __pyx_L95_continue; - - /* "pygeoprocessing/routing/routing.pyx":3522 - * working_flow_accum_threshold, - * coord_to_stream_ids) - * if payload is None: # <<<<<<<<<<<<<< - * _delete_feature( - * stream_feature, stream_layer, - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3529 - * continue - * (x_u, y_u, ds_x_1, ds_y_1, upstream_id_list, - * stream_line) = payload # <<<<<<<<<<<<<< - * # recalculate the drop distance set - * stream_feature.SetGeometry(stream_line) - */ - if ((likely(PyTuple_CheckExact(__pyx_v_payload))) || (PyList_CheckExact(__pyx_v_payload))) { - PyObject* sequence = __pyx_v_payload; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 6)) { - if (size > 6) __Pyx_RaiseTooManyValuesError(6); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 3528, __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_8 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 2); - __pyx_t_7 = PyTuple_GET_ITEM(sequence, 3); - __pyx_t_30 = PyTuple_GET_ITEM(sequence, 4); - __pyx_t_31 = PyTuple_GET_ITEM(sequence, 5); - } else { - __pyx_t_2 = PyList_GET_ITEM(sequence, 0); - __pyx_t_8 = PyList_GET_ITEM(sequence, 1); - __pyx_t_3 = PyList_GET_ITEM(sequence, 2); - __pyx_t_7 = PyList_GET_ITEM(sequence, 3); - __pyx_t_30 = PyList_GET_ITEM(sequence, 4); - __pyx_t_31 = PyList_GET_ITEM(sequence, 5); - } - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(__pyx_t_30); - __Pyx_INCREF(__pyx_t_31); - #else - { - Py_ssize_t i; - PyObject** temps[6] = {&__pyx_t_2,&__pyx_t_8,&__pyx_t_3,&__pyx_t_7,&__pyx_t_30,&__pyx_t_31}; - for (i=0; i < 6; i++) { - PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 3528, __pyx_L1_error) - __Pyx_GOTREF(item); - *(temps[i]) = item; - } - } - #endif - } else { - Py_ssize_t index = -1; - PyObject** temps[6] = {&__pyx_t_2,&__pyx_t_8,&__pyx_t_3,&__pyx_t_7,&__pyx_t_30,&__pyx_t_31}; - __pyx_t_32 = PyObject_GetIter(__pyx_v_payload); if (unlikely(!__pyx_t_32)) __PYX_ERR(0, 3528, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_32); - __pyx_t_10 = Py_TYPE(__pyx_t_32)->tp_iternext; - for (index=0; index < 6; index++) { - PyObject* item = __pyx_t_10(__pyx_t_32); if (unlikely(!item)) goto __pyx_L100_unpacking_failed; - __Pyx_GOTREF(item); - *(temps[index]) = item; - } - if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_32), 6) < 0) __PYX_ERR(0, 3528, __pyx_L1_error) - __pyx_t_10 = NULL; - __Pyx_DECREF(__pyx_t_32); __pyx_t_32 = 0; - goto __pyx_L101_unpacking_done; - __pyx_L100_unpacking_failed:; - __Pyx_DECREF(__pyx_t_32); __pyx_t_32 = 0; - __pyx_t_10 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 3528, __pyx_L1_error) - __pyx_L101_unpacking_done:; - } - - /* "pygeoprocessing/routing/routing.pyx":3528 - * downstream_to_upstream_ids) - * continue - * (x_u, y_u, ds_x_1, ds_y_1, upstream_id_list, # <<<<<<<<<<<<<< - * stream_line) = payload - * # recalculate the drop distance set - */ - __Pyx_XDECREF_SET(__pyx_v_x_u, __pyx_t_2); - __pyx_t_2 = 0; - __Pyx_XDECREF_SET(__pyx_v_y_u, __pyx_t_8); - __pyx_t_8 = 0; - __Pyx_XDECREF_SET(__pyx_v_ds_x_1, __pyx_t_3); - __pyx_t_3 = 0; - __Pyx_XDECREF_SET(__pyx_v_ds_y_1, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_XDECREF_SET(__pyx_v_upstream_id_list, __pyx_t_30); - __pyx_t_30 = 0; - __Pyx_XDECREF_SET(__pyx_v_stream_line, __pyx_t_31); - __pyx_t_31 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3531 - * stream_line) = payload - * # recalculate the drop distance set - * stream_feature.SetGeometry(stream_line) # <<<<<<<<<<<<<< - * upstream_dem = dem_managed_raster.get(x_u, y_u) - * downstream_dem = dem_managed_raster.get( - */ - __pyx_t_30 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetGeometry); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3531, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_30); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_30))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_30); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_30); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_30, function); - } - } - __pyx_t_31 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_30, __pyx_t_7, __pyx_v_stream_line) : __Pyx_PyObject_CallOneArg(__pyx_t_30, __pyx_v_stream_line); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3531, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3532 - * # recalculate the drop distance set - * stream_feature.SetGeometry(stream_line) - * upstream_dem = dem_managed_raster.get(x_u, y_u) # <<<<<<<<<<<<<< - * downstream_dem = dem_managed_raster.get( - * ds_x, ds_y) - */ - __pyx_t_18 = __Pyx_PyInt_As_int(__pyx_v_x_u); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3532, __pyx_L1_error) - __pyx_t_17 = __Pyx_PyInt_As_int(__pyx_v_y_u); if (unlikely((__pyx_t_17 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3532, __pyx_L1_error) - __pyx_v_upstream_dem = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_dem_managed_raster, __pyx_t_18, __pyx_t_17); - - /* "pygeoprocessing/routing/routing.pyx":3534 - * upstream_dem = dem_managed_raster.get(x_u, y_u) - * downstream_dem = dem_managed_raster.get( - * ds_x, ds_y) # <<<<<<<<<<<<<< - * drop_distance = upstream_dem - downstream_dem - * drop_distance_collection[order].append( - */ - __pyx_t_17 = __Pyx_PyInt_As_int(__pyx_v_ds_x); if (unlikely((__pyx_t_17 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3534, __pyx_L1_error) - __pyx_t_18 = __Pyx_PyInt_As_int(__pyx_v_ds_y); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3534, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3533 - * stream_feature.SetGeometry(stream_line) - * upstream_dem = dem_managed_raster.get(x_u, y_u) - * downstream_dem = dem_managed_raster.get( # <<<<<<<<<<<<<< - * ds_x, ds_y) - * drop_distance = upstream_dem - downstream_dem - */ - __pyx_v_downstream_dem = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_dem_managed_raster, __pyx_t_17, __pyx_t_18); - - /* "pygeoprocessing/routing/routing.pyx":3535 - * downstream_dem = dem_managed_raster.get( - * ds_x, ds_y) - * drop_distance = upstream_dem - downstream_dem # <<<<<<<<<<<<<< - * drop_distance_collection[order].append( - * drop_distance) - */ - __pyx_v_drop_distance = (__pyx_v_upstream_dem - __pyx_v_downstream_dem); - - /* "pygeoprocessing/routing/routing.pyx":3536 - * ds_x, ds_y) - * drop_distance = upstream_dem - downstream_dem - * drop_distance_collection[order].append( # <<<<<<<<<<<<<< - * drop_distance) - * stream_feature.SetField( - */ - __pyx_t_31 = __Pyx_PyObject_GetItem(__pyx_v_drop_distance_collection, __pyx_v_order); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3536, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - - /* "pygeoprocessing/routing/routing.pyx":3537 - * drop_distance = upstream_dem - downstream_dem - * drop_distance_collection[order].append( - * drop_distance) # <<<<<<<<<<<<<< - * stream_feature.SetField( - * 'drop_distance', drop_distance) - */ - __pyx_t_30 = PyFloat_FromDouble(__pyx_v_drop_distance); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3537, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_30); - - /* "pygeoprocessing/routing/routing.pyx":3536 - * ds_x, ds_y) - * drop_distance = upstream_dem - downstream_dem - * drop_distance_collection[order].append( # <<<<<<<<<<<<<< - * drop_distance) - * stream_feature.SetField( - */ - __pyx_t_27 = __Pyx_PyObject_Append(__pyx_t_31, __pyx_t_30); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3536, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3538 - * drop_distance_collection[order].append( - * drop_distance) - * stream_feature.SetField( # <<<<<<<<<<<<<< - * 'drop_distance', drop_distance) - * stream_feature.SetField( - */ - __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3538, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - - /* "pygeoprocessing/routing/routing.pyx":3539 - * drop_distance) - * stream_feature.SetField( - * 'drop_distance', drop_distance) # <<<<<<<<<<<<<< - * stream_feature.SetField( - * 'us_fa', flow_accum_managed_raster.get( - */ - __pyx_t_7 = PyFloat_FromDouble(__pyx_v_drop_distance); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3539, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_3 = NULL; - __pyx_t_18 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_31); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_31, function); - __pyx_t_18 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_31)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_drop_distance, __pyx_t_7}; - __pyx_t_30 = __Pyx_PyFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_18, 2+__pyx_t_18); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3538, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_30); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_31)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_drop_distance, __pyx_t_7}; - __pyx_t_30 = __Pyx_PyCFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_18, 2+__pyx_t_18); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3538, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_30); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - { - __pyx_t_8 = PyTuple_New(2+__pyx_t_18); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3538, __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_n_u_drop_distance); - __Pyx_GIVEREF(__pyx_n_u_drop_distance); - PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_18, __pyx_n_u_drop_distance); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_18, __pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_30 = __Pyx_PyObject_Call(__pyx_t_31, __pyx_t_8, NULL); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3538, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_30); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3540 - * stream_feature.SetField( - * 'drop_distance', drop_distance) - * stream_feature.SetField( # <<<<<<<<<<<<<< - * 'us_fa', flow_accum_managed_raster.get( - * x_u, y_u)) - */ - __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3540, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - - /* "pygeoprocessing/routing/routing.pyx":3542 - * stream_feature.SetField( - * 'us_fa', flow_accum_managed_raster.get( - * x_u, y_u)) # <<<<<<<<<<<<<< - * stream_feature.SetField( - * 'thresh_fa', working_flow_accum_threshold) - */ - __pyx_t_18 = __Pyx_PyInt_As_int(__pyx_v_x_u); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3542, __pyx_L1_error) - __pyx_t_17 = __Pyx_PyInt_As_int(__pyx_v_y_u); if (unlikely((__pyx_t_17 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3542, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3541 - * 'drop_distance', drop_distance) - * stream_feature.SetField( - * 'us_fa', flow_accum_managed_raster.get( # <<<<<<<<<<<<<< - * x_u, y_u)) - * stream_feature.SetField( - */ - __pyx_t_8 = PyFloat_FromDouble(__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_accum_managed_raster, __pyx_t_18, __pyx_t_17)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3541, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_7 = NULL; - __pyx_t_17 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_31); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_31, function); - __pyx_t_17 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_31)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_us_fa, __pyx_t_8}; - __pyx_t_30 = __Pyx_PyFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3540, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_30); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_31)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_n_u_us_fa, __pyx_t_8}; - __pyx_t_30 = __Pyx_PyCFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3540, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_30); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else - #endif - { - __pyx_t_3 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3540, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (__pyx_t_7) { - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_7); __pyx_t_7 = NULL; - } - __Pyx_INCREF(__pyx_n_u_us_fa); - __Pyx_GIVEREF(__pyx_n_u_us_fa); - PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_17, __pyx_n_u_us_fa); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_17, __pyx_t_8); - __pyx_t_8 = 0; - __pyx_t_30 = __Pyx_PyObject_Call(__pyx_t_31, __pyx_t_3, NULL); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3540, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_30); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3543 - * 'us_fa', flow_accum_managed_raster.get( - * x_u, y_u)) - * stream_feature.SetField( # <<<<<<<<<<<<<< - * 'thresh_fa', working_flow_accum_threshold) - * stream_feature.SetField( - */ - __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3543, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - - /* "pygeoprocessing/routing/routing.pyx":3544 - * x_u, y_u)) - * stream_feature.SetField( - * 'thresh_fa', working_flow_accum_threshold) # <<<<<<<<<<<<<< - * stream_feature.SetField( - * 'ds_x', ds_x) - */ - __pyx_t_3 = NULL; - __pyx_t_17 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_31); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_31, function); - __pyx_t_17 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_31)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_thresh_fa, __pyx_v_working_flow_accum_threshold}; - __pyx_t_30 = __Pyx_PyFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3543, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_30); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_31)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_thresh_fa, __pyx_v_working_flow_accum_threshold}; - __pyx_t_30 = __Pyx_PyCFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3543, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_30); - } else - #endif - { - __pyx_t_8 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3543, __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_n_u_thresh_fa); - __Pyx_GIVEREF(__pyx_n_u_thresh_fa); - PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_17, __pyx_n_u_thresh_fa); - __Pyx_INCREF(__pyx_v_working_flow_accum_threshold); - __Pyx_GIVEREF(__pyx_v_working_flow_accum_threshold); - PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_17, __pyx_v_working_flow_accum_threshold); - __pyx_t_30 = __Pyx_PyObject_Call(__pyx_t_31, __pyx_t_8, NULL); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3543, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_30); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3545 - * stream_feature.SetField( - * 'thresh_fa', working_flow_accum_threshold) - * stream_feature.SetField( # <<<<<<<<<<<<<< - * 'ds_x', ds_x) - * stream_feature.SetField( - */ - __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3545, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - - /* "pygeoprocessing/routing/routing.pyx":3546 - * 'thresh_fa', working_flow_accum_threshold) - * stream_feature.SetField( - * 'ds_x', ds_x) # <<<<<<<<<<<<<< - * stream_feature.SetField( - * 'ds_y', ds_y) - */ - __pyx_t_8 = NULL; - __pyx_t_17 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_31); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_31, function); - __pyx_t_17 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_31)) { - PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_n_u_ds_x, __pyx_v_ds_x}; - __pyx_t_30 = __Pyx_PyFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3545, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_30); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_31)) { - PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_n_u_ds_x, __pyx_v_ds_x}; - __pyx_t_30 = __Pyx_PyCFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3545, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_30); - } else - #endif - { - __pyx_t_3 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3545, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (__pyx_t_8) { - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8); __pyx_t_8 = NULL; - } - __Pyx_INCREF(__pyx_n_u_ds_x); - __Pyx_GIVEREF(__pyx_n_u_ds_x); - PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_17, __pyx_n_u_ds_x); - __Pyx_INCREF(__pyx_v_ds_x); - __Pyx_GIVEREF(__pyx_v_ds_x); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_17, __pyx_v_ds_x); - __pyx_t_30 = __Pyx_PyObject_Call(__pyx_t_31, __pyx_t_3, NULL); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3545, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_30); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3547 - * stream_feature.SetField( - * 'ds_x', ds_x) - * stream_feature.SetField( # <<<<<<<<<<<<<< - * 'ds_y', ds_y) - * stream_feature.SetField( - */ - __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3547, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - - /* "pygeoprocessing/routing/routing.pyx":3548 - * 'ds_x', ds_x) - * stream_feature.SetField( - * 'ds_y', ds_y) # <<<<<<<<<<<<<< - * stream_feature.SetField( - * 'ds_x_1', ds_x_1) - */ - __pyx_t_3 = NULL; - __pyx_t_17 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_31); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_31, function); - __pyx_t_17 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_31)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_ds_y, __pyx_v_ds_y}; - __pyx_t_30 = __Pyx_PyFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3547, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_30); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_31)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_ds_y, __pyx_v_ds_y}; - __pyx_t_30 = __Pyx_PyCFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3547, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_30); - } else - #endif - { - __pyx_t_8 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3547, __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_n_u_ds_y); - __Pyx_GIVEREF(__pyx_n_u_ds_y); - PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_17, __pyx_n_u_ds_y); - __Pyx_INCREF(__pyx_v_ds_y); - __Pyx_GIVEREF(__pyx_v_ds_y); - PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_17, __pyx_v_ds_y); - __pyx_t_30 = __Pyx_PyObject_Call(__pyx_t_31, __pyx_t_8, NULL); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3547, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_30); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3549 - * stream_feature.SetField( - * 'ds_y', ds_y) - * stream_feature.SetField( # <<<<<<<<<<<<<< - * 'ds_x_1', ds_x_1) - * stream_feature.SetField( - */ - __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3549, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - - /* "pygeoprocessing/routing/routing.pyx":3550 - * 'ds_y', ds_y) - * stream_feature.SetField( - * 'ds_x_1', ds_x_1) # <<<<<<<<<<<<<< - * stream_feature.SetField( - * 'ds_y_1', ds_y_1) - */ - __pyx_t_8 = NULL; - __pyx_t_17 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_31); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_31, function); - __pyx_t_17 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_31)) { - PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_n_u_ds_x_1, __pyx_v_ds_x_1}; - __pyx_t_30 = __Pyx_PyFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3549, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_30); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_31)) { - PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_n_u_ds_x_1, __pyx_v_ds_x_1}; - __pyx_t_30 = __Pyx_PyCFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3549, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_30); - } else - #endif - { - __pyx_t_3 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3549, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (__pyx_t_8) { - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8); __pyx_t_8 = NULL; - } - __Pyx_INCREF(__pyx_n_u_ds_x_1); - __Pyx_GIVEREF(__pyx_n_u_ds_x_1); - PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_17, __pyx_n_u_ds_x_1); - __Pyx_INCREF(__pyx_v_ds_x_1); - __Pyx_GIVEREF(__pyx_v_ds_x_1); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_17, __pyx_v_ds_x_1); - __pyx_t_30 = __Pyx_PyObject_Call(__pyx_t_31, __pyx_t_3, NULL); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3549, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_30); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3551 - * stream_feature.SetField( - * 'ds_x_1', ds_x_1) - * stream_feature.SetField( # <<<<<<<<<<<<<< - * 'ds_y_1', ds_y_1) - * stream_feature.SetField('us_x', x_u) - */ - __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3551, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - - /* "pygeoprocessing/routing/routing.pyx":3552 - * 'ds_x_1', ds_x_1) - * stream_feature.SetField( - * 'ds_y_1', ds_y_1) # <<<<<<<<<<<<<< - * stream_feature.SetField('us_x', x_u) - * stream_feature.SetField('us_y', y_u) - */ - __pyx_t_3 = NULL; - __pyx_t_17 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_31); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_31, function); - __pyx_t_17 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_31)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_ds_y_1, __pyx_v_ds_y_1}; - __pyx_t_30 = __Pyx_PyFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3551, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_30); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_31)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_ds_y_1, __pyx_v_ds_y_1}; - __pyx_t_30 = __Pyx_PyCFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3551, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_30); - } else - #endif - { - __pyx_t_8 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3551, __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_n_u_ds_y_1); - __Pyx_GIVEREF(__pyx_n_u_ds_y_1); - PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_17, __pyx_n_u_ds_y_1); - __Pyx_INCREF(__pyx_v_ds_y_1); - __Pyx_GIVEREF(__pyx_v_ds_y_1); - PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_17, __pyx_v_ds_y_1); - __pyx_t_30 = __Pyx_PyObject_Call(__pyx_t_31, __pyx_t_8, NULL); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3551, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_30); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3553 - * stream_feature.SetField( - * 'ds_y_1', ds_y_1) - * stream_feature.SetField('us_x', x_u) # <<<<<<<<<<<<<< - * stream_feature.SetField('us_y', y_u) - * - */ - __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3553, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - __pyx_t_8 = NULL; - __pyx_t_17 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_31); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_31, function); - __pyx_t_17 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_31)) { - PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_n_u_us_x, __pyx_v_x_u}; - __pyx_t_30 = __Pyx_PyFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3553, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_30); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_31)) { - PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_n_u_us_x, __pyx_v_x_u}; - __pyx_t_30 = __Pyx_PyCFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3553, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_30); - } else - #endif - { - __pyx_t_3 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3553, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (__pyx_t_8) { - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8); __pyx_t_8 = NULL; - } - __Pyx_INCREF(__pyx_n_u_us_x); - __Pyx_GIVEREF(__pyx_n_u_us_x); - PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_17, __pyx_n_u_us_x); - __Pyx_INCREF(__pyx_v_x_u); - __Pyx_GIVEREF(__pyx_v_x_u); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_17, __pyx_v_x_u); - __pyx_t_30 = __Pyx_PyObject_Call(__pyx_t_31, __pyx_t_3, NULL); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3553, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_30); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3554 - * 'ds_y_1', ds_y_1) - * stream_feature.SetField('us_x', x_u) - * stream_feature.SetField('us_y', y_u) # <<<<<<<<<<<<<< - * - * streams_to_retest.append(stream_feature) - */ - __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3554, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - __pyx_t_3 = NULL; - __pyx_t_17 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_31); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_31, function); - __pyx_t_17 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_31)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_us_y, __pyx_v_y_u}; - __pyx_t_30 = __Pyx_PyFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3554, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_30); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_31)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_n_u_us_y, __pyx_v_y_u}; - __pyx_t_30 = __Pyx_PyCFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3554, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_30); - } else - #endif - { - __pyx_t_8 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3554, __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_n_u_us_y); - __Pyx_GIVEREF(__pyx_n_u_us_y); - PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_17, __pyx_n_u_us_y); - __Pyx_INCREF(__pyx_v_y_u); - __Pyx_GIVEREF(__pyx_v_y_u); - PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_17, __pyx_v_y_u); - __pyx_t_30 = __Pyx_PyObject_Call(__pyx_t_31, __pyx_t_8, NULL); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3554, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_30); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3556 - * stream_feature.SetField('us_y', y_u) - * - * streams_to_retest.append(stream_feature) # <<<<<<<<<<<<<< - * stream_layer.SetFeature(stream_feature) - * - */ - __pyx_t_27 = __Pyx_PyList_Append(__pyx_v_streams_to_retest, __pyx_v_stream_feature); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3556, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3557 - * - * streams_to_retest.append(stream_feature) - * stream_layer.SetFeature(stream_feature) # <<<<<<<<<<<<<< - * - * streams_by_order[order] = streams_to_retest - */ - __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_SetFeature); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3557, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_31); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_31, function); - } - } - __pyx_t_30 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_31, __pyx_t_8, __pyx_v_stream_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_31, __pyx_v_stream_feature); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3557, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_30); - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - __pyx_L95_continue:; - } - - /* "pygeoprocessing/routing/routing.pyx":3559 - * stream_layer.SetFeature(stream_feature) - * - * streams_by_order[order] = streams_to_retest # <<<<<<<<<<<<<< - * working_river_id += 1 - * - */ - if (unlikely(PyObject_SetItem(__pyx_v_streams_by_order, __pyx_v_order, __pyx_v_streams_to_retest) < 0)) __PYX_ERR(0, 3559, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3475 - * working_flow_accum_threshold *= 1.25 - * # reconstruct stream segments of <= test_order - * for order in range(1, test_order+1): # <<<<<<<<<<<<<< - * # This will build up a list of kept or reconstructed - * # streams. Other streams will be deleted. - */ - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __pyx_L77_break:; - - /* "pygeoprocessing/routing/routing.pyx":3560 - * - * streams_by_order[order] = streams_to_retest - * working_river_id += 1 # <<<<<<<<<<<<<< - * - * LOGGER.info( - */ - __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_v_working_river_id, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3560, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF_SET(__pyx_v_working_river_id, __pyx_t_4); - __pyx_t_4 = 0; - } - __pyx_L71:; - } - - /* "pygeoprocessing/routing/routing.pyx":3398 - * '(extract_strahler_streams_d8): determine rivers') - * working_river_id = 0 - * for outlet_index, outlet_fid in enumerate(outlet_fid_list): # <<<<<<<<<<<<<< - * # walk upstream starting from this outlet to search for rivers - * # defined as stream segments whose order is <= river_order. Note it - */ - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3562 - * working_river_id += 1 - * - * LOGGER.info( # <<<<<<<<<<<<<< - * '(extract_strahler_streams_d8): ' - * 'flow accumulation adjustment complete') - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3562, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_info); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3562, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - 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_9 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, __pyx_kp_u_extract_strahler_streams_d8_flo_2) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_extract_strahler_streams_d8_flo_2); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3562, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3566 - * 'flow accumulation adjustment complete') - * - * stream_layer.DeleteField( # <<<<<<<<<<<<<< - * stream_layer.FindFieldIndex('upstream_d8_dir', 1)) - * stream_layer.CommitTransaction() - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_DeleteField); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3566, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - - /* "pygeoprocessing/routing/routing.pyx":3567 - * - * stream_layer.DeleteField( - * stream_layer.FindFieldIndex('upstream_d8_dir', 1)) # <<<<<<<<<<<<<< - * stream_layer.CommitTransaction() - * stream_layer.StartTransaction() - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_FindFieldIndex); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3567, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_30 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3567, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_30); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_9 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, __pyx_t_30) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_30); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3566, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3568 - * stream_layer.DeleteField( - * stream_layer.FindFieldIndex('upstream_d8_dir', 1)) - * stream_layer.CommitTransaction() # <<<<<<<<<<<<<< - * stream_layer.StartTransaction() - * LOGGER.info( - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CommitTransaction); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3568, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_30 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_30 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_30)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_30); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - __pyx_t_9 = (__pyx_t_30) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_30) : __Pyx_PyObject_CallNoArg(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_30); __pyx_t_30 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3568, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3569 - * stream_layer.FindFieldIndex('upstream_d8_dir', 1)) - * stream_layer.CommitTransaction() - * stream_layer.StartTransaction() # <<<<<<<<<<<<<< - * LOGGER.info( - * '(extract_strahler_streams_d8): ' - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_StartTransaction); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3569, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_30 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_30 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_30)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_30); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - __pyx_t_9 = (__pyx_t_30) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_30) : __Pyx_PyObject_CallNoArg(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_30); __pyx_t_30 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3569, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3570 - * stream_layer.CommitTransaction() - * stream_layer.StartTransaction() - * LOGGER.info( # <<<<<<<<<<<<<< - * '(extract_strahler_streams_d8): ' - * 'final pass on stream order and geometry') - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3570, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_30 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_info); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3570, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_30); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_30))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_30); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_30); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_30, function); - } - } - __pyx_t_9 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_30, __pyx_t_4, __pyx_kp_u_extract_strahler_streams_d8_fin) : __Pyx_PyObject_CallOneArg(__pyx_t_30, __pyx_kp_u_extract_strahler_streams_d8_fin); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3570, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3575 - * - * # seed the stack with all the upstream orders - * working_stack = [ # <<<<<<<<<<<<<< - * fid for fid in downstream_to_upstream_ids if - * not downstream_to_upstream_ids[fid]] - */ - { /* enter inner scope */ - __pyx_t_9 = PyList_New(0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3575, __pyx_L104_error) - __Pyx_GOTREF(__pyx_t_9); - - /* "pygeoprocessing/routing/routing.pyx":3576 - * # seed the stack with all the upstream orders - * working_stack = [ - * fid for fid in downstream_to_upstream_ids if # <<<<<<<<<<<<<< - * not downstream_to_upstream_ids[fid]] - * fid_to_order = {} - */ - __pyx_t_13 = 0; - __pyx_t_4 = __Pyx_dict_iterator(__pyx_v_downstream_to_upstream_ids, 1, ((PyObject *)NULL), (&__pyx_t_15), (&__pyx_t_17)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3576, __pyx_L104_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_30); - __pyx_t_30 = __pyx_t_4; - __pyx_t_4 = 0; - while (1) { - __pyx_t_18 = __Pyx_dict_iter_next(__pyx_t_30, __pyx_t_15, &__pyx_t_13, &__pyx_t_4, NULL, NULL, __pyx_t_17); - if (unlikely(__pyx_t_18 == 0)) break; - if (unlikely(__pyx_t_18 == -1)) __PYX_ERR(0, 3576, __pyx_L104_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_XDECREF_SET(__pyx_8genexpr1__pyx_v_fid, __pyx_t_4); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3577 - * working_stack = [ - * fid for fid in downstream_to_upstream_ids if - * not downstream_to_upstream_ids[fid]] # <<<<<<<<<<<<<< - * fid_to_order = {} - * processed_segments = 0 - */ - __pyx_t_4 = __Pyx_PyDict_GetItem(__pyx_v_downstream_to_upstream_ids, __pyx_8genexpr1__pyx_v_fid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3577, __pyx_L104_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_29 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_29 < 0)) __PYX_ERR(0, 3577, __pyx_L104_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_21 = ((!__pyx_t_29) != 0); - - /* "pygeoprocessing/routing/routing.pyx":3576 - * # seed the stack with all the upstream orders - * working_stack = [ - * fid for fid in downstream_to_upstream_ids if # <<<<<<<<<<<<<< - * not downstream_to_upstream_ids[fid]] - * fid_to_order = {} - */ - if (__pyx_t_21) { - if (unlikely(__Pyx_ListComp_Append(__pyx_t_9, (PyObject*)__pyx_8genexpr1__pyx_v_fid))) __PYX_ERR(0, 3575, __pyx_L104_error) - } - } - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - __Pyx_XDECREF(__pyx_8genexpr1__pyx_v_fid); __pyx_8genexpr1__pyx_v_fid = 0; - goto __pyx_L108_exit_scope; - __pyx_L104_error:; - __Pyx_XDECREF(__pyx_8genexpr1__pyx_v_fid); __pyx_8genexpr1__pyx_v_fid = 0; - goto __pyx_L1_error; - __pyx_L108_exit_scope:; - } /* exit inner scope */ - __pyx_v_working_stack = ((PyObject*)__pyx_t_9); - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3578 - * fid for fid in downstream_to_upstream_ids if - * not downstream_to_upstream_ids[fid]] - * fid_to_order = {} # <<<<<<<<<<<<<< - * processed_segments = 0 - * segments_to_process = len(downstream_to_upstream_ids) - */ - __pyx_t_9 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3578, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_v_fid_to_order = ((PyObject*)__pyx_t_9); - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3579 - * not downstream_to_upstream_ids[fid]] - * fid_to_order = {} - * processed_segments = 0 # <<<<<<<<<<<<<< - * segments_to_process = len(downstream_to_upstream_ids) - * deleted_set = set() - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_v_processed_segments = __pyx_int_0; - - /* "pygeoprocessing/routing/routing.pyx":3580 - * fid_to_order = {} - * processed_segments = 0 - * segments_to_process = len(downstream_to_upstream_ids) # <<<<<<<<<<<<<< - * deleted_set = set() - * while working_stack: - */ - __pyx_t_15 = PyDict_Size(__pyx_v_downstream_to_upstream_ids); if (unlikely(__pyx_t_15 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3580, __pyx_L1_error) - __pyx_v_segments_to_process = __pyx_t_15; - - /* "pygeoprocessing/routing/routing.pyx":3581 - * processed_segments = 0 - * segments_to_process = len(downstream_to_upstream_ids) - * deleted_set = set() # <<<<<<<<<<<<<< - * while working_stack: - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: - */ - __pyx_t_9 = PySet_New(0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3581, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_v_deleted_set = ((PyObject*)__pyx_t_9); - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3582 - * segments_to_process = len(downstream_to_upstream_ids) - * deleted_set = set() - * while working_stack: # <<<<<<<<<<<<<< - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: - * LOGGER.info( - */ - while (1) { - __pyx_t_21 = (PyList_GET_SIZE(__pyx_v_working_stack) != 0); - if (!__pyx_t_21) break; - - /* "pygeoprocessing/routing/routing.pyx":3583 - * deleted_set = set() - * while working_stack: - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * LOGGER.info( - * '(extract_strahler_streams_d8): ' - */ - __pyx_t_21 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); - if (__pyx_t_21) { - - /* "pygeoprocessing/routing/routing.pyx":3584 - * while working_stack: - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: - * LOGGER.info( # <<<<<<<<<<<<<< - * '(extract_strahler_streams_d8): ' - * 'final pass on stream order ' - */ - __Pyx_GetModuleGlobalName(__pyx_t_30, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3584, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_30); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_30, __pyx_n_s_info); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3584, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3585 - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: - * LOGGER.info( - * '(extract_strahler_streams_d8): ' # <<<<<<<<<<<<<< - * 'final pass on stream order ' - * f'{processed_segments} of {segments_to_process} ' - */ - __pyx_t_30 = PyTuple_New(5); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3585, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_30); - __pyx_t_15 = 0; - __pyx_t_16 = 127; - __Pyx_INCREF(__pyx_kp_u_extract_strahler_streams_d8_fin_2); - __pyx_t_15 += 58; - __Pyx_GIVEREF(__pyx_kp_u_extract_strahler_streams_d8_fin_2); - PyTuple_SET_ITEM(__pyx_t_30, 0, __pyx_kp_u_extract_strahler_streams_d8_fin_2); - - /* "pygeoprocessing/routing/routing.pyx":3587 - * '(extract_strahler_streams_d8): ' - * 'final pass on stream order ' - * f'{processed_segments} of {segments_to_process} ' # <<<<<<<<<<<<<< - * 'segments complete') - * last_log_time = ctime(NULL) - */ - __pyx_t_1 = __Pyx_PyObject_FormatSimple(__pyx_v_processed_segments, __pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3587, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_16 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) > __pyx_t_16) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) : __pyx_t_16; - __pyx_t_15 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_30, 1, __pyx_t_1); - __pyx_t_1 = 0; - __Pyx_INCREF(__pyx_kp_u_of); - __pyx_t_15 += 4; - __Pyx_GIVEREF(__pyx_kp_u_of); - PyTuple_SET_ITEM(__pyx_t_30, 2, __pyx_kp_u_of); - __pyx_t_1 = __Pyx_PyUnicode_From_Py_ssize_t(__pyx_v_segments_to_process, 0, ' ', 'd'); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3587, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_15 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_30, 3, __pyx_t_1); - __pyx_t_1 = 0; - __Pyx_INCREF(__pyx_kp_u_segments_complete); - __pyx_t_15 += 18; - __Pyx_GIVEREF(__pyx_kp_u_segments_complete); - PyTuple_SET_ITEM(__pyx_t_30, 4, __pyx_kp_u_segments_complete); - - /* "pygeoprocessing/routing/routing.pyx":3585 - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: - * LOGGER.info( - * '(extract_strahler_streams_d8): ' # <<<<<<<<<<<<<< - * 'final pass on stream order ' - * f'{processed_segments} of {segments_to_process} ' - */ - __pyx_t_1 = __Pyx_PyUnicode_Join(__pyx_t_30, 5, __pyx_t_15, __pyx_t_16); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3585, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - __pyx_t_30 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_30 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_30)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_30); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - __pyx_t_9 = (__pyx_t_30) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_30, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_1); - __Pyx_XDECREF(__pyx_t_30); __pyx_t_30 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3584, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3589 - * f'{processed_segments} of {segments_to_process} ' - * 'segments complete') - * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< - * processed_segments += 1 - * - */ - __pyx_v_last_log_time = time(NULL); - - /* "pygeoprocessing/routing/routing.pyx":3583 - * deleted_set = set() - * while working_stack: - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * LOGGER.info( - * '(extract_strahler_streams_d8): ' - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3590 - * 'segments complete') - * last_log_time = ctime(NULL) - * processed_segments += 1 # <<<<<<<<<<<<<< - * - * working_fid = working_stack.pop() - */ - __pyx_t_9 = __Pyx_PyInt_AddObjC(__pyx_v_processed_segments, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3590, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF_SET(__pyx_v_processed_segments, __pyx_t_9); - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3592 - * processed_segments += 1 - * - * working_fid = working_stack.pop() # <<<<<<<<<<<<<< - * # invariant: working_fid and all upstream are processed, order not set - * - */ - __pyx_t_9 = __Pyx_PyList_Pop(__pyx_v_working_stack); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3592, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_XDECREF_SET(__pyx_v_working_fid, __pyx_t_9); - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3595 - * # invariant: working_fid and all upstream are processed, order not set - * - * upstream_fid_list = downstream_to_upstream_ids[working_fid] # <<<<<<<<<<<<<< - * if upstream_fid_list: - * order_count = collections.defaultdict(int) - */ - __pyx_t_9 = __Pyx_PyDict_GetItem(__pyx_v_downstream_to_upstream_ids, __pyx_v_working_fid); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3595, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_XDECREF_SET(__pyx_v_upstream_fid_list, __pyx_t_9); - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3596 - * - * upstream_fid_list = downstream_to_upstream_ids[working_fid] - * if upstream_fid_list: # <<<<<<<<<<<<<< - * order_count = collections.defaultdict(int) - * for upstream_fid in upstream_fid_list: - */ - __pyx_t_21 = __Pyx_PyObject_IsTrue(__pyx_v_upstream_fid_list); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3596, __pyx_L1_error) - if (__pyx_t_21) { - - /* "pygeoprocessing/routing/routing.pyx":3597 - * upstream_fid_list = downstream_to_upstream_ids[working_fid] - * if upstream_fid_list: - * order_count = collections.defaultdict(int) # <<<<<<<<<<<<<< - * for upstream_fid in upstream_fid_list: - * order_count[fid_to_order[upstream_fid]] += 1 - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_collections); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3597, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3597, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __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); - } - } - __pyx_t_9 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_4, ((PyObject *)(&PyInt_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_1, ((PyObject *)(&PyInt_Type))); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3597, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF_SET(__pyx_v_order_count, __pyx_t_9); - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3598 - * if upstream_fid_list: - * order_count = collections.defaultdict(int) - * for upstream_fid in upstream_fid_list: # <<<<<<<<<<<<<< - * order_count[fid_to_order[upstream_fid]] += 1 - * working_order = max(order_count) - */ - if (likely(PyList_CheckExact(__pyx_v_upstream_fid_list)) || PyTuple_CheckExact(__pyx_v_upstream_fid_list)) { - __pyx_t_9 = __pyx_v_upstream_fid_list; __Pyx_INCREF(__pyx_t_9); __pyx_t_15 = 0; - __pyx_t_14 = NULL; - } else { - __pyx_t_15 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_v_upstream_fid_list); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3598, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_14 = Py_TYPE(__pyx_t_9)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 3598, __pyx_L1_error) - } - for (;;) { - if (likely(!__pyx_t_14)) { - if (likely(PyList_CheckExact(__pyx_t_9))) { - if (__pyx_t_15 >= PyList_GET_SIZE(__pyx_t_9)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_15); __Pyx_INCREF(__pyx_t_1); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 3598, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_9, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3598, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } else { - if (__pyx_t_15 >= PyTuple_GET_SIZE(__pyx_t_9)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_15); __Pyx_INCREF(__pyx_t_1); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 3598, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_9, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3598, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } - } else { - __pyx_t_1 = __pyx_t_14(__pyx_t_9); - 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, 3598, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - __Pyx_XDECREF_SET(__pyx_v_upstream_fid, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3599 - * order_count = collections.defaultdict(int) - * for upstream_fid in upstream_fid_list: - * order_count[fid_to_order[upstream_fid]] += 1 # <<<<<<<<<<<<<< - * working_order = max(order_count) - * if order_count[working_order] > 1: - */ - __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_fid_to_order, __pyx_v_upstream_fid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3599, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_order_count, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3599, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_30 = __Pyx_PyInt_AddObjC(__pyx_t_4, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3599, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_30); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(PyObject_SetItem(__pyx_v_order_count, __pyx_t_1, __pyx_t_30) < 0)) __PYX_ERR(0, 3599, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3598 - * if upstream_fid_list: - * order_count = collections.defaultdict(int) - * for upstream_fid in upstream_fid_list: # <<<<<<<<<<<<<< - * order_count[fid_to_order[upstream_fid]] += 1 - * working_order = max(order_count) - */ - } - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3600 - * for upstream_fid in upstream_fid_list: - * order_count[fid_to_order[upstream_fid]] += 1 - * working_order = max(order_count) # <<<<<<<<<<<<<< - * if order_count[working_order] > 1: - * working_order += 1 - */ - __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_max, __pyx_v_order_count); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3600, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_XDECREF_SET(__pyx_v_working_order, __pyx_t_9); - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3601 - * order_count[fid_to_order[upstream_fid]] += 1 - * working_order = max(order_count) - * if order_count[working_order] > 1: # <<<<<<<<<<<<<< - * working_order += 1 - * fid_to_order[working_fid] = working_order - */ - __pyx_t_9 = __Pyx_PyObject_GetItem(__pyx_v_order_count, __pyx_v_working_order); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3601, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = PyObject_RichCompare(__pyx_t_9, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3601, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_21 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3601, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_21) { - - /* "pygeoprocessing/routing/routing.pyx":3602 - * working_order = max(order_count) - * if order_count[working_order] > 1: - * working_order += 1 # <<<<<<<<<<<<<< - * fid_to_order[working_fid] = working_order - * else: - */ - __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_v_working_order, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3602, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF_SET(__pyx_v_working_order, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3601 - * order_count[fid_to_order[upstream_fid]] += 1 - * working_order = max(order_count) - * if order_count[working_order] > 1: # <<<<<<<<<<<<<< - * working_order += 1 - * fid_to_order[working_fid] = working_order - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3603 - * if order_count[working_order] > 1: - * working_order += 1 - * fid_to_order[working_fid] = working_order # <<<<<<<<<<<<<< - * else: - * fid_to_order[working_fid] = 1 - */ - if (unlikely(PyDict_SetItem(__pyx_v_fid_to_order, __pyx_v_working_fid, __pyx_v_working_order) < 0)) __PYX_ERR(0, 3603, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3596 - * - * upstream_fid_list = downstream_to_upstream_ids[working_fid] - * if upstream_fid_list: # <<<<<<<<<<<<<< - * order_count = collections.defaultdict(int) - * for upstream_fid in upstream_fid_list: - */ - goto __pyx_L112; - } - - /* "pygeoprocessing/routing/routing.pyx":3605 - * fid_to_order[working_fid] = working_order - * else: - * fid_to_order[working_fid] = 1 # <<<<<<<<<<<<<< - * - * working_feature = stream_layer.GetFeature(working_fid) - */ - /*else*/ { - if (unlikely(PyDict_SetItem(__pyx_v_fid_to_order, __pyx_v_working_fid, __pyx_int_1) < 0)) __PYX_ERR(0, 3605, __pyx_L1_error) - } - __pyx_L112:; - - /* "pygeoprocessing/routing/routing.pyx":3607 - * fid_to_order[working_fid] = 1 - * - * working_feature = stream_layer.GetFeature(working_fid) # <<<<<<<<<<<<<< - * working_feature.SetField('order', fid_to_order[working_fid]) - * stream_layer.SetFeature(working_feature) - */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3607, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_30 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { - __pyx_t_30 = PyMethod_GET_SELF(__pyx_t_9); - if (likely(__pyx_t_30)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); - __Pyx_INCREF(__pyx_t_30); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_9, function); - } - } - __pyx_t_1 = (__pyx_t_30) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_30, __pyx_v_working_fid) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_working_fid); - __Pyx_XDECREF(__pyx_t_30); __pyx_t_30 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3607, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_XDECREF_SET(__pyx_v_working_feature, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3608 - * - * working_feature = stream_layer.GetFeature(working_fid) - * working_feature.SetField('order', fid_to_order[working_fid]) # <<<<<<<<<<<<<< - * stream_layer.SetFeature(working_feature) - * working_feature = None - */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3608, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_30 = __Pyx_PyDict_GetItem(__pyx_v_fid_to_order, __pyx_v_working_fid); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3608, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_30); - __pyx_t_4 = NULL; - __pyx_t_17 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_9); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_9, function); - __pyx_t_17 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_order, __pyx_t_30}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3608, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_order, __pyx_t_30}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3608, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - } else - #endif - { - __pyx_t_31 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3608, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - if (__pyx_t_4) { - __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_31, 0, __pyx_t_4); __pyx_t_4 = NULL; - } - __Pyx_INCREF(__pyx_n_u_order); - __Pyx_GIVEREF(__pyx_n_u_order); - PyTuple_SET_ITEM(__pyx_t_31, 0+__pyx_t_17, __pyx_n_u_order); - __Pyx_GIVEREF(__pyx_t_30); - PyTuple_SET_ITEM(__pyx_t_31, 1+__pyx_t_17, __pyx_t_30); - __pyx_t_30 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_31, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3608, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - } - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3609 - * working_feature = stream_layer.GetFeature(working_fid) - * working_feature.SetField('order', fid_to_order[working_fid]) - * stream_layer.SetFeature(working_feature) # <<<<<<<<<<<<<< - * working_feature = None - * - */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_SetFeature); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3609, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_31 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { - __pyx_t_31 = PyMethod_GET_SELF(__pyx_t_9); - if (likely(__pyx_t_31)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); - __Pyx_INCREF(__pyx_t_31); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_9, function); - } - } - __pyx_t_1 = (__pyx_t_31) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_31, __pyx_v_working_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_working_feature); - __Pyx_XDECREF(__pyx_t_31); __pyx_t_31 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3609, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3610 - * working_feature.SetField('order', fid_to_order[working_fid]) - * stream_layer.SetFeature(working_feature) - * working_feature = None # <<<<<<<<<<<<<< - * - * if working_fid not in upstream_to_downstream_id: - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_working_feature, Py_None); - - /* "pygeoprocessing/routing/routing.pyx":3612 - * working_feature = None - * - * if working_fid not in upstream_to_downstream_id: # <<<<<<<<<<<<<< - * # nothing downstream so it's done - * continue - */ - __pyx_t_21 = (__Pyx_PyDict_ContainsTF(__pyx_v_working_fid, __pyx_v_upstream_to_downstream_id, Py_NE)); if (unlikely(__pyx_t_21 < 0)) __PYX_ERR(0, 3612, __pyx_L1_error) - __pyx_t_29 = (__pyx_t_21 != 0); - if (__pyx_t_29) { - - /* "pygeoprocessing/routing/routing.pyx":3614 - * if working_fid not in upstream_to_downstream_id: - * # nothing downstream so it's done - * continue # <<<<<<<<<<<<<< - * - * downstream_fid = upstream_to_downstream_id[working_fid] - */ - goto __pyx_L109_continue; - - /* "pygeoprocessing/routing/routing.pyx":3612 - * working_feature = None - * - * if working_fid not in upstream_to_downstream_id: # <<<<<<<<<<<<<< - * # nothing downstream so it's done - * continue - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3616 - * continue - * - * downstream_fid = upstream_to_downstream_id[working_fid] # <<<<<<<<<<<<<< - * connected_fids = downstream_to_upstream_ids[downstream_fid] - * if len(connected_fids) == 1: - */ - __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_upstream_to_downstream_id, __pyx_v_working_fid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3616, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_XDECREF_SET(__pyx_v_downstream_fid, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3617 - * - * downstream_fid = upstream_to_downstream_id[working_fid] - * connected_fids = downstream_to_upstream_ids[downstream_fid] # <<<<<<<<<<<<<< - * if len(connected_fids) == 1: - * # There's only one downstream, join it. - */ - __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_downstream_to_upstream_ids, __pyx_v_downstream_fid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3617, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_XDECREF_SET(__pyx_v_connected_fids, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3618 - * downstream_fid = upstream_to_downstream_id[working_fid] - * connected_fids = downstream_to_upstream_ids[downstream_fid] - * if len(connected_fids) == 1: # <<<<<<<<<<<<<< - * # There's only one downstream, join it. - * # Downstream order is the same as upstream - */ - __pyx_t_15 = PyObject_Length(__pyx_v_connected_fids); if (unlikely(__pyx_t_15 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3618, __pyx_L1_error) - __pyx_t_29 = ((__pyx_t_15 == 1) != 0); - if (__pyx_t_29) { - - /* "pygeoprocessing/routing/routing.pyx":3621 - * # There's only one downstream, join it. - * # Downstream order is the same as upstream - * fid_to_order[downstream_fid] = fid_to_order[working_fid] # <<<<<<<<<<<<<< - * del fid_to_order[working_fid] - * - */ - __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_fid_to_order, __pyx_v_working_fid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3621, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (unlikely(PyDict_SetItem(__pyx_v_fid_to_order, __pyx_v_downstream_fid, __pyx_t_1) < 0)) __PYX_ERR(0, 3621, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3622 - * # Downstream order is the same as upstream - * fid_to_order[downstream_fid] = fid_to_order[working_fid] - * del fid_to_order[working_fid] # <<<<<<<<<<<<<< - * - * # set downstream order to working order - */ - if (unlikely(PyDict_DelItem(__pyx_v_fid_to_order, __pyx_v_working_fid) < 0)) __PYX_ERR(0, 3622, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3626 - * # set downstream order to working order - * downstream_to_upstream_ids[downstream_fid] = ( - * downstream_to_upstream_ids[working_fid]) # <<<<<<<<<<<<<< - * # since we're deleting the upstream segment we need upstream - * # connecting segments to connect to the new downstream - */ - __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_downstream_to_upstream_ids, __pyx_v_working_fid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3626, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":3625 - * - * # set downstream order to working order - * downstream_to_upstream_ids[downstream_fid] = ( # <<<<<<<<<<<<<< - * downstream_to_upstream_ids[working_fid]) - * # since we're deleting the upstream segment we need upstream - */ - if (unlikely(PyDict_SetItem(__pyx_v_downstream_to_upstream_ids, __pyx_v_downstream_fid, __pyx_t_1) < 0)) __PYX_ERR(0, 3625, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3629 - * # since we're deleting the upstream segment we need upstream - * # connecting segments to connect to the new downstream - * for upstream_fid in downstream_to_upstream_ids[downstream_fid]: # <<<<<<<<<<<<<< - * upstream_to_downstream_id[upstream_fid] = downstream_fid - * del downstream_to_upstream_ids[working_fid] - */ - __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_downstream_to_upstream_ids, __pyx_v_downstream_fid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3629, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { - __pyx_t_9 = __pyx_t_1; __Pyx_INCREF(__pyx_t_9); __pyx_t_15 = 0; - __pyx_t_14 = NULL; - } else { - __pyx_t_15 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3629, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_14 = Py_TYPE(__pyx_t_9)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 3629, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - for (;;) { - if (likely(!__pyx_t_14)) { - if (likely(PyList_CheckExact(__pyx_t_9))) { - if (__pyx_t_15 >= PyList_GET_SIZE(__pyx_t_9)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_15); __Pyx_INCREF(__pyx_t_1); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 3629, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_9, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3629, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } else { - if (__pyx_t_15 >= PyTuple_GET_SIZE(__pyx_t_9)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_15); __Pyx_INCREF(__pyx_t_1); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 3629, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_9, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3629, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } - } else { - __pyx_t_1 = __pyx_t_14(__pyx_t_9); - 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, 3629, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - __Pyx_XDECREF_SET(__pyx_v_upstream_fid, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3630 - * # connecting segments to connect to the new downstream - * for upstream_fid in downstream_to_upstream_ids[downstream_fid]: - * upstream_to_downstream_id[upstream_fid] = downstream_fid # <<<<<<<<<<<<<< - * del downstream_to_upstream_ids[working_fid] - * del upstream_to_downstream_id[working_fid] - */ - if (unlikely(PyDict_SetItem(__pyx_v_upstream_to_downstream_id, __pyx_v_upstream_fid, __pyx_v_downstream_fid) < 0)) __PYX_ERR(0, 3630, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3629 - * # since we're deleting the upstream segment we need upstream - * # connecting segments to connect to the new downstream - * for upstream_fid in downstream_to_upstream_ids[downstream_fid]: # <<<<<<<<<<<<<< - * upstream_to_downstream_id[upstream_fid] = downstream_fid - * del downstream_to_upstream_ids[working_fid] - */ - } - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3631 - * for upstream_fid in downstream_to_upstream_ids[downstream_fid]: - * upstream_to_downstream_id[upstream_fid] = downstream_fid - * del downstream_to_upstream_ids[working_fid] # <<<<<<<<<<<<<< - * del upstream_to_downstream_id[working_fid] - * - */ - if (unlikely(PyDict_DelItem(__pyx_v_downstream_to_upstream_ids, __pyx_v_working_fid) < 0)) __PYX_ERR(0, 3631, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3632 - * upstream_to_downstream_id[upstream_fid] = downstream_fid - * del downstream_to_upstream_ids[working_fid] - * del upstream_to_downstream_id[working_fid] # <<<<<<<<<<<<<< - * - * # join working line with downstream line - */ - if (unlikely(PyDict_DelItem(__pyx_v_upstream_to_downstream_id, __pyx_v_working_fid) < 0)) __PYX_ERR(0, 3632, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3635 - * - * # join working line with downstream line - * working_feature = stream_layer.GetFeature(working_fid) # <<<<<<<<<<<<<< - * downstream_feature = stream_layer.GetFeature(downstream_fid) - * downstream_geom = downstream_feature.GetGeometryRef() - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3635, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_31 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_31 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_31)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_31); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_9 = (__pyx_t_31) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_31, __pyx_v_working_fid) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_working_fid); - __Pyx_XDECREF(__pyx_t_31); __pyx_t_31 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3635, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF_SET(__pyx_v_working_feature, __pyx_t_9); - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3636 - * # join working line with downstream line - * working_feature = stream_layer.GetFeature(working_fid) - * downstream_feature = stream_layer.GetFeature(downstream_fid) # <<<<<<<<<<<<<< - * downstream_geom = downstream_feature.GetGeometryRef() - * working_geom = working_feature.GetGeometryRef() - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3636, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_31 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_31 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_31)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_31); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_9 = (__pyx_t_31) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_31, __pyx_v_downstream_fid) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_downstream_fid); - __Pyx_XDECREF(__pyx_t_31); __pyx_t_31 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3636, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF_SET(__pyx_v_downstream_feature, __pyx_t_9); - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3637 - * working_feature = stream_layer.GetFeature(working_fid) - * downstream_feature = stream_layer.GetFeature(downstream_fid) - * downstream_geom = downstream_feature.GetGeometryRef() # <<<<<<<<<<<<<< - * working_geom = working_feature.GetGeometryRef() - * - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_downstream_feature, __pyx_n_s_GetGeometryRef); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3637, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_31 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_31 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_31)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_31); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_9 = (__pyx_t_31) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_31) : __Pyx_PyObject_CallNoArg(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_31); __pyx_t_31 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3637, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF_SET(__pyx_v_downstream_geom, __pyx_t_9); - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3638 - * downstream_feature = stream_layer.GetFeature(downstream_fid) - * downstream_geom = downstream_feature.GetGeometryRef() - * working_geom = working_feature.GetGeometryRef() # <<<<<<<<<<<<<< - * - * # Union creates a multiline string by default but we know it's - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_GetGeometryRef); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3638, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_31 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_31 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_31)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_31); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_9 = (__pyx_t_31) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_31) : __Pyx_PyObject_CallNoArg(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_31); __pyx_t_31 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3638, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF_SET(__pyx_v_working_geom, __pyx_t_9); - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3643 - * # connected only at one point, so the next step ensures it's a - * # regular linestring - * multi_line = working_geom.Union(downstream_geom) # <<<<<<<<<<<<<< - * joined_line = ogr.CreateGeometryFromWkb( - * shapely.ops.linemerge(shapely.wkb.loads( - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_geom, __pyx_n_s_Union); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3643, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_31 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_31 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_31)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_31); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_9 = (__pyx_t_31) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_31, __pyx_v_downstream_geom) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_downstream_geom); - __Pyx_XDECREF(__pyx_t_31); __pyx_t_31 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3643, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF_SET(__pyx_v_multi_line, __pyx_t_9); - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3644 - * # regular linestring - * multi_line = working_geom.Union(downstream_geom) - * joined_line = ogr.CreateGeometryFromWkb( # <<<<<<<<<<<<<< - * shapely.ops.linemerge(shapely.wkb.loads( - * multi_line.ExportToWkb())).wkb) - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3644, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_CreateGeometryFromWkb); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3644, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3645 - * multi_line = working_geom.Union(downstream_geom) - * joined_line = ogr.CreateGeometryFromWkb( - * shapely.ops.linemerge(shapely.wkb.loads( # <<<<<<<<<<<<<< - * multi_line.ExportToWkb())).wkb) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_30, __pyx_n_s_shapely); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3645, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_30); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_30, __pyx_n_s_ops); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3645, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - __pyx_t_30 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_linemerge); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3645, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_30); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_shapely); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3645, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_wkb); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3645, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_loads); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3645, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3646 - * joined_line = ogr.CreateGeometryFromWkb( - * shapely.ops.linemerge(shapely.wkb.loads( - * multi_line.ExportToWkb())).wkb) # <<<<<<<<<<<<<< - * - * downstream_feature.SetGeometry(joined_line) - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_multi_line, __pyx_n_s_ExportToWkb); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3646, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_3 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3646, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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); - } - } - __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_7, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_3); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3645, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_30))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_30); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_30); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_30, function); - } - } - __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_30, __pyx_t_8, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_30, __pyx_t_4); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3645, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - __pyx_t_30 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_wkb); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3646, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_30); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_31))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_31); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_31, function); - } - } - __pyx_t_9 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_31, __pyx_t_1, __pyx_t_30) : __Pyx_PyObject_CallOneArg(__pyx_t_31, __pyx_t_30); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3644, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - __Pyx_XDECREF_SET(__pyx_v_joined_line, __pyx_t_9); - __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3648 - * multi_line.ExportToWkb())).wkb) - * - * downstream_feature.SetGeometry(joined_line) # <<<<<<<<<<<<<< - * downstream_feature.SetField( - * 'us_x', working_feature.GetField('us_x')) - */ - __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_downstream_feature, __pyx_n_s_SetGeometry); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3648, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - __pyx_t_30 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { - __pyx_t_30 = PyMethod_GET_SELF(__pyx_t_31); - if (likely(__pyx_t_30)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); - __Pyx_INCREF(__pyx_t_30); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_31, function); - } - } - __pyx_t_9 = (__pyx_t_30) ? __Pyx_PyObject_Call2Args(__pyx_t_31, __pyx_t_30, __pyx_v_joined_line) : __Pyx_PyObject_CallOneArg(__pyx_t_31, __pyx_v_joined_line); - __Pyx_XDECREF(__pyx_t_30); __pyx_t_30 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3648, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3649 - * - * downstream_feature.SetGeometry(joined_line) - * downstream_feature.SetField( # <<<<<<<<<<<<<< - * 'us_x', working_feature.GetField('us_x')) - * downstream_feature.SetField( - */ - __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_downstream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3649, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - - /* "pygeoprocessing/routing/routing.pyx":3650 - * downstream_feature.SetGeometry(joined_line) - * downstream_feature.SetField( - * 'us_x', working_feature.GetField('us_x')) # <<<<<<<<<<<<<< - * downstream_feature.SetField( - * 'us_y', working_feature.GetField('us_y')) - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3650, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = NULL; - 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_30 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_4, __pyx_n_u_us_x) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_n_u_us_x); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3650, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_30); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - __pyx_t_17 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_31); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_31, function); - __pyx_t_17 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_31)) { - PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_n_u_us_x, __pyx_t_30}; - __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3649, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_31)) { - PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_n_u_us_x, __pyx_t_30}; - __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3649, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - } else - #endif - { - __pyx_t_4 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3649, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (__pyx_t_1) { - __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __pyx_t_1 = NULL; - } - __Pyx_INCREF(__pyx_n_u_us_x); - __Pyx_GIVEREF(__pyx_n_u_us_x); - PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_17, __pyx_n_u_us_x); - __Pyx_GIVEREF(__pyx_t_30); - PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_17, __pyx_t_30); - __pyx_t_30 = 0; - __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_31, __pyx_t_4, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3649, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3651 - * downstream_feature.SetField( - * 'us_x', working_feature.GetField('us_x')) - * downstream_feature.SetField( # <<<<<<<<<<<<<< - * 'us_y', working_feature.GetField('us_y')) - * stream_layer.SetFeature(downstream_feature) - */ - __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_downstream_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3651, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - - /* "pygeoprocessing/routing/routing.pyx":3652 - * 'us_x', working_feature.GetField('us_x')) - * downstream_feature.SetField( - * 'us_y', working_feature.GetField('us_y')) # <<<<<<<<<<<<<< - * stream_layer.SetFeature(downstream_feature) - * working_feature = None - */ - __pyx_t_30 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 3652, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_30); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_30))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_30); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_30); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_30, function); - } - } - __pyx_t_4 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_30, __pyx_t_1, __pyx_n_u_us_y) : __Pyx_PyObject_CallOneArg(__pyx_t_30, __pyx_n_u_us_y); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3652, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_30); __pyx_t_30 = 0; - __pyx_t_30 = NULL; - __pyx_t_17 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { - __pyx_t_30 = PyMethod_GET_SELF(__pyx_t_31); - if (likely(__pyx_t_30)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); - __Pyx_INCREF(__pyx_t_30); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_31, function); - __pyx_t_17 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_31)) { - PyObject *__pyx_temp[3] = {__pyx_t_30, __pyx_n_u_us_y, __pyx_t_4}; - __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3651, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_30); __pyx_t_30 = 0; - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_31)) { - PyObject *__pyx_temp[3] = {__pyx_t_30, __pyx_n_u_us_y, __pyx_t_4}; - __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_31, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3651, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_30); __pyx_t_30 = 0; - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - { - __pyx_t_1 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3651, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (__pyx_t_30) { - __Pyx_GIVEREF(__pyx_t_30); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_30); __pyx_t_30 = NULL; - } - __Pyx_INCREF(__pyx_n_u_us_y); - __Pyx_GIVEREF(__pyx_n_u_us_y); - PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_17, __pyx_n_u_us_y); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_17, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_31, __pyx_t_1, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3651, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3653 - * downstream_feature.SetField( - * 'us_y', working_feature.GetField('us_y')) - * stream_layer.SetFeature(downstream_feature) # <<<<<<<<<<<<<< - * working_feature = None - * downstream_feature = None - */ - __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_SetFeature); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3653, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_31); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_31, function); - } - } - __pyx_t_9 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_31, __pyx_t_1, __pyx_v_downstream_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_31, __pyx_v_downstream_feature); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3653, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3654 - * 'us_y', working_feature.GetField('us_y')) - * stream_layer.SetFeature(downstream_feature) - * working_feature = None # <<<<<<<<<<<<<< - * downstream_feature = None - * multi_line = None - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_working_feature, Py_None); - - /* "pygeoprocessing/routing/routing.pyx":3655 - * stream_layer.SetFeature(downstream_feature) - * working_feature = None - * downstream_feature = None # <<<<<<<<<<<<<< - * multi_line = None - * joined_line = None - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_downstream_feature, Py_None); - - /* "pygeoprocessing/routing/routing.pyx":3656 - * working_feature = None - * downstream_feature = None - * multi_line = None # <<<<<<<<<<<<<< - * joined_line = None - * - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_multi_line, Py_None); - - /* "pygeoprocessing/routing/routing.pyx":3657 - * downstream_feature = None - * multi_line = None - * joined_line = None # <<<<<<<<<<<<<< - * - * # delete working line - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_joined_line, Py_None); - - /* "pygeoprocessing/routing/routing.pyx":3660 - * - * # delete working line - * stream_layer.DeleteFeature(working_fid) # <<<<<<<<<<<<<< - * deleted_set.add(working_fid) - * - */ - __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_DeleteFeature); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3660, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_31); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_31, function); - } - } - __pyx_t_9 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_31, __pyx_t_1, __pyx_v_working_fid) : __Pyx_PyObject_CallOneArg(__pyx_t_31, __pyx_v_working_fid); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3660, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3661 - * # delete working line - * stream_layer.DeleteFeature(working_fid) - * deleted_set.add(working_fid) # <<<<<<<<<<<<<< - * - * # push downstream line for processing - */ - __pyx_t_27 = PySet_Add(__pyx_v_deleted_set, __pyx_v_working_fid); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3661, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3664 - * - * # push downstream line for processing - * working_stack.append(downstream_fid) # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_27 = __Pyx_PyList_Append(__pyx_v_working_stack, __pyx_v_downstream_fid); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3664, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3665 - * # push downstream line for processing - * working_stack.append(downstream_fid) - * continue # <<<<<<<<<<<<<< - * - * # otherwise check if connected streams are all defined and if so - */ - goto __pyx_L109_continue; - - /* "pygeoprocessing/routing/routing.pyx":3618 - * downstream_fid = upstream_to_downstream_id[working_fid] - * connected_fids = downstream_to_upstream_ids[downstream_fid] - * if len(connected_fids) == 1: # <<<<<<<<<<<<<< - * # There's only one downstream, join it. - * # Downstream order is the same as upstream - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3669 - * # otherwise check if connected streams are all defined and if so - * # set a new downstream order - * upstream_all_defined = True # <<<<<<<<<<<<<< - * for connected_fid in connected_fids: - * if connected_fid == working_fid: - */ - __pyx_v_upstream_all_defined = 1; - - /* "pygeoprocessing/routing/routing.pyx":3670 - * # set a new downstream order - * upstream_all_defined = True - * for connected_fid in connected_fids: # <<<<<<<<<<<<<< - * if connected_fid == working_fid: - * # skip current - */ - if (likely(PyList_CheckExact(__pyx_v_connected_fids)) || PyTuple_CheckExact(__pyx_v_connected_fids)) { - __pyx_t_9 = __pyx_v_connected_fids; __Pyx_INCREF(__pyx_t_9); __pyx_t_15 = 0; - __pyx_t_14 = NULL; - } else { - __pyx_t_15 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_v_connected_fids); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3670, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_14 = Py_TYPE(__pyx_t_9)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 3670, __pyx_L1_error) - } - for (;;) { - if (likely(!__pyx_t_14)) { - if (likely(PyList_CheckExact(__pyx_t_9))) { - if (__pyx_t_15 >= PyList_GET_SIZE(__pyx_t_9)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_31 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_15); __Pyx_INCREF(__pyx_t_31); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 3670, __pyx_L1_error) - #else - __pyx_t_31 = PySequence_ITEM(__pyx_t_9, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3670, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - #endif - } else { - if (__pyx_t_15 >= PyTuple_GET_SIZE(__pyx_t_9)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_31 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_15); __Pyx_INCREF(__pyx_t_31); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 3670, __pyx_L1_error) - #else - __pyx_t_31 = PySequence_ITEM(__pyx_t_9, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3670, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - #endif - } - } else { - __pyx_t_31 = __pyx_t_14(__pyx_t_9); - if (unlikely(!__pyx_t_31)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 3670, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_31); - } - __Pyx_XDECREF_SET(__pyx_v_connected_fid, __pyx_t_31); - __pyx_t_31 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3671 - * upstream_all_defined = True - * for connected_fid in connected_fids: - * if connected_fid == working_fid: # <<<<<<<<<<<<<< - * # skip current - * continue - */ - __pyx_t_31 = PyObject_RichCompare(__pyx_v_connected_fid, __pyx_v_working_fid, Py_EQ); __Pyx_XGOTREF(__pyx_t_31); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3671, __pyx_L1_error) - __pyx_t_29 = __Pyx_PyObject_IsTrue(__pyx_t_31); if (unlikely(__pyx_t_29 < 0)) __PYX_ERR(0, 3671, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - if (__pyx_t_29) { - - /* "pygeoprocessing/routing/routing.pyx":3673 - * if connected_fid == working_fid: - * # skip current - * continue # <<<<<<<<<<<<<< - * if connected_fid not in fid_to_order: - * # upstream not defined so skip it and it will be processed - */ - goto __pyx_L120_continue; - - /* "pygeoprocessing/routing/routing.pyx":3671 - * upstream_all_defined = True - * for connected_fid in connected_fids: - * if connected_fid == working_fid: # <<<<<<<<<<<<<< - * # skip current - * continue - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3674 - * # skip current - * continue - * if connected_fid not in fid_to_order: # <<<<<<<<<<<<<< - * # upstream not defined so skip it and it will be processed - * # on another iteration - */ - __pyx_t_29 = (__Pyx_PyDict_ContainsTF(__pyx_v_connected_fid, __pyx_v_fid_to_order, Py_NE)); if (unlikely(__pyx_t_29 < 0)) __PYX_ERR(0, 3674, __pyx_L1_error) - __pyx_t_21 = (__pyx_t_29 != 0); - if (__pyx_t_21) { - - /* "pygeoprocessing/routing/routing.pyx":3677 - * # upstream not defined so skip it and it will be processed - * # on another iteration - * upstream_all_defined = False # <<<<<<<<<<<<<< - * break - * - */ - __pyx_v_upstream_all_defined = 0; - - /* "pygeoprocessing/routing/routing.pyx":3678 - * # on another iteration - * upstream_all_defined = False - * break # <<<<<<<<<<<<<< - * - * if not upstream_all_defined: - */ - goto __pyx_L121_break; - - /* "pygeoprocessing/routing/routing.pyx":3674 - * # skip current - * continue - * if connected_fid not in fid_to_order: # <<<<<<<<<<<<<< - * # upstream not defined so skip it and it will be processed - * # on another iteration - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3670 - * # set a new downstream order - * upstream_all_defined = True - * for connected_fid in connected_fids: # <<<<<<<<<<<<<< - * if connected_fid == working_fid: - * # skip current - */ - __pyx_L120_continue:; - } - __pyx_L121_break:; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3680 - * break - * - * if not upstream_all_defined: # <<<<<<<<<<<<<< - * # wait for other upstream components to be defined - * continue - */ - __pyx_t_21 = ((!(__pyx_v_upstream_all_defined != 0)) != 0); - if (__pyx_t_21) { - - /* "pygeoprocessing/routing/routing.pyx":3682 - * if not upstream_all_defined: - * # wait for other upstream components to be defined - * continue # <<<<<<<<<<<<<< - * - * # all upstream components of this fid are calculated so it can be - */ - goto __pyx_L109_continue; - - /* "pygeoprocessing/routing/routing.pyx":3680 - * break - * - * if not upstream_all_defined: # <<<<<<<<<<<<<< - * # wait for other upstream components to be defined - * continue - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3686 - * # all upstream components of this fid are calculated so it can be - * # calculated now too - * working_stack.append(downstream_fid) # <<<<<<<<<<<<<< - * - * LOGGER.info( - */ - __pyx_t_27 = __Pyx_PyList_Append(__pyx_v_working_stack, __pyx_v_downstream_fid); if (unlikely(__pyx_t_27 == ((int)-1))) __PYX_ERR(0, 3686, __pyx_L1_error) - __pyx_L109_continue:; - } - - /* "pygeoprocessing/routing/routing.pyx":3688 - * working_stack.append(downstream_fid) - * - * LOGGER.info( # <<<<<<<<<<<<<< - * '(extract_strahler_streams_d8): ' - * 'final pass on stream order complete') - */ - __Pyx_GetModuleGlobalName(__pyx_t_31, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3688, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_31, __pyx_n_s_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3688, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - __pyx_t_31 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_31 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_31)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_31); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_9 = (__pyx_t_31) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_31, __pyx_kp_u_extract_strahler_streams_d8_fin_3) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_kp_u_extract_strahler_streams_d8_fin_3); - __Pyx_XDECREF(__pyx_t_31); __pyx_t_31 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3688, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3691 - * '(extract_strahler_streams_d8): ' - * 'final pass on stream order complete') - * LOGGER.info( # <<<<<<<<<<<<<< - * '(extract_strahler_streams_d8): ' - * 'commit transaction due to stream joining') - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3691, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_info); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3691, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_31))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_31); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_31, function); - } - } - __pyx_t_9 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_31, __pyx_t_1, __pyx_kp_u_extract_strahler_streams_d8_com) : __Pyx_PyObject_CallOneArg(__pyx_t_31, __pyx_kp_u_extract_strahler_streams_d8_com); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3691, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3694 - * '(extract_strahler_streams_d8): ' - * 'commit transaction due to stream joining') - * stream_layer.CommitTransaction() # <<<<<<<<<<<<<< - * stream_layer = None - * stream_vector = None - */ - __pyx_t_31 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_CommitTransaction); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3694, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_31))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_31); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_31); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_31, function); - } - } - __pyx_t_9 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_31, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_31); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3694, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3695 - * 'commit transaction due to stream joining') - * stream_layer.CommitTransaction() - * stream_layer = None # <<<<<<<<<<<<<< - * stream_vector = None - * LOGGER.info('(extract_strahler_streams_d8): all done') - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_stream_layer, Py_None); - - /* "pygeoprocessing/routing/routing.pyx":3696 - * stream_layer.CommitTransaction() - * stream_layer = None - * stream_vector = None # <<<<<<<<<<<<<< - * LOGGER.info('(extract_strahler_streams_d8): all done') - * - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_stream_vector, Py_None); - - /* "pygeoprocessing/routing/routing.pyx":3697 - * stream_layer = None - * stream_vector = None - * LOGGER.info('(extract_strahler_streams_d8): all done') # <<<<<<<<<<<<<< - * - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_31, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 3697, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_31); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_31, __pyx_n_s_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3697, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_31); __pyx_t_31 = 0; - __pyx_t_31 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_31 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_31)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_31); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_9 = (__pyx_t_31) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_31, __pyx_kp_u_extract_strahler_streams_d8_all) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_kp_u_extract_strahler_streams_d8_all); - __Pyx_XDECREF(__pyx_t_31); __pyx_t_31 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3697, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3025 - * - * - * def extract_strahler_streams_d8( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band, flow_accum_raster_path_band, - * dem_raster_path_band, - */ - - /* 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_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_30); - __Pyx_XDECREF(__pyx_t_31); - __Pyx_XDECREF(__pyx_t_32); - __Pyx_AddTraceback("pygeoprocessing.routing.routing.extract_strahler_streams_d8", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_flow_dir_info); - __Pyx_XDECREF(__pyx_v_flow_dir_srs); - __Pyx_XDECREF(__pyx_v_gpkg_driver); - __Pyx_XDECREF(__pyx_v_stream_vector); - __Pyx_XDECREF(__pyx_v_stream_basename); - __Pyx_XDECREF(__pyx_v_stream_layer); - __Pyx_XDECREF((PyObject *)__pyx_v_flow_dir_managed_raster); - __Pyx_XDECREF((PyObject *)__pyx_v_flow_accum_managed_raster); - __Pyx_XDECREF((PyObject *)__pyx_v_dem_managed_raster); - __Pyx_XDECREF(__pyx_v_coord_to_stream_ids); - __Pyx_XDECREF(__pyx_v_offset_dict); - __Pyx_XDECREF(__pyx_v_stream_feature); - __Pyx_XDECREF(__pyx_v_stream_fid); - __Pyx_XDECREF(__pyx_v_n_points); - __Pyx_XDECREF(__pyx_v_downstream_to_upstream_ids); - __Pyx_XDECREF(__pyx_v_upstream_to_downstream_id); - __Pyx_XDECREF(__pyx_v_payload); - __Pyx_XDECREF(__pyx_v_x_u); - __Pyx_XDECREF(__pyx_v_y_u); - __Pyx_XDECREF(__pyx_v_ds_x_1); - __Pyx_XDECREF(__pyx_v_ds_y_1); - __Pyx_XDECREF(__pyx_v_upstream_id_list); - __Pyx_XDECREF(__pyx_v_stream_line); - __Pyx_XDECREF(__pyx_v_upstream_id); - __Pyx_XDECREF(__pyx_v_streams_to_process); - __Pyx_XDECREF(__pyx_v_base_feature_count); - __Pyx_XDECREF(__pyx_v_outlet_fid_list); - __Pyx_XDECREF(__pyx_v_downstream_fid); - __Pyx_XDECREF(__pyx_v_downstream_feature); - __Pyx_XDECREF(__pyx_v_connected_upstream_fids); - __Pyx_XDECREF(__pyx_v_stream_order_list); - __Pyx_XDECREF(__pyx_v_upstream_fid); - __Pyx_XDECREF(__pyx_v_upstream_feature); - __Pyx_XDECREF(__pyx_v_upstream_order); - __Pyx_XDECREF(__pyx_v_sorted_stream_order_list); - __Pyx_XDECREF(__pyx_v_downstream_order); - __Pyx_XDECREF(__pyx_v_working_river_id); - __Pyx_XDECREF(__pyx_v_outlet_index); - __Pyx_XDECREF(__pyx_v_outlet_fid); - __Pyx_XDECREF(__pyx_v_search_stack); - __Pyx_XDECREF(__pyx_v_feature_id); - __Pyx_XDECREF(__pyx_v_stream_order); - __Pyx_XDECREF(__pyx_v_upstream_stack); - __Pyx_XDECREF(__pyx_v_streams_by_order); - __Pyx_XDECREF(__pyx_v_drop_distance_collection); - __Pyx_XDECREF(__pyx_v_max_upstream_flow_accum); - __Pyx_XDECREF(__pyx_v_order); - __Pyx_XDECREF(__pyx_v_working_flow_accum_threshold); - __Pyx_XDECREF(__pyx_v_test_order); - __Pyx_XDECREF(__pyx_v__); - __Pyx_XDECREF(__pyx_v_p_val); - __Pyx_XDECREF(__pyx_v_streams_to_retest); - __Pyx_XDECREF(__pyx_v_ds_x); - __Pyx_XDECREF(__pyx_v_ds_y); - __Pyx_XDECREF(__pyx_v_upstream_d8_dir); - __Pyx_XDECREF(__pyx_v_working_stack); - __Pyx_XDECREF(__pyx_v_fid_to_order); - __Pyx_XDECREF(__pyx_v_processed_segments); - __Pyx_XDECREF(__pyx_v_deleted_set); - __Pyx_XDECREF(__pyx_v_working_fid); - __Pyx_XDECREF(__pyx_v_upstream_fid_list); - __Pyx_XDECREF(__pyx_v_order_count); - __Pyx_XDECREF(__pyx_v_working_order); - __Pyx_XDECREF(__pyx_v_working_feature); - __Pyx_XDECREF(__pyx_v_connected_fids); - __Pyx_XDECREF(__pyx_v_downstream_geom); - __Pyx_XDECREF(__pyx_v_working_geom); - __Pyx_XDECREF(__pyx_v_multi_line); - __Pyx_XDECREF(__pyx_v_joined_line); - __Pyx_XDECREF(__pyx_v_connected_fid); - __Pyx_XDECREF(__pyx_7genexpr__pyx_v_stream_feature); - __Pyx_XDECREF(__pyx_8genexpr1__pyx_v_fid); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pygeoprocessing/routing/routing.pyx":3700 - * - * - * def _build_discovery_finish_rasters( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band, target_discovery_raster_path, - * target_finish_raster_path): - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_23_build_discovery_finish_rasters(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_15pygeoprocessing_7routing_7routing_22_build_discovery_finish_rasters[] = "Generates a discovery and finish time raster for a given d8 flow path.\n\n Args:\n flow_dir_d8_raster_path_band (tuple): a D8 flow raster path band tuple\n target_discovery_raster_path (str): path to a generated raster that\n creates discovery time (i.e. what count the pixel is visited in)\n target_finish_raster_path (str): path to generated raster that creates\n maximum upstream finish time.\n\n Returns:\n None\n "; -static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_23_build_discovery_finish_rasters = {"_build_discovery_finish_rasters", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_7routing_7routing_23_build_discovery_finish_rasters, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_7routing_7routing_22_build_discovery_finish_rasters}; -static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_23_build_discovery_finish_rasters(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_flow_dir_d8_raster_path_band = 0; - PyObject *__pyx_v_target_discovery_raster_path = 0; - PyObject *__pyx_v_target_finish_raster_path = 0; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_build_discovery_finish_rasters (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_flow_dir_d8_raster_path_band,&__pyx_n_s_target_discovery_raster_path,&__pyx_n_s_target_finish_raster_path,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_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_target_discovery_raster_path)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_build_discovery_finish_rasters", 1, 3, 3, 1); __PYX_ERR(0, 3700, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_finish_raster_path)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_build_discovery_finish_rasters", 1, 3, 3, 2); __PYX_ERR(0, 3700, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_build_discovery_finish_rasters") < 0)) __PYX_ERR(0, 3700, __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_flow_dir_d8_raster_path_band = values[0]; - __pyx_v_target_discovery_raster_path = values[1]; - __pyx_v_target_finish_raster_path = values[2]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_build_discovery_finish_rasters", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3700, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pygeoprocessing.routing.routing._build_discovery_finish_rasters", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing_22_build_discovery_finish_rasters(__pyx_self, __pyx_v_flow_dir_d8_raster_path_band, __pyx_v_target_discovery_raster_path, __pyx_v_target_finish_raster_path); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_22_build_discovery_finish_rasters(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_flow_dir_d8_raster_path_band, PyObject *__pyx_v_target_discovery_raster_path, PyObject *__pyx_v_target_finish_raster_path) { - PyObject *__pyx_v_flow_dir_info = NULL; - int __pyx_v_n_cols; - int __pyx_v_n_rows; - int __pyx_v_flow_dir_nodata; - struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_flow_dir_managed_raster = NULL; - struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_discovery_managed_raster = NULL; - struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_finish_managed_raster = NULL; - std::stack __pyx_v_discovery_stack; - std::stack __pyx_v_finish_stack; - struct __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateType __pyx_v_raster_coord; - struct __pyx_t_15pygeoprocessing_7routing_7routing_FinishType __pyx_v_finish_coordinate; - long __pyx_v_discovery_count; - int __pyx_v_n_processed; - int __pyx_v_n_pixels; - time_t __pyx_v_last_log_time; - int __pyx_v_n_pushed; - int __pyx_v_i; - int __pyx_v_j; - int __pyx_v_xoff; - int __pyx_v_yoff; - int __pyx_v_win_xsize; - int __pyx_v_win_ysize; - int __pyx_v_x_l; - int __pyx_v_y_l; - int __pyx_v_x_n; - int __pyx_v_y_n; - int __pyx_v_n_dir; - int __pyx_v_test_dir; - PyObject *__pyx_v_offset_dict = NULL; - int __pyx_v_d_n; - 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)(PyObject *); - int __pyx_t_6; - int __pyx_t_7; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - Py_ssize_t __pyx_t_11; - PyObject *(*__pyx_t_12)(PyObject *); - int __pyx_t_13; - Py_ssize_t __pyx_t_14; - Py_UCS4 __pyx_t_15; - int __pyx_t_16; - int __pyx_t_17; - int __pyx_t_18; - int __pyx_t_19; - int __pyx_t_20; - struct __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateType __pyx_t_21; - struct __pyx_t_15pygeoprocessing_7routing_7routing_FinishType __pyx_t_22; - int __pyx_t_23; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("_build_discovery_finish_rasters", 0); - - /* "pygeoprocessing/routing/routing.pyx":3715 - * None - * """ - * flow_dir_info = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band[0]) - * cdef int n_cols, n_rows - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3715, __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, 3715, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3716 - * """ - * flow_dir_info = pygeoprocessing.get_raster_info( - * flow_dir_d8_raster_path_band[0]) # <<<<<<<<<<<<<< - * cdef int n_cols, n_rows - * n_cols, n_rows = flow_dir_info['raster_size'] - */ - __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, 3716, __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); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3715, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_flow_dir_info = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3718 - * flow_dir_d8_raster_path_band[0]) - * cdef int n_cols, n_rows - * n_cols, n_rows = flow_dir_info['raster_size'] # <<<<<<<<<<<<<< - * cdef int flow_dir_nodata = ( - * flow_dir_info['nodata'][flow_dir_d8_raster_path_band[1]-1]) - */ - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3718, __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, 3718, __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, 3718, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3718, __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, 3718, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext; - index = 0; __pyx_t_3 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L3_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - index = 1; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L3_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) __PYX_ERR(0, 3718, __pyx_L1_error) - __pyx_t_5 = NULL; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L4_unpacking_done; - __pyx_L3_unpacking_failed:; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_5 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 3718, __pyx_L1_error) - __pyx_L4_unpacking_done:; - } - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3718, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3718, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_n_cols = __pyx_t_6; - __pyx_v_n_rows = __pyx_t_7; - - /* "pygeoprocessing/routing/routing.pyx":3720 - * n_cols, n_rows = flow_dir_info['raster_size'] - * cdef int flow_dir_nodata = ( - * flow_dir_info['nodata'][flow_dir_d8_raster_path_band[1]-1]) # <<<<<<<<<<<<<< - * - * flow_dir_managed_raster = _ManagedRaster( - */ - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3720, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3720, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_SubtractObjC(__pyx_t_2, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3720, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3720, __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_7 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3720, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_flow_dir_nodata = __pyx_t_7; - - /* "pygeoprocessing/routing/routing.pyx":3723 - * - * flow_dir_managed_raster = _ManagedRaster( - * flow_dir_d8_raster_path_band[0], flow_dir_d8_raster_path_band[1], 0) # <<<<<<<<<<<<<< - * pygeoprocessing.new_raster_from_base( - * flow_dir_d8_raster_path_band[0], target_discovery_raster_path, - */ - __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, 3723, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3723, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pygeoprocessing/routing/routing.pyx":3722 - * flow_dir_info['nodata'][flow_dir_d8_raster_path_band[1]-1]) - * - * flow_dir_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band[0], flow_dir_d8_raster_path_band[1], 0) - * pygeoprocessing.new_raster_from_base( - */ - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3722, __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_3); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_int_0); - __pyx_t_2 = 0; - __pyx_t_3 = 0; - __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, 3722, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_flow_dir_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3724 - * flow_dir_managed_raster = _ManagedRaster( - * flow_dir_d8_raster_path_band[0], flow_dir_d8_raster_path_band[1], 0) - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band[0], target_discovery_raster_path, - * gdal.GDT_Float64, [-1]) - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3724, __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, 3724, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3725 - * flow_dir_d8_raster_path_band[0], flow_dir_d8_raster_path_band[1], 0) - * pygeoprocessing.new_raster_from_base( - * flow_dir_d8_raster_path_band[0], target_discovery_raster_path, # <<<<<<<<<<<<<< - * gdal.GDT_Float64, [-1]) - * discovery_managed_raster = _ManagedRaster( - */ - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3725, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":3726 - * pygeoprocessing.new_raster_from_base( - * flow_dir_d8_raster_path_band[0], target_discovery_raster_path, - * gdal.GDT_Float64, [-1]) # <<<<<<<<<<<<<< - * discovery_managed_raster = _ManagedRaster( - * target_discovery_raster_path, 1, 1) - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3726, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3726, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3726, __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); - __pyx_t_9 = NULL; - __pyx_t_7 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(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); - __pyx_t_7 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[5] = {__pyx_t_9, __pyx_t_1, __pyx_v_target_discovery_raster_path, __pyx_t_8, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_7, 4+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3724, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[5] = {__pyx_t_9, __pyx_t_1, __pyx_v_target_discovery_raster_path, __pyx_t_8, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_7, 4+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3724, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - { - __pyx_t_10 = PyTuple_New(4+__pyx_t_7); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3724, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - if (__pyx_t_9) { - __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); __pyx_t_9 = NULL; - } - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_7, __pyx_t_1); - __Pyx_INCREF(__pyx_v_target_discovery_raster_path); - __Pyx_GIVEREF(__pyx_v_target_discovery_raster_path); - PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_7, __pyx_v_target_discovery_raster_path); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_10, 2+__pyx_t_7, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_10, 3+__pyx_t_7, __pyx_t_4); - __pyx_t_1 = 0; - __pyx_t_8 = 0; - __pyx_t_4 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3724, __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_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3727 - * flow_dir_d8_raster_path_band[0], target_discovery_raster_path, - * gdal.GDT_Float64, [-1]) - * discovery_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< - * target_discovery_raster_path, 1, 1) - * pygeoprocessing.new_raster_from_base( - */ - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3727, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_target_discovery_raster_path); - __Pyx_GIVEREF(__pyx_v_target_discovery_raster_path); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_target_discovery_raster_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_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3727, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_discovery_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3729 - * discovery_managed_raster = _ManagedRaster( - * target_discovery_raster_path, 1, 1) - * pygeoprocessing.new_raster_from_base( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band[0], target_finish_raster_path, - * gdal.GDT_Float64, [-1]) - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3729, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3729, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3730 - * target_discovery_raster_path, 1, 1) - * pygeoprocessing.new_raster_from_base( - * flow_dir_d8_raster_path_band[0], target_finish_raster_path, # <<<<<<<<<<<<<< - * gdal.GDT_Float64, [-1]) - * finish_managed_raster = _ManagedRaster(target_finish_raster_path, 1, 1) - */ - __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3730, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pygeoprocessing/routing/routing.pyx":3731 - * pygeoprocessing.new_raster_from_base( - * flow_dir_d8_raster_path_band[0], target_finish_raster_path, - * gdal.GDT_Float64, [-1]) # <<<<<<<<<<<<<< - * finish_managed_raster = _ManagedRaster(target_finish_raster_path, 1, 1) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3731, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3731, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3731, __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); - __pyx_t_1 = NULL; - __pyx_t_7 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_10); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_10, function); - __pyx_t_7 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[5] = {__pyx_t_1, __pyx_t_3, __pyx_v_target_finish_raster_path, __pyx_t_8, __pyx_t_4}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_7, 4+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3729, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[5] = {__pyx_t_1, __pyx_t_3, __pyx_v_target_finish_raster_path, __pyx_t_8, __pyx_t_4}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_7, 4+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3729, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - { - __pyx_t_9 = PyTuple_New(4+__pyx_t_7); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3729, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - if (__pyx_t_1) { - __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1); __pyx_t_1 = NULL; - } - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_7, __pyx_t_3); - __Pyx_INCREF(__pyx_v_target_finish_raster_path); - __Pyx_GIVEREF(__pyx_v_target_finish_raster_path); - PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_7, __pyx_v_target_finish_raster_path); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_9, 2+__pyx_t_7, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_9, 3+__pyx_t_7, __pyx_t_4); - __pyx_t_3 = 0; - __pyx_t_8 = 0; - __pyx_t_4 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3729, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3732 - * flow_dir_d8_raster_path_band[0], target_finish_raster_path, - * gdal.GDT_Float64, [-1]) - * finish_managed_raster = _ManagedRaster(target_finish_raster_path, 1, 1) # <<<<<<<<<<<<<< - * - * cdef stack[CoordinateType] discovery_stack - */ - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3732, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_target_finish_raster_path); - __Pyx_GIVEREF(__pyx_v_target_finish_raster_path); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_target_finish_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_10 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_2, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3732, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_finish_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_10); - __pyx_t_10 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3739 - * cdef FinishType finish_coordinate - * - * cdef long discovery_count = 0 # <<<<<<<<<<<<<< - * cdef int n_processed, n_pixels - * n_pixels = n_rows * n_cols - */ - __pyx_v_discovery_count = 0; - - /* "pygeoprocessing/routing/routing.pyx":3741 - * cdef long discovery_count = 0 - * cdef int n_processed, n_pixels - * n_pixels = n_rows * n_cols # <<<<<<<<<<<<<< - * n_processed = 0 - * cdef time_t last_log_time = ctime(NULL) - */ - __pyx_v_n_pixels = (__pyx_v_n_rows * __pyx_v_n_cols); - - /* "pygeoprocessing/routing/routing.pyx":3742 - * cdef int n_processed, n_pixels - * n_pixels = n_rows * n_cols - * n_processed = 0 # <<<<<<<<<<<<<< - * cdef time_t last_log_time = ctime(NULL) - * cdef int n_pushed - */ - __pyx_v_n_processed = 0; - - /* "pygeoprocessing/routing/routing.pyx":3743 - * n_pixels = n_rows * n_cols - * n_processed = 0 - * cdef time_t last_log_time = ctime(NULL) # <<<<<<<<<<<<<< - * cdef int n_pushed - * - */ - __pyx_v_last_log_time = time(NULL); - - /* "pygeoprocessing/routing/routing.pyx":3749 - * cdef int n_dir, test_dir - * - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band, offset_only=True): - * # search raster block by raster block - */ - __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3749, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3749, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3750 - * - * for offset_dict in pygeoprocessing.iterblocks( - * flow_dir_d8_raster_path_band, offset_only=True): # <<<<<<<<<<<<<< - * # search raster block by raster block - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: - */ - __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3749, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __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_10, 0, __pyx_v_flow_dir_d8_raster_path_band); - __pyx_t_9 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3750, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 3750, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3749 - * cdef int n_dir, test_dir - * - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band, offset_only=True): - * # search raster block by raster block - */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_10, __pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3749, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) { - __pyx_t_9 = __pyx_t_4; __Pyx_INCREF(__pyx_t_9); __pyx_t_11 = 0; - __pyx_t_12 = NULL; - } else { - __pyx_t_11 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3749, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_12 = Py_TYPE(__pyx_t_9)->tp_iternext; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 3749, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - for (;;) { - if (likely(!__pyx_t_12)) { - if (likely(PyList_CheckExact(__pyx_t_9))) { - if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_9)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_11); __Pyx_INCREF(__pyx_t_4); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 3749, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_9, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3749, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } else { - if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_9)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_11); __Pyx_INCREF(__pyx_t_4); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 3749, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_9, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3749, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } - } else { - __pyx_t_4 = __pyx_t_12(__pyx_t_9); - 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, 3749, __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":3752 - * flow_dir_d8_raster_path_band, offset_only=True): - * # search raster block by raster block - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * LOGGER.info( - * f'(discovery time processing): ' - */ - __pyx_t_13 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); - if (__pyx_t_13) { - - /* "pygeoprocessing/routing/routing.pyx":3753 - * # search raster block by raster block - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: - * LOGGER.info( # <<<<<<<<<<<<<< - * f'(discovery time processing): ' - * f'{n_processed/n_pixels*100:.1f}% complete') - */ - __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3753, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3753, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3754 - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: - * LOGGER.info( - * f'(discovery time processing): ' # <<<<<<<<<<<<<< - * f'{n_processed/n_pixels*100:.1f}% complete') - * last_log_time = ctime(NULL) - */ - __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3754, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_14 = 0; - __pyx_t_15 = 127; - __Pyx_INCREF(__pyx_kp_u_discovery_time_processing); - __pyx_t_14 += 29; - __Pyx_GIVEREF(__pyx_kp_u_discovery_time_processing); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_kp_u_discovery_time_processing); - - /* "pygeoprocessing/routing/routing.pyx":3755 - * LOGGER.info( - * f'(discovery time processing): ' - * f'{n_processed/n_pixels*100:.1f}% complete') # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * xoff = offset_dict['xoff'] - */ - if (unlikely(__pyx_v_n_pixels == 0)) { - PyErr_SetString(PyExc_ZeroDivisionError, "float division"); - __PYX_ERR(0, 3755, __pyx_L1_error) - } - __pyx_t_8 = PyFloat_FromDouble(((((double)__pyx_v_n_processed) / ((double)__pyx_v_n_pixels)) * 100.0)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3755, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_3 = __Pyx_PyObject_Format(__pyx_t_8, __pyx_kp_u_1f); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3755, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_15 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) > __pyx_t_15) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) : __pyx_t_15; - __pyx_t_14 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_3); - __pyx_t_3 = 0; - __Pyx_INCREF(__pyx_kp_u_complete); - __pyx_t_14 += 10; - __Pyx_GIVEREF(__pyx_kp_u_complete); - PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_kp_u_complete); - - /* "pygeoprocessing/routing/routing.pyx":3754 - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: - * LOGGER.info( - * f'(discovery time processing): ' # <<<<<<<<<<<<<< - * f'{n_processed/n_pixels*100:.1f}% complete') - * last_log_time = ctime(NULL) - */ - __pyx_t_3 = __Pyx_PyUnicode_Join(__pyx_t_10, 3, __pyx_t_14, __pyx_t_15); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3754, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_10)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_4 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_10, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3753, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3756 - * f'(discovery time processing): ' - * f'{n_processed/n_pixels*100:.1f}% complete') - * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< - * xoff = offset_dict['xoff'] - * yoff = offset_dict['yoff'] - */ - __pyx_v_last_log_time = time(NULL); - - /* "pygeoprocessing/routing/routing.pyx":3752 - * flow_dir_d8_raster_path_band, offset_only=True): - * # search raster block by raster block - * if ctime(NULL)-last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * LOGGER.info( - * f'(discovery time processing): ' - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3757 - * f'{n_processed/n_pixels*100:.1f}% complete') - * last_log_time = ctime(NULL) - * xoff = offset_dict['xoff'] # <<<<<<<<<<<<<< - * yoff = offset_dict['yoff'] - * win_xsize = offset_dict['win_xsize'] - */ - __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_xoff); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3757, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3757, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_xoff = __pyx_t_7; - - /* "pygeoprocessing/routing/routing.pyx":3758 - * last_log_time = ctime(NULL) - * xoff = offset_dict['xoff'] - * yoff = offset_dict['yoff'] # <<<<<<<<<<<<<< - * win_xsize = offset_dict['win_xsize'] - * win_ysize = offset_dict['win_ysize'] - */ - __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_yoff); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3758, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3758, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_yoff = __pyx_t_7; - - /* "pygeoprocessing/routing/routing.pyx":3759 - * xoff = offset_dict['xoff'] - * yoff = offset_dict['yoff'] - * win_xsize = offset_dict['win_xsize'] # <<<<<<<<<<<<<< - * win_ysize = offset_dict['win_ysize'] - * n_processed += win_xsize * win_ysize - */ - __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3759, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3759, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_win_xsize = __pyx_t_7; - - /* "pygeoprocessing/routing/routing.pyx":3760 - * yoff = offset_dict['yoff'] - * win_xsize = offset_dict['win_xsize'] - * win_ysize = offset_dict['win_ysize'] # <<<<<<<<<<<<<< - * n_processed += win_xsize * win_ysize - * - */ - __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3760, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3760, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_win_ysize = __pyx_t_7; - - /* "pygeoprocessing/routing/routing.pyx":3761 - * win_xsize = offset_dict['win_xsize'] - * win_ysize = offset_dict['win_ysize'] - * n_processed += win_xsize * win_ysize # <<<<<<<<<<<<<< - * - * for i in range(win_xsize): - */ - __pyx_v_n_processed = (__pyx_v_n_processed + (__pyx_v_win_xsize * __pyx_v_win_ysize)); - - /* "pygeoprocessing/routing/routing.pyx":3763 - * n_processed += win_xsize * win_ysize - * - * for i in range(win_xsize): # <<<<<<<<<<<<<< - * for j in range(win_ysize): - * x_l = xoff + i - */ - __pyx_t_7 = __pyx_v_win_xsize; - __pyx_t_6 = __pyx_t_7; - for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_6; __pyx_t_16+=1) { - __pyx_v_i = __pyx_t_16; - - /* "pygeoprocessing/routing/routing.pyx":3764 - * - * for i in range(win_xsize): - * for j in range(win_ysize): # <<<<<<<<<<<<<< - * x_l = xoff + i - * y_l = yoff + j - */ - __pyx_t_17 = __pyx_v_win_ysize; - __pyx_t_18 = __pyx_t_17; - for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_18; __pyx_t_19+=1) { - __pyx_v_j = __pyx_t_19; - - /* "pygeoprocessing/routing/routing.pyx":3765 - * for i in range(win_xsize): - * for j in range(win_ysize): - * x_l = xoff + i # <<<<<<<<<<<<<< - * y_l = yoff + j - * # check to see if this pixel is a drain - */ - __pyx_v_x_l = (__pyx_v_xoff + __pyx_v_i); - - /* "pygeoprocessing/routing/routing.pyx":3766 - * for j in range(win_ysize): - * x_l = xoff + i - * y_l = yoff + j # <<<<<<<<<<<<<< - * # check to see if this pixel is a drain - * d_n = flow_dir_managed_raster.get(x_l, y_l) - */ - __pyx_v_y_l = (__pyx_v_yoff + __pyx_v_j); - - /* "pygeoprocessing/routing/routing.pyx":3768 - * y_l = yoff + j - * # check to see if this pixel is a drain - * d_n = flow_dir_managed_raster.get(x_l, y_l) # <<<<<<<<<<<<<< - * if d_n == flow_dir_nodata: - * continue - */ - __pyx_v_d_n = ((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_dir_managed_raster, __pyx_v_x_l, __pyx_v_y_l)); - - /* "pygeoprocessing/routing/routing.pyx":3769 - * # check to see if this pixel is a drain - * d_n = flow_dir_managed_raster.get(x_l, y_l) - * if d_n == flow_dir_nodata: # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_13 = ((__pyx_v_d_n == __pyx_v_flow_dir_nodata) != 0); - if (__pyx_t_13) { - - /* "pygeoprocessing/routing/routing.pyx":3770 - * d_n = flow_dir_managed_raster.get(x_l, y_l) - * if d_n == flow_dir_nodata: - * continue # <<<<<<<<<<<<<< - * - * # check if downstream neighbor runs off raster or is nodata - */ - goto __pyx_L10_continue; - - /* "pygeoprocessing/routing/routing.pyx":3769 - * # check to see if this pixel is a drain - * d_n = flow_dir_managed_raster.get(x_l, y_l) - * if d_n == flow_dir_nodata: # <<<<<<<<<<<<<< - * continue - * - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3773 - * - * # check if downstream neighbor runs off raster or is nodata - * x_n = x_l + D8_XOFFSET[d_n] # <<<<<<<<<<<<<< - * y_n = y_l + D8_YOFFSET[d_n] - * - */ - __pyx_v_x_n = (__pyx_v_x_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_d_n])); - - /* "pygeoprocessing/routing/routing.pyx":3774 - * # check if downstream neighbor runs off raster or is nodata - * x_n = x_l + D8_XOFFSET[d_n] - * y_n = y_l + D8_YOFFSET[d_n] # <<<<<<<<<<<<<< - * - * if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows or - */ - __pyx_v_y_n = (__pyx_v_y_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_d_n])); - - /* "pygeoprocessing/routing/routing.pyx":3776 - * y_n = y_l + D8_YOFFSET[d_n] - * - * if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows or # <<<<<<<<<<<<<< - * flow_dir_managed_raster.get( - * x_n, y_n) == flow_dir_nodata): - */ - __pyx_t_20 = ((__pyx_v_x_n < 0) != 0); - if (!__pyx_t_20) { - } else { - __pyx_t_13 = __pyx_t_20; - goto __pyx_L14_bool_binop_done; - } - __pyx_t_20 = ((__pyx_v_y_n < 0) != 0); - if (!__pyx_t_20) { - } else { - __pyx_t_13 = __pyx_t_20; - goto __pyx_L14_bool_binop_done; - } - __pyx_t_20 = ((__pyx_v_x_n >= __pyx_v_n_cols) != 0); - if (!__pyx_t_20) { - } else { - __pyx_t_13 = __pyx_t_20; - goto __pyx_L14_bool_binop_done; - } - __pyx_t_20 = ((__pyx_v_y_n >= __pyx_v_n_rows) != 0); - if (!__pyx_t_20) { - } else { - __pyx_t_13 = __pyx_t_20; - goto __pyx_L14_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":3778 - * if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows or - * flow_dir_managed_raster.get( - * x_n, y_n) == flow_dir_nodata): # <<<<<<<<<<<<<< - * discovery_stack.push(CoordinateType(x_l, y_l)) - * finish_stack.push(FinishType(x_l, y_l, 1)) - */ - __pyx_t_20 = ((((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_dir_managed_raster, __pyx_v_x_n, __pyx_v_y_n)) == __pyx_v_flow_dir_nodata) != 0); - __pyx_t_13 = __pyx_t_20; - __pyx_L14_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":3776 - * y_n = y_l + D8_YOFFSET[d_n] - * - * if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows or # <<<<<<<<<<<<<< - * flow_dir_managed_raster.get( - * x_n, y_n) == flow_dir_nodata): - */ - if (__pyx_t_13) { - - /* "pygeoprocessing/routing/routing.pyx":3779 - * flow_dir_managed_raster.get( - * x_n, y_n) == flow_dir_nodata): - * discovery_stack.push(CoordinateType(x_l, y_l)) # <<<<<<<<<<<<<< - * finish_stack.push(FinishType(x_l, y_l, 1)) - * - */ - __pyx_t_21.xi = __pyx_v_x_l; - __pyx_t_21.yi = __pyx_v_y_l; - __pyx_v_discovery_stack.push(__pyx_t_21); - - /* "pygeoprocessing/routing/routing.pyx":3780 - * x_n, y_n) == flow_dir_nodata): - * discovery_stack.push(CoordinateType(x_l, y_l)) - * finish_stack.push(FinishType(x_l, y_l, 1)) # <<<<<<<<<<<<<< - * - * while not discovery_stack.empty(): - */ - __pyx_t_22.xi = __pyx_v_x_l; - __pyx_t_22.yi = __pyx_v_y_l; - __pyx_t_22.n_pushed = 1; - __pyx_v_finish_stack.push(__pyx_t_22); - - /* "pygeoprocessing/routing/routing.pyx":3776 - * y_n = y_l + D8_YOFFSET[d_n] - * - * if (x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows or # <<<<<<<<<<<<<< - * flow_dir_managed_raster.get( - * x_n, y_n) == flow_dir_nodata): - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3782 - * finish_stack.push(FinishType(x_l, y_l, 1)) - * - * while not discovery_stack.empty(): # <<<<<<<<<<<<<< - * # This coordinate is the downstream end of the stream - * raster_coord = discovery_stack.top() - */ - while (1) { - __pyx_t_13 = ((!(__pyx_v_discovery_stack.empty() != 0)) != 0); - if (!__pyx_t_13) break; - - /* "pygeoprocessing/routing/routing.pyx":3784 - * while not discovery_stack.empty(): - * # This coordinate is the downstream end of the stream - * raster_coord = discovery_stack.top() # <<<<<<<<<<<<<< - * discovery_stack.pop() - * - */ - __pyx_v_raster_coord = __pyx_v_discovery_stack.top(); - - /* "pygeoprocessing/routing/routing.pyx":3785 - * # This coordinate is the downstream end of the stream - * raster_coord = discovery_stack.top() - * discovery_stack.pop() # <<<<<<<<<<<<<< - * - * discovery_managed_raster.set( - */ - __pyx_v_discovery_stack.pop(); - - /* "pygeoprocessing/routing/routing.pyx":3787 - * discovery_stack.pop() - * - * discovery_managed_raster.set( # <<<<<<<<<<<<<< - * raster_coord.xi, raster_coord.yi, discovery_count) - * discovery_count += 1 - */ - __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_discovery_managed_raster, __pyx_v_raster_coord.xi, __pyx_v_raster_coord.yi, __pyx_v_discovery_count); - - /* "pygeoprocessing/routing/routing.pyx":3789 - * discovery_managed_raster.set( - * raster_coord.xi, raster_coord.yi, discovery_count) - * discovery_count += 1 # <<<<<<<<<<<<<< - * - * n_pushed = 0 - */ - __pyx_v_discovery_count = (__pyx_v_discovery_count + 1); - - /* "pygeoprocessing/routing/routing.pyx":3791 - * discovery_count += 1 - * - * n_pushed = 0 # <<<<<<<<<<<<<< - * # check each neighbor to see if it drains to this cell - * # if so, it's on the traversal path - */ - __pyx_v_n_pushed = 0; - - /* "pygeoprocessing/routing/routing.pyx":3794 - * # check each neighbor to see if it drains to this cell - * # if so, it's on the traversal path - * for test_dir in range(8): # <<<<<<<<<<<<<< - * x_n = raster_coord.xi + D8_XOFFSET[test_dir % 8] - * y_n = raster_coord.yi + D8_YOFFSET[test_dir % 8] - */ - for (__pyx_t_23 = 0; __pyx_t_23 < 8; __pyx_t_23+=1) { - __pyx_v_test_dir = __pyx_t_23; - - /* "pygeoprocessing/routing/routing.pyx":3795 - * # if so, it's on the traversal path - * for test_dir in range(8): - * x_n = raster_coord.xi + D8_XOFFSET[test_dir % 8] # <<<<<<<<<<<<<< - * y_n = raster_coord.yi + D8_YOFFSET[test_dir % 8] - * if x_n < 0 or y_n < 0 or \ - */ - __pyx_v_x_n = (__pyx_v_raster_coord.xi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__Pyx_mod_long(__pyx_v_test_dir, 8)])); - - /* "pygeoprocessing/routing/routing.pyx":3796 - * for test_dir in range(8): - * x_n = raster_coord.xi + D8_XOFFSET[test_dir % 8] - * y_n = raster_coord.yi + D8_YOFFSET[test_dir % 8] # <<<<<<<<<<<<<< - * if x_n < 0 or y_n < 0 or \ - * x_n >= n_cols or y_n >= n_rows: - */ - __pyx_v_y_n = (__pyx_v_raster_coord.yi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__Pyx_mod_long(__pyx_v_test_dir, 8)])); - - /* "pygeoprocessing/routing/routing.pyx":3797 - * x_n = raster_coord.xi + D8_XOFFSET[test_dir % 8] - * y_n = raster_coord.yi + D8_YOFFSET[test_dir % 8] - * if x_n < 0 or y_n < 0 or \ # <<<<<<<<<<<<<< - * x_n >= n_cols or y_n >= n_rows: - * continue - */ - __pyx_t_20 = ((__pyx_v_x_n < 0) != 0); - if (!__pyx_t_20) { - } else { - __pyx_t_13 = __pyx_t_20; - goto __pyx_L24_bool_binop_done; - } - __pyx_t_20 = ((__pyx_v_y_n < 0) != 0); - if (!__pyx_t_20) { - } else { - __pyx_t_13 = __pyx_t_20; - goto __pyx_L24_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":3798 - * y_n = raster_coord.yi + D8_YOFFSET[test_dir % 8] - * if x_n < 0 or y_n < 0 or \ - * x_n >= n_cols or y_n >= n_rows: # <<<<<<<<<<<<<< - * continue - * n_dir = flow_dir_managed_raster.get(x_n, y_n) - */ - __pyx_t_20 = ((__pyx_v_x_n >= __pyx_v_n_cols) != 0); - if (!__pyx_t_20) { - } else { - __pyx_t_13 = __pyx_t_20; - goto __pyx_L24_bool_binop_done; - } - __pyx_t_20 = ((__pyx_v_y_n >= __pyx_v_n_rows) != 0); - __pyx_t_13 = __pyx_t_20; - __pyx_L24_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":3797 - * x_n = raster_coord.xi + D8_XOFFSET[test_dir % 8] - * y_n = raster_coord.yi + D8_YOFFSET[test_dir % 8] - * if x_n < 0 or y_n < 0 or \ # <<<<<<<<<<<<<< - * x_n >= n_cols or y_n >= n_rows: - * continue - */ - if (__pyx_t_13) { - - /* "pygeoprocessing/routing/routing.pyx":3799 - * if x_n < 0 or y_n < 0 or \ - * x_n >= n_cols or y_n >= n_rows: - * continue # <<<<<<<<<<<<<< - * n_dir = flow_dir_managed_raster.get(x_n, y_n) - * if n_dir == flow_dir_nodata: - */ - goto __pyx_L21_continue; - - /* "pygeoprocessing/routing/routing.pyx":3797 - * x_n = raster_coord.xi + D8_XOFFSET[test_dir % 8] - * y_n = raster_coord.yi + D8_YOFFSET[test_dir % 8] - * if x_n < 0 or y_n < 0 or \ # <<<<<<<<<<<<<< - * x_n >= n_cols or y_n >= n_rows: - * continue - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3800 - * x_n >= n_cols or y_n >= n_rows: - * continue - * n_dir = flow_dir_managed_raster.get(x_n, y_n) # <<<<<<<<<<<<<< - * if n_dir == flow_dir_nodata: - * continue - */ - __pyx_v_n_dir = ((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_dir_managed_raster, __pyx_v_x_n, __pyx_v_y_n)); - - /* "pygeoprocessing/routing/routing.pyx":3801 - * continue - * n_dir = flow_dir_managed_raster.get(x_n, y_n) - * if n_dir == flow_dir_nodata: # <<<<<<<<<<<<<< - * continue - * if D8_REVERSE_DIRECTION[test_dir] == n_dir: - */ - __pyx_t_13 = ((__pyx_v_n_dir == __pyx_v_flow_dir_nodata) != 0); - if (__pyx_t_13) { - - /* "pygeoprocessing/routing/routing.pyx":3802 - * n_dir = flow_dir_managed_raster.get(x_n, y_n) - * if n_dir == flow_dir_nodata: - * continue # <<<<<<<<<<<<<< - * if D8_REVERSE_DIRECTION[test_dir] == n_dir: - * discovery_stack.push(CoordinateType(x_n, y_n)) - */ - goto __pyx_L21_continue; - - /* "pygeoprocessing/routing/routing.pyx":3801 - * continue - * n_dir = flow_dir_managed_raster.get(x_n, y_n) - * if n_dir == flow_dir_nodata: # <<<<<<<<<<<<<< - * continue - * if D8_REVERSE_DIRECTION[test_dir] == n_dir: - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3803 - * if n_dir == flow_dir_nodata: - * continue - * if D8_REVERSE_DIRECTION[test_dir] == n_dir: # <<<<<<<<<<<<<< - * discovery_stack.push(CoordinateType(x_n, y_n)) - * n_pushed += 1 - */ - __pyx_t_13 = (((__pyx_v_15pygeoprocessing_7routing_7routing_D8_REVERSE_DIRECTION[__pyx_v_test_dir]) == __pyx_v_n_dir) != 0); - if (__pyx_t_13) { - - /* "pygeoprocessing/routing/routing.pyx":3804 - * continue - * if D8_REVERSE_DIRECTION[test_dir] == n_dir: - * discovery_stack.push(CoordinateType(x_n, y_n)) # <<<<<<<<<<<<<< - * n_pushed += 1 - * # this reference is for the previous top and represents - */ - __pyx_t_21.xi = __pyx_v_x_n; - __pyx_t_21.yi = __pyx_v_y_n; - __pyx_v_discovery_stack.push(__pyx_t_21); - - /* "pygeoprocessing/routing/routing.pyx":3805 - * if D8_REVERSE_DIRECTION[test_dir] == n_dir: - * discovery_stack.push(CoordinateType(x_n, y_n)) - * n_pushed += 1 # <<<<<<<<<<<<<< - * # this reference is for the previous top and represents - * # how many elements must be processed before finish - */ - __pyx_v_n_pushed = (__pyx_v_n_pushed + 1); - - /* "pygeoprocessing/routing/routing.pyx":3803 - * if n_dir == flow_dir_nodata: - * continue - * if D8_REVERSE_DIRECTION[test_dir] == n_dir: # <<<<<<<<<<<<<< - * discovery_stack.push(CoordinateType(x_n, y_n)) - * n_pushed += 1 - */ - } - __pyx_L21_continue:; - } - - /* "pygeoprocessing/routing/routing.pyx":3811 - * finish_stack.push( - * FinishType( - * raster_coord.xi, raster_coord.yi, n_pushed)) # <<<<<<<<<<<<<< - * - * # pop the finish stack until n_pushed > 1 - */ - __pyx_t_22.xi = __pyx_v_raster_coord.xi; - __pyx_t_22.yi = __pyx_v_raster_coord.yi; - __pyx_t_22.n_pushed = __pyx_v_n_pushed; - - /* "pygeoprocessing/routing/routing.pyx":3809 - * # how many elements must be processed before finish - * # time can be defined - * finish_stack.push( # <<<<<<<<<<<<<< - * FinishType( - * raster_coord.xi, raster_coord.yi, n_pushed)) - */ - __pyx_v_finish_stack.push(__pyx_t_22); - - /* "pygeoprocessing/routing/routing.pyx":3814 - * - * # pop the finish stack until n_pushed > 1 - * if n_pushed == 0: # <<<<<<<<<<<<<< - * while (not finish_stack.empty() and - * finish_stack.top().n_pushed <= 1): - */ - __pyx_t_13 = ((__pyx_v_n_pushed == 0) != 0); - if (__pyx_t_13) { - - /* "pygeoprocessing/routing/routing.pyx":3815 - * # pop the finish stack until n_pushed > 1 - * if n_pushed == 0: - * while (not finish_stack.empty() and # <<<<<<<<<<<<<< - * finish_stack.top().n_pushed <= 1): - * finish_coordinate = finish_stack.top() - */ - while (1) { - __pyx_t_20 = ((!(__pyx_v_finish_stack.empty() != 0)) != 0); - if (__pyx_t_20) { - } else { - __pyx_t_13 = __pyx_t_20; - goto __pyx_L33_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":3816 - * if n_pushed == 0: - * while (not finish_stack.empty() and - * finish_stack.top().n_pushed <= 1): # <<<<<<<<<<<<<< - * finish_coordinate = finish_stack.top() - * finish_stack.pop() - */ - __pyx_t_20 = ((__pyx_v_finish_stack.top().n_pushed <= 1) != 0); - __pyx_t_13 = __pyx_t_20; - __pyx_L33_bool_binop_done:; - if (!__pyx_t_13) break; - - /* "pygeoprocessing/routing/routing.pyx":3817 - * while (not finish_stack.empty() and - * finish_stack.top().n_pushed <= 1): - * finish_coordinate = finish_stack.top() # <<<<<<<<<<<<<< - * finish_stack.pop() - * finish_managed_raster.set( - */ - __pyx_v_finish_coordinate = __pyx_v_finish_stack.top(); - - /* "pygeoprocessing/routing/routing.pyx":3818 - * finish_stack.top().n_pushed <= 1): - * finish_coordinate = finish_stack.top() - * finish_stack.pop() # <<<<<<<<<<<<<< - * finish_managed_raster.set( - * finish_coordinate.xi, finish_coordinate.yi, - */ - __pyx_v_finish_stack.pop(); - - /* "pygeoprocessing/routing/routing.pyx":3819 - * finish_coordinate = finish_stack.top() - * finish_stack.pop() - * finish_managed_raster.set( # <<<<<<<<<<<<<< - * finish_coordinate.xi, finish_coordinate.yi, - * discovery_count-1) - */ - __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_finish_managed_raster, __pyx_v_finish_coordinate.xi, __pyx_v_finish_coordinate.yi, (__pyx_v_discovery_count - 1)); - } - - /* "pygeoprocessing/routing/routing.pyx":3822 - * finish_coordinate.xi, finish_coordinate.yi, - * discovery_count-1) - * if not finish_stack.empty(): # <<<<<<<<<<<<<< - * # then take one more because one branch is done - * finish_coordinate = finish_stack.top() - */ - __pyx_t_13 = ((!(__pyx_v_finish_stack.empty() != 0)) != 0); - if (__pyx_t_13) { - - /* "pygeoprocessing/routing/routing.pyx":3824 - * if not finish_stack.empty(): - * # then take one more because one branch is done - * finish_coordinate = finish_stack.top() # <<<<<<<<<<<<<< - * finish_stack.pop() - * finish_coordinate.n_pushed -= 1 - */ - __pyx_v_finish_coordinate = __pyx_v_finish_stack.top(); - - /* "pygeoprocessing/routing/routing.pyx":3825 - * # then take one more because one branch is done - * finish_coordinate = finish_stack.top() - * finish_stack.pop() # <<<<<<<<<<<<<< - * finish_coordinate.n_pushed -= 1 - * finish_stack.push(finish_coordinate) - */ - __pyx_v_finish_stack.pop(); - - /* "pygeoprocessing/routing/routing.pyx":3826 - * finish_coordinate = finish_stack.top() - * finish_stack.pop() - * finish_coordinate.n_pushed -= 1 # <<<<<<<<<<<<<< - * finish_stack.push(finish_coordinate) - * - */ - __pyx_v_finish_coordinate.n_pushed = (__pyx_v_finish_coordinate.n_pushed - 1); - - /* "pygeoprocessing/routing/routing.pyx":3827 - * finish_stack.pop() - * finish_coordinate.n_pushed -= 1 - * finish_stack.push(finish_coordinate) # <<<<<<<<<<<<<< - * - * - */ - __pyx_v_finish_stack.push(__pyx_v_finish_coordinate); - - /* "pygeoprocessing/routing/routing.pyx":3822 - * finish_coordinate.xi, finish_coordinate.yi, - * discovery_count-1) - * if not finish_stack.empty(): # <<<<<<<<<<<<<< - * # then take one more because one branch is done - * finish_coordinate = finish_stack.top() - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3814 - * - * # pop the finish stack until n_pushed > 1 - * if n_pushed == 0: # <<<<<<<<<<<<<< - * while (not finish_stack.empty() and - * finish_stack.top().n_pushed <= 1): - */ - } - } - __pyx_L10_continue:; - } - } - - /* "pygeoprocessing/routing/routing.pyx":3749 - * cdef int n_dir, test_dir - * - * for offset_dict in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band, offset_only=True): - * # search raster block by raster block - */ - } - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3700 - * - * - * def _build_discovery_finish_rasters( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band, target_discovery_raster_path, - * target_finish_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_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_AddTraceback("pygeoprocessing.routing.routing._build_discovery_finish_rasters", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_flow_dir_info); - __Pyx_XDECREF((PyObject *)__pyx_v_flow_dir_managed_raster); - __Pyx_XDECREF((PyObject *)__pyx_v_discovery_managed_raster); - __Pyx_XDECREF((PyObject *)__pyx_v_finish_managed_raster); - __Pyx_XDECREF(__pyx_v_offset_dict); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pygeoprocessing/routing/routing.pyx":3830 - * - * - * def calculate_subwatershed_boundary( # <<<<<<<<<<<<<< - * d8_flow_dir_raster_path_band, - * strahler_stream_vector_path, target_watershed_boundary_vector_path, - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_25calculate_subwatershed_boundary(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_15pygeoprocessing_7routing_7routing_24calculate_subwatershed_boundary[] = "Calculate a linestring boundary around all subwatersheds.\n\n Subwatersheds start where the ``strahler_stream_vector`` has a junction\n starting at this highest upstream to lowest and ending at the outlet of\n a river.\n\n Args:\n d8_flow_dir_raster_path_band (tuple): raster/path band for d8 flow dir\n raster\n strahler_stream_vector_path (str): path to stream segment vector\n target_watershed_boundary_vector_path (str): path to created vector\n of linestring for watershed boundaries. Contains the fields:\n\n * \"stream_id\": this is the stream ID from the\n ``strahler_stream_vector_path`` that corresponds to this\n subwatershed.\n * \"terminated_early\": if set to 1 this watershed generation was\n terminated before it could be complete. This value should\n always be 0 unless something is wrong as a software bug\n or some degenerate case of data.\n * \"outlet_x\", \"outlet_y\": this is the x/y coordinate in raster\n space of the outlet of the watershed. It can be useful when\n determining other properties about the watershed when indexed\n with underlying raster data that created the streams in\n ``strahler_stream_vector_path``.\n\n max_steps_per_watershed (int): maximum number of steps to take when\n defining a watershed boundary. Useful if the DEM is large and\n degenerate or some other user known condition to limit long large\n polygons. Defaults to 1000000.\n outlet_at_confluence (bool): If True the outlet of subwatersheds\n starts at the confluence of streams. If False (the default)\n subwatersheds will start one pixel up from the confluence.\n\n Returns:\n None.\n "; -static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_25calculate_subwatershed_boundary = {"calculate_subwatershed_boundary", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_7routing_7routing_25calculate_subwatershed_boundary, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_7routing_7routing_24calculate_subwatershed_boundary}; -static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_25calculate_subwatershed_boundary(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_d8_flow_dir_raster_path_band = 0; - PyObject *__pyx_v_strahler_stream_vector_path = 0; - PyObject *__pyx_v_target_watershed_boundary_vector_path = 0; - PyObject *__pyx_v_max_steps_per_watershed = 0; - PyObject *__pyx_v_outlet_at_confluence = 0; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("calculate_subwatershed_boundary (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_d8_flow_dir_raster_path_band,&__pyx_n_s_strahler_stream_vector_path,&__pyx_n_s_target_watershed_boundary_vector,&__pyx_n_s_max_steps_per_watershed,&__pyx_n_s_outlet_at_confluence,0}; - PyObject* values[5] = {0,0,0,0,0}; - values[3] = ((PyObject *)__pyx_int_1000000); - - /* "pygeoprocessing/routing/routing.pyx":3834 - * strahler_stream_vector_path, target_watershed_boundary_vector_path, - * max_steps_per_watershed=1000000, - * outlet_at_confluence=False): # <<<<<<<<<<<<<< - * """Calculate a linestring boundary around all subwatersheds. - * - */ - values[4] = ((PyObject *)Py_False); - 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_d8_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_strahler_stream_vector_path)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("calculate_subwatershed_boundary", 0, 3, 5, 1); __PYX_ERR(0, 3830, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_watershed_boundary_vector)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("calculate_subwatershed_boundary", 0, 3, 5, 2); __PYX_ERR(0, 3830, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_max_steps_per_watershed); - 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_outlet_at_confluence); - if (value) { values[4] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "calculate_subwatershed_boundary") < 0)) __PYX_ERR(0, 3830, __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_d8_flow_dir_raster_path_band = values[0]; - __pyx_v_strahler_stream_vector_path = values[1]; - __pyx_v_target_watershed_boundary_vector_path = values[2]; - __pyx_v_max_steps_per_watershed = values[3]; - __pyx_v_outlet_at_confluence = values[4]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("calculate_subwatershed_boundary", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3830, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pygeoprocessing.routing.routing.calculate_subwatershed_boundary", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing_24calculate_subwatershed_boundary(__pyx_self, __pyx_v_d8_flow_dir_raster_path_band, __pyx_v_strahler_stream_vector_path, __pyx_v_target_watershed_boundary_vector_path, __pyx_v_max_steps_per_watershed, __pyx_v_outlet_at_confluence); - - /* "pygeoprocessing/routing/routing.pyx":3830 - * - * - * def calculate_subwatershed_boundary( # <<<<<<<<<<<<<< - * d8_flow_dir_raster_path_band, - * strahler_stream_vector_path, target_watershed_boundary_vector_path, - */ - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_24calculate_subwatershed_boundary(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_d8_flow_dir_raster_path_band, PyObject *__pyx_v_strahler_stream_vector_path, PyObject *__pyx_v_target_watershed_boundary_vector_path, PyObject *__pyx_v_max_steps_per_watershed, PyObject *__pyx_v_outlet_at_confluence) { - PyObject *__pyx_v_workspace_dir = NULL; - PyObject *__pyx_v_discovery_time_raster_path = NULL; - PyObject *__pyx_v_finish_time_raster_path = NULL; - struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_discovery_managed_raster = NULL; - struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_finish_managed_raster = NULL; - struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_d8_flow_dir_managed_raster = NULL; - PyObject *__pyx_v_discovery_info = NULL; - long __pyx_v_discovery_nodata; - int __pyx_v_n_cols; - int __pyx_v_n_rows; - PyObject *__pyx_v_geotransform = NULL; - double __pyx_v_g0; - double __pyx_v_g1; - double __pyx_v_g2; - double __pyx_v_g3; - double __pyx_v_g4; - double __pyx_v_g5; - PyObject *__pyx_v_discovery_srs = NULL; - PyObject *__pyx_v_gpkg_driver = NULL; - PyObject *__pyx_v_watershed_vector = NULL; - PyObject *__pyx_v_watershed_basename = NULL; - PyObject *__pyx_v_watershed_layer = NULL; - int __pyx_v_x_l; - int __pyx_v_y_l; - int __pyx_v_outflow_dir; - double __pyx_v_x_f; - double __pyx_v_y_f; - double __pyx_v_x_p; - double __pyx_v_y_p; - long __pyx_v_discovery; - long __pyx_v_finish; - time_t __pyx_v_last_log_time; - PyObject *__pyx_v_stream_vector = NULL; - PyObject *__pyx_v_stream_layer = NULL; - PyObject *__pyx_v_upstream_fid_map = NULL; - PyObject *__pyx_v_stream_feature = NULL; - PyObject *__pyx_v_ds_x = NULL; - PyObject *__pyx_v_ds_y = NULL; - PyObject *__pyx_v_visit_order_stack = NULL; - CYTHON_UNUSED PyObject *__pyx_v__ = NULL; - PyObject *__pyx_v_outlet_fid = NULL; - PyObject *__pyx_v_working_stack = NULL; - PyObject *__pyx_v_processed_nodes = NULL; - PyObject *__pyx_v_working_fid = NULL; - PyObject *__pyx_v_working_feature = NULL; - PyObject *__pyx_v_us_x = NULL; - PyObject *__pyx_v_us_y = NULL; - PyObject *__pyx_v_ds_x_1 = NULL; - PyObject *__pyx_v_ds_y_1 = NULL; - PyObject *__pyx_v_upstream_coord = NULL; - PyObject *__pyx_v_upstream_fids = NULL; - int __pyx_v_edge_side; - int __pyx_v_edge_dir; - int __pyx_v_cell_to_test; - int __pyx_v_out_dir_increase; - int __pyx_v_left; - int __pyx_v_right; - int __pyx_v_n_steps; - int __pyx_v_terminated_early; - int __pyx_v_delta_x; - int __pyx_v_delta_y; - int __pyx_v__int_max_steps_per_watershed; - PyObject *__pyx_v_index = NULL; - PyObject *__pyx_v_stream_fid = NULL; - PyObject *__pyx_v_boundary_list = NULL; - int __pyx_v_outlet_x; - int __pyx_v_outlet_y; - PyObject *__pyx_v_watershed_boundary = NULL; - int __pyx_v_left_in; - int __pyx_v_right_in; - int __pyx_v_out_dir; - PyObject *__pyx_v_watershed_feature = NULL; - PyObject *__pyx_v_watershed_polygon = NULL; - PyObject *__pyx_v_boundary_x = NULL; - PyObject *__pyx_v_boundary_y = NULL; - PyObject *__pyx_8genexpr2__pyx_v_x = NULL; - PyObject *__pyx_8genexpr3__pyx_v_fid = NULL; - 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; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - int __pyx_t_8; - long __pyx_t_9; - PyObject *(*__pyx_t_10)(PyObject *); - int __pyx_t_11; - double __pyx_t_12; - double __pyx_t_13; - double __pyx_t_14; - double __pyx_t_15; - double __pyx_t_16; - double __pyx_t_17; - int __pyx_t_18; - Py_ssize_t __pyx_t_19; - PyObject *(*__pyx_t_20)(PyObject *); - int __pyx_t_21; - Py_ssize_t __pyx_t_22; - PyObject *(*__pyx_t_23)(PyObject *); - int __pyx_t_24; - int __pyx_t_25; - Py_UCS4 __pyx_t_26; - Py_ssize_t __pyx_t_27; - PyObject *__pyx_t_28 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("calculate_subwatershed_boundary", 0); - - /* "pygeoprocessing/routing/routing.pyx":3872 - * None. - * """ - * workspace_dir = tempfile.mkdtemp( # <<<<<<<<<<<<<< - * prefix='calculate_subwatershed_boundary_workspace_', - * dir=os.path.join( - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_tempfile); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3872, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_mkdtemp); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3872, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3873 - * """ - * workspace_dir = tempfile.mkdtemp( - * prefix='calculate_subwatershed_boundary_workspace_', # <<<<<<<<<<<<<< - * dir=os.path.join( - * os.path.dirname(target_watershed_boundary_vector_path))) - */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3873, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_prefix, __pyx_n_u_calculate_subwatershed_boundary) < 0) __PYX_ERR(0, 3873, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3874 - * workspace_dir = tempfile.mkdtemp( - * prefix='calculate_subwatershed_boundary_workspace_', - * dir=os.path.join( # <<<<<<<<<<<<<< - * os.path.dirname(target_watershed_boundary_vector_path))) - * discovery_time_raster_path = os.path.join(workspace_dir, 'discovery.tif') - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_os); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3874, __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, 3874, __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, 3874, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3875 - * prefix='calculate_subwatershed_boundary_workspace_', - * dir=os.path.join( - * os.path.dirname(target_watershed_boundary_vector_path))) # <<<<<<<<<<<<<< - * discovery_time_raster_path = os.path.join(workspace_dir, 'discovery.tif') - * finish_time_raster_path = os.path.join(workspace_dir, 'finish.tif') - */ - __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_os); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3875, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_path); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3875, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_dirname); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3875, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_5 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_7, __pyx_v_target_watershed_boundary_vector_path) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_target_watershed_boundary_vector_path); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3875, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3874, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dir, __pyx_t_3) < 0) __PYX_ERR(0, 3873, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3872 - * None. - * """ - * workspace_dir = tempfile.mkdtemp( # <<<<<<<<<<<<<< - * prefix='calculate_subwatershed_boundary_workspace_', - * dir=os.path.join( - */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3872, __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_v_workspace_dir = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3876 - * dir=os.path.join( - * os.path.dirname(target_watershed_boundary_vector_path))) - * discovery_time_raster_path = os.path.join(workspace_dir, 'discovery.tif') # <<<<<<<<<<<<<< - * finish_time_raster_path = os.path.join(workspace_dir, 'finish.tif') - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3876, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_path); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3876, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_join); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3876, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - __pyx_t_8 = 0; - if (CYTHON_UNPACK_METHODS && likely(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_8 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_workspace_dir, __pyx_kp_u_discovery_tif}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3876, __pyx_L1_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[3] = {__pyx_t_2, __pyx_v_workspace_dir, __pyx_kp_u_discovery_tif}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3876, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - { - __pyx_t_4 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3876, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (__pyx_t_2) { - __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __pyx_t_2 = NULL; - } - __Pyx_INCREF(__pyx_v_workspace_dir); - __Pyx_GIVEREF(__pyx_v_workspace_dir); - PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_8, __pyx_v_workspace_dir); - __Pyx_INCREF(__pyx_kp_u_discovery_tif); - __Pyx_GIVEREF(__pyx_kp_u_discovery_tif); - PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_8, __pyx_kp_u_discovery_tif); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3876, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_discovery_time_raster_path = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3877 - * os.path.dirname(target_watershed_boundary_vector_path))) - * discovery_time_raster_path = os.path.join(workspace_dir, 'discovery.tif') - * finish_time_raster_path = os.path.join(workspace_dir, 'finish.tif') # <<<<<<<<<<<<<< - * - * # construct the discovery/finish time rasters for fast individual cell - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3877, __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, 3877, __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, 3877, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = NULL; - __pyx_t_8 = 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_8 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_workspace_dir, __pyx_kp_u_finish_tif}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3877, __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_workspace_dir, __pyx_kp_u_finish_tif}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3877, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - { - __pyx_t_2 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3877, __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_INCREF(__pyx_v_workspace_dir); - __Pyx_GIVEREF(__pyx_v_workspace_dir); - PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_8, __pyx_v_workspace_dir); - __Pyx_INCREF(__pyx_kp_u_finish_tif); - __Pyx_GIVEREF(__pyx_kp_u_finish_tif); - PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_8, __pyx_kp_u_finish_tif); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3877, __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_v_finish_time_raster_path = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3881 - * # construct the discovery/finish time rasters for fast individual cell - * # watershed detection - * _build_discovery_finish_rasters( # <<<<<<<<<<<<<< - * d8_flow_dir_raster_path_band, discovery_time_raster_path, - * finish_time_raster_path) - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_build_discovery_finish_rasters); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3881, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":3883 - * _build_discovery_finish_rasters( - * d8_flow_dir_raster_path_band, discovery_time_raster_path, - * finish_time_raster_path) # <<<<<<<<<<<<<< - * - * shutil.copyfile( - */ - __pyx_t_2 = NULL; - __pyx_t_8 = 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_8 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_v_d8_flow_dir_raster_path_band, __pyx_v_discovery_time_raster_path, __pyx_v_finish_time_raster_path}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3881, __pyx_L1_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[4] = {__pyx_t_2, __pyx_v_d8_flow_dir_raster_path_band, __pyx_v_discovery_time_raster_path, __pyx_v_finish_time_raster_path}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3881, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - { - __pyx_t_4 = PyTuple_New(3+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3881, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (__pyx_t_2) { - __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __pyx_t_2 = NULL; - } - __Pyx_INCREF(__pyx_v_d8_flow_dir_raster_path_band); - __Pyx_GIVEREF(__pyx_v_d8_flow_dir_raster_path_band); - PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_8, __pyx_v_d8_flow_dir_raster_path_band); - __Pyx_INCREF(__pyx_v_discovery_time_raster_path); - __Pyx_GIVEREF(__pyx_v_discovery_time_raster_path); - PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_8, __pyx_v_discovery_time_raster_path); - __Pyx_INCREF(__pyx_v_finish_time_raster_path); - __Pyx_GIVEREF(__pyx_v_finish_time_raster_path); - PyTuple_SET_ITEM(__pyx_t_4, 2+__pyx_t_8, __pyx_v_finish_time_raster_path); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3881, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __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; - - /* "pygeoprocessing/routing/routing.pyx":3885 - * finish_time_raster_path) - * - * shutil.copyfile( # <<<<<<<<<<<<<< - * discovery_time_raster_path, f'{discovery_time_raster_path}_bak.tif') - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_shutil); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3885, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_copyfile); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3885, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3886 - * - * shutil.copyfile( - * discovery_time_raster_path, f'{discovery_time_raster_path}_bak.tif') # <<<<<<<<<<<<<< - * - * # the discovery raster is filled with nodata around the edges of - */ - __pyx_t_1 = __Pyx_PyObject_FormatSimple(__pyx_v_discovery_time_raster_path, __pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3886, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyUnicode_Concat(__pyx_t_1, __pyx_kp_u_bak_tif); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3886, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - __pyx_t_8 = 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_8 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_discovery_time_raster_path, __pyx_t_2}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3885, __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; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_discovery_time_raster_path, __pyx_t_2}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3885, __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; - } else - #endif - { - __pyx_t_5 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3885, __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_discovery_time_raster_path); - __Pyx_GIVEREF(__pyx_v_discovery_time_raster_path); - PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_8, __pyx_v_discovery_time_raster_path); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_8, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3885, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3890 - * # the discovery raster is filled with nodata around the edges of - * # discovered watersheds, so it is opened for writing - * discovery_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< - * discovery_time_raster_path, 1, 1) - * finish_managed_raster = _ManagedRaster(finish_time_raster_path, 1, 0) - */ - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3890, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_discovery_time_raster_path); - __Pyx_GIVEREF(__pyx_v_discovery_time_raster_path); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_discovery_time_raster_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_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3890, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_discovery_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_4); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3892 - * discovery_managed_raster = _ManagedRaster( - * discovery_time_raster_path, 1, 1) - * finish_managed_raster = _ManagedRaster(finish_time_raster_path, 1, 0) # <<<<<<<<<<<<<< - * d8_flow_dir_managed_raster = _ManagedRaster( - * d8_flow_dir_raster_path_band[0], d8_flow_dir_raster_path_band[1], 0) - */ - __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3892, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_v_finish_time_raster_path); - __Pyx_GIVEREF(__pyx_v_finish_time_raster_path); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_finish_time_raster_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_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_int_0); - __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3892, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_finish_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3894 - * finish_managed_raster = _ManagedRaster(finish_time_raster_path, 1, 0) - * d8_flow_dir_managed_raster = _ManagedRaster( - * d8_flow_dir_raster_path_band[0], d8_flow_dir_raster_path_band[1], 0) # <<<<<<<<<<<<<< - * - * discovery_info = pygeoprocessing.get_raster_info( - */ - __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_d8_flow_dir_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3894, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_d8_flow_dir_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3894, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - - /* "pygeoprocessing/routing/routing.pyx":3893 - * discovery_time_raster_path, 1, 1) - * finish_managed_raster = _ManagedRaster(finish_time_raster_path, 1, 0) - * d8_flow_dir_managed_raster = _ManagedRaster( # <<<<<<<<<<<<<< - * d8_flow_dir_raster_path_band[0], d8_flow_dir_raster_path_band[1], 0) - * - */ - __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3893, __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_4); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_int_0); - __pyx_t_3 = 0; - __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3893, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_d8_flow_dir_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_4); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3896 - * d8_flow_dir_raster_path_band[0], d8_flow_dir_raster_path_band[1], 0) - * - * discovery_info = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< - * discovery_time_raster_path) - * cdef long discovery_nodata = discovery_info['nodata'][0] - */ - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3896, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3896, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3897 - * - * discovery_info = pygeoprocessing.get_raster_info( - * discovery_time_raster_path) # <<<<<<<<<<<<<< - * cdef long discovery_nodata = discovery_info['nodata'][0] - * - */ - __pyx_t_5 = NULL; - 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_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_v_discovery_time_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_discovery_time_raster_path); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3896, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_discovery_info = __pyx_t_4; - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3898 - * discovery_info = pygeoprocessing.get_raster_info( - * discovery_time_raster_path) - * cdef long discovery_nodata = discovery_info['nodata'][0] # <<<<<<<<<<<<<< - * - * cdef int n_cols, n_rows - */ - __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_discovery_info, __pyx_n_u_nodata); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3898, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_4, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3898, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_9 = __Pyx_PyInt_As_long(__pyx_t_3); if (unlikely((__pyx_t_9 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 3898, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_discovery_nodata = __pyx_t_9; - - /* "pygeoprocessing/routing/routing.pyx":3901 - * - * cdef int n_cols, n_rows - * n_cols, n_rows = discovery_info['raster_size'] # <<<<<<<<<<<<<< - * - * geotransform = discovery_info['geotransform'] - */ - __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_discovery_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3901, __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, 3901, __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_5 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_4 = PyList_GET_ITEM(sequence, 0); - __pyx_t_5 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_5); - #else - __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3901, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3901, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3901, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_10 = Py_TYPE(__pyx_t_2)->tp_iternext; - index = 0; __pyx_t_4 = __pyx_t_10(__pyx_t_2); if (unlikely(!__pyx_t_4)) goto __pyx_L3_unpacking_failed; - __Pyx_GOTREF(__pyx_t_4); - index = 1; __pyx_t_5 = __pyx_t_10(__pyx_t_2); if (unlikely(!__pyx_t_5)) goto __pyx_L3_unpacking_failed; - __Pyx_GOTREF(__pyx_t_5); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_2), 2) < 0) __PYX_ERR(0, 3901, __pyx_L1_error) - __pyx_t_10 = NULL; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L4_unpacking_done; - __pyx_L3_unpacking_failed:; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_10 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 3901, __pyx_L1_error) - __pyx_L4_unpacking_done:; - } - __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3901, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3901, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_n_cols = __pyx_t_8; - __pyx_v_n_rows = __pyx_t_11; - - /* "pygeoprocessing/routing/routing.pyx":3903 - * n_cols, n_rows = discovery_info['raster_size'] - * - * geotransform = discovery_info['geotransform'] # <<<<<<<<<<<<<< - * cdef double g0, g1, g2, g3, g4, g5 - * g0, g1, g2, g3, g4, g5 = geotransform - */ - __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_discovery_info, __pyx_n_u_geotransform); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3903, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_geotransform = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3905 - * geotransform = discovery_info['geotransform'] - * cdef double g0, g1, g2, g3, g4, g5 - * g0, g1, g2, g3, g4, g5 = geotransform # <<<<<<<<<<<<<< - * - * if discovery_info['projection_wkt']: - */ - if ((likely(PyTuple_CheckExact(__pyx_v_geotransform))) || (PyList_CheckExact(__pyx_v_geotransform))) { - PyObject* sequence = __pyx_v_geotransform; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 6)) { - if (size > 6) __Pyx_RaiseTooManyValuesError(6); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 3905, __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_5 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_4 = PyTuple_GET_ITEM(sequence, 2); - __pyx_t_2 = PyTuple_GET_ITEM(sequence, 3); - __pyx_t_1 = PyTuple_GET_ITEM(sequence, 4); - __pyx_t_6 = PyTuple_GET_ITEM(sequence, 5); - } else { - __pyx_t_3 = PyList_GET_ITEM(sequence, 0); - __pyx_t_5 = PyList_GET_ITEM(sequence, 1); - __pyx_t_4 = PyList_GET_ITEM(sequence, 2); - __pyx_t_2 = PyList_GET_ITEM(sequence, 3); - __pyx_t_1 = PyList_GET_ITEM(sequence, 4); - __pyx_t_6 = PyList_GET_ITEM(sequence, 5); - } - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_6); - #else - { - Py_ssize_t i; - PyObject** temps[6] = {&__pyx_t_3,&__pyx_t_5,&__pyx_t_4,&__pyx_t_2,&__pyx_t_1,&__pyx_t_6}; - for (i=0; i < 6; i++) { - PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 3905, __pyx_L1_error) - __Pyx_GOTREF(item); - *(temps[i]) = item; - } - } - #endif - } else { - Py_ssize_t index = -1; - PyObject** temps[6] = {&__pyx_t_3,&__pyx_t_5,&__pyx_t_4,&__pyx_t_2,&__pyx_t_1,&__pyx_t_6}; - __pyx_t_7 = PyObject_GetIter(__pyx_v_geotransform); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3905, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_10 = Py_TYPE(__pyx_t_7)->tp_iternext; - for (index=0; index < 6; index++) { - PyObject* item = __pyx_t_10(__pyx_t_7); if (unlikely(!item)) goto __pyx_L5_unpacking_failed; - __Pyx_GOTREF(item); - *(temps[index]) = item; - } - if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_7), 6) < 0) __PYX_ERR(0, 3905, __pyx_L1_error) - __pyx_t_10 = NULL; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L6_unpacking_done; - __pyx_L5_unpacking_failed:; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_10 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 3905, __pyx_L1_error) - __pyx_L6_unpacking_done:; - } - __pyx_t_12 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_12 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 3905, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_13 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_13 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 3905, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_14 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_14 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 3905, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_15 = __pyx_PyFloat_AsDouble(__pyx_t_2); if (unlikely((__pyx_t_15 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 3905, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_16 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_16 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 3905, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_17 = __pyx_PyFloat_AsDouble(__pyx_t_6); if (unlikely((__pyx_t_17 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 3905, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_g0 = __pyx_t_12; - __pyx_v_g1 = __pyx_t_13; - __pyx_v_g2 = __pyx_t_14; - __pyx_v_g3 = __pyx_t_15; - __pyx_v_g4 = __pyx_t_16; - __pyx_v_g5 = __pyx_t_17; - - /* "pygeoprocessing/routing/routing.pyx":3907 - * g0, g1, g2, g3, g4, g5 = geotransform - * - * if discovery_info['projection_wkt']: # <<<<<<<<<<<<<< - * discovery_srs = osr.SpatialReference() - * discovery_srs.ImportFromWkt(discovery_info['projection_wkt']) - */ - __pyx_t_6 = __Pyx_PyObject_Dict_GetItem(__pyx_v_discovery_info, __pyx_n_u_projection_wkt); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3907, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_18 < 0)) __PYX_ERR(0, 3907, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (__pyx_t_18) { - - /* "pygeoprocessing/routing/routing.pyx":3908 - * - * if discovery_info['projection_wkt']: - * discovery_srs = osr.SpatialReference() # <<<<<<<<<<<<<< - * discovery_srs.ImportFromWkt(discovery_info['projection_wkt']) - * else: - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_osr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3908, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_SpatialReference); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3908, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_6 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3908, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_discovery_srs = __pyx_t_6; - __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3909 - * if discovery_info['projection_wkt']: - * discovery_srs = osr.SpatialReference() - * discovery_srs.ImportFromWkt(discovery_info['projection_wkt']) # <<<<<<<<<<<<<< - * else: - * discovery_srs = None - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_discovery_srs, __pyx_n_s_ImportFromWkt); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3909, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_discovery_info, __pyx_n_u_projection_wkt); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3909, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_6 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3909, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3907 - * g0, g1, g2, g3, g4, g5 = geotransform - * - * if discovery_info['projection_wkt']: # <<<<<<<<<<<<<< - * discovery_srs = osr.SpatialReference() - * discovery_srs.ImportFromWkt(discovery_info['projection_wkt']) - */ - goto __pyx_L7; - } - - /* "pygeoprocessing/routing/routing.pyx":3911 - * discovery_srs.ImportFromWkt(discovery_info['projection_wkt']) - * else: - * discovery_srs = None # <<<<<<<<<<<<<< - * gpkg_driver = gdal.GetDriverByName('GPKG') - * - */ - /*else*/ { - __Pyx_INCREF(Py_None); - __pyx_v_discovery_srs = Py_None; - } - __pyx_L7:; - - /* "pygeoprocessing/routing/routing.pyx":3912 - * else: - * discovery_srs = None - * gpkg_driver = gdal.GetDriverByName('GPKG') # <<<<<<<<<<<<<< - * - * if os.path.exists(target_watershed_boundary_vector_path): - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3912, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_GetDriverByName); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3912, __pyx_L1_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); - } - } - __pyx_t_6 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_n_u_GPKG) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_n_u_GPKG); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3912, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_gpkg_driver = __pyx_t_6; - __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3914 - * gpkg_driver = gdal.GetDriverByName('GPKG') - * - * if os.path.exists(target_watershed_boundary_vector_path): # <<<<<<<<<<<<<< - * LOGGER.warning( - * f'{target_watershed_boundary_vector_path} exists, removing ' - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3914, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_path); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3914, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_exists); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3914, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_6 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_v_target_watershed_boundary_vector_path) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_target_watershed_boundary_vector_path); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3914, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_18 < 0)) __PYX_ERR(0, 3914, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (__pyx_t_18) { - - /* "pygeoprocessing/routing/routing.pyx":3915 - * - * if os.path.exists(target_watershed_boundary_vector_path): - * LOGGER.warning( # <<<<<<<<<<<<<< - * f'{target_watershed_boundary_vector_path} exists, removing ' - * 'before creating a new one.') - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3915, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_warning); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3915, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3916 - * if os.path.exists(target_watershed_boundary_vector_path): - * LOGGER.warning( - * f'{target_watershed_boundary_vector_path} exists, removing ' # <<<<<<<<<<<<<< - * 'before creating a new one.') - * os.remove(target_watershed_boundary_vector_path) - */ - __pyx_t_1 = __Pyx_PyObject_FormatSimple(__pyx_v_target_watershed_boundary_vector_path, __pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3916, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyUnicode_Concat(__pyx_t_1, __pyx_kp_u_exists_removing_before_creating); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3916, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_6 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_1, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3915, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3918 - * f'{target_watershed_boundary_vector_path} exists, removing ' - * 'before creating a new one.') - * os.remove(target_watershed_boundary_vector_path) # <<<<<<<<<<<<<< - * watershed_vector = gpkg_driver.Create( - * target_watershed_boundary_vector_path, 0, 0, 0, gdal.GDT_Unknown) - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3918, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_remove); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3918, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - 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_6 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_2, __pyx_v_target_watershed_boundary_vector_path) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_target_watershed_boundary_vector_path); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3918, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3914 - * gpkg_driver = gdal.GetDriverByName('GPKG') - * - * if os.path.exists(target_watershed_boundary_vector_path): # <<<<<<<<<<<<<< - * LOGGER.warning( - * f'{target_watershed_boundary_vector_path} exists, removing ' - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3919 - * 'before creating a new one.') - * os.remove(target_watershed_boundary_vector_path) - * watershed_vector = gpkg_driver.Create( # <<<<<<<<<<<<<< - * target_watershed_boundary_vector_path, 0, 0, 0, gdal.GDT_Unknown) - * watershed_basename = os.path.basename(os.path.splitext( - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_gpkg_driver, __pyx_n_s_Create); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3919, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - - /* "pygeoprocessing/routing/routing.pyx":3920 - * os.remove(target_watershed_boundary_vector_path) - * watershed_vector = gpkg_driver.Create( - * target_watershed_boundary_vector_path, 0, 0, 0, gdal.GDT_Unknown) # <<<<<<<<<<<<<< - * watershed_basename = os.path.basename(os.path.splitext( - * target_watershed_boundary_vector_path)[0]) - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3920, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_GDT_Unknown); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3920, __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 && likely(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_11 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[6] = {__pyx_t_2, __pyx_v_target_watershed_boundary_vector_path, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_t_1}; - __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 5+__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3919, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_6); - __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[6] = {__pyx_t_2, __pyx_v_target_watershed_boundary_vector_path, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_t_1}; - __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 5+__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3919, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - { - __pyx_t_5 = PyTuple_New(5+__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3919, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (__pyx_t_2) { - __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __pyx_t_2 = NULL; - } - __Pyx_INCREF(__pyx_v_target_watershed_boundary_vector_path); - __Pyx_GIVEREF(__pyx_v_target_watershed_boundary_vector_path); - PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_11, __pyx_v_target_watershed_boundary_vector_path); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_11, __pyx_int_0); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_11, __pyx_int_0); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_5, 3+__pyx_t_11, __pyx_int_0); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_5, 4+__pyx_t_11, __pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3919, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_watershed_vector = __pyx_t_6; - __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3921 - * watershed_vector = gpkg_driver.Create( - * target_watershed_boundary_vector_path, 0, 0, 0, gdal.GDT_Unknown) - * watershed_basename = os.path.basename(os.path.splitext( # <<<<<<<<<<<<<< - * target_watershed_boundary_vector_path)[0]) - * watershed_layer = watershed_vector.CreateLayer( - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_os); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3921, __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, 3921, __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_basename); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3921, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3921, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_path); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3921, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_splitext); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3921, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3922 - * target_watershed_boundary_vector_path, 0, 0, 0, gdal.GDT_Unknown) - * watershed_basename = os.path.basename(os.path.splitext( - * target_watershed_boundary_vector_path)[0]) # <<<<<<<<<<<<<< - * watershed_layer = watershed_vector.CreateLayer( - * watershed_basename, discovery_srs, ogr.wkbPolygon) - */ - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_5 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_v_target_watershed_boundary_vector_path) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_target_watershed_boundary_vector_path); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3921, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_5, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3922, __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 && 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_6 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_1); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3921, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_watershed_basename = __pyx_t_6; - __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3923 - * watershed_basename = os.path.basename(os.path.splitext( - * target_watershed_boundary_vector_path)[0]) - * watershed_layer = watershed_vector.CreateLayer( # <<<<<<<<<<<<<< - * watershed_basename, discovery_srs, ogr.wkbPolygon) - * watershed_layer.CreateField(ogr.FieldDefn('stream_fid', ogr.OFTInteger)) - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_vector, __pyx_n_s_CreateLayer); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3923, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - - /* "pygeoprocessing/routing/routing.pyx":3924 - * target_watershed_boundary_vector_path)[0]) - * watershed_layer = watershed_vector.CreateLayer( - * watershed_basename, discovery_srs, ogr.wkbPolygon) # <<<<<<<<<<<<<< - * watershed_layer.CreateField(ogr.FieldDefn('stream_fid', ogr.OFTInteger)) - * watershed_layer.CreateField( - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3924, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_wkbPolygon); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3924, __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 && likely(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[4] = {__pyx_t_1, __pyx_v_watershed_basename, __pyx_v_discovery_srs, __pyx_t_5}; - __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 3+__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3923, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 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_4)) { - PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_v_watershed_basename, __pyx_v_discovery_srs, __pyx_t_5}; - __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 3+__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3923, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - { - __pyx_t_2 = PyTuple_New(3+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3923, __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_v_watershed_basename); - __Pyx_GIVEREF(__pyx_v_watershed_basename); - PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_11, __pyx_v_watershed_basename); - __Pyx_INCREF(__pyx_v_discovery_srs); - __Pyx_GIVEREF(__pyx_v_discovery_srs); - PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_11, __pyx_v_discovery_srs); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_2, 2+__pyx_t_11, __pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3923, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_watershed_layer = __pyx_t_6; - __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3925 - * watershed_layer = watershed_vector.CreateLayer( - * watershed_basename, discovery_srs, ogr.wkbPolygon) - * watershed_layer.CreateField(ogr.FieldDefn('stream_fid', ogr.OFTInteger)) # <<<<<<<<<<<<<< - * watershed_layer.CreateField( - * ogr.FieldDefn('terminated_early', ogr.OFTInteger)) - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3925, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_ogr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3925, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3925, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_ogr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3925, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3925, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = NULL; - __pyx_t_11 = 0; - 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); - __pyx_t_11 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_n_u_stream_fid, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3925, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_2); - __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[3] = {__pyx_t_5, __pyx_n_u_stream_fid, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3925, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3925, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_5) { - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL; - } - __Pyx_INCREF(__pyx_n_u_stream_fid); - __Pyx_GIVEREF(__pyx_n_u_stream_fid); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_11, __pyx_n_u_stream_fid); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_11, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3925, __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_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_6 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3925, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3926 - * watershed_basename, discovery_srs, ogr.wkbPolygon) - * watershed_layer.CreateField(ogr.FieldDefn('stream_fid', ogr.OFTInteger)) - * watershed_layer.CreateField( # <<<<<<<<<<<<<< - * ogr.FieldDefn('terminated_early', ogr.OFTInteger)) - * watershed_layer.CreateField(ogr.FieldDefn('outlet_x', ogr.OFTInteger)) - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3926, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - - /* "pygeoprocessing/routing/routing.pyx":3927 - * watershed_layer.CreateField(ogr.FieldDefn('stream_fid', ogr.OFTInteger)) - * watershed_layer.CreateField( - * ogr.FieldDefn('terminated_early', ogr.OFTInteger)) # <<<<<<<<<<<<<< - * watershed_layer.CreateField(ogr.FieldDefn('outlet_x', ogr.OFTInteger)) - * watershed_layer.CreateField(ogr.FieldDefn('outlet_y', ogr.OFTInteger)) - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3927, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3927, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3927, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3927, __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 && unlikely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - __pyx_t_11 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_n_u_terminated_early, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3927, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_n_u_terminated_early, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3927, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - { - __pyx_t_5 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3927, __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_n_u_terminated_early); - __Pyx_GIVEREF(__pyx_n_u_terminated_early); - PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_11, __pyx_n_u_terminated_early); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_11, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3927, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - __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); - } - } - __pyx_t_6 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_7, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3926, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3928 - * watershed_layer.CreateField( - * ogr.FieldDefn('terminated_early', ogr.OFTInteger)) - * watershed_layer.CreateField(ogr.FieldDefn('outlet_x', ogr.OFTInteger)) # <<<<<<<<<<<<<< - * watershed_layer.CreateField(ogr.FieldDefn('outlet_y', ogr.OFTInteger)) - * watershed_layer.StartTransaction() - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3928, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3928, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3928, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3928, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3928, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - __pyx_t_11 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_7); - __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_7, __pyx_n_u_outlet_x, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3928, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_2); - __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_7, __pyx_n_u_outlet_x, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3928, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_2); - __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, 3928, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (__pyx_t_7) { - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7); __pyx_t_7 = NULL; - } - __Pyx_INCREF(__pyx_n_u_outlet_x); - __Pyx_GIVEREF(__pyx_n_u_outlet_x); - PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_11, __pyx_n_u_outlet_x); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_11, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3928, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = NULL; - 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_6 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3928, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3929 - * ogr.FieldDefn('terminated_early', ogr.OFTInteger)) - * watershed_layer.CreateField(ogr.FieldDefn('outlet_x', ogr.OFTInteger)) - * watershed_layer.CreateField(ogr.FieldDefn('outlet_y', ogr.OFTInteger)) # <<<<<<<<<<<<<< - * watershed_layer.StartTransaction() - * - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3929, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_ogr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3929, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3929, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_ogr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3929, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3929, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = NULL; - __pyx_t_11 = 0; - 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); - __pyx_t_11 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_n_u_outlet_y, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3929, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_2); - __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[3] = {__pyx_t_5, __pyx_n_u_outlet_y, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3929, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3929, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_5) { - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL; - } - __Pyx_INCREF(__pyx_n_u_outlet_y); - __Pyx_GIVEREF(__pyx_n_u_outlet_y); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_11, __pyx_n_u_outlet_y); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_11, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3929, __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_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_6 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3929, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3930 - * watershed_layer.CreateField(ogr.FieldDefn('outlet_x', ogr.OFTInteger)) - * watershed_layer.CreateField(ogr.FieldDefn('outlet_y', ogr.OFTInteger)) - * watershed_layer.StartTransaction() # <<<<<<<<<<<<<< - * - * cdef int x_l, y_l, outflow_dir - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_layer, __pyx_n_s_StartTransaction); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3930, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_6 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3930, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3937 - * cdef long discovery, finish - * - * cdef time_t last_log_time = ctime(NULL) # <<<<<<<<<<<<<< - * - * stream_vector = gdal.OpenEx(strahler_stream_vector_path, gdal.OF_VECTOR) - */ - __pyx_v_last_log_time = time(NULL); - - /* "pygeoprocessing/routing/routing.pyx":3939 - * cdef time_t last_log_time = ctime(NULL) - * - * stream_vector = gdal.OpenEx(strahler_stream_vector_path, gdal.OF_VECTOR) # <<<<<<<<<<<<<< - * stream_layer = stream_vector.GetLayer() - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3939, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3939, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3939, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OF_VECTOR); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3939, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __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_2))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - __pyx_t_11 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_strahler_stream_vector_path, __pyx_t_1}; - __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3939, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_strahler_stream_vector_path, __pyx_t_1}; - __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3939, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3939, __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_strahler_stream_vector_path); - __Pyx_GIVEREF(__pyx_v_strahler_stream_vector_path); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_11, __pyx_v_strahler_stream_vector_path); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_11, __pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_7, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3939, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_stream_vector = __pyx_t_6; - __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3940 - * - * stream_vector = gdal.OpenEx(strahler_stream_vector_path, gdal.OF_VECTOR) - * stream_layer = stream_vector.GetLayer() # <<<<<<<<<<<<<< - * - * # construct linkage data structure for upstream streams - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_vector, __pyx_n_s_GetLayer); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3940, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_6 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3940, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_stream_layer = __pyx_t_6; - __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3943 - * - * # construct linkage data structure for upstream streams - * upstream_fid_map = collections.defaultdict(list) # <<<<<<<<<<<<<< - * for stream_feature in stream_layer: - * ds_x = int(stream_feature.GetField('ds_x')) - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_collections); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3943, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3943, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - 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_6 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_2, ((PyObject *)(&PyList_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_7, ((PyObject *)(&PyList_Type))); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3943, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_upstream_fid_map = __pyx_t_6; - __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3944 - * # construct linkage data structure for upstream streams - * upstream_fid_map = collections.defaultdict(list) - * for stream_feature in stream_layer: # <<<<<<<<<<<<<< - * ds_x = int(stream_feature.GetField('ds_x')) - * ds_y = int(stream_feature.GetField('ds_y')) - */ - if (likely(PyList_CheckExact(__pyx_v_stream_layer)) || PyTuple_CheckExact(__pyx_v_stream_layer)) { - __pyx_t_6 = __pyx_v_stream_layer; __Pyx_INCREF(__pyx_t_6); __pyx_t_19 = 0; - __pyx_t_20 = NULL; - } else { - __pyx_t_19 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_v_stream_layer); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3944, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_20 = Py_TYPE(__pyx_t_6)->tp_iternext; if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 3944, __pyx_L1_error) - } - for (;;) { - if (likely(!__pyx_t_20)) { - if (likely(PyList_CheckExact(__pyx_t_6))) { - if (__pyx_t_19 >= PyList_GET_SIZE(__pyx_t_6)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_19); __Pyx_INCREF(__pyx_t_7); __pyx_t_19++; if (unlikely(0 < 0)) __PYX_ERR(0, 3944, __pyx_L1_error) - #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_6, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3944, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - #endif - } else { - if (__pyx_t_19 >= PyTuple_GET_SIZE(__pyx_t_6)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_19); __Pyx_INCREF(__pyx_t_7); __pyx_t_19++; if (unlikely(0 < 0)) __PYX_ERR(0, 3944, __pyx_L1_error) - #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_6, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3944, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - #endif - } - } else { - __pyx_t_7 = __pyx_t_20(__pyx_t_6); - if (unlikely(!__pyx_t_7)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 3944, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_7); - } - __Pyx_XDECREF_SET(__pyx_v_stream_feature, __pyx_t_7); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3945 - * upstream_fid_map = collections.defaultdict(list) - * for stream_feature in stream_layer: - * ds_x = int(stream_feature.GetField('ds_x')) # <<<<<<<<<<<<<< - * ds_y = int(stream_feature.GetField('ds_y')) - * upstream_fid_map[(ds_x, ds_y)].append( - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3945, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_7 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_1, __pyx_n_u_ds_x) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_n_u_ds_x); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3945, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyNumber_Int(__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3945, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF_SET(__pyx_v_ds_x, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3946 - * for stream_feature in stream_layer: - * ds_x = int(stream_feature.GetField('ds_x')) - * ds_y = int(stream_feature.GetField('ds_y')) # <<<<<<<<<<<<<< - * upstream_fid_map[(ds_x, ds_y)].append( - * stream_feature.GetFID()) - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3946, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_2 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_1, __pyx_n_u_ds_y) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_n_u_ds_y); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3946, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyNumber_Int(__pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3946, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF_SET(__pyx_v_ds_y, __pyx_t_7); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3947 - * ds_x = int(stream_feature.GetField('ds_x')) - * ds_y = int(stream_feature.GetField('ds_y')) - * upstream_fid_map[(ds_x, ds_y)].append( # <<<<<<<<<<<<<< - * stream_feature.GetFID()) - * - */ - __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3947, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_INCREF(__pyx_v_ds_x); - __Pyx_GIVEREF(__pyx_v_ds_x); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_ds_x); - __Pyx_INCREF(__pyx_v_ds_y); - __Pyx_GIVEREF(__pyx_v_ds_y); - PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_ds_y); - __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_upstream_fid_map, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3947, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3948 - * ds_y = int(stream_feature.GetField('ds_y')) - * upstream_fid_map[(ds_x, ds_y)].append( - * stream_feature.GetFID()) # <<<<<<<<<<<<<< - * - * stream_layer.ResetReading() - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetFID); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3948, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = NULL; - 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_7 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3948, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3947 - * ds_x = int(stream_feature.GetField('ds_x')) - * ds_y = int(stream_feature.GetField('ds_y')) - * upstream_fid_map[(ds_x, ds_y)].append( # <<<<<<<<<<<<<< - * stream_feature.GetFID()) - * - */ - __pyx_t_21 = __Pyx_PyObject_Append(__pyx_t_2, __pyx_t_7); if (unlikely(__pyx_t_21 == ((int)-1))) __PYX_ERR(0, 3947, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3944 - * # construct linkage data structure for upstream streams - * upstream_fid_map = collections.defaultdict(list) - * for stream_feature in stream_layer: # <<<<<<<<<<<<<< - * ds_x = int(stream_feature.GetField('ds_x')) - * ds_y = int(stream_feature.GetField('ds_y')) - */ - } - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3950 - * stream_feature.GetFID()) - * - * stream_layer.ResetReading() # <<<<<<<<<<<<<< - * # construct visit order, this list will have a tuple of (fid, 0/1) - * # this stack will be used to build watersheds from upstream to downstream - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_ResetReading); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3950, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_6 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3950, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3953 - * # construct visit order, this list will have a tuple of (fid, 0/1) - * # this stack will be used to build watersheds from upstream to downstream - * visit_order_stack = [] # <<<<<<<<<<<<<< - * # visit the highest order to lowest order in case there's a branching - * # junction of a order 1 and order 5 stream... visit order 5 upstream - */ - __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3953, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_v_visit_order_stack = ((PyObject*)__pyx_t_6); - __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3957 - * # junction of a order 1 and order 5 stream... visit order 5 upstream - * # first - * stream_layer.SetAttributeFilter(f'"outlet"=1') # <<<<<<<<<<<<<< - * # these are done last - * for _, outlet_fid in sorted([ - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_SetAttributeFilter); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3957, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_6 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_2, __pyx_kp_u_outlet_1) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_kp_u_outlet_1); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3957, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3959 - * stream_layer.SetAttributeFilter(f'"outlet"=1') - * # these are done last - * for _, outlet_fid in sorted([ # <<<<<<<<<<<<<< - * (x.GetField('order'), x.GetFID()) for x in stream_layer], - * reverse=True): - */ - { /* enter inner scope */ - __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3959, __pyx_L15_error) - __Pyx_GOTREF(__pyx_t_6); - - /* "pygeoprocessing/routing/routing.pyx":3960 - * # these are done last - * for _, outlet_fid in sorted([ - * (x.GetField('order'), x.GetFID()) for x in stream_layer], # <<<<<<<<<<<<<< - * reverse=True): - * working_stack = [outlet_fid] - */ - if (likely(PyList_CheckExact(__pyx_v_stream_layer)) || PyTuple_CheckExact(__pyx_v_stream_layer)) { - __pyx_t_7 = __pyx_v_stream_layer; __Pyx_INCREF(__pyx_t_7); __pyx_t_19 = 0; - __pyx_t_20 = NULL; - } else { - __pyx_t_19 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_v_stream_layer); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3960, __pyx_L15_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_20 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 3960, __pyx_L15_error) - } - for (;;) { - if (likely(!__pyx_t_20)) { - if (likely(PyList_CheckExact(__pyx_t_7))) { - if (__pyx_t_19 >= PyList_GET_SIZE(__pyx_t_7)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_19); __Pyx_INCREF(__pyx_t_2); __pyx_t_19++; if (unlikely(0 < 0)) __PYX_ERR(0, 3960, __pyx_L15_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_7, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3960, __pyx_L15_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } else { - if (__pyx_t_19 >= PyTuple_GET_SIZE(__pyx_t_7)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_19); __Pyx_INCREF(__pyx_t_2); __pyx_t_19++; if (unlikely(0 < 0)) __PYX_ERR(0, 3960, __pyx_L15_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_7, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3960, __pyx_L15_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } - } else { - __pyx_t_2 = __pyx_t_20(__pyx_t_7); - if (unlikely(!__pyx_t_2)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 3960, __pyx_L15_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XDECREF_SET(__pyx_8genexpr2__pyx_v_x, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_8genexpr2__pyx_v_x, __pyx_n_s_GetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3960, __pyx_L15_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = NULL; - 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_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_4, __pyx_n_u_order) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_n_u_order); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3960, __pyx_L15_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_8genexpr2__pyx_v_x, __pyx_n_s_GetFID); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3960, __pyx_L15_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3960, __pyx_L15_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3960, __pyx_L15_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1); - __pyx_t_2 = 0; - __pyx_t_1 = 0; - if (unlikely(__Pyx_ListComp_Append(__pyx_t_6, (PyObject*)__pyx_t_4))) __PYX_ERR(0, 3959, __pyx_L15_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_x); __pyx_8genexpr2__pyx_v_x = 0; - goto __pyx_L18_exit_scope; - __pyx_L15_error:; - __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_x); __pyx_8genexpr2__pyx_v_x = 0; - goto __pyx_L1_error; - __pyx_L18_exit_scope:; - } /* exit inner scope */ - - /* "pygeoprocessing/routing/routing.pyx":3959 - * stream_layer.SetAttributeFilter(f'"outlet"=1') - * # these are done last - * for _, outlet_fid in sorted([ # <<<<<<<<<<<<<< - * (x.GetField('order'), x.GetFID()) for x in stream_layer], - * reverse=True): - */ - __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3959, __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 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3961 - * for _, outlet_fid in sorted([ - * (x.GetField('order'), x.GetFID()) for x in stream_layer], - * reverse=True): # <<<<<<<<<<<<<< - * working_stack = [outlet_fid] - * processed_nodes = set() - */ - __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3961, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_reverse, Py_True) < 0) __PYX_ERR(0, 3961, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3959 - * stream_layer.SetAttributeFilter(f'"outlet"=1') - * # these are done last - * for _, outlet_fid in sorted([ # <<<<<<<<<<<<<< - * (x.GetField('order'), x.GetFID()) for x in stream_layer], - * reverse=True): - */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_sorted, __pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3959, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) { - __pyx_t_6 = __pyx_t_4; __Pyx_INCREF(__pyx_t_6); __pyx_t_19 = 0; - __pyx_t_20 = NULL; - } else { - __pyx_t_19 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3959, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_20 = Py_TYPE(__pyx_t_6)->tp_iternext; if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 3959, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - for (;;) { - if (likely(!__pyx_t_20)) { - if (likely(PyList_CheckExact(__pyx_t_6))) { - if (__pyx_t_19 >= PyList_GET_SIZE(__pyx_t_6)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_19); __Pyx_INCREF(__pyx_t_4); __pyx_t_19++; if (unlikely(0 < 0)) __PYX_ERR(0, 3959, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_6, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3959, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } else { - if (__pyx_t_19 >= PyTuple_GET_SIZE(__pyx_t_6)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_19); __Pyx_INCREF(__pyx_t_4); __pyx_t_19++; if (unlikely(0 < 0)) __PYX_ERR(0, 3959, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_6, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3959, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } - } else { - __pyx_t_4 = __pyx_t_20(__pyx_t_6); - 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, 3959, __pyx_L1_error) - } - break; - } - __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, 3959, __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); - } else { - __pyx_t_7 = PyList_GET_ITEM(sequence, 0); - __pyx_t_1 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(__pyx_t_1); - #else - __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3959, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3959, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_2 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3959, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_10 = Py_TYPE(__pyx_t_2)->tp_iternext; - index = 0; __pyx_t_7 = __pyx_t_10(__pyx_t_2); if (unlikely(!__pyx_t_7)) goto __pyx_L19_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - index = 1; __pyx_t_1 = __pyx_t_10(__pyx_t_2); if (unlikely(!__pyx_t_1)) goto __pyx_L19_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_2), 2) < 0) __PYX_ERR(0, 3959, __pyx_L1_error) - __pyx_t_10 = NULL; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L20_unpacking_done; - __pyx_L19_unpacking_failed:; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_10 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 3959, __pyx_L1_error) - __pyx_L20_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_XDECREF_SET(__pyx_v_outlet_fid, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3962 - * (x.GetField('order'), x.GetFID()) for x in stream_layer], - * reverse=True): - * working_stack = [outlet_fid] # <<<<<<<<<<<<<< - * processed_nodes = set() - * while working_stack: - */ - __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3962, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_v_outlet_fid); - __Pyx_GIVEREF(__pyx_v_outlet_fid); - PyList_SET_ITEM(__pyx_t_4, 0, __pyx_v_outlet_fid); - __Pyx_XDECREF_SET(__pyx_v_working_stack, ((PyObject*)__pyx_t_4)); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3963 - * reverse=True): - * working_stack = [outlet_fid] - * processed_nodes = set() # <<<<<<<<<<<<<< - * while working_stack: - * working_fid = working_stack[-1] - */ - __pyx_t_4 = PySet_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3963, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_XDECREF_SET(__pyx_v_processed_nodes, ((PyObject*)__pyx_t_4)); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3964 - * working_stack = [outlet_fid] - * processed_nodes = set() - * while working_stack: # <<<<<<<<<<<<<< - * working_fid = working_stack[-1] - * processed_nodes.add(working_fid) - */ - while (1) { - __pyx_t_18 = (PyList_GET_SIZE(__pyx_v_working_stack) != 0); - if (!__pyx_t_18) break; - - /* "pygeoprocessing/routing/routing.pyx":3965 - * processed_nodes = set() - * while working_stack: - * working_fid = working_stack[-1] # <<<<<<<<<<<<<< - * processed_nodes.add(working_fid) - * working_feature = stream_layer.GetFeature(working_fid) - */ - __pyx_t_4 = __Pyx_GetItemInt_List(__pyx_v_working_stack, -1L, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3965, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_XDECREF_SET(__pyx_v_working_fid, __pyx_t_4); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3966 - * while working_stack: - * working_fid = working_stack[-1] - * processed_nodes.add(working_fid) # <<<<<<<<<<<<<< - * working_feature = stream_layer.GetFeature(working_fid) - * - */ - __pyx_t_21 = PySet_Add(__pyx_v_processed_nodes, __pyx_v_working_fid); if (unlikely(__pyx_t_21 == ((int)-1))) __PYX_ERR(0, 3966, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3967 - * working_fid = working_stack[-1] - * processed_nodes.add(working_fid) - * working_feature = stream_layer.GetFeature(working_fid) # <<<<<<<<<<<<<< - * - * us_x = int(working_feature.GetField('us_x')) - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3967, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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); - } - } - __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_7, __pyx_v_working_fid) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_working_fid); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3967, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF_SET(__pyx_v_working_feature, __pyx_t_4); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3969 - * working_feature = stream_layer.GetFeature(working_fid) - * - * us_x = int(working_feature.GetField('us_x')) # <<<<<<<<<<<<<< - * us_y = int(working_feature.GetField('us_y')) - * ds_x_1 = int(working_feature.GetField('ds_x_1')) - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3969, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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); - } - } - __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_7, __pyx_n_u_us_x) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_n_u_us_x); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3969, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3969, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF_SET(__pyx_v_us_x, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3970 - * - * us_x = int(working_feature.GetField('us_x')) - * us_y = int(working_feature.GetField('us_y')) # <<<<<<<<<<<<<< - * ds_x_1 = int(working_feature.GetField('ds_x_1')) - * ds_y_1 = int(working_feature.GetField('ds_y_1')) - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3970, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __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); - } - } - __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_7, __pyx_n_u_us_y) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_n_u_us_y); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3970, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3970, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF_SET(__pyx_v_us_y, __pyx_t_4); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3971 - * us_x = int(working_feature.GetField('us_x')) - * us_y = int(working_feature.GetField('us_y')) - * ds_x_1 = int(working_feature.GetField('ds_x_1')) # <<<<<<<<<<<<<< - * ds_y_1 = int(working_feature.GetField('ds_y_1')) - * - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3971, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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); - } - } - __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_7, __pyx_n_u_ds_x_1) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_n_u_ds_x_1); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3971, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3971, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF_SET(__pyx_v_ds_x_1, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3972 - * us_y = int(working_feature.GetField('us_y')) - * ds_x_1 = int(working_feature.GetField('ds_x_1')) - * ds_y_1 = int(working_feature.GetField('ds_y_1')) # <<<<<<<<<<<<<< - * - * upstream_coord = (us_x, us_y) - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3972, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __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); - } - } - __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_7, __pyx_n_u_ds_y_1) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_n_u_ds_y_1); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3972, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3972, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF_SET(__pyx_v_ds_y_1, __pyx_t_4); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3974 - * ds_y_1 = int(working_feature.GetField('ds_y_1')) - * - * upstream_coord = (us_x, us_y) # <<<<<<<<<<<<<< - * upstream_fids = [ - * fid for fid in upstream_fid_map[upstream_coord] - */ - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3974, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_v_us_x); - __Pyx_GIVEREF(__pyx_v_us_x); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_us_x); - __Pyx_INCREF(__pyx_v_us_y); - __Pyx_GIVEREF(__pyx_v_us_y); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_us_y); - __Pyx_XDECREF_SET(__pyx_v_upstream_coord, ((PyObject*)__pyx_t_4)); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3975 - * - * upstream_coord = (us_x, us_y) - * upstream_fids = [ # <<<<<<<<<<<<<< - * fid for fid in upstream_fid_map[upstream_coord] - * if fid not in processed_nodes] - */ - { /* enter inner scope */ - __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3975, __pyx_L25_error) - __Pyx_GOTREF(__pyx_t_4); - - /* "pygeoprocessing/routing/routing.pyx":3976 - * upstream_coord = (us_x, us_y) - * upstream_fids = [ - * fid for fid in upstream_fid_map[upstream_coord] # <<<<<<<<<<<<<< - * if fid not in processed_nodes] - * if upstream_fids: - */ - __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_upstream_fid_map, __pyx_v_upstream_coord); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3976, __pyx_L25_error) - __Pyx_GOTREF(__pyx_t_1); - if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { - __pyx_t_7 = __pyx_t_1; __Pyx_INCREF(__pyx_t_7); __pyx_t_22 = 0; - __pyx_t_23 = NULL; - } else { - __pyx_t_22 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3976, __pyx_L25_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_23 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 3976, __pyx_L25_error) - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - for (;;) { - if (likely(!__pyx_t_23)) { - if (likely(PyList_CheckExact(__pyx_t_7))) { - if (__pyx_t_22 >= PyList_GET_SIZE(__pyx_t_7)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_22); __Pyx_INCREF(__pyx_t_1); __pyx_t_22++; if (unlikely(0 < 0)) __PYX_ERR(0, 3976, __pyx_L25_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_7, __pyx_t_22); __pyx_t_22++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3976, __pyx_L25_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } else { - if (__pyx_t_22 >= PyTuple_GET_SIZE(__pyx_t_7)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_22); __Pyx_INCREF(__pyx_t_1); __pyx_t_22++; if (unlikely(0 < 0)) __PYX_ERR(0, 3976, __pyx_L25_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_7, __pyx_t_22); __pyx_t_22++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3976, __pyx_L25_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } - } else { - __pyx_t_1 = __pyx_t_23(__pyx_t_7); - 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, 3976, __pyx_L25_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - __Pyx_XDECREF_SET(__pyx_8genexpr3__pyx_v_fid, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3977 - * upstream_fids = [ - * fid for fid in upstream_fid_map[upstream_coord] - * if fid not in processed_nodes] # <<<<<<<<<<<<<< - * if upstream_fids: - * working_stack.extend(upstream_fids) - */ - __pyx_t_18 = (__Pyx_PySet_ContainsTF(__pyx_8genexpr3__pyx_v_fid, __pyx_v_processed_nodes, Py_NE)); if (unlikely(__pyx_t_18 < 0)) __PYX_ERR(0, 3977, __pyx_L25_error) - __pyx_t_24 = (__pyx_t_18 != 0); - if (__pyx_t_24) { - - /* "pygeoprocessing/routing/routing.pyx":3976 - * upstream_coord = (us_x, us_y) - * upstream_fids = [ - * fid for fid in upstream_fid_map[upstream_coord] # <<<<<<<<<<<<<< - * if fid not in processed_nodes] - * if upstream_fids: - */ - if (unlikely(__Pyx_ListComp_Append(__pyx_t_4, (PyObject*)__pyx_8genexpr3__pyx_v_fid))) __PYX_ERR(0, 3975, __pyx_L25_error) - - /* "pygeoprocessing/routing/routing.pyx":3977 - * upstream_fids = [ - * fid for fid in upstream_fid_map[upstream_coord] - * if fid not in processed_nodes] # <<<<<<<<<<<<<< - * if upstream_fids: - * working_stack.extend(upstream_fids) - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3976 - * upstream_coord = (us_x, us_y) - * upstream_fids = [ - * fid for fid in upstream_fid_map[upstream_coord] # <<<<<<<<<<<<<< - * if fid not in processed_nodes] - * if upstream_fids: - */ - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF(__pyx_8genexpr3__pyx_v_fid); __pyx_8genexpr3__pyx_v_fid = 0; - goto __pyx_L29_exit_scope; - __pyx_L25_error:; - __Pyx_XDECREF(__pyx_8genexpr3__pyx_v_fid); __pyx_8genexpr3__pyx_v_fid = 0; - goto __pyx_L1_error; - __pyx_L29_exit_scope:; - } /* exit inner scope */ - __Pyx_XDECREF_SET(__pyx_v_upstream_fids, ((PyObject*)__pyx_t_4)); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3978 - * fid for fid in upstream_fid_map[upstream_coord] - * if fid not in processed_nodes] - * if upstream_fids: # <<<<<<<<<<<<<< - * working_stack.extend(upstream_fids) - * else: - */ - __pyx_t_24 = (PyList_GET_SIZE(__pyx_v_upstream_fids) != 0); - if (__pyx_t_24) { - - /* "pygeoprocessing/routing/routing.pyx":3979 - * if fid not in processed_nodes] - * if upstream_fids: - * working_stack.extend(upstream_fids) # <<<<<<<<<<<<<< - * else: - * working_stack.pop() - */ - __pyx_t_21 = __Pyx_PyList_Extend(__pyx_v_working_stack, __pyx_v_upstream_fids); if (unlikely(__pyx_t_21 == ((int)-1))) __PYX_ERR(0, 3979, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3978 - * fid for fid in upstream_fid_map[upstream_coord] - * if fid not in processed_nodes] - * if upstream_fids: # <<<<<<<<<<<<<< - * working_stack.extend(upstream_fids) - * else: - */ - goto __pyx_L30; - } - - /* "pygeoprocessing/routing/routing.pyx":3981 - * working_stack.extend(upstream_fids) - * else: - * working_stack.pop() # <<<<<<<<<<<<<< - * # the `not outlet_at_confluence` bit allows us to seed - * # even if the order is 1, otherwise confluences fill - */ - /*else*/ { - __pyx_t_4 = __Pyx_PyList_Pop(__pyx_v_working_stack); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3981, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3985 - * # even if the order is 1, otherwise confluences fill - * # the order 1 streams - * if (working_feature.GetField('order') > 1 or # <<<<<<<<<<<<<< - * not outlet_at_confluence): - * if outlet_at_confluence: - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3985, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_4 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_1, __pyx_n_u_order) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_n_u_order); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3985, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyObject_RichCompare(__pyx_t_4, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3985, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_18 < 0)) __PYX_ERR(0, 3985, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (!__pyx_t_18) { - } else { - __pyx_t_24 = __pyx_t_18; - goto __pyx_L32_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":3986 - * # the order 1 streams - * if (working_feature.GetField('order') > 1 or - * not outlet_at_confluence): # <<<<<<<<<<<<<< - * if outlet_at_confluence: - * # seed the upstream point - */ - __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_v_outlet_at_confluence); if (unlikely(__pyx_t_18 < 0)) __PYX_ERR(0, 3986, __pyx_L1_error) - __pyx_t_25 = ((!__pyx_t_18) != 0); - __pyx_t_24 = __pyx_t_25; - __pyx_L32_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":3985 - * # even if the order is 1, otherwise confluences fill - * # the order 1 streams - * if (working_feature.GetField('order') > 1 or # <<<<<<<<<<<<<< - * not outlet_at_confluence): - * if outlet_at_confluence: - */ - if (__pyx_t_24) { - - /* "pygeoprocessing/routing/routing.pyx":3987 - * if (working_feature.GetField('order') > 1 or - * not outlet_at_confluence): - * if outlet_at_confluence: # <<<<<<<<<<<<<< - * # seed the upstream point - * visit_order_stack.append((working_fid, us_x, us_y)) - */ - __pyx_t_24 = __Pyx_PyObject_IsTrue(__pyx_v_outlet_at_confluence); if (unlikely(__pyx_t_24 < 0)) __PYX_ERR(0, 3987, __pyx_L1_error) - if (__pyx_t_24) { - - /* "pygeoprocessing/routing/routing.pyx":3989 - * if outlet_at_confluence: - * # seed the upstream point - * visit_order_stack.append((working_fid, us_x, us_y)) # <<<<<<<<<<<<<< - * else: - * # seed the downstream but +1 step point - */ - __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3989, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_INCREF(__pyx_v_working_fid); - __Pyx_GIVEREF(__pyx_v_working_fid); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_working_fid); - __Pyx_INCREF(__pyx_v_us_x); - __Pyx_GIVEREF(__pyx_v_us_x); - PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_us_x); - __Pyx_INCREF(__pyx_v_us_y); - __Pyx_GIVEREF(__pyx_v_us_y); - PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_v_us_y); - __pyx_t_21 = __Pyx_PyList_Append(__pyx_v_visit_order_stack, __pyx_t_7); if (unlikely(__pyx_t_21 == ((int)-1))) __PYX_ERR(0, 3989, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3987 - * if (working_feature.GetField('order') > 1 or - * not outlet_at_confluence): - * if outlet_at_confluence: # <<<<<<<<<<<<<< - * # seed the upstream point - * visit_order_stack.append((working_fid, us_x, us_y)) - */ - goto __pyx_L34; - } - - /* "pygeoprocessing/routing/routing.pyx":3992 - * else: - * # seed the downstream but +1 step point - * visit_order_stack.append( # <<<<<<<<<<<<<< - * (working_fid, ds_x_1, ds_y_1)) - * if working_feature.GetField('outlet') == 1: - */ - /*else*/ { - - /* "pygeoprocessing/routing/routing.pyx":3993 - * # seed the downstream but +1 step point - * visit_order_stack.append( - * (working_fid, ds_x_1, ds_y_1)) # <<<<<<<<<<<<<< - * if working_feature.GetField('outlet') == 1: - * # an outlet is a special case where the outlet itself - */ - __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3993, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_INCREF(__pyx_v_working_fid); - __Pyx_GIVEREF(__pyx_v_working_fid); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_working_fid); - __Pyx_INCREF(__pyx_v_ds_x_1); - __Pyx_GIVEREF(__pyx_v_ds_x_1); - PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_ds_x_1); - __Pyx_INCREF(__pyx_v_ds_y_1); - __Pyx_GIVEREF(__pyx_v_ds_y_1); - PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_v_ds_y_1); - - /* "pygeoprocessing/routing/routing.pyx":3992 - * else: - * # seed the downstream but +1 step point - * visit_order_stack.append( # <<<<<<<<<<<<<< - * (working_fid, ds_x_1, ds_y_1)) - * if working_feature.GetField('outlet') == 1: - */ - __pyx_t_21 = __Pyx_PyList_Append(__pyx_v_visit_order_stack, __pyx_t_7); if (unlikely(__pyx_t_21 == ((int)-1))) __PYX_ERR(0, 3992, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __pyx_L34:; - - /* "pygeoprocessing/routing/routing.pyx":3985 - * # even if the order is 1, otherwise confluences fill - * # the order 1 streams - * if (working_feature.GetField('order') > 1 or # <<<<<<<<<<<<<< - * not outlet_at_confluence): - * if outlet_at_confluence: - */ - } - - /* "pygeoprocessing/routing/routing.pyx":3994 - * visit_order_stack.append( - * (working_fid, ds_x_1, ds_y_1)) - * if working_feature.GetField('outlet') == 1: # <<<<<<<<<<<<<< - * # an outlet is a special case where the outlet itself - * # should be a subwatershed done last. - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3994, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_7 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, __pyx_n_u_outlet) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_n_u_outlet); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3994, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyInt_EqObjC(__pyx_t_7, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3994, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_24 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_24 < 0)) __PYX_ERR(0, 3994, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__pyx_t_24) { - - /* "pygeoprocessing/routing/routing.pyx":3997 - * # an outlet is a special case where the outlet itself - * # should be a subwatershed done last. - * ds_x = int(working_feature.GetField('ds_x')) # <<<<<<<<<<<<<< - * ds_y = int(working_feature.GetField('ds_y')) - * if not outlet_at_confluence: - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3997, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_4 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_1, __pyx_n_u_ds_x) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_n_u_ds_x); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3997, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyNumber_Int(__pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3997, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF_SET(__pyx_v_ds_x, __pyx_t_7); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3998 - * # should be a subwatershed done last. - * ds_x = int(working_feature.GetField('ds_x')) - * ds_y = int(working_feature.GetField('ds_y')) # <<<<<<<<<<<<<< - * if not outlet_at_confluence: - * # undo the previous visit because it will be at - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_working_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3998, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_7 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, __pyx_n_u_ds_y) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_n_u_ds_y); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3998, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyNumber_Int(__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3998, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF_SET(__pyx_v_ds_y, __pyx_t_4); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3999 - * ds_x = int(working_feature.GetField('ds_x')) - * ds_y = int(working_feature.GetField('ds_y')) - * if not outlet_at_confluence: # <<<<<<<<<<<<<< - * # undo the previous visit because it will be at - * # one pixel up and we want the pixel right at - */ - __pyx_t_24 = __Pyx_PyObject_IsTrue(__pyx_v_outlet_at_confluence); if (unlikely(__pyx_t_24 < 0)) __PYX_ERR(0, 3999, __pyx_L1_error) - __pyx_t_25 = ((!__pyx_t_24) != 0); - if (__pyx_t_25) { - - /* "pygeoprocessing/routing/routing.pyx":4003 - * # one pixel up and we want the pixel right at - * # the outlet - * visit_order_stack.pop() # <<<<<<<<<<<<<< - * visit_order_stack.append((working_fid, ds_x, ds_y)) - * - */ - __pyx_t_4 = __Pyx_PyList_Pop(__pyx_v_visit_order_stack); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4003, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3999 - * ds_x = int(working_feature.GetField('ds_x')) - * ds_y = int(working_feature.GetField('ds_y')) - * if not outlet_at_confluence: # <<<<<<<<<<<<<< - * # undo the previous visit because it will be at - * # one pixel up and we want the pixel right at - */ - } - - /* "pygeoprocessing/routing/routing.pyx":4004 - * # the outlet - * visit_order_stack.pop() - * visit_order_stack.append((working_fid, ds_x, ds_y)) # <<<<<<<<<<<<<< - * - * cdef int edge_side, edge_dir, cell_to_test, out_dir_increase=-1 - */ - __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4004, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_v_working_fid); - __Pyx_GIVEREF(__pyx_v_working_fid); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_working_fid); - __Pyx_INCREF(__pyx_v_ds_x); - __Pyx_GIVEREF(__pyx_v_ds_x); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_ds_x); - __Pyx_INCREF(__pyx_v_ds_y); - __Pyx_GIVEREF(__pyx_v_ds_y); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_ds_y); - __pyx_t_21 = __Pyx_PyList_Append(__pyx_v_visit_order_stack, __pyx_t_4); if (unlikely(__pyx_t_21 == ((int)-1))) __PYX_ERR(0, 4004, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3994 - * visit_order_stack.append( - * (working_fid, ds_x_1, ds_y_1)) - * if working_feature.GetField('outlet') == 1: # <<<<<<<<<<<<<< - * # an outlet is a special case where the outlet itself - * # should be a subwatershed done last. - */ - } - } - __pyx_L30:; - } - - /* "pygeoprocessing/routing/routing.pyx":3959 - * stream_layer.SetAttributeFilter(f'"outlet"=1') - * # these are done last - * for _, outlet_fid in sorted([ # <<<<<<<<<<<<<< - * (x.GetField('order'), x.GetFID()) for x in stream_layer], - * reverse=True): - */ - } - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4006 - * visit_order_stack.append((working_fid, ds_x, ds_y)) - * - * cdef int edge_side, edge_dir, cell_to_test, out_dir_increase=-1 # <<<<<<<<<<<<<< - * cdef int left, right, n_steps, terminated_early - * cdef int delta_x, delta_y - */ - __pyx_v_out_dir_increase = -1; - - /* "pygeoprocessing/routing/routing.pyx":4009 - * cdef int left, right, n_steps, terminated_early - * cdef int delta_x, delta_y - * cdef int _int_max_steps_per_watershed = max_steps_per_watershed # <<<<<<<<<<<<<< - * - * for index, (stream_fid, x_l, y_l) in enumerate(visit_order_stack): - */ - __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_v_max_steps_per_watershed); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4009, __pyx_L1_error) - __pyx_v__int_max_steps_per_watershed = __pyx_t_11; - - /* "pygeoprocessing/routing/routing.pyx":4011 - * cdef int _int_max_steps_per_watershed = max_steps_per_watershed - * - * for index, (stream_fid, x_l, y_l) in enumerate(visit_order_stack): # <<<<<<<<<<<<<< - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * LOGGER.info( - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_t_6 = __pyx_int_0; - __pyx_t_4 = __pyx_v_visit_order_stack; __Pyx_INCREF(__pyx_t_4); __pyx_t_19 = 0; - for (;;) { - if (__pyx_t_19 >= PyList_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_19); __Pyx_INCREF(__pyx_t_7); __pyx_t_19++; if (unlikely(0 < 0)) __PYX_ERR(0, 4011, __pyx_L1_error) - #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4011, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - #endif - if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) { - PyObject* sequence = __pyx_t_7; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 3)) { - if (size > 3) __Pyx_RaiseTooManyValuesError(3); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 4011, __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_3 = PyTuple_GET_ITEM(sequence, 2); - } else { - __pyx_t_1 = PyList_GET_ITEM(sequence, 0); - __pyx_t_2 = PyList_GET_ITEM(sequence, 1); - __pyx_t_3 = PyList_GET_ITEM(sequence, 2); - } - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - #else - __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4011, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4011, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4011, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_5 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4011, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_10 = Py_TYPE(__pyx_t_5)->tp_iternext; - index = 0; __pyx_t_1 = __pyx_t_10(__pyx_t_5); if (unlikely(!__pyx_t_1)) goto __pyx_L39_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - index = 1; __pyx_t_2 = __pyx_t_10(__pyx_t_5); if (unlikely(!__pyx_t_2)) goto __pyx_L39_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - index = 2; __pyx_t_3 = __pyx_t_10(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L39_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_5), 3) < 0) __PYX_ERR(0, 4011, __pyx_L1_error) - __pyx_t_10 = NULL; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - goto __pyx_L40_unpacking_done; - __pyx_L39_unpacking_failed:; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_10 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 4011, __pyx_L1_error) - __pyx_L40_unpacking_done:; - } - __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4011, __pyx_L1_error) - __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, 4011, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF_SET(__pyx_v_stream_fid, __pyx_t_1); - __pyx_t_1 = 0; - __pyx_v_x_l = __pyx_t_11; - __pyx_v_y_l = __pyx_t_8; - __Pyx_INCREF(__pyx_t_6); - __Pyx_XDECREF_SET(__pyx_v_index, __pyx_t_6); - __pyx_t_7 = __Pyx_PyInt_AddObjC(__pyx_t_6, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4011, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_6); - __pyx_t_6 = __pyx_t_7; - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4012 - * - * for index, (stream_fid, x_l, y_l) in enumerate(visit_order_stack): - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * LOGGER.info( - * f'(calculate_subwatershed_boundary): watershed building ' - */ - __pyx_t_25 = (((time(NULL) - __pyx_v_last_log_time) > __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD) != 0); - if (__pyx_t_25) { - - /* "pygeoprocessing/routing/routing.pyx":4013 - * for index, (stream_fid, x_l, y_l) in enumerate(visit_order_stack): - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * LOGGER.info( # <<<<<<<<<<<<<< - * f'(calculate_subwatershed_boundary): watershed building ' - * f'{(index/len(visit_order_stack))*100:.1f}% complete') - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4013, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4013, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4014 - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * LOGGER.info( - * f'(calculate_subwatershed_boundary): watershed building ' # <<<<<<<<<<<<<< - * f'{(index/len(visit_order_stack))*100:.1f}% complete') - * last_log_time = ctime(NULL) - */ - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4014, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_22 = 0; - __pyx_t_26 = 127; - __Pyx_INCREF(__pyx_kp_u_calculate_subwatershed_boundary_2); - __pyx_t_22 += 54; - __Pyx_GIVEREF(__pyx_kp_u_calculate_subwatershed_boundary_2); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_u_calculate_subwatershed_boundary_2); - - /* "pygeoprocessing/routing/routing.pyx":4015 - * LOGGER.info( - * f'(calculate_subwatershed_boundary): watershed building ' - * f'{(index/len(visit_order_stack))*100:.1f}% complete') # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * discovery = discovery_managed_raster.get(x_l, y_l) - */ - __pyx_t_27 = PyList_GET_SIZE(__pyx_v_visit_order_stack); if (unlikely(__pyx_t_27 == ((Py_ssize_t)-1))) __PYX_ERR(0, 4015, __pyx_L1_error) - __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_27); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4015, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyNumber_Divide(__pyx_v_index, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4015, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Multiply(__pyx_t_5, __pyx_int_100); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4015, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_Format(__pyx_t_1, __pyx_kp_u_1f); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4015, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_26 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_26) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_26; - __pyx_t_22 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_5); - __pyx_t_5 = 0; - __Pyx_INCREF(__pyx_kp_u_complete); - __pyx_t_22 += 10; - __Pyx_GIVEREF(__pyx_kp_u_complete); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_kp_u_complete); - - /* "pygeoprocessing/routing/routing.pyx":4014 - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * LOGGER.info( - * f'(calculate_subwatershed_boundary): watershed building ' # <<<<<<<<<<<<<< - * f'{(index/len(visit_order_stack))*100:.1f}% complete') - * last_log_time = ctime(NULL) - */ - __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_3, 3, __pyx_t_22, __pyx_t_26); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4014, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __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); - } - } - __pyx_t_7 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_5); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4013, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4016 - * f'(calculate_subwatershed_boundary): watershed building ' - * f'{(index/len(visit_order_stack))*100:.1f}% complete') - * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< - * discovery = discovery_managed_raster.get(x_l, y_l) - * if discovery == -1: - */ - __pyx_v_last_log_time = time(NULL); - - /* "pygeoprocessing/routing/routing.pyx":4012 - * - * for index, (stream_fid, x_l, y_l) in enumerate(visit_order_stack): - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: # <<<<<<<<<<<<<< - * LOGGER.info( - * f'(calculate_subwatershed_boundary): watershed building ' - */ - } - - /* "pygeoprocessing/routing/routing.pyx":4017 - * f'{(index/len(visit_order_stack))*100:.1f}% complete') - * last_log_time = ctime(NULL) - * discovery = discovery_managed_raster.get(x_l, y_l) # <<<<<<<<<<<<<< - * if discovery == -1: - * continue - */ - __pyx_v_discovery = ((long)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_discovery_managed_raster, __pyx_v_x_l, __pyx_v_y_l)); - - /* "pygeoprocessing/routing/routing.pyx":4018 - * last_log_time = ctime(NULL) - * discovery = discovery_managed_raster.get(x_l, y_l) - * if discovery == -1: # <<<<<<<<<<<<<< - * continue - * boundary_list = [(x_l, y_l)] - */ - __pyx_t_25 = ((__pyx_v_discovery == -1L) != 0); - if (__pyx_t_25) { - - /* "pygeoprocessing/routing/routing.pyx":4019 - * discovery = discovery_managed_raster.get(x_l, y_l) - * if discovery == -1: - * continue # <<<<<<<<<<<<<< - * boundary_list = [(x_l, y_l)] - * finish = finish_managed_raster.get(x_l, y_l) - */ - goto __pyx_L37_continue; - - /* "pygeoprocessing/routing/routing.pyx":4018 - * last_log_time = ctime(NULL) - * discovery = discovery_managed_raster.get(x_l, y_l) - * if discovery == -1: # <<<<<<<<<<<<<< - * continue - * boundary_list = [(x_l, y_l)] - */ - } - - /* "pygeoprocessing/routing/routing.pyx":4020 - * if discovery == -1: - * continue - * boundary_list = [(x_l, y_l)] # <<<<<<<<<<<<<< - * finish = finish_managed_raster.get(x_l, y_l) - * outlet_x = x_l - */ - __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_x_l); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4020, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_y_l); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4020, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4020, __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_2); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2); - __pyx_t_7 = 0; - __pyx_t_2 = 0; - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4020, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_5); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_5); - __pyx_t_5 = 0; - __Pyx_XDECREF_SET(__pyx_v_boundary_list, ((PyObject*)__pyx_t_2)); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4021 - * continue - * boundary_list = [(x_l, y_l)] - * finish = finish_managed_raster.get(x_l, y_l) # <<<<<<<<<<<<<< - * outlet_x = x_l - * outlet_y = y_l - */ - __pyx_v_finish = ((long)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_finish_managed_raster, __pyx_v_x_l, __pyx_v_y_l)); - - /* "pygeoprocessing/routing/routing.pyx":4022 - * boundary_list = [(x_l, y_l)] - * finish = finish_managed_raster.get(x_l, y_l) - * outlet_x = x_l # <<<<<<<<<<<<<< - * outlet_y = y_l - * - */ - __pyx_v_outlet_x = __pyx_v_x_l; - - /* "pygeoprocessing/routing/routing.pyx":4023 - * finish = finish_managed_raster.get(x_l, y_l) - * outlet_x = x_l - * outlet_y = y_l # <<<<<<<<<<<<<< - * - * watershed_boundary = ogr.Geometry(ogr.wkbLinearRing) - */ - __pyx_v_outlet_y = __pyx_v_y_l; - - /* "pygeoprocessing/routing/routing.pyx":4025 - * outlet_y = y_l - * - * watershed_boundary = ogr.Geometry(ogr.wkbLinearRing) # <<<<<<<<<<<<<< - * outflow_dir = d8_flow_dir_managed_raster.get(x_l, y_l) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_ogr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4025, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_Geometry); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4025, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_ogr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4025, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_wkbLinearRing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4025, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __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); - } - } - __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_3); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4025, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF_SET(__pyx_v_watershed_boundary, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4026 - * - * watershed_boundary = ogr.Geometry(ogr.wkbLinearRing) - * outflow_dir = d8_flow_dir_managed_raster.get(x_l, y_l) # <<<<<<<<<<<<<< - * - * # this is the center point of the pixel that will be offset to - */ - __pyx_v_outflow_dir = ((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_d8_flow_dir_managed_raster, __pyx_v_x_l, __pyx_v_y_l)); - - /* "pygeoprocessing/routing/routing.pyx":4030 - * # this is the center point of the pixel that will be offset to - * # make the edge - * x_f = x_l+0.5 # <<<<<<<<<<<<<< - * y_f = y_l+0.5 - * - */ - __pyx_v_x_f = (__pyx_v_x_l + 0.5); - - /* "pygeoprocessing/routing/routing.pyx":4031 - * # make the edge - * x_f = x_l+0.5 - * y_f = y_l+0.5 # <<<<<<<<<<<<<< - * - * x_f += D8_XOFFSET[outflow_dir]*0.5 - */ - __pyx_v_y_f = (__pyx_v_y_l + 0.5); - - /* "pygeoprocessing/routing/routing.pyx":4033 - * y_f = y_l+0.5 - * - * x_f += D8_XOFFSET[outflow_dir]*0.5 # <<<<<<<<<<<<<< - * y_f += D8_YOFFSET[outflow_dir]*0.5 - * if outflow_dir % 2 == 0: - */ - __pyx_v_x_f = (__pyx_v_x_f + ((__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_outflow_dir]) * 0.5)); - - /* "pygeoprocessing/routing/routing.pyx":4034 - * - * x_f += D8_XOFFSET[outflow_dir]*0.5 - * y_f += D8_YOFFSET[outflow_dir]*0.5 # <<<<<<<<<<<<<< - * if outflow_dir % 2 == 0: - * # need to back up the point a bit - */ - __pyx_v_y_f = (__pyx_v_y_f + ((__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_outflow_dir]) * 0.5)); - - /* "pygeoprocessing/routing/routing.pyx":4035 - * x_f += D8_XOFFSET[outflow_dir]*0.5 - * y_f += D8_YOFFSET[outflow_dir]*0.5 - * if outflow_dir % 2 == 0: # <<<<<<<<<<<<<< - * # need to back up the point a bit - * x_f -= D8_YOFFSET[outflow_dir]*0.5 - */ - __pyx_t_25 = ((__Pyx_mod_long(__pyx_v_outflow_dir, 2) == 0) != 0); - if (__pyx_t_25) { - - /* "pygeoprocessing/routing/routing.pyx":4037 - * if outflow_dir % 2 == 0: - * # need to back up the point a bit - * x_f -= D8_YOFFSET[outflow_dir]*0.5 # <<<<<<<<<<<<<< - * y_f += D8_XOFFSET[outflow_dir]*0.5 - * - */ - __pyx_v_x_f = (__pyx_v_x_f - ((__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_outflow_dir]) * 0.5)); - - /* "pygeoprocessing/routing/routing.pyx":4038 - * # need to back up the point a bit - * x_f -= D8_YOFFSET[outflow_dir]*0.5 - * y_f += D8_XOFFSET[outflow_dir]*0.5 # <<<<<<<<<<<<<< - * - * x_p, y_p = gdal.ApplyGeoTransform(geotransform, x_f, y_f) - */ - __pyx_v_y_f = (__pyx_v_y_f + ((__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_outflow_dir]) * 0.5)); - - /* "pygeoprocessing/routing/routing.pyx":4035 - * x_f += D8_XOFFSET[outflow_dir]*0.5 - * y_f += D8_YOFFSET[outflow_dir]*0.5 - * if outflow_dir % 2 == 0: # <<<<<<<<<<<<<< - * # need to back up the point a bit - * x_f -= D8_YOFFSET[outflow_dir]*0.5 - */ - } - - /* "pygeoprocessing/routing/routing.pyx":4040 - * y_f += D8_XOFFSET[outflow_dir]*0.5 - * - * x_p, y_p = gdal.ApplyGeoTransform(geotransform, x_f, y_f) # <<<<<<<<<<<<<< - * watershed_boundary.AddPoint(x_p, y_p) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4040, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_ApplyGeoTransform); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4040, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyFloat_FromDouble(__pyx_v_x_f); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4040, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_5 = PyFloat_FromDouble(__pyx_v_y_f); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4040, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = NULL; - __pyx_t_8 = 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_8 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_v_geotransform, __pyx_t_7, __pyx_t_5}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4040, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 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[4] = {__pyx_t_1, __pyx_v_geotransform, __pyx_t_7, __pyx_t_5}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4040, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - { - __pyx_t_28 = PyTuple_New(3+__pyx_t_8); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4040, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_28); - if (__pyx_t_1) { - __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_28, 0, __pyx_t_1); __pyx_t_1 = NULL; - } - __Pyx_INCREF(__pyx_v_geotransform); - __Pyx_GIVEREF(__pyx_v_geotransform); - PyTuple_SET_ITEM(__pyx_t_28, 0+__pyx_t_8, __pyx_v_geotransform); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_28, 1+__pyx_t_8, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_28, 2+__pyx_t_8, __pyx_t_5); - __pyx_t_7 = 0; - __pyx_t_5 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_28, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4040, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - 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 != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 4040, __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_28 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_3 = PyList_GET_ITEM(sequence, 0); - __pyx_t_28 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_28); - #else - __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4040, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_28 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4040, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_28); - #endif - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_5 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4040, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_10 = Py_TYPE(__pyx_t_5)->tp_iternext; - index = 0; __pyx_t_3 = __pyx_t_10(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L44_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - index = 1; __pyx_t_28 = __pyx_t_10(__pyx_t_5); if (unlikely(!__pyx_t_28)) goto __pyx_L44_unpacking_failed; - __Pyx_GOTREF(__pyx_t_28); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_5), 2) < 0) __PYX_ERR(0, 4040, __pyx_L1_error) - __pyx_t_10 = NULL; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - goto __pyx_L45_unpacking_done; - __pyx_L44_unpacking_failed:; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_10 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 4040, __pyx_L1_error) - __pyx_L45_unpacking_done:; - } - __pyx_t_17 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_17 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 4040, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_16 = __pyx_PyFloat_AsDouble(__pyx_t_28); if (unlikely((__pyx_t_16 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 4040, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; - __pyx_v_x_p = __pyx_t_17; - __pyx_v_y_p = __pyx_t_16; - - /* "pygeoprocessing/routing/routing.pyx":4041 - * - * x_p, y_p = gdal.ApplyGeoTransform(geotransform, x_f, y_f) - * watershed_boundary.AddPoint(x_p, y_p) # <<<<<<<<<<<<<< - * - * # keep track of how many steps x/y and when we get back to 0 we've - */ - __pyx_t_28 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_boundary, __pyx_n_s_AddPoint); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4041, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_28); - __pyx_t_3 = PyFloat_FromDouble(__pyx_v_x_p); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4041, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyFloat_FromDouble(__pyx_v_y_p); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4041, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_7 = NULL; - __pyx_t_8 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_28))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_28); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_28); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_28, function); - __pyx_t_8 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_28)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_3, __pyx_t_5}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_28, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4041, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_2); - __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_28)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_3, __pyx_t_5}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_28, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4041, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - { - __pyx_t_1 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4041, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (__pyx_t_7) { - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7); __pyx_t_7 = NULL; - } - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_8, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_8, __pyx_t_5); - __pyx_t_3 = 0; - __pyx_t_5 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_28, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4041, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4045 - * # keep track of how many steps x/y and when we get back to 0 we've - * # made a loop - * delta_x, delta_y = 0, 0 # <<<<<<<<<<<<<< - * - * # determine the first edge - */ - __pyx_t_8 = 0; - __pyx_t_11 = 0; - __pyx_v_delta_x = __pyx_t_8; - __pyx_v_delta_y = __pyx_t_11; - - /* "pygeoprocessing/routing/routing.pyx":4048 - * - * # determine the first edge - * if outflow_dir % 2 == 0: # <<<<<<<<<<<<<< - * # outflow through a straight side, so trivial edge detection - * edge_side = outflow_dir - */ - __pyx_t_25 = ((__Pyx_mod_long(__pyx_v_outflow_dir, 2) == 0) != 0); - if (__pyx_t_25) { - - /* "pygeoprocessing/routing/routing.pyx":4050 - * if outflow_dir % 2 == 0: - * # outflow through a straight side, so trivial edge detection - * edge_side = outflow_dir # <<<<<<<<<<<<<< - * edge_dir = (2+edge_side) % 8 - * else: - */ - __pyx_v_edge_side = __pyx_v_outflow_dir; - - /* "pygeoprocessing/routing/routing.pyx":4051 - * # outflow through a straight side, so trivial edge detection - * edge_side = outflow_dir - * edge_dir = (2+edge_side) % 8 # <<<<<<<<<<<<<< - * else: - * # diagonal outflow requires testing neighboring cells to - */ - __pyx_v_edge_dir = __Pyx_mod_long((2 + __pyx_v_edge_side), 8); - - /* "pygeoprocessing/routing/routing.pyx":4048 - * - * # determine the first edge - * if outflow_dir % 2 == 0: # <<<<<<<<<<<<<< - * # outflow through a straight side, so trivial edge detection - * edge_side = outflow_dir - */ - goto __pyx_L46; - } - - /* "pygeoprocessing/routing/routing.pyx":4055 - * # diagonal outflow requires testing neighboring cells to - * # determine first edge - * cell_to_test = (outflow_dir+1) % 8 # <<<<<<<<<<<<<< - * edge_side = cell_to_test - * edge_dir = (cell_to_test+2) % 8 - */ - /*else*/ { - __pyx_v_cell_to_test = __Pyx_mod_long((__pyx_v_outflow_dir + 1), 8); - - /* "pygeoprocessing/routing/routing.pyx":4056 - * # determine first edge - * cell_to_test = (outflow_dir+1) % 8 - * edge_side = cell_to_test # <<<<<<<<<<<<<< - * edge_dir = (cell_to_test+2) % 8 - * if _in_watershed( - */ - __pyx_v_edge_side = __pyx_v_cell_to_test; - - /* "pygeoprocessing/routing/routing.pyx":4057 - * cell_to_test = (outflow_dir+1) % 8 - * edge_side = cell_to_test - * edge_dir = (cell_to_test+2) % 8 # <<<<<<<<<<<<<< - * if _in_watershed( - * x_l, y_l, cell_to_test, discovery, finish, - */ - __pyx_v_edge_dir = __Pyx_mod_long((__pyx_v_cell_to_test + 2), 8); - - /* "pygeoprocessing/routing/routing.pyx":4058 - * edge_side = cell_to_test - * edge_dir = (cell_to_test+2) % 8 - * if _in_watershed( # <<<<<<<<<<<<<< - * x_l, y_l, cell_to_test, discovery, finish, - * n_cols, n_rows, - */ - __pyx_t_25 = (__pyx_f_15pygeoprocessing_7routing_7routing__in_watershed(__pyx_v_x_l, __pyx_v_y_l, __pyx_v_cell_to_test, __pyx_v_discovery, __pyx_v_finish, __pyx_v_n_cols, __pyx_v_n_rows, __pyx_v_discovery_managed_raster, __pyx_v_discovery_nodata) != 0); - if (__pyx_t_25) { - - /* "pygeoprocessing/routing/routing.pyx":4062 - * n_cols, n_rows, - * discovery_managed_raster, discovery_nodata): - * edge_side = (edge_side-2) % 8 # <<<<<<<<<<<<<< - * edge_dir = (edge_dir-2) % 8 - * x_l += D8_XOFFSET[edge_dir] - */ - __pyx_v_edge_side = __Pyx_mod_long((__pyx_v_edge_side - 2), 8); - - /* "pygeoprocessing/routing/routing.pyx":4063 - * discovery_managed_raster, discovery_nodata): - * edge_side = (edge_side-2) % 8 - * edge_dir = (edge_dir-2) % 8 # <<<<<<<<<<<<<< - * x_l += D8_XOFFSET[edge_dir] - * y_l += D8_YOFFSET[edge_dir] - */ - __pyx_v_edge_dir = __Pyx_mod_long((__pyx_v_edge_dir - 2), 8); - - /* "pygeoprocessing/routing/routing.pyx":4064 - * edge_side = (edge_side-2) % 8 - * edge_dir = (edge_dir-2) % 8 - * x_l += D8_XOFFSET[edge_dir] # <<<<<<<<<<<<<< - * y_l += D8_YOFFSET[edge_dir] - * # note the pixel moved - */ - __pyx_v_x_l = (__pyx_v_x_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_edge_dir])); - - /* "pygeoprocessing/routing/routing.pyx":4065 - * edge_dir = (edge_dir-2) % 8 - * x_l += D8_XOFFSET[edge_dir] - * y_l += D8_YOFFSET[edge_dir] # <<<<<<<<<<<<<< - * # note the pixel moved - * boundary_list.append((x_l, y_l)) - */ - __pyx_v_y_l = (__pyx_v_y_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_edge_dir])); - - /* "pygeoprocessing/routing/routing.pyx":4067 - * y_l += D8_YOFFSET[edge_dir] - * # note the pixel moved - * boundary_list.append((x_l, y_l)) # <<<<<<<<<<<<<< - * - * n_steps = 0 - */ - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_x_l); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4067, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_28 = __Pyx_PyInt_From_int(__pyx_v_y_l); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4067, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_28); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4067, __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_28); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_28); - __pyx_t_2 = 0; - __pyx_t_28 = 0; - __pyx_t_21 = __Pyx_PyList_Append(__pyx_v_boundary_list, __pyx_t_1); if (unlikely(__pyx_t_21 == ((int)-1))) __PYX_ERR(0, 4067, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4058 - * edge_side = cell_to_test - * edge_dir = (cell_to_test+2) % 8 - * if _in_watershed( # <<<<<<<<<<<<<< - * x_l, y_l, cell_to_test, discovery, finish, - * n_cols, n_rows, - */ - } - } - __pyx_L46:; - - /* "pygeoprocessing/routing/routing.pyx":4069 - * boundary_list.append((x_l, y_l)) - * - * n_steps = 0 # <<<<<<<<<<<<<< - * terminated_early = 0 - * while True: - */ - __pyx_v_n_steps = 0; - - /* "pygeoprocessing/routing/routing.pyx":4070 - * - * n_steps = 0 - * terminated_early = 0 # <<<<<<<<<<<<<< - * while True: - * # step the edge then determine the projected coordinates - */ - __pyx_v_terminated_early = 0; - - /* "pygeoprocessing/routing/routing.pyx":4071 - * n_steps = 0 - * terminated_early = 0 - * while True: # <<<<<<<<<<<<<< - * # step the edge then determine the projected coordinates - * x_f += D8_XOFFSET[edge_dir] - */ - while (1) { - - /* "pygeoprocessing/routing/routing.pyx":4073 - * while True: - * # step the edge then determine the projected coordinates - * x_f += D8_XOFFSET[edge_dir] # <<<<<<<<<<<<<< - * y_f += D8_YOFFSET[edge_dir] - * delta_x += D8_XOFFSET[edge_dir] - */ - __pyx_v_x_f = (__pyx_v_x_f + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_edge_dir])); - - /* "pygeoprocessing/routing/routing.pyx":4074 - * # step the edge then determine the projected coordinates - * x_f += D8_XOFFSET[edge_dir] - * y_f += D8_YOFFSET[edge_dir] # <<<<<<<<<<<<<< - * delta_x += D8_XOFFSET[edge_dir] - * delta_y += D8_YOFFSET[edge_dir] - */ - __pyx_v_y_f = (__pyx_v_y_f + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_edge_dir])); - - /* "pygeoprocessing/routing/routing.pyx":4075 - * x_f += D8_XOFFSET[edge_dir] - * y_f += D8_YOFFSET[edge_dir] - * delta_x += D8_XOFFSET[edge_dir] # <<<<<<<<<<<<<< - * delta_y += D8_YOFFSET[edge_dir] - * # equivalent to gdal.ApplyGeoTransform(geotransform, x_f, y_f) - */ - __pyx_v_delta_x = (__pyx_v_delta_x + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_edge_dir])); - - /* "pygeoprocessing/routing/routing.pyx":4076 - * y_f += D8_YOFFSET[edge_dir] - * delta_x += D8_XOFFSET[edge_dir] - * delta_y += D8_YOFFSET[edge_dir] # <<<<<<<<<<<<<< - * # equivalent to gdal.ApplyGeoTransform(geotransform, x_f, y_f) - * # to eliminate python function call overhead - */ - __pyx_v_delta_y = (__pyx_v_delta_y + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_edge_dir])); - - /* "pygeoprocessing/routing/routing.pyx":4079 - * # equivalent to gdal.ApplyGeoTransform(geotransform, x_f, y_f) - * # to eliminate python function call overhead - * x_p = g0 + g1*x_f + g2*y_f # <<<<<<<<<<<<<< - * y_p = g3 + g4*x_f + g5*y_f - * watershed_boundary.AddPoint(x_p, y_p) - */ - __pyx_v_x_p = ((__pyx_v_g0 + (__pyx_v_g1 * __pyx_v_x_f)) + (__pyx_v_g2 * __pyx_v_y_f)); - - /* "pygeoprocessing/routing/routing.pyx":4080 - * # to eliminate python function call overhead - * x_p = g0 + g1*x_f + g2*y_f - * y_p = g3 + g4*x_f + g5*y_f # <<<<<<<<<<<<<< - * watershed_boundary.AddPoint(x_p, y_p) - * n_steps += 1 - */ - __pyx_v_y_p = ((__pyx_v_g3 + (__pyx_v_g4 * __pyx_v_x_f)) + (__pyx_v_g5 * __pyx_v_y_f)); - - /* "pygeoprocessing/routing/routing.pyx":4081 - * x_p = g0 + g1*x_f + g2*y_f - * y_p = g3 + g4*x_f + g5*y_f - * watershed_boundary.AddPoint(x_p, y_p) # <<<<<<<<<<<<<< - * n_steps += 1 - * if n_steps > _int_max_steps_per_watershed: - */ - __pyx_t_28 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_boundary, __pyx_n_s_AddPoint); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4081, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_28); - __pyx_t_2 = PyFloat_FromDouble(__pyx_v_x_p); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4081, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = PyFloat_FromDouble(__pyx_v_y_p); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4081, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = NULL; - __pyx_t_11 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_28))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_28); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_28); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_28, function); - __pyx_t_11 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_28)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_t_2, __pyx_t_5}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_28, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4081, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_28)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_t_2, __pyx_t_5}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_28, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4081, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4081, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_11, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_11, __pyx_t_5); - __pyx_t_2 = 0; - __pyx_t_5 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_28, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4081, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4082 - * y_p = g3 + g4*x_f + g5*y_f - * watershed_boundary.AddPoint(x_p, y_p) - * n_steps += 1 # <<<<<<<<<<<<<< - * if n_steps > _int_max_steps_per_watershed: - * LOGGER.warning('quitting, too many steps') - */ - __pyx_v_n_steps = (__pyx_v_n_steps + 1); - - /* "pygeoprocessing/routing/routing.pyx":4083 - * watershed_boundary.AddPoint(x_p, y_p) - * n_steps += 1 - * if n_steps > _int_max_steps_per_watershed: # <<<<<<<<<<<<<< - * LOGGER.warning('quitting, too many steps') - * terminated_early = 1 - */ - __pyx_t_25 = ((__pyx_v_n_steps > __pyx_v__int_max_steps_per_watershed) != 0); - if (__pyx_t_25) { - - /* "pygeoprocessing/routing/routing.pyx":4084 - * n_steps += 1 - * if n_steps > _int_max_steps_per_watershed: - * LOGGER.warning('quitting, too many steps') # <<<<<<<<<<<<<< - * terminated_early = 1 - * break - */ - __Pyx_GetModuleGlobalName(__pyx_t_28, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4084, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_28); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_28, __pyx_n_s_warning); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4084, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; - __pyx_t_28 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_28 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_28)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_28); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_1 = (__pyx_t_28) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_28, __pyx_kp_u_quitting_too_many_steps) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_kp_u_quitting_too_many_steps); - __Pyx_XDECREF(__pyx_t_28); __pyx_t_28 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4084, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4085 - * if n_steps > _int_max_steps_per_watershed: - * LOGGER.warning('quitting, too many steps') - * terminated_early = 1 # <<<<<<<<<<<<<< - * break - * if x_l < 0 or y_l < 0 or x_l >= n_cols or y_l >= n_rows: - */ - __pyx_v_terminated_early = 1; - - /* "pygeoprocessing/routing/routing.pyx":4086 - * LOGGER.warning('quitting, too many steps') - * terminated_early = 1 - * break # <<<<<<<<<<<<<< - * if x_l < 0 or y_l < 0 or x_l >= n_cols or y_l >= n_rows: - * # This is unexpected but worth checking since missing this - */ - goto __pyx_L49_break; - - /* "pygeoprocessing/routing/routing.pyx":4083 - * watershed_boundary.AddPoint(x_p, y_p) - * n_steps += 1 - * if n_steps > _int_max_steps_per_watershed: # <<<<<<<<<<<<<< - * LOGGER.warning('quitting, too many steps') - * terminated_early = 1 - */ - } - - /* "pygeoprocessing/routing/routing.pyx":4087 - * terminated_early = 1 - * break - * if x_l < 0 or y_l < 0 or x_l >= n_cols or y_l >= n_rows: # <<<<<<<<<<<<<< - * # This is unexpected but worth checking since missing this - * # error would be very difficult to debug. - */ - __pyx_t_24 = ((__pyx_v_x_l < 0) != 0); - if (!__pyx_t_24) { - } else { - __pyx_t_25 = __pyx_t_24; - goto __pyx_L52_bool_binop_done; - } - __pyx_t_24 = ((__pyx_v_y_l < 0) != 0); - if (!__pyx_t_24) { - } else { - __pyx_t_25 = __pyx_t_24; - goto __pyx_L52_bool_binop_done; - } - __pyx_t_24 = ((__pyx_v_x_l >= __pyx_v_n_cols) != 0); - if (!__pyx_t_24) { - } else { - __pyx_t_25 = __pyx_t_24; - goto __pyx_L52_bool_binop_done; - } - __pyx_t_24 = ((__pyx_v_y_l >= __pyx_v_n_rows) != 0); - __pyx_t_25 = __pyx_t_24; - __pyx_L52_bool_binop_done:; - if (unlikely(__pyx_t_25)) { - - /* "pygeoprocessing/routing/routing.pyx":4091 - * # error would be very difficult to debug. - * raise RuntimeError( - * f'{x_l}, {y_l} out of bounds for ' # <<<<<<<<<<<<<< - * f'{n_cols}x{n_rows} raster.') - * if edge_side - ((edge_dir-2) % 8) == 0: - */ - __pyx_t_1 = PyTuple_New(8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4091, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_22 = 0; - __pyx_t_26 = 127; - __pyx_t_7 = __Pyx_PyUnicode_From_int(__pyx_v_x_l, 0, ' ', 'd'); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4091, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_22 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_INCREF(__pyx_kp_u_); - __pyx_t_22 += 2; - __Pyx_GIVEREF(__pyx_kp_u_); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_kp_u_); - __pyx_t_7 = __Pyx_PyUnicode_From_int(__pyx_v_y_l, 0, ' ', 'd'); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4091, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_22 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_INCREF(__pyx_kp_u_out_of_bounds_for); - __pyx_t_22 += 19; - __Pyx_GIVEREF(__pyx_kp_u_out_of_bounds_for); - PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_kp_u_out_of_bounds_for); - - /* "pygeoprocessing/routing/routing.pyx":4092 - * raise RuntimeError( - * f'{x_l}, {y_l} out of bounds for ' - * f'{n_cols}x{n_rows} raster.') # <<<<<<<<<<<<<< - * if edge_side - ((edge_dir-2) % 8) == 0: - * # counterclockwise configuration - */ - __pyx_t_7 = __Pyx_PyUnicode_From_int(__pyx_v_n_cols, 0, ' ', 'd'); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4092, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_22 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_INCREF(__pyx_n_u_x); - __pyx_t_22 += 1; - __Pyx_GIVEREF(__pyx_n_u_x); - PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_n_u_x); - __pyx_t_7 = __Pyx_PyUnicode_From_int(__pyx_v_n_rows, 0, ' ', 'd'); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4092, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_22 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_1, 6, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_INCREF(__pyx_kp_u_raster); - __pyx_t_22 += 8; - __Pyx_GIVEREF(__pyx_kp_u_raster); - PyTuple_SET_ITEM(__pyx_t_1, 7, __pyx_kp_u_raster); - - /* "pygeoprocessing/routing/routing.pyx":4091 - * # error would be very difficult to debug. - * raise RuntimeError( - * f'{x_l}, {y_l} out of bounds for ' # <<<<<<<<<<<<<< - * f'{n_cols}x{n_rows} raster.') - * if edge_side - ((edge_dir-2) % 8) == 0: - */ - __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_1, 8, __pyx_t_22, __pyx_t_26); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4091, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4090 - * # This is unexpected but worth checking since missing this - * # error would be very difficult to debug. - * raise RuntimeError( # <<<<<<<<<<<<<< - * f'{x_l}, {y_l} out of bounds for ' - * f'{n_cols}x{n_rows} raster.') - */ - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_RuntimeError, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4090, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 4090, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":4087 - * terminated_early = 1 - * break - * if x_l < 0 or y_l < 0 or x_l >= n_cols or y_l >= n_rows: # <<<<<<<<<<<<<< - * # This is unexpected but worth checking since missing this - * # error would be very difficult to debug. - */ - } - - /* "pygeoprocessing/routing/routing.pyx":4093 - * f'{x_l}, {y_l} out of bounds for ' - * f'{n_cols}x{n_rows} raster.') - * if edge_side - ((edge_dir-2) % 8) == 0: # <<<<<<<<<<<<<< - * # counterclockwise configuration - * left = edge_dir - */ - __pyx_t_25 = (((__pyx_v_edge_side - __Pyx_mod_long((__pyx_v_edge_dir - 2), 8)) == 0) != 0); - if (__pyx_t_25) { - - /* "pygeoprocessing/routing/routing.pyx":4095 - * if edge_side - ((edge_dir-2) % 8) == 0: - * # counterclockwise configuration - * left = edge_dir # <<<<<<<<<<<<<< - * right = (left-1) % 8 - * out_dir_increase = 2 - */ - __pyx_v_left = __pyx_v_edge_dir; - - /* "pygeoprocessing/routing/routing.pyx":4096 - * # counterclockwise configuration - * left = edge_dir - * right = (left-1) % 8 # <<<<<<<<<<<<<< - * out_dir_increase = 2 - * else: - */ - __pyx_v_right = __Pyx_mod_long((__pyx_v_left - 1), 8); - - /* "pygeoprocessing/routing/routing.pyx":4097 - * left = edge_dir - * right = (left-1) % 8 - * out_dir_increase = 2 # <<<<<<<<<<<<<< - * else: - * # clockwise configuration (swapping "left" and "right") - */ - __pyx_v_out_dir_increase = 2; - - /* "pygeoprocessing/routing/routing.pyx":4093 - * f'{x_l}, {y_l} out of bounds for ' - * f'{n_cols}x{n_rows} raster.') - * if edge_side - ((edge_dir-2) % 8) == 0: # <<<<<<<<<<<<<< - * # counterclockwise configuration - * left = edge_dir - */ - goto __pyx_L56; - } - - /* "pygeoprocessing/routing/routing.pyx":4100 - * else: - * # clockwise configuration (swapping "left" and "right") - * right = edge_dir # <<<<<<<<<<<<<< - * left = (edge_side+1) - * out_dir_increase = -2 - */ - /*else*/ { - __pyx_v_right = __pyx_v_edge_dir; - - /* "pygeoprocessing/routing/routing.pyx":4101 - * # clockwise configuration (swapping "left" and "right") - * right = edge_dir - * left = (edge_side+1) # <<<<<<<<<<<<<< - * out_dir_increase = -2 - * left_in = _in_watershed( - */ - __pyx_v_left = (__pyx_v_edge_side + 1); - - /* "pygeoprocessing/routing/routing.pyx":4102 - * right = edge_dir - * left = (edge_side+1) - * out_dir_increase = -2 # <<<<<<<<<<<<<< - * left_in = _in_watershed( - * x_l, y_l, left, discovery, finish, n_cols, n_rows, - */ - __pyx_v_out_dir_increase = -2; - } - __pyx_L56:; - - /* "pygeoprocessing/routing/routing.pyx":4103 - * left = (edge_side+1) - * out_dir_increase = -2 - * left_in = _in_watershed( # <<<<<<<<<<<<<< - * x_l, y_l, left, discovery, finish, n_cols, n_rows, - * discovery_managed_raster, discovery_nodata) - */ - __pyx_v_left_in = __pyx_f_15pygeoprocessing_7routing_7routing__in_watershed(__pyx_v_x_l, __pyx_v_y_l, __pyx_v_left, __pyx_v_discovery, __pyx_v_finish, __pyx_v_n_cols, __pyx_v_n_rows, __pyx_v_discovery_managed_raster, __pyx_v_discovery_nodata); - - /* "pygeoprocessing/routing/routing.pyx":4106 - * x_l, y_l, left, discovery, finish, n_cols, n_rows, - * discovery_managed_raster, discovery_nodata) - * right_in = _in_watershed( # <<<<<<<<<<<<<< - * x_l, y_l, right, discovery, finish, n_cols, n_rows, - * discovery_managed_raster, discovery_nodata) - */ - __pyx_v_right_in = __pyx_f_15pygeoprocessing_7routing_7routing__in_watershed(__pyx_v_x_l, __pyx_v_y_l, __pyx_v_right, __pyx_v_discovery, __pyx_v_finish, __pyx_v_n_cols, __pyx_v_n_rows, __pyx_v_discovery_managed_raster, __pyx_v_discovery_nodata); - - /* "pygeoprocessing/routing/routing.pyx":4109 - * x_l, y_l, right, discovery, finish, n_cols, n_rows, - * discovery_managed_raster, discovery_nodata) - * if right_in: # <<<<<<<<<<<<<< - * # turn right - * out_dir = edge_side - */ - __pyx_t_25 = (__pyx_v_right_in != 0); - if (__pyx_t_25) { - - /* "pygeoprocessing/routing/routing.pyx":4111 - * if right_in: - * # turn right - * out_dir = edge_side # <<<<<<<<<<<<<< - * edge_side = (edge_side-out_dir_increase) % 8 - * edge_dir = out_dir - */ - __pyx_v_out_dir = __pyx_v_edge_side; - - /* "pygeoprocessing/routing/routing.pyx":4112 - * # turn right - * out_dir = edge_side - * edge_side = (edge_side-out_dir_increase) % 8 # <<<<<<<<<<<<<< - * edge_dir = out_dir - * # pixel moves to be the right cell - */ - __pyx_v_edge_side = __Pyx_mod_long((__pyx_v_edge_side - __pyx_v_out_dir_increase), 8); - - /* "pygeoprocessing/routing/routing.pyx":4113 - * out_dir = edge_side - * edge_side = (edge_side-out_dir_increase) % 8 - * edge_dir = out_dir # <<<<<<<<<<<<<< - * # pixel moves to be the right cell - * x_l += D8_XOFFSET[right] - */ - __pyx_v_edge_dir = __pyx_v_out_dir; - - /* "pygeoprocessing/routing/routing.pyx":4115 - * edge_dir = out_dir - * # pixel moves to be the right cell - * x_l += D8_XOFFSET[right] # <<<<<<<<<<<<<< - * y_l += D8_YOFFSET[right] - * _diagonal_fill_step( - */ - __pyx_v_x_l = (__pyx_v_x_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_right])); - - /* "pygeoprocessing/routing/routing.pyx":4116 - * # pixel moves to be the right cell - * x_l += D8_XOFFSET[right] - * y_l += D8_YOFFSET[right] # <<<<<<<<<<<<<< - * _diagonal_fill_step( - * x_l, y_l, right, - */ - __pyx_v_y_l = (__pyx_v_y_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_right])); - - /* "pygeoprocessing/routing/routing.pyx":4117 - * x_l += D8_XOFFSET[right] - * y_l += D8_YOFFSET[right] - * _diagonal_fill_step( # <<<<<<<<<<<<<< - * x_l, y_l, right, - * discovery, finish, discovery_managed_raster, - */ - __pyx_f_15pygeoprocessing_7routing_7routing__diagonal_fill_step(__pyx_v_x_l, __pyx_v_y_l, __pyx_v_right, __pyx_v_discovery, __pyx_v_finish, __pyx_v_discovery_managed_raster, __pyx_v_discovery_nodata, __pyx_v_boundary_list); - - /* "pygeoprocessing/routing/routing.pyx":4109 - * x_l, y_l, right, discovery, finish, n_cols, n_rows, - * discovery_managed_raster, discovery_nodata) - * if right_in: # <<<<<<<<<<<<<< - * # turn right - * out_dir = edge_side - */ - goto __pyx_L57; - } - - /* "pygeoprocessing/routing/routing.pyx":4122 - * discovery_nodata, - * boundary_list) - * elif left_in: # <<<<<<<<<<<<<< - * # step forward - * x_l += D8_XOFFSET[edge_dir] - */ - __pyx_t_25 = (__pyx_v_left_in != 0); - if (__pyx_t_25) { - - /* "pygeoprocessing/routing/routing.pyx":4124 - * elif left_in: - * # step forward - * x_l += D8_XOFFSET[edge_dir] # <<<<<<<<<<<<<< - * y_l += D8_YOFFSET[edge_dir] - * # the pixel moves forward - */ - __pyx_v_x_l = (__pyx_v_x_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_edge_dir])); - - /* "pygeoprocessing/routing/routing.pyx":4125 - * # step forward - * x_l += D8_XOFFSET[edge_dir] - * y_l += D8_YOFFSET[edge_dir] # <<<<<<<<<<<<<< - * # the pixel moves forward - * boundary_list.append((x_l, y_l)) - */ - __pyx_v_y_l = (__pyx_v_y_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_edge_dir])); - - /* "pygeoprocessing/routing/routing.pyx":4127 - * y_l += D8_YOFFSET[edge_dir] - * # the pixel moves forward - * boundary_list.append((x_l, y_l)) # <<<<<<<<<<<<<< - * else: - * # turn left - */ - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_x_l); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4127, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_y_l); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4127, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_28 = PyTuple_New(2); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4127, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_28); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_28, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_28, 1, __pyx_t_7); - __pyx_t_1 = 0; - __pyx_t_7 = 0; - __pyx_t_21 = __Pyx_PyList_Append(__pyx_v_boundary_list, __pyx_t_28); if (unlikely(__pyx_t_21 == ((int)-1))) __PYX_ERR(0, 4127, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4122 - * discovery_nodata, - * boundary_list) - * elif left_in: # <<<<<<<<<<<<<< - * # step forward - * x_l += D8_XOFFSET[edge_dir] - */ - goto __pyx_L57; - } - - /* "pygeoprocessing/routing/routing.pyx":4130 - * else: - * # turn left - * edge_side = edge_dir # <<<<<<<<<<<<<< - * edge_dir = (edge_side + out_dir_increase) % 8 - * - */ - /*else*/ { - __pyx_v_edge_side = __pyx_v_edge_dir; - - /* "pygeoprocessing/routing/routing.pyx":4131 - * # turn left - * edge_side = edge_dir - * edge_dir = (edge_side + out_dir_increase) % 8 # <<<<<<<<<<<<<< - * - * if delta_x == 0 and delta_y == 0: - */ - __pyx_v_edge_dir = __Pyx_mod_long((__pyx_v_edge_side + __pyx_v_out_dir_increase), 8); - } - __pyx_L57:; - - /* "pygeoprocessing/routing/routing.pyx":4133 - * edge_dir = (edge_side + out_dir_increase) % 8 - * - * if delta_x == 0 and delta_y == 0: # <<<<<<<<<<<<<< - * # met the start point so we completed the watershed loop - * break - */ - __pyx_t_24 = ((__pyx_v_delta_x == 0) != 0); - if (__pyx_t_24) { - } else { - __pyx_t_25 = __pyx_t_24; - goto __pyx_L59_bool_binop_done; - } - __pyx_t_24 = ((__pyx_v_delta_y == 0) != 0); - __pyx_t_25 = __pyx_t_24; - __pyx_L59_bool_binop_done:; - if (__pyx_t_25) { - - /* "pygeoprocessing/routing/routing.pyx":4135 - * if delta_x == 0 and delta_y == 0: - * # met the start point so we completed the watershed loop - * break # <<<<<<<<<<<<<< - * - * watershed_feature = ogr.Feature(watershed_layer.GetLayerDefn()) - */ - goto __pyx_L49_break; - - /* "pygeoprocessing/routing/routing.pyx":4133 - * edge_dir = (edge_side + out_dir_increase) % 8 - * - * if delta_x == 0 and delta_y == 0: # <<<<<<<<<<<<<< - * # met the start point so we completed the watershed loop - * break - */ - } - } - __pyx_L49_break:; - - /* "pygeoprocessing/routing/routing.pyx":4137 - * break - * - * watershed_feature = ogr.Feature(watershed_layer.GetLayerDefn()) # <<<<<<<<<<<<<< - * watershed_polygon = ogr.Geometry(ogr.wkbPolygon) - * watershed_polygon.AddGeometry(watershed_boundary) - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4137, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_Feature); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4137, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_layer, __pyx_n_s_GetLayerDefn); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4137, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - } - } - __pyx_t_7 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4137, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __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); - } - } - __pyx_t_28 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_5, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_7); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4137, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_28); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF_SET(__pyx_v_watershed_feature, __pyx_t_28); - __pyx_t_28 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4138 - * - * watershed_feature = ogr.Feature(watershed_layer.GetLayerDefn()) - * watershed_polygon = ogr.Geometry(ogr.wkbPolygon) # <<<<<<<<<<<<<< - * watershed_polygon.AddGeometry(watershed_boundary) - * watershed_feature.SetGeometry(watershed_polygon) - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4138, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_Geometry); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4138, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4138, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_wkbPolygon); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4138, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_28 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_1, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_5); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4138, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_28); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF_SET(__pyx_v_watershed_polygon, __pyx_t_28); - __pyx_t_28 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4139 - * watershed_feature = ogr.Feature(watershed_layer.GetLayerDefn()) - * watershed_polygon = ogr.Geometry(ogr.wkbPolygon) - * watershed_polygon.AddGeometry(watershed_boundary) # <<<<<<<<<<<<<< - * watershed_feature.SetGeometry(watershed_polygon) - * watershed_feature.SetField('stream_fid', stream_fid) - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_polygon, __pyx_n_s_AddGeometry); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4139, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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); - } - } - __pyx_t_28 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_5, __pyx_v_watershed_boundary) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_watershed_boundary); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4139, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_28); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4140 - * watershed_polygon = ogr.Geometry(ogr.wkbPolygon) - * watershed_polygon.AddGeometry(watershed_boundary) - * watershed_feature.SetGeometry(watershed_polygon) # <<<<<<<<<<<<<< - * watershed_feature.SetField('stream_fid', stream_fid) - * watershed_feature.SetField('terminated_early', terminated_early) - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_feature, __pyx_n_s_SetGeometry); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4140, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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); - } - } - __pyx_t_28 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_5, __pyx_v_watershed_polygon) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_watershed_polygon); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4140, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_28); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4141 - * watershed_polygon.AddGeometry(watershed_boundary) - * watershed_feature.SetGeometry(watershed_polygon) - * watershed_feature.SetField('stream_fid', stream_fid) # <<<<<<<<<<<<<< - * watershed_feature.SetField('terminated_early', terminated_early) - * watershed_feature.SetField('outlet_x', outlet_x) - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4141, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_5 = NULL; - __pyx_t_11 = 0; - if (CYTHON_UNPACK_METHODS && likely(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); - __pyx_t_11 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_n_u_stream_fid, __pyx_v_stream_fid}; - __pyx_t_28 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4141, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_28); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_n_u_stream_fid, __pyx_v_stream_fid}; - __pyx_t_28 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4141, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_28); - } else - #endif - { - __pyx_t_1 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4141, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (__pyx_t_5) { - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5); __pyx_t_5 = NULL; - } - __Pyx_INCREF(__pyx_n_u_stream_fid); - __Pyx_GIVEREF(__pyx_n_u_stream_fid); - PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_11, __pyx_n_u_stream_fid); - __Pyx_INCREF(__pyx_v_stream_fid); - __Pyx_GIVEREF(__pyx_v_stream_fid); - PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_11, __pyx_v_stream_fid); - __pyx_t_28 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_1, NULL); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4141, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_28); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4142 - * watershed_feature.SetGeometry(watershed_polygon) - * watershed_feature.SetField('stream_fid', stream_fid) - * watershed_feature.SetField('terminated_early', terminated_early) # <<<<<<<<<<<<<< - * watershed_feature.SetField('outlet_x', outlet_x) - * watershed_feature.SetField('outlet_y', outlet_y) - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4142, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_terminated_early); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4142, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = NULL; - __pyx_t_11 = 0; - if (CYTHON_UNPACK_METHODS && likely(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); - __pyx_t_11 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_n_u_terminated_early, __pyx_t_1}; - __pyx_t_28 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4142, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_28); - __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_5, __pyx_n_u_terminated_early, __pyx_t_1}; - __pyx_t_28 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4142, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_28); - __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, 4142, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (__pyx_t_5) { - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5); __pyx_t_5 = NULL; - } - __Pyx_INCREF(__pyx_n_u_terminated_early); - __Pyx_GIVEREF(__pyx_n_u_terminated_early); - PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_11, __pyx_n_u_terminated_early); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_11, __pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_28 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_2, NULL); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4142, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_28); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4143 - * watershed_feature.SetField('stream_fid', stream_fid) - * watershed_feature.SetField('terminated_early', terminated_early) - * watershed_feature.SetField('outlet_x', outlet_x) # <<<<<<<<<<<<<< - * watershed_feature.SetField('outlet_y', outlet_y) - * watershed_layer.CreateFeature(watershed_feature) - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4143, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_outlet_x); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4143, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = NULL; - __pyx_t_11 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - __pyx_t_11 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_n_u_outlet_x, __pyx_t_2}; - __pyx_t_28 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4143, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_28); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_n_u_outlet_x, __pyx_t_2}; - __pyx_t_28 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4143, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_28); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else - #endif - { - __pyx_t_5 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4143, __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_n_u_outlet_x); - __Pyx_GIVEREF(__pyx_n_u_outlet_x); - PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_11, __pyx_n_u_outlet_x); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_11, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_28 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_5, NULL); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4143, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_28); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4144 - * watershed_feature.SetField('terminated_early', terminated_early) - * watershed_feature.SetField('outlet_x', outlet_x) - * watershed_feature.SetField('outlet_y', outlet_y) # <<<<<<<<<<<<<< - * watershed_layer.CreateFeature(watershed_feature) - * - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4144, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_outlet_y); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4144, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_2 = NULL; - __pyx_t_11 = 0; - if (CYTHON_UNPACK_METHODS && likely(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_11 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_n_u_outlet_y, __pyx_t_5}; - __pyx_t_28 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4144, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_28); - __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[3] = {__pyx_t_2, __pyx_n_u_outlet_y, __pyx_t_5}; - __pyx_t_28 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4144, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_28); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - { - __pyx_t_1 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4144, __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_n_u_outlet_y); - __Pyx_GIVEREF(__pyx_n_u_outlet_y); - PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_11, __pyx_n_u_outlet_y); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_11, __pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_28 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_1, NULL); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4144, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_28); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4145 - * watershed_feature.SetField('outlet_x', outlet_x) - * watershed_feature.SetField('outlet_y', outlet_y) - * watershed_layer.CreateFeature(watershed_feature) # <<<<<<<<<<<<<< - * - * # this loop fills in the raster at the boundary, done at end so it - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_layer, __pyx_n_s_CreateFeature); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4145, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_28 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_1, __pyx_v_watershed_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_watershed_feature); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4145, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_28); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4150 - * # doesn't interfere with the loop return to think the cells are no - * # longer in the watershed - * for boundary_x, boundary_y in boundary_list: # <<<<<<<<<<<<<< - * discovery_managed_raster.set(boundary_x, boundary_y, -1) - * watershed_layer.CommitTransaction() - */ - __pyx_t_28 = __pyx_v_boundary_list; __Pyx_INCREF(__pyx_t_28); __pyx_t_22 = 0; - for (;;) { - if (__pyx_t_22 >= PyList_GET_SIZE(__pyx_t_28)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyList_GET_ITEM(__pyx_t_28, __pyx_t_22); __Pyx_INCREF(__pyx_t_7); __pyx_t_22++; if (unlikely(0 < 0)) __PYX_ERR(0, 4150, __pyx_L1_error) - #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_28, __pyx_t_22); __pyx_t_22++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4150, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - #endif - if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) { - PyObject* sequence = __pyx_t_7; - 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, 4150, __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_5 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_1 = PyList_GET_ITEM(sequence, 0); - __pyx_t_5 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_5); - #else - __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4150, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4150, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_2 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4150, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_10 = Py_TYPE(__pyx_t_2)->tp_iternext; - index = 0; __pyx_t_1 = __pyx_t_10(__pyx_t_2); if (unlikely(!__pyx_t_1)) goto __pyx_L63_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - index = 1; __pyx_t_5 = __pyx_t_10(__pyx_t_2); if (unlikely(!__pyx_t_5)) goto __pyx_L63_unpacking_failed; - __Pyx_GOTREF(__pyx_t_5); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_2), 2) < 0) __PYX_ERR(0, 4150, __pyx_L1_error) - __pyx_t_10 = NULL; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L64_unpacking_done; - __pyx_L63_unpacking_failed:; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_10 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 4150, __pyx_L1_error) - __pyx_L64_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v_boundary_x, __pyx_t_1); - __pyx_t_1 = 0; - __Pyx_XDECREF_SET(__pyx_v_boundary_y, __pyx_t_5); - __pyx_t_5 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4151 - * # longer in the watershed - * for boundary_x, boundary_y in boundary_list: - * discovery_managed_raster.set(boundary_x, boundary_y, -1) # <<<<<<<<<<<<<< - * watershed_layer.CommitTransaction() - * watershed_layer = None - */ - __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_v_boundary_x); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4151, __pyx_L1_error) - __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_v_boundary_y); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4151, __pyx_L1_error) - __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_discovery_managed_raster, __pyx_t_11, __pyx_t_8, -1.0); - - /* "pygeoprocessing/routing/routing.pyx":4150 - * # doesn't interfere with the loop return to think the cells are no - * # longer in the watershed - * for boundary_x, boundary_y in boundary_list: # <<<<<<<<<<<<<< - * discovery_managed_raster.set(boundary_x, boundary_y, -1) - * watershed_layer.CommitTransaction() - */ - } - __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4011 - * cdef int _int_max_steps_per_watershed = max_steps_per_watershed - * - * for index, (stream_fid, x_l, y_l) in enumerate(visit_order_stack): # <<<<<<<<<<<<<< - * if ctime(NULL) - last_log_time > _LOGGING_PERIOD: - * LOGGER.info( - */ - __pyx_L37_continue:; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4152 - * for boundary_x, boundary_y in boundary_list: - * discovery_managed_raster.set(boundary_x, boundary_y, -1) - * watershed_layer.CommitTransaction() # <<<<<<<<<<<<<< - * watershed_layer = None - * watershed_vector = None - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_layer, __pyx_n_s_CommitTransaction); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4152, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_28 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_28 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_28)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_28); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - __pyx_t_6 = (__pyx_t_28) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_28) : __Pyx_PyObject_CallNoArg(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_28); __pyx_t_28 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4152, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4153 - * discovery_managed_raster.set(boundary_x, boundary_y, -1) - * watershed_layer.CommitTransaction() - * watershed_layer = None # <<<<<<<<<<<<<< - * watershed_vector = None - * discovery_managed_raster.close() - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_watershed_layer, Py_None); - - /* "pygeoprocessing/routing/routing.pyx":4154 - * watershed_layer.CommitTransaction() - * watershed_layer = None - * watershed_vector = None # <<<<<<<<<<<<<< - * discovery_managed_raster.close() - * finish_managed_raster.close() - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_watershed_vector, Py_None); - - /* "pygeoprocessing/routing/routing.pyx":4155 - * watershed_layer = None - * watershed_vector = None - * discovery_managed_raster.close() # <<<<<<<<<<<<<< - * finish_managed_raster.close() - * shutil.rmtree(workspace_dir) - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_discovery_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4155, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_28 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_28 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_28)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_28); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - __pyx_t_6 = (__pyx_t_28) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_28) : __Pyx_PyObject_CallNoArg(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_28); __pyx_t_28 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4155, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4156 - * watershed_vector = None - * discovery_managed_raster.close() - * finish_managed_raster.close() # <<<<<<<<<<<<<< - * shutil.rmtree(workspace_dir) - * LOGGER.info( - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_finish_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4156, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_28 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_28 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_28)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_28); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - __pyx_t_6 = (__pyx_t_28) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_28) : __Pyx_PyObject_CallNoArg(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_28); __pyx_t_28 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4156, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4157 - * discovery_managed_raster.close() - * finish_managed_raster.close() - * shutil.rmtree(workspace_dir) # <<<<<<<<<<<<<< - * LOGGER.info( - * '(calculate_subwatershed_boundary): watershed building 100% complete') - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_shutil); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4157, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_28 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_rmtree); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4157, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_28); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_28))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_28); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_28); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_28, function); - } - } - __pyx_t_6 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_28, __pyx_t_4, __pyx_v_workspace_dir) : __Pyx_PyObject_CallOneArg(__pyx_t_28, __pyx_v_workspace_dir); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4157, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4158 - * finish_managed_raster.close() - * shutil.rmtree(workspace_dir) - * LOGGER.info( # <<<<<<<<<<<<<< - * '(calculate_subwatershed_boundary): watershed building 100% complete') - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_28, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 4158, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_28); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_28, __pyx_n_s_info); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4158, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0; - __pyx_t_28 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_28 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_28)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_28); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - __pyx_t_6 = (__pyx_t_28) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_28, __pyx_kp_u_calculate_subwatershed_boundary_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_calculate_subwatershed_boundary_3); - __Pyx_XDECREF(__pyx_t_28); __pyx_t_28 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4158, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3830 - * - * - * def calculate_subwatershed_boundary( # <<<<<<<<<<<<<< - * d8_flow_dir_raster_path_band, - * strahler_stream_vector_path, target_watershed_boundary_vector_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_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_28); - __Pyx_AddTraceback("pygeoprocessing.routing.routing.calculate_subwatershed_boundary", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_workspace_dir); - __Pyx_XDECREF(__pyx_v_discovery_time_raster_path); - __Pyx_XDECREF(__pyx_v_finish_time_raster_path); - __Pyx_XDECREF((PyObject *)__pyx_v_discovery_managed_raster); - __Pyx_XDECREF((PyObject *)__pyx_v_finish_managed_raster); - __Pyx_XDECREF((PyObject *)__pyx_v_d8_flow_dir_managed_raster); - __Pyx_XDECREF(__pyx_v_discovery_info); - __Pyx_XDECREF(__pyx_v_geotransform); - __Pyx_XDECREF(__pyx_v_discovery_srs); - __Pyx_XDECREF(__pyx_v_gpkg_driver); - __Pyx_XDECREF(__pyx_v_watershed_vector); - __Pyx_XDECREF(__pyx_v_watershed_basename); - __Pyx_XDECREF(__pyx_v_watershed_layer); - __Pyx_XDECREF(__pyx_v_stream_vector); - __Pyx_XDECREF(__pyx_v_stream_layer); - __Pyx_XDECREF(__pyx_v_upstream_fid_map); - __Pyx_XDECREF(__pyx_v_stream_feature); - __Pyx_XDECREF(__pyx_v_ds_x); - __Pyx_XDECREF(__pyx_v_ds_y); - __Pyx_XDECREF(__pyx_v_visit_order_stack); - __Pyx_XDECREF(__pyx_v__); - __Pyx_XDECREF(__pyx_v_outlet_fid); - __Pyx_XDECREF(__pyx_v_working_stack); - __Pyx_XDECREF(__pyx_v_processed_nodes); - __Pyx_XDECREF(__pyx_v_working_fid); - __Pyx_XDECREF(__pyx_v_working_feature); - __Pyx_XDECREF(__pyx_v_us_x); - __Pyx_XDECREF(__pyx_v_us_y); - __Pyx_XDECREF(__pyx_v_ds_x_1); - __Pyx_XDECREF(__pyx_v_ds_y_1); - __Pyx_XDECREF(__pyx_v_upstream_coord); - __Pyx_XDECREF(__pyx_v_upstream_fids); - __Pyx_XDECREF(__pyx_v_index); - __Pyx_XDECREF(__pyx_v_stream_fid); - __Pyx_XDECREF(__pyx_v_boundary_list); - __Pyx_XDECREF(__pyx_v_watershed_boundary); - __Pyx_XDECREF(__pyx_v_watershed_feature); - __Pyx_XDECREF(__pyx_v_watershed_polygon); - __Pyx_XDECREF(__pyx_v_boundary_x); - __Pyx_XDECREF(__pyx_v_boundary_y); - __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_x); - __Pyx_XDECREF(__pyx_8genexpr3__pyx_v_fid); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pygeoprocessing/routing/routing.pyx":4162 - * - * - * def detect_outlets( # <<<<<<<<<<<<<< - * flow_dir_raster_path_band, flow_dir_type, target_outlet_vector_path): - * """Create point vector indicating flow raster outlets. - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_27detect_outlets(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_15pygeoprocessing_7routing_7routing_26detect_outlets[] = "Create point vector indicating flow raster outlets.\n\n If either D8 or MFD rasters have a flow direction to the edge of the\n raster or to a nodata flow direction pixel the originating pixel is\n considered an outlet.\n\n Args:\n flow_dir_raster_path_band (tuple): raster path/band tuple\n indicating D8 or MFD flow direction created by\n `routing.flow_dir_d8` or `routing.flow_dir_mfd`.\n flow_dir_type (str): one of 'd8' or 'mfd' to indicate the\n ``flow_dir_raster_path_band`` is either a D8 or MFD flow\n direction raster.\n target_outlet_vector_path (str): path to a vector that is created\n by this call that will be in the same projection units as the\n raster and have a point feature in the center of each pixel that\n is a raster outlet. Additional fields include:\n\n * \"i\" - the column raster coordinate where the outlet exists\n * \"j\" - the row raster coordinate where the outlet exists\n * \"ID\" - unique identification for the outlet.\n\n Return:\n None.\n "; -static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_27detect_outlets = {"detect_outlets", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_7routing_7routing_27detect_outlets, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_7routing_7routing_26detect_outlets}; -static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_27detect_outlets(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_flow_dir_raster_path_band = 0; - PyObject *__pyx_v_flow_dir_type = 0; - PyObject *__pyx_v_target_outlet_vector_path = 0; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("detect_outlets (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_flow_dir_raster_path_band,&__pyx_n_s_flow_dir_type,&__pyx_n_s_target_outlet_vector_path,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_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_flow_dir_type)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("detect_outlets", 1, 3, 3, 1); __PYX_ERR(0, 4162, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_outlet_vector_path)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("detect_outlets", 1, 3, 3, 2); __PYX_ERR(0, 4162, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "detect_outlets") < 0)) __PYX_ERR(0, 4162, __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_flow_dir_raster_path_band = values[0]; - __pyx_v_flow_dir_type = values[1]; - __pyx_v_target_outlet_vector_path = values[2]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("detect_outlets", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 4162, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pygeoprocessing.routing.routing.detect_outlets", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing_26detect_outlets(__pyx_self, __pyx_v_flow_dir_raster_path_band, __pyx_v_flow_dir_type, __pyx_v_target_outlet_vector_path); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_26detect_outlets(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_flow_dir_raster_path_band, PyObject *__pyx_v_flow_dir_type, PyObject *__pyx_v_target_outlet_vector_path) { - int __pyx_v_d8_flow_dir_mode; - 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_raster_x_size; - int __pyx_v_raster_y_size; - int __pyx_v_flow_dir; - int __pyx_v_flow_dir_n; - int __pyx_v_next_id; - int __pyx_v_n_dir; - int __pyx_v_is_outlet; - char __pyx_v_x_off_border; - char __pyx_v_y_off_border; - char __pyx_v_win_xsize_border; - char __pyx_v_win_ysize_border; - PyArrayObject *__pyx_v_flow_dir_block = 0; - PyObject *__pyx_v_raster_info = NULL; - int __pyx_v_flow_dir_nodata; - PyObject *__pyx_v_flow_dir_raster = NULL; - PyObject *__pyx_v_flow_dir_band = NULL; - PyObject *__pyx_v_raster_srs = NULL; - PyObject *__pyx_v_gpkg_driver = NULL; - PyObject *__pyx_v_outlet_vector = NULL; - PyObject *__pyx_v_outet_basename = NULL; - PyObject *__pyx_v_outlet_layer = NULL; - time_t __pyx_v_last_log_time; - PyObject *__pyx_v_block_offsets = NULL; - PyObject *__pyx_v_current_pixel = NULL; - PyObject *__pyx_v_outlet_point = NULL; - PyObject *__pyx_v_proj_x = NULL; - PyObject *__pyx_v_proj_y = NULL; - PyObject *__pyx_v_outlet_feature = NULL; - __Pyx_LocalBuf_ND __pyx_pybuffernd_flow_dir_block; - __Pyx_Buffer __pyx_pybuffer_flow_dir_block; - 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; - int __pyx_t_5; - int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - PyObject *(*__pyx_t_8)(PyObject *); - int __pyx_t_9; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - Py_ssize_t __pyx_t_12; - Py_UCS4 __pyx_t_13; - PyObject *__pyx_t_14 = NULL; - 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; - long __pyx_t_20; - long __pyx_t_21; - Py_ssize_t __pyx_t_22; - long __pyx_t_23; - long __pyx_t_24; - Py_ssize_t __pyx_t_25; - Py_ssize_t __pyx_t_26; - int __pyx_t_27; - int __pyx_t_28; - PyObject *__pyx_t_29 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("detect_outlets", 0); - __Pyx_INCREF(__pyx_v_flow_dir_type); - __pyx_pybuffer_flow_dir_block.pybuffer.buf = NULL; - __pyx_pybuffer_flow_dir_block.refcount = 0; - __pyx_pybuffernd_flow_dir_block.data = NULL; - __pyx_pybuffernd_flow_dir_block.rcbuffer = &__pyx_pybuffer_flow_dir_block; - - /* "pygeoprocessing/routing/routing.pyx":4189 - * None. - * """ - * flow_dir_type = flow_dir_type.lower() # <<<<<<<<<<<<<< - * if flow_dir_type not in ['d8', 'mfd']: - * raise ValueError( - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_type, __pyx_n_s_lower); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4189, __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); - } - } - __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4189, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF_SET(__pyx_v_flow_dir_type, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4190 - * """ - * flow_dir_type = flow_dir_type.lower() - * if flow_dir_type not in ['d8', 'mfd']: # <<<<<<<<<<<<<< - * raise ValueError( - * f'expected flow dir type of either d8 or mfd but got ' - */ - __Pyx_INCREF(__pyx_v_flow_dir_type); - __pyx_t_1 = __pyx_v_flow_dir_type; - __pyx_t_5 = (__Pyx_PyUnicode_Equals(__pyx_t_1, __pyx_n_u_d8, Py_NE)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 4190, __pyx_L1_error) - if (__pyx_t_5) { - } else { - __pyx_t_4 = __pyx_t_5; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_5 = (__Pyx_PyUnicode_Equals(__pyx_t_1, __pyx_n_u_mfd, Py_NE)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 4190, __pyx_L1_error) - __pyx_t_4 = __pyx_t_5; - __pyx_L4_bool_binop_done:; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_5 = (__pyx_t_4 != 0); - if (unlikely(__pyx_t_5)) { - - /* "pygeoprocessing/routing/routing.pyx":4193 - * raise ValueError( - * f'expected flow dir type of either d8 or mfd but got ' - * f'{flow_dir_type}') # <<<<<<<<<<<<<< - * cdef int d8_flow_dir_mode = (flow_dir_type == 'd8') - * - */ - __pyx_t_1 = __Pyx_PyObject_FormatSimple(__pyx_v_flow_dir_type, __pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4193, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":4192 - * if flow_dir_type not in ['d8', 'mfd']: - * raise ValueError( - * f'expected flow dir type of either d8 or mfd but got ' # <<<<<<<<<<<<<< - * f'{flow_dir_type}') - * cdef int d8_flow_dir_mode = (flow_dir_type == 'd8') - */ - __pyx_t_2 = __Pyx_PyUnicode_Concat(__pyx_kp_u_expected_flow_dir_type_of_either, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4192, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4191 - * flow_dir_type = flow_dir_type.lower() - * if flow_dir_type not in ['d8', 'mfd']: - * raise ValueError( # <<<<<<<<<<<<<< - * f'expected flow dir type of either d8 or mfd but got ' - * f'{flow_dir_type}') - */ - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4191, __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, 4191, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":4190 - * """ - * flow_dir_type = flow_dir_type.lower() - * if flow_dir_type not in ['d8', 'mfd']: # <<<<<<<<<<<<<< - * raise ValueError( - * f'expected flow dir type of either d8 or mfd but got ' - */ - } - - /* "pygeoprocessing/routing/routing.pyx":4194 - * f'expected flow dir type of either d8 or mfd but got ' - * f'{flow_dir_type}') - * cdef int d8_flow_dir_mode = (flow_dir_type == 'd8') # <<<<<<<<<<<<<< - * - * cdef int xoff, yoff, win_xsize, win_ysize, xi, yi - */ - __pyx_t_1 = PyObject_RichCompare(__pyx_v_flow_dir_type, __pyx_n_u_d8, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4194, __pyx_L1_error) - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4194, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_d8_flow_dir_mode = __pyx_t_6; - - /* "pygeoprocessing/routing/routing.pyx":4199 - * cdef int xi_root, yi_root, raster_x_size, raster_y_size - * cdef int flow_dir, flow_dir_n - * cdef int next_id=0, n_dir, is_outlet # <<<<<<<<<<<<<< - * cdef char x_off_border, y_off_border, win_xsize_border, win_ysize_border - * - */ - __pyx_v_next_id = 0; - - /* "pygeoprocessing/routing/routing.pyx":4204 - * cdef numpy.ndarray[numpy.npy_int32, ndim=2] flow_dir_block - * - * raster_info = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< - * flow_dir_raster_path_band[0]) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4204, __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, 4204, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4205 - * - * raster_info = pygeoprocessing.get_raster_info( - * flow_dir_raster_path_band[0]) # <<<<<<<<<<<<<< - * - * cdef int flow_dir_nodata = raster_info['nodata'][ - */ - __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_flow_dir_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4205, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_7, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4204, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_raster_info = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4207 - * flow_dir_raster_path_band[0]) - * - * cdef int flow_dir_nodata = raster_info['nodata'][ # <<<<<<<<<<<<<< - * flow_dir_raster_path_band[1]-1] - * - */ - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4207, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/routing.pyx":4208 - * - * cdef int flow_dir_nodata = raster_info['nodata'][ - * flow_dir_raster_path_band[1]-1] # <<<<<<<<<<<<<< - * - * raster_x_size, raster_y_size = raster_info['raster_size'] - */ - __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_flow_dir_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4208, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_t_3, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4208, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4207 - * flow_dir_raster_path_band[0]) - * - * cdef int flow_dir_nodata = raster_info['nodata'][ # <<<<<<<<<<<<<< - * flow_dir_raster_path_band[1]-1] - * - */ - __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4207, __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_6 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4207, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_flow_dir_nodata = __pyx_t_6; - - /* "pygeoprocessing/routing/routing.pyx":4210 - * flow_dir_raster_path_band[1]-1] - * - * raster_x_size, raster_y_size = raster_info['raster_size'] # <<<<<<<<<<<<<< - * - * flow_dir_raster = gdal.OpenEx( - */ - __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4210, __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, 4210, __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_1 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_2 = PyList_GET_ITEM(sequence, 0); - __pyx_t_1 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_1); - #else - __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4210, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4210, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_7 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4210, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; - index = 0; __pyx_t_2 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_2)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - index = 1; __pyx_t_1 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_1)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 4210, __pyx_L1_error) - __pyx_t_8 = NULL; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L7_unpacking_done; - __pyx_L6_unpacking_failed:; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_8 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 4210, __pyx_L1_error) - __pyx_L7_unpacking_done:; - } - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4210, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4210, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_raster_x_size = __pyx_t_6; - __pyx_v_raster_y_size = __pyx_t_9; - - /* "pygeoprocessing/routing/routing.pyx":4212 - * raster_x_size, raster_y_size = raster_info['raster_size'] - * - * flow_dir_raster = gdal.OpenEx( # <<<<<<<<<<<<<< - * flow_dir_raster_path_band[0], gdal.OF_RASTER) - * flow_dir_band = flow_dir_raster.GetRasterBand( - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4212, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4212, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4213 - * - * 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_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, 4213, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4213, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4213, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - __pyx_t_9 = 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_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_1, __pyx_t_10}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4212, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_1, __pyx_t_10}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4212, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } else - #endif - { - __pyx_t_11 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4212, __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_1); - PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_9, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_9, __pyx_t_10); - __pyx_t_1 = 0; - __pyx_t_10 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_11, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4212, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_flow_dir_raster = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4214 - * 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_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4214, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - - /* "pygeoprocessing/routing/routing.pyx":4215 - * flow_dir_raster_path_band[0], gdal.OF_RASTER) - * flow_dir_band = flow_dir_raster.GetRasterBand( - * flow_dir_raster_path_band[1]) # <<<<<<<<<<<<<< - * - * if raster_info['projection_wkt']: - */ - __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_flow_dir_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4215, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_10 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_10)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_3 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_10, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_11); - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4214, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_flow_dir_band = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4217 - * flow_dir_raster_path_band[1]) - * - * if raster_info['projection_wkt']: # <<<<<<<<<<<<<< - * raster_srs = osr.SpatialReference() - * raster_srs.ImportFromWkt(raster_info['projection_wkt']) - */ - __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_projection_wkt); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4217, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 4217, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":4218 - * - * if raster_info['projection_wkt']: - * raster_srs = osr.SpatialReference() # <<<<<<<<<<<<<< - * raster_srs.ImportFromWkt(raster_info['projection_wkt']) - * else: - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_osr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4218, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_SpatialReference); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4218, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(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); - } - } - __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4218, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_v_raster_srs = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4219 - * if raster_info['projection_wkt']: - * raster_srs = osr.SpatialReference() - * raster_srs.ImportFromWkt(raster_info['projection_wkt']) # <<<<<<<<<<<<<< - * else: - * raster_srs = None - */ - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster_srs, __pyx_n_s_ImportFromWkt); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4219, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_projection_wkt); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4219, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_10 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_10)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - } - } - __pyx_t_3 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_10, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4219, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4217 - * flow_dir_raster_path_band[1]) - * - * if raster_info['projection_wkt']: # <<<<<<<<<<<<<< - * raster_srs = osr.SpatialReference() - * raster_srs.ImportFromWkt(raster_info['projection_wkt']) - */ - goto __pyx_L8; - } - - /* "pygeoprocessing/routing/routing.pyx":4221 - * raster_srs.ImportFromWkt(raster_info['projection_wkt']) - * else: - * raster_srs = None # <<<<<<<<<<<<<< - * - * gpkg_driver = gdal.GetDriverByName('GPKG') - */ - /*else*/ { - __Pyx_INCREF(Py_None); - __pyx_v_raster_srs = Py_None; - } - __pyx_L8:; - - /* "pygeoprocessing/routing/routing.pyx":4223 - * raster_srs = None - * - * gpkg_driver = gdal.GetDriverByName('GPKG') # <<<<<<<<<<<<<< - * - * if os.path.exists(target_outlet_vector_path): - */ - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_gdal); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4223, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_GetDriverByName); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4223, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = NULL; - 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_3 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_11, __pyx_n_u_GPKG) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_n_u_GPKG); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4223, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_gpkg_driver = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4225 - * gpkg_driver = gdal.GetDriverByName('GPKG') - * - * if os.path.exists(target_outlet_vector_path): # <<<<<<<<<<<<<< - * LOGGER.warning( - * f'outlet detection: {target_outlet_vector_path} exists, ' - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4225, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_path); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4225, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_exists); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4225, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_3 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_11, __pyx_v_target_outlet_vector_path) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_target_outlet_vector_path); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4225, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 4225, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":4226 - * - * if os.path.exists(target_outlet_vector_path): - * LOGGER.warning( # <<<<<<<<<<<<<< - * f'outlet detection: {target_outlet_vector_path} exists, ' - * 'removing before creating a new one.') - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4226, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_warning); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4226, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4227 - * if os.path.exists(target_outlet_vector_path): - * LOGGER.warning( - * f'outlet detection: {target_outlet_vector_path} exists, ' # <<<<<<<<<<<<<< - * 'removing before creating a new one.') - * os.remove(target_outlet_vector_path) - */ - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4227, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_12 = 0; - __pyx_t_13 = 127; - __Pyx_INCREF(__pyx_kp_u_outlet_detection); - __pyx_t_12 += 18; - __Pyx_GIVEREF(__pyx_kp_u_outlet_detection); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_u_outlet_detection); - __pyx_t_10 = __Pyx_PyObject_FormatSimple(__pyx_v_target_outlet_vector_path, __pyx_empty_unicode); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4227, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_13 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_10) > __pyx_t_13) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_10) : __pyx_t_13; - __pyx_t_12 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_10); - __pyx_t_10 = 0; - __Pyx_INCREF(__pyx_kp_u_exists_removing_before_creating); - __pyx_t_12 += 44; - __Pyx_GIVEREF(__pyx_kp_u_exists_removing_before_creating); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_kp_u_exists_removing_before_creating); - __pyx_t_10 = __Pyx_PyUnicode_Join(__pyx_t_2, 3, __pyx_t_12, __pyx_t_13); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4227, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(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); - } - } - __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_2, __pyx_t_10) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_10); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4226, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4229 - * f'outlet detection: {target_outlet_vector_path} exists, ' - * 'removing before creating a new one.') - * os.remove(target_outlet_vector_path) # <<<<<<<<<<<<<< - * outlet_vector = gpkg_driver.Create( - * target_outlet_vector_path, 0, 0, 0, gdal.GDT_Unknown) - */ - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_os); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4229, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_remove); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4229, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_10); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_10, function); - } - } - __pyx_t_3 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_11, __pyx_v_target_outlet_vector_path) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_v_target_outlet_vector_path); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4229, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4225 - * gpkg_driver = gdal.GetDriverByName('GPKG') - * - * if os.path.exists(target_outlet_vector_path): # <<<<<<<<<<<<<< - * LOGGER.warning( - * f'outlet detection: {target_outlet_vector_path} exists, ' - */ - } - - /* "pygeoprocessing/routing/routing.pyx":4230 - * 'removing before creating a new one.') - * os.remove(target_outlet_vector_path) - * outlet_vector = gpkg_driver.Create( # <<<<<<<<<<<<<< - * target_outlet_vector_path, 0, 0, 0, gdal.GDT_Unknown) - * outet_basename = os.path.basename( - */ - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_gpkg_driver, __pyx_n_s_Create); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4230, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - - /* "pygeoprocessing/routing/routing.pyx":4231 - * os.remove(target_outlet_vector_path) - * outlet_vector = gpkg_driver.Create( - * target_outlet_vector_path, 0, 0, 0, gdal.GDT_Unknown) # <<<<<<<<<<<<<< - * outet_basename = os.path.basename( - * os.path.splitext(target_outlet_vector_path)[0]) - */ - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_gdal); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4231, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_GDT_Unknown); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4231, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_10); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_10, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[6] = {__pyx_t_11, __pyx_v_target_outlet_vector_path, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_t_2}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_9, 5+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4230, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 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_10)) { - PyObject *__pyx_temp[6] = {__pyx_t_11, __pyx_v_target_outlet_vector_path, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_t_2}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_9, 5+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4230, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else - #endif - { - __pyx_t_1 = PyTuple_New(5+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4230, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (__pyx_t_11) { - __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_11); __pyx_t_11 = NULL; - } - __Pyx_INCREF(__pyx_v_target_outlet_vector_path); - __Pyx_GIVEREF(__pyx_v_target_outlet_vector_path); - PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_9, __pyx_v_target_outlet_vector_path); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_9, __pyx_int_0); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_1, 2+__pyx_t_9, __pyx_int_0); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_1, 3+__pyx_t_9, __pyx_int_0); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_1, 4+__pyx_t_9, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4230, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_v_outlet_vector = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4232 - * outlet_vector = gpkg_driver.Create( - * target_outlet_vector_path, 0, 0, 0, gdal.GDT_Unknown) - * outet_basename = os.path.basename( # <<<<<<<<<<<<<< - * os.path.splitext(target_outlet_vector_path)[0]) - * outlet_layer = outlet_vector.CreateLayer( - */ - __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_os); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4232, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4232, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_basename); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4232, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4233 - * target_outlet_vector_path, 0, 0, 0, gdal.GDT_Unknown) - * outet_basename = os.path.basename( - * os.path.splitext(target_outlet_vector_path)[0]) # <<<<<<<<<<<<<< - * outlet_layer = outlet_vector.CreateLayer( - * outet_basename, raster_srs, ogr.wkbPoint) - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4233, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_path); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4233, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_splitext); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4233, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_1 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_11, __pyx_v_target_outlet_vector_path) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_target_outlet_vector_path); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4233, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4233, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_10); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_10, function); - } - } - __pyx_t_3 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_1, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4232, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_v_outet_basename = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4234 - * outet_basename = os.path.basename( - * os.path.splitext(target_outlet_vector_path)[0]) - * outlet_layer = outlet_vector.CreateLayer( # <<<<<<<<<<<<<< - * outet_basename, raster_srs, ogr.wkbPoint) - * # i and j indicate the coordinates of the point in raster space whereas - */ - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_vector, __pyx_n_s_CreateLayer); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4234, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - - /* "pygeoprocessing/routing/routing.pyx":4235 - * os.path.splitext(target_outlet_vector_path)[0]) - * outlet_layer = outlet_vector.CreateLayer( - * outet_basename, raster_srs, ogr.wkbPoint) # <<<<<<<<<<<<<< - * # i and j indicate the coordinates of the point in raster space whereas - * # the geometry is in projected space - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_ogr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4235, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_wkbPoint); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4235, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && likely(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); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_v_outet_basename, __pyx_v_raster_srs, __pyx_t_1}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4234, __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[4] = {__pyx_t_2, __pyx_v_outet_basename, __pyx_v_raster_srs, __pyx_t_1}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4234, __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_11 = PyTuple_New(3+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4234, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - if (__pyx_t_2) { - __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_2); __pyx_t_2 = NULL; - } - __Pyx_INCREF(__pyx_v_outet_basename); - __Pyx_GIVEREF(__pyx_v_outet_basename); - PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_9, __pyx_v_outet_basename); - __Pyx_INCREF(__pyx_v_raster_srs); - __Pyx_GIVEREF(__pyx_v_raster_srs); - PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_9, __pyx_v_raster_srs); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_11, 2+__pyx_t_9, __pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_11, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4234, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_v_outlet_layer = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4238 - * # i and j indicate the coordinates of the point in raster space whereas - * # the geometry is in projected space - * outlet_layer.CreateField(ogr.FieldDefn('i', ogr.OFTInteger)) # <<<<<<<<<<<<<< - * outlet_layer.CreateField(ogr.FieldDefn('j', ogr.OFTInteger)) - * outlet_layer.CreateField(ogr.FieldDefn('ID', ogr.OFTInteger)) - */ - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4238, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4238, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4238, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4238, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4238, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_n_u_i, __pyx_t_7}; - __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4238, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_n_u_i, __pyx_t_7}; - __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4238, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - { - __pyx_t_14 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4238, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - if (__pyx_t_1) { - __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_1); __pyx_t_1 = NULL; - } - __Pyx_INCREF(__pyx_n_u_i); - __Pyx_GIVEREF(__pyx_n_u_i); - PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_9, __pyx_n_u_i); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_9, __pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_14, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4238, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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); - } - } - __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_2, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_11); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4238, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4239 - * # the geometry is in projected space - * outlet_layer.CreateField(ogr.FieldDefn('i', ogr.OFTInteger)) - * outlet_layer.CreateField(ogr.FieldDefn('j', ogr.OFTInteger)) # <<<<<<<<<<<<<< - * outlet_layer.CreateField(ogr.FieldDefn('ID', ogr.OFTInteger)) - * outlet_layer.StartTransaction() - */ - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4239, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_ogr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4239, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4239, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_ogr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4239, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4239, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __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_14))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_14)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_n_u_j, __pyx_t_7}; - __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4239, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_n_u_j, __pyx_t_7}; - __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4239, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - { - __pyx_t_1 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4239, __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_n_u_j); - __Pyx_GIVEREF(__pyx_n_u_j); - PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_9, __pyx_n_u_j); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_9, __pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_1, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4239, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_14 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { - __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_10); - if (likely(__pyx_t_14)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); - __Pyx_INCREF(__pyx_t_14); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_10, function); - } - } - __pyx_t_3 = (__pyx_t_14) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_14, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_11); - __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4239, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4240 - * outlet_layer.CreateField(ogr.FieldDefn('i', ogr.OFTInteger)) - * outlet_layer.CreateField(ogr.FieldDefn('j', ogr.OFTInteger)) - * outlet_layer.CreateField(ogr.FieldDefn('ID', ogr.OFTInteger)) # <<<<<<<<<<<<<< - * outlet_layer.StartTransaction() - * - */ - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4240, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_ogr); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4240, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4240, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_ogr); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4240, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4240, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_14 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_14)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_14); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_14, __pyx_n_u_ID, __pyx_t_7}; - __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4240, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_14, __pyx_n_u_ID, __pyx_t_7}; - __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4240, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - { - __pyx_t_2 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4240, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (__pyx_t_14) { - __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_14); __pyx_t_14 = NULL; - } - __Pyx_INCREF(__pyx_n_u_ID); - __Pyx_GIVEREF(__pyx_n_u_ID); - PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_9, __pyx_n_u_ID); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_9, __pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4240, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_10); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_10, function); - } - } - __pyx_t_3 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_1, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_11); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4240, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4241 - * outlet_layer.CreateField(ogr.FieldDefn('j', ogr.OFTInteger)) - * outlet_layer.CreateField(ogr.FieldDefn('ID', ogr.OFTInteger)) - * outlet_layer.StartTransaction() # <<<<<<<<<<<<<< - * - * cdef time_t last_log_time = ctime(NULL) - */ - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_layer, __pyx_n_s_StartTransaction); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4241, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_10); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_10, function); - } - } - __pyx_t_3 = (__pyx_t_11) ? __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_11) : __Pyx_PyObject_CallNoArg(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4241, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4243 - * outlet_layer.StartTransaction() - * - * cdef time_t last_log_time = ctime(NULL) # <<<<<<<<<<<<<< - * # iterate by iterblocks so ReadAsArray can efficiently cache reads - * # and writes - */ - __pyx_v_last_log_time = time(NULL); - - /* "pygeoprocessing/routing/routing.pyx":4246 - * # iterate by iterblocks so ReadAsArray can efficiently cache reads - * # and writes - * LOGGER.info('outlet detection: 0% complete') # <<<<<<<<<<<<<< - * for block_offsets in pygeoprocessing.iterblocks( - * flow_dir_raster_path_band, offset_only=True): - */ - __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4246, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_info); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4246, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_10)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - } - } - __pyx_t_3 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_10, __pyx_kp_u_outlet_detection_0_complete) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_kp_u_outlet_detection_0_complete); - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4246, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4247 - * # and writes - * LOGGER.info('outlet detection: 0% complete') - * for block_offsets in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * flow_dir_raster_path_band, offset_only=True): - * xoff = block_offsets['xoff'] - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4247, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4247, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4248 - * LOGGER.info('outlet detection: 0% complete') - * for block_offsets in pygeoprocessing.iterblocks( - * flow_dir_raster_path_band, offset_only=True): # <<<<<<<<<<<<<< - * xoff = block_offsets['xoff'] - * yoff = block_offsets['yoff'] - */ - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4247, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_flow_dir_raster_path_band); - __Pyx_GIVEREF(__pyx_v_flow_dir_raster_path_band); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_flow_dir_raster_path_band); - __pyx_t_10 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4248, __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, 4248, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":4247 - * # and writes - * LOGGER.info('outlet detection: 0% complete') - * for block_offsets in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * flow_dir_raster_path_band, offset_only=True): - * xoff = block_offsets['xoff'] - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_3, __pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4247, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { - __pyx_t_10 = __pyx_t_1; __Pyx_INCREF(__pyx_t_10); __pyx_t_12 = 0; - __pyx_t_15 = NULL; - } else { - __pyx_t_12 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4247, __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, 4247, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - for (;;) { - if (likely(!__pyx_t_15)) { - if (likely(PyList_CheckExact(__pyx_t_10))) { - if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_10)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_12); __Pyx_INCREF(__pyx_t_1); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 4247, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_10, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4247, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } else { - if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_10)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_12); __Pyx_INCREF(__pyx_t_1); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 4247, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_10, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4247, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } - } else { - __pyx_t_1 = __pyx_t_15(__pyx_t_10); - 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, 4247, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - __Pyx_XDECREF_SET(__pyx_v_block_offsets, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4249 - * for block_offsets in pygeoprocessing.iterblocks( - * flow_dir_raster_path_band, offset_only=True): - * xoff = block_offsets['xoff'] # <<<<<<<<<<<<<< - * yoff = block_offsets['yoff'] - * win_xsize = block_offsets['win_xsize'] - */ - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_u_xoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4249, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4249, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_xoff = __pyx_t_9; - - /* "pygeoprocessing/routing/routing.pyx":4250 - * flow_dir_raster_path_band, 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_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_u_yoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4250, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_yoff = __pyx_t_9; - - /* "pygeoprocessing/routing/routing.pyx":4251 - * xoff = block_offsets['xoff'] - * yoff = block_offsets['yoff'] - * win_xsize = block_offsets['win_xsize'] # <<<<<<<<<<<<<< - * win_ysize = block_offsets['win_ysize'] - * - */ - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_u_win_xsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4251, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4251, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_win_xsize = __pyx_t_9; - - /* "pygeoprocessing/routing/routing.pyx":4252 - * yoff = block_offsets['yoff'] - * win_xsize = block_offsets['win_xsize'] - * win_ysize = block_offsets['win_ysize'] # <<<<<<<<<<<<<< - * - * # Make an array with a 1 pixel border around the iterblocks window - */ - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_u_win_ysize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4252, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4252, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_win_ysize = __pyx_t_9; - - /* "pygeoprocessing/routing/routing.pyx":4257 - * # That border will be filled in with nodata or data from the raster - * # if the window does not align with a top/bottom/left/right edge - * flow_dir_block = numpy.empty( # <<<<<<<<<<<<<< - * (win_ysize+2, win_xsize+2), dtype=numpy.int32) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4257, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4257, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4258 - * # if the window does not align with a top/bottom/left/right edge - * flow_dir_block = numpy.empty( - * (win_ysize+2, win_xsize+2), dtype=numpy.int32) # <<<<<<<<<<<<<< - * - * # Test for left border and if so stripe nodata on the left margin - */ - __pyx_t_1 = __Pyx_PyInt_From_long((__pyx_v_win_ysize + 2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4258, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_11 = __Pyx_PyInt_From_long((__pyx_v_win_xsize + 2)); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4258, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4258, __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_11); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_11); - __pyx_t_1 = 0; - __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4257 - * # That border will be filled in with nodata or data from the raster - * # if the window does not align with a top/bottom/left/right edge - * flow_dir_block = numpy.empty( # <<<<<<<<<<<<<< - * (win_ysize+2, win_xsize+2), dtype=numpy.int32) - * - */ - __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4257, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4258 - * # if the window does not align with a top/bottom/left/right edge - * flow_dir_block = numpy.empty( - * (win_ysize+2, win_xsize+2), dtype=numpy.int32) # <<<<<<<<<<<<<< - * - * # Test for left border and if so stripe nodata on the left margin - */ - __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4258, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4258, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_int32); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4258, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 4258, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4257 - * # That border will be filled in with nodata or data from the raster - * # if the window does not align with a top/bottom/left/right edge - * flow_dir_block = numpy.empty( # <<<<<<<<<<<<<< - * (win_ysize+2, win_xsize+2), dtype=numpy.int32) - * - */ - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_11, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4257, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 4257, __pyx_L1_error) - __pyx_t_16 = ((PyArrayObject *)__pyx_t_7); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_flow_dir_block.rcbuffer->pybuffer); - __pyx_t_9 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_flow_dir_block.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo_nn_npy_int32, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); - if (unlikely(__pyx_t_9 < 0)) { - PyErr_Fetch(&__pyx_t_17, &__pyx_t_18, &__pyx_t_19); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_flow_dir_block.rcbuffer->pybuffer, (PyObject*)__pyx_v_flow_dir_block, &__Pyx_TypeInfo_nn_npy_int32, 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_block.diminfo[0].strides = __pyx_pybuffernd_flow_dir_block.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_flow_dir_block.diminfo[0].shape = __pyx_pybuffernd_flow_dir_block.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_flow_dir_block.diminfo[1].strides = __pyx_pybuffernd_flow_dir_block.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_flow_dir_block.diminfo[1].shape = __pyx_pybuffernd_flow_dir_block.rcbuffer->pybuffer.shape[1]; - if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 4257, __pyx_L1_error) - } - __pyx_t_16 = 0; - __Pyx_XDECREF_SET(__pyx_v_flow_dir_block, ((PyArrayObject *)__pyx_t_7)); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4261 - * - * # Test for left border and if so stripe nodata on the left margin - * x_off_border = 0 # <<<<<<<<<<<<<< - * if xoff > 0: - * x_off_border = 1 - */ - __pyx_v_x_off_border = 0; - - /* "pygeoprocessing/routing/routing.pyx":4262 - * # Test for left border and if so stripe nodata on the left margin - * x_off_border = 0 - * if xoff > 0: # <<<<<<<<<<<<<< - * x_off_border = 1 - * else: - */ - __pyx_t_5 = ((__pyx_v_xoff > 0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":4263 - * x_off_border = 0 - * if xoff > 0: - * x_off_border = 1 # <<<<<<<<<<<<<< - * else: - * flow_dir_block[:, 0] = flow_dir_nodata - */ - __pyx_v_x_off_border = 1; - - /* "pygeoprocessing/routing/routing.pyx":4262 - * # Test for left border and if so stripe nodata on the left margin - * x_off_border = 0 - * if xoff > 0: # <<<<<<<<<<<<<< - * x_off_border = 1 - * else: - */ - goto __pyx_L12; - } - - /* "pygeoprocessing/routing/routing.pyx":4265 - * x_off_border = 1 - * else: - * flow_dir_block[:, 0] = flow_dir_nodata # <<<<<<<<<<<<<< - * - * # Test for top border and if so stripe nodata on the top margin - */ - /*else*/ { - __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_flow_dir_nodata); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4265, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_block), __pyx_tuple__20, __pyx_t_7) < 0)) __PYX_ERR(0, 4265, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __pyx_L12:; - - /* "pygeoprocessing/routing/routing.pyx":4268 - * - * # Test for top border and if so stripe nodata on the top margin - * y_off_border = 0 # <<<<<<<<<<<<<< - * if yoff > 0: - * y_off_border = 1 - */ - __pyx_v_y_off_border = 0; - - /* "pygeoprocessing/routing/routing.pyx":4269 - * # Test for top border and if so stripe nodata on the top margin - * y_off_border = 0 - * if yoff > 0: # <<<<<<<<<<<<<< - * y_off_border = 1 - * else: - */ - __pyx_t_5 = ((__pyx_v_yoff > 0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":4270 - * y_off_border = 0 - * if yoff > 0: - * y_off_border = 1 # <<<<<<<<<<<<<< - * else: - * flow_dir_block[0, :] = flow_dir_nodata - */ - __pyx_v_y_off_border = 1; - - /* "pygeoprocessing/routing/routing.pyx":4269 - * # Test for top border and if so stripe nodata on the top margin - * y_off_border = 0 - * if yoff > 0: # <<<<<<<<<<<<<< - * y_off_border = 1 - * else: - */ - goto __pyx_L13; - } - - /* "pygeoprocessing/routing/routing.pyx":4272 - * y_off_border = 1 - * else: - * flow_dir_block[0, :] = flow_dir_nodata # <<<<<<<<<<<<<< - * - * # Test for right border and if so stripe nodata on the right margin - */ - /*else*/ { - __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_flow_dir_nodata); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4272, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_block), __pyx_tuple__21, __pyx_t_7) < 0)) __PYX_ERR(0, 4272, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __pyx_L13:; - - /* "pygeoprocessing/routing/routing.pyx":4275 - * - * # Test for right border and if so stripe nodata on the right margin - * win_xsize_border = 0 # <<<<<<<<<<<<<< - * if xoff+win_xsize < raster_x_size-1: - * win_xsize_border += 1 - */ - __pyx_v_win_xsize_border = 0; - - /* "pygeoprocessing/routing/routing.pyx":4276 - * # Test for right border and if so stripe nodata on the right margin - * win_xsize_border = 0 - * if xoff+win_xsize < raster_x_size-1: # <<<<<<<<<<<<<< - * win_xsize_border += 1 - * else: - */ - __pyx_t_5 = (((__pyx_v_xoff + __pyx_v_win_xsize) < (__pyx_v_raster_x_size - 1)) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":4277 - * win_xsize_border = 0 - * if xoff+win_xsize < raster_x_size-1: - * win_xsize_border += 1 # <<<<<<<<<<<<<< - * else: - * flow_dir_block[:, -1] = flow_dir_nodata - */ - __pyx_v_win_xsize_border = (__pyx_v_win_xsize_border + 1); - - /* "pygeoprocessing/routing/routing.pyx":4276 - * # Test for right border and if so stripe nodata on the right margin - * win_xsize_border = 0 - * if xoff+win_xsize < raster_x_size-1: # <<<<<<<<<<<<<< - * win_xsize_border += 1 - * else: - */ - goto __pyx_L14; - } - - /* "pygeoprocessing/routing/routing.pyx":4279 - * win_xsize_border += 1 - * else: - * flow_dir_block[:, -1] = flow_dir_nodata # <<<<<<<<<<<<<< - * - * # Test for bottom border and if so stripe nodata on the bottom margin - */ - /*else*/ { - __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_flow_dir_nodata); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4279, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_block), __pyx_tuple__22, __pyx_t_7) < 0)) __PYX_ERR(0, 4279, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __pyx_L14:; - - /* "pygeoprocessing/routing/routing.pyx":4282 - * - * # Test for bottom border and if so stripe nodata on the bottom margin - * win_ysize_border = 0 # <<<<<<<<<<<<<< - * if yoff+win_ysize < raster_y_size-1: - * win_ysize_border += 1 - */ - __pyx_v_win_ysize_border = 0; - - /* "pygeoprocessing/routing/routing.pyx":4283 - * # Test for bottom border and if so stripe nodata on the bottom margin - * win_ysize_border = 0 - * if yoff+win_ysize < raster_y_size-1: # <<<<<<<<<<<<<< - * win_ysize_border += 1 - * else: - */ - __pyx_t_5 = (((__pyx_v_yoff + __pyx_v_win_ysize) < (__pyx_v_raster_y_size - 1)) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":4284 - * win_ysize_border = 0 - * if yoff+win_ysize < raster_y_size-1: - * win_ysize_border += 1 # <<<<<<<<<<<<<< - * else: - * flow_dir_block[-1, :] = flow_dir_nodata - */ - __pyx_v_win_ysize_border = (__pyx_v_win_ysize_border + 1); - - /* "pygeoprocessing/routing/routing.pyx":4283 - * # Test for bottom border and if so stripe nodata on the bottom margin - * win_ysize_border = 0 - * if yoff+win_ysize < raster_y_size-1: # <<<<<<<<<<<<<< - * win_ysize_border += 1 - * else: - */ - goto __pyx_L15; - } - - /* "pygeoprocessing/routing/routing.pyx":4286 - * win_ysize_border += 1 - * else: - * flow_dir_block[-1, :] = flow_dir_nodata # <<<<<<<<<<<<<< - * - * # Read iterblock plus a possible margin on top/bottom/left/right side - */ - /*else*/ { - __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_flow_dir_nodata); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4286, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_block), __pyx_tuple__23, __pyx_t_7) < 0)) __PYX_ERR(0, 4286, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __pyx_L15:; - - /* "pygeoprocessing/routing/routing.pyx":4293 - * 1-y_off_border:win_ysize+1+win_ysize_border, - * 1-x_off_border:win_xsize+1+win_xsize_border] = \ - * flow_dir_band.ReadAsArray( # <<<<<<<<<<<<<< - * xoff=xoff-x_off_border, - * yoff=yoff-y_off_border, - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4293, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - - /* "pygeoprocessing/routing/routing.pyx":4294 - * 1-x_off_border:win_xsize+1+win_xsize_border] = \ - * flow_dir_band.ReadAsArray( - * xoff=xoff-x_off_border, # <<<<<<<<<<<<<< - * yoff=yoff-y_off_border, - * win_xsize=win_xsize+win_xsize_border+x_off_border, - */ - __pyx_t_11 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4294, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_3 = __Pyx_PyInt_From_int((__pyx_v_xoff - __pyx_v_x_off_border)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4294, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_xoff, __pyx_t_3) < 0) __PYX_ERR(0, 4294, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4295 - * flow_dir_band.ReadAsArray( - * xoff=xoff-x_off_border, - * yoff=yoff-y_off_border, # <<<<<<<<<<<<<< - * win_xsize=win_xsize+win_xsize_border+x_off_border, - * win_ysize=win_ysize+win_ysize_border+y_off_border).astype( - */ - __pyx_t_3 = __Pyx_PyInt_From_int((__pyx_v_yoff - __pyx_v_y_off_border)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4295, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_yoff, __pyx_t_3) < 0) __PYX_ERR(0, 4294, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4296 - * xoff=xoff-x_off_border, - * yoff=yoff-y_off_border, - * win_xsize=win_xsize+win_xsize_border+x_off_border, # <<<<<<<<<<<<<< - * win_ysize=win_ysize+win_ysize_border+y_off_border).astype( - * numpy.int32) - */ - __pyx_t_3 = __Pyx_PyInt_From_int(((__pyx_v_win_xsize + __pyx_v_win_xsize_border) + __pyx_v_x_off_border)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4296, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_win_xsize, __pyx_t_3) < 0) __PYX_ERR(0, 4294, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4297 - * yoff=yoff-y_off_border, - * win_xsize=win_xsize+win_xsize_border+x_off_border, - * win_ysize=win_ysize+win_ysize_border+y_off_border).astype( # <<<<<<<<<<<<<< - * numpy.int32) - * - */ - __pyx_t_3 = __Pyx_PyInt_From_int(((__pyx_v_win_ysize + __pyx_v_win_ysize_border) + __pyx_v_y_off_border)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4297, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_win_ysize, __pyx_t_3) < 0) __PYX_ERR(0, 4294, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4293 - * 1-y_off_border:win_ysize+1+win_ysize_border, - * 1-x_off_border:win_xsize+1+win_xsize_border] = \ - * flow_dir_band.ReadAsArray( # <<<<<<<<<<<<<< - * xoff=xoff-x_off_border, - * yoff=yoff-y_off_border, - */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4293, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4297 - * yoff=yoff-y_off_border, - * win_xsize=win_xsize+win_xsize_border+x_off_border, - * win_ysize=win_ysize+win_ysize_border+y_off_border).astype( # <<<<<<<<<<<<<< - * numpy.int32) - * - */ - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_astype); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4297, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4298 - * win_xsize=win_xsize+win_xsize_border+x_off_border, - * win_ysize=win_ysize+win_ysize_border+y_off_border).astype( - * numpy.int32) # <<<<<<<<<<<<<< - * - * for yi in range(1, win_ysize+1): - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4298, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4298, __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_11))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - } - } - __pyx_t_7 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4297, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4291 - * # and read as type int32 to handle both d8 or mfd formats - * flow_dir_block[ - * 1-y_off_border:win_ysize+1+win_ysize_border, # <<<<<<<<<<<<<< - * 1-x_off_border:win_xsize+1+win_xsize_border] = \ - * flow_dir_band.ReadAsArray( - */ - __pyx_t_11 = __Pyx_PyInt_From_long((1 - __pyx_v_y_off_border)); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4291, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_2 = __Pyx_PyInt_From_long(((__pyx_v_win_ysize + 1) + __pyx_v_win_ysize_border)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4291, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - - /* "pygeoprocessing/routing/routing.pyx":4290 - * # Read iterblock plus a possible margin on top/bottom/left/right side - * # and read as type int32 to handle both d8 or mfd formats - * flow_dir_block[ # <<<<<<<<<<<<<< - * 1-y_off_border:win_ysize+1+win_ysize_border, - * 1-x_off_border:win_xsize+1+win_xsize_border] = \ - */ - __pyx_t_3 = PySlice_New(__pyx_t_11, __pyx_t_2, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4290, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4292 - * flow_dir_block[ - * 1-y_off_border:win_ysize+1+win_ysize_border, - * 1-x_off_border:win_xsize+1+win_xsize_border] = \ # <<<<<<<<<<<<<< - * flow_dir_band.ReadAsArray( - * xoff=xoff-x_off_border, - */ - __pyx_t_2 = __Pyx_PyInt_From_long((1 - __pyx_v_x_off_border)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4292, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = __Pyx_PyInt_From_long(((__pyx_v_win_xsize + 1) + __pyx_v_win_xsize_border)); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4292, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - - /* "pygeoprocessing/routing/routing.pyx":4290 - * # Read iterblock plus a possible margin on top/bottom/left/right side - * # and read as type int32 to handle both d8 or mfd formats - * flow_dir_block[ # <<<<<<<<<<<<<< - * 1-y_off_border:win_ysize+1+win_ysize_border, - * 1-x_off_border:win_xsize+1+win_xsize_border] = \ - */ - __pyx_t_1 = PySlice_New(__pyx_t_2, __pyx_t_11, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4290, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4290, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_1); - __pyx_t_3 = 0; - __pyx_t_1 = 0; - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_block), __pyx_t_11, __pyx_t_7) < 0)) __PYX_ERR(0, 4290, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4300 - * numpy.int32) - * - * for yi in range(1, win_ysize+1): # <<<<<<<<<<<<<< - * if ctime(NULL) - last_log_time > 5.0: - * last_log_time = ctime(NULL) - */ - __pyx_t_20 = (__pyx_v_win_ysize + 1); - __pyx_t_21 = __pyx_t_20; - for (__pyx_t_9 = 1; __pyx_t_9 < __pyx_t_21; __pyx_t_9+=1) { - __pyx_v_yi = __pyx_t_9; - - /* "pygeoprocessing/routing/routing.pyx":4301 - * - * for yi in range(1, win_ysize+1): - * 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":4302 - * for yi in range(1, win_ysize+1): - * if ctime(NULL) - last_log_time > 5.0: - * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info( - */ - __pyx_v_last_log_time = time(NULL); - - /* "pygeoprocessing/routing/routing.pyx":4303 - * if ctime(NULL) - last_log_time > 5.0: - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size # <<<<<<<<<<<<<< - * LOGGER.info( - * f'''outlet detection: { - */ - __pyx_t_7 = __Pyx_PyInt_From_int((__pyx_v_xoff + (__pyx_v_yoff * __pyx_v_raster_x_size))); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4303, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_XDECREF_SET(__pyx_v_current_pixel, __pyx_t_7); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4304 - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info( # <<<<<<<<<<<<<< - * f'''outlet detection: { - * 100.0 * current_pixel / ( - */ - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4304, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4304, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4305 - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info( - * f'''outlet detection: { # <<<<<<<<<<<<<< - * 100.0 * current_pixel / ( - * raster_x_size * raster_y_size):.1f} complete''') - */ - __pyx_t_11 = PyTuple_New(3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4305, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_22 = 0; - __pyx_t_13 = 127; - __Pyx_INCREF(__pyx_kp_u_outlet_detection); - __pyx_t_22 += 18; - __Pyx_GIVEREF(__pyx_kp_u_outlet_detection); - PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_kp_u_outlet_detection); - - /* "pygeoprocessing/routing/routing.pyx":4306 - * LOGGER.info( - * f'''outlet detection: { - * 100.0 * current_pixel / ( # <<<<<<<<<<<<<< - * raster_x_size * raster_y_size):.1f} complete''') - * for xi in range(1, win_xsize+1): - */ - __pyx_t_3 = PyNumber_Multiply(__pyx_float_100_0, __pyx_v_current_pixel); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4306, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pygeoprocessing/routing/routing.pyx":4307 - * f'''outlet detection: { - * 100.0 * current_pixel / ( - * raster_x_size * raster_y_size):.1f} complete''') # <<<<<<<<<<<<<< - * for xi in range(1, win_xsize+1): - * flow_dir = flow_dir_block[yi, xi] - */ - __pyx_t_2 = PyFloat_FromDouble(((float)(__pyx_v_raster_x_size * __pyx_v_raster_y_size))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4306, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - - /* "pygeoprocessing/routing/routing.pyx":4306 - * LOGGER.info( - * f'''outlet detection: { - * 100.0 * current_pixel / ( # <<<<<<<<<<<<<< - * raster_x_size * raster_y_size):.1f} complete''') - * for xi in range(1, win_xsize+1): - */ - __pyx_t_14 = __Pyx_PyNumber_Divide(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4306, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4305 - * current_pixel = xoff + yoff * raster_x_size - * LOGGER.info( - * f'''outlet detection: { # <<<<<<<<<<<<<< - * 100.0 * current_pixel / ( - * raster_x_size * raster_y_size):.1f} complete''') - */ - __pyx_t_2 = __Pyx_PyObject_Format(__pyx_t_14, __pyx_kp_u_1f); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4305, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_13 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) > __pyx_t_13) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) : __pyx_t_13; - __pyx_t_22 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_2); - __pyx_t_2 = 0; - __Pyx_INCREF(__pyx_kp_u_complete_2); - __pyx_t_22 += 9; - __Pyx_GIVEREF(__pyx_kp_u_complete_2); - PyTuple_SET_ITEM(__pyx_t_11, 2, __pyx_kp_u_complete_2); - __pyx_t_2 = __Pyx_PyUnicode_Join(__pyx_t_11, 3, __pyx_t_22, __pyx_t_13); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4305, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_7 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_11, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4304, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4301 - * - * for yi in range(1, win_ysize+1): - * if ctime(NULL) - last_log_time > 5.0: # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * current_pixel = xoff + yoff * raster_x_size - */ - } - - /* "pygeoprocessing/routing/routing.pyx":4308 - * 100.0 * current_pixel / ( - * raster_x_size * raster_y_size):.1f} complete''') - * for xi in range(1, win_xsize+1): # <<<<<<<<<<<<<< - * flow_dir = flow_dir_block[yi, xi] - * if flow_dir == flow_dir_nodata: - */ - __pyx_t_23 = (__pyx_v_win_xsize + 1); - __pyx_t_24 = __pyx_t_23; - for (__pyx_t_6 = 1; __pyx_t_6 < __pyx_t_24; __pyx_t_6+=1) { - __pyx_v_xi = __pyx_t_6; - - /* "pygeoprocessing/routing/routing.pyx":4309 - * raster_x_size * raster_y_size):.1f} complete''') - * for xi in range(1, win_xsize+1): - * flow_dir = flow_dir_block[yi, xi] # <<<<<<<<<<<<<< - * if flow_dir == flow_dir_nodata: - * continue - */ - __pyx_t_25 = __pyx_v_yi; - __pyx_t_26 = __pyx_v_xi; - __pyx_t_27 = -1; - if (__pyx_t_25 < 0) { - __pyx_t_25 += __pyx_pybuffernd_flow_dir_block.diminfo[0].shape; - if (unlikely(__pyx_t_25 < 0)) __pyx_t_27 = 0; - } else if (unlikely(__pyx_t_25 >= __pyx_pybuffernd_flow_dir_block.diminfo[0].shape)) __pyx_t_27 = 0; - if (__pyx_t_26 < 0) { - __pyx_t_26 += __pyx_pybuffernd_flow_dir_block.diminfo[1].shape; - if (unlikely(__pyx_t_26 < 0)) __pyx_t_27 = 1; - } else if (unlikely(__pyx_t_26 >= __pyx_pybuffernd_flow_dir_block.diminfo[1].shape)) __pyx_t_27 = 1; - if (unlikely(__pyx_t_27 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_27); - __PYX_ERR(0, 4309, __pyx_L1_error) - } - __pyx_v_flow_dir = (*__Pyx_BufPtrStrided2d(npy_int32 *, __pyx_pybuffernd_flow_dir_block.rcbuffer->pybuffer.buf, __pyx_t_25, __pyx_pybuffernd_flow_dir_block.diminfo[0].strides, __pyx_t_26, __pyx_pybuffernd_flow_dir_block.diminfo[1].strides)); - - /* "pygeoprocessing/routing/routing.pyx":4310 - * for xi in range(1, win_xsize+1): - * flow_dir = flow_dir_block[yi, xi] - * if flow_dir == flow_dir_nodata: # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_5 = ((__pyx_v_flow_dir == __pyx_v_flow_dir_nodata) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":4311 - * flow_dir = flow_dir_block[yi, xi] - * if flow_dir == flow_dir_nodata: - * continue # <<<<<<<<<<<<<< - * - * is_outlet = 1 - */ - goto __pyx_L19_continue; - - /* "pygeoprocessing/routing/routing.pyx":4310 - * for xi in range(1, win_xsize+1): - * flow_dir = flow_dir_block[yi, xi] - * if flow_dir == flow_dir_nodata: # <<<<<<<<<<<<<< - * continue - * - */ - } - - /* "pygeoprocessing/routing/routing.pyx":4313 - * continue - * - * is_outlet = 1 # <<<<<<<<<<<<<< - * if d8_flow_dir_mode: - * # inspect the outflow pixel neighbor - */ - __pyx_v_is_outlet = 1; - - /* "pygeoprocessing/routing/routing.pyx":4314 - * - * is_outlet = 1 - * if d8_flow_dir_mode: # <<<<<<<<<<<<<< - * # inspect the outflow pixel neighbor - * flow_dir_n = flow_dir_block[ - */ - __pyx_t_5 = (__pyx_v_d8_flow_dir_mode != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":4316 - * if d8_flow_dir_mode: - * # inspect the outflow pixel neighbor - * flow_dir_n = flow_dir_block[ # <<<<<<<<<<<<<< - * yi+D8_YOFFSET[flow_dir], - * xi+D8_XOFFSET[flow_dir]] - */ - __pyx_t_26 = (__pyx_v_yi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_flow_dir])); - __pyx_t_25 = (__pyx_v_xi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_flow_dir])); - __pyx_t_27 = -1; - if (__pyx_t_26 < 0) { - __pyx_t_26 += __pyx_pybuffernd_flow_dir_block.diminfo[0].shape; - if (unlikely(__pyx_t_26 < 0)) __pyx_t_27 = 0; - } else if (unlikely(__pyx_t_26 >= __pyx_pybuffernd_flow_dir_block.diminfo[0].shape)) __pyx_t_27 = 0; - if (__pyx_t_25 < 0) { - __pyx_t_25 += __pyx_pybuffernd_flow_dir_block.diminfo[1].shape; - if (unlikely(__pyx_t_25 < 0)) __pyx_t_27 = 1; - } else if (unlikely(__pyx_t_25 >= __pyx_pybuffernd_flow_dir_block.diminfo[1].shape)) __pyx_t_27 = 1; - if (unlikely(__pyx_t_27 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_27); - __PYX_ERR(0, 4316, __pyx_L1_error) - } - __pyx_v_flow_dir_n = (*__Pyx_BufPtrStrided2d(npy_int32 *, __pyx_pybuffernd_flow_dir_block.rcbuffer->pybuffer.buf, __pyx_t_26, __pyx_pybuffernd_flow_dir_block.diminfo[0].strides, __pyx_t_25, __pyx_pybuffernd_flow_dir_block.diminfo[1].strides)); - - /* "pygeoprocessing/routing/routing.pyx":4322 - * # if the outflow pixel is outside the raster boundaries or - * # is a nodata pixel it must mean xi,yi is an outlet - * if flow_dir_n != flow_dir_nodata: # <<<<<<<<<<<<<< - * is_outlet = 0 - * else: - */ - __pyx_t_5 = ((__pyx_v_flow_dir_n != __pyx_v_flow_dir_nodata) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":4323 - * # is a nodata pixel it must mean xi,yi is an outlet - * if flow_dir_n != flow_dir_nodata: - * is_outlet = 0 # <<<<<<<<<<<<<< - * else: - * # inspect all the outflow pixel neighbors in MFD mode - */ - __pyx_v_is_outlet = 0; - - /* "pygeoprocessing/routing/routing.pyx":4322 - * # if the outflow pixel is outside the raster boundaries or - * # is a nodata pixel it must mean xi,yi is an outlet - * if flow_dir_n != flow_dir_nodata: # <<<<<<<<<<<<<< - * is_outlet = 0 - * else: - */ - } - - /* "pygeoprocessing/routing/routing.pyx":4314 - * - * is_outlet = 1 - * if d8_flow_dir_mode: # <<<<<<<<<<<<<< - * # inspect the outflow pixel neighbor - * flow_dir_n = flow_dir_block[ - */ - goto __pyx_L22; - } - - /* "pygeoprocessing/routing/routing.pyx":4326 - * else: - * # inspect all the outflow pixel neighbors in MFD mode - * for n_dir in range(8): # <<<<<<<<<<<<<< - * # shift the 0xF mask to the outflow direction and - * # test if there's any outflow or not. 0 means nothing - */ - /*else*/ { - for (__pyx_t_27 = 0; __pyx_t_27 < 8; __pyx_t_27+=1) { - __pyx_v_n_dir = __pyx_t_27; - - /* "pygeoprocessing/routing/routing.pyx":4338 - * # if it equals 0 it means there was no proportional - * # flow in the `n_dir` direction. - * if flow_dir&(0xF<<(n_dir*4)) == 0: # <<<<<<<<<<<<<< - * continue - * flow_dir_n = flow_dir_block[ - */ - __pyx_t_5 = (((__pyx_v_flow_dir & (0xF << (__pyx_v_n_dir * 4))) == 0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":4339 - * # flow in the `n_dir` direction. - * if flow_dir&(0xF<<(n_dir*4)) == 0: - * continue # <<<<<<<<<<<<<< - * flow_dir_n = flow_dir_block[ - * yi+D8_YOFFSET[n_dir], - */ - goto __pyx_L24_continue; - - /* "pygeoprocessing/routing/routing.pyx":4338 - * # if it equals 0 it means there was no proportional - * # flow in the `n_dir` direction. - * if flow_dir&(0xF<<(n_dir*4)) == 0: # <<<<<<<<<<<<<< - * continue - * flow_dir_n = flow_dir_block[ - */ - } - - /* "pygeoprocessing/routing/routing.pyx":4340 - * if flow_dir&(0xF<<(n_dir*4)) == 0: - * continue - * flow_dir_n = flow_dir_block[ # <<<<<<<<<<<<<< - * yi+D8_YOFFSET[n_dir], - * xi+D8_XOFFSET[n_dir]] - */ - __pyx_t_25 = (__pyx_v_yi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_n_dir])); - __pyx_t_26 = (__pyx_v_xi + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_n_dir])); - __pyx_t_28 = -1; - if (__pyx_t_25 < 0) { - __pyx_t_25 += __pyx_pybuffernd_flow_dir_block.diminfo[0].shape; - if (unlikely(__pyx_t_25 < 0)) __pyx_t_28 = 0; - } else if (unlikely(__pyx_t_25 >= __pyx_pybuffernd_flow_dir_block.diminfo[0].shape)) __pyx_t_28 = 0; - if (__pyx_t_26 < 0) { - __pyx_t_26 += __pyx_pybuffernd_flow_dir_block.diminfo[1].shape; - if (unlikely(__pyx_t_26 < 0)) __pyx_t_28 = 1; - } else if (unlikely(__pyx_t_26 >= __pyx_pybuffernd_flow_dir_block.diminfo[1].shape)) __pyx_t_28 = 1; - if (unlikely(__pyx_t_28 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_28); - __PYX_ERR(0, 4340, __pyx_L1_error) - } - __pyx_v_flow_dir_n = (*__Pyx_BufPtrStrided2d(npy_int32 *, __pyx_pybuffernd_flow_dir_block.rcbuffer->pybuffer.buf, __pyx_t_25, __pyx_pybuffernd_flow_dir_block.diminfo[0].strides, __pyx_t_26, __pyx_pybuffernd_flow_dir_block.diminfo[1].strides)); - - /* "pygeoprocessing/routing/routing.pyx":4343 - * yi+D8_YOFFSET[n_dir], - * xi+D8_XOFFSET[n_dir]] - * if flow_dir_n != flow_dir_nodata: # <<<<<<<<<<<<<< - * is_outlet = 0 - * break - */ - __pyx_t_5 = ((__pyx_v_flow_dir_n != __pyx_v_flow_dir_nodata) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":4344 - * xi+D8_XOFFSET[n_dir]] - * if flow_dir_n != flow_dir_nodata: - * is_outlet = 0 # <<<<<<<<<<<<<< - * break - * - */ - __pyx_v_is_outlet = 0; - - /* "pygeoprocessing/routing/routing.pyx":4345 - * if flow_dir_n != flow_dir_nodata: - * is_outlet = 0 - * break # <<<<<<<<<<<<<< - * - * # if the outflow pixel is outside the raster boundaries or - */ - goto __pyx_L25_break; - - /* "pygeoprocessing/routing/routing.pyx":4343 - * yi+D8_YOFFSET[n_dir], - * xi+D8_XOFFSET[n_dir]] - * if flow_dir_n != flow_dir_nodata: # <<<<<<<<<<<<<< - * is_outlet = 0 - * break - */ - } - __pyx_L24_continue:; - } - __pyx_L25_break:; - } - __pyx_L22:; - - /* "pygeoprocessing/routing/routing.pyx":4349 - * # if the outflow pixel is outside the raster boundaries or - * # is a nodata pixel it must mean xi,yi is an outlet - * if is_outlet: # <<<<<<<<<<<<<< - * outlet_point = ogr.Geometry(ogr.wkbPoint) - * # calculate global x/y raster coordinate, the -1 is for - */ - __pyx_t_5 = (__pyx_v_is_outlet != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":4350 - * # is a nodata pixel it must mean xi,yi is an outlet - * if is_outlet: - * outlet_point = ogr.Geometry(ogr.wkbPoint) # <<<<<<<<<<<<<< - * # calculate global x/y raster coordinate, the -1 is for - * # the left/top border of the test array window - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4350, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_Geometry); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4350, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4350, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_wkbPoint); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4350, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_7 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_1, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_11); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4350, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF_SET(__pyx_v_outlet_point, __pyx_t_7); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4353 - * # calculate global x/y raster coordinate, the -1 is for - * # the left/top border of the test array window - * xi_root = xi+xoff-1 # <<<<<<<<<<<<<< - * yi_root = yi+yoff-1 - * # created a projected point in the center of the pixel - */ - __pyx_v_xi_root = ((__pyx_v_xi + __pyx_v_xoff) - 1); - - /* "pygeoprocessing/routing/routing.pyx":4354 - * # the left/top border of the test array window - * xi_root = xi+xoff-1 - * yi_root = yi+yoff-1 # <<<<<<<<<<<<<< - * # created a projected point in the center of the pixel - * # thus the + 0.5 to x and y - */ - __pyx_v_yi_root = ((__pyx_v_yi + __pyx_v_yoff) - 1); - - /* "pygeoprocessing/routing/routing.pyx":4357 - * # created a projected point in the center of the pixel - * # thus the + 0.5 to x and y - * proj_x, proj_y = gdal.ApplyGeoTransform( # <<<<<<<<<<<<<< - * raster_info['geotransform'], - * xi_root+0.5, yi_root+0.5) - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4357, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_ApplyGeoTransform); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4357, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4358 - * # thus the + 0.5 to x and y - * proj_x, proj_y = gdal.ApplyGeoTransform( - * raster_info['geotransform'], # <<<<<<<<<<<<<< - * xi_root+0.5, yi_root+0.5) - * outlet_point.AddPoint(proj_x, proj_y) - */ - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_geotransform); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4358, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - - /* "pygeoprocessing/routing/routing.pyx":4359 - * proj_x, proj_y = gdal.ApplyGeoTransform( - * raster_info['geotransform'], - * xi_root+0.5, yi_root+0.5) # <<<<<<<<<<<<<< - * outlet_point.AddPoint(proj_x, proj_y) - * outlet_feature = ogr.Feature(outlet_layer.GetLayerDefn()) - */ - __pyx_t_1 = PyFloat_FromDouble((__pyx_v_xi_root + 0.5)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4359, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_14 = PyFloat_FromDouble((__pyx_v_yi_root + 0.5)); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4359, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_3 = NULL; - __pyx_t_27 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - __pyx_t_27 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_11)) { - PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_t_2, __pyx_t_1, __pyx_t_14}; - __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_27, 3+__pyx_t_27); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4357, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { - PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_t_2, __pyx_t_1, __pyx_t_14}; - __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_27, 3+__pyx_t_27); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4357, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - } else - #endif - { - __pyx_t_29 = PyTuple_New(3+__pyx_t_27); if (unlikely(!__pyx_t_29)) __PYX_ERR(0, 4357, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_29); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_29, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_29, 0+__pyx_t_27, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_29, 1+__pyx_t_27, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_29, 2+__pyx_t_27, __pyx_t_14); - __pyx_t_2 = 0; - __pyx_t_1 = 0; - __pyx_t_14 = 0; - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_29, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4357, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_29); __pyx_t_29 = 0; - } - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) { - PyObject* sequence = __pyx_t_7; - 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, 4357, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_11 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_29 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_11 = PyList_GET_ITEM(sequence, 0); - __pyx_t_29 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(__pyx_t_29); - #else - __pyx_t_11 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4357, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_29 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_29)) __PYX_ERR(0, 4357, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_29); - #endif - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_14 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4357, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_14)->tp_iternext; - index = 0; __pyx_t_11 = __pyx_t_8(__pyx_t_14); if (unlikely(!__pyx_t_11)) goto __pyx_L29_unpacking_failed; - __Pyx_GOTREF(__pyx_t_11); - index = 1; __pyx_t_29 = __pyx_t_8(__pyx_t_14); if (unlikely(!__pyx_t_29)) goto __pyx_L29_unpacking_failed; - __Pyx_GOTREF(__pyx_t_29); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_14), 2) < 0) __PYX_ERR(0, 4357, __pyx_L1_error) - __pyx_t_8 = NULL; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - goto __pyx_L30_unpacking_done; - __pyx_L29_unpacking_failed:; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_8 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 4357, __pyx_L1_error) - __pyx_L30_unpacking_done:; - } - - /* "pygeoprocessing/routing/routing.pyx":4357 - * # created a projected point in the center of the pixel - * # thus the + 0.5 to x and y - * proj_x, proj_y = gdal.ApplyGeoTransform( # <<<<<<<<<<<<<< - * raster_info['geotransform'], - * xi_root+0.5, yi_root+0.5) - */ - __Pyx_XDECREF_SET(__pyx_v_proj_x, __pyx_t_11); - __pyx_t_11 = 0; - __Pyx_XDECREF_SET(__pyx_v_proj_y, __pyx_t_29); - __pyx_t_29 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4360 - * raster_info['geotransform'], - * xi_root+0.5, yi_root+0.5) - * outlet_point.AddPoint(proj_x, proj_y) # <<<<<<<<<<<<<< - * outlet_feature = ogr.Feature(outlet_layer.GetLayerDefn()) - * outlet_feature.SetGeometry(outlet_point) - */ - __pyx_t_29 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_point, __pyx_n_s_AddPoint); if (unlikely(!__pyx_t_29)) __PYX_ERR(0, 4360, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_29); - __pyx_t_11 = NULL; - __pyx_t_27 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_29))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_29); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_29); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_29, function); - __pyx_t_27 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_29)) { - PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_proj_x, __pyx_v_proj_y}; - __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_29, __pyx_temp+1-__pyx_t_27, 2+__pyx_t_27); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4360, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_GOTREF(__pyx_t_7); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_29)) { - PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_proj_x, __pyx_v_proj_y}; - __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_29, __pyx_temp+1-__pyx_t_27, 2+__pyx_t_27); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4360, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_GOTREF(__pyx_t_7); - } else - #endif - { - __pyx_t_14 = PyTuple_New(2+__pyx_t_27); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4360, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - if (__pyx_t_11) { - __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_11); __pyx_t_11 = NULL; - } - __Pyx_INCREF(__pyx_v_proj_x); - __Pyx_GIVEREF(__pyx_v_proj_x); - PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_27, __pyx_v_proj_x); - __Pyx_INCREF(__pyx_v_proj_y); - __Pyx_GIVEREF(__pyx_v_proj_y); - PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_27, __pyx_v_proj_y); - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_29, __pyx_t_14, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4360, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - } - __Pyx_DECREF(__pyx_t_29); __pyx_t_29 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4361 - * xi_root+0.5, yi_root+0.5) - * outlet_point.AddPoint(proj_x, proj_y) - * outlet_feature = ogr.Feature(outlet_layer.GetLayerDefn()) # <<<<<<<<<<<<<< - * outlet_feature.SetGeometry(outlet_point) - * # save the raster coordinates of the outlet pixel as i,j - */ - __Pyx_GetModuleGlobalName(__pyx_t_29, __pyx_n_s_ogr); if (unlikely(!__pyx_t_29)) __PYX_ERR(0, 4361, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_29); - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_29, __pyx_n_s_Feature); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4361, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_29); __pyx_t_29 = 0; - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_layer, __pyx_n_s_GetLayerDefn); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4361, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - } - } - __pyx_t_29 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_29)) __PYX_ERR(0, 4361, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_29); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - } - } - __pyx_t_7 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_11, __pyx_t_29) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_t_29); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_29); __pyx_t_29 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4361, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_XDECREF_SET(__pyx_v_outlet_feature, __pyx_t_7); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4362 - * outlet_point.AddPoint(proj_x, proj_y) - * outlet_feature = ogr.Feature(outlet_layer.GetLayerDefn()) - * outlet_feature.SetGeometry(outlet_point) # <<<<<<<<<<<<<< - * # save the raster coordinates of the outlet pixel as i,j - * outlet_feature.SetField('i', xi_root) - */ - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_feature, __pyx_n_s_SetGeometry); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4362, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_29 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) { - __pyx_t_29 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_29)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_29); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - } - } - __pyx_t_7 = (__pyx_t_29) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_29, __pyx_v_outlet_point) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_v_outlet_point); - __Pyx_XDECREF(__pyx_t_29); __pyx_t_29 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4362, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4364 - * outlet_feature.SetGeometry(outlet_point) - * # save the raster coordinates of the outlet pixel as i,j - * outlet_feature.SetField('i', xi_root) # <<<<<<<<<<<<<< - * outlet_feature.SetField('j', yi_root) - * outlet_feature.SetField('ID', next_id) - */ - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4364, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_29 = __Pyx_PyInt_From_int(__pyx_v_xi_root); if (unlikely(!__pyx_t_29)) __PYX_ERR(0, 4364, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_29); - __pyx_t_11 = NULL; - __pyx_t_27 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - __pyx_t_27 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_14)) { - PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_n_u_i, __pyx_t_29}; - __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_27, 2+__pyx_t_27); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4364, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_29); __pyx_t_29 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) { - PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_n_u_i, __pyx_t_29}; - __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_27, 2+__pyx_t_27); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4364, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_29); __pyx_t_29 = 0; - } else - #endif - { - __pyx_t_1 = PyTuple_New(2+__pyx_t_27); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4364, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (__pyx_t_11) { - __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_11); __pyx_t_11 = NULL; - } - __Pyx_INCREF(__pyx_n_u_i); - __Pyx_GIVEREF(__pyx_n_u_i); - PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_27, __pyx_n_u_i); - __Pyx_GIVEREF(__pyx_t_29); - PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_27, __pyx_t_29); - __pyx_t_29 = 0; - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_1, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4364, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4365 - * # save the raster coordinates of the outlet pixel as i,j - * outlet_feature.SetField('i', xi_root) - * outlet_feature.SetField('j', yi_root) # <<<<<<<<<<<<<< - * outlet_feature.SetField('ID', next_id) - * next_id += 1 - */ - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4365, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_yi_root); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4365, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_29 = NULL; - __pyx_t_27 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) { - __pyx_t_29 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_29)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_29); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - __pyx_t_27 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_14)) { - PyObject *__pyx_temp[3] = {__pyx_t_29, __pyx_n_u_j, __pyx_t_1}; - __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_27, 2+__pyx_t_27); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4365, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_29); __pyx_t_29 = 0; - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) { - PyObject *__pyx_temp[3] = {__pyx_t_29, __pyx_n_u_j, __pyx_t_1}; - __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_27, 2+__pyx_t_27); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4365, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_29); __pyx_t_29 = 0; - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - { - __pyx_t_11 = PyTuple_New(2+__pyx_t_27); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4365, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - if (__pyx_t_29) { - __Pyx_GIVEREF(__pyx_t_29); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_29); __pyx_t_29 = NULL; - } - __Pyx_INCREF(__pyx_n_u_j); - __Pyx_GIVEREF(__pyx_n_u_j); - PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_27, __pyx_n_u_j); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_27, __pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_11, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4365, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4366 - * outlet_feature.SetField('i', xi_root) - * outlet_feature.SetField('j', yi_root) - * outlet_feature.SetField('ID', next_id) # <<<<<<<<<<<<<< - * next_id += 1 - * outlet_layer.CreateFeature(outlet_feature) - */ - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4366, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_11 = __Pyx_PyInt_From_int(__pyx_v_next_id); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4366, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_1 = NULL; - __pyx_t_27 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - __pyx_t_27 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_14)) { - PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_n_u_ID, __pyx_t_11}; - __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_27, 2+__pyx_t_27); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4366, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) { - PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_n_u_ID, __pyx_t_11}; - __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_27, 2+__pyx_t_27); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4366, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } else - #endif - { - __pyx_t_29 = PyTuple_New(2+__pyx_t_27); if (unlikely(!__pyx_t_29)) __PYX_ERR(0, 4366, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_29); - if (__pyx_t_1) { - __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_29, 0, __pyx_t_1); __pyx_t_1 = NULL; - } - __Pyx_INCREF(__pyx_n_u_ID); - __Pyx_GIVEREF(__pyx_n_u_ID); - PyTuple_SET_ITEM(__pyx_t_29, 0+__pyx_t_27, __pyx_n_u_ID); - __Pyx_GIVEREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_29, 1+__pyx_t_27, __pyx_t_11); - __pyx_t_11 = 0; - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_29, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4366, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_29); __pyx_t_29 = 0; - } - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4367 - * outlet_feature.SetField('j', yi_root) - * outlet_feature.SetField('ID', next_id) - * next_id += 1 # <<<<<<<<<<<<<< - * outlet_layer.CreateFeature(outlet_feature) - * outlet_feature = None - */ - __pyx_v_next_id = (__pyx_v_next_id + 1); - - /* "pygeoprocessing/routing/routing.pyx":4368 - * outlet_feature.SetField('ID', next_id) - * next_id += 1 - * outlet_layer.CreateFeature(outlet_feature) # <<<<<<<<<<<<<< - * outlet_feature = None - * outlet_point = None - */ - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_layer, __pyx_n_s_CreateFeature); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4368, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_29 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) { - __pyx_t_29 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_29)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_29); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - } - } - __pyx_t_7 = (__pyx_t_29) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_29, __pyx_v_outlet_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_v_outlet_feature); - __Pyx_XDECREF(__pyx_t_29); __pyx_t_29 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4368, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4369 - * next_id += 1 - * outlet_layer.CreateFeature(outlet_feature) - * outlet_feature = None # <<<<<<<<<<<<<< - * outlet_point = None - * - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_outlet_feature, Py_None); - - /* "pygeoprocessing/routing/routing.pyx":4370 - * outlet_layer.CreateFeature(outlet_feature) - * outlet_feature = None - * outlet_point = None # <<<<<<<<<<<<<< - * - * flow_dir_raster = None - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_outlet_point, Py_None); - - /* "pygeoprocessing/routing/routing.pyx":4349 - * # if the outflow pixel is outside the raster boundaries or - * # is a nodata pixel it must mean xi,yi is an outlet - * if is_outlet: # <<<<<<<<<<<<<< - * outlet_point = ogr.Geometry(ogr.wkbPoint) - * # calculate global x/y raster coordinate, the -1 is for - */ - } - __pyx_L19_continue:; - } - } - - /* "pygeoprocessing/routing/routing.pyx":4247 - * # and writes - * LOGGER.info('outlet detection: 0% complete') - * for block_offsets in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * flow_dir_raster_path_band, offset_only=True): - * xoff = block_offsets['xoff'] - */ - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4372 - * outlet_point = None - * - * flow_dir_raster = None # <<<<<<<<<<<<<< - * flow_dir_band = None - * LOGGER.info('outlet detection: 100% complete -- committing transaction') - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_flow_dir_raster, Py_None); - - /* "pygeoprocessing/routing/routing.pyx":4373 - * - * flow_dir_raster = None - * flow_dir_band = None # <<<<<<<<<<<<<< - * LOGGER.info('outlet detection: 100% complete -- committing transaction') - * outlet_layer.CommitTransaction() - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_flow_dir_band, Py_None); - - /* "pygeoprocessing/routing/routing.pyx":4374 - * flow_dir_raster = None - * flow_dir_band = None - * LOGGER.info('outlet detection: 100% complete -- committing transaction') # <<<<<<<<<<<<<< - * outlet_layer.CommitTransaction() - * outlet_layer = None - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4374, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_info); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4374, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - } - } - __pyx_t_10 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_7, __pyx_kp_u_outlet_detection_100_complete_co) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_kp_u_outlet_detection_100_complete_co); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4374, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4375 - * flow_dir_band = None - * LOGGER.info('outlet detection: 100% complete -- committing transaction') - * outlet_layer.CommitTransaction() # <<<<<<<<<<<<<< - * outlet_layer = None - * outlet_vector = None - */ - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_outlet_layer, __pyx_n_s_CommitTransaction); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4375, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - } - } - __pyx_t_10 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_14); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4375, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4376 - * LOGGER.info('outlet detection: 100% complete -- committing transaction') - * outlet_layer.CommitTransaction() - * outlet_layer = None # <<<<<<<<<<<<<< - * outlet_vector = None - * LOGGER.info('outlet detection: done') - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_outlet_layer, Py_None); - - /* "pygeoprocessing/routing/routing.pyx":4377 - * outlet_layer.CommitTransaction() - * outlet_layer = None - * outlet_vector = None # <<<<<<<<<<<<<< - * LOGGER.info('outlet detection: done') - * - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_outlet_vector, Py_None); - - /* "pygeoprocessing/routing/routing.pyx":4378 - * outlet_layer = None - * outlet_vector = None - * LOGGER.info('outlet detection: done') # <<<<<<<<<<<<<< - * - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4378, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4378, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_14 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_14)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_14); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_10 = (__pyx_t_14) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_14, __pyx_kp_u_outlet_detection_done) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_kp_u_outlet_detection_done); - __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; - if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4378, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4162 - * - * - * def detect_outlets( # <<<<<<<<<<<<<< - * flow_dir_raster_path_band, flow_dir_type, target_outlet_vector_path): - * """Create point vector indicating flow raster outlets. - */ - - /* 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_7); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_14); - __Pyx_XDECREF(__pyx_t_29); - { 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_block.rcbuffer->pybuffer); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("pygeoprocessing.routing.routing.detect_outlets", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_flow_dir_block.rcbuffer->pybuffer); - __pyx_L2:; - __Pyx_XDECREF((PyObject *)__pyx_v_flow_dir_block); - __Pyx_XDECREF(__pyx_v_raster_info); - __Pyx_XDECREF(__pyx_v_flow_dir_raster); - __Pyx_XDECREF(__pyx_v_flow_dir_band); - __Pyx_XDECREF(__pyx_v_raster_srs); - __Pyx_XDECREF(__pyx_v_gpkg_driver); - __Pyx_XDECREF(__pyx_v_outlet_vector); - __Pyx_XDECREF(__pyx_v_outet_basename); - __Pyx_XDECREF(__pyx_v_outlet_layer); - __Pyx_XDECREF(__pyx_v_block_offsets); - __Pyx_XDECREF(__pyx_v_current_pixel); - __Pyx_XDECREF(__pyx_v_outlet_point); - __Pyx_XDECREF(__pyx_v_proj_x); - __Pyx_XDECREF(__pyx_v_proj_y); - __Pyx_XDECREF(__pyx_v_outlet_feature); - __Pyx_XDECREF(__pyx_v_flow_dir_type); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pygeoprocessing/routing/routing.pyx":4381 - * - * - * cdef void _diagonal_fill_step( # <<<<<<<<<<<<<< - * int x_l, int y_l, int edge_dir, - * long discovery, long finish, - */ - -static void __pyx_f_15pygeoprocessing_7routing_7routing__diagonal_fill_step(int __pyx_v_x_l, int __pyx_v_y_l, int __pyx_v_edge_dir, long __pyx_v_discovery, long __pyx_v_finish, struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_discovery_managed_raster, long __pyx_v_discovery_nodata, PyObject *__pyx_v_boundary_list) { - int __pyx_v_xdelta; - int __pyx_v_ydelta; - PyObject *__pyx_v_test_list = NULL; - PyObject *__pyx_v_x_t = NULL; - PyObject *__pyx_v_y_t = NULL; - long __pyx_v_point_discovery; - __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; - Py_ssize_t __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - PyObject *(*__pyx_t_8)(PyObject *); - int __pyx_t_9; - int __pyx_t_10; - int __pyx_t_11; - int __pyx_t_12; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("_diagonal_fill_step", 0); - - /* "pygeoprocessing/routing/routing.pyx":4419 - * """ - * # always add the current pixel - * boundary_list.append((x_l, y_l)) # <<<<<<<<<<<<<< - * - * # this section determines which back diagonal was in the watershed and - */ - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_x_l); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4419, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_y_l); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4419, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4419, __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_2); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); - __pyx_t_1 = 0; - __pyx_t_2 = 0; - __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_boundary_list, __pyx_t_3); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 4419, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4423 - * # this section determines which back diagonal was in the watershed and - * # fills it. if none are we pick one so there's no degenerate case - * cdef int xdelta = D8_XOFFSET[edge_dir] # <<<<<<<<<<<<<< - * cdef int ydelta = D8_YOFFSET[edge_dir] - * test_list = [ - */ - __pyx_v_xdelta = (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_edge_dir]); - - /* "pygeoprocessing/routing/routing.pyx":4424 - * # fills it. if none are we pick one so there's no degenerate case - * cdef int xdelta = D8_XOFFSET[edge_dir] - * cdef int ydelta = D8_YOFFSET[edge_dir] # <<<<<<<<<<<<<< - * test_list = [ - * (x_l - xdelta, y_l), - */ - __pyx_v_ydelta = (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_edge_dir]); - - /* "pygeoprocessing/routing/routing.pyx":4426 - * cdef int ydelta = D8_YOFFSET[edge_dir] - * test_list = [ - * (x_l - xdelta, y_l), # <<<<<<<<<<<<<< - * (x_l, y_l - ydelta)] - * for x_t, y_t in test_list: - */ - __pyx_t_3 = __Pyx_PyInt_From_int((__pyx_v_x_l - __pyx_v_xdelta)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4426, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_y_l); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4426, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4426, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2); - __pyx_t_3 = 0; - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4427 - * test_list = [ - * (x_l - xdelta, y_l), - * (x_l, y_l - ydelta)] # <<<<<<<<<<<<<< - * for x_t, y_t in test_list: - * point_discovery = discovery_managed_raster.get( - */ - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_x_l); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4427, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_From_int((__pyx_v_y_l - __pyx_v_ydelta)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4427, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4427, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3); - __pyx_t_2 = 0; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4425 - * cdef int xdelta = D8_XOFFSET[edge_dir] - * cdef int ydelta = D8_YOFFSET[edge_dir] - * test_list = [ # <<<<<<<<<<<<<< - * (x_l - xdelta, y_l), - * (x_l, y_l - ydelta)] - */ - __pyx_t_3 = PyList_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4425, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_1); - PyList_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_5); - PyList_SET_ITEM(__pyx_t_3, 1, __pyx_t_5); - __pyx_t_1 = 0; - __pyx_t_5 = 0; - __pyx_v_test_list = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4428 - * (x_l - xdelta, y_l), - * (x_l, y_l - ydelta)] - * for x_t, y_t in test_list: # <<<<<<<<<<<<<< - * point_discovery = discovery_managed_raster.get( - * x_t, y_t) - */ - __pyx_t_3 = __pyx_v_test_list; __Pyx_INCREF(__pyx_t_3); __pyx_t_6 = 0; - for (;;) { - if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 4428, __pyx_L1_error) - #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4428, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - 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, 4428, __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, 4428, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4428, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_7 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4428, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; - index = 0; __pyx_t_1 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_1)) goto __pyx_L5_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - index = 1; __pyx_t_2 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_2)) goto __pyx_L5_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 4428, __pyx_L1_error) - __pyx_t_8 = NULL; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L6_unpacking_done; - __pyx_L5_unpacking_failed:; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_8 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 4428, __pyx_L1_error) - __pyx_L6_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v_x_t, __pyx_t_1); - __pyx_t_1 = 0; - __Pyx_XDECREF_SET(__pyx_v_y_t, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4430 - * for x_t, y_t in test_list: - * point_discovery = discovery_managed_raster.get( - * x_t, y_t) # <<<<<<<<<<<<<< - * if (point_discovery != discovery_nodata and - * point_discovery >= discovery and - */ - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_v_x_t); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4430, __pyx_L1_error) - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_v_y_t); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4430, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":4429 - * (x_l, y_l - ydelta)] - * for x_t, y_t in test_list: - * point_discovery = discovery_managed_raster.get( # <<<<<<<<<<<<<< - * x_t, y_t) - * if (point_discovery != discovery_nodata and - */ - __pyx_v_point_discovery = ((long)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_discovery_managed_raster, __pyx_t_9, __pyx_t_10)); - - /* "pygeoprocessing/routing/routing.pyx":4431 - * point_discovery = discovery_managed_raster.get( - * x_t, y_t) - * if (point_discovery != discovery_nodata and # <<<<<<<<<<<<<< - * point_discovery >= discovery and - * point_discovery <= finish): - */ - __pyx_t_12 = ((__pyx_v_point_discovery != __pyx_v_discovery_nodata) != 0); - if (__pyx_t_12) { - } else { - __pyx_t_11 = __pyx_t_12; - goto __pyx_L8_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":4432 - * x_t, y_t) - * if (point_discovery != discovery_nodata and - * point_discovery >= discovery and # <<<<<<<<<<<<<< - * point_discovery <= finish): - * boundary_list.append((int(x_t), int(y_t))) - */ - __pyx_t_12 = ((__pyx_v_point_discovery >= __pyx_v_discovery) != 0); - if (__pyx_t_12) { - } else { - __pyx_t_11 = __pyx_t_12; - goto __pyx_L8_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":4433 - * if (point_discovery != discovery_nodata and - * point_discovery >= discovery and - * point_discovery <= finish): # <<<<<<<<<<<<<< - * boundary_list.append((int(x_t), int(y_t))) - * # there's only one diagonal to fill in so it's done here - */ - __pyx_t_12 = ((__pyx_v_point_discovery <= __pyx_v_finish) != 0); - __pyx_t_11 = __pyx_t_12; - __pyx_L8_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":4431 - * point_discovery = discovery_managed_raster.get( - * x_t, y_t) - * if (point_discovery != discovery_nodata and # <<<<<<<<<<<<<< - * point_discovery >= discovery and - * point_discovery <= finish): - */ - if (__pyx_t_11) { - - /* "pygeoprocessing/routing/routing.pyx":4434 - * point_discovery >= discovery and - * point_discovery <= finish): - * boundary_list.append((int(x_t), int(y_t))) # <<<<<<<<<<<<<< - * # there's only one diagonal to fill in so it's done here - * return - */ - __pyx_t_5 = __Pyx_PyNumber_Int(__pyx_v_x_t); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4434, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_2 = __Pyx_PyNumber_Int(__pyx_v_y_t); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4434, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4434, __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_2); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2); - __pyx_t_5 = 0; - __pyx_t_2 = 0; - __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_boundary_list, __pyx_t_1); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 4434, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4436 - * boundary_list.append((int(x_t), int(y_t))) - * # there's only one diagonal to fill in so it's done here - * return # <<<<<<<<<<<<<< - * - * # if there's a degenerate case then just add the xdelta, - */ - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L0; - - /* "pygeoprocessing/routing/routing.pyx":4431 - * point_discovery = discovery_managed_raster.get( - * x_t, y_t) - * if (point_discovery != discovery_nodata and # <<<<<<<<<<<<<< - * point_discovery >= discovery and - * point_discovery <= finish): - */ - } - - /* "pygeoprocessing/routing/routing.pyx":4428 - * (x_l - xdelta, y_l), - * (x_l, y_l - ydelta)] - * for x_t, y_t in test_list: # <<<<<<<<<<<<<< - * point_discovery = discovery_managed_raster.get( - * x_t, y_t) - */ - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4440 - * # if there's a degenerate case then just add the xdelta, - * # it doesn't matter - * boundary_list.append(test_list[0]) # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_3 = __Pyx_GetItemInt_List(__pyx_v_test_list, 0, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4440, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_boundary_list, __pyx_t_3); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 4440, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4381 - * - * - * cdef void _diagonal_fill_step( # <<<<<<<<<<<<<< - * int x_l, int y_l, int edge_dir, - * long discovery, long finish, - */ - - /* 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_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_WriteUnraisable("pygeoprocessing.routing.routing._diagonal_fill_step", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_test_list); - __Pyx_XDECREF(__pyx_v_x_t); - __Pyx_XDECREF(__pyx_v_y_t); - __Pyx_RefNannyFinishContext(); -} - -/* "pygeoprocessing/routing/routing.pyx":4443 - * - * - * cdef int _in_watershed( # <<<<<<<<<<<<<< - * int x_l, int y_l, int direction_to_test, int discovery, int finish, - * int n_cols, int n_rows, - */ - -static int __pyx_f_15pygeoprocessing_7routing_7routing__in_watershed(int __pyx_v_x_l, int __pyx_v_y_l, int __pyx_v_direction_to_test, int __pyx_v_discovery, int __pyx_v_finish, int __pyx_v_n_cols, int __pyx_v_n_rows, struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_discovery_managed_raster, long __pyx_v_discovery_nodata) { - int __pyx_v_x_n; - int __pyx_v_y_n; - long __pyx_v_point_discovery; - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - __Pyx_RefNannySetupContext("_in_watershed", 0); - - /* "pygeoprocessing/routing/routing.pyx":4466 - * 1 if in, 0 if out. - * """ - * cdef int x_n = x_l + D8_XOFFSET[direction_to_test] # <<<<<<<<<<<<<< - * cdef int y_n = y_l + D8_YOFFSET[direction_to_test] - * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: - */ - __pyx_v_x_n = (__pyx_v_x_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_direction_to_test])); - - /* "pygeoprocessing/routing/routing.pyx":4467 - * """ - * cdef int x_n = x_l + D8_XOFFSET[direction_to_test] - * cdef int y_n = y_l + D8_YOFFSET[direction_to_test] # <<<<<<<<<<<<<< - * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: - * return 0 - */ - __pyx_v_y_n = (__pyx_v_y_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_direction_to_test])); - - /* "pygeoprocessing/routing/routing.pyx":4468 - * cdef int x_n = x_l + D8_XOFFSET[direction_to_test] - * cdef int y_n = y_l + D8_YOFFSET[direction_to_test] - * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: # <<<<<<<<<<<<<< - * return 0 - * cdef long point_discovery = discovery_managed_raster.get(x_n, y_n) - */ - __pyx_t_2 = ((__pyx_v_x_n < 0) != 0); - if (!__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_2 = ((__pyx_v_y_n < 0) != 0); - if (!__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_2 = ((__pyx_v_x_n >= __pyx_v_n_cols) != 0); - if (!__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_2 = ((__pyx_v_y_n >= __pyx_v_n_rows) != 0); - __pyx_t_1 = __pyx_t_2; - __pyx_L4_bool_binop_done:; - if (__pyx_t_1) { - - /* "pygeoprocessing/routing/routing.pyx":4469 - * cdef int y_n = y_l + D8_YOFFSET[direction_to_test] - * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: - * return 0 # <<<<<<<<<<<<<< - * cdef long point_discovery = discovery_managed_raster.get(x_n, y_n) - * return (point_discovery != discovery_nodata and - */ - __pyx_r = 0; - goto __pyx_L0; - - /* "pygeoprocessing/routing/routing.pyx":4468 - * cdef int x_n = x_l + D8_XOFFSET[direction_to_test] - * cdef int y_n = y_l + D8_YOFFSET[direction_to_test] - * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: # <<<<<<<<<<<<<< - * return 0 - * cdef long point_discovery = discovery_managed_raster.get(x_n, y_n) - */ - } - - /* "pygeoprocessing/routing/routing.pyx":4470 - * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: - * return 0 - * cdef long point_discovery = discovery_managed_raster.get(x_n, y_n) # <<<<<<<<<<<<<< - * return (point_discovery != discovery_nodata and - * point_discovery >= discovery and - */ - __pyx_v_point_discovery = ((long)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_discovery_managed_raster, __pyx_v_x_n, __pyx_v_y_n)); - - /* "pygeoprocessing/routing/routing.pyx":4471 - * return 0 - * cdef long point_discovery = discovery_managed_raster.get(x_n, y_n) - * return (point_discovery != discovery_nodata and # <<<<<<<<<<<<<< - * point_discovery >= discovery and - * point_discovery <= finish) - */ - __pyx_t_1 = (__pyx_v_point_discovery != __pyx_v_discovery_nodata); - if (__pyx_t_1) { - } else { - __pyx_t_3 = __pyx_t_1; - goto __pyx_L8_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":4472 - * cdef long point_discovery = discovery_managed_raster.get(x_n, y_n) - * return (point_discovery != discovery_nodata and - * point_discovery >= discovery and # <<<<<<<<<<<<<< - * point_discovery <= finish) - * - */ - __pyx_t_1 = (__pyx_v_point_discovery >= __pyx_v_discovery); - if (__pyx_t_1) { - } else { - __pyx_t_3 = __pyx_t_1; - goto __pyx_L8_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":4473 - * return (point_discovery != discovery_nodata and - * point_discovery >= discovery and - * point_discovery <= finish) # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_1 = (__pyx_v_point_discovery <= __pyx_v_finish); - __pyx_t_3 = __pyx_t_1; - __pyx_L8_bool_binop_done:; - __pyx_r = __pyx_t_3; - goto __pyx_L0; - - /* "pygeoprocessing/routing/routing.pyx":4443 - * - * - * cdef int _in_watershed( # <<<<<<<<<<<<<< - * int x_l, int y_l, int direction_to_test, int discovery, int finish, - * int n_cols, int n_rows, - */ - - /* function exit code */ - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pygeoprocessing/routing/routing.pyx":4476 - * - * - * cdef _calculate_stream_geometry( # <<<<<<<<<<<<<< - * int x_l, int y_l, int upstream_d8_dir, geotransform, int n_cols, - * int n_rows, _ManagedRaster flow_accum_managed_raster, - */ - -static PyObject *__pyx_f_15pygeoprocessing_7routing_7routing__calculate_stream_geometry(int __pyx_v_x_l, int __pyx_v_y_l, int __pyx_v_upstream_d8_dir, PyObject *__pyx_v_geotransform, int __pyx_v_n_cols, int __pyx_v_n_rows, struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_flow_accum_managed_raster, struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_flow_dir_managed_raster, int __pyx_v_flow_dir_nodata, int __pyx_v_flow_accum_threshold, PyObject *__pyx_v_coord_to_stream_ids) { - int __pyx_v_x_1; - int __pyx_v_y_1; - int __pyx_v_x_n; - int __pyx_v_y_n; - int __pyx_v_d; - int __pyx_v_d_n; - int __pyx_v_stream_end; - int __pyx_v_pixel_length; - PyObject *__pyx_v_upstream_id_list = NULL; - PyObject *__pyx_v_stream_line = NULL; - PyObject *__pyx_v_x_p = NULL; - PyObject *__pyx_v_y_p = NULL; - int __pyx_v_next_dir; - int __pyx_v_last_dir; - 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; - int __pyx_t_7; - PyObject *__pyx_t_8 = NULL; - PyObject *(*__pyx_t_9)(PyObject *); - int __pyx_t_10; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("_calculate_stream_geometry", 0); - - /* "pygeoprocessing/routing/routing.pyx":4518 - * - * """ - * cdef int x_1, y_1, x_n, y_n, d, d_n, stream_end=0, pixel_length # <<<<<<<<<<<<<< - * - * if flow_accum_managed_raster.get(x_l, y_l) < flow_accum_threshold: - */ - __pyx_v_stream_end = 0; - - /* "pygeoprocessing/routing/routing.pyx":4520 - * cdef int x_1, y_1, x_n, y_n, d, d_n, stream_end=0, pixel_length - * - * if flow_accum_managed_raster.get(x_l, y_l) < flow_accum_threshold: # <<<<<<<<<<<<<< - * return None - * upstream_id_list = [] - */ - __pyx_t_1 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_accum_managed_raster, __pyx_v_x_l, __pyx_v_y_l) < __pyx_v_flow_accum_threshold) != 0); - if (__pyx_t_1) { - - /* "pygeoprocessing/routing/routing.pyx":4521 - * - * if flow_accum_managed_raster.get(x_l, y_l) < flow_accum_threshold: - * return None # <<<<<<<<<<<<<< - * upstream_id_list = [] - * # anchor the line at the downstream end - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - - /* "pygeoprocessing/routing/routing.pyx":4520 - * cdef int x_1, y_1, x_n, y_n, d, d_n, stream_end=0, pixel_length - * - * if flow_accum_managed_raster.get(x_l, y_l) < flow_accum_threshold: # <<<<<<<<<<<<<< - * return None - * upstream_id_list = [] - */ - } - - /* "pygeoprocessing/routing/routing.pyx":4522 - * if flow_accum_managed_raster.get(x_l, y_l) < flow_accum_threshold: - * return None - * upstream_id_list = [] # <<<<<<<<<<<<<< - * # anchor the line at the downstream end - * stream_line = ogr.Geometry(ogr.wkbLineString) - */ - __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4522, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_v_upstream_id_list = __pyx_t_2; - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4524 - * upstream_id_list = [] - * # anchor the line at the downstream end - * stream_line = ogr.Geometry(ogr.wkbLineString) # <<<<<<<<<<<<<< - * x_p, y_p = gdal.ApplyGeoTransform(geotransform, x_l+0.5, y_l+0.5) - * stream_line.AddPoint(x_p, y_p) - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_ogr); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4524, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_Geometry); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4524, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_ogr); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4524, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_wkbLineString); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4524, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - 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_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4524, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_stream_line = __pyx_t_2; - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4525 - * # anchor the line at the downstream end - * stream_line = ogr.Geometry(ogr.wkbLineString) - * x_p, y_p = gdal.ApplyGeoTransform(geotransform, x_l+0.5, y_l+0.5) # <<<<<<<<<<<<<< - * stream_line.AddPoint(x_p, y_p) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4525, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_ApplyGeoTransform); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4525, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyFloat_FromDouble((__pyx_v_x_l + 0.5)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4525, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyFloat_FromDouble((__pyx_v_y_l + 0.5)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4525, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = NULL; - __pyx_t_7 = 0; - 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); - __pyx_t_7 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[4] = {__pyx_t_6, __pyx_v_geotransform, __pyx_t_4, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_7, 3+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4525, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_2); - __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_5)) { - PyObject *__pyx_temp[4] = {__pyx_t_6, __pyx_v_geotransform, __pyx_t_4, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_7, 3+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4525, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - { - __pyx_t_8 = PyTuple_New(3+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4525, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - if (__pyx_t_6) { - __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL; - } - __Pyx_INCREF(__pyx_v_geotransform); - __Pyx_GIVEREF(__pyx_v_geotransform); - PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_v_geotransform); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_8, 2+__pyx_t_7, __pyx_t_3); - __pyx_t_4 = 0; - __pyx_t_3 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4525, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - 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 != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 4525, __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_8 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_5 = PyList_GET_ITEM(sequence, 0); - __pyx_t_8 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(__pyx_t_8); - #else - __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4525, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_8 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4525, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - #endif - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4525, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_9 = Py_TYPE(__pyx_t_3)->tp_iternext; - index = 0; __pyx_t_5 = __pyx_t_9(__pyx_t_3); if (unlikely(!__pyx_t_5)) goto __pyx_L4_unpacking_failed; - __Pyx_GOTREF(__pyx_t_5); - index = 1; __pyx_t_8 = __pyx_t_9(__pyx_t_3); if (unlikely(!__pyx_t_8)) goto __pyx_L4_unpacking_failed; - __Pyx_GOTREF(__pyx_t_8); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_3), 2) < 0) __PYX_ERR(0, 4525, __pyx_L1_error) - __pyx_t_9 = NULL; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L5_unpacking_done; - __pyx_L4_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, 4525, __pyx_L1_error) - __pyx_L5_unpacking_done:; - } - __pyx_v_x_p = __pyx_t_5; - __pyx_t_5 = 0; - __pyx_v_y_p = __pyx_t_8; - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4526 - * stream_line = ogr.Geometry(ogr.wkbLineString) - * x_p, y_p = gdal.ApplyGeoTransform(geotransform, x_l+0.5, y_l+0.5) - * stream_line.AddPoint(x_p, y_p) # <<<<<<<<<<<<<< - * - * # initialize next_dir and last_dir so we only drop new points when - */ - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_line, __pyx_n_s_AddPoint); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4526, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 = NULL; - __pyx_t_7 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - __pyx_t_7 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_x_p, __pyx_v_y_p}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4526, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_x_p, __pyx_v_y_p}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4526, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - { - __pyx_t_3 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4526, __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_x_p); - __Pyx_GIVEREF(__pyx_v_x_p); - PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_7, __pyx_v_x_p); - __Pyx_INCREF(__pyx_v_y_p); - __Pyx_GIVEREF(__pyx_v_y_p); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_7, __pyx_v_y_p); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4526, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4530 - * # initialize next_dir and last_dir so we only drop new points when - * # the line changes direction - * cdef int next_dir = upstream_d8_dir # <<<<<<<<<<<<<< - * cdef int last_dir = next_dir - * - */ - __pyx_v_next_dir = __pyx_v_upstream_d8_dir; - - /* "pygeoprocessing/routing/routing.pyx":4531 - * # the line changes direction - * cdef int next_dir = upstream_d8_dir - * cdef int last_dir = next_dir # <<<<<<<<<<<<<< - * - * stream_end = 0 - */ - __pyx_v_last_dir = __pyx_v_next_dir; - - /* "pygeoprocessing/routing/routing.pyx":4533 - * cdef int last_dir = next_dir - * - * stream_end = 0 # <<<<<<<<<<<<<< - * pixel_length = 0 - * # initialize these for the compiler warniing - */ - __pyx_v_stream_end = 0; - - /* "pygeoprocessing/routing/routing.pyx":4534 - * - * stream_end = 0 - * pixel_length = 0 # <<<<<<<<<<<<<< - * # initialize these for the compiler warniing - * x_1 = -1 - */ - __pyx_v_pixel_length = 0; - - /* "pygeoprocessing/routing/routing.pyx":4536 - * pixel_length = 0 - * # initialize these for the compiler warniing - * x_1 = -1 # <<<<<<<<<<<<<< - * y_1 = -1 - * while not stream_end: - */ - __pyx_v_x_1 = -1; - - /* "pygeoprocessing/routing/routing.pyx":4537 - * # initialize these for the compiler warniing - * x_1 = -1 - * y_1 = -1 # <<<<<<<<<<<<<< - * while not stream_end: - * # walk upstream - */ - __pyx_v_y_1 = -1; - - /* "pygeoprocessing/routing/routing.pyx":4538 - * x_1 = -1 - * y_1 = -1 - * while not stream_end: # <<<<<<<<<<<<<< - * # walk upstream - * x_l += D8_XOFFSET[next_dir] - */ - while (1) { - __pyx_t_1 = ((!(__pyx_v_stream_end != 0)) != 0); - if (!__pyx_t_1) break; - - /* "pygeoprocessing/routing/routing.pyx":4540 - * while not stream_end: - * # walk upstream - * x_l += D8_XOFFSET[next_dir] # <<<<<<<<<<<<<< - * y_l += D8_YOFFSET[next_dir] - * - */ - __pyx_v_x_l = (__pyx_v_x_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_next_dir])); - - /* "pygeoprocessing/routing/routing.pyx":4541 - * # walk upstream - * x_l += D8_XOFFSET[next_dir] - * y_l += D8_YOFFSET[next_dir] # <<<<<<<<<<<<<< - * - * stream_end = 1 - */ - __pyx_v_y_l = (__pyx_v_y_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_next_dir])); - - /* "pygeoprocessing/routing/routing.pyx":4543 - * y_l += D8_YOFFSET[next_dir] - * - * stream_end = 1 # <<<<<<<<<<<<<< - * pixel_length += 1 - * # do <= 1 in case there's a degenerate single point stream - */ - __pyx_v_stream_end = 1; - - /* "pygeoprocessing/routing/routing.pyx":4544 - * - * stream_end = 1 - * pixel_length += 1 # <<<<<<<<<<<<<< - * # do <= 1 in case there's a degenerate single point stream - * if pixel_length <= 1: - */ - __pyx_v_pixel_length = (__pyx_v_pixel_length + 1); - - /* "pygeoprocessing/routing/routing.pyx":4546 - * pixel_length += 1 - * # do <= 1 in case there's a degenerate single point stream - * if pixel_length <= 1: # <<<<<<<<<<<<<< - * x_1 = x_l - * y_1 = y_l - */ - __pyx_t_1 = ((__pyx_v_pixel_length <= 1) != 0); - if (__pyx_t_1) { - - /* "pygeoprocessing/routing/routing.pyx":4547 - * # do <= 1 in case there's a degenerate single point stream - * if pixel_length <= 1: - * x_1 = x_l # <<<<<<<<<<<<<< - * y_1 = y_l - * - */ - __pyx_v_x_1 = __pyx_v_x_l; - - /* "pygeoprocessing/routing/routing.pyx":4548 - * if pixel_length <= 1: - * x_1 = x_l - * y_1 = y_l # <<<<<<<<<<<<<< - * - * # check if we reached an upstream junction - */ - __pyx_v_y_1 = __pyx_v_y_l; - - /* "pygeoprocessing/routing/routing.pyx":4546 - * pixel_length += 1 - * # do <= 1 in case there's a degenerate single point stream - * if pixel_length <= 1: # <<<<<<<<<<<<<< - * x_1 = x_l - * y_1 = y_l - */ - } - - /* "pygeoprocessing/routing/routing.pyx":4551 - * - * # check if we reached an upstream junction - * if (x_l, y_l) in coord_to_stream_ids: # <<<<<<<<<<<<<< - * upstream_id_list = coord_to_stream_ids[(x_l, y_l)] - * del coord_to_stream_ids[(x_l, y_l)] - */ - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_x_l); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4551, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_y_l); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4551, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4551, __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_8); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_8); - __pyx_t_2 = 0; - __pyx_t_8 = 0; - __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_t_3, __pyx_v_coord_to_stream_ids, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 4551, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_10 = (__pyx_t_1 != 0); - if (__pyx_t_10) { - - /* "pygeoprocessing/routing/routing.pyx":4552 - * # check if we reached an upstream junction - * if (x_l, y_l) in coord_to_stream_ids: - * upstream_id_list = coord_to_stream_ids[(x_l, y_l)] # <<<<<<<<<<<<<< - * del coord_to_stream_ids[(x_l, y_l)] - * elif flow_accum_managed_raster.get(x_l, y_l) >= \ - */ - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_x_l); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4552, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_y_l); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4552, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4552, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_8); - __pyx_t_3 = 0; - __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_coord_to_stream_ids, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4552, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF_SET(__pyx_v_upstream_id_list, __pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4553 - * if (x_l, y_l) in coord_to_stream_ids: - * upstream_id_list = coord_to_stream_ids[(x_l, y_l)] - * del coord_to_stream_ids[(x_l, y_l)] # <<<<<<<<<<<<<< - * elif flow_accum_managed_raster.get(x_l, y_l) >= \ - * flow_accum_threshold: - */ - __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_x_l); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4553, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_y_l); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4553, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4553, __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_2); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); - __pyx_t_8 = 0; - __pyx_t_2 = 0; - if (unlikely(PyObject_DelItem(__pyx_v_coord_to_stream_ids, __pyx_t_3) < 0)) __PYX_ERR(0, 4553, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4551 - * - * # check if we reached an upstream junction - * if (x_l, y_l) in coord_to_stream_ids: # <<<<<<<<<<<<<< - * upstream_id_list = coord_to_stream_ids[(x_l, y_l)] - * del coord_to_stream_ids[(x_l, y_l)] - */ - goto __pyx_L9; - } - - /* "pygeoprocessing/routing/routing.pyx":4554 - * upstream_id_list = coord_to_stream_ids[(x_l, y_l)] - * del coord_to_stream_ids[(x_l, y_l)] - * elif flow_accum_managed_raster.get(x_l, y_l) >= \ # <<<<<<<<<<<<<< - * flow_accum_threshold: - * # check to see if we can take a step upstream - */ - __pyx_t_10 = ((((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_accum_managed_raster, __pyx_v_x_l, __pyx_v_y_l)) >= __pyx_v_flow_accum_threshold) != 0); - if (__pyx_t_10) { - - /* "pygeoprocessing/routing/routing.pyx":4557 - * flow_accum_threshold: - * # check to see if we can take a step upstream - * for d in range(8): # <<<<<<<<<<<<<< - * x_n = x_l + D8_XOFFSET[d] - * y_n = y_l + D8_YOFFSET[d] - */ - for (__pyx_t_7 = 0; __pyx_t_7 < 8; __pyx_t_7+=1) { - __pyx_v_d = __pyx_t_7; - - /* "pygeoprocessing/routing/routing.pyx":4558 - * # check to see if we can take a step upstream - * for d in range(8): - * x_n = x_l + D8_XOFFSET[d] # <<<<<<<<<<<<<< - * y_n = y_l + D8_YOFFSET[d] - * - */ - __pyx_v_x_n = (__pyx_v_x_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET[__pyx_v_d])); - - /* "pygeoprocessing/routing/routing.pyx":4559 - * for d in range(8): - * x_n = x_l + D8_XOFFSET[d] - * y_n = y_l + D8_YOFFSET[d] # <<<<<<<<<<<<<< - * - * # check out of bounds - */ - __pyx_v_y_n = (__pyx_v_y_l + (__pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET[__pyx_v_d])); - - /* "pygeoprocessing/routing/routing.pyx":4562 - * - * # check out of bounds - * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_1 = ((__pyx_v_x_n < 0) != 0); - if (!__pyx_t_1) { - } else { - __pyx_t_10 = __pyx_t_1; - goto __pyx_L13_bool_binop_done; - } - __pyx_t_1 = ((__pyx_v_y_n < 0) != 0); - if (!__pyx_t_1) { - } else { - __pyx_t_10 = __pyx_t_1; - goto __pyx_L13_bool_binop_done; - } - __pyx_t_1 = ((__pyx_v_x_n >= __pyx_v_n_cols) != 0); - if (!__pyx_t_1) { - } else { - __pyx_t_10 = __pyx_t_1; - goto __pyx_L13_bool_binop_done; - } - __pyx_t_1 = ((__pyx_v_y_n >= __pyx_v_n_rows) != 0); - __pyx_t_10 = __pyx_t_1; - __pyx_L13_bool_binop_done:; - if (__pyx_t_10) { - - /* "pygeoprocessing/routing/routing.pyx":4563 - * # check out of bounds - * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: - * continue # <<<<<<<<<<<<<< - * - * # check for nodata - */ - goto __pyx_L10_continue; - - /* "pygeoprocessing/routing/routing.pyx":4562 - * - * # check out of bounds - * if x_n < 0 or y_n < 0 or x_n >= n_cols or y_n >= n_rows: # <<<<<<<<<<<<<< - * continue - * - */ - } - - /* "pygeoprocessing/routing/routing.pyx":4566 - * - * # check for nodata - * d_n = flow_dir_managed_raster.get(x_n, y_n) # <<<<<<<<<<<<<< - * if d_n == flow_dir_nodata: - * continue - */ - __pyx_v_d_n = ((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_dir_managed_raster, __pyx_v_x_n, __pyx_v_y_n)); - - /* "pygeoprocessing/routing/routing.pyx":4567 - * # check for nodata - * d_n = flow_dir_managed_raster.get(x_n, y_n) - * if d_n == flow_dir_nodata: # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_10 = ((__pyx_v_d_n == __pyx_v_flow_dir_nodata) != 0); - if (__pyx_t_10) { - - /* "pygeoprocessing/routing/routing.pyx":4568 - * d_n = flow_dir_managed_raster.get(x_n, y_n) - * if d_n == flow_dir_nodata: - * continue # <<<<<<<<<<<<<< - * - * # check if there's an upstream inflow pixel with flow accum - */ - goto __pyx_L10_continue; - - /* "pygeoprocessing/routing/routing.pyx":4567 - * # check for nodata - * d_n = flow_dir_managed_raster.get(x_n, y_n) - * if d_n == flow_dir_nodata: # <<<<<<<<<<<<<< - * continue - * - */ - } - - /* "pygeoprocessing/routing/routing.pyx":4572 - * # check if there's an upstream inflow pixel with flow accum - * # greater than the threshold - * if D8_REVERSE_DIRECTION[d] == d_n and ( # <<<<<<<<<<<<<< - * flow_accum_managed_raster.get( - * x_n, y_n) > flow_accum_threshold): - */ - __pyx_t_1 = (((__pyx_v_15pygeoprocessing_7routing_7routing_D8_REVERSE_DIRECTION[__pyx_v_d]) == __pyx_v_d_n) != 0); - if (__pyx_t_1) { - } else { - __pyx_t_10 = __pyx_t_1; - goto __pyx_L19_bool_binop_done; - } - - /* "pygeoprocessing/routing/routing.pyx":4574 - * if D8_REVERSE_DIRECTION[d] == d_n and ( - * flow_accum_managed_raster.get( - * x_n, y_n) > flow_accum_threshold): # <<<<<<<<<<<<<< - * stream_end = 0 - * next_dir = d - */ - __pyx_t_1 = ((((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_accum_managed_raster, __pyx_v_x_n, __pyx_v_y_n)) > __pyx_v_flow_accum_threshold) != 0); - __pyx_t_10 = __pyx_t_1; - __pyx_L19_bool_binop_done:; - - /* "pygeoprocessing/routing/routing.pyx":4572 - * # check if there's an upstream inflow pixel with flow accum - * # greater than the threshold - * if D8_REVERSE_DIRECTION[d] == d_n and ( # <<<<<<<<<<<<<< - * flow_accum_managed_raster.get( - * x_n, y_n) > flow_accum_threshold): - */ - if (__pyx_t_10) { - - /* "pygeoprocessing/routing/routing.pyx":4575 - * flow_accum_managed_raster.get( - * x_n, y_n) > flow_accum_threshold): - * stream_end = 0 # <<<<<<<<<<<<<< - * next_dir = d - * break - */ - __pyx_v_stream_end = 0; - - /* "pygeoprocessing/routing/routing.pyx":4576 - * x_n, y_n) > flow_accum_threshold): - * stream_end = 0 - * next_dir = d # <<<<<<<<<<<<<< - * break - * else: - */ - __pyx_v_next_dir = __pyx_v_d; - - /* "pygeoprocessing/routing/routing.pyx":4577 - * stream_end = 0 - * next_dir = d - * break # <<<<<<<<<<<<<< - * else: - * # terminated because of flow accumulation too small, so back up - */ - goto __pyx_L11_break; - - /* "pygeoprocessing/routing/routing.pyx":4572 - * # check if there's an upstream inflow pixel with flow accum - * # greater than the threshold - * if D8_REVERSE_DIRECTION[d] == d_n and ( # <<<<<<<<<<<<<< - * flow_accum_managed_raster.get( - * x_n, y_n) > flow_accum_threshold): - */ - } - __pyx_L10_continue:; - } - __pyx_L11_break:; - - /* "pygeoprocessing/routing/routing.pyx":4554 - * upstream_id_list = coord_to_stream_ids[(x_l, y_l)] - * del coord_to_stream_ids[(x_l, y_l)] - * elif flow_accum_managed_raster.get(x_l, y_l) >= \ # <<<<<<<<<<<<<< - * flow_accum_threshold: - * # check to see if we can take a step upstream - */ - goto __pyx_L9; - } - - /* "pygeoprocessing/routing/routing.pyx":4581 - * # terminated because of flow accumulation too small, so back up - * # one pixel - * pixel_length -= 1 # <<<<<<<<<<<<<< - * - * # drop a point on the line if direction changed or last point - */ - /*else*/ { - __pyx_v_pixel_length = (__pyx_v_pixel_length - 1); - } - __pyx_L9:; - - /* "pygeoprocessing/routing/routing.pyx":4584 - * - * # drop a point on the line if direction changed or last point - * if last_dir != next_dir or stream_end: # <<<<<<<<<<<<<< - * x_p, y_p = gdal.ApplyGeoTransform( - * geotransform, x_l+0.5, y_l+0.5) - */ - __pyx_t_1 = ((__pyx_v_last_dir != __pyx_v_next_dir) != 0); - if (!__pyx_t_1) { - } else { - __pyx_t_10 = __pyx_t_1; - goto __pyx_L22_bool_binop_done; - } - __pyx_t_1 = (__pyx_v_stream_end != 0); - __pyx_t_10 = __pyx_t_1; - __pyx_L22_bool_binop_done:; - if (__pyx_t_10) { - - /* "pygeoprocessing/routing/routing.pyx":4585 - * # drop a point on the line if direction changed or last point - * if last_dir != next_dir or stream_end: - * x_p, y_p = gdal.ApplyGeoTransform( # <<<<<<<<<<<<<< - * geotransform, x_l+0.5, y_l+0.5) - * stream_line.AddPoint(x_p, y_p) - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4585, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_ApplyGeoTransform); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4585, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4586 - * if last_dir != next_dir or stream_end: - * x_p, y_p = gdal.ApplyGeoTransform( - * geotransform, x_l+0.5, y_l+0.5) # <<<<<<<<<<<<<< - * stream_line.AddPoint(x_p, y_p) - * last_dir = next_dir - */ - __pyx_t_2 = PyFloat_FromDouble((__pyx_v_x_l + 0.5)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4586, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = PyFloat_FromDouble((__pyx_v_y_l + 0.5)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4586, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = NULL; - __pyx_t_7 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(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); - __pyx_t_7 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_geotransform, __pyx_t_2, __pyx_t_5}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_7, 3+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4585, __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; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_geotransform, __pyx_t_2, __pyx_t_5}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_7, 3+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4585, __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; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - { - __pyx_t_6 = PyTuple_New(3+__pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4585, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (__pyx_t_4) { - __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; - } - __Pyx_INCREF(__pyx_v_geotransform); - __Pyx_GIVEREF(__pyx_v_geotransform); - PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_7, __pyx_v_geotransform); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_7, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_7, __pyx_t_5); - __pyx_t_2 = 0; - __pyx_t_5 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4585, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 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, 4585, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_8 = PyList_GET_ITEM(sequence, 0); - __pyx_t_6 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(__pyx_t_6); - #else - __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4585, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4585, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - #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, 4585, __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_8 = __pyx_t_9(__pyx_t_5); if (unlikely(!__pyx_t_8)) goto __pyx_L24_unpacking_failed; - __Pyx_GOTREF(__pyx_t_8); - index = 1; __pyx_t_6 = __pyx_t_9(__pyx_t_5); if (unlikely(!__pyx_t_6)) goto __pyx_L24_unpacking_failed; - __Pyx_GOTREF(__pyx_t_6); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_5), 2) < 0) __PYX_ERR(0, 4585, __pyx_L1_error) - __pyx_t_9 = NULL; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - goto __pyx_L25_unpacking_done; - __pyx_L24_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, 4585, __pyx_L1_error) - __pyx_L25_unpacking_done:; - } - - /* "pygeoprocessing/routing/routing.pyx":4585 - * # drop a point on the line if direction changed or last point - * if last_dir != next_dir or stream_end: - * x_p, y_p = gdal.ApplyGeoTransform( # <<<<<<<<<<<<<< - * geotransform, x_l+0.5, y_l+0.5) - * stream_line.AddPoint(x_p, y_p) - */ - __Pyx_DECREF_SET(__pyx_v_x_p, __pyx_t_8); - __pyx_t_8 = 0; - __Pyx_DECREF_SET(__pyx_v_y_p, __pyx_t_6); - __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4587 - * x_p, y_p = gdal.ApplyGeoTransform( - * geotransform, x_l+0.5, y_l+0.5) - * stream_line.AddPoint(x_p, y_p) # <<<<<<<<<<<<<< - * last_dir = next_dir - * - */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_line, __pyx_n_s_AddPoint); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4587, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_8 = NULL; - __pyx_t_7 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - __pyx_t_7 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_x_p, __pyx_v_y_p}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4587, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_x_p, __pyx_v_y_p}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4587, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - { - __pyx_t_5 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4587, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (__pyx_t_8) { - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_8); __pyx_t_8 = NULL; - } - __Pyx_INCREF(__pyx_v_x_p); - __Pyx_GIVEREF(__pyx_v_x_p); - PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_7, __pyx_v_x_p); - __Pyx_INCREF(__pyx_v_y_p); - __Pyx_GIVEREF(__pyx_v_y_p); - PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_7, __pyx_v_y_p); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4587, __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(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4588 - * geotransform, x_l+0.5, y_l+0.5) - * stream_line.AddPoint(x_p, y_p) - * last_dir = next_dir # <<<<<<<<<<<<<< - * - * if pixel_length == 0: - */ - __pyx_v_last_dir = __pyx_v_next_dir; - - /* "pygeoprocessing/routing/routing.pyx":4584 - * - * # drop a point on the line if direction changed or last point - * if last_dir != next_dir or stream_end: # <<<<<<<<<<<<<< - * x_p, y_p = gdal.ApplyGeoTransform( - * geotransform, x_l+0.5, y_l+0.5) - */ - } - } - - /* "pygeoprocessing/routing/routing.pyx":4590 - * last_dir = next_dir - * - * if pixel_length == 0: # <<<<<<<<<<<<<< - * return None - * return x_l, y_l, x_1, y_1, upstream_id_list, stream_line - */ - __pyx_t_10 = ((__pyx_v_pixel_length == 0) != 0); - if (__pyx_t_10) { - - /* "pygeoprocessing/routing/routing.pyx":4591 - * - * if pixel_length == 0: - * return None # <<<<<<<<<<<<<< - * return x_l, y_l, x_1, y_1, upstream_id_list, stream_line - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - - /* "pygeoprocessing/routing/routing.pyx":4590 - * last_dir = next_dir - * - * if pixel_length == 0: # <<<<<<<<<<<<<< - * return None - * return x_l, y_l, x_1, y_1, upstream_id_list, stream_line - */ - } - - /* "pygeoprocessing/routing/routing.pyx":4592 - * if pixel_length == 0: - * return None - * return x_l, y_l, x_1, y_1, upstream_id_list, stream_line # <<<<<<<<<<<<<< - * - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_x_l); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4592, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_y_l); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4592, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_x_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4592, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_y_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4592, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_2 = PyTuple_New(6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4592, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_8); - __Pyx_INCREF(__pyx_v_upstream_id_list); - __Pyx_GIVEREF(__pyx_v_upstream_id_list); - PyTuple_SET_ITEM(__pyx_t_2, 4, __pyx_v_upstream_id_list); - __Pyx_INCREF(__pyx_v_stream_line); - __Pyx_GIVEREF(__pyx_v_stream_line); - PyTuple_SET_ITEM(__pyx_t_2, 5, __pyx_v_stream_line); - __pyx_t_3 = 0; - __pyx_t_6 = 0; - __pyx_t_5 = 0; - __pyx_t_8 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - - /* "pygeoprocessing/routing/routing.pyx":4476 - * - * - * cdef _calculate_stream_geometry( # <<<<<<<<<<<<<< - * int x_l, int y_l, int upstream_d8_dir, geotransform, int n_cols, - * int n_rows, _ManagedRaster flow_accum_managed_raster, - */ - - /* function exit code */ - __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); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("pygeoprocessing.routing.routing._calculate_stream_geometry", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_upstream_id_list); - __Pyx_XDECREF(__pyx_v_stream_line); - __Pyx_XDECREF(__pyx_v_x_p); - __Pyx_XDECREF(__pyx_v_y_p); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pygeoprocessing/routing/routing.pyx":4595 - * - * - * def _delete_feature( # <<<<<<<<<<<<<< - * stream_feature, stream_layer, upstream_to_downstream_id, - * downstream_to_upstream_ids): - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_29_delete_feature(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_15pygeoprocessing_7routing_7routing_28_delete_feature[] = "Helper for Mahler extraction to delete all references to a stream.\n\n Args:\n stream_feature (ogr.Feature): feature to delete\n stream_layer (ogr.Layer): layer to delete the feature\n upstream_to_downstream_id (dict): can be referenced by FID and should\n remove all instances of stream from this dict\n downstream_to_upstream_ids (dict): stream feature contained in\n the values of this dict and should remove all instances of stream\n from this dict\n\n Returns:\n None.\n "; -static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_29_delete_feature = {"_delete_feature", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_7routing_7routing_29_delete_feature, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_7routing_7routing_28_delete_feature}; -static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_29_delete_feature(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_stream_feature = 0; - PyObject *__pyx_v_stream_layer = 0; - PyObject *__pyx_v_upstream_to_downstream_id = 0; - PyObject *__pyx_v_downstream_to_upstream_ids = 0; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_delete_feature (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_stream_feature,&__pyx_n_s_stream_layer,&__pyx_n_s_upstream_to_downstream_id,&__pyx_n_s_downstream_to_upstream_ids,0}; - PyObject* values[4] = {0,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 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_stream_feature)) != 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_stream_layer)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_delete_feature", 1, 4, 4, 1); __PYX_ERR(0, 4595, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_upstream_to_downstream_id)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_delete_feature", 1, 4, 4, 2); __PYX_ERR(0, 4595, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_downstream_to_upstream_ids)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_delete_feature", 1, 4, 4, 3); __PYX_ERR(0, 4595, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_delete_feature") < 0)) __PYX_ERR(0, 4595, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { - 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); - values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - } - __pyx_v_stream_feature = values[0]; - __pyx_v_stream_layer = values[1]; - __pyx_v_upstream_to_downstream_id = values[2]; - __pyx_v_downstream_to_upstream_ids = values[3]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_delete_feature", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 4595, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pygeoprocessing.routing.routing._delete_feature", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing_28_delete_feature(__pyx_self, __pyx_v_stream_feature, __pyx_v_stream_layer, __pyx_v_upstream_to_downstream_id, __pyx_v_downstream_to_upstream_ids); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_28_delete_feature(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_stream_feature, PyObject *__pyx_v_stream_layer, PyObject *__pyx_v_upstream_to_downstream_id, PyObject *__pyx_v_downstream_to_upstream_ids) { - PyObject *__pyx_v_stream_fid = NULL; - PyObject *__pyx_v_downstream_fid = 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; - int __pyx_t_5; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("_delete_feature", 0); - - /* "pygeoprocessing/routing/routing.pyx":4612 - * None. - * """ - * stream_fid = stream_feature.GetFID() # <<<<<<<<<<<<<< - * if stream_fid in upstream_to_downstream_id: - * downstream_fid = upstream_to_downstream_id[ - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_feature, __pyx_n_s_GetFID); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4612, __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); - } - } - __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4612, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_stream_fid = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4613 - * """ - * stream_fid = stream_feature.GetFID() - * if stream_fid in upstream_to_downstream_id: # <<<<<<<<<<<<<< - * downstream_fid = upstream_to_downstream_id[ - * stream_fid] - */ - __pyx_t_4 = (__Pyx_PySequence_ContainsTF(__pyx_v_stream_fid, __pyx_v_upstream_to_downstream_id, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 4613, __pyx_L1_error) - __pyx_t_5 = (__pyx_t_4 != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":4614 - * stream_fid = stream_feature.GetFID() - * if stream_fid in upstream_to_downstream_id: - * downstream_fid = upstream_to_downstream_id[ # <<<<<<<<<<<<<< - * stream_fid] - * del upstream_to_downstream_id[stream_fid] - */ - __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_upstream_to_downstream_id, __pyx_v_stream_fid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4614, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_downstream_fid = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4616 - * downstream_fid = upstream_to_downstream_id[ - * stream_fid] - * del upstream_to_downstream_id[stream_fid] # <<<<<<<<<<<<<< - * if downstream_fid in downstream_to_upstream_ids: - * downstream_to_upstream_ids[ - */ - if (unlikely(PyObject_DelItem(__pyx_v_upstream_to_downstream_id, __pyx_v_stream_fid) < 0)) __PYX_ERR(0, 4616, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":4617 - * stream_fid] - * del upstream_to_downstream_id[stream_fid] - * if downstream_fid in downstream_to_upstream_ids: # <<<<<<<<<<<<<< - * downstream_to_upstream_ids[ - * downstream_fid].remove(stream_fid) - */ - __pyx_t_5 = (__Pyx_PySequence_ContainsTF(__pyx_v_downstream_fid, __pyx_v_downstream_to_upstream_ids, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 4617, __pyx_L1_error) - __pyx_t_4 = (__pyx_t_5 != 0); - if (__pyx_t_4) { - - /* "pygeoprocessing/routing/routing.pyx":4618 - * del upstream_to_downstream_id[stream_fid] - * if downstream_fid in downstream_to_upstream_ids: - * downstream_to_upstream_ids[ # <<<<<<<<<<<<<< - * downstream_fid].remove(stream_fid) - * if stream_fid in downstream_to_upstream_ids: - */ - __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_downstream_to_upstream_ids, __pyx_v_downstream_fid); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4618, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - - /* "pygeoprocessing/routing/routing.pyx":4619 - * if downstream_fid in downstream_to_upstream_ids: - * downstream_to_upstream_ids[ - * downstream_fid].remove(stream_fid) # <<<<<<<<<<<<<< - * if stream_fid in downstream_to_upstream_ids: - * del downstream_to_upstream_ids[ - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_remove); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4619, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_stream_fid) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_stream_fid); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4619, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4617 - * stream_fid] - * del upstream_to_downstream_id[stream_fid] - * if downstream_fid in downstream_to_upstream_ids: # <<<<<<<<<<<<<< - * downstream_to_upstream_ids[ - * downstream_fid].remove(stream_fid) - */ - } - - /* "pygeoprocessing/routing/routing.pyx":4613 - * """ - * stream_fid = stream_feature.GetFID() - * if stream_fid in upstream_to_downstream_id: # <<<<<<<<<<<<<< - * downstream_fid = upstream_to_downstream_id[ - * stream_fid] - */ - } - - /* "pygeoprocessing/routing/routing.pyx":4620 - * downstream_to_upstream_ids[ - * downstream_fid].remove(stream_fid) - * if stream_fid in downstream_to_upstream_ids: # <<<<<<<<<<<<<< - * del downstream_to_upstream_ids[ - * stream_fid] - */ - __pyx_t_4 = (__Pyx_PySequence_ContainsTF(__pyx_v_stream_fid, __pyx_v_downstream_to_upstream_ids, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 4620, __pyx_L1_error) - __pyx_t_5 = (__pyx_t_4 != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/routing.pyx":4622 - * if stream_fid in downstream_to_upstream_ids: - * del downstream_to_upstream_ids[ - * stream_fid] # <<<<<<<<<<<<<< - * stream_layer.DeleteFeature(stream_fid) - */ - if (unlikely(PyObject_DelItem(__pyx_v_downstream_to_upstream_ids, __pyx_v_stream_fid) < 0)) __PYX_ERR(0, 4621, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":4620 - * downstream_to_upstream_ids[ - * downstream_fid].remove(stream_fid) - * if stream_fid in downstream_to_upstream_ids: # <<<<<<<<<<<<<< - * del downstream_to_upstream_ids[ - * stream_fid] - */ - } - - /* "pygeoprocessing/routing/routing.pyx":4623 - * del downstream_to_upstream_ids[ - * stream_fid] - * stream_layer.DeleteFeature(stream_fid) # <<<<<<<<<<<<<< - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_layer, __pyx_n_s_DeleteFeature); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4623, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_stream_fid) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_stream_fid); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4623, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4595 - * - * - * def _delete_feature( # <<<<<<<<<<<<<< - * stream_feature, stream_layer, upstream_to_downstream_id, - * downstream_to_upstream_ids): - */ - - /* 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_AddTraceback("pygeoprocessing.routing.routing._delete_feature", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_stream_fid); - __Pyx_XDECREF(__pyx_v_downstream_fid); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":735 - * ctypedef npy_cdouble complex_t - * - * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(1, 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew1", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":736 - * - * cdef inline object PyArray_MultiIterNew1(a): - * return PyArray_MultiIterNew(1, 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, 736, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":735 - * ctypedef npy_cdouble complex_t - * - * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(1, 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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":738 - * return PyArray_MultiIterNew(1, a) - * - * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(2, a, 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew2", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":739 - * - * cdef inline object PyArray_MultiIterNew2(a, b): - * return PyArray_MultiIterNew(2, a, 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, 739, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":738 - * return PyArray_MultiIterNew(1, a) - * - * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(2, a, 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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":741 - * return PyArray_MultiIterNew(2, a, b) - * - * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(3, a, b, 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew3", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":742 - * - * cdef inline object PyArray_MultiIterNew3(a, b, c): - * return PyArray_MultiIterNew(3, a, b, 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, 742, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":741 - * return PyArray_MultiIterNew(2, a, b) - * - * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(3, a, b, 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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":744 - * return PyArray_MultiIterNew(3, a, b, c) - * - * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(4, a, b, c, 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew4", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":745 - * - * cdef inline object PyArray_MultiIterNew4(a, b, c, d): - * return PyArray_MultiIterNew(4, a, b, c, 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, 745, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":744 - * return PyArray_MultiIterNew(3, a, b, c) - * - * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(4, a, b, c, 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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":747 - * return PyArray_MultiIterNew(4, a, b, c, d) - * - * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(5, a, b, c, d, 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew5", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":748 - * - * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): - * return PyArray_MultiIterNew(5, a, b, c, d, 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, 748, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":747 - * return PyArray_MultiIterNew(4, a, b, c, d) - * - * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(5, a, b, c, d, 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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":750 - * return PyArray_MultiIterNew(5, a, b, c, d, e) - * - * cdef inline tuple PyDataType_SHAPE(dtype d): # <<<<<<<<<<<<<< - * if PyDataType_HASSUBARRAY(d): - * return 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); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":751 - * - * cdef inline tuple PyDataType_SHAPE(dtype d): - * if PyDataType_HASSUBARRAY(d): # <<<<<<<<<<<<<< - * return d.subarray.shape - * else: - */ - __pyx_t_1 = (PyDataType_HASSUBARRAY(__pyx_v_d) != 0); - if (__pyx_t_1) { - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":752 - * cdef inline tuple PyDataType_SHAPE(dtype d): - * if PyDataType_HASSUBARRAY(d): - * return 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; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":751 - * - * cdef inline tuple PyDataType_SHAPE(dtype d): - * if PyDataType_HASSUBARRAY(d): # <<<<<<<<<<<<<< - * return d.subarray.shape - * else: - */ - } - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":754 - * return d.subarray.shape - * else: - * return () # <<<<<<<<<<<<<< - * - * - */ - /*else*/ { - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_empty_tuple); - __pyx_r = __pyx_empty_tuple; - goto __pyx_L0; - } - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":750 - * return PyArray_MultiIterNew(5, a, b, c, d, e) - * - * cdef inline tuple PyDataType_SHAPE(dtype d): # <<<<<<<<<<<<<< - * if PyDataType_HASSUBARRAY(d): - * return d.subarray.shape - */ - - /* function exit code */ - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":931 - * int _import_umath() except -1 - * - * cdef inline void set_array_base(ndarray arr, object base): # <<<<<<<<<<<<<< - * Py_INCREF(base) # important to do this before stealing the reference below! - * PyArray_SetBaseObject(arr, base) - */ - -static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_arr, PyObject *__pyx_v_base) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("set_array_base", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":932 - * - * cdef inline void set_array_base(ndarray arr, object base): - * Py_INCREF(base) # important to do this before stealing the reference below! # <<<<<<<<<<<<<< - * PyArray_SetBaseObject(arr, base) - * - */ - Py_INCREF(__pyx_v_base); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":933 - * cdef inline void set_array_base(ndarray arr, object base): - * Py_INCREF(base) # important to do this before stealing the reference below! - * PyArray_SetBaseObject(arr, base) # <<<<<<<<<<<<<< - * - * cdef inline object get_array_base(ndarray arr): - */ - (void)(PyArray_SetBaseObject(__pyx_v_arr, __pyx_v_base)); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":931 - * int _import_umath() except -1 - * - * cdef inline void set_array_base(ndarray arr, object base): # <<<<<<<<<<<<<< - * Py_INCREF(base) # important to do this before stealing the reference below! - * PyArray_SetBaseObject(arr, base) - */ - - /* function exit code */ - __Pyx_RefNannyFinishContext(); -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":935 - * PyArray_SetBaseObject(arr, base) - * - * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< - * base = PyArray_BASE(arr) - * if base is NULL: - */ - -static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__pyx_v_arr) { - PyObject *__pyx_v_base; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("get_array_base", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":936 - * - * cdef inline object get_array_base(ndarray arr): - * base = PyArray_BASE(arr) # <<<<<<<<<<<<<< - * if base is NULL: - * return None - */ - __pyx_v_base = PyArray_BASE(__pyx_v_arr); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":937 - * cdef inline object get_array_base(ndarray arr): - * base = PyArray_BASE(arr) - * if base is NULL: # <<<<<<<<<<<<<< - * return None - * return base - */ - __pyx_t_1 = ((__pyx_v_base == NULL) != 0); - if (__pyx_t_1) { - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":938 - * base = PyArray_BASE(arr) - * if base is NULL: - * return None # <<<<<<<<<<<<<< - * return base - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":937 - * cdef inline object get_array_base(ndarray arr): - * base = PyArray_BASE(arr) - * if base is NULL: # <<<<<<<<<<<<<< - * return None - * return base - */ - } - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":939 - * if base is NULL: - * return None - * return base # <<<<<<<<<<<<<< - * - * # Versions of the import_* functions which are more suitable for - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_base)); - __pyx_r = ((PyObject *)__pyx_v_base); - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":935 - * PyArray_SetBaseObject(arr, base) - * - * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< - * base = PyArray_BASE(arr) - * if base is NULL: - */ - - /* function exit code */ - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":943 - * # Versions of the import_* functions which are more suitable for - * # Cython code. - * cdef inline int import_array() except -1: # <<<<<<<<<<<<<< - * try: - * __pyx_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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("import_array", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":944 - * # Cython code. - * cdef inline int import_array() except -1: - * try: # <<<<<<<<<<<<<< - * __pyx_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:*/ { - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":945 - * cdef inline int import_array() except -1: - * try: - * __pyx_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, 945, __pyx_L3_error) - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":944 - * # Cython code. - * cdef inline int import_array() except -1: - * try: # <<<<<<<<<<<<<< - * __pyx_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:; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":946 - * try: - * __pyx_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, 946, __pyx_L5_except_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GOTREF(__pyx_t_7); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":947 - * __pyx_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__24, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 947, __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, 947, __pyx_L5_except_error) - } - goto __pyx_L5_except_error; - __pyx_L5_except_error:; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":944 - * # Cython code. - * cdef inline int import_array() except -1: - * try: # <<<<<<<<<<<<<< - * __pyx_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:; - } - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":943 - * # Versions of the import_* functions which are more suitable for - * # Cython code. - * cdef inline int import_array() except -1: # <<<<<<<<<<<<<< - * try: - * __pyx_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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":949 - * 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("import_umath", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":950 - * - * 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:*/ { - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":951 - * 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, 951, __pyx_L3_error) - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":950 - * - * 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:; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":952 - * 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, 952, __pyx_L5_except_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GOTREF(__pyx_t_7); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":953 - * _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__25, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 953, __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, 953, __pyx_L5_except_error) - } - goto __pyx_L5_except_error; - __pyx_L5_except_error:; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":950 - * - * 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:; - } - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":949 - * 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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":955 - * 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("import_ufunc", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":956 - * - * 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:*/ { - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":957 - * 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, 957, __pyx_L3_error) - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":956 - * - * 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:; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":958 - * 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, 958, __pyx_L5_except_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GOTREF(__pyx_t_7); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":959 - * _import_umath() - * except Exception: - * raise ImportError("numpy.core.umath failed to import") # <<<<<<<<<<<<<< - * - * cdef extern from *: - */ - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 959, __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, 959, __pyx_L5_except_error) - } - goto __pyx_L5_except_error; - __pyx_L5_except_error:; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":956 - * - * 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:; - } - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":955 - * 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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":969 - * - * - * cdef inline bint is_timedelta64_object(object obj): # <<<<<<<<<<<<<< - * """ - * Cython equivalent of `isinstance(obj, np.timedelta64)` - */ - -static CYTHON_INLINE int __pyx_f_5numpy_is_timedelta64_object(PyObject *__pyx_v_obj) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("is_timedelta64_object", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":981 - * bool - * """ - * return PyObject_TypeCheck(obj, &PyTimedeltaArrType_Type) # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = PyObject_TypeCheck(__pyx_v_obj, (&PyTimedeltaArrType_Type)); - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":969 - * - * - * cdef inline bint is_timedelta64_object(object obj): # <<<<<<<<<<<<<< - * """ - * Cython equivalent of `isinstance(obj, np.timedelta64)` - */ - - /* function exit code */ - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":984 - * - * - * cdef inline bint is_datetime64_object(object obj): # <<<<<<<<<<<<<< - * """ - * Cython equivalent of `isinstance(obj, np.datetime64)` - */ - -static CYTHON_INLINE int __pyx_f_5numpy_is_datetime64_object(PyObject *__pyx_v_obj) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("is_datetime64_object", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":996 - * bool - * """ - * return PyObject_TypeCheck(obj, &PyDatetimeArrType_Type) # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = PyObject_TypeCheck(__pyx_v_obj, (&PyDatetimeArrType_Type)); - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":984 - * - * - * cdef inline bint is_datetime64_object(object obj): # <<<<<<<<<<<<<< - * """ - * Cython equivalent of `isinstance(obj, np.datetime64)` - */ - - /* function exit code */ - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":999 - * - * - * cdef inline npy_datetime get_datetime64_value(object obj) nogil: # <<<<<<<<<<<<<< - * """ - * returns the int64 value underlying scalar numpy datetime64 object - */ - -static CYTHON_INLINE npy_datetime __pyx_f_5numpy_get_datetime64_value(PyObject *__pyx_v_obj) { - npy_datetime __pyx_r; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1006 - * also needed. That can be found using `get_datetime64_unit`. - * """ - * return (obj).obval # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = ((PyDatetimeScalarObject *)__pyx_v_obj)->obval; - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":999 - * - * - * cdef inline npy_datetime get_datetime64_value(object obj) nogil: # <<<<<<<<<<<<<< - * """ - * returns the int64 value underlying scalar numpy datetime64 object - */ - - /* function exit code */ - __pyx_L0:; - return __pyx_r; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1009 - * - * - * cdef inline npy_timedelta get_timedelta64_value(object obj) nogil: # <<<<<<<<<<<<<< - * """ - * returns the int64 value underlying scalar numpy timedelta64 object - */ - -static CYTHON_INLINE npy_timedelta __pyx_f_5numpy_get_timedelta64_value(PyObject *__pyx_v_obj) { - npy_timedelta __pyx_r; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1013 - * returns the int64 value underlying scalar numpy timedelta64 object - * """ - * return (obj).obval # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = ((PyTimedeltaScalarObject *)__pyx_v_obj)->obval; - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1009 - * - * - * cdef inline npy_timedelta get_timedelta64_value(object obj) nogil: # <<<<<<<<<<<<<< - * """ - * returns the int64 value underlying scalar numpy timedelta64 object - */ - - /* function exit code */ - __pyx_L0:; - return __pyx_r; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1016 - * - * - * cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil: # <<<<<<<<<<<<<< - * """ - * returns the unit part of the dtype for a numpy datetime64 object. - */ - -static CYTHON_INLINE NPY_DATETIMEUNIT __pyx_f_5numpy_get_datetime64_unit(PyObject *__pyx_v_obj) { - NPY_DATETIMEUNIT __pyx_r; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1020 - * returns the unit part of the dtype for a numpy datetime64 object. - * """ - * return (obj).obmeta.base # <<<<<<<<<<<<<< - */ - __pyx_r = ((NPY_DATETIMEUNIT)((PyDatetimeScalarObject *)__pyx_v_obj)->obmeta.base); - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1016 - * - * - * cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil: # <<<<<<<<<<<<<< - * """ - * returns the unit part of the dtype for a numpy datetime64 object. - */ - - /* function exit code */ - __pyx_L0:; - 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 (); - 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); - __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1); - __pyx_pw_15pygeoprocessing_7routing_7routing_14_ManagedRaster_3__dealloc__(o); - __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1); - 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*/ - #if PY_VERSION_HEX < 0x030800b4 - 0, /*tp_print*/ - #endif - #if PY_VERSION_HEX >= 0x030800b4 - 0, /*tp_vectorcall_offset*/ - #endif - 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 - #if PY_VERSION_HEX >= 0x030800b1 - 0, /*tp_vectorcall*/ - #endif - #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000 - 0, /*tp_print*/ - #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 -#ifndef CYTHON_SMALL_CODE -#if defined(__clang__) - #define CYTHON_SMALL_CODE -#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) - #define CYTHON_SMALL_CODE __attribute__((cold)) -#else - #define CYTHON_SMALL_CODE -#endif -#endif - -static __Pyx_StringTabEntry __pyx_string_tab[] = { - {&__pyx_kp_u_, __pyx_k_, sizeof(__pyx_k_), 0, 1, 0, 0}, - {&__pyx_kp_u_100_0_complete, __pyx_k_100_0_complete, sizeof(__pyx_k_100_0_complete), 0, 1, 0, 0}, - {&__pyx_kp_u_1f, __pyx_k_1f, sizeof(__pyx_k_1f), 0, 1, 0, 0}, - {&__pyx_kp_u_1f_complete, __pyx_k_1f_complete, sizeof(__pyx_k_1f_complete), 0, 1, 0, 0}, - {&__pyx_n_s_AddGeometry, __pyx_k_AddGeometry, sizeof(__pyx_k_AddGeometry), 0, 0, 1, 1}, - {&__pyx_n_s_AddPoint, __pyx_k_AddPoint, sizeof(__pyx_k_AddPoint), 0, 0, 1, 1}, - {&__pyx_n_s_ApplyGeoTransform, __pyx_k_ApplyGeoTransform, sizeof(__pyx_k_ApplyGeoTransform), 0, 0, 1, 1}, - {&__pyx_kp_u_BIGTIFF_YES, __pyx_k_BIGTIFF_YES, sizeof(__pyx_k_BIGTIFF_YES), 0, 1, 0, 0}, - {&__pyx_kp_u_BLOCKXSIZE_d, __pyx_k_BLOCKXSIZE_d, sizeof(__pyx_k_BLOCKXSIZE_d), 0, 1, 0, 0}, - {&__pyx_kp_u_BLOCKYSIZE_d, __pyx_k_BLOCKYSIZE_d, sizeof(__pyx_k_BLOCKYSIZE_d), 0, 1, 0, 0}, - {&__pyx_kp_u_COMPRESS_LZW, __pyx_k_COMPRESS_LZW, sizeof(__pyx_k_COMPRESS_LZW), 0, 1, 0, 0}, - {&__pyx_n_s_CommitTransaction, __pyx_k_CommitTransaction, sizeof(__pyx_k_CommitTransaction), 0, 0, 1, 1}, - {&__pyx_n_s_Create, __pyx_k_Create, sizeof(__pyx_k_Create), 0, 0, 1, 1}, - {&__pyx_n_s_CreateCopy, __pyx_k_CreateCopy, sizeof(__pyx_k_CreateCopy), 0, 0, 1, 1}, - {&__pyx_n_s_CreateFeature, __pyx_k_CreateFeature, sizeof(__pyx_k_CreateFeature), 0, 0, 1, 1}, - {&__pyx_n_s_CreateField, __pyx_k_CreateField, sizeof(__pyx_k_CreateField), 0, 0, 1, 1}, - {&__pyx_n_s_CreateGeometryFromWkb, __pyx_k_CreateGeometryFromWkb, sizeof(__pyx_k_CreateGeometryFromWkb), 0, 0, 1, 1}, - {&__pyx_n_s_CreateLayer, __pyx_k_CreateLayer, sizeof(__pyx_k_CreateLayer), 0, 0, 1, 1}, - {&__pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT, __pyx_k_DEFAULT_GTIFF_CREATION_TUPLE_OPT, sizeof(__pyx_k_DEFAULT_GTIFF_CREATION_TUPLE_OPT), 0, 0, 1, 1}, - {&__pyx_n_s_DEFAULT_OSR_AXIS_MAPPING_STRATEG, __pyx_k_DEFAULT_OSR_AXIS_MAPPING_STRATEG, sizeof(__pyx_k_DEFAULT_OSR_AXIS_MAPPING_STRATEG), 0, 0, 1, 1}, - {&__pyx_n_s_DeleteFeature, __pyx_k_DeleteFeature, sizeof(__pyx_k_DeleteFeature), 0, 0, 1, 1}, - {&__pyx_n_s_DeleteField, __pyx_k_DeleteField, sizeof(__pyx_k_DeleteField), 0, 0, 1, 1}, - {&__pyx_kp_u_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, 1, 0, 0}, - {&__pyx_kp_u_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, 1, 0, 0}, - {&__pyx_n_s_ExportToWkb, __pyx_k_ExportToWkb, sizeof(__pyx_k_ExportToWkb), 0, 0, 1, 1}, - {&__pyx_n_s_Feature, __pyx_k_Feature, sizeof(__pyx_k_Feature), 0, 0, 1, 1}, - {&__pyx_n_s_FieldDefn, __pyx_k_FieldDefn, sizeof(__pyx_k_FieldDefn), 0, 0, 1, 1}, - {&__pyx_n_s_FindFieldIndex, __pyx_k_FindFieldIndex, sizeof(__pyx_k_FindFieldIndex), 0, 0, 1, 1}, - {&__pyx_n_s_FlushCache, __pyx_k_FlushCache, sizeof(__pyx_k_FlushCache), 0, 0, 1, 1}, - {&__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_GDT_Unknown, __pyx_k_GDT_Unknown, sizeof(__pyx_k_GDT_Unknown), 0, 0, 1, 1}, - {&__pyx_n_u_GPKG, __pyx_k_GPKG, sizeof(__pyx_k_GPKG), 0, 1, 0, 1}, - {&__pyx_n_u_GTiff, __pyx_k_GTiff, sizeof(__pyx_k_GTiff), 0, 1, 0, 1}, - {&__pyx_n_s_Geometry, __pyx_k_Geometry, sizeof(__pyx_k_Geometry), 0, 0, 1, 1}, - {&__pyx_n_s_GetDriverByName, __pyx_k_GetDriverByName, sizeof(__pyx_k_GetDriverByName), 0, 0, 1, 1}, - {&__pyx_n_s_GetFID, __pyx_k_GetFID, sizeof(__pyx_k_GetFID), 0, 0, 1, 1}, - {&__pyx_n_s_GetFeature, __pyx_k_GetFeature, sizeof(__pyx_k_GetFeature), 0, 0, 1, 1}, - {&__pyx_n_s_GetField, __pyx_k_GetField, sizeof(__pyx_k_GetField), 0, 0, 1, 1}, - {&__pyx_n_s_GetGeometryRef, __pyx_k_GetGeometryRef, sizeof(__pyx_k_GetGeometryRef), 0, 0, 1, 1}, - {&__pyx_n_s_GetLayer, __pyx_k_GetLayer, sizeof(__pyx_k_GetLayer), 0, 0, 1, 1}, - {&__pyx_n_s_GetLayerDefn, __pyx_k_GetLayerDefn, sizeof(__pyx_k_GetLayerDefn), 0, 0, 1, 1}, - {&__pyx_n_s_GetRasterBand, __pyx_k_GetRasterBand, sizeof(__pyx_k_GetRasterBand), 0, 0, 1, 1}, - {&__pyx_n_u_ID, __pyx_k_ID, sizeof(__pyx_k_ID), 0, 1, 0, 1}, - {&__pyx_n_s_ImportError, __pyx_k_ImportError, sizeof(__pyx_k_ImportError), 0, 0, 1, 1}, - {&__pyx_n_s_ImportFromWkt, __pyx_k_ImportFromWkt, sizeof(__pyx_k_ImportFromWkt), 0, 0, 1, 1}, - {&__pyx_n_s_LOGGER, __pyx_k_LOGGER, sizeof(__pyx_k_LOGGER), 0, 0, 1, 1}, - {&__pyx_n_s_ManagedRaster, __pyx_k_ManagedRaster, sizeof(__pyx_k_ManagedRaster), 0, 0, 1, 1}, - {&__pyx_n_s_OFTInteger, __pyx_k_OFTInteger, sizeof(__pyx_k_OFTInteger), 0, 0, 1, 1}, - {&__pyx_n_s_OFTInteger64, __pyx_k_OFTInteger64, sizeof(__pyx_k_OFTInteger64), 0, 0, 1, 1}, - {&__pyx_n_s_OFTReal, __pyx_k_OFTReal, sizeof(__pyx_k_OFTReal), 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_OF_VECTOR, __pyx_k_OF_VECTOR, sizeof(__pyx_k_OF_VECTOR), 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_ResetReading, __pyx_k_ResetReading, sizeof(__pyx_k_ResetReading), 0, 0, 1, 1}, - {&__pyx_n_s_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 0, 0, 1, 1}, - {&__pyx_kp_u_SPARSE_OK_TRUE, __pyx_k_SPARSE_OK_TRUE, sizeof(__pyx_k_SPARSE_OK_TRUE), 0, 1, 0, 0}, - {&__pyx_n_s_SetAttributeFilter, __pyx_k_SetAttributeFilter, sizeof(__pyx_k_SetAttributeFilter), 0, 0, 1, 1}, - {&__pyx_n_s_SetAxisMappingStrategy, __pyx_k_SetAxisMappingStrategy, sizeof(__pyx_k_SetAxisMappingStrategy), 0, 0, 1, 1}, - {&__pyx_n_s_SetFeature, __pyx_k_SetFeature, sizeof(__pyx_k_SetFeature), 0, 0, 1, 1}, - {&__pyx_n_s_SetField, __pyx_k_SetField, sizeof(__pyx_k_SetField), 0, 0, 1, 1}, - {&__pyx_n_s_SetGeometry, __pyx_k_SetGeometry, sizeof(__pyx_k_SetGeometry), 0, 0, 1, 1}, - {&__pyx_n_s_SpatialReference, __pyx_k_SpatialReference, sizeof(__pyx_k_SpatialReference), 0, 0, 1, 1}, - {&__pyx_n_s_StartTransaction, __pyx_k_StartTransaction, sizeof(__pyx_k_StartTransaction), 0, 0, 1, 1}, - {&__pyx_kp_u_TILED_YES, __pyx_k_TILED_YES, sizeof(__pyx_k_TILED_YES), 0, 1, 0, 0}, - {&__pyx_kp_u_This_exception_is_happeningin_C, __pyx_k_This_exception_is_happeningin_C, sizeof(__pyx_k_This_exception_is_happeningin_C), 0, 1, 0, 0}, - {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1}, - {&__pyx_n_s_Union, __pyx_k_Union, sizeof(__pyx_k_Union), 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_u_Y_m_d__H__M__S, __pyx_k_Y_m_d__H__M__S, sizeof(__pyx_k_Y_m_d__H__M__S), 0, 1, 0, 0}, - {&__pyx_n_s__34, __pyx_k__34, sizeof(__pyx_k__34), 0, 0, 1, 1}, - {&__pyx_n_s_all_defined, __pyx_k_all_defined, sizeof(__pyx_k_all_defined), 0, 0, 1, 1}, - {&__pyx_n_s_append, __pyx_k_append, sizeof(__pyx_k_append), 0, 0, 1, 1}, - {&__pyx_n_s_astype, __pyx_k_astype, sizeof(__pyx_k_astype), 0, 0, 1, 1}, - {&__pyx_n_s_autotune_flow_accumulation, __pyx_k_autotune_flow_accumulation, sizeof(__pyx_k_autotune_flow_accumulation), 0, 0, 1, 1}, - {&__pyx_n_s_backtrace_set, __pyx_k_backtrace_set, sizeof(__pyx_k_backtrace_set), 0, 0, 1, 1}, - {&__pyx_kp_u_bak_tif, __pyx_k_bak_tif, sizeof(__pyx_k_bak_tif), 0, 1, 0, 0}, - {&__pyx_n_s_band_id, __pyx_k_band_id, sizeof(__pyx_k_band_id), 0, 0, 1, 1}, - {&__pyx_n_s_base_datatype, __pyx_k_base_datatype, sizeof(__pyx_k_base_datatype), 0, 0, 1, 1}, - {&__pyx_n_s_base_feature_count, __pyx_k_base_feature_count, sizeof(__pyx_k_base_feature_count), 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_basename, __pyx_k_basename, sizeof(__pyx_k_basename), 0, 0, 1, 1}, - {&__pyx_n_s_block_array, __pyx_k_block_array, sizeof(__pyx_k_block_array), 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_offsets_list, __pyx_k_block_offsets_list, sizeof(__pyx_k_block_offsets_list), 0, 0, 1, 1}, - {&__pyx_n_u_block_size, __pyx_k_block_size, sizeof(__pyx_k_block_size), 0, 1, 0, 1}, - {&__pyx_n_s_boundary_list, __pyx_k_boundary_list, sizeof(__pyx_k_boundary_list), 0, 0, 1, 1}, - {&__pyx_n_s_boundary_x, __pyx_k_boundary_x, sizeof(__pyx_k_boundary_x), 0, 0, 1, 1}, - {&__pyx_n_s_boundary_y, __pyx_k_boundary_y, sizeof(__pyx_k_boundary_y), 0, 0, 1, 1}, - {&__pyx_n_s_build_discovery_finish_rasters, __pyx_k_build_discovery_finish_rasters, sizeof(__pyx_k_build_discovery_finish_rasters), 0, 0, 1, 1}, - {&__pyx_n_u_calculate_subwatershed_boundary, __pyx_k_calculate_subwatershed_boundary, sizeof(__pyx_k_calculate_subwatershed_boundary), 0, 1, 0, 1}, - {&__pyx_kp_u_calculate_subwatershed_boundary_2, __pyx_k_calculate_subwatershed_boundary_2, sizeof(__pyx_k_calculate_subwatershed_boundary_2), 0, 1, 0, 0}, - {&__pyx_kp_u_calculate_subwatershed_boundary_3, __pyx_k_calculate_subwatershed_boundary_3, sizeof(__pyx_k_calculate_subwatershed_boundary_3), 0, 1, 0, 0}, - {&__pyx_n_s_calculate_subwatershed_boundary_4, __pyx_k_calculate_subwatershed_boundary_4, sizeof(__pyx_k_calculate_subwatershed_boundary_4), 0, 0, 1, 1}, - {&__pyx_n_s_cell_to_test, __pyx_k_cell_to_test, sizeof(__pyx_k_cell_to_test), 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_collections, __pyx_k_collections, sizeof(__pyx_k_collections), 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_u_compatable_dem_tif, __pyx_k_compatable_dem_tif, sizeof(__pyx_k_compatable_dem_tif), 0, 1, 0, 0}, - {&__pyx_kp_u_compatible_dem_complete, __pyx_k_compatible_dem_complete, sizeof(__pyx_k_compatible_dem_complete), 0, 1, 0, 0}, - {&__pyx_kp_u_complete, __pyx_k_complete, sizeof(__pyx_k_complete), 0, 1, 0, 0}, - {&__pyx_kp_u_complete_2, __pyx_k_complete_2, sizeof(__pyx_k_complete_2), 0, 1, 0, 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_connected_fid, __pyx_k_connected_fid, sizeof(__pyx_k_connected_fid), 0, 0, 1, 1}, - {&__pyx_n_s_connected_fids, __pyx_k_connected_fids, sizeof(__pyx_k_connected_fids), 0, 0, 1, 1}, - {&__pyx_n_s_connected_upstream_fids, __pyx_k_connected_upstream_fids, sizeof(__pyx_k_connected_upstream_fids), 0, 0, 1, 1}, - {&__pyx_n_s_coord_to_stream_ids, __pyx_k_coord_to_stream_ids, sizeof(__pyx_k_coord_to_stream_ids), 0, 0, 1, 1}, - {&__pyx_n_s_copy, __pyx_k_copy, sizeof(__pyx_k_copy), 0, 0, 1, 1}, - {&__pyx_n_s_copyfile, __pyx_k_copyfile, sizeof(__pyx_k_copyfile), 0, 0, 1, 1}, - {&__pyx_kp_u_could_not_open, __pyx_k_could_not_open, sizeof(__pyx_k_could_not_open), 0, 1, 0, 0}, - {&__pyx_kp_u_couldn_t_remove_temp_dir, __pyx_k_couldn_t_remove_temp_dir, sizeof(__pyx_k_couldn_t_remove_temp_dir), 0, 1, 0, 0}, - {&__pyx_kp_u_creating_target_flow_accum_raste, __pyx_k_creating_target_flow_accum_raste, sizeof(__pyx_k_creating_target_flow_accum_raste), 0, 1, 0, 0}, - {&__pyx_kp_u_creating_visited_raster_layer, __pyx_k_creating_visited_raster_layer, sizeof(__pyx_k_creating_visited_raster_layer), 0, 1, 0, 0}, - {&__pyx_n_s_current_pixel, __pyx_k_current_pixel, sizeof(__pyx_k_current_pixel), 0, 0, 1, 1}, - {&__pyx_n_s_d, __pyx_k_d, sizeof(__pyx_k_d), 0, 0, 1, 1}, - {&__pyx_n_u_d, __pyx_k_d, sizeof(__pyx_k_d), 0, 1, 0, 1}, - {&__pyx_n_u_d8, __pyx_k_d8, sizeof(__pyx_k_d8), 0, 1, 0, 1}, - {&__pyx_n_s_d8_flow_dir_managed_raster, __pyx_k_d8_flow_dir_managed_raster, sizeof(__pyx_k_d8_flow_dir_managed_raster), 0, 0, 1, 1}, - {&__pyx_n_s_d8_flow_dir_mode, __pyx_k_d8_flow_dir_mode, sizeof(__pyx_k_d8_flow_dir_mode), 0, 0, 1, 1}, - {&__pyx_n_s_d8_flow_dir_raster_path_band, __pyx_k_d8_flow_dir_raster_path_band, sizeof(__pyx_k_d8_flow_dir_raster_path_band), 0, 0, 1, 1}, - {&__pyx_n_s_d_n, __pyx_k_d_n, sizeof(__pyx_k_d_n), 0, 0, 1, 1}, - {&__pyx_n_u_datatype, __pyx_k_datatype, sizeof(__pyx_k_datatype), 0, 1, 0, 1}, - {&__pyx_n_s_debug, __pyx_k_debug, sizeof(__pyx_k_debug), 0, 0, 1, 1}, - {&__pyx_n_s_defaultdict, __pyx_k_defaultdict, sizeof(__pyx_k_defaultdict), 0, 0, 1, 1}, - {&__pyx_n_s_delete_feature, __pyx_k_delete_feature, sizeof(__pyx_k_delete_feature), 0, 0, 1, 1}, - {&__pyx_n_s_deleted_set, __pyx_k_deleted_set, sizeof(__pyx_k_deleted_set), 0, 0, 1, 1}, - {&__pyx_n_s_delta_x, __pyx_k_delta_x, sizeof(__pyx_k_delta_x), 0, 0, 1, 1}, - {&__pyx_n_s_delta_y, __pyx_k_delta_y, sizeof(__pyx_k_delta_y), 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_u_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, 1, 0, 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_detect_outlets, __pyx_k_detect_outlets, sizeof(__pyx_k_detect_outlets), 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_dirname, __pyx_k_dirname, sizeof(__pyx_k_dirname), 0, 0, 1, 1}, - {&__pyx_n_s_discovery, __pyx_k_discovery, sizeof(__pyx_k_discovery), 0, 0, 1, 1}, - {&__pyx_n_s_discovery_count, __pyx_k_discovery_count, sizeof(__pyx_k_discovery_count), 0, 0, 1, 1}, - {&__pyx_n_s_discovery_info, __pyx_k_discovery_info, sizeof(__pyx_k_discovery_info), 0, 0, 1, 1}, - {&__pyx_n_s_discovery_managed_raster, __pyx_k_discovery_managed_raster, sizeof(__pyx_k_discovery_managed_raster), 0, 0, 1, 1}, - {&__pyx_n_s_discovery_nodata, __pyx_k_discovery_nodata, sizeof(__pyx_k_discovery_nodata), 0, 0, 1, 1}, - {&__pyx_n_s_discovery_srs, __pyx_k_discovery_srs, sizeof(__pyx_k_discovery_srs), 0, 0, 1, 1}, - {&__pyx_n_s_discovery_stack, __pyx_k_discovery_stack, sizeof(__pyx_k_discovery_stack), 0, 0, 1, 1}, - {&__pyx_kp_u_discovery_tif, __pyx_k_discovery_tif, sizeof(__pyx_k_discovery_tif), 0, 1, 0, 0}, - {&__pyx_kp_u_discovery_time_processing, __pyx_k_discovery_time_processing, sizeof(__pyx_k_discovery_time_processing), 0, 1, 0, 0}, - {&__pyx_n_s_discovery_time_raster_path, __pyx_k_discovery_time_raster_path, sizeof(__pyx_k_discovery_time_raster_path), 0, 0, 1, 1}, - {&__pyx_n_u_dist_to_channel_mfd_work_dir, __pyx_k_dist_to_channel_mfd_work_dir, sizeof(__pyx_k_dist_to_channel_mfd_work_dir), 0, 1, 0, 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_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_downstream_dem, __pyx_k_downstream_dem, sizeof(__pyx_k_downstream_dem), 0, 0, 1, 1}, - {&__pyx_n_s_downstream_feature, __pyx_k_downstream_feature, sizeof(__pyx_k_downstream_feature), 0, 0, 1, 1}, - {&__pyx_n_s_downstream_fid, __pyx_k_downstream_fid, sizeof(__pyx_k_downstream_fid), 0, 0, 1, 1}, - {&__pyx_n_s_downstream_geom, __pyx_k_downstream_geom, sizeof(__pyx_k_downstream_geom), 0, 0, 1, 1}, - {&__pyx_n_s_downstream_order, __pyx_k_downstream_order, sizeof(__pyx_k_downstream_order), 0, 0, 1, 1}, - {&__pyx_n_s_downstream_to_upstream_ids, __pyx_k_downstream_to_upstream_ids, sizeof(__pyx_k_downstream_to_upstream_ids), 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_drop_distance, __pyx_k_drop_distance, sizeof(__pyx_k_drop_distance), 0, 0, 1, 1}, - {&__pyx_n_u_drop_distance, __pyx_k_drop_distance, sizeof(__pyx_k_drop_distance), 0, 1, 0, 1}, - {&__pyx_n_s_drop_distance_collection, __pyx_k_drop_distance_collection, sizeof(__pyx_k_drop_distance_collection), 0, 0, 1, 1}, - {&__pyx_n_u_ds_fa, __pyx_k_ds_fa, sizeof(__pyx_k_ds_fa), 0, 1, 0, 1}, - {&__pyx_n_s_ds_x, __pyx_k_ds_x, sizeof(__pyx_k_ds_x), 0, 0, 1, 1}, - {&__pyx_n_u_ds_x, __pyx_k_ds_x, sizeof(__pyx_k_ds_x), 0, 1, 0, 1}, - {&__pyx_n_s_ds_x_1, __pyx_k_ds_x_1, sizeof(__pyx_k_ds_x_1), 0, 0, 1, 1}, - {&__pyx_n_u_ds_x_1, __pyx_k_ds_x_1, sizeof(__pyx_k_ds_x_1), 0, 1, 0, 1}, - {&__pyx_n_s_ds_y, __pyx_k_ds_y, sizeof(__pyx_k_ds_y), 0, 0, 1, 1}, - {&__pyx_n_u_ds_y, __pyx_k_ds_y, sizeof(__pyx_k_ds_y), 0, 1, 0, 1}, - {&__pyx_n_s_ds_y_1, __pyx_k_ds_y_1, sizeof(__pyx_k_ds_y_1), 0, 0, 1, 1}, - {&__pyx_n_u_ds_y_1, __pyx_k_ds_y_1, sizeof(__pyx_k_ds_y_1), 0, 1, 0, 1}, - {&__pyx_n_s_dtype, __pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 0, 1, 1}, - {&__pyx_n_s_edge_dir, __pyx_k_edge_dir, sizeof(__pyx_k_edge_dir), 0, 0, 1, 1}, - {&__pyx_n_s_edge_side, __pyx_k_edge_side, sizeof(__pyx_k_edge_side), 0, 0, 1, 1}, - {&__pyx_n_s_empty, __pyx_k_empty, sizeof(__pyx_k_empty), 0, 0, 1, 1}, - {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1}, - {&__pyx_n_s_equal_var, __pyx_k_equal_var, sizeof(__pyx_k_equal_var), 0, 0, 1, 1}, - {&__pyx_n_s_error, __pyx_k_error, sizeof(__pyx_k_error), 0, 0, 1, 1}, - {&__pyx_n_s_exception, __pyx_k_exception, sizeof(__pyx_k_exception), 0, 0, 1, 1}, - {&__pyx_n_s_exists, __pyx_k_exists, sizeof(__pyx_k_exists), 0, 0, 1, 1}, - {&__pyx_kp_u_exists_removing_before_creating, __pyx_k_exists_removing_before_creating, sizeof(__pyx_k_exists_removing_before_creating), 0, 1, 0, 0}, - {&__pyx_kp_u_expected_flow_dir_type_of_either, __pyx_k_expected_flow_dir_type_of_either, sizeof(__pyx_k_expected_flow_dir_type_of_either), 0, 1, 0, 0}, - {&__pyx_n_s_extract_strahler_streams_d8, __pyx_k_extract_strahler_streams_d8, sizeof(__pyx_k_extract_strahler_streams_d8), 0, 0, 1, 1}, - {&__pyx_kp_u_extract_strahler_streams_d8_all, __pyx_k_extract_strahler_streams_d8_all, sizeof(__pyx_k_extract_strahler_streams_d8_all), 0, 1, 0, 0}, - {&__pyx_kp_u_extract_strahler_streams_d8_com, __pyx_k_extract_strahler_streams_d8_com, sizeof(__pyx_k_extract_strahler_streams_d8_com), 0, 1, 0, 0}, - {&__pyx_kp_u_extract_strahler_streams_d8_det, __pyx_k_extract_strahler_streams_d8_det, sizeof(__pyx_k_extract_strahler_streams_d8_det), 0, 1, 0, 0}, - {&__pyx_kp_u_extract_strahler_streams_d8_det_2, __pyx_k_extract_strahler_streams_d8_det_2, sizeof(__pyx_k_extract_strahler_streams_d8_det_2), 0, 1, 0, 0}, - {&__pyx_kp_u_extract_strahler_streams_d8_dra, __pyx_k_extract_strahler_streams_d8_dra, sizeof(__pyx_k_extract_strahler_streams_d8_dra), 0, 1, 0, 0}, - {&__pyx_kp_u_extract_strahler_streams_d8_dra_2, __pyx_k_extract_strahler_streams_d8_dra_2, sizeof(__pyx_k_extract_strahler_streams_d8_dra_2), 0, 1, 0, 0}, - {&__pyx_kp_u_extract_strahler_streams_d8_fin, __pyx_k_extract_strahler_streams_d8_fin, sizeof(__pyx_k_extract_strahler_streams_d8_fin), 0, 1, 0, 0}, - {&__pyx_kp_u_extract_strahler_streams_d8_fin_2, __pyx_k_extract_strahler_streams_d8_fin_2, sizeof(__pyx_k_extract_strahler_streams_d8_fin_2), 0, 1, 0, 0}, - {&__pyx_kp_u_extract_strahler_streams_d8_fin_3, __pyx_k_extract_strahler_streams_d8_fin_3, sizeof(__pyx_k_extract_strahler_streams_d8_fin_3), 0, 1, 0, 0}, - {&__pyx_kp_u_extract_strahler_streams_d8_flo, __pyx_k_extract_strahler_streams_d8_flo, sizeof(__pyx_k_extract_strahler_streams_d8_flo), 0, 1, 0, 0}, - {&__pyx_kp_u_extract_strahler_streams_d8_flo_2, __pyx_k_extract_strahler_streams_d8_flo_2, sizeof(__pyx_k_extract_strahler_streams_d8_flo_2), 0, 1, 0, 0}, - {&__pyx_kp_u_extract_strahler_streams_d8_see, __pyx_k_extract_strahler_streams_d8_see, sizeof(__pyx_k_extract_strahler_streams_d8_see), 0, 1, 0, 0}, - {&__pyx_kp_u_extract_strahler_streams_d8_sta, __pyx_k_extract_strahler_streams_d8_sta, sizeof(__pyx_k_extract_strahler_streams_d8_sta), 0, 1, 0, 0}, - {&__pyx_kp_u_extract_strahler_streams_d8_str, __pyx_k_extract_strahler_streams_d8_str, sizeof(__pyx_k_extract_strahler_streams_d8_str), 0, 1, 0, 0}, - {&__pyx_kp_u_extract_strahler_streams_d8_str_2, __pyx_k_extract_strahler_streams_d8_str_2, sizeof(__pyx_k_extract_strahler_streams_d8_str_2), 0, 1, 0, 0}, - {&__pyx_kp_u_extract_strahler_streams_d8_str_3, __pyx_k_extract_strahler_streams_d8_str_3, sizeof(__pyx_k_extract_strahler_streams_d8_str_3), 0, 1, 0, 0}, - {&__pyx_kp_u_extract_strahler_streams_d8_str_4, __pyx_k_extract_strahler_streams_d8_str_4, sizeof(__pyx_k_extract_strahler_streams_d8_str_4), 0, 1, 0, 0}, - {&__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_fid, __pyx_k_fid, sizeof(__pyx_k_fid), 0, 0, 1, 1}, - {&__pyx_n_s_fid_to_order, __pyx_k_fid_to_order, sizeof(__pyx_k_fid_to_order), 0, 0, 1, 1}, - {&__pyx_n_s_fill_height, __pyx_k_fill_height, sizeof(__pyx_k_fill_height), 0, 0, 1, 1}, - {&__pyx_kp_u_fill_pits, __pyx_k_fill_pits, sizeof(__pyx_k_fill_pits), 0, 1, 0, 0}, - {&__pyx_n_s_fill_pits_2, __pyx_k_fill_pits_2, sizeof(__pyx_k_fill_pits_2), 0, 0, 1, 1}, - {&__pyx_kp_u_fill_pits__s, __pyx_k_fill_pits__s, sizeof(__pyx_k_fill_pits__s), 0, 1, 0, 0}, - {&__pyx_kp_u_fill_pits_complete, __pyx_k_fill_pits_complete, sizeof(__pyx_k_fill_pits_complete), 0, 1, 0, 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_band, __pyx_k_filled_dem_band, sizeof(__pyx_k_filled_dem_band), 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_n_s_filled_dem_raster, __pyx_k_filled_dem_raster, sizeof(__pyx_k_filled_dem_raster), 0, 0, 1, 1}, - {&__pyx_kp_u_filter_out_incomplete_divergent, __pyx_k_filter_out_incomplete_divergent, sizeof(__pyx_k_filter_out_incomplete_divergent), 0, 1, 0, 0}, - {&__pyx_n_s_finish, __pyx_k_finish, sizeof(__pyx_k_finish), 0, 0, 1, 1}, - {&__pyx_n_s_finish_coordinate, __pyx_k_finish_coordinate, sizeof(__pyx_k_finish_coordinate), 0, 0, 1, 1}, - {&__pyx_n_s_finish_managed_raster, __pyx_k_finish_managed_raster, sizeof(__pyx_k_finish_managed_raster), 0, 0, 1, 1}, - {&__pyx_n_s_finish_stack, __pyx_k_finish_stack, sizeof(__pyx_k_finish_stack), 0, 0, 1, 1}, - {&__pyx_kp_u_finish_tif, __pyx_k_finish_tif, sizeof(__pyx_k_finish_tif), 0, 1, 0, 0}, - {&__pyx_n_s_finish_time_raster_path, __pyx_k_finish_time_raster_path, sizeof(__pyx_k_finish_time_raster_path), 0, 0, 1, 1}, - {&__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_u_flat_region_mask_tif, __pyx_k_flat_region_mask_tif, sizeof(__pyx_k_flat_region_mask_tif), 0, 1, 0, 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_block, __pyx_k_flow_dir_block, sizeof(__pyx_k_flow_dir_block), 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_kp_u_flow_dir_d8, __pyx_k_flow_dir_d8, sizeof(__pyx_k_flow_dir_d8), 0, 1, 0, 0}, - {&__pyx_n_s_flow_dir_d8_2, __pyx_k_flow_dir_d8_2, sizeof(__pyx_k_flow_dir_d8_2), 0, 0, 1, 1}, - {&__pyx_kp_u_flow_dir_d8__s, __pyx_k_flow_dir_d8__s, sizeof(__pyx_k_flow_dir_d8__s), 0, 1, 0, 0}, - {&__pyx_kp_u_flow_dir_d8_complete, __pyx_k_flow_dir_d8_complete, sizeof(__pyx_k_flow_dir_d8_complete), 0, 1, 0, 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_info, __pyx_k_flow_dir_info, sizeof(__pyx_k_flow_dir_info), 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_u_flow_dir_multiple_flow_dir__s, __pyx_k_flow_dir_multiple_flow_dir__s, sizeof(__pyx_k_flow_dir_multiple_flow_dir__s), 0, 1, 0, 0}, - {&__pyx_n_s_flow_dir_n, __pyx_k_flow_dir_n, sizeof(__pyx_k_flow_dir_n), 0, 0, 1, 1}, - {&__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_srs, __pyx_k_flow_dir_srs, sizeof(__pyx_k_flow_dir_srs), 0, 0, 1, 1}, - {&__pyx_n_s_flow_dir_type, __pyx_k_flow_dir_type, sizeof(__pyx_k_flow_dir_type), 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_nodata, __pyx_k_flow_nodata, sizeof(__pyx_k_flow_nodata), 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_kp_u_for_writing, __pyx_k_for_writing, sizeof(__pyx_k_for_writing), 0, 1, 0, 0}, - {&__pyx_n_s_g0, __pyx_k_g0, sizeof(__pyx_k_g0), 0, 0, 1, 1}, - {&__pyx_n_s_g1, __pyx_k_g1, sizeof(__pyx_k_g1), 0, 0, 1, 1}, - {&__pyx_n_s_g2, __pyx_k_g2, sizeof(__pyx_k_g2), 0, 0, 1, 1}, - {&__pyx_n_s_g3, __pyx_k_g3, sizeof(__pyx_k_g3), 0, 0, 1, 1}, - {&__pyx_n_s_g4, __pyx_k_g4, sizeof(__pyx_k_g4), 0, 0, 1, 1}, - {&__pyx_n_s_g5, __pyx_k_g5, sizeof(__pyx_k_g5), 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_geoprocessing_core, __pyx_k_geoprocessing_core, sizeof(__pyx_k_geoprocessing_core), 0, 0, 1, 1}, - {&__pyx_n_s_geotransform, __pyx_k_geotransform, sizeof(__pyx_k_geotransform), 0, 0, 1, 1}, - {&__pyx_n_u_geotransform, __pyx_k_geotransform, sizeof(__pyx_k_geotransform), 0, 1, 0, 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_gpkg_driver, __pyx_k_gpkg_driver, sizeof(__pyx_k_gpkg_driver), 0, 0, 1, 1}, - {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1}, - {&__pyx_n_u_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 1, 0, 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_kp_u_in_ManagedRaster_flush, __pyx_k_in_ManagedRaster_flush, sizeof(__pyx_k_in_ManagedRaster_flush), 0, 1, 0, 0}, - {&__pyx_n_s_index, __pyx_k_index, sizeof(__pyx_k_index), 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_int_max_steps_per_watershed, __pyx_k_int_max_steps_per_watershed, sizeof(__pyx_k_int_max_steps_per_watershed), 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_drain, __pyx_k_is_drain, sizeof(__pyx_k_is_drain), 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_isnan, __pyx_k_isnan, sizeof(__pyx_k_isnan), 0, 0, 1, 1}, - {&__pyx_n_s_iterblocks, __pyx_k_iterblocks, sizeof(__pyx_k_iterblocks), 0, 0, 1, 1}, - {&__pyx_n_s_j, __pyx_k_j, sizeof(__pyx_k_j), 0, 0, 1, 1}, - {&__pyx_n_u_j, __pyx_k_j, sizeof(__pyx_k_j), 0, 1, 0, 1}, - {&__pyx_n_s_join, __pyx_k_join, sizeof(__pyx_k_join), 0, 0, 1, 1}, - {&__pyx_n_s_joined_line, __pyx_k_joined_line, sizeof(__pyx_k_joined_line), 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_left, __pyx_k_left, sizeof(__pyx_k_left), 0, 0, 1, 1}, - {&__pyx_n_s_left_in, __pyx_k_left_in, sizeof(__pyx_k_left_in), 0, 0, 1, 1}, - {&__pyx_n_s_linemerge, __pyx_k_linemerge, sizeof(__pyx_k_linemerge), 0, 0, 1, 1}, - {&__pyx_n_s_loads, __pyx_k_loads, sizeof(__pyx_k_loads), 0, 0, 1, 1}, - {&__pyx_n_s_local_flow_accum, __pyx_k_local_flow_accum, sizeof(__pyx_k_local_flow_accum), 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_lower, __pyx_k_lower, sizeof(__pyx_k_lower), 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_max, __pyx_k_max, sizeof(__pyx_k_max), 0, 0, 1, 1}, - {&__pyx_n_s_max_pixel_fill_count, __pyx_k_max_pixel_fill_count, sizeof(__pyx_k_max_pixel_fill_count), 0, 0, 1, 1}, - {&__pyx_n_s_max_steps_per_watershed, __pyx_k_max_steps_per_watershed, sizeof(__pyx_k_max_steps_per_watershed), 0, 0, 1, 1}, - {&__pyx_n_s_max_upstream_flow_accum, __pyx_k_max_upstream_flow_accum, sizeof(__pyx_k_max_upstream_flow_accum), 0, 0, 1, 1}, - {&__pyx_n_u_mfd, __pyx_k_mfd, sizeof(__pyx_k_mfd), 0, 1, 0, 1}, - {&__pyx_kp_u_mfd_flow_accum_1f_complete, __pyx_k_mfd_flow_accum_1f_complete, sizeof(__pyx_k_mfd_flow_accum_1f_complete), 0, 1, 0, 0}, - {&__pyx_n_u_mfd_flow_dir, __pyx_k_mfd_flow_dir, sizeof(__pyx_k_mfd_flow_dir), 0, 1, 0, 1}, - {&__pyx_n_s_min, __pyx_k_min, sizeof(__pyx_k_min), 0, 0, 1, 1}, - {&__pyx_n_s_min_flow_accum_threshold, __pyx_k_min_flow_accum_threshold, sizeof(__pyx_k_min_flow_accum_threshold), 0, 0, 1, 1}, - {&__pyx_n_s_min_p_val, __pyx_k_min_p_val, sizeof(__pyx_k_min_p_val), 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_kp_u_more_times, __pyx_k_more_times, sizeof(__pyx_k_more_times), 0, 1, 0, 0}, - {&__pyx_n_s_multi_line, __pyx_k_multi_line, sizeof(__pyx_k_multi_line), 0, 0, 1, 1}, - {&__pyx_n_u_n_bands, __pyx_k_n_bands, sizeof(__pyx_k_n_bands), 0, 1, 0, 1}, - {&__pyx_n_s_n_cols, __pyx_k_n_cols, sizeof(__pyx_k_n_cols), 0, 0, 1, 1}, - {&__pyx_n_s_n_dir, __pyx_k_n_dir, sizeof(__pyx_k_n_dir), 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_pixels, __pyx_k_n_pixels, sizeof(__pyx_k_n_pixels), 0, 0, 1, 1}, - {&__pyx_n_s_n_points, __pyx_k_n_points, sizeof(__pyx_k_n_points), 0, 0, 1, 1}, - {&__pyx_n_s_n_processed, __pyx_k_n_processed, sizeof(__pyx_k_n_processed), 0, 0, 1, 1}, - {&__pyx_n_s_n_pushed, __pyx_k_n_pushed, sizeof(__pyx_k_n_pushed), 0, 0, 1, 1}, - {&__pyx_n_s_n_rows, __pyx_k_n_rows, sizeof(__pyx_k_n_rows), 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_steps, __pyx_k_n_steps, sizeof(__pyx_k_n_steps), 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_n_s_natural_drain_exists, __pyx_k_natural_drain_exists, sizeof(__pyx_k_natural_drain_exists), 0, 0, 1, 1}, - {&__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_n_s_next_id, __pyx_k_next_id, sizeof(__pyx_k_next_id), 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_u_nodata, __pyx_k_nodata, sizeof(__pyx_k_nodata), 0, 1, 0, 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_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_u_numpy_core_multiarray_failed_to, __pyx_k_numpy_core_multiarray_failed_to, sizeof(__pyx_k_numpy_core_multiarray_failed_to), 0, 1, 0, 0}, - {&__pyx_kp_u_numpy_core_umath_failed_to_impor, __pyx_k_numpy_core_umath_failed_to_impor, sizeof(__pyx_k_numpy_core_umath_failed_to_impor), 0, 1, 0, 0}, - {&__pyx_kp_u_of, __pyx_k_of, sizeof(__pyx_k_of), 0, 1, 0, 0}, - {&__pyx_n_s_offset_dict, __pyx_k_offset_dict, sizeof(__pyx_k_offset_dict), 0, 0, 1, 1}, - {&__pyx_n_s_offset_info, __pyx_k_offset_info, sizeof(__pyx_k_offset_info), 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_ogr, __pyx_k_ogr, sizeof(__pyx_k_ogr), 0, 0, 1, 1}, - {&__pyx_n_s_open_set, __pyx_k_open_set, sizeof(__pyx_k_open_set), 0, 0, 1, 1}, - {&__pyx_kp_u_opening, __pyx_k_opening, sizeof(__pyx_k_opening), 0, 1, 0, 0}, - {&__pyx_n_s_ops, __pyx_k_ops, sizeof(__pyx_k_ops), 0, 0, 1, 1}, - {&__pyx_n_s_options, __pyx_k_options, sizeof(__pyx_k_options), 0, 0, 1, 1}, - {&__pyx_n_s_order, __pyx_k_order, sizeof(__pyx_k_order), 0, 0, 1, 1}, - {&__pyx_n_u_order, __pyx_k_order, sizeof(__pyx_k_order), 0, 1, 0, 1}, - {&__pyx_kp_u_order_1, __pyx_k_order_1, sizeof(__pyx_k_order_1), 0, 1, 0, 0}, - {&__pyx_n_s_order_count, __pyx_k_order_count, sizeof(__pyx_k_order_count), 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_osr, __pyx_k_osr, sizeof(__pyx_k_osr), 0, 0, 1, 1}, - {&__pyx_n_s_osr_axis_mapping_strategy, __pyx_k_osr_axis_mapping_strategy, sizeof(__pyx_k_osr_axis_mapping_strategy), 0, 0, 1, 1}, - {&__pyx_n_s_out_dir, __pyx_k_out_dir, sizeof(__pyx_k_out_dir), 0, 0, 1, 1}, - {&__pyx_n_s_out_dir_increase, __pyx_k_out_dir_increase, sizeof(__pyx_k_out_dir_increase), 0, 0, 1, 1}, - {&__pyx_kp_u_out_of_bounds_for, __pyx_k_out_of_bounds_for, sizeof(__pyx_k_out_of_bounds_for), 0, 1, 0, 0}, - {&__pyx_n_s_outet_basename, __pyx_k_outet_basename, sizeof(__pyx_k_outet_basename), 0, 0, 1, 1}, - {&__pyx_n_s_outflow_dir, __pyx_k_outflow_dir, sizeof(__pyx_k_outflow_dir), 0, 0, 1, 1}, - {&__pyx_n_u_outlet, __pyx_k_outlet, sizeof(__pyx_k_outlet), 0, 1, 0, 1}, - {&__pyx_kp_u_outlet_1, __pyx_k_outlet_1, sizeof(__pyx_k_outlet_1), 0, 1, 0, 0}, - {&__pyx_n_s_outlet_at_confluence, __pyx_k_outlet_at_confluence, sizeof(__pyx_k_outlet_at_confluence), 0, 0, 1, 1}, - {&__pyx_kp_u_outlet_detection, __pyx_k_outlet_detection, sizeof(__pyx_k_outlet_detection), 0, 1, 0, 0}, - {&__pyx_kp_u_outlet_detection_0_complete, __pyx_k_outlet_detection_0_complete, sizeof(__pyx_k_outlet_detection_0_complete), 0, 1, 0, 0}, - {&__pyx_kp_u_outlet_detection_100_complete_co, __pyx_k_outlet_detection_100_complete_co, sizeof(__pyx_k_outlet_detection_100_complete_co), 0, 1, 0, 0}, - {&__pyx_kp_u_outlet_detection_done, __pyx_k_outlet_detection_done, sizeof(__pyx_k_outlet_detection_done), 0, 1, 0, 0}, - {&__pyx_n_s_outlet_feature, __pyx_k_outlet_feature, sizeof(__pyx_k_outlet_feature), 0, 0, 1, 1}, - {&__pyx_n_s_outlet_fid, __pyx_k_outlet_fid, sizeof(__pyx_k_outlet_fid), 0, 0, 1, 1}, - {&__pyx_n_s_outlet_fid_list, __pyx_k_outlet_fid_list, sizeof(__pyx_k_outlet_fid_list), 0, 0, 1, 1}, - {&__pyx_n_s_outlet_index, __pyx_k_outlet_index, sizeof(__pyx_k_outlet_index), 0, 0, 1, 1}, - {&__pyx_n_s_outlet_layer, __pyx_k_outlet_layer, sizeof(__pyx_k_outlet_layer), 0, 0, 1, 1}, - {&__pyx_n_s_outlet_point, __pyx_k_outlet_point, sizeof(__pyx_k_outlet_point), 0, 0, 1, 1}, - {&__pyx_n_s_outlet_vector, __pyx_k_outlet_vector, sizeof(__pyx_k_outlet_vector), 0, 0, 1, 1}, - {&__pyx_n_s_outlet_x, __pyx_k_outlet_x, sizeof(__pyx_k_outlet_x), 0, 0, 1, 1}, - {&__pyx_n_u_outlet_x, __pyx_k_outlet_x, sizeof(__pyx_k_outlet_x), 0, 1, 0, 1}, - {&__pyx_n_s_outlet_y, __pyx_k_outlet_y, sizeof(__pyx_k_outlet_y), 0, 0, 1, 1}, - {&__pyx_n_u_outlet_y, __pyx_k_outlet_y, sizeof(__pyx_k_outlet_y), 0, 1, 0, 1}, - {&__pyx_kp_u_outlets_complete, __pyx_k_outlets_complete, sizeof(__pyx_k_outlets_complete), 0, 1, 0, 0}, - {&__pyx_n_s_p_val, __pyx_k_p_val, sizeof(__pyx_k_p_val), 0, 0, 1, 1}, - {&__pyx_n_s_path, __pyx_k_path, sizeof(__pyx_k_path), 0, 0, 1, 1}, - {&__pyx_n_s_payload, __pyx_k_payload, sizeof(__pyx_k_payload), 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_u_pit_mask_tif, __pyx_k_pit_mask_tif, sizeof(__pyx_k_pit_mask_tif), 0, 1, 0, 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_count, __pyx_k_pixel_count, sizeof(__pyx_k_pixel_count), 0, 0, 1, 1}, - {&__pyx_n_s_pixel_val, __pyx_k_pixel_val, sizeof(__pyx_k_pixel_val), 0, 0, 1, 1}, - {&__pyx_kp_u_pixels_complete, __pyx_k_pixels_complete, sizeof(__pyx_k_pixels_complete), 0, 1, 0, 0}, - {&__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_u_plateau_distance_tif, __pyx_k_plateau_distance_tif, sizeof(__pyx_k_plateau_distance_tif), 0, 1, 0, 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_u_plateu_drain_mask_tif, __pyx_k_plateu_drain_mask_tif, sizeof(__pyx_k_plateu_drain_mask_tif), 0, 1, 0, 0}, - {&__pyx_n_s_pop, __pyx_k_pop, sizeof(__pyx_k_pop), 0, 0, 1, 1}, - {&__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_processed_nodes, __pyx_k_processed_nodes, sizeof(__pyx_k_processed_nodes), 0, 0, 1, 1}, - {&__pyx_n_s_processed_segments, __pyx_k_processed_segments, sizeof(__pyx_k_processed_segments), 0, 0, 1, 1}, - {&__pyx_n_s_proj_x, __pyx_k_proj_x, sizeof(__pyx_k_proj_x), 0, 0, 1, 1}, - {&__pyx_n_s_proj_y, __pyx_k_proj_y, sizeof(__pyx_k_proj_y), 0, 0, 1, 1}, - {&__pyx_n_u_projection_wkt, __pyx_k_projection_wkt, sizeof(__pyx_k_projection_wkt), 0, 1, 0, 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_kp_u_quitting_too_many_steps, __pyx_k_quitting_too_many_steps, sizeof(__pyx_k_quitting_too_many_steps), 0, 1, 0, 0}, - {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1}, - {&__pyx_kp_u_raster, __pyx_k_raster, sizeof(__pyx_k_raster), 0, 1, 0, 0}, - {&__pyx_n_s_raster_coord, __pyx_k_raster_coord, sizeof(__pyx_k_raster_coord), 0, 0, 1, 1}, - {&__pyx_n_s_raster_driver, __pyx_k_raster_driver, sizeof(__pyx_k_raster_driver), 0, 0, 1, 1}, - {&__pyx_n_s_raster_driver_creation_tuple, __pyx_k_raster_driver_creation_tuple, sizeof(__pyx_k_raster_driver_creation_tuple), 0, 0, 1, 1}, - {&__pyx_n_s_raster_info, __pyx_k_raster_info, sizeof(__pyx_k_raster_info), 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_u_raster_size, __pyx_k_raster_size, sizeof(__pyx_k_raster_size), 0, 1, 0, 1}, - {&__pyx_n_s_raster_srs, __pyx_k_raster_srs, sizeof(__pyx_k_raster_srs), 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_remove, __pyx_k_remove, sizeof(__pyx_k_remove), 0, 0, 1, 1}, - {&__pyx_kp_u_resulted_in_null_trying, __pyx_k_resulted_in_null_trying, sizeof(__pyx_k_resulted_in_null_trying), 0, 1, 0, 0}, - {&__pyx_kp_u_retrying, __pyx_k_retrying, sizeof(__pyx_k_retrying), 0, 1, 0, 0}, - {&__pyx_n_s_reverse, __pyx_k_reverse, sizeof(__pyx_k_reverse), 0, 0, 1, 1}, - {&__pyx_n_s_right, __pyx_k_right, sizeof(__pyx_k_right), 0, 0, 1, 1}, - {&__pyx_n_s_right_in, __pyx_k_right_in, sizeof(__pyx_k_right_in), 0, 0, 1, 1}, - {&__pyx_n_u_river_id, __pyx_k_river_id, sizeof(__pyx_k_river_id), 0, 1, 0, 1}, - {&__pyx_n_s_river_order, __pyx_k_river_order, sizeof(__pyx_k_river_order), 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_u_s_is_not_a_file, __pyx_k_s_is_not_a_file, sizeof(__pyx_k_s_is_not_a_file), 0, 1, 0, 0}, - {&__pyx_kp_u_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, 1, 0, 0}, - {&__pyx_n_s_scipy, __pyx_k_scipy, sizeof(__pyx_k_scipy), 0, 0, 1, 1}, - {&__pyx_n_s_scipy_stats, __pyx_k_scipy_stats, sizeof(__pyx_k_scipy_stats), 0, 0, 1, 1}, - {&__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_search_steps, __pyx_k_search_steps, sizeof(__pyx_k_search_steps), 0, 0, 1, 1}, - {&__pyx_kp_u_segments_complete, __pyx_k_segments_complete, sizeof(__pyx_k_segments_complete), 0, 1, 0, 0}, - {&__pyx_n_s_segments_to_process, __pyx_k_segments_to_process, sizeof(__pyx_k_segments_to_process), 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_shapely, __pyx_k_shapely, sizeof(__pyx_k_shapely), 0, 0, 1, 1}, - {&__pyx_n_s_shapely_ops, __pyx_k_shapely_ops, sizeof(__pyx_k_shapely_ops), 0, 0, 1, 1}, - {&__pyx_n_s_shapely_wkb, __pyx_k_shapely_wkb, sizeof(__pyx_k_shapely_wkb), 0, 0, 1, 1}, - {&__pyx_n_s_shutil, __pyx_k_shutil, sizeof(__pyx_k_shutil), 0, 0, 1, 1}, - {&__pyx_n_s_sleep, __pyx_k_sleep, sizeof(__pyx_k_sleep), 0, 0, 1, 1}, - {&__pyx_n_s_sorted, __pyx_k_sorted, sizeof(__pyx_k_sorted), 0, 0, 1, 1}, - {&__pyx_n_s_sorted_stream_order_list, __pyx_k_sorted_stream_order_list, sizeof(__pyx_k_sorted_stream_order_list), 0, 0, 1, 1}, - {&__pyx_n_s_source_id, __pyx_k_source_id, sizeof(__pyx_k_source_id), 0, 0, 1, 1}, - {&__pyx_n_s_source_point_stack, __pyx_k_source_point_stack, sizeof(__pyx_k_source_point_stack), 0, 0, 1, 1}, - {&__pyx_kp_u_source_points_complete, __pyx_k_source_points_complete, sizeof(__pyx_k_source_points_complete), 0, 1, 0, 0}, - {&__pyx_n_s_source_stream_point, __pyx_k_source_stream_point, sizeof(__pyx_k_source_stream_point), 0, 0, 1, 1}, - {&__pyx_n_s_splitext, __pyx_k_splitext, sizeof(__pyx_k_splitext), 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_kp_u_starting_search, __pyx_k_starting_search, sizeof(__pyx_k_starting_search), 0, 1, 0, 0}, - {&__pyx_n_s_stats, __pyx_k_stats, sizeof(__pyx_k_stats), 0, 0, 1, 1}, - {&__pyx_n_s_strahler_stream_vector_path, __pyx_k_strahler_stream_vector_path, sizeof(__pyx_k_strahler_stream_vector_path), 0, 0, 1, 1}, - {&__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_basename, __pyx_k_stream_basename, sizeof(__pyx_k_stream_basename), 0, 0, 1, 1}, - {&__pyx_n_s_stream_feature, __pyx_k_stream_feature, sizeof(__pyx_k_stream_feature), 0, 0, 1, 1}, - {&__pyx_n_s_stream_fid, __pyx_k_stream_fid, sizeof(__pyx_k_stream_fid), 0, 0, 1, 1}, - {&__pyx_n_u_stream_fid, __pyx_k_stream_fid, sizeof(__pyx_k_stream_fid), 0, 1, 0, 1}, - {&__pyx_kp_u_stream_fragments_complete, __pyx_k_stream_fragments_complete, sizeof(__pyx_k_stream_fragments_complete), 0, 1, 0, 0}, - {&__pyx_n_s_stream_layer, __pyx_k_stream_layer, sizeof(__pyx_k_stream_layer), 0, 0, 1, 1}, - {&__pyx_n_s_stream_line, __pyx_k_stream_line, sizeof(__pyx_k_stream_line), 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_order, __pyx_k_stream_order, sizeof(__pyx_k_stream_order), 0, 0, 1, 1}, - {&__pyx_n_s_stream_order_list, __pyx_k_stream_order_list, sizeof(__pyx_k_stream_order_list), 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_stream_vector, __pyx_k_stream_vector, sizeof(__pyx_k_stream_vector), 0, 0, 1, 1}, - {&__pyx_n_s_streams_by_order, __pyx_k_streams_by_order, sizeof(__pyx_k_streams_by_order), 0, 0, 1, 1}, - {&__pyx_n_s_streams_to_process, __pyx_k_streams_to_process, sizeof(__pyx_k_streams_to_process), 0, 0, 1, 1}, - {&__pyx_n_s_streams_to_retest, __pyx_k_streams_to_retest, sizeof(__pyx_k_streams_to_retest), 0, 0, 1, 1}, - {&__pyx_n_s_strftime, __pyx_k_strftime, sizeof(__pyx_k_strftime), 0, 0, 1, 1}, - {&__pyx_n_s_suffix, __pyx_k_suffix, sizeof(__pyx_k_suffix), 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_discovery_raster_path, __pyx_k_target_discovery_raster_path, sizeof(__pyx_k_target_discovery_raster_path), 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_finish_raster_path, __pyx_k_target_finish_raster_path, sizeof(__pyx_k_target_finish_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_outlet_vector_path, __pyx_k_target_outlet_vector_path, sizeof(__pyx_k_target_outlet_vector_path), 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_target_stream_vector_path, __pyx_k_target_stream_vector_path, sizeof(__pyx_k_target_stream_vector_path), 0, 0, 1, 1}, - {&__pyx_n_s_target_watershed_boundary_vector, __pyx_k_target_watershed_boundary_vector, sizeof(__pyx_k_target_watershed_boundary_vector), 0, 0, 1, 1}, - {&__pyx_n_s_tempfile, __pyx_k_tempfile, sizeof(__pyx_k_tempfile), 0, 0, 1, 1}, - {&__pyx_n_s_terminated_early, __pyx_k_terminated_early, sizeof(__pyx_k_terminated_early), 0, 0, 1, 1}, - {&__pyx_n_u_terminated_early, __pyx_k_terminated_early, sizeof(__pyx_k_terminated_early), 0, 1, 0, 1}, - {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, - {&__pyx_n_s_test_dir, __pyx_k_test_dir, sizeof(__pyx_k_test_dir), 0, 0, 1, 1}, - {&__pyx_n_s_test_order, __pyx_k_test_order, sizeof(__pyx_k_test_order), 0, 0, 1, 1}, - {&__pyx_n_u_thresh_fa, __pyx_k_thresh_fa, sizeof(__pyx_k_thresh_fa), 0, 1, 0, 1}, - {&__pyx_n_s_time, __pyx_k_time, sizeof(__pyx_k_time), 0, 0, 1, 1}, - {&__pyx_n_s_tmp_dir, __pyx_k_tmp_dir, sizeof(__pyx_k_tmp_dir), 0, 0, 1, 1}, - {&__pyx_n_s_tmp_dir_root, __pyx_k_tmp_dir_root, sizeof(__pyx_k_tmp_dir_root), 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_tmp_work_dir, __pyx_k_tmp_work_dir, sizeof(__pyx_k_tmp_work_dir), 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_u_trace_threshold_proportion_shoul, __pyx_k_trace_threshold_proportion_shoul, sizeof(__pyx_k_trace_threshold_proportion_shoul), 0, 1, 0, 0}, - {&__pyx_n_s_ttest_ind, __pyx_k_ttest_ind, sizeof(__pyx_k_ttest_ind), 0, 0, 1, 1}, - {&__pyx_n_s_uint8, __pyx_k_uint8, sizeof(__pyx_k_uint8), 0, 0, 1, 1}, - {&__pyx_kp_u_unable_to_open, __pyx_k_unable_to_open, sizeof(__pyx_k_unable_to_open), 0, 1, 0, 0}, - {&__pyx_n_s_upstream_all_defined, __pyx_k_upstream_all_defined, sizeof(__pyx_k_upstream_all_defined), 0, 0, 1, 1}, - {&__pyx_n_s_upstream_coord, __pyx_k_upstream_coord, sizeof(__pyx_k_upstream_coord), 0, 0, 1, 1}, - {&__pyx_n_s_upstream_count, __pyx_k_upstream_count, sizeof(__pyx_k_upstream_count), 0, 0, 1, 1}, - {&__pyx_n_s_upstream_d8_dir, __pyx_k_upstream_d8_dir, sizeof(__pyx_k_upstream_d8_dir), 0, 0, 1, 1}, - {&__pyx_n_u_upstream_d8_dir, __pyx_k_upstream_d8_dir, sizeof(__pyx_k_upstream_d8_dir), 0, 1, 0, 1}, - {&__pyx_n_s_upstream_dem, __pyx_k_upstream_dem, sizeof(__pyx_k_upstream_dem), 0, 0, 1, 1}, - {&__pyx_n_s_upstream_dirs, __pyx_k_upstream_dirs, sizeof(__pyx_k_upstream_dirs), 0, 0, 1, 1}, - {&__pyx_n_s_upstream_feature, __pyx_k_upstream_feature, sizeof(__pyx_k_upstream_feature), 0, 0, 1, 1}, - {&__pyx_n_s_upstream_fid, __pyx_k_upstream_fid, sizeof(__pyx_k_upstream_fid), 0, 0, 1, 1}, - {&__pyx_n_s_upstream_fid_list, __pyx_k_upstream_fid_list, sizeof(__pyx_k_upstream_fid_list), 0, 0, 1, 1}, - {&__pyx_n_s_upstream_fid_map, __pyx_k_upstream_fid_map, sizeof(__pyx_k_upstream_fid_map), 0, 0, 1, 1}, - {&__pyx_n_s_upstream_fids, __pyx_k_upstream_fids, sizeof(__pyx_k_upstream_fids), 0, 0, 1, 1}, - {&__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_upstream_id, __pyx_k_upstream_id, sizeof(__pyx_k_upstream_id), 0, 0, 1, 1}, - {&__pyx_n_s_upstream_id_list, __pyx_k_upstream_id_list, sizeof(__pyx_k_upstream_id_list), 0, 0, 1, 1}, - {&__pyx_n_s_upstream_index, __pyx_k_upstream_index, sizeof(__pyx_k_upstream_index), 0, 0, 1, 1}, - {&__pyx_n_s_upstream_order, __pyx_k_upstream_order, sizeof(__pyx_k_upstream_order), 0, 0, 1, 1}, - {&__pyx_n_s_upstream_stack, __pyx_k_upstream_stack, sizeof(__pyx_k_upstream_stack), 0, 0, 1, 1}, - {&__pyx_n_s_upstream_to_downstream_id, __pyx_k_upstream_to_downstream_id, sizeof(__pyx_k_upstream_to_downstream_id), 0, 0, 1, 1}, - {&__pyx_n_u_us_fa, __pyx_k_us_fa, sizeof(__pyx_k_us_fa), 0, 1, 0, 1}, - {&__pyx_n_s_us_x, __pyx_k_us_x, sizeof(__pyx_k_us_x), 0, 0, 1, 1}, - {&__pyx_n_u_us_x, __pyx_k_us_x, sizeof(__pyx_k_us_x), 0, 1, 0, 1}, - {&__pyx_n_s_us_y, __pyx_k_us_y, sizeof(__pyx_k_us_y), 0, 0, 1, 1}, - {&__pyx_n_u_us_y, __pyx_k_us_y, sizeof(__pyx_k_us_y), 0, 1, 0, 1}, - {&__pyx_n_s_value, __pyx_k_value, sizeof(__pyx_k_value), 0, 0, 1, 1}, - {&__pyx_n_s_visit_count, __pyx_k_visit_count, sizeof(__pyx_k_visit_count), 0, 0, 1, 1}, - {&__pyx_n_s_visit_order_stack, __pyx_k_visit_order_stack, sizeof(__pyx_k_visit_order_stack), 0, 0, 1, 1}, - {&__pyx_n_s_visited_managed_raster, __pyx_k_visited_managed_raster, sizeof(__pyx_k_visited_managed_raster), 0, 0, 1, 1}, - {&__pyx_n_s_visited_raster_path, __pyx_k_visited_raster_path, sizeof(__pyx_k_visited_raster_path), 0, 0, 1, 1}, - {&__pyx_kp_u_visited_tif, __pyx_k_visited_tif, sizeof(__pyx_k_visited_tif), 0, 1, 0, 0}, - {&__pyx_n_s_warning, __pyx_k_warning, sizeof(__pyx_k_warning), 0, 0, 1, 1}, - {&__pyx_n_s_watershed_basename, __pyx_k_watershed_basename, sizeof(__pyx_k_watershed_basename), 0, 0, 1, 1}, - {&__pyx_n_s_watershed_boundary, __pyx_k_watershed_boundary, sizeof(__pyx_k_watershed_boundary), 0, 0, 1, 1}, - {&__pyx_n_s_watershed_feature, __pyx_k_watershed_feature, sizeof(__pyx_k_watershed_feature), 0, 0, 1, 1}, - {&__pyx_n_s_watershed_layer, __pyx_k_watershed_layer, sizeof(__pyx_k_watershed_layer), 0, 0, 1, 1}, - {&__pyx_n_s_watershed_polygon, __pyx_k_watershed_polygon, sizeof(__pyx_k_watershed_polygon), 0, 0, 1, 1}, - {&__pyx_n_s_watershed_vector, __pyx_k_watershed_vector, sizeof(__pyx_k_watershed_vector), 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_u_win_xsize, __pyx_k_win_xsize, sizeof(__pyx_k_win_xsize), 0, 1, 0, 1}, - {&__pyx_n_s_win_xsize_border, __pyx_k_win_xsize_border, sizeof(__pyx_k_win_xsize_border), 0, 0, 1, 1}, - {&__pyx_n_s_win_ysize, __pyx_k_win_ysize, sizeof(__pyx_k_win_ysize), 0, 0, 1, 1}, - {&__pyx_n_u_win_ysize, __pyx_k_win_ysize, sizeof(__pyx_k_win_ysize), 0, 1, 0, 1}, - {&__pyx_n_s_win_ysize_border, __pyx_k_win_ysize_border, sizeof(__pyx_k_win_ysize_border), 0, 0, 1, 1}, - {&__pyx_n_s_wkb, __pyx_k_wkb, sizeof(__pyx_k_wkb), 0, 0, 1, 1}, - {&__pyx_n_s_wkbLineString, __pyx_k_wkbLineString, sizeof(__pyx_k_wkbLineString), 0, 0, 1, 1}, - {&__pyx_n_s_wkbLinearRing, __pyx_k_wkbLinearRing, sizeof(__pyx_k_wkbLinearRing), 0, 0, 1, 1}, - {&__pyx_n_s_wkbPoint, __pyx_k_wkbPoint, sizeof(__pyx_k_wkbPoint), 0, 0, 1, 1}, - {&__pyx_n_s_wkbPolygon, __pyx_k_wkbPolygon, sizeof(__pyx_k_wkbPolygon), 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_working_feature, __pyx_k_working_feature, sizeof(__pyx_k_working_feature), 0, 0, 1, 1}, - {&__pyx_n_s_working_fid, __pyx_k_working_fid, sizeof(__pyx_k_working_fid), 0, 0, 1, 1}, - {&__pyx_n_s_working_flow_accum_threshold, __pyx_k_working_flow_accum_threshold, sizeof(__pyx_k_working_flow_accum_threshold), 0, 0, 1, 1}, - {&__pyx_n_s_working_geom, __pyx_k_working_geom, sizeof(__pyx_k_working_geom), 0, 0, 1, 1}, - {&__pyx_n_s_working_order, __pyx_k_working_order, sizeof(__pyx_k_working_order), 0, 0, 1, 1}, - {&__pyx_n_s_working_river_id, __pyx_k_working_river_id, sizeof(__pyx_k_working_river_id), 0, 0, 1, 1}, - {&__pyx_n_s_working_stack, __pyx_k_working_stack, sizeof(__pyx_k_working_stack), 0, 0, 1, 1}, - {&__pyx_n_s_workspace_dir, __pyx_k_workspace_dir, sizeof(__pyx_k_workspace_dir), 0, 0, 1, 1}, - {&__pyx_n_s_write_mode, __pyx_k_write_mode, sizeof(__pyx_k_write_mode), 0, 0, 1, 1}, - {&__pyx_n_s_x, __pyx_k_x, sizeof(__pyx_k_x), 0, 0, 1, 1}, - {&__pyx_n_u_x, __pyx_k_x, sizeof(__pyx_k_x), 0, 1, 0, 1}, - {&__pyx_n_s_x_f, __pyx_k_x_f, sizeof(__pyx_k_x_f), 0, 0, 1, 1}, - {&__pyx_n_s_x_l, __pyx_k_x_l, sizeof(__pyx_k_x_l), 0, 0, 1, 1}, - {&__pyx_n_s_x_n, __pyx_k_x_n, sizeof(__pyx_k_x_n), 0, 0, 1, 1}, - {&__pyx_n_s_x_off_border, __pyx_k_x_off_border, sizeof(__pyx_k_x_off_border), 0, 0, 1, 1}, - {&__pyx_kp_u_x_out_of_bounds_s, __pyx_k_x_out_of_bounds_s, sizeof(__pyx_k_x_out_of_bounds_s), 0, 1, 0, 0}, - {&__pyx_n_s_x_p, __pyx_k_x_p, sizeof(__pyx_k_x_p), 0, 0, 1, 1}, - {&__pyx_n_s_x_u, __pyx_k_x_u, sizeof(__pyx_k_x_u), 0, 0, 1, 1}, - {&__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_n_u_xoff, __pyx_k_xoff, sizeof(__pyx_k_xoff), 0, 1, 0, 1}, - {&__pyx_n_s_y_f, __pyx_k_y_f, sizeof(__pyx_k_y_f), 0, 0, 1, 1}, - {&__pyx_n_s_y_l, __pyx_k_y_l, sizeof(__pyx_k_y_l), 0, 0, 1, 1}, - {&__pyx_n_s_y_n, __pyx_k_y_n, sizeof(__pyx_k_y_n), 0, 0, 1, 1}, - {&__pyx_n_s_y_off_border, __pyx_k_y_off_border, sizeof(__pyx_k_y_off_border), 0, 0, 1, 1}, - {&__pyx_kp_u_y_out_of_bounds_s, __pyx_k_y_out_of_bounds_s, sizeof(__pyx_k_y_out_of_bounds_s), 0, 1, 0, 0}, - {&__pyx_n_s_y_p, __pyx_k_y_p, sizeof(__pyx_k_y_p), 0, 0, 1, 1}, - {&__pyx_n_s_y_u, __pyx_k_y_u, sizeof(__pyx_k_y_u), 0, 0, 1, 1}, - {&__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}, - {&__pyx_n_u_yoff, __pyx_k_yoff, sizeof(__pyx_k_yoff), 0, 1, 0, 1}, - {0, 0, 0, 0, 0, 0, 0} -}; -static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_print = __Pyx_GetBuiltinName(__pyx_n_s_print); if (!__pyx_builtin_print) __PYX_ERR(0, 232, __pyx_L1_error) - __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 233, __pyx_L1_error) - __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 340, __pyx_L1_error) - __pyx_builtin_RuntimeError = __Pyx_GetBuiltinName(__pyx_n_s_RuntimeError); if (!__pyx_builtin_RuntimeError) __PYX_ERR(0, 441, __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, 724, __pyx_L1_error) - __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(0, 3398, __pyx_L1_error) - __pyx_builtin_min = __Pyx_GetBuiltinName(__pyx_n_s_min); if (!__pyx_builtin_min) __PYX_ERR(0, 3454, __pyx_L1_error) - __pyx_builtin_max = __Pyx_GetBuiltinName(__pyx_n_s_max); if (!__pyx_builtin_max) __PYX_ERR(0, 3455, __pyx_L1_error) - __pyx_builtin_sorted = __Pyx_GetBuiltinName(__pyx_n_s_sorted); if (!__pyx_builtin_sorted) __PYX_ERR(0, 3959, __pyx_L1_error) - __pyx_builtin_ImportError = __Pyx_GetBuiltinName(__pyx_n_s_ImportError); if (!__pyx_builtin_ImportError) __PYX_ERR(2, 947, __pyx_L1_error) - return 0; - __pyx_L1_error:; - return -1; -} - -static CYTHON_SMALL_CODE 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__2 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__2); - __Pyx_GIVEREF(__pyx_tuple__2); - - /* "(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__3 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__3); - __Pyx_GIVEREF(__pyx_tuple__3); - - /* "pygeoprocessing/routing/routing.pyx":1180 - * (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__7 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__7)) __PYX_ERR(0, 1180, __pyx_L1_error) - __Pyx_GOTREF(__pyx_slice__7); - __Pyx_GIVEREF(__pyx_slice__7); - - /* "pygeoprocessing/routing/routing.pyx":1579 - * if weight_raster is not None: - * weight_raster.close() - * LOGGER.info('%.1f%% complete', 100.0) # <<<<<<<<<<<<<< - * - * - */ - __pyx_tuple__9 = PyTuple_Pack(2, __pyx_kp_u_1f_complete, __pyx_float_100_0); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 1579, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__9); - __Pyx_GIVEREF(__pyx_tuple__9); - - /* "pygeoprocessing/routing/routing.pyx":3245 - * stream_feature = ogr.Feature( - * stream_layer.GetLayerDefn()) - * stream_feature.SetField('outlet', 0) # <<<<<<<<<<<<<< - * stream_layer.CreateFeature(stream_feature) - * stream_fid = stream_feature.GetFID() - */ - __pyx_tuple__16 = PyTuple_Pack(2, __pyx_n_u_outlet, __pyx_int_0); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 3245, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__16); - __Pyx_GIVEREF(__pyx_tuple__16); - - /* "pygeoprocessing/routing/routing.pyx":3316 - * # if no upstream it means it is an order 1 source stream - * if not upstream_id_list: - * stream_feature.SetField('order', 1) # <<<<<<<<<<<<<< - * stream_feature.SetGeometry(stream_line) - * - */ - __pyx_tuple__17 = PyTuple_Pack(2, __pyx_n_u_order, __pyx_int_1); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 3316, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__17); - __Pyx_GIVEREF(__pyx_tuple__17); - - /* "pygeoprocessing/routing/routing.pyx":3350 - * if stream_fid not in upstream_to_downstream_id: - * # it's an outlet so no downstream to process - * stream_feature.SetField('outlet', 1) # <<<<<<<<<<<<<< - * stream_layer.SetFeature(stream_feature) - * outlet_fid_list.append(stream_feature.GetFID()) - */ - __pyx_tuple__18 = PyTuple_Pack(2, __pyx_n_u_outlet, __pyx_int_1); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 3350, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__18); - __Pyx_GIVEREF(__pyx_tuple__18); - - /* "pygeoprocessing/routing/routing.pyx":3567 - * - * stream_layer.DeleteField( - * stream_layer.FindFieldIndex('upstream_d8_dir', 1)) # <<<<<<<<<<<<<< - * stream_layer.CommitTransaction() - * stream_layer.StartTransaction() - */ - __pyx_tuple__19 = PyTuple_Pack(2, __pyx_n_u_upstream_d8_dir, __pyx_int_1); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 3567, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__19); - __Pyx_GIVEREF(__pyx_tuple__19); - - /* "pygeoprocessing/routing/routing.pyx":4265 - * x_off_border = 1 - * else: - * flow_dir_block[:, 0] = flow_dir_nodata # <<<<<<<<<<<<<< - * - * # Test for top border and if so stripe nodata on the top margin - */ - __pyx_tuple__20 = PyTuple_Pack(2, __pyx_slice__7, __pyx_int_0); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 4265, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__20); - __Pyx_GIVEREF(__pyx_tuple__20); - - /* "pygeoprocessing/routing/routing.pyx":4272 - * y_off_border = 1 - * else: - * flow_dir_block[0, :] = flow_dir_nodata # <<<<<<<<<<<<<< - * - * # Test for right border and if so stripe nodata on the right margin - */ - __pyx_tuple__21 = PyTuple_Pack(2, __pyx_int_0, __pyx_slice__7); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 4272, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__21); - __Pyx_GIVEREF(__pyx_tuple__21); - - /* "pygeoprocessing/routing/routing.pyx":4279 - * win_xsize_border += 1 - * else: - * flow_dir_block[:, -1] = flow_dir_nodata # <<<<<<<<<<<<<< - * - * # Test for bottom border and if so stripe nodata on the bottom margin - */ - __pyx_tuple__22 = PyTuple_Pack(2, __pyx_slice__7, __pyx_int_neg_1); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 4279, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__22); - __Pyx_GIVEREF(__pyx_tuple__22); - - /* "pygeoprocessing/routing/routing.pyx":4286 - * win_ysize_border += 1 - * else: - * flow_dir_block[-1, :] = flow_dir_nodata # <<<<<<<<<<<<<< - * - * # Read iterblock plus a possible margin on top/bottom/left/right side - */ - __pyx_tuple__23 = PyTuple_Pack(2, __pyx_int_neg_1, __pyx_slice__7); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 4286, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__23); - __Pyx_GIVEREF(__pyx_tuple__23); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":947 - * __pyx_import_array() - * except Exception: - * raise ImportError("numpy.core.multiarray failed to import") # <<<<<<<<<<<<<< - * - * cdef inline int import_umath() except -1: - */ - __pyx_tuple__24 = PyTuple_Pack(1, __pyx_kp_u_numpy_core_multiarray_failed_to); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(2, 947, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__24); - __Pyx_GIVEREF(__pyx_tuple__24); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":953 - * _import_umath() - * except Exception: - * raise ImportError("numpy.core.umath failed to import") # <<<<<<<<<<<<<< - * - * cdef inline int import_ufunc() except -1: - */ - __pyx_tuple__25 = PyTuple_Pack(1, __pyx_kp_u_numpy_core_umath_failed_to_impor); if (unlikely(!__pyx_tuple__25)) __PYX_ERR(2, 953, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__25); - __Pyx_GIVEREF(__pyx_tuple__25); - - /* "pygeoprocessing/routing/routing.pyx":568 - * - * - * 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__26 = 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__26)) __PYX_ERR(0, 568, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__26); - __Pyx_GIVEREF(__pyx_tuple__26); - __pyx_codeobj__27 = (PyObject*)__Pyx_PyCode_New(3, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_generate_read_bounds, 568, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__27)) __PYX_ERR(0, 568, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":612 - * - * - * def fill_pits( # <<<<<<<<<<<<<< - * dem_raster_path_band, target_filled_dem_raster_path, - * working_dir=None, long max_pixel_fill_count=_MAX_PIXEL_FILL_COUNT, - */ - __pyx_tuple__28 = PyTuple_Pack(52, __pyx_n_s_dem_raster_path_band, __pyx_n_s_target_filled_dem_raster_path, __pyx_n_s_working_dir, __pyx_n_s_max_pixel_fill_count, __pyx_n_s_raster_driver_creation_tuple, __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_natural_drain_exists, __pyx_n_s_search_steps, __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_base_datatype, __pyx_n_s_filled_dem_raster, __pyx_n_s_filled_dem_band, __pyx_n_s_offset_info, __pyx_n_s_block_array, __pyx_n_s_filled_dem_managed_raster, __pyx_n_s_offset_dict, __pyx_n_s_current_pixel, __pyx_n_s_n_height, __pyx_n_s_pour_point); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 612, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__28); - __Pyx_GIVEREF(__pyx_tuple__28); - __pyx_codeobj__29 = (PyObject*)__Pyx_PyCode_New(5, 0, 52, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_fill_pits_2, 612, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__29)) __PYX_ERR(0, 612, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":994 - * - * - * def flow_dir_d8( # <<<<<<<<<<<<<< - * dem_raster_path_band, target_flow_dir_path, - * working_dir=None, - */ - __pyx_tuple__30 = 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_raster_driver_creation_tuple, __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_raster_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__30)) __PYX_ERR(0, 994, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__30); - __Pyx_GIVEREF(__pyx_tuple__30); - __pyx_codeobj__31 = (PyObject*)__Pyx_PyCode_New(4, 0, 58, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__30, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_flow_dir_d8_2, 994, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__31)) __PYX_ERR(0, 994, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":1359 - * - * - * def flow_accumulation_d8( # <<<<<<<<<<<<<< - * flow_dir_raster_path_band, target_flow_accum_raster_path, - * weight_raster_path_band=None, - */ - __pyx_tuple__32 = 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_raster_driver_creation_tuple, __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__32)) __PYX_ERR(0, 1359, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__32); - __Pyx_GIVEREF(__pyx_tuple__32); - __pyx_codeobj__33 = (PyObject*)__Pyx_PyCode_New(4, 0, 44, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__32, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_flow_accumulation_d8, 1359, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__33)) __PYX_ERR(0, 1359, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":1582 - * - * - * def flow_dir_mfd( # <<<<<<<<<<<<<< - * dem_raster_path_band, target_flow_dir_path, working_dir=None, - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): - */ - __pyx_tuple__35 = 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_raster_driver_creation_tuple, __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_raster_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__34, __pyx_n_s_n_distance); if (unlikely(!__pyx_tuple__35)) __PYX_ERR(0, 1582, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__35); - __Pyx_GIVEREF(__pyx_tuple__35); - __pyx_codeobj__36 = (PyObject*)__Pyx_PyCode_New(4, 0, 69, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__35, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_flow_dir_mfd, 1582, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__36)) __PYX_ERR(0, 1582, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2073 - * - * - * def flow_accumulation_mfd( # <<<<<<<<<<<<<< - * flow_dir_mfd_raster_path_band, target_flow_accum_raster_path, - * weight_raster_path_band=None, - */ - __pyx_tuple__37 = PyTuple_Pack(51, __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_raster_driver_creation_tuple, __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_visit_count, __pyx_n_s_pixel_count, __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_tmp_dir_root, __pyx_n_s_tmp_dir, __pyx_n_s_visited_raster_path, __pyx_n_s_visited_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__37)) __PYX_ERR(0, 2073, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__37); - __Pyx_GIVEREF(__pyx_tuple__37); - __pyx_codeobj__38 = (PyObject*)__Pyx_PyCode_New(4, 0, 51, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__37, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_flow_accumulation_mfd, 2073, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__38)) __PYX_ERR(0, 2073, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2354 - * - * - * def distance_to_channel_d8( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band, channel_raster_path_band, - * target_distance_to_channel_raster_path, - */ - __pyx_tuple__39 = 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_raster_driver_creation_tuple, __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__39)) __PYX_ERR(0, 2354, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__39); - __Pyx_GIVEREF(__pyx_tuple__39); - __pyx_codeobj__40 = (PyObject*)__Pyx_PyCode_New(5, 0, 41, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__39, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_distance_to_channel_d8, 2354, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__40)) __PYX_ERR(0, 2354, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2544 - * - * - * 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__41 = PyTuple_Pack(53, __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_raster_driver_creation_tuple, __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_tmp_work_dir, __pyx_n_s_visited_raster_path, __pyx_n_s_visited_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__41)) __PYX_ERR(0, 2544, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__41); - __Pyx_GIVEREF(__pyx_tuple__41); - __pyx_codeobj__42 = (PyObject*)__Pyx_PyCode_New(5, 0, 53, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__41, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_distance_to_channel_mfd, 2544, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__42)) __PYX_ERR(0, 2544, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":2811 - * - * - * def extract_streams_mfd( # <<<<<<<<<<<<<< - * flow_accum_raster_path_band, flow_dir_mfd_path_band, - * double flow_threshold, target_stream_raster_path, - */ - __pyx_tuple__43 = PyTuple_Pack(46, __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_raster_driver_creation_tuple, __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_block_offsets_list, __pyx_n_s_stream_raster, __pyx_n_s_stream_band, __pyx_n_s_stream_array); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(0, 2811, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__43); - __Pyx_GIVEREF(__pyx_tuple__43); - __pyx_codeobj__44 = (PyObject*)__Pyx_PyCode_New(6, 0, 46, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__43, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_extract_streams_mfd, 2811, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__44)) __PYX_ERR(0, 2811, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3011 - * - * - * 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__45 = PyTuple_Pack(1, __pyx_n_s_raster_path_band); if (unlikely(!__pyx_tuple__45)) __PYX_ERR(0, 3011, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__45); - __Pyx_GIVEREF(__pyx_tuple__45); - __pyx_codeobj__46 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__45, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_is_raster_path_band_formatted, 3011, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__46)) __PYX_ERR(0, 3011, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3025 - * - * - * def extract_strahler_streams_d8( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band, flow_accum_raster_path_band, - * dem_raster_path_band, - */ - __pyx_tuple__47 = PyTuple_Pack(112, __pyx_n_s_flow_dir_d8_raster_path_band, __pyx_n_s_flow_accum_raster_path_band, __pyx_n_s_dem_raster_path_band, __pyx_n_s_target_stream_vector_path, __pyx_n_s_min_flow_accum_threshold, __pyx_n_s_river_order, __pyx_n_s_min_p_val, __pyx_n_s_autotune_flow_accumulation, __pyx_n_s_osr_axis_mapping_strategy, __pyx_n_s_flow_dir_info, __pyx_n_s_flow_dir_srs, __pyx_n_s_gpkg_driver, __pyx_n_s_stream_vector, __pyx_n_s_stream_basename, __pyx_n_s_stream_layer, __pyx_n_s_flow_dir_managed_raster, __pyx_n_s_flow_accum_managed_raster, __pyx_n_s_dem_managed_raster, __pyx_n_s_flow_nodata, __pyx_n_s_xoff, __pyx_n_s_yoff, __pyx_n_s_i, __pyx_n_s_j, __pyx_n_s_d, __pyx_n_s_d_n, __pyx_n_s_n_cols, __pyx_n_s_n_rows, __pyx_n_s_win_xsize, __pyx_n_s_win_ysize, __pyx_n_s_n_pixels, __pyx_n_s_n_processed, __pyx_n_s_last_log_time, __pyx_n_s_source_point_stack, __pyx_n_s_source_stream_point, __pyx_n_s_x_l, __pyx_n_s_y_l, __pyx_n_s_x_n, __pyx_n_s_y_n, __pyx_n_s_upstream_count, __pyx_n_s_upstream_index, __pyx_n_s_upstream_dirs, __pyx_n_s_local_flow_accum, __pyx_n_s_is_drain, __pyx_n_s_coord_to_stream_ids, __pyx_n_s_offset_dict, __pyx_n_s_stream_feature, __pyx_n_s_stream_fid, __pyx_n_s_n_points, __pyx_n_s_downstream_to_upstream_ids, __pyx_n_s_upstream_to_downstream_id, __pyx_n_s_payload, __pyx_n_s_x_u, __pyx_n_s_y_u, __pyx_n_s_ds_x_1, __pyx_n_s_ds_y_1, __pyx_n_s_upstream_id_list, __pyx_n_s_stream_line, __pyx_n_s_downstream_dem, __pyx_n_s_upstream_id, __pyx_n_s_upstream_dem, __pyx_n_s_drop_distance, __pyx_n_s_streams_to_process, __pyx_n_s_base_feature_count, __pyx_n_s_outlet_fid_list, __pyx_n_s_downstream_fid, __pyx_n_s_downstream_feature, __pyx_n_s_connected_upstream_fids, __pyx_n_s_stream_order_list, __pyx_n_s_all_defined, __pyx_n_s_upstream_fid, __pyx_n_s_upstream_feature, __pyx_n_s_upstream_order, __pyx_n_s_sorted_stream_order_list, __pyx_n_s_downstream_order, __pyx_n_s_working_river_id, __pyx_n_s_outlet_index, __pyx_n_s_outlet_fid, __pyx_n_s_search_stack, __pyx_n_s_feature_id, __pyx_n_s_stream_order, __pyx_n_s_upstream_stack, __pyx_n_s_streams_by_order, __pyx_n_s_drop_distance_collection, __pyx_n_s_max_upstream_flow_accum, __pyx_n_s_order, __pyx_n_s_working_flow_accum_threshold, __pyx_n_s_test_order, __pyx_n_s__34, __pyx_n_s_p_val, __pyx_n_s_streams_to_retest, __pyx_n_s_ds_x, __pyx_n_s_ds_y, __pyx_n_s_upstream_d8_dir, __pyx_n_s_working_stack, __pyx_n_s_fid_to_order, __pyx_n_s_processed_segments, __pyx_n_s_segments_to_process, __pyx_n_s_deleted_set, __pyx_n_s_working_fid, __pyx_n_s_upstream_fid_list, __pyx_n_s_order_count, __pyx_n_s_working_order, __pyx_n_s_working_feature, __pyx_n_s_connected_fids, __pyx_n_s_downstream_geom, __pyx_n_s_working_geom, __pyx_n_s_multi_line, __pyx_n_s_joined_line, __pyx_n_s_upstream_all_defined, __pyx_n_s_connected_fid, __pyx_n_s_stream_feature, __pyx_n_s_fid); if (unlikely(!__pyx_tuple__47)) __PYX_ERR(0, 3025, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__47); - __Pyx_GIVEREF(__pyx_tuple__47); - __pyx_codeobj__48 = (PyObject*)__Pyx_PyCode_New(9, 0, 112, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__47, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_extract_strahler_streams_d8, 3025, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__48)) __PYX_ERR(0, 3025, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3700 - * - * - * def _build_discovery_finish_rasters( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band, target_discovery_raster_path, - * target_finish_raster_path): - */ - __pyx_tuple__49 = PyTuple_Pack(33, __pyx_n_s_flow_dir_d8_raster_path_band, __pyx_n_s_target_discovery_raster_path, __pyx_n_s_target_finish_raster_path, __pyx_n_s_flow_dir_info, __pyx_n_s_n_cols, __pyx_n_s_n_rows, __pyx_n_s_flow_dir_nodata, __pyx_n_s_flow_dir_managed_raster, __pyx_n_s_discovery_managed_raster, __pyx_n_s_finish_managed_raster, __pyx_n_s_discovery_stack, __pyx_n_s_finish_stack, __pyx_n_s_raster_coord, __pyx_n_s_finish_coordinate, __pyx_n_s_discovery_count, __pyx_n_s_n_processed, __pyx_n_s_n_pixels, __pyx_n_s_last_log_time, __pyx_n_s_n_pushed, __pyx_n_s_i, __pyx_n_s_j, __pyx_n_s_xoff, __pyx_n_s_yoff, __pyx_n_s_win_xsize, __pyx_n_s_win_ysize, __pyx_n_s_x_l, __pyx_n_s_y_l, __pyx_n_s_x_n, __pyx_n_s_y_n, __pyx_n_s_n_dir, __pyx_n_s_test_dir, __pyx_n_s_offset_dict, __pyx_n_s_d_n); if (unlikely(!__pyx_tuple__49)) __PYX_ERR(0, 3700, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__49); - __Pyx_GIVEREF(__pyx_tuple__49); - __pyx_codeobj__50 = (PyObject*)__Pyx_PyCode_New(3, 0, 33, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__49, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_build_discovery_finish_rasters, 3700, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__50)) __PYX_ERR(0, 3700, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":3830 - * - * - * def calculate_subwatershed_boundary( # <<<<<<<<<<<<<< - * d8_flow_dir_raster_path_band, - * strahler_stream_vector_path, target_watershed_boundary_vector_path, - */ - __pyx_tuple__51 = PyTuple_Pack(82, __pyx_n_s_d8_flow_dir_raster_path_band, __pyx_n_s_strahler_stream_vector_path, __pyx_n_s_target_watershed_boundary_vector, __pyx_n_s_max_steps_per_watershed, __pyx_n_s_outlet_at_confluence, __pyx_n_s_workspace_dir, __pyx_n_s_discovery_time_raster_path, __pyx_n_s_finish_time_raster_path, __pyx_n_s_discovery_managed_raster, __pyx_n_s_finish_managed_raster, __pyx_n_s_d8_flow_dir_managed_raster, __pyx_n_s_discovery_info, __pyx_n_s_discovery_nodata, __pyx_n_s_n_cols, __pyx_n_s_n_rows, __pyx_n_s_geotransform, __pyx_n_s_g0, __pyx_n_s_g1, __pyx_n_s_g2, __pyx_n_s_g3, __pyx_n_s_g4, __pyx_n_s_g5, __pyx_n_s_discovery_srs, __pyx_n_s_gpkg_driver, __pyx_n_s_watershed_vector, __pyx_n_s_watershed_basename, __pyx_n_s_watershed_layer, __pyx_n_s_x_l, __pyx_n_s_y_l, __pyx_n_s_outflow_dir, __pyx_n_s_x_f, __pyx_n_s_y_f, __pyx_n_s_x_p, __pyx_n_s_y_p, __pyx_n_s_discovery, __pyx_n_s_finish, __pyx_n_s_last_log_time, __pyx_n_s_stream_vector, __pyx_n_s_stream_layer, __pyx_n_s_upstream_fid_map, __pyx_n_s_stream_feature, __pyx_n_s_ds_x, __pyx_n_s_ds_y, __pyx_n_s_visit_order_stack, __pyx_n_s__34, __pyx_n_s_outlet_fid, __pyx_n_s_working_stack, __pyx_n_s_processed_nodes, __pyx_n_s_working_fid, __pyx_n_s_working_feature, __pyx_n_s_us_x, __pyx_n_s_us_y, __pyx_n_s_ds_x_1, __pyx_n_s_ds_y_1, __pyx_n_s_upstream_coord, __pyx_n_s_upstream_fids, __pyx_n_s_edge_side, __pyx_n_s_edge_dir, __pyx_n_s_cell_to_test, __pyx_n_s_out_dir_increase, __pyx_n_s_left, __pyx_n_s_right, __pyx_n_s_n_steps, __pyx_n_s_terminated_early, __pyx_n_s_delta_x, __pyx_n_s_delta_y, __pyx_n_s_int_max_steps_per_watershed, __pyx_n_s_index, __pyx_n_s_stream_fid, __pyx_n_s_boundary_list, __pyx_n_s_outlet_x, __pyx_n_s_outlet_y, __pyx_n_s_watershed_boundary, __pyx_n_s_left_in, __pyx_n_s_right_in, __pyx_n_s_out_dir, __pyx_n_s_watershed_feature, __pyx_n_s_watershed_polygon, __pyx_n_s_boundary_x, __pyx_n_s_boundary_y, __pyx_n_s_x, __pyx_n_s_fid); if (unlikely(!__pyx_tuple__51)) __PYX_ERR(0, 3830, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__51); - __Pyx_GIVEREF(__pyx_tuple__51); - __pyx_codeobj__52 = (PyObject*)__Pyx_PyCode_New(5, 0, 82, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__51, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_calculate_subwatershed_boundary_4, 3830, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__52)) __PYX_ERR(0, 3830, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":4162 - * - * - * def detect_outlets( # <<<<<<<<<<<<<< - * flow_dir_raster_path_band, flow_dir_type, target_outlet_vector_path): - * """Create point vector indicating flow raster outlets. - */ - __pyx_tuple__53 = PyTuple_Pack(40, __pyx_n_s_flow_dir_raster_path_band, __pyx_n_s_flow_dir_type, __pyx_n_s_target_outlet_vector_path, __pyx_n_s_d8_flow_dir_mode, __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_raster_x_size, __pyx_n_s_raster_y_size, __pyx_n_s_flow_dir, __pyx_n_s_flow_dir_n, __pyx_n_s_next_id, __pyx_n_s_n_dir, __pyx_n_s_is_outlet, __pyx_n_s_x_off_border, __pyx_n_s_y_off_border, __pyx_n_s_win_xsize_border, __pyx_n_s_win_ysize_border, __pyx_n_s_flow_dir_block, __pyx_n_s_raster_info, __pyx_n_s_flow_dir_nodata, __pyx_n_s_flow_dir_raster, __pyx_n_s_flow_dir_band, __pyx_n_s_raster_srs, __pyx_n_s_gpkg_driver, __pyx_n_s_outlet_vector, __pyx_n_s_outet_basename, __pyx_n_s_outlet_layer, __pyx_n_s_last_log_time, __pyx_n_s_block_offsets, __pyx_n_s_current_pixel, __pyx_n_s_outlet_point, __pyx_n_s_proj_x, __pyx_n_s_proj_y, __pyx_n_s_outlet_feature); if (unlikely(!__pyx_tuple__53)) __PYX_ERR(0, 4162, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__53); - __Pyx_GIVEREF(__pyx_tuple__53); - __pyx_codeobj__54 = (PyObject*)__Pyx_PyCode_New(3, 0, 40, 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_detect_outlets, 4162, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__54)) __PYX_ERR(0, 4162, __pyx_L1_error) - - /* "pygeoprocessing/routing/routing.pyx":4595 - * - * - * def _delete_feature( # <<<<<<<<<<<<<< - * stream_feature, stream_layer, upstream_to_downstream_id, - * downstream_to_upstream_ids): - */ - __pyx_tuple__55 = PyTuple_Pack(6, __pyx_n_s_stream_feature, __pyx_n_s_stream_layer, __pyx_n_s_upstream_to_downstream_id, __pyx_n_s_downstream_to_upstream_ids, __pyx_n_s_stream_fid, __pyx_n_s_downstream_fid); if (unlikely(!__pyx_tuple__55)) __PYX_ERR(0, 4595, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__55); - __Pyx_GIVEREF(__pyx_tuple__55); - __pyx_codeobj__56 = (PyObject*)__Pyx_PyCode_New(4, 0, 6, 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_delete_feature, 4595, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__56)) __PYX_ERR(0, 4595, __pyx_L1_error) - __Pyx_RefNannyFinishContext(); - return 0; - __pyx_L1_error:; - __Pyx_RefNannyFinishContext(); - return -1; -} - -static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { - __pyx_umethod_PyList_Type_pop.type = (PyObject*)&PyList_Type; - if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); - __pyx_float_0_2 = PyFloat_FromDouble(0.2); if (unlikely(!__pyx_float_0_2)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_float_0_5 = PyFloat_FromDouble(0.5); if (unlikely(!__pyx_float_0_5)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_float_1_25 = PyFloat_FromDouble(1.25); if (unlikely(!__pyx_float_1_25)) __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_5 = PyInt_FromLong(5); if (unlikely(!__pyx_int_5)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_100 = PyInt_FromLong(100); if (unlikely(!__pyx_int_100)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_1000000 = PyInt_FromLong(1000000L); if (unlikely(!__pyx_int_1000000)) __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 CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/ -static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/ -static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/ -static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/ -static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/ -static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/ -static CYTHON_SMALL_CODE 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 - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __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; - __pyx_vtable_15pygeoprocessing_7routing_7routing__ManagedRaster.flush = (void (*)(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *))__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_flush; - if (PyType_Ready(&__pyx_type_15pygeoprocessing_7routing_7routing__ManagedRaster) < 0) __PYX_ERR(0, 184, __pyx_L1_error) - #if PY_VERSION_HEX < 0x030800B1 - __pyx_type_15pygeoprocessing_7routing_7routing__ManagedRaster.tp_print = 0; - #endif - 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, 184, __pyx_L1_error) - if (PyObject_SetAttr(__pyx_m, __pyx_n_s_ManagedRaster, (PyObject *)&__pyx_type_15pygeoprocessing_7routing_7routing__ManagedRaster) < 0) __PYX_ERR(0, 184, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_15pygeoprocessing_7routing_7routing__ManagedRaster) < 0) __PYX_ERR(0, 184, __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 - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); - /*--- Type import code ---*/ - __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 9, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", - #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 - sizeof(PyTypeObject), - #else - sizeof(PyHeapTypeObject), - #endif - __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(3, 9, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyImport_ImportModule("numpy"); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 200, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_ptype_5numpy_dtype = __Pyx_ImportType(__pyx_t_1, "numpy", "dtype", sizeof(PyArray_Descr), __Pyx_ImportType_CheckSize_Ignore); - if (!__pyx_ptype_5numpy_dtype) __PYX_ERR(2, 200, __pyx_L1_error) - __pyx_ptype_5numpy_flatiter = __Pyx_ImportType(__pyx_t_1, "numpy", "flatiter", sizeof(PyArrayIterObject), __Pyx_ImportType_CheckSize_Ignore); - if (!__pyx_ptype_5numpy_flatiter) __PYX_ERR(2, 223, __pyx_L1_error) - __pyx_ptype_5numpy_broadcast = __Pyx_ImportType(__pyx_t_1, "numpy", "broadcast", sizeof(PyArrayMultiIterObject), __Pyx_ImportType_CheckSize_Ignore); - if (!__pyx_ptype_5numpy_broadcast) __PYX_ERR(2, 227, __pyx_L1_error) - __pyx_ptype_5numpy_ndarray = __Pyx_ImportType(__pyx_t_1, "numpy", "ndarray", sizeof(PyArrayObject), __Pyx_ImportType_CheckSize_Ignore); - if (!__pyx_ptype_5numpy_ndarray) __PYX_ERR(2, 239, __pyx_L1_error) - __pyx_ptype_5numpy_generic = __Pyx_ImportType(__pyx_t_1, "numpy", "generic", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_generic) __PYX_ERR(2, 771, __pyx_L1_error) - __pyx_ptype_5numpy_number = __Pyx_ImportType(__pyx_t_1, "numpy", "number", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_number) __PYX_ERR(2, 773, __pyx_L1_error) - __pyx_ptype_5numpy_integer = __Pyx_ImportType(__pyx_t_1, "numpy", "integer", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_integer) __PYX_ERR(2, 775, __pyx_L1_error) - __pyx_ptype_5numpy_signedinteger = __Pyx_ImportType(__pyx_t_1, "numpy", "signedinteger", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_signedinteger) __PYX_ERR(2, 777, __pyx_L1_error) - __pyx_ptype_5numpy_unsignedinteger = __Pyx_ImportType(__pyx_t_1, "numpy", "unsignedinteger", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_unsignedinteger) __PYX_ERR(2, 779, __pyx_L1_error) - __pyx_ptype_5numpy_inexact = __Pyx_ImportType(__pyx_t_1, "numpy", "inexact", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_inexact) __PYX_ERR(2, 781, __pyx_L1_error) - __pyx_ptype_5numpy_floating = __Pyx_ImportType(__pyx_t_1, "numpy", "floating", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_floating) __PYX_ERR(2, 783, __pyx_L1_error) - __pyx_ptype_5numpy_complexfloating = __Pyx_ImportType(__pyx_t_1, "numpy", "complexfloating", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_complexfloating) __PYX_ERR(2, 785, __pyx_L1_error) - __pyx_ptype_5numpy_flexible = __Pyx_ImportType(__pyx_t_1, "numpy", "flexible", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_flexible) __PYX_ERR(2, 787, __pyx_L1_error) - __pyx_ptype_5numpy_character = __Pyx_ImportType(__pyx_t_1, "numpy", "character", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_character) __PYX_ERR(2, 789, __pyx_L1_error) - __pyx_ptype_5numpy_ufunc = __Pyx_ImportType(__pyx_t_1, "numpy", "ufunc", sizeof(PyUFuncObject), __Pyx_ImportType_CheckSize_Ignore); - if (!__pyx_ptype_5numpy_ufunc) __PYX_ERR(2, 827, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_RefNannyFinishContext(); - return 0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __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; -} - - -#ifndef CYTHON_NO_PYINIT_EXPORT -#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC -#elif PY_MAJOR_VERSION < 3 -#ifdef __cplusplus -#define __Pyx_PyMODINIT_FUNC extern "C" void -#else -#define __Pyx_PyMODINIT_FUNC void -#endif -#else -#ifdef __cplusplus -#define __Pyx_PyMODINIT_FUNC extern "C" PyObject * -#else -#define __Pyx_PyMODINIT_FUNC PyObject * -#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 CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) { - #if PY_VERSION_HEX >= 0x030700A1 - static PY_INT64_T main_interpreter_id = -1; - PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp); - if (main_interpreter_id == -1) { - main_interpreter_id = current_id; - return (unlikely(current_id == -1)) ? -1 : 0; - } else if (unlikely(main_interpreter_id != current_id)) - #else - static PyInterpreterState *main_interpreter = NULL; - PyInterpreterState *current_interpreter = PyThreadState_Get()->interp; - if (!main_interpreter) { - main_interpreter = current_interpreter; - } else if (unlikely(main_interpreter != current_interpreter)) - #endif - { - PyErr_SetString( - PyExc_ImportError, - "Interpreter change detected - this module can only be loaded into one interpreter per process."); - return -1; - } - return 0; -} -static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) { - PyObject *value = PyObject_GetAttrString(spec, from_name); - int result = 0; - if (likely(value)) { - if (allow_none || value != Py_None) { - result = PyDict_SetItemString(moddict, to_name, value); - } - Py_DECREF(value); - } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { - PyErr_Clear(); - } else { - result = -1; - } - return result; -} -static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) { - PyObject *module = NULL, *moddict, *modname; - if (__Pyx_check_single_interpreter()) - return NULL; - 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__", 1) < 0)) goto bad; - if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad; - if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad; - if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad; - return module; -bad: - Py_XDECREF(module); - return NULL; -} - - -static CYTHON_SMALL_CODE 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[8]; - static int __pyx_t_5[8]; - static int __pyx_t_6[8]; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannyDeclarations - #if CYTHON_PEP489_MULTI_PHASE_INIT - if (__pyx_m) { - if (__pyx_m == __pyx_pyinit_module) return 0; - PyErr_SetString(PyExc_RuntimeError, "Module 'routing' has already been imported. Re-initialisation is not supported."); - return -1; - } - #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) - #ifdef __Pxy_PyFrame_Initialize_Offsets - __Pxy_PyFrame_Initialize_Offsets(); - #endif - __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) - Py_INCREF(__pyx_b); - __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) - Py_INCREF(__pyx_cython_runtime); - 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_SetAttr(__pyx_m, __pyx_n_s_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)) __PYX_ERR(0, 1, __pyx_L1_error) - if (unlikely(__Pyx_modinit_type_import_code() < 0)) __PYX_ERR(0, 1, __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":20 - * 5 6 7 - * """ - * import collections # <<<<<<<<<<<<<< - * import logging - * import os - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_collections, 0, 0); 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_collections, __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 collections - * import logging # <<<<<<<<<<<<<< - * import os - * import shutil - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_logging, 0, 0); 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_logging, __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 collections - * import logging - * import os # <<<<<<<<<<<<<< - * import shutil - * import tempfile - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_os, 0, 0); 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_os, __pyx_t_1) < 0) __PYX_ERR(0, 22, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":23 - * import logging - * import os - * import shutil # <<<<<<<<<<<<<< - * import tempfile - * import time - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_shutil, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 23, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_shutil, __pyx_t_1) < 0) __PYX_ERR(0, 23, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":24 - * import os - * import shutil - * import tempfile # <<<<<<<<<<<<<< - * import time - * - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_tempfile, 0, 0); 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_tempfile, __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 shutil - * import tempfile - * import time # <<<<<<<<<<<<<< - * - * cimport cython - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_time, 0, 0); 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_time, __pyx_t_1) < 0) __PYX_ERR(0, 25, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":41 - * from libcpp.stack cimport stack - * from libcpp.vector cimport vector - * from osgeo import gdal # <<<<<<<<<<<<<< - * from osgeo import ogr - * from osgeo import osr - */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 41, __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, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 41, __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, 41, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_gdal, __pyx_t_1) < 0) __PYX_ERR(0, 41, __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.vector cimport vector - * from osgeo import gdal - * from osgeo import ogr # <<<<<<<<<<<<<< - * from osgeo import osr - * import numpy - */ - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 42, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_n_s_ogr); - __Pyx_GIVEREF(__pyx_n_s_ogr); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_ogr); - __pyx_t_1 = __Pyx_Import(__pyx_n_s_osgeo, __pyx_t_2, 0); 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_ImportFrom(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 42, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_ogr, __pyx_t_2) < 0) __PYX_ERR(0, 42, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":43 - * from osgeo import gdal - * from osgeo import ogr - * from osgeo import osr # <<<<<<<<<<<<<< - * import numpy - * import shapely.wkb - */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_n_s_osr); - __Pyx_GIVEREF(__pyx_n_s_osr); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_osr); - __pyx_t_2 = __Pyx_Import(__pyx_n_s_osgeo, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 43, __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_osr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_osr, __pyx_t_1) < 0) __PYX_ERR(0, 43, __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":44 - * from osgeo import ogr - * from osgeo import osr - * import numpy # <<<<<<<<<<<<<< - * import shapely.wkb - * import shapely.ops - */ - __pyx_t_2 = __Pyx_Import(__pyx_n_s_numpy, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 44, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_numpy, __pyx_t_2) < 0) __PYX_ERR(0, 44, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":45 - * from osgeo import osr - * import numpy - * import shapely.wkb # <<<<<<<<<<<<<< - * import shapely.ops - * import scipy.stats - */ - __pyx_t_2 = __Pyx_Import(__pyx_n_s_shapely_wkb, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 45, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_shapely, __pyx_t_2) < 0) __PYX_ERR(0, 45, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":46 - * import numpy - * import shapely.wkb - * import shapely.ops # <<<<<<<<<<<<<< - * import scipy.stats - * - */ - __pyx_t_2 = __Pyx_Import(__pyx_n_s_shapely_ops, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 46, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_shapely, __pyx_t_2) < 0) __PYX_ERR(0, 46, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":47 - * import shapely.wkb - * import shapely.ops - * import scipy.stats # <<<<<<<<<<<<<< - * - * from ..geoprocessing_core import DEFAULT_OSR_AXIS_MAPPING_STRATEGY - */ - __pyx_t_2 = __Pyx_Import(__pyx_n_s_scipy_stats, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 47, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_scipy, __pyx_t_2) < 0) __PYX_ERR(0, 47, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":49 - * import scipy.stats - * - * from ..geoprocessing_core import DEFAULT_OSR_AXIS_MAPPING_STRATEGY # <<<<<<<<<<<<<< - * import pygeoprocessing - * - */ - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 49, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_n_s_DEFAULT_OSR_AXIS_MAPPING_STRATEG); - __Pyx_GIVEREF(__pyx_n_s_DEFAULT_OSR_AXIS_MAPPING_STRATEG); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_DEFAULT_OSR_AXIS_MAPPING_STRATEG); - __pyx_t_1 = __Pyx_Import(__pyx_n_s_geoprocessing_core, __pyx_t_2, 2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 49, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_DEFAULT_OSR_AXIS_MAPPING_STRATEG); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 49, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_DEFAULT_OSR_AXIS_MAPPING_STRATEG, __pyx_t_2) < 0) __PYX_ERR(0, 49, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":50 - * - * from ..geoprocessing_core import DEFAULT_OSR_AXIS_MAPPING_STRATEGY - * import pygeoprocessing # <<<<<<<<<<<<<< - * - * LOGGER = logging.getLogger(__name__) - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_pygeoprocessing, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 50, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pygeoprocessing, __pyx_t_1) < 0) __PYX_ERR(0, 50, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/routing.pyx":52 - * import pygeoprocessing - * - * LOGGER = logging.getLogger(__name__) # <<<<<<<<<<<<<< - * - * cdef float _LOGGING_PERIOD = 10.0 - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_logging); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 52, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_getLogger); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 52, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 52, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 52, __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; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_LOGGER, __pyx_t_3) < 0) __PYX_ERR(0, 52, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":54 - * LOGGER = logging.getLogger(__name__) - * - * cdef float _LOGGING_PERIOD = 10.0 # <<<<<<<<<<<<<< - * - * # This module creates rasters with a memory xy block size of 2**BLOCK_BITS - */ - __pyx_v_15pygeoprocessing_7routing_7routing__LOGGING_PERIOD = 10.0; - - /* "pygeoprocessing/routing/routing.pyx":57 - * - * # 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":60 - * - * # 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":65 - * DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS = ('GTiff', ( - * 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', - * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), # <<<<<<<<<<<<<< - * 'BLOCKYSIZE=%d' % (1 << BLOCK_BITS))) - * - */ - __pyx_t_3 = __Pyx_PyInt_From_long((1 << __pyx_v_15pygeoprocessing_7routing_7routing_BLOCK_BITS)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 65, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyUnicode_Format(__pyx_kp_u_BLOCKXSIZE_d, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 65, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":66 - * '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_3 = __Pyx_PyInt_From_long((1 << __pyx_v_15pygeoprocessing_7routing_7routing_BLOCK_BITS)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 66, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyUnicode_Format(__pyx_kp_u_BLOCKYSIZE_d, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 66, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/routing.pyx":64 - * # these are the creation options that'll be used for all the rasters - * DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS = ('GTiff', ( - * 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', # <<<<<<<<<<<<<< - * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), - * 'BLOCKYSIZE=%d' % (1 << BLOCK_BITS))) - */ - __pyx_t_3 = PyTuple_New(5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 64, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_kp_u_TILED_YES); - __Pyx_GIVEREF(__pyx_kp_u_TILED_YES); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_u_TILED_YES); - __Pyx_INCREF(__pyx_kp_u_BIGTIFF_YES); - __Pyx_GIVEREF(__pyx_kp_u_BIGTIFF_YES); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_kp_u_BIGTIFF_YES); - __Pyx_INCREF(__pyx_kp_u_COMPRESS_LZW); - __Pyx_GIVEREF(__pyx_kp_u_COMPRESS_LZW); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_kp_u_COMPRESS_LZW); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_t_2); - __pyx_t_1 = 0; - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":63 - * - * # these are the creation options that'll be used for all the rasters - * DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS = ('GTiff', ( # <<<<<<<<<<<<<< - * 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', - * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), - */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 63, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_n_u_GTiff); - __Pyx_GIVEREF(__pyx_n_u_GTiff); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_n_u_GTiff); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); - __pyx_t_3 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT, __pyx_t_2) < 0) __PYX_ERR(0, 63, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":70 - * # 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":73 - * - * # 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":74 - * # 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":80 - * # 4x0 - * # 567 - * cdef int *D8_XOFFSET = [1, 1, 0, -1, -1, -1, 0, 1] # <<<<<<<<<<<<<< - * cdef int *D8_YOFFSET = [0, -1, -1, -1, 0, +1, +1, +1] - * - */ - __pyx_t_4[0] = 1; - __pyx_t_4[1] = 1; - __pyx_t_4[2] = 0; - __pyx_t_4[3] = -1; - __pyx_t_4[4] = -1; - __pyx_t_4[5] = -1; - __pyx_t_4[6] = 0; - __pyx_t_4[7] = 1; - __pyx_v_15pygeoprocessing_7routing_7routing_D8_XOFFSET = __pyx_t_4; - - /* "pygeoprocessing/routing/routing.pyx":81 - * # 567 - * cdef int *D8_XOFFSET = [1, 1, 0, -1, -1, -1, 0, 1] - * cdef int *D8_YOFFSET = [0, -1, -1, -1, 0, +1, +1, +1] # <<<<<<<<<<<<<< - * - * # this is used to calculate the opposite D8 direction interpreting the index - */ - __pyx_t_5[0] = 0; - __pyx_t_5[1] = -1; - __pyx_t_5[2] = -1; - __pyx_t_5[3] = -1; - __pyx_t_5[4] = 0; - __pyx_t_5[5] = 1; - __pyx_t_5[6] = 1; - __pyx_t_5[7] = 1; - __pyx_v_15pygeoprocessing_7routing_7routing_D8_YOFFSET = __pyx_t_5; - - /* "pygeoprocessing/routing/routing.pyx":85 - * # 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] # <<<<<<<<<<<<<< - * - * # default of number of pixels to naturally drain. This number was derived off - */ - __pyx_t_6[0] = 4; - __pyx_t_6[1] = 5; - __pyx_t_6[2] = 6; - __pyx_t_6[3] = 7; - __pyx_t_6[4] = 0; - __pyx_t_6[5] = 1; - __pyx_t_6[6] = 2; - __pyx_t_6[7] = 3; - __pyx_v_15pygeoprocessing_7routing_7routing_D8_REVERSE_DIRECTION = __pyx_t_6; - - /* "pygeoprocessing/routing/routing.pyx":89 - * # default of number of pixels to naturally drain. This number was derived off - * # of reasonable expectations from a 30m DEM - * cdef int _MAX_PIXEL_FILL_COUNT = 500 # <<<<<<<<<<<<<< - * - * # exposing stl::priority_queue so we can have all 3 template arguments so - */ - __pyx_v_15pygeoprocessing_7routing_7routing__MAX_PIXEL_FILL_COUNT = 0x1F4; - - /* "pygeoprocessing/routing/routing.pyx":568 - * - * - * 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_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_1_generate_read_bounds, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 568, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_generate_read_bounds, __pyx_t_2) < 0) __PYX_ERR(0, 568, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":614 - * def fill_pits( - * dem_raster_path_band, target_filled_dem_raster_path, - * working_dir=None, long max_pixel_fill_count=_MAX_PIXEL_FILL_COUNT, # <<<<<<<<<<<<<< - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): - * """Fill the pits in a DEM. - */ - __pyx_k__5 = __pyx_v_15pygeoprocessing_7routing_7routing__MAX_PIXEL_FILL_COUNT; - - /* "pygeoprocessing/routing/routing.pyx":615 - * dem_raster_path_band, target_filled_dem_raster_path, - * working_dir=None, long max_pixel_fill_count=_MAX_PIXEL_FILL_COUNT, - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): # <<<<<<<<<<<<<< - * """Fill the pits in a DEM. - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 615, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_k__4 = __pyx_t_2; - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":612 - * - * - * def fill_pits( # <<<<<<<<<<<<<< - * dem_raster_path_band, target_filled_dem_raster_path, - * working_dir=None, long max_pixel_fill_count=_MAX_PIXEL_FILL_COUNT, - */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_3fill_pits, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 612, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_fill_pits_2, __pyx_t_2) < 0) __PYX_ERR(0, 612, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":997 - * dem_raster_path_band, target_flow_dir_path, - * working_dir=None, - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): # <<<<<<<<<<<<<< - * """D8 flow direction. - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 997, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_k__6 = __pyx_t_2; - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":994 - * - * - * def flow_dir_d8( # <<<<<<<<<<<<<< - * dem_raster_path_band, target_flow_dir_path, - * working_dir=None, - */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_5flow_dir_d8, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 994, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_flow_dir_d8_2, __pyx_t_2) < 0) __PYX_ERR(0, 994, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1362 - * flow_dir_raster_path_band, target_flow_accum_raster_path, - * weight_raster_path_band=None, - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): # <<<<<<<<<<<<<< - * """D8 flow accumulation. - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1362, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_k__8 = __pyx_t_2; - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1359 - * - * - * def flow_accumulation_d8( # <<<<<<<<<<<<<< - * flow_dir_raster_path_band, target_flow_accum_raster_path, - * weight_raster_path_band=None, - */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_7flow_accumulation_d8, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1359, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_flow_accumulation_d8, __pyx_t_2) < 0) __PYX_ERR(0, 1359, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1584 - * def flow_dir_mfd( - * dem_raster_path_band, target_flow_dir_path, working_dir=None, - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): # <<<<<<<<<<<<<< - * """Multiple flow direction. - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1584, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_k__10 = __pyx_t_2; - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1582 - * - * - * def flow_dir_mfd( # <<<<<<<<<<<<<< - * dem_raster_path_band, target_flow_dir_path, working_dir=None, - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): - */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_9flow_dir_mfd, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1582, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_flow_dir_mfd, __pyx_t_2) < 0) __PYX_ERR(0, 1582, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2076 - * flow_dir_mfd_raster_path_band, target_flow_accum_raster_path, - * weight_raster_path_band=None, - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): # <<<<<<<<<<<<<< - * """Multiple flow direction accumulation. - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2076, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_k__11 = __pyx_t_2; - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2073 - * - * - * def flow_accumulation_mfd( # <<<<<<<<<<<<<< - * flow_dir_mfd_raster_path_band, target_flow_accum_raster_path, - * weight_raster_path_band=None, - */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_11flow_accumulation_mfd, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2073, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_flow_accumulation_mfd, __pyx_t_2) < 0) __PYX_ERR(0, 2073, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2358 - * target_distance_to_channel_raster_path, - * weight_raster_path_band=None, - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): # <<<<<<<<<<<<<< - * """Calculate distance to channel with D8 flow. - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2358, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_k__12 = __pyx_t_2; - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2354 - * - * - * def distance_to_channel_d8( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band, channel_raster_path_band, - * target_distance_to_channel_raster_path, - */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_13distance_to_channel_d8, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2354, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_distance_to_channel_d8, __pyx_t_2) < 0) __PYX_ERR(0, 2354, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2547 - * flow_dir_mfd_raster_path_band, channel_raster_path_band, - * target_distance_to_channel_raster_path, weight_raster_path_band=None, - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): # <<<<<<<<<<<<<< - * """Calculate distance to channel with multiple flow direction. - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2547, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_k__13 = __pyx_t_2; - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2544 - * - * - * 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_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_15distance_to_channel_mfd, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2544, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_distance_to_channel_mfd, __pyx_t_2) < 0) __PYX_ERR(0, 2544, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2815 - * double flow_threshold, target_stream_raster_path, - * double trace_threshold_proportion=1.0, - * raster_driver_creation_tuple=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS): # <<<<<<<<<<<<<< - * """Classify a stream raster from MFD flow accumulation. - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_DEFAULT_GTIFF_CREATION_TUPLE_OPT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2815, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_k__14 = __pyx_t_2; - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":2811 - * - * - * def extract_streams_mfd( # <<<<<<<<<<<<<< - * flow_accum_raster_path_band, flow_dir_mfd_path_band, - * double flow_threshold, target_stream_raster_path, - */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_17extract_streams_mfd, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2811, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_extract_streams_mfd, __pyx_t_2) < 0) __PYX_ERR(0, 2811, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3011 - * - * - * 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_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_19_is_raster_path_band_formatted, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3011, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_is_raster_path_band_formatted, __pyx_t_2) < 0) __PYX_ERR(0, 3011, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3033 - * float min_p_val=0.05, - * autotune_flow_accumulation=False, - * osr_axis_mapping_strategy=DEFAULT_OSR_AXIS_MAPPING_STRATEGY): # <<<<<<<<<<<<<< - * """Extract Strahler order stream geometry from flow accumulation. - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_DEFAULT_OSR_AXIS_MAPPING_STRATEG); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3033, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_k__15 = __pyx_t_2; - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3025 - * - * - * def extract_strahler_streams_d8( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band, flow_accum_raster_path_band, - * dem_raster_path_band, - */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_21extract_strahler_streams_d8, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3025, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_extract_strahler_streams_d8, __pyx_t_2) < 0) __PYX_ERR(0, 3025, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3700 - * - * - * def _build_discovery_finish_rasters( # <<<<<<<<<<<<<< - * flow_dir_d8_raster_path_band, target_discovery_raster_path, - * target_finish_raster_path): - */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_23_build_discovery_finish_rasters, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3700, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_build_discovery_finish_rasters, __pyx_t_2) < 0) __PYX_ERR(0, 3700, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":3830 - * - * - * def calculate_subwatershed_boundary( # <<<<<<<<<<<<<< - * d8_flow_dir_raster_path_band, - * strahler_stream_vector_path, target_watershed_boundary_vector_path, - */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_25calculate_subwatershed_boundary, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3830, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_calculate_subwatershed_boundary_4, __pyx_t_2) < 0) __PYX_ERR(0, 3830, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4162 - * - * - * def detect_outlets( # <<<<<<<<<<<<<< - * flow_dir_raster_path_band, flow_dir_type, target_outlet_vector_path): - * """Create point vector indicating flow raster outlets. - */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_27detect_outlets, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4162, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_detect_outlets, __pyx_t_2) < 0) __PYX_ERR(0, 4162, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":4595 - * - * - * def _delete_feature( # <<<<<<<<<<<<<< - * stream_feature, stream_layer, upstream_to_downstream_id, - * downstream_to_upstream_ids): - */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_29_delete_feature, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4595, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_delete_feature, __pyx_t_2) < 0) __PYX_ERR(0, 4595, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/routing.pyx":1 - * # coding=UTF-8 # <<<<<<<<<<<<<< - * # distutils: language=c++ - * # cython: language_level=3 - */ - __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1016 - * - * - * cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil: # <<<<<<<<<<<<<< - * """ - * returns the unit part of the dtype for a numpy datetime64 object. - */ - - /*--- 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", __pyx_clineno, __pyx_lineno, __pyx_filename); - } - Py_CLEAR(__pyx_m); - } 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(modname); - if (!m) goto end; - p = PyObject_GetAttrString(m, "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_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 - (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(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 - (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(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; -} - -/* PyDictVersioning */ -#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS -static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { - PyObject *dict = Py_TYPE(obj)->tp_dict; - return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0; -} -static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { - PyObject **dictptr = NULL; - Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; - if (offset) { -#if CYTHON_COMPILING_IN_CPYTHON - dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); -#else - dictptr = _PyObject_GetDictPtr(obj); -#endif - } - return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; -} -static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { - PyObject *dict = Py_TYPE(obj)->tp_dict; - if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict))) - return 0; - return obj_dict_version == __Pyx_get_object_dict_version(obj); -} -#endif - -/* GetModuleGlobalName */ -#if CYTHON_USE_DICT_VERSIONS -static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value) -#else -static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name) -#endif -{ - 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); - __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) - if (likely(result)) { - return __Pyx_NewRef(result); - } else if (unlikely(PyErr_Occurred())) { - return NULL; - } -#else - result = PyDict_GetItem(__pyx_d, name); - __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) - if (likely(result)) { - return __Pyx_NewRef(result); - } -#endif -#else - result = PyObject_GetItem(__pyx_d, name); - __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) - if (likely(result)) { - return __Pyx_NewRef(result); - } - PyErr_Clear(); -#endif - return __Pyx_GetBuiltinName(name); -} - -/* 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 | METH_STACKLESS))); - 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)(void*)meth)) (self, args, nargs, NULL); - } else { - return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs); - } -} -#endif - -/* PyFunctionFastCall */ -#if CYTHON_FAST_PYCALL -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 = __Pyx_PyFrame_GetLocalsplus(f); - 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, Py_ssize_t 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, (int)nargs, - k, (int)nk, - d, (int)nd, kwdefs, closure); -#else - result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL, - args, (int)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 - -/* PyObjectCall2Args */ -static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) { - PyObject *args, *result = NULL; - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(function)) { - PyObject *args[2] = {arg1, arg2}; - return __Pyx_PyFunction_FastCall(function, args, 2); - } - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(function)) { - PyObject *args[2] = {arg1, arg2}; - return __Pyx_PyCFunction_FastCall(function, args, 2); - } - #endif - args = PyTuple_New(2); - if (unlikely(!args)) goto done; - Py_INCREF(arg1); - PyTuple_SET_ITEM(args, 0, arg1); - Py_INCREF(arg2); - PyTuple_SET_ITEM(args, 1, arg2); - Py_INCREF(function); - result = __Pyx_PyObject_Call(function, args, NULL); - Py_DECREF(args); - Py_DECREF(function); -done: - return result; -} - -/* 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 (__Pyx_PyFastCFunction_Check(func)) { - 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()) { - if (unlikely(PyTuple_Check(key))) { - PyObject* args = PyTuple_Pack(1, key); - if (likely(args)) { - PyErr_SetObject(PyExc_KeyError, args); - Py_DECREF(args); - } - } else { - PyErr_SetObject(PyExc_KeyError, key); - } - } - 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 - -/* CIntToDigits */ -static const char DIGIT_PAIRS_10[2*10*10+1] = { - "00010203040506070809" - "10111213141516171819" - "20212223242526272829" - "30313233343536373839" - "40414243444546474849" - "50515253545556575859" - "60616263646566676869" - "70717273747576777879" - "80818283848586878889" - "90919293949596979899" -}; -static const char DIGIT_PAIRS_8[2*8*8+1] = { - "0001020304050607" - "1011121314151617" - "2021222324252627" - "3031323334353637" - "4041424344454647" - "5051525354555657" - "6061626364656667" - "7071727374757677" -}; -static const char DIGITS_HEX[2*16+1] = { - "0123456789abcdef" - "0123456789ABCDEF" -}; - -/* BuildPyUnicode */ -static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, char* chars, int clength, - int prepend_sign, char padding_char) { - PyObject *uval; - Py_ssize_t uoffset = ulength - clength; -#if CYTHON_USE_UNICODE_INTERNALS - Py_ssize_t i; -#if CYTHON_PEP393_ENABLED - void *udata; - uval = PyUnicode_New(ulength, 127); - if (unlikely(!uval)) return NULL; - udata = PyUnicode_DATA(uval); -#else - Py_UNICODE *udata; - uval = PyUnicode_FromUnicode(NULL, ulength); - if (unlikely(!uval)) return NULL; - udata = PyUnicode_AS_UNICODE(uval); -#endif - if (uoffset > 0) { - i = 0; - if (prepend_sign) { - __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, 0, '-'); - i++; - } - for (; i < uoffset; i++) { - __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, i, padding_char); - } - } - for (i=0; i < clength; i++) { - __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, uoffset+i, chars[i]); - } -#else - { - PyObject *sign = NULL, *padding = NULL; - uval = NULL; - if (uoffset > 0) { - prepend_sign = !!prepend_sign; - if (uoffset > prepend_sign) { - padding = PyUnicode_FromOrdinal(padding_char); - if (likely(padding) && uoffset > prepend_sign + 1) { - PyObject *tmp; - PyObject *repeat = PyInt_FromSize_t(uoffset - prepend_sign); - if (unlikely(!repeat)) goto done_or_error; - tmp = PyNumber_Multiply(padding, repeat); - Py_DECREF(repeat); - Py_DECREF(padding); - padding = tmp; - } - if (unlikely(!padding)) goto done_or_error; - } - if (prepend_sign) { - sign = PyUnicode_FromOrdinal('-'); - if (unlikely(!sign)) goto done_or_error; - } - } - uval = PyUnicode_DecodeASCII(chars, clength, NULL); - if (likely(uval) && padding) { - PyObject *tmp = PyNumber_Add(padding, uval); - Py_DECREF(uval); - uval = tmp; - } - if (likely(uval) && sign) { - PyObject *tmp = PyNumber_Add(sign, uval); - Py_DECREF(uval); - uval = tmp; - } -done_or_error: - Py_XDECREF(padding); - Py_XDECREF(sign); - } -#endif - return uval; -} - -/* CIntToPyUnicode */ -#ifdef _MSC_VER - #ifndef _MSC_STDINT_H_ - #if _MSC_VER < 1300 - typedef unsigned short uint16_t; - #else - typedef unsigned __int16 uint16_t; - #endif - #endif -#else - #include -#endif -static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_int(int value, Py_ssize_t width, char padding_char, char format_char) { - char digits[sizeof(int)*3+2]; - char *dpos, *end = digits + sizeof(int)*3+2; - const char *hex_digits = DIGITS_HEX; - Py_ssize_t length, ulength; - int prepend_sign, last_one_off; - int remaining; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const int neg_one = (int) -1, const_zero = (int) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - const int is_unsigned = neg_one > const_zero; - if (format_char == 'X') { - hex_digits += 16; - format_char = 'x'; - } - remaining = value; - last_one_off = 0; - dpos = end; - do { - int digit_pos; - switch (format_char) { - case 'o': - digit_pos = abs((int)(remaining % (8*8))); - remaining = (int) (remaining / (8*8)); - dpos -= 2; - *(uint16_t*)dpos = ((const uint16_t*)DIGIT_PAIRS_8)[digit_pos]; - last_one_off = (digit_pos < 8); - break; - case 'd': - digit_pos = abs((int)(remaining % (10*10))); - remaining = (int) (remaining / (10*10)); - dpos -= 2; - *(uint16_t*)dpos = ((const uint16_t*)DIGIT_PAIRS_10)[digit_pos]; - last_one_off = (digit_pos < 10); - break; - case 'x': - *(--dpos) = hex_digits[abs((int)(remaining % 16))]; - remaining = (int) (remaining / 16); - break; - default: - assert(0); - break; - } - } while (unlikely(remaining != 0)); - if (last_one_off) { - assert(*dpos == '0'); - dpos++; - } - length = end - dpos; - ulength = length; - prepend_sign = 0; - if (!is_unsigned && value <= neg_one) { - if (padding_char == ' ' || width <= length + 1) { - *(--dpos) = '-'; - ++length; - } else { - prepend_sign = 1; - } - ++ulength; - } - if (width > ulength) { - ulength = width; - } - if (ulength == 1) { - return PyUnicode_FromOrdinal(*dpos); - } - return __Pyx_PyUnicode_BuildFromAscii(ulength, dpos, (int) length, prepend_sign, padding_char); -} - -/* PyObjectFormatAndDecref */ -static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f) { - if (unlikely(!s)) return NULL; - if (likely(PyUnicode_CheckExact(s))) return s; - #if PY_MAJOR_VERSION < 3 - if (likely(PyString_CheckExact(s))) { - PyObject *result = PyUnicode_FromEncodedObject(s, NULL, "strict"); - Py_DECREF(s); - return result; - } - #endif - return __Pyx_PyObject_FormatAndDecref(s, f); -} -static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f) { - PyObject *result = PyObject_Format(s, f); - Py_DECREF(s); - return result; -} - -/* JoinPyUnicode */ -static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength, - CYTHON_UNUSED Py_UCS4 max_char) { -#if CYTHON_USE_UNICODE_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - PyObject *result_uval; - int result_ukind; - Py_ssize_t i, char_pos; - void *result_udata; -#if CYTHON_PEP393_ENABLED - result_uval = PyUnicode_New(result_ulength, max_char); - if (unlikely(!result_uval)) return NULL; - result_ukind = (max_char <= 255) ? PyUnicode_1BYTE_KIND : (max_char <= 65535) ? PyUnicode_2BYTE_KIND : PyUnicode_4BYTE_KIND; - result_udata = PyUnicode_DATA(result_uval); -#else - result_uval = PyUnicode_FromUnicode(NULL, result_ulength); - if (unlikely(!result_uval)) return NULL; - result_ukind = sizeof(Py_UNICODE); - result_udata = PyUnicode_AS_UNICODE(result_uval); -#endif - char_pos = 0; - for (i=0; i < value_count; i++) { - int ukind; - Py_ssize_t ulength; - void *udata; - PyObject *uval = PyTuple_GET_ITEM(value_tuple, i); - if (unlikely(__Pyx_PyUnicode_READY(uval))) - goto bad; - ulength = __Pyx_PyUnicode_GET_LENGTH(uval); - if (unlikely(!ulength)) - continue; - if (unlikely(char_pos + ulength < 0)) - goto overflow; - ukind = __Pyx_PyUnicode_KIND(uval); - udata = __Pyx_PyUnicode_DATA(uval); - if (!CYTHON_PEP393_ENABLED || ukind == result_ukind) { - memcpy((char *)result_udata + char_pos * result_ukind, udata, (size_t) (ulength * result_ukind)); - } else { - #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030300F0 || defined(_PyUnicode_FastCopyCharacters) - _PyUnicode_FastCopyCharacters(result_uval, char_pos, uval, 0, ulength); - #else - Py_ssize_t j; - for (j=0; j < ulength; j++) { - Py_UCS4 uchar = __Pyx_PyUnicode_READ(ukind, udata, j); - __Pyx_PyUnicode_WRITE(result_ukind, result_udata, char_pos+j, uchar); - } - #endif - } - char_pos += ulength; - } - return result_uval; -overflow: - PyErr_SetString(PyExc_OverflowError, "join() result is too long for a Python string"); -bad: - Py_DECREF(result_uval); - return NULL; -#else - result_ulength++; - value_count++; - return PyUnicode_Join(__pyx_empty_unicode, value_tuple); -#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_CyFunction_Check(func))) -#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 '?': return "'bool'"; - 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 '?': 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 '?': 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, 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; - ndim = ctx->head->field->type->ndim; - 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 '?': 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->is_valid_array)) { - 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((size_t)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(__Pyx_is_valid_index(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(__Pyx_is_valid_index(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(__Pyx_is_valid_index(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(__Pyx_is_valid_index(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!"); -} - -/* PyIntCompare */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED long 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))) { - int unequal; - unsigned long uintval; - Py_ssize_t size = Py_SIZE(op1); - const digit* digits = ((PyLongObject*)op1)->ob_digit; - if (intval == 0) { - if (size == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE; - } else if (intval < 0) { - if (size >= 0) - Py_RETURN_FALSE; - intval = -intval; - size = -size; - } else { - if (size <= 0) - Py_RETURN_FALSE; - } - uintval = (unsigned long) intval; -#if PyLong_SHIFT * 4 < SIZEOF_LONG*8 - if (uintval >> (PyLong_SHIFT * 4)) { - unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) - | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); - } else -#endif -#if PyLong_SHIFT * 3 < SIZEOF_LONG*8 - if (uintval >> (PyLong_SHIFT * 3)) { - unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) - | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); - } else -#endif -#if PyLong_SHIFT * 2 < SIZEOF_LONG*8 - if (uintval >> (PyLong_SHIFT * 2)) { - unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) - | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); - } else -#endif -#if PyLong_SHIFT * 1 < SIZEOF_LONG*8 - if (uintval >> (PyLong_SHIFT * 1)) { - unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) - | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); - } else -#endif - unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK)); - if (unequal == 0) 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)); -} - -/* PyIntBinop */ - #if !CYTHON_COMPILING_IN_PYPY -static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) { - (void)inplace; - (void)zerodivision_check; - #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 - -/* None */ - static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) { - PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname); -} - -/* PyIntBinop */ - #if !CYTHON_COMPILING_IN_PYPY -static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) { - (void)inplace; - (void)zerodivision_check; - #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 - -/* GetTopmostException */ - #if CYTHON_USE_EXC_INFO_STACK -static _PyErr_StackItem * -__Pyx_PyErr_GetTopmostException(PyThreadState *tstate) -{ - _PyErr_StackItem *exc_info = tstate->exc_info; - while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) && - exc_info->previous_item != NULL) - { - exc_info = exc_info->previous_item; - } - return exc_info; -} -#endif - -/* SaveResetException */ - #if CYTHON_FAST_THREAD_STATE -static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { - #if CYTHON_USE_EXC_INFO_STACK - _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate); - *type = exc_info->exc_type; - *value = exc_info->exc_value; - *tb = exc_info->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 CYTHON_USE_EXC_INFO_STACK - _PyErr_StackItem *exc_info = tstate->exc_info; - tmp_type = exc_info->exc_type; - tmp_value = exc_info->exc_value; - tmp_tb = exc_info->exc_traceback; - exc_info->exc_type = type; - exc_info->exc_value = value; - exc_info->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; icurexc_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 - -/* PyIntCompare */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_NeObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED long inplace) { - if (op1 == op2) { - Py_RETURN_FALSE; - } - #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))) { - int unequal; - unsigned long uintval; - Py_ssize_t size = Py_SIZE(op1); - const digit* digits = ((PyLongObject*)op1)->ob_digit; - if (intval == 0) { - if (size != 0) Py_RETURN_TRUE; else Py_RETURN_FALSE; - } else if (intval < 0) { - if (size >= 0) - Py_RETURN_TRUE; - intval = -intval; - size = -size; - } else { - if (size <= 0) - Py_RETURN_TRUE; - } - uintval = (unsigned long) intval; -#if PyLong_SHIFT * 4 < SIZEOF_LONG*8 - if (uintval >> (PyLong_SHIFT * 4)) { - unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) - | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); - } else -#endif -#if PyLong_SHIFT * 3 < SIZEOF_LONG*8 - if (uintval >> (PyLong_SHIFT * 3)) { - unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) - | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); - } else -#endif -#if PyLong_SHIFT * 2 < SIZEOF_LONG*8 - if (uintval >> (PyLong_SHIFT * 2)) { - unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) - | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); - } else -#endif -#if PyLong_SHIFT * 1 < SIZEOF_LONG*8 - if (uintval >> (PyLong_SHIFT * 1)) { - unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) - | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); - } else -#endif - unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK)); - if (unequal != 0) 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_NE)); -} - -/* 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 CYTHON_USE_EXC_INFO_STACK - { - _PyErr_StackItem *exc_info = tstate->exc_info; - tmp_type = exc_info->exc_type; - tmp_value = exc_info->exc_value; - tmp_tb = exc_info->exc_traceback; - exc_info->exc_type = local_type; - exc_info->exc_value = local_value; - exc_info->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; -} - -/* 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; -} - -/* CIntToPyUnicode */ - #ifdef _MSC_VER - #ifndef _MSC_STDINT_H_ - #if _MSC_VER < 1300 - typedef unsigned short uint16_t; - #else - typedef unsigned __int16 uint16_t; - #endif - #endif -#else - #include -#endif -static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_long(long value, Py_ssize_t width, char padding_char, char format_char) { - char digits[sizeof(long)*3+2]; - char *dpos, *end = digits + sizeof(long)*3+2; - const char *hex_digits = DIGITS_HEX; - Py_ssize_t length, ulength; - int prepend_sign, last_one_off; - long remaining; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const long neg_one = (long) -1, const_zero = (long) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - const int is_unsigned = neg_one > const_zero; - if (format_char == 'X') { - hex_digits += 16; - format_char = 'x'; - } - remaining = value; - last_one_off = 0; - dpos = end; - do { - int digit_pos; - switch (format_char) { - case 'o': - digit_pos = abs((int)(remaining % (8*8))); - remaining = (long) (remaining / (8*8)); - dpos -= 2; - *(uint16_t*)dpos = ((const uint16_t*)DIGIT_PAIRS_8)[digit_pos]; - last_one_off = (digit_pos < 8); - break; - case 'd': - digit_pos = abs((int)(remaining % (10*10))); - remaining = (long) (remaining / (10*10)); - dpos -= 2; - *(uint16_t*)dpos = ((const uint16_t*)DIGIT_PAIRS_10)[digit_pos]; - last_one_off = (digit_pos < 10); - break; - case 'x': - *(--dpos) = hex_digits[abs((int)(remaining % 16))]; - remaining = (long) (remaining / 16); - break; - default: - assert(0); - break; - } - } while (unlikely(remaining != 0)); - if (last_one_off) { - assert(*dpos == '0'); - dpos++; - } - length = end - dpos; - ulength = length; - prepend_sign = 0; - if (!is_unsigned && value <= neg_one) { - if (padding_char == ' ' || width <= length + 1) { - *(--dpos) = '-'; - ++length; - } else { - prepend_sign = 1; - } - ++ulength; - } - if (width > ulength) { - ulength = width; - } - if (ulength == 1) { - return PyUnicode_FromOrdinal(*dpos); - } - return __Pyx_PyUnicode_BuildFromAscii(ulength, dpos, (int) length, prepend_sign, padding_char); -} - -/* PyObjectGetMethod */ - static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) { - PyObject *attr; -#if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP - PyTypeObject *tp = Py_TYPE(obj); - PyObject *descr; - descrgetfunc f = NULL; - PyObject **dictptr, *dict; - int meth_found = 0; - assert (*method == NULL); - if (unlikely(tp->tp_getattro != PyObject_GenericGetAttr)) { - attr = __Pyx_PyObject_GetAttrStr(obj, name); - goto try_unpack; - } - if (unlikely(tp->tp_dict == NULL) && unlikely(PyType_Ready(tp) < 0)) { - return 0; - } - descr = _PyType_Lookup(tp, name); - if (likely(descr != NULL)) { - Py_INCREF(descr); -#if PY_MAJOR_VERSION >= 3 - #ifdef __Pyx_CyFunction_USED - if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type) || __Pyx_CyFunction_Check(descr))) - #else - if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type))) - #endif -#else - #ifdef __Pyx_CyFunction_USED - if (likely(PyFunction_Check(descr) || __Pyx_CyFunction_Check(descr))) - #else - if (likely(PyFunction_Check(descr))) - #endif -#endif - { - meth_found = 1; - } else { - f = Py_TYPE(descr)->tp_descr_get; - if (f != NULL && PyDescr_IsData(descr)) { - attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); - Py_DECREF(descr); - goto try_unpack; - } - } - } - dictptr = _PyObject_GetDictPtr(obj); - if (dictptr != NULL && (dict = *dictptr) != NULL) { - Py_INCREF(dict); - attr = __Pyx_PyDict_GetItemStr(dict, name); - if (attr != NULL) { - Py_INCREF(attr); - Py_DECREF(dict); - Py_XDECREF(descr); - goto try_unpack; - } - Py_DECREF(dict); - } - if (meth_found) { - *method = descr; - return 1; - } - if (f != NULL) { - attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); - Py_DECREF(descr); - goto try_unpack; - } - if (descr != NULL) { - *method = descr; - return 0; - } - PyErr_Format(PyExc_AttributeError, -#if PY_MAJOR_VERSION >= 3 - "'%.50s' object has no attribute '%U'", - tp->tp_name, name); -#else - "'%.50s' object has no attribute '%.400s'", - tp->tp_name, PyString_AS_STRING(name)); -#endif - return 0; -#else - attr = __Pyx_PyObject_GetAttrStr(obj, name); - goto try_unpack; -#endif -try_unpack: -#if CYTHON_UNPACK_METHODS - if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) { - PyObject *function = PyMethod_GET_FUNCTION(attr); - Py_INCREF(function); - Py_DECREF(attr); - *method = function; - return 1; - } -#endif - *method = attr; - return 0; -} - -/* PyObjectCallMethod1 */ - static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) { - PyObject *result = __Pyx_PyObject_CallOneArg(method, arg); - Py_DECREF(method); - return result; -} -static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) { - PyObject *method = NULL, *result; - int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); - if (likely(is_method)) { - result = __Pyx_PyObject_Call2Args(method, obj, arg); - Py_DECREF(method); - return result; - } - if (unlikely(!method)) return NULL; - return __Pyx__PyObject_CallMethod1(method, arg); -} - -/* append */ - static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x) { - if (likely(PyList_CheckExact(L))) { - if (unlikely(__Pyx_PyList_Append(L, x) < 0)) return -1; - } else { - PyObject* retval = __Pyx_PyObject_CallMethod1(L, __pyx_n_s_append, x); - if (unlikely(!retval)) - return -1; - Py_DECREF(retval); - } - return 0; -} - -/* pop_index */ - static PyObject* __Pyx__PyObject_PopNewIndex(PyObject* L, PyObject* py_ix) { - PyObject *r; - if (unlikely(!py_ix)) return NULL; - r = __Pyx__PyObject_PopIndex(L, py_ix); - Py_DECREF(py_ix); - return r; -} -static PyObject* __Pyx__PyObject_PopIndex(PyObject* L, PyObject* py_ix) { - return __Pyx_PyObject_CallMethod1(L, __pyx_n_s_pop, py_ix); -} -#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS -static PyObject* __Pyx__PyList_PopIndex(PyObject* L, PyObject* py_ix, Py_ssize_t ix) { - Py_ssize_t size = PyList_GET_SIZE(L); - if (likely(size > (((PyListObject*)L)->allocated >> 1))) { - Py_ssize_t cix = ix; - if (cix < 0) { - cix += size; - } - if (likely(__Pyx_is_valid_index(cix, size))) { - PyObject* v = PyList_GET_ITEM(L, cix); - __Pyx_SET_SIZE(L, Py_SIZE(L) - 1); - size -= 1; - memmove(&PyList_GET_ITEM(L, cix), &PyList_GET_ITEM(L, cix+1), (size_t)(size-cix)*sizeof(PyObject*)); - return v; - } - } - if (py_ix == Py_None) { - return __Pyx__PyObject_PopNewIndex(L, PyInt_FromSsize_t(ix)); - } else { - return __Pyx__PyObject_PopIndex(L, py_ix); - } -} -#endif - -/* CIntToPyUnicode */ - #ifdef _MSC_VER - #ifndef _MSC_STDINT_H_ - #if _MSC_VER < 1300 - typedef unsigned short uint16_t; - #else - typedef unsigned __int16 uint16_t; - #endif - #endif -#else - #include -#endif -static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_Py_ssize_t(Py_ssize_t value, Py_ssize_t width, char padding_char, char format_char) { - char digits[sizeof(Py_ssize_t)*3+2]; - char *dpos, *end = digits + sizeof(Py_ssize_t)*3+2; - const char *hex_digits = DIGITS_HEX; - Py_ssize_t length, ulength; - int prepend_sign, last_one_off; - Py_ssize_t remaining; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const Py_ssize_t neg_one = (Py_ssize_t) -1, const_zero = (Py_ssize_t) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - const int is_unsigned = neg_one > const_zero; - if (format_char == 'X') { - hex_digits += 16; - format_char = 'x'; - } - remaining = value; - last_one_off = 0; - dpos = end; - do { - int digit_pos; - switch (format_char) { - case 'o': - digit_pos = abs((int)(remaining % (8*8))); - remaining = (Py_ssize_t) (remaining / (8*8)); - dpos -= 2; - *(uint16_t*)dpos = ((const uint16_t*)DIGIT_PAIRS_8)[digit_pos]; - last_one_off = (digit_pos < 8); - break; - case 'd': - digit_pos = abs((int)(remaining % (10*10))); - remaining = (Py_ssize_t) (remaining / (10*10)); - dpos -= 2; - *(uint16_t*)dpos = ((const uint16_t*)DIGIT_PAIRS_10)[digit_pos]; - last_one_off = (digit_pos < 10); - break; - case 'x': - *(--dpos) = hex_digits[abs((int)(remaining % 16))]; - remaining = (Py_ssize_t) (remaining / 16); - break; - default: - assert(0); - break; - } - } while (unlikely(remaining != 0)); - if (last_one_off) { - assert(*dpos == '0'); - dpos++; - } - length = end - dpos; - ulength = length; - prepend_sign = 0; - if (!is_unsigned && value <= neg_one) { - if (padding_char == ' ' || width <= length + 1) { - *(--dpos) = '-'; - ++length; - } else { - prepend_sign = 1; - } - ++ulength; - } - if (width > ulength) { - ulength = width; - } - if (ulength == 1) { - return PyUnicode_FromOrdinal(*dpos); - } - return __Pyx_PyUnicode_BuildFromAscii(ulength, dpos, (int) length, prepend_sign, padding_char); -} - -/* PyObjectCallMethod0 */ - static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) { - PyObject *method = NULL, *result = NULL; - int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); - if (likely(is_method)) { - result = __Pyx_PyObject_CallOneArg(method, obj); - Py_DECREF(method); - return result; - } - if (unlikely(!method)) goto bad; - result = __Pyx_PyObject_CallNoArg(method); - Py_DECREF(method); -bad: - return result; -} - -/* UnpackUnboundCMethod */ - static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) { - PyObject *method; - method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name); - if (unlikely(!method)) - return -1; - target->method = method; -#if CYTHON_COMPILING_IN_CPYTHON - #if PY_MAJOR_VERSION >= 3 - if (likely(__Pyx_TypeCheck(method, &PyMethodDescr_Type))) - #endif - { - PyMethodDescrObject *descr = (PyMethodDescrObject*) method; - target->func = descr->d_method->ml_meth; - target->flag = descr->d_method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS); - } -#endif - return 0; -} - -/* CallUnboundCMethod0 */ - static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self) { - PyObject *args, *result = NULL; - if (unlikely(!cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL; -#if CYTHON_ASSUME_SAFE_MACROS - args = PyTuple_New(1); - if (unlikely(!args)) goto bad; - Py_INCREF(self); - PyTuple_SET_ITEM(args, 0, self); -#else - args = PyTuple_Pack(1, self); - if (unlikely(!args)) goto bad; -#endif - result = __Pyx_PyObject_Call(cfunc->method, args, NULL); - Py_DECREF(args); -bad: - return result; -} - -/* pop */ - static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L) { - if (Py_TYPE(L) == &PySet_Type) { - return PySet_Pop(L); - } - return __Pyx_PyObject_CallMethod0(L, __pyx_n_s_pop); -} -#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS -static CYTHON_INLINE PyObject* __Pyx_PyList_Pop(PyObject* L) { - if (likely(PyList_GET_SIZE(L) > (((PyListObject*)L)->allocated >> 1))) { - __Pyx_SET_SIZE(L, Py_SIZE(L) - 1); - return PyList_GET_ITEM(L, PyList_GET_SIZE(L)); - } - return __Pyx_CallUnboundCMethod0(&__pyx_umethod_PyList_Type_pop, L); -} -#endif - -/* RaiseNoneIterError */ - static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); -} - -/* UnpackTupleError */ - static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) { - if (t == Py_None) { - __Pyx_RaiseNoneNotIterableError(); - } else if (PyTuple_GET_SIZE(t) < index) { - __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(t)); - } else { - __Pyx_RaiseTooManyValuesError(index); - } -} - -/* UnpackTuple2 */ - static CYTHON_INLINE int __Pyx_unpack_tuple2_exact( - PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2, int decref_tuple) { - PyObject *value1 = NULL, *value2 = NULL; -#if CYTHON_COMPILING_IN_PYPY - value1 = PySequence_ITEM(tuple, 0); if (unlikely(!value1)) goto bad; - value2 = PySequence_ITEM(tuple, 1); if (unlikely(!value2)) goto bad; -#else - value1 = PyTuple_GET_ITEM(tuple, 0); Py_INCREF(value1); - value2 = PyTuple_GET_ITEM(tuple, 1); Py_INCREF(value2); -#endif - if (decref_tuple) { - Py_DECREF(tuple); - } - *pvalue1 = value1; - *pvalue2 = value2; - return 0; -#if CYTHON_COMPILING_IN_PYPY -bad: - Py_XDECREF(value1); - Py_XDECREF(value2); - if (decref_tuple) { Py_XDECREF(tuple); } - return -1; -#endif -} -static int __Pyx_unpack_tuple2_generic(PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2, - int has_known_size, int decref_tuple) { - Py_ssize_t index; - PyObject *value1 = NULL, *value2 = NULL, *iter = NULL; - iternextfunc iternext; - iter = PyObject_GetIter(tuple); - if (unlikely(!iter)) goto bad; - if (decref_tuple) { Py_DECREF(tuple); tuple = NULL; } - iternext = Py_TYPE(iter)->tp_iternext; - value1 = iternext(iter); if (unlikely(!value1)) { index = 0; goto unpacking_failed; } - value2 = iternext(iter); if (unlikely(!value2)) { index = 1; goto unpacking_failed; } - if (!has_known_size && unlikely(__Pyx_IternextUnpackEndCheck(iternext(iter), 2))) goto bad; - Py_DECREF(iter); - *pvalue1 = value1; - *pvalue2 = value2; - return 0; -unpacking_failed: - if (!has_known_size && __Pyx_IterFinish() == 0) - __Pyx_RaiseNeedMoreValuesError(index); -bad: - Py_XDECREF(iter); - Py_XDECREF(value1); - Py_XDECREF(value2); - if (decref_tuple) { Py_XDECREF(tuple); } - return -1; -} - -/* dict_iter */ - static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_dict, PyObject* method_name, - Py_ssize_t* p_orig_length, int* p_source_is_dict) { - is_dict = is_dict || likely(PyDict_CheckExact(iterable)); - *p_source_is_dict = is_dict; - if (is_dict) { -#if !CYTHON_COMPILING_IN_PYPY - *p_orig_length = PyDict_Size(iterable); - Py_INCREF(iterable); - return iterable; -#elif PY_MAJOR_VERSION >= 3 - static PyObject *py_items = NULL, *py_keys = NULL, *py_values = NULL; - PyObject **pp = NULL; - if (method_name) { - const char *name = PyUnicode_AsUTF8(method_name); - if (strcmp(name, "iteritems") == 0) pp = &py_items; - else if (strcmp(name, "iterkeys") == 0) pp = &py_keys; - else if (strcmp(name, "itervalues") == 0) pp = &py_values; - if (pp) { - if (!*pp) { - *pp = PyUnicode_FromString(name + 4); - if (!*pp) - return NULL; - } - method_name = *pp; - } - } -#endif - } - *p_orig_length = 0; - if (method_name) { - PyObject* iter; - iterable = __Pyx_PyObject_CallMethod0(iterable, method_name); - if (!iterable) - return NULL; -#if !CYTHON_COMPILING_IN_PYPY - if (PyTuple_CheckExact(iterable) || PyList_CheckExact(iterable)) - return iterable; -#endif - iter = PyObject_GetIter(iterable); - Py_DECREF(iterable); - return iter; - } - return PyObject_GetIter(iterable); -} -static CYTHON_INLINE int __Pyx_dict_iter_next( - PyObject* iter_obj, CYTHON_NCP_UNUSED Py_ssize_t orig_length, CYTHON_NCP_UNUSED Py_ssize_t* ppos, - PyObject** pkey, PyObject** pvalue, PyObject** pitem, int source_is_dict) { - PyObject* next_item; -#if !CYTHON_COMPILING_IN_PYPY - if (source_is_dict) { - PyObject *key, *value; - if (unlikely(orig_length != PyDict_Size(iter_obj))) { - PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration"); - return -1; - } - if (unlikely(!PyDict_Next(iter_obj, ppos, &key, &value))) { - return 0; - } - if (pitem) { - PyObject* tuple = PyTuple_New(2); - if (unlikely(!tuple)) { - return -1; - } - Py_INCREF(key); - Py_INCREF(value); - PyTuple_SET_ITEM(tuple, 0, key); - PyTuple_SET_ITEM(tuple, 1, value); - *pitem = tuple; - } else { - if (pkey) { - Py_INCREF(key); - *pkey = key; - } - if (pvalue) { - Py_INCREF(value); - *pvalue = value; - } - } - return 1; - } else if (PyTuple_CheckExact(iter_obj)) { - Py_ssize_t pos = *ppos; - if (unlikely(pos >= PyTuple_GET_SIZE(iter_obj))) return 0; - *ppos = pos + 1; - next_item = PyTuple_GET_ITEM(iter_obj, pos); - Py_INCREF(next_item); - } else if (PyList_CheckExact(iter_obj)) { - Py_ssize_t pos = *ppos; - if (unlikely(pos >= PyList_GET_SIZE(iter_obj))) return 0; - *ppos = pos + 1; - next_item = PyList_GET_ITEM(iter_obj, pos); - Py_INCREF(next_item); - } else -#endif - { - next_item = PyIter_Next(iter_obj); - if (unlikely(!next_item)) { - return __Pyx_IterFinish(); - } - } - if (pitem) { - *pitem = next_item; - } else if (pkey && pvalue) { - if (__Pyx_unpack_tuple2(next_item, pkey, pvalue, source_is_dict, source_is_dict, 1)) - return -1; - } else if (pkey) { - *pkey = next_item; - } else { - *pvalue = next_item; - } - return 1; -} - -/* PyObjectFormat */ - #if CYTHON_USE_UNICODE_WRITER -static PyObject* __Pyx_PyObject_Format(PyObject* obj, PyObject* format_spec) { - int ret; - _PyUnicodeWriter writer; - if (likely(PyFloat_CheckExact(obj))) { -#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x03040000 - _PyUnicodeWriter_Init(&writer, 0); -#else - _PyUnicodeWriter_Init(&writer); -#endif - ret = _PyFloat_FormatAdvancedWriter( - &writer, - obj, - format_spec, 0, PyUnicode_GET_LENGTH(format_spec)); - } else if (likely(PyLong_CheckExact(obj))) { -#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x03040000 - _PyUnicodeWriter_Init(&writer, 0); -#else - _PyUnicodeWriter_Init(&writer); -#endif - ret = _PyLong_FormatAdvancedWriter( - &writer, - obj, - format_spec, 0, PyUnicode_GET_LENGTH(format_spec)); - } else { - return PyObject_Format(obj, format_spec); - } - if (unlikely(ret == -1)) { - _PyUnicodeWriter_Dealloc(&writer); - return NULL; - } - return _PyUnicodeWriter_Finish(&writer); -} -#endif - -/* pyfrozenset_new */ - static CYTHON_INLINE PyObject* __Pyx_PyFrozenSet_New(PyObject* it) { - if (it) { - PyObject* result; -#if CYTHON_COMPILING_IN_PYPY - PyObject* args; - args = PyTuple_Pack(1, it); - if (unlikely(!args)) - return NULL; - result = PyObject_Call((PyObject*)&PyFrozenSet_Type, args, NULL); - Py_DECREF(args); - return result; -#else - if (PyFrozenSet_CheckExact(it)) { - Py_INCREF(it); - return it; - } - result = PyFrozenSet_New(it); - if (unlikely(!result)) - return NULL; - if ((PY_VERSION_HEX >= 0x031000A1) || likely(PySet_GET_SIZE(result))) - return result; - Py_DECREF(result); -#endif - } -#if CYTHON_USE_TYPE_SLOTS - return PyFrozenSet_Type.tp_new(&PyFrozenSet_Type, __pyx_empty_tuple, NULL); -#else - return PyObject_Call((PyObject*)&PyFrozenSet_Type, __pyx_empty_tuple, NULL); -#endif -} - -/* PySetContains */ - static int __Pyx_PySet_ContainsUnhashable(PyObject *set, PyObject *key) { - int result = -1; - if (PySet_Check(key) && PyErr_ExceptionMatches(PyExc_TypeError)) { - PyObject *tmpkey; - PyErr_Clear(); - tmpkey = __Pyx_PyFrozenSet_New(key); - if (tmpkey != NULL) { - result = PySet_Contains(set, tmpkey); - Py_DECREF(tmpkey); - } - } - return result; -} -static CYTHON_INLINE int __Pyx_PySet_ContainsTF(PyObject* key, PyObject* set, int eq) { - int result = PySet_Contains(set, key); - if (unlikely(result < 0)) { - result = __Pyx_PySet_ContainsUnhashable(set, key); - } - return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); -} - -/* BytesEquals */ - static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) { -#if CYTHON_COMPILING_IN_PYPY - return PyObject_RichCompareBool(s1, s2, equals); -#else - if (s1 == s2) { - return (equals == Py_EQ); - } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) { - const char *ps1, *ps2; - Py_ssize_t length = PyBytes_GET_SIZE(s1); - if (length != PyBytes_GET_SIZE(s2)) - return (equals == Py_NE); - ps1 = PyBytes_AS_STRING(s1); - ps2 = PyBytes_AS_STRING(s2); - if (ps1[0] != ps2[0]) { - return (equals == Py_NE); - } else if (length == 1) { - return (equals == Py_EQ); - } else { - int result; -#if CYTHON_USE_UNICODE_INTERNALS - Py_hash_t hash1, hash2; - hash1 = ((PyBytesObject*)s1)->ob_shash; - hash2 = ((PyBytesObject*)s2)->ob_shash; - if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { - return (equals == Py_NE); - } -#endif - result = memcmp(ps1, ps2, (size_t)length); - return (equals == Py_EQ) ? (result == 0) : (result != 0); - } - } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) { - return (equals == Py_NE); - } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) { - return (equals == Py_NE); - } else { - int result; - PyObject* py_result = PyObject_RichCompare(s1, s2, equals); - if (!py_result) - return -1; - result = __Pyx_PyObject_IsTrue(py_result); - Py_DECREF(py_result); - return result; - } -#endif -} - -/* UnicodeEquals */ - static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) { -#if CYTHON_COMPILING_IN_PYPY - return PyObject_RichCompareBool(s1, s2, equals); -#else -#if PY_MAJOR_VERSION < 3 - PyObject* owned_ref = NULL; -#endif - int s1_is_unicode, s2_is_unicode; - if (s1 == s2) { - goto return_eq; - } - s1_is_unicode = PyUnicode_CheckExact(s1); - s2_is_unicode = PyUnicode_CheckExact(s2); -#if PY_MAJOR_VERSION < 3 - if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) { - owned_ref = PyUnicode_FromObject(s2); - if (unlikely(!owned_ref)) - return -1; - s2 = owned_ref; - s2_is_unicode = 1; - } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) { - owned_ref = PyUnicode_FromObject(s1); - if (unlikely(!owned_ref)) - return -1; - s1 = owned_ref; - s1_is_unicode = 1; - } else if (((!s2_is_unicode) & (!s1_is_unicode))) { - return __Pyx_PyBytes_Equals(s1, s2, equals); - } -#endif - if (s1_is_unicode & s2_is_unicode) { - Py_ssize_t length; - int kind; - void *data1, *data2; - if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0)) - return -1; - length = __Pyx_PyUnicode_GET_LENGTH(s1); - if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) { - goto return_ne; - } -#if CYTHON_USE_UNICODE_INTERNALS - { - Py_hash_t hash1, hash2; - #if CYTHON_PEP393_ENABLED - hash1 = ((PyASCIIObject*)s1)->hash; - hash2 = ((PyASCIIObject*)s2)->hash; - #else - hash1 = ((PyUnicodeObject*)s1)->hash; - hash2 = ((PyUnicodeObject*)s2)->hash; - #endif - if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { - goto return_ne; - } - } -#endif - kind = __Pyx_PyUnicode_KIND(s1); - if (kind != __Pyx_PyUnicode_KIND(s2)) { - goto return_ne; - } - data1 = __Pyx_PyUnicode_DATA(s1); - data2 = __Pyx_PyUnicode_DATA(s2); - if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) { - goto return_ne; - } else if (length == 1) { - goto return_eq; - } else { - int result = memcmp(data1, data2, (size_t)(length * kind)); - #if PY_MAJOR_VERSION < 3 - Py_XDECREF(owned_ref); - #endif - return (equals == Py_EQ) ? (result == 0) : (result != 0); - } - } else if ((s1 == Py_None) & s2_is_unicode) { - goto return_ne; - } else if ((s2 == Py_None) & s1_is_unicode) { - goto return_ne; - } else { - int result; - PyObject* py_result = PyObject_RichCompare(s1, s2, equals); - #if PY_MAJOR_VERSION < 3 - Py_XDECREF(owned_ref); - #endif - if (!py_result) - return -1; - result = __Pyx_PyObject_IsTrue(py_result); - Py_DECREF(py_result); - return result; - } -return_eq: - #if PY_MAJOR_VERSION < 3 - Py_XDECREF(owned_ref); - #endif - return (equals == Py_EQ); -return_ne: - #if PY_MAJOR_VERSION < 3 - Py_XDECREF(owned_ref); - #endif - return (equals == Py_NE); -#endif -} - -/* 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; -} - -/* PyObjectGetAttrStrNoError */ - static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) - __Pyx_PyErr_Clear(); -} -static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) { - PyObject *result; -#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1 - PyTypeObject* tp = Py_TYPE(obj); - if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) { - return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1); - } -#endif - result = __Pyx_PyObject_GetAttrStr(obj, attr_name); - if (unlikely(!result)) { - __Pyx_PyObject_GetAttrStr_ClearAttributeError(); - } - return result; -} - -/* 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 __PYX_GOOD; -#else - if (PyObject_HasAttr(type_obj, __pyx_n_s_getstate)) goto __PYX_GOOD; -#endif -#if CYTHON_USE_PYTYPE_LOOKUP - object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; -#else - object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; -#endif - reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto __PYX_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 __PYX_BAD; -#else - object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD; -#endif - reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto __PYX_BAD; - if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) { - reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_reduce_cython); - if (likely(reduce_cython)) { - ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; - ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; - } else if (reduce == object_reduce || PyErr_Occurred()) { - goto __PYX_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_GetAttrStrNoError(type_obj, __pyx_n_s_setstate_cython); - if (likely(setstate_cython)) { - ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; - ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; - } else if (!setstate || PyErr_Occurred()) { - goto __PYX_BAD; - } - } - PyType_Modified((PyTypeObject*)type_obj); - } - } - goto __PYX_GOOD; -__PYX_BAD: - if (!PyErr_Occurred()) - PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name); - ret = -1; -__PYX_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; -} - -/* TypeImport */ - #ifndef __PYX_HAVE_RT_ImportType -#define __PYX_HAVE_RT_ImportType -static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name, - size_t size, enum __Pyx_ImportType_CheckSize check_size) -{ - PyObject *result = 0; - char warning[200]; - Py_ssize_t basicsize; -#ifdef Py_LIMITED_API - PyObject *py_basicsize; -#endif - result = PyObject_GetAttrString(module, class_name); - 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 ((size_t)basicsize < size) { - PyErr_Format(PyExc_ValueError, - "%.200s.%.200s size changed, may indicate binary incompatibility. " - "Expected %zd from C header, got %zd from PyObject", - module_name, class_name, size, basicsize); - goto bad; - } - if (check_size == __Pyx_ImportType_CheckSize_Error && (size_t)basicsize != size) { - PyErr_Format(PyExc_ValueError, - "%.200s.%.200s size changed, may indicate binary incompatibility. " - "Expected %zd from C header, got %zd from PyObject", - module_name, class_name, size, basicsize); - goto bad; - } - else if (check_size == __Pyx_ImportType_CheckSize_Warn && (size_t)basicsize > size) { - PyOS_snprintf(warning, sizeof(warning), - "%s.%s size changed, may indicate binary incompatibility. " - "Expected %zd from C header, got %zd from PyObject", - module_name, class_name, size, basicsize); - if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad; - } - return (PyTypeObject *)result; -bad: - Py_XDECREF(result); - return NULL; -} -#endif - -/* 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 ((1) && (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, (PyObject *)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_NCP_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)) { - __PYX_PY_DICT_LOOKUP_IF_MODIFIED( - use_cline, *cython_runtime_dict, - __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 (use_cline == Py_False || (use_cline != Py_True && 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); - 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)) {} - view->obj = NULL; - Py_DECREF(obj); -} -#endif - - - /* 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;\ - } - -/* 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 = (float)(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 = (float)(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: - 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.0, -1.0); - } - } 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 = (double)(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 = (double)(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: - 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.0, -1.0); - } - } 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_long(long value) { -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const long neg_one = (long) -1, const_zero = (long) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - 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); - } -} - -/* CIntFromPy */ - static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const long neg_one = (long) -1, const_zero = (long) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - 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; -} - -/* CIntFromPy */ - static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const int neg_one = (int) -1, const_zero = (int) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - 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; -} - -/* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const int neg_one = (int) -1, const_zero = (int) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - 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); - } -} - -/* CIntFromPy */ - static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *x) { -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const size_t neg_one = (size_t) -1, const_zero = (size_t) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - 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; -} - -/* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_PY_LONG_LONG(PY_LONG_LONG value) { -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const PY_LONG_LONG neg_one = (PY_LONG_LONG) -1, const_zero = (PY_LONG_LONG) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - const int is_unsigned = neg_one > const_zero; - if (is_unsigned) { - if (sizeof(PY_LONG_LONG) < sizeof(long)) { - return PyInt_FromLong((long) value); - } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned long)) { - return PyLong_FromUnsignedLong((unsigned long) value); -#ifdef HAVE_LONG_LONG - } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) { - return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); -#endif - } - } else { - if (sizeof(PY_LONG_LONG) <= sizeof(long)) { - return PyInt_FromLong((long) value); -#ifdef HAVE_LONG_LONG - } else if (sizeof(PY_LONG_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(PY_LONG_LONG), - little, !is_unsigned); - } -} - -/* 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 int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { - Py_ssize_t i, n; - assert(PyExceptionClass_Check(exc_type)); - n = PyTuple_GET_SIZE(tuple); -#if PY_MAJOR_VERSION >= 3 - for (i=0; ip) { - #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 CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) { - int retval; - if (unlikely(!x)) return -1; - retval = __Pyx_PyObject_IsTrue(x); - Py_DECREF(x); - return retval; -} -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(b); - } -#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 */ diff --git a/src/pygeoprocessing/routing/watershed.cpp b/src/pygeoprocessing/routing/watershed.cpp deleted file mode 100644 index 0cefd5c4..00000000 --- a/src/pygeoprocessing/routing/watershed.cpp +++ /dev/null @@ -1,21754 +0,0 @@ -/* Generated by Cython 0.29.23 */ - -#ifndef PY_SSIZE_T_CLEAN -#define PY_SSIZE_T_CLEAN -#endif /* 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_29_23" -#define CYTHON_HEX_VERSION 0x001D17F0 -#define CYTHON_FUTURE_DIVISION 1 -#include -#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 - #undef CYTHON_USE_DICT_VERSIONS - #define CYTHON_USE_DICT_VERSIONS 0 - #undef CYTHON_USE_EXC_INFO_STACK - #define CYTHON_USE_EXC_INFO_STACK 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 - #undef CYTHON_USE_DICT_VERSIONS - #define CYTHON_USE_DICT_VERSIONS 0 - #undef CYTHON_USE_EXC_INFO_STACK - #define CYTHON_USE_EXC_INFO_STACK 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 (PY_VERSION_HEX >= 0x03050000) - #endif - #ifndef CYTHON_USE_TP_FINALIZE - #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1) - #endif - #ifndef CYTHON_USE_DICT_VERSIONS - #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1) - #endif - #ifndef CYTHON_USE_EXC_INFO_STACK - #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3) - #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 - #ifdef SIZEOF_VOID_P - enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) }; - #endif -#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 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 -#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 -void __Pyx_call_destructor(T& x) { - x.~T(); -} -template -class __Pyx_FakeReference { - public: - __Pyx_FakeReference() : ptr(NULL) { } - __Pyx_FakeReference(const T& ref) : ptr(const_cast(&ref)) { } - T *operator->() { return ptr; } - T *operator&() { return ptr; } - operator T&() { return *ptr; } - template bool operator ==(U other) { return *ptr == other; } - template 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" -#if PY_VERSION_HEX >= 0x030800A4 && PY_VERSION_HEX < 0x030800B2 - #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ - PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) -#else - #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) -#endif - #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 -#ifndef METH_STACKLESS - #define METH_STACKLESS 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 | METH_STACKLESS))))) -#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_CPYTHON && PY_VERSION_HEX < 0x030400A1 - #define PyMem_RawMalloc(n) PyMem_Malloc(n) - #define PyMem_RawRealloc(p, n) PyMem_Realloc(p, n) - #define PyMem_RawFree(p) PyMem_Free(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; -} -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 -#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) - #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE) - #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) - #else - #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) - #endif -#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 || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) -#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? 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 -#ifndef PyObject_Unicode - #define PyObject_Unicode PyObject_Str -#endif -#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 PY_VERSION_HEX >= 0x030900A4 - #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt) - #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size) -#else - #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt) - #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size) -#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) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(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 -#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_MARK_ERR_POS(f_index, lineno) \ - { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; } -#define __PYX_ERR(f_index, lineno, Ln_error) \ - { __PYX_MARK_ERR_POS(f_index, lineno) 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__watershed -#define __PYX_HAVE_API__pygeoprocessing__routing__watershed -/* Early includes */ -#include -#include -#include "numpy/arrayobject.h" -#include "numpy/ndarrayobject.h" -#include "numpy/ndarraytypes.h" -#include "numpy/arrayscalars.h" -#include "numpy/ufuncobject.h" - - /* NumPy API declarations from "numpy/__init__.pxd" */ - -#include -#include -#include "ios" -#include "new" -#include "stdexcept" -#include "typeinfo" -#include -#include - - #if __cplusplus > 199711L - #include - - namespace cython_std { - template typename std::remove_reference::type&& move(T& t) noexcept { return std::move(t); } - template typename std::remove_reference::type&& move(T&& t) noexcept { return std::move(t); } - } - - #endif - -#include -#include -#include -#include "LRUCache.h" -#ifdef _OPENMP -#include -#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_UTF8 0 -#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8) -#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))) ) -static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) { - return (size_t) i < (size_t) limit; -} -#if defined (__cplusplus) && __cplusplus >= 201103L - #include - #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 int __Pyx_PyObject_IsTrueAndDecref(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) + 1); - 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 - #else - #include - #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/watershed.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; - - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":690 - * # 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":691 - * - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":692 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":693 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":697 - * #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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":698 - * - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":699 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":700 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":704 - * #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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":705 - * - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":714 - * # 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":715 - * # 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":716 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":718 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":719 - * - * ctypedef npy_ulong uint_t - * ctypedef npy_ulonglong ulong_t # <<<<<<<<<<<<<< - * ctypedef npy_ulonglong ulonglong_t - * - */ -typedef npy_ulonglong __pyx_t_5numpy_ulong_t; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":720 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":722 - * ctypedef npy_ulonglong ulonglong_t - * - * ctypedef npy_intp intp_t # <<<<<<<<<<<<<< - * ctypedef npy_uintp uintp_t - * - */ -typedef npy_intp __pyx_t_5numpy_intp_t; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":723 - * - * ctypedef npy_intp intp_t - * ctypedef npy_uintp uintp_t # <<<<<<<<<<<<<< - * - * ctypedef npy_double float_t - */ -typedef npy_uintp __pyx_t_5numpy_uintp_t; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":725 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":726 - * - * ctypedef npy_double float_t - * ctypedef npy_double double_t # <<<<<<<<<<<<<< - * ctypedef npy_longdouble longdouble_t - * - */ -typedef npy_double __pyx_t_5numpy_double_t; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":727 - * 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_9watershed__ManagedRaster; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":729 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":730 - * - * ctypedef npy_cfloat cfloat_t - * ctypedef npy_cdouble cdouble_t # <<<<<<<<<<<<<< - * ctypedef npy_clongdouble clongdouble_t - * - */ -typedef npy_cdouble __pyx_t_5numpy_cdouble_t; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":731 - * 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; - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":733 - * 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_opt_args_15pygeoprocessing_7routing_9watershed__c_split_geometry_into_seeds; - -/* "pygeoprocessing/routing/watershed.pyx":65 - * # this ctype is used to store the block ID and the block buffer as one object - * # inside Managed Raster - * ctypedef pair[int, int*] BlockBufferPair # <<<<<<<<<<<<<< - * - * # a class to allow fast random per-pixel access to a raster for both setting - */ -typedef std::pair __pyx_t_15pygeoprocessing_7routing_9watershed_BlockBufferPair; - -/* "pygeoprocessing/routing/watershed.pyx":385 - * # CoordinatePair().second is the y coordinate. Both are in integer pixel - * # coordinates. - * ctypedef pair[long, long] CoordinatePair # <<<<<<<<<<<<<< - * - * - */ -typedef std::pair __pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair; - -/* "pygeoprocessing/routing/watershed.pyx":402 - * - * - * cdef cset[CoordinatePair] _c_split_geometry_into_seeds( # <<<<<<<<<<<<<< - * source_geom_wkb, tuple flow_dir_geotransform, flow_dir_srs, - * flow_dir_n_cols, flow_dir_n_rows, - */ -struct __pyx_opt_args_15pygeoprocessing_7routing_9watershed__c_split_geometry_into_seeds { - int __pyx_n; - PyObject *diagnostic_vector_path; -}; - -/* "pygeoprocessing/routing/watershed.pyx":69 - * # a class to allow fast random per-pixel access to a raster for both setting - * # and reading pixels. - * cdef class _ManagedRaster: # <<<<<<<<<<<<<< - * cdef LRUCache[int, int*]* lru_cache - * cdef cset[int] dirty_blocks - */ -struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster { - PyObject_HEAD - struct __pyx_vtabstruct_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_vtab; - LRUCache *lru_cache; - std::set 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_9watershed__ManagedRaster { - void (*set)(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *, int, int, int); - int (*get)(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *, int, int); - void (*_load_block)(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *, int); -}; -static struct __pyx_vtabstruct_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_vtabptr_15pygeoprocessing_7routing_9watershed__ManagedRaster; -static CYTHON_INLINE void __pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_set(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *, int, int, int); -static CYTHON_INLINE int __pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_get(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__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); - -/* PyDictVersioning.proto */ -#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS -#define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1) -#define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag) -#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\ - (version_var) = __PYX_GET_DICT_VERSION(dict);\ - (cache_var) = (value); -#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\ - static PY_UINT64_T __pyx_dict_version = 0;\ - static PyObject *__pyx_dict_cached_value = NULL;\ - if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\ - (VAR) = __pyx_dict_cached_value;\ - } else {\ - (VAR) = __pyx_dict_cached_value = (LOOKUP);\ - __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\ - }\ -} -static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj); -static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj); -static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version); -#else -#define __PYX_GET_DICT_VERSION(dict) (0) -#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) -#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP); -#endif - -/* GetModuleGlobalName.proto */ -#if CYTHON_USE_DICT_VERSIONS -#define __Pyx_GetModuleGlobalName(var, name) {\ - static PY_UINT64_T __pyx_dict_version = 0;\ - static PyObject *__pyx_dict_cached_value = NULL;\ - (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\ - (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\ - __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ -} -#define __Pyx_GetModuleGlobalNameUncached(var, name) {\ - PY_UINT64_T __pyx_dict_version;\ - PyObject *__pyx_dict_cached_value;\ - (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ -} -static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); -#else -#define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name) -#define __Pyx_GetModuleGlobalNameUncached(var, name) (var) = __Pyx__GetModuleGlobalName(name) -static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name); -#endif - -/* 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, Py_ssize_t nargs, PyObject *kwargs); -#else -#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs) -#endif -#define __Pyx_BUILD_ASSERT_EXPR(cond)\ - (sizeof(char [1 - 2*!(cond)]) - 1) -#ifndef Py_MEMBER_SIZE -#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member) -#endif - static size_t __pyx_pyframe_localsplus_offset = 0; - #include "frameobject.h" - #define __Pxy_PyFrame_Initialize_Offsets()\ - ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\ - (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus))) - #define __Pyx_PyFrame_GetLocalsplus(frame)\ - (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset)) -#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 - -/* PyObjectCall2Args.proto */ -static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2); - -/* 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); - -/* 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); - -/* 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); - -/* PyIntCompare.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyInt_NeObjC(PyObject *op1, PyObject *op2, long intval, long inplace); - -/* PyIntBinop.proto */ -#if !CYTHON_COMPILING_IN_PYPY -static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check); -#else -#define __Pyx_PyInt_SubtractObjC(op1, op2, intval, inplace, zerodivision_check)\ - (inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2)) -#endif - -/* PyObjectFormatAndDecref.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f); -static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f); - -/* IncludeStringH.proto */ -#include - -/* JoinPyUnicode.proto */ -static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength, - Py_UCS4 max_char); - -/* 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); - -/* PyIntFromDouble.proto */ -#if PY_MAJOR_VERSION < 3 -static CYTHON_INLINE PyObject* __Pyx_PyInt_FromDouble(double value); -#else -#define __Pyx_PyInt_FromDouble(value) PyLong_FromDouble(value) -#endif - -/* GetTopmostException.proto */ -#if CYTHON_USE_EXC_INFO_STACK -static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate); -#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 - -/* PyObjectGetMethod.proto */ -static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method); - -/* PyObjectCallMethod0.proto */ -static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name); - -/* RaiseNoneIterError.proto */ -static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void); - -/* UnpackTupleError.proto */ -static void __Pyx_UnpackTupleError(PyObject *, Py_ssize_t index); - -/* UnpackTuple2.proto */ -#define __Pyx_unpack_tuple2(tuple, value1, value2, is_tuple, has_known_size, decref_tuple)\ - (likely(is_tuple || PyTuple_Check(tuple)) ?\ - (likely(has_known_size || PyTuple_GET_SIZE(tuple) == 2) ?\ - __Pyx_unpack_tuple2_exact(tuple, value1, value2, decref_tuple) :\ - (__Pyx_UnpackTupleError(tuple, 2), -1)) :\ - __Pyx_unpack_tuple2_generic(tuple, value1, value2, has_known_size, decref_tuple)) -static CYTHON_INLINE int __Pyx_unpack_tuple2_exact( - PyObject* tuple, PyObject** value1, PyObject** value2, int decref_tuple); -static int __Pyx_unpack_tuple2_generic( - PyObject* tuple, PyObject** value1, PyObject** value2, int has_known_size, int decref_tuple); - -/* dict_iter.proto */ -static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* dict, int is_dict, PyObject* method_name, - Py_ssize_t* p_orig_length, int* p_is_dict); -static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* dict_or_iter, Py_ssize_t orig_length, Py_ssize_t* ppos, - PyObject** pkey, PyObject** pvalue, PyObject** pitem, int is_dict); - -/* BytesEquals.proto */ -static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); - -/* UnicodeEquals.proto */ -static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); - -/* 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); - -/* PyObjectGetAttrStrNoError.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name); - -/* SetupReduce.proto */ -static int __Pyx_setup_reduce(PyObject* type_obj); - -/* TypeImport.proto */ -#ifndef __PYX_HAVE_RT_ImportType_proto -#define __PYX_HAVE_RT_ImportType_proto -enum __Pyx_ImportType_CheckSize { - __Pyx_ImportType_CheckSize_Error = 0, - __Pyx_ImportType_CheckSize_Warn = 1, - __Pyx_ImportType_CheckSize_Ignore = 2 -}; -static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size); -#endif - -/* 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 - -/* 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 - - -/* GCCDiagnostics.proto */ -#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) -#define __Pyx_HAS_GCC_DIAGNOSTIC -#endif - -/* CppExceptionConversion.proto */ -#ifndef __Pyx_CppExn2PyErr -#include -#include -#include -#include -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_long(long value); - -/* CIntFromPy.proto */ -static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); - -/* CIntToPy.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); - -/* CIntFromPy.proto */ -static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); - -/* CIntToPy.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyInt_From_Py_intptr_t(Py_intptr_t value); - -/* 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); - -/* InitStrings.proto */ -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); - -static CYTHON_INLINE void __pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_set(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self, int __pyx_v_xi, int __pyx_v_yi, int __pyx_v_value); /* proto*/ -static CYTHON_INLINE int __pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_get(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self, int __pyx_v_xi, int __pyx_v_yi); /* proto*/ -static void __pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster__load_block(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self, int __pyx_v_block_index); /* proto*/ - -/* Module declarations from 'cython' */ - -/* 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_generic = 0; -static PyTypeObject *__pyx_ptype_5numpy_number = 0; -static PyTypeObject *__pyx_ptype_5numpy_integer = 0; -static PyTypeObject *__pyx_ptype_5numpy_signedinteger = 0; -static PyTypeObject *__pyx_ptype_5numpy_unsignedinteger = 0; -static PyTypeObject *__pyx_ptype_5numpy_inexact = 0; -static PyTypeObject *__pyx_ptype_5numpy_floating = 0; -static PyTypeObject *__pyx_ptype_5numpy_complexfloating = 0; -static PyTypeObject *__pyx_ptype_5numpy_flexible = 0; -static PyTypeObject *__pyx_ptype_5numpy_character = 0; -static PyTypeObject *__pyx_ptype_5numpy_ufunc = 0; - -/* Module declarations from 'libc.stddef' */ - -/* Module declarations from 'libc.time' */ - -/* Module declarations from 'libcpp.list' */ - -/* Module declarations from 'libcpp.utility' */ - -/* Module declarations from 'libcpp.map' */ - -/* Module declarations from 'libcpp.pair' */ - -/* Module declarations from 'libcpp.queue' */ - -/* Module declarations from 'libcpp.set' */ - -/* Module declarations from 'pygeoprocessing.routing.watershed' */ -static PyTypeObject *__pyx_ptype_15pygeoprocessing_7routing_9watershed__ManagedRaster = 0; -static int __pyx_v_15pygeoprocessing_7routing_9watershed_BLOCK_BITS; -static int __pyx_v_15pygeoprocessing_7routing_9watershed_MANAGED_RASTER_N_BLOCKS; -static int *__pyx_v_15pygeoprocessing_7routing_9watershed_D8_REVERSE_DIRECTION; -static int *__pyx_v_15pygeoprocessing_7routing_9watershed_NEIGHBOR_COL; -static int *__pyx_v_15pygeoprocessing_7routing_9watershed_NEIGHBOR_ROW; -static std::set<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> __pyx_f_15pygeoprocessing_7routing_9watershed__c_split_geometry_into_seeds(PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, struct __pyx_opt_args_15pygeoprocessing_7routing_9watershed__c_split_geometry_into_seeds *__pyx_optional_args); /*proto*/ -static PyObject *__pyx_convert_pair_to_py_long____long(std::pair const &); /*proto*/ -static std::pair __pyx_convert_pair_from_py_long__and_long(PyObject *); /*proto*/ -static __Pyx_TypeInfo __Pyx_TypeInfo_int = { "int", NULL, sizeof(int), { 0 }, 0, IS_UNSIGNED(int) ? 'U' : 'I', IS_UNSIGNED(int), 0 }; -static __Pyx_TypeInfo __Pyx_TypeInfo_nn_npy_uint8 = { "npy_uint8", NULL, sizeof(npy_uint8), { 0 }, 0, IS_UNSIGNED(npy_uint8) ? 'U' : 'I', IS_UNSIGNED(npy_uint8), 0 }; -#define __Pyx_MODULE_NAME "pygeoprocessing.routing.watershed" -extern int __pyx_module_is_main_pygeoprocessing__routing__watershed; -int __pyx_module_is_main_pygeoprocessing__routing__watershed = 0; - -/* Implementation of 'pygeoprocessing.routing.watershed' */ -static PyObject *__pyx_builtin_OSError; -static PyObject *__pyx_builtin_ValueError; -static PyObject *__pyx_builtin_xrange; -static PyObject *__pyx_builtin_TypeError; -static PyObject *__pyx_builtin_range; -static PyObject *__pyx_builtin_ImportError; -static const char __pyx_k_[] = ", "; -static const char __pyx_k_d[] = "d"; -static const char __pyx_k_os[] = "os"; -static const char __pyx_k_x1[] = "x1"; -static const char __pyx_k_x2[] = "x2"; -static const char __pyx_k_y1[] = "y1"; -static const char __pyx_k_y2[] = "y2"; -static const char __pyx_k_VRT[] = "VRT"; -static const char __pyx_k__10[] = "_"; -static const char __pyx_k_box[] = "box"; -static const char __pyx_k_dir[] = "dir"; -static const char __pyx_k_fid[] = "fid"; -static const char __pyx_k_mem[] = "mem"; -static const char __pyx_k_ogr[] = "ogr"; -static const char __pyx_k_osr[] = "osr"; -static const char __pyx_k_wkb[] = "wkb"; -static const char __pyx_k_GPKG[] = "GPKG"; -static const char __pyx_k_gdal[] = "gdal"; -static const char __pyx_k_geom[] = "geom"; -static const char __pyx_k_info[] = "info"; -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_prep[] = "prep"; -static const char __pyx_k_seed[] = "seed"; -static const char __pyx_k_test[] = "__test__"; -static const char __pyx_k_time[] = "time"; -static const char __pyx_k_xoff[] = "xoff"; -static const char __pyx_k_yoff[] = "yoff"; -static const char __pyx_k_GTiff[] = "GTiff"; -static const char __pyx_k_Point[] = "Point"; -static const char __pyx_k_close[] = "close"; -static const char __pyx_k_debug[] = "debug"; -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_items[] = "items"; -static const char __pyx_k_loads[] = "loads"; -static const char __pyx_k_numpy[] = "numpy"; -static const char __pyx_k_osgeo[] = "osgeo"; -static const char __pyx_k_range[] = "range"; -static const char __pyx_k_seeds[] = "seeds"; -static const char __pyx_k_ws_id[] = "ws_id"; -static const char __pyx_k_Create[] = "Create"; -static const char __pyx_k_GetFID[] = "GetFID"; -static const char __pyx_k_LOGGER[] = "LOGGER"; -static const char __pyx_k_Memory[] = "Memory"; -static const char __pyx_k_OpenEx[] = "OpenEx"; -static const char __pyx_k_WSID_1[] = "WSID <= 1!"; -static const char __pyx_k_astype[] = "astype"; -static const char __pyx_k_bounds[] = "bounds"; -static const char __pyx_k_driver[] = "driver"; -static const char __pyx_k_exists[] = "exists"; -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_ix_max[] = "ix_max"; -static const char __pyx_k_ix_min[] = "ix_min"; -static const char __pyx_k_iy_max[] = "iy_max"; -static const char __pyx_k_iy_min[] = "iy_min"; -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_remove[] = "remove"; -static const char __pyx_k_rmtree[] = "rmtree"; -static const char __pyx_k_schema[] = "schema"; -static const char __pyx_k_shutil[] = "shutil"; -static const char __pyx_k_xrange[] = "xrange"; -static const char __pyx_k_Feature[] = "Feature"; -static const char __pyx_k_IsEmpty[] = "IsEmpty"; -static const char __pyx_k_OSError[] = "OSError"; -static const char __pyx_k_Polygon[] = "Polygon"; -static const char __pyx_k_band_id[] = "band_id"; -static const char __pyx_k_feature[] = "feature"; -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_options[] = "options"; -static const char __pyx_k_shapely[] = "shapely"; -static const char __pyx_k_BuildVRT[] = "BuildVRT"; -static const char __pyx_k_GDT_Byte[] = "GDT_Byte"; -static const char __pyx_k_Geometry[] = "Geometry"; -static const char __pyx_k_GetField[] = "GetField"; -static const char __pyx_k_GetLayer[] = "GetLayer"; -static const char __pyx_k_SetField[] = "SetField"; -static const char __pyx_k_SetWidth[] = "SetWidth"; -static const char __pyx_k_geom_wkb[] = "geom_wkb"; -static const char __pyx_k_geometry[] = "geometry"; -static const char __pyx_k_getstate[] = "__getstate__"; -static const char __pyx_k_makedirs[] = "makedirs"; -static const char __pyx_k_prepared[] = "prepared"; -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_vrt_band[] = "vrt_band"; -static const char __pyx_k_vrt_path[] = "vrt_path"; -static const char __pyx_k_wkbPoint[] = "wkbPoint"; -static const char __pyx_k_FieldDefn[] = "FieldDefn"; -static const char __pyx_k_GA_Update[] = "GA_Update"; -static const char __pyx_k_OF_RASTER[] = "OF_RASTER"; -static const char __pyx_k_OF_VECTOR[] = "OF_VECTOR"; -static const char __pyx_k_TILED_YES[] = "TILED=YES"; -static const char __pyx_k_TypeError[] = "TypeError"; -static const char __pyx_k_bbox_maxx[] = "bbox_maxx"; -static const char __pyx_k_bbox_maxy[] = "bbox_maxy"; -static const char __pyx_k_bbox_minx[] = "bbox_minx"; -static const char __pyx_k_bbox_miny[] = "bbox_miny"; -static const char __pyx_k_getLogger[] = "getLogger"; -static const char __pyx_k_reduce_ex[] = "__reduce_ex__"; -static const char __pyx_k_s_vrt_vrt[] = "%s_vrt.vrt"; -static const char __pyx_k_source_gt[] = "source_gt"; -static const char __pyx_k_win_xsize[] = "win_xsize"; -static const char __pyx_k_win_ysize[] = "win_ysize"; -static const char __pyx_k_FlushCache[] = "FlushCache"; -static const char __pyx_k_GDT_UInt32[] = "GDT_UInt32"; -static const char __pyx_k_GetFeature[] = "GetFeature"; -static const char __pyx_k_OFTInteger[] = "OFTInteger"; -static const char __pyx_k_Polygonize[] = "Polygonize"; -static const char __pyx_k_ValueError[] = "ValueError"; -static const char __pyx_k_WriteArray[] = "WriteArray"; -static const char __pyx_k_block_size[] = "block_size"; -static const char __pyx_k_field_name[] = "field_name"; -static const char __pyx_k_intersects[] = "intersects"; -static const char __pyx_k_iterblocks[] = "iterblocks"; -static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__"; -static const char __pyx_k_return_set[] = "return_set"; -static const char __pyx_k_vrt_raster[] = "vrt_raster"; -static const char __pyx_k_watersheds[] = "watersheds"; -static const char __pyx_k_wkbPolygon[] = "wkbPolygon"; -static const char __pyx_k_wkbUnknown[] = "wkbUnknown"; -static const char __pyx_k_write_mode[] = "write_mode"; -static const char __pyx_k_AddGeometry[] = "AddGeometry"; -static const char __pyx_k_BIGTIFF_YES[] = "BIGTIFF=YES"; -static const char __pyx_k_CreateField[] = "CreateField"; -static const char __pyx_k_CreateLayer[] = "CreateLayer"; -static const char __pyx_k_DeleteLayer[] = "DeleteLayer"; -static const char __pyx_k_ExportToWkb[] = "ExportToWkb"; -static const char __pyx_k_ExportToWkt[] = "ExportToWkt"; -static const char __pyx_k_GDT_Unknown[] = "GDT_Unknown"; -static const char __pyx_k_ImportError[] = "ImportError"; -static const char __pyx_k_ReadAsArray[] = "ReadAsArray"; -static const char __pyx_k_SetGeometry[] = "SetGeometry"; -static const char __pyx_k_burn_values[] = "burn_values"; -static const char __pyx_k_current_fid[] = "current_fid"; -static const char __pyx_k_field_value[] = "field_value"; -static const char __pyx_k_index_field[] = "index_field"; -static const char __pyx_k_raster_path[] = "raster_path"; -static const char __pyx_k_raster_size[] = "raster_size"; -static const char __pyx_k_shapely_wkb[] = "shapely.wkb"; -static const char __pyx_k_vrt_options[] = "vrt_options"; -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_CreateFields[] = "CreateFields"; -static const char __pyx_k_GetLayerDefn[] = "GetLayerDefn"; -static const char __pyx_k_ResetReading[] = "ResetReading"; -static const char __pyx_k_bounding_box[] = "bounding_box"; -static const char __pyx_k_flow_dir_srs[] = "flow_dir_srs"; -static const char __pyx_k_geotransform[] = "geotransform"; -static const char __pyx_k_gtiff_driver[] = "gtiff_driver"; -static const char __pyx_k_neighbor_col[] = "neighbor_col"; -static const char __pyx_k_neighbor_row[] = "neighbor_row"; -static const char __pyx_k_new_geometry[] = "new_geometry"; -static const char __pyx_k_outputBounds[] = "outputBounds"; -static const char __pyx_k_reverse_flow[] = "reverse_flow"; -static const char __pyx_k_s_seeds_gpkg[] = "%s_seeds.gpkg"; -static const char __pyx_k_shapely_geom[] = "shapely_geom"; -static const char __pyx_k_source_layer[] = "source_layer"; -static const char __pyx_k_CreateFeature[] = "CreateFeature"; -static const char __pyx_k_GetRasterBand[] = "GetRasterBand"; -static const char __pyx_k_ImportFromWkt[] = "ImportFromWkt"; -static const char __pyx_k_ManagedRaster[] = "_ManagedRaster"; -static const char __pyx_k_SetProjection[] = "SetProjection"; -static const char __pyx_k_current_pixel[] = "current_pixel"; -static const char __pyx_k_duplicate_fid[] = "duplicate_fid"; -static const char __pyx_k_flow_dir_bbox[] = "flow_dir_bbox"; -static const char __pyx_k_flow_dir_info[] = "flow_dir_info"; -static const char __pyx_k_last_log_time[] = "last_log_time"; -static const char __pyx_k_outflow_layer[] = "outflow_layer"; -static const char __pyx_k_process_queue[] = "process_queue"; -static const char __pyx_k_reduce_cython[] = "__reduce_cython__"; -static const char __pyx_k_s_scratch_tif[] = "%s_scratch.tif"; -static const char __pyx_k_seed_iterator[] = "seed_iterator"; -static const char __pyx_k_source_vector[] = "source_vector"; -static const char __pyx_k_user_geometry[] = "user_geometry"; -static const char __pyx_k_GetGeometryRef[] = "GetGeometryRef"; -static const char __pyx_k_RasterizeLayer[] = "RasterizeLayer"; -static const char __pyx_k_SPARSE_OK_TRUE[] = "SPARSE_OK=TRUE"; -static const char __pyx_k_Y_m_d__H__M__S[] = "%Y-%m-%d_%H_%M_%S"; -static const char __pyx_k_neighbor_index[] = "neighbor_index"; -static const char __pyx_k_neighbor_pixel[] = "neighbor_pixel"; -static const char __pyx_k_outflow_vector[] = "outflow_vector"; -static const char __pyx_k_projection_wkt[] = "projection_wkt"; -static const char __pyx_k_scratch_raster[] = "scratch_raster"; -static const char __pyx_k_seeds_iterator[] = "seeds_iterator"; -static const char __pyx_k_source_feature[] = "source_feature"; -static const char __pyx_k_watersheds_srs[] = "watersheds_srs"; -static const char __pyx_k_BuildVRTOptions[] = "BuildVRTOptions"; -static const char __pyx_k_GetDriverByName[] = "GetDriverByName"; -static const char __pyx_k_GetFeatureCount[] = "GetFeatureCount"; -static const char __pyx_k_SetGeoTransform[] = "SetGeoTransform"; -static const char __pyx_k_allowed_drivers[] = "allowed_drivers"; -static const char __pyx_k_flow_dir_n_cols[] = "flow_dir_n_cols"; -static const char __pyx_k_flow_dir_n_rows[] = "flow_dir_n_rows"; -static const char __pyx_k_flow_dir_nodata[] = "flow_dir_nodata"; -static const char __pyx_k_get_raster_info[] = "get_raster_info"; -static const char __pyx_k_n_cells_visited[] = "n_cells_visited"; -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_source_geom_wkb[] = "source_geom_wkb"; -static const char __pyx_k_wkbMultiPolygon[] = "wkbMultiPolygon"; -static const char __pyx_k_ALL_TOUCHED_True[] = "ALL_TOUCHED=True"; -static const char __pyx_k_CreateDataSource[] = "CreateDataSource"; -static const char __pyx_k_SpatialReference[] = "SpatialReference"; -static const char __pyx_k_StartTransaction[] = "StartTransaction"; -static const char __pyx_k_raster_path_band[] = "raster_path_band"; -static const char __pyx_k_s_rasterized_tif[] = "%s_rasterized.tif"; -static const char __pyx_k_shapely_geometry[] = "shapely.geometry"; -static const char __pyx_k_shapely_prepared[] = "shapely.prepared"; -static const char __pyx_k_watersheds_layer[] = "watersheds_layer"; -static const char __pyx_k_working_dir_path[] = "working_dir_path"; -static const char __pyx_k_CommitTransaction[] = "CommitTransaction"; -static const char __pyx_k_duplicate_feature[] = "duplicate_feature"; -static const char __pyx_k_duplicate_ids_set[] = "duplicate_ids_set"; -static const char __pyx_k_flow_dir_origin_x[] = "flow_dir_origin_x"; -static const char __pyx_k_flow_dir_origin_y[] = "flow_dir_origin_y"; -static const char __pyx_k_process_queue_set[] = "process_queue_set"; -static const char __pyx_k_remove_temp_files[] = "remove_temp_files"; -static const char __pyx_k_seeds_raster_path[] = "seeds_raster_path"; -static const char __pyx_k_target_layer_name[] = "target_layer_name"; -static const char __pyx_k_watershed_feature[] = "watershed_feature"; -static const char __pyx_k_watersheds_vector[] = "watersheds_vector"; -static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; -static const char __pyx_k_duplicate_geometry[] = "duplicate_geometry"; -static const char __pyx_k_seeds_in_watershed[] = "seeds_in_watershed"; -static const char __pyx_k_target_raster_path[] = "target_raster_path"; -static const char __pyx_k_watersheds_created[] = "watersheds_created"; -static const char __pyx_k_outflow_vector_path[] = "outflow_vector_path"; -static const char __pyx_k_scratch_raster_path[] = "scratch_raster_path"; -static const char __pyx_k_flow_dir_pixelsize_x[] = "flow_dir_pixelsize_x"; -static const char __pyx_k_flow_dir_pixelsize_y[] = "flow_dir_pixelsize_y"; -static const char __pyx_k_CreateGeometryFromWkb[] = "CreateGeometryFromWkb"; -static const char __pyx_k_Testing_geometry_bbox[] = "Testing geometry bbox"; -static const char __pyx_k_outflow_feature_count[] = "outflow_feature_count"; -static const char __pyx_k_Creating_flow_dir_bbox[] = "Creating flow dir bbox"; -static const char __pyx_k_Delineating_watersheds[] = "Delineating watersheds"; -static const char __pyx_k_GTIFF_CREATION_OPTIONS[] = "GTIFF_CREATION_OPTIONS"; -static const char __pyx_k_diagnostic_vector_path[] = "diagnostic_vector_path"; -static const char __pyx_k_polygonized_watersheds[] = "polygonized_watersheds"; -static const char __pyx_k_scratch_managed_raster[] = "scratch_managed_raster"; -static const char __pyx_k_delineate_watersheds_d8[] = "delineate_watersheds_d8"; -static const char __pyx_k_flow_dir_managed_raster[] = "flow_dir_managed_raster"; -static const char __pyx_k_write_diagnostic_vector[] = "write_diagnostic_vector"; -static const char __pyx_k_fragments_with_duplicates[] = "fragments_with_duplicates"; -static const char __pyx_k_split_geometry_into_seeds[] = "_split_geometry_into_seeds"; -static const char __pyx_k_duplicate_ids_set_iterator[] = "duplicate_ids_set_iterator"; -static const char __pyx_k_d8_flow_dir_raster_path_band[] = "d8_flow_dir_raster_path_band"; -static const char __pyx_k_polygonized_watersheds_layer[] = "polygonized_watersheds_layer"; -static const char __pyx_k_Finished_vector_consolidation[] = "Finished vector consolidation"; -static const char __pyx_k_is_raster_path_band_formatted[] = "_is_raster_path_band_formatted"; -static const char __pyx_k_target_watersheds_vector_path[] = "target_watersheds_vector_path"; -static const char __pyx_k_Watershed_delineation_complete[] = "Watershed delineation complete"; -static const char __pyx_k_Could_not_open_outflow_vector_s[] = "Could not open outflow vector %s"; -static const char __pyx_k_Delineating_watershed_s_of_s_ws[] = "Delineating watershed %s of %s (ws_id %s)"; -static const char __pyx_k_Error_Block_size_is_not_a_power[] = "Error: Block size is not a power of two: block_xsize: "; -static const char __pyx_k_This_exception_is_happeningin_C[] = ". 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_numpy_core_multiarray_failed_to[] = "numpy.core.multiarray failed to import"; -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_Consolidating_s_fragments_and_co[] = "Consolidating %s fragments and copying field values to watersheds layer."; -static const char __pyx_k_Creating_flow_dir_managed_raster[] = "Creating flow dir managed raster"; -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_Finished_delineating_s_watershed[] = "Finished delineating %s watersheds"; -static const char __pyx_k_Outflow_feature_s_does_not_inter[] = "Outflow feature %s does not intersect any pixels with valid flow direction. Skipping."; -static const char __pyx_k_Outflow_feature_s_does_not_overl[] = "Outflow feature %s does not overlap with the flow direction raster. Skipping."; -static const char __pyx_k_Outflow_feature_s_has_empty_geom[] = "Outflow feature %s has empty geometry. Skipping."; -static const char __pyx_k_fragments_with_duplicates_iterat[] = "fragments_with_duplicates_iterator"; -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_pygeoprocessing_routing_watershe[] = "pygeoprocessing.routing.watershed"; -static const char __pyx_k_src_pygeoprocessing_routing_wate[] = "src/pygeoprocessing/routing/watershed.pyx"; -static const char __pyx_k_watershed_delineation_trivial__s[] = "watershed_delineation_trivial_%s_"; -static const char __pyx_k_Delineating_watershed_s_of_s_ws_2[] = "Delineating watershed %s of %s (ws_id %s), %s pixels found so far"; -static PyObject *__pyx_kp_u_; -static PyObject *__pyx_kp_u_ALL_TOUCHED_True; -static PyObject *__pyx_n_s_AddGeometry; -static PyObject *__pyx_kp_u_BIGTIFF_YES; -static PyObject *__pyx_kp_u_BLOCKXSIZE_d; -static PyObject *__pyx_kp_u_BLOCKYSIZE_d; -static PyObject *__pyx_n_s_BuildVRT; -static PyObject *__pyx_n_s_BuildVRTOptions; -static PyObject *__pyx_kp_u_COMPRESS_LZW; -static PyObject *__pyx_n_s_CommitTransaction; -static PyObject *__pyx_kp_u_Consolidating_s_fragments_and_co; -static PyObject *__pyx_kp_u_Could_not_open_outflow_vector_s; -static PyObject *__pyx_n_s_Create; -static PyObject *__pyx_n_s_CreateDataSource; -static PyObject *__pyx_n_s_CreateFeature; -static PyObject *__pyx_n_s_CreateField; -static PyObject *__pyx_n_s_CreateFields; -static PyObject *__pyx_n_s_CreateGeometryFromWkb; -static PyObject *__pyx_n_s_CreateLayer; -static PyObject *__pyx_kp_u_Creating_flow_dir_bbox; -static PyObject *__pyx_kp_u_Creating_flow_dir_managed_raster; -static PyObject *__pyx_n_s_DeleteLayer; -static PyObject *__pyx_kp_u_Delineating_watershed_s_of_s_ws; -static PyObject *__pyx_kp_u_Delineating_watershed_s_of_s_ws_2; -static PyObject *__pyx_kp_u_Delineating_watersheds; -static PyObject *__pyx_kp_u_Error_Block_size_is_not_a_power; -static PyObject *__pyx_kp_u_Error_band_ID_s_is_not_a_valid_b; -static PyObject *__pyx_n_s_ExportToWkb; -static PyObject *__pyx_n_s_ExportToWkt; -static PyObject *__pyx_n_s_Feature; -static PyObject *__pyx_n_s_FieldDefn; -static PyObject *__pyx_kp_u_Finished_delineating_s_watershed; -static PyObject *__pyx_kp_u_Finished_vector_consolidation; -static PyObject *__pyx_n_s_FlushCache; -static PyObject *__pyx_n_s_GA_Update; -static PyObject *__pyx_n_s_GDT_Byte; -static PyObject *__pyx_n_s_GDT_UInt32; -static PyObject *__pyx_n_s_GDT_Unknown; -static PyObject *__pyx_n_u_GPKG; -static PyObject *__pyx_n_s_GTIFF_CREATION_OPTIONS; -static PyObject *__pyx_n_u_GTiff; -static PyObject *__pyx_n_s_Geometry; -static PyObject *__pyx_n_s_GetDriverByName; -static PyObject *__pyx_n_s_GetFID; -static PyObject *__pyx_n_s_GetFeature; -static PyObject *__pyx_n_s_GetFeatureCount; -static PyObject *__pyx_n_s_GetField; -static PyObject *__pyx_n_s_GetGeometryRef; -static PyObject *__pyx_n_s_GetLayer; -static PyObject *__pyx_n_s_GetLayerDefn; -static PyObject *__pyx_n_s_GetRasterBand; -static PyObject *__pyx_n_s_ImportError; -static PyObject *__pyx_n_s_ImportFromWkt; -static PyObject *__pyx_n_s_IsEmpty; -static PyObject *__pyx_n_s_LOGGER; -static PyObject *__pyx_n_s_ManagedRaster; -static PyObject *__pyx_n_u_Memory; -static PyObject *__pyx_n_s_OFTInteger; -static PyObject *__pyx_n_s_OF_RASTER; -static PyObject *__pyx_n_s_OF_VECTOR; -static PyObject *__pyx_n_s_OSError; -static PyObject *__pyx_n_s_OpenEx; -static PyObject *__pyx_kp_u_Outflow_feature_s_does_not_inter; -static PyObject *__pyx_kp_u_Outflow_feature_s_does_not_overl; -static PyObject *__pyx_kp_u_Outflow_feature_s_has_empty_geom; -static PyObject *__pyx_n_s_Point; -static PyObject *__pyx_n_s_Polygon; -static PyObject *__pyx_n_s_Polygonize; -static PyObject *__pyx_n_s_RasterizeLayer; -static PyObject *__pyx_n_s_ReadAsArray; -static PyObject *__pyx_n_s_ResetReading; -static PyObject *__pyx_kp_u_SPARSE_OK_TRUE; -static PyObject *__pyx_n_s_SetField; -static PyObject *__pyx_n_s_SetGeoTransform; -static PyObject *__pyx_n_s_SetGeometry; -static PyObject *__pyx_n_s_SetProjection; -static PyObject *__pyx_n_s_SetWidth; -static PyObject *__pyx_n_s_SpatialReference; -static PyObject *__pyx_n_s_StartTransaction; -static PyObject *__pyx_kp_u_TILED_YES; -static PyObject *__pyx_kp_u_Testing_geometry_bbox; -static PyObject *__pyx_kp_u_This_exception_is_happeningin_C; -static PyObject *__pyx_n_s_TypeError; -static PyObject *__pyx_n_u_VRT; -static PyObject *__pyx_n_s_ValueError; -static PyObject *__pyx_kp_u_WSID_1; -static PyObject *__pyx_kp_u_Watershed_delineation_complete; -static PyObject *__pyx_n_s_WriteArray; -static PyObject *__pyx_kp_u_Y_m_d__H__M__S; -static PyObject *__pyx_n_s__10; -static PyObject *__pyx_n_s_allowed_drivers; -static PyObject *__pyx_n_s_astype; -static PyObject *__pyx_n_s_band_id; -static PyObject *__pyx_n_s_bbox_maxx; -static PyObject *__pyx_n_s_bbox_maxy; -static PyObject *__pyx_n_s_bbox_minx; -static PyObject *__pyx_n_s_bbox_miny; -static PyObject *__pyx_n_u_block_size; -static PyObject *__pyx_n_u_bounding_box; -static PyObject *__pyx_n_s_bounds; -static PyObject *__pyx_n_s_box; -static PyObject *__pyx_n_s_burn_values; -static PyObject *__pyx_n_s_cline_in_traceback; -static PyObject *__pyx_n_s_close; -static PyObject *__pyx_n_s_current_fid; -static PyObject *__pyx_n_s_current_pixel; -static PyObject *__pyx_n_u_d; -static PyObject *__pyx_n_s_d8_flow_dir_raster_path_band; -static PyObject *__pyx_n_s_debug; -static PyObject *__pyx_n_s_delineate_watersheds_d8; -static PyObject *__pyx_n_s_diagnostic_vector_path; -static PyObject *__pyx_n_s_dir; -static PyObject *__pyx_n_s_driver; -static PyObject *__pyx_n_s_dtype; -static PyObject *__pyx_n_s_duplicate_feature; -static PyObject *__pyx_n_s_duplicate_fid; -static PyObject *__pyx_n_s_duplicate_geometry; -static PyObject *__pyx_n_s_duplicate_ids_set; -static PyObject *__pyx_n_s_duplicate_ids_set_iterator; -static PyObject *__pyx_n_s_empty; -static PyObject *__pyx_n_s_error; -static PyObject *__pyx_n_s_exists; -static PyObject *__pyx_n_s_feature; -static PyObject *__pyx_n_s_fid; -static PyObject *__pyx_n_s_field_name; -static PyObject *__pyx_n_s_field_value; -static PyObject *__pyx_n_s_flow_dir_bbox; -static PyObject *__pyx_n_s_flow_dir_info; -static PyObject *__pyx_n_s_flow_dir_managed_raster; -static PyObject *__pyx_n_s_flow_dir_n_cols; -static PyObject *__pyx_n_s_flow_dir_n_rows; -static PyObject *__pyx_n_s_flow_dir_nodata; -static PyObject *__pyx_n_s_flow_dir_origin_x; -static PyObject *__pyx_n_s_flow_dir_origin_y; -static PyObject *__pyx_n_s_flow_dir_pixelsize_x; -static PyObject *__pyx_n_s_flow_dir_pixelsize_y; -static PyObject *__pyx_n_s_flow_dir_srs; -static PyObject *__pyx_n_s_fragments_with_duplicates; -static PyObject *__pyx_n_s_fragments_with_duplicates_iterat; -static PyObject *__pyx_n_s_gdal; -static PyObject *__pyx_n_s_geom; -static PyObject *__pyx_n_s_geom_wkb; -static PyObject *__pyx_n_s_geometry; -static PyObject *__pyx_n_s_geotransform; -static PyObject *__pyx_n_u_geotransform; -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_driver; -static PyObject *__pyx_n_s_import; -static PyObject *__pyx_n_s_index_field; -static PyObject *__pyx_n_s_info; -static PyObject *__pyx_n_s_int32; -static PyObject *__pyx_n_s_intersects; -static PyObject *__pyx_n_s_is_raster_path_band_formatted; -static PyObject *__pyx_n_s_isfile; -static PyObject *__pyx_n_s_items; -static PyObject *__pyx_n_s_iterblocks; -static PyObject *__pyx_n_s_ix_max; -static PyObject *__pyx_n_s_ix_min; -static PyObject *__pyx_n_s_iy_max; -static PyObject *__pyx_n_s_iy_min; -static PyObject *__pyx_n_s_join; -static PyObject *__pyx_n_s_last_log_time; -static PyObject *__pyx_n_s_loads; -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_u_mem; -static PyObject *__pyx_n_s_mkdtemp; -static PyObject *__pyx_n_u_n_bands; -static PyObject *__pyx_n_s_n_cells_visited; -static PyObject *__pyx_n_s_name; -static PyObject *__pyx_n_s_neighbor_col; -static PyObject *__pyx_n_s_neighbor_index; -static PyObject *__pyx_n_s_neighbor_pixel; -static PyObject *__pyx_n_s_neighbor_row; -static PyObject *__pyx_n_s_new_geometry; -static PyObject *__pyx_kp_s_no_default___reduce___due_to_non; -static PyObject *__pyx_n_u_nodata; -static PyObject *__pyx_n_s_numpy; -static PyObject *__pyx_kp_u_numpy_core_multiarray_failed_to; -static PyObject *__pyx_kp_u_numpy_core_umath_failed_to_impor; -static PyObject *__pyx_n_s_ogr; -static PyObject *__pyx_n_s_options; -static PyObject *__pyx_n_s_os; -static PyObject *__pyx_n_s_osgeo; -static PyObject *__pyx_n_s_osr; -static PyObject *__pyx_n_s_outflow_feature_count; -static PyObject *__pyx_n_s_outflow_layer; -static PyObject *__pyx_n_s_outflow_vector; -static PyObject *__pyx_n_s_outflow_vector_path; -static PyObject *__pyx_n_s_outputBounds; -static PyObject *__pyx_n_s_path; -static PyObject *__pyx_n_u_polygonized_watersheds; -static PyObject *__pyx_n_s_polygonized_watersheds_layer; -static PyObject *__pyx_n_s_prefix; -static PyObject *__pyx_n_s_prep; -static PyObject *__pyx_n_s_prepared; -static PyObject *__pyx_n_s_process_queue; -static PyObject *__pyx_n_s_process_queue_set; -static PyObject *__pyx_n_u_projection_wkt; -static PyObject *__pyx_n_s_pygeoprocessing; -static PyObject *__pyx_n_s_pygeoprocessing_routing_watershe; -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_u_raster_size; -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_remove; -static PyObject *__pyx_n_s_remove_temp_files; -static PyObject *__pyx_n_s_return_set; -static PyObject *__pyx_n_s_reverse_flow; -static PyObject *__pyx_n_s_rmtree; -static PyObject *__pyx_kp_u_s_is_not_a_file; -static PyObject *__pyx_kp_u_s_is_supposed_to_be_a_raster_ba; -static PyObject *__pyx_kp_u_s_rasterized_tif; -static PyObject *__pyx_kp_u_s_scratch_tif; -static PyObject *__pyx_kp_u_s_seeds_gpkg; -static PyObject *__pyx_kp_u_s_vrt_vrt; -static PyObject *__pyx_n_s_schema; -static PyObject *__pyx_n_s_scratch_managed_raster; -static PyObject *__pyx_n_s_scratch_raster; -static PyObject *__pyx_n_s_scratch_raster_path; -static PyObject *__pyx_n_s_seed; -static PyObject *__pyx_n_s_seed_iterator; -static PyObject *__pyx_n_s_seeds; -static PyObject *__pyx_n_u_seeds; -static PyObject *__pyx_n_s_seeds_in_watershed; -static PyObject *__pyx_n_s_seeds_iterator; -static PyObject *__pyx_n_s_seeds_raster_path; -static PyObject *__pyx_n_s_setstate; -static PyObject *__pyx_n_s_setstate_cython; -static PyObject *__pyx_n_s_shapely; -static PyObject *__pyx_n_s_shapely_geom; -static PyObject *__pyx_n_s_shapely_geometry; -static PyObject *__pyx_n_s_shapely_prepared; -static PyObject *__pyx_n_s_shapely_wkb; -static PyObject *__pyx_n_s_shutil; -static PyObject *__pyx_n_s_source_feature; -static PyObject *__pyx_n_s_source_geom_wkb; -static PyObject *__pyx_n_s_source_gt; -static PyObject *__pyx_n_s_source_layer; -static PyObject *__pyx_n_s_source_vector; -static PyObject *__pyx_n_s_split_geometry_into_seeds; -static PyObject *__pyx_kp_s_src_pygeoprocessing_routing_wate; -static PyObject *__pyx_n_s_strftime; -static PyObject *__pyx_n_s_target_layer_name; -static PyObject *__pyx_n_s_target_raster_path; -static PyObject *__pyx_n_s_target_watersheds_vector_path; -static PyObject *__pyx_n_s_tempfile; -static PyObject *__pyx_n_s_test; -static PyObject *__pyx_n_s_time; -static PyObject *__pyx_n_u_user_geometry; -static PyObject *__pyx_n_s_vrt_band; -static PyObject *__pyx_n_s_vrt_options; -static PyObject *__pyx_n_s_vrt_path; -static PyObject *__pyx_n_s_vrt_raster; -static PyObject *__pyx_kp_u_watershed_delineation_trivial__s; -static PyObject *__pyx_n_s_watershed_feature; -static PyObject *__pyx_n_u_watersheds; -static PyObject *__pyx_n_s_watersheds_created; -static PyObject *__pyx_n_s_watersheds_layer; -static PyObject *__pyx_n_s_watersheds_srs; -static PyObject *__pyx_n_s_watersheds_vector; -static PyObject *__pyx_n_s_win_xsize; -static PyObject *__pyx_n_s_win_ysize; -static PyObject *__pyx_n_s_wkb; -static PyObject *__pyx_n_s_wkbMultiPolygon; -static PyObject *__pyx_n_s_wkbPoint; -static PyObject *__pyx_n_s_wkbPolygon; -static PyObject *__pyx_n_s_wkbUnknown; -static PyObject *__pyx_n_s_working_dir; -static PyObject *__pyx_n_s_working_dir_path; -static PyObject *__pyx_n_s_write_diagnostic_vector; -static PyObject *__pyx_n_s_write_mode; -static PyObject *__pyx_n_s_ws_id; -static PyObject *__pyx_n_u_ws_id; -static PyObject *__pyx_n_s_x1; -static PyObject *__pyx_n_s_x2; -static PyObject *__pyx_n_s_xoff; -static PyObject *__pyx_n_u_xoff; -static PyObject *__pyx_n_s_xrange; -static PyObject *__pyx_n_s_y1; -static PyObject *__pyx_n_s_y2; -static PyObject *__pyx_n_s_yoff; -static PyObject *__pyx_n_u_yoff; -static int __pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster___init__(CYTHON_UNUSED struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self, PyObject *__pyx_v_raster_path, PyObject *__pyx_v_band_id, CYTHON_UNUSED PyObject *__pyx_v_write_mode); /* proto */ -static int __pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_2__cinit__(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__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_9watershed_14_ManagedRaster_4__dealloc__(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_6close(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ -static PyObject *__pyx_pf_15pygeoprocessing_7routing_9watershed__is_raster_path_band_formatted(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_raster_path_band); /* proto */ -static PyObject *__pyx_pf_15pygeoprocessing_7routing_9watershed_2_split_geometry_into_seeds(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_source_geom_wkb, PyObject *__pyx_v_geotransform, PyObject *__pyx_v_flow_dir_srs, PyObject *__pyx_v_flow_dir_n_cols, PyObject *__pyx_v_flow_dir_n_rows, PyObject *__pyx_v_target_raster_path, PyObject *__pyx_v_diagnostic_vector_path); /* proto */ -static PyObject *__pyx_pf_15pygeoprocessing_7routing_9watershed_4delineate_watersheds_d8(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_d8_flow_dir_raster_path_band, PyObject *__pyx_v_outflow_vector_path, PyObject *__pyx_v_target_watersheds_vector_path, PyObject *__pyx_v_working_dir, PyObject *__pyx_v_write_diagnostic_vector, PyObject *__pyx_v_remove_temp_files, PyObject *__pyx_v_target_layer_name); /* proto */ -static PyObject *__pyx_tp_new_15pygeoprocessing_7routing_9watershed__ManagedRaster(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ -static PyObject *__pyx_int_0; -static PyObject *__pyx_int_1; -static PyObject *__pyx_int_24; -static PyObject *__pyx_tuple__2; -static PyObject *__pyx_tuple__3; -static PyObject *__pyx_tuple__4; -static PyObject *__pyx_tuple__5; -static PyObject *__pyx_tuple__6; -static PyObject *__pyx_tuple__8; -static PyObject *__pyx_tuple__11; -static PyObject *__pyx_codeobj__7; -static PyObject *__pyx_codeobj__9; -static PyObject *__pyx_codeobj__12; -/* Late includes */ - -/* "pygeoprocessing/routing/watershed.pyx":87 - * cdef int closed - * - * def __init__(self, raster_path, band_id, write_mode): # <<<<<<<<<<<<<< - * """Create new instance of Managed Raster. - * - */ - -/* Python wrapper */ -static int __pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_15pygeoprocessing_7routing_9watershed_14_ManagedRaster___init__[] = "Create new instance of Managed Raster.\n\n Parameters:\n raster_path (char*): path to raster that has block sizes that are\n powers of 2. If not, an exception is raised.\n band_id (int): which band in `raster_path` to index. Uses GDAL\n notation that starts at 1.\n write_mode (boolean): if true, this raster is writable and dirty\n memory blocks will be written back to the raster as blocks\n are swapped out of the cache or when the object deconstructs.\n\n Returns:\n None.\n "; -#if CYTHON_COMPILING_IN_CPYTHON -struct wrapperbase __pyx_wrapperbase_15pygeoprocessing_7routing_9watershed_14_ManagedRaster___init__; -#endif -static int __pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_raster_path = 0; - PyObject *__pyx_v_band_id = 0; - CYTHON_UNUSED PyObject *__pyx_v_write_mode = 0; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__init__ (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("__init__", 1, 3, 3, 1); __PYX_ERR(0, 87, __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("__init__", 1, 3, 3, 2); __PYX_ERR(0, 87, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 87, __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("__init__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 87, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pygeoprocessing.routing.watershed._ManagedRaster.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster___init__(((struct __pyx_obj_15pygeoprocessing_7routing_9watershed__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_9watershed_14_ManagedRaster___init__(CYTHON_UNUSED struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self, PyObject *__pyx_v_raster_path, PyObject *__pyx_v_band_id, CYTHON_UNUSED PyObject *__pyx_v_write_mode) { - PyObject *__pyx_v_raster_info = NULL; - PyObject *__pyx_v_err_msg = NULL; - PyObject *__pyx_v_block_xsize = NULL; - PyObject *__pyx_v_block_ysize = NULL; - int __pyx_r; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - PyObject *(*__pyx_t_8)(PyObject *); - Py_ssize_t __pyx_t_9; - Py_UCS4 __pyx_t_10; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__init__", 0); - - /* "pygeoprocessing/routing/watershed.pyx":102 - * None. - * """ - * if not os.path.isfile(raster_path): # <<<<<<<<<<<<<< - * LOGGER.error("%s is not a file.", raster_path) - * raise OSError('%s is not a file.' % raster_path) - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 102, __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, 102, __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, 102, __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); - } - } - __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_raster_path); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 102, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __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, 102, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_5 = ((!__pyx_t_4) != 0); - if (unlikely(__pyx_t_5)) { - - /* "pygeoprocessing/routing/watershed.pyx":103 - * """ - * if not os.path.isfile(raster_path): - * LOGGER.error("%s is not a file.", raster_path) # <<<<<<<<<<<<<< - * raise OSError('%s is not a file.' % raster_path) - * raster_info = pygeoprocessing.get_raster_info(raster_path) - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 103, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_error); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 103, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - __pyx_t_6 = 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_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_kp_u_s_is_not_a_file, __pyx_v_raster_path}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 103, __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_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_kp_u_s_is_not_a_file, __pyx_v_raster_path}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 103, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 103, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_2) { - __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2); __pyx_t_2 = NULL; - } - __Pyx_INCREF(__pyx_kp_u_s_is_not_a_file); - __Pyx_GIVEREF(__pyx_kp_u_s_is_not_a_file); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_kp_u_s_is_not_a_file); - __Pyx_INCREF(__pyx_v_raster_path); - __Pyx_GIVEREF(__pyx_v_raster_path); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_raster_path); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 103, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":104 - * if not os.path.isfile(raster_path): - * LOGGER.error("%s is not a file.", raster_path) - * raise OSError('%s is not a file.' % raster_path) # <<<<<<<<<<<<<< - * raster_info = pygeoprocessing.get_raster_info(raster_path) - * - */ - __pyx_t_1 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_s_is_not_a_file, __pyx_v_raster_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 104, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_OSError, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 104, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 104, __pyx_L1_error) - - /* "pygeoprocessing/routing/watershed.pyx":102 - * None. - * """ - * if not os.path.isfile(raster_path): # <<<<<<<<<<<<<< - * LOGGER.error("%s is not a file.", raster_path) - * raise OSError('%s is not a file.' % raster_path) - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":105 - * LOGGER.error("%s is not a file.", raster_path) - * raise OSError('%s is not a file.' % raster_path) - * raster_info = pygeoprocessing.get_raster_info(raster_path) # <<<<<<<<<<<<<< - * - * if not (1 <= band_id <= raster_info['n_bands']): - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 105, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 105, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_3 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_1, __pyx_v_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_raster_path); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 105, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_raster_info = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":107 - * raster_info = pygeoprocessing.get_raster_info(raster_path) - * - * if not (1 <= band_id <= raster_info['n_bands']): # <<<<<<<<<<<<<< - * err_msg = ( - * "Error: band ID (%s) is not a valid band number. " - */ - __pyx_t_3 = PyObject_RichCompare(__pyx_int_1, __pyx_v_band_id, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 107, __pyx_L1_error) - if (__Pyx_PyObject_IsTrue(__pyx_t_3)) { - __Pyx_DECREF(__pyx_t_3); - __pyx_t_7 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_n_bands); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 107, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_band_id, __pyx_t_7, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 107, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 107, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_4 = ((!__pyx_t_5) != 0); - if (unlikely(__pyx_t_4)) { - - /* "pygeoprocessing/routing/watershed.pyx":112 - * "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)) # <<<<<<<<<<<<<< - * LOGGER.error(err_msg) - * raise ValueError(err_msg) - */ - __pyx_t_3 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_Error_band_ID_s_is_not_a_valid_b, __pyx_v_band_id); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 112, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_err_msg = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":113 - * "hard seg-fault, but it's otherwise meant to be a " - * "ValueError." % (band_id)) - * LOGGER.error(err_msg) # <<<<<<<<<<<<<< - * raise ValueError(err_msg) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 113, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_error); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 113, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __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); - } - } - __pyx_t_3 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_7, __pyx_v_err_msg) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_err_msg); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 113, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":114 - * "ValueError." % (band_id)) - * LOGGER.error(err_msg) - * raise ValueError(err_msg) # <<<<<<<<<<<<<< - * - * block_xsize, block_ysize = raster_info['block_size'] - */ - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_v_err_msg); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 114, __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, 114, __pyx_L1_error) - - /* "pygeoprocessing/routing/watershed.pyx":107 - * raster_info = pygeoprocessing.get_raster_info(raster_path) - * - * if not (1 <= band_id <= raster_info['n_bands']): # <<<<<<<<<<<<<< - * err_msg = ( - * "Error: band ID (%s) is not a valid band number. " - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":116 - * raise ValueError(err_msg) - * - * block_xsize, block_ysize = raster_info['block_size'] # <<<<<<<<<<<<<< - * if (block_xsize & (block_xsize - 1) != 0) or ( - * block_ysize & (block_ysize - 1) != 0): - */ - __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_u_block_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 116, __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, 116, __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, 116, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 116, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - #endif - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 116, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_2)->tp_iternext; - index = 0; __pyx_t_1 = __pyx_t_8(__pyx_t_2); if (unlikely(!__pyx_t_1)) goto __pyx_L5_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - index = 1; __pyx_t_7 = __pyx_t_8(__pyx_t_2); if (unlikely(!__pyx_t_7)) goto __pyx_L5_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_2), 2) < 0) __PYX_ERR(0, 116, __pyx_L1_error) - __pyx_t_8 = NULL; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L6_unpacking_done; - __pyx_L5_unpacking_failed:; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_8 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 116, __pyx_L1_error) - __pyx_L6_unpacking_done:; - } - __pyx_v_block_xsize = __pyx_t_1; - __pyx_t_1 = 0; - __pyx_v_block_ysize = __pyx_t_7; - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":117 - * - * block_xsize, block_ysize = raster_info['block_size'] - * if (block_xsize & (block_xsize - 1) != 0) or ( # <<<<<<<<<<<<<< - * block_ysize & (block_ysize - 1) != 0): - * # If inputs are not a power of two, this will at least print - */ - __pyx_t_3 = __Pyx_PyInt_SubtractObjC(__pyx_v_block_xsize, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 117, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = PyNumber_And(__pyx_v_block_xsize, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 117, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyInt_NeObjC(__pyx_t_7, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 117, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 117, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (!__pyx_t_5) { - } else { - __pyx_t_4 = __pyx_t_5; - goto __pyx_L8_bool_binop_done; - } - - /* "pygeoprocessing/routing/watershed.pyx":118 - * block_xsize, block_ysize = raster_info['block_size'] - * if (block_xsize & (block_xsize - 1) != 0) or ( - * block_ysize & (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_3 = __Pyx_PyInt_SubtractObjC(__pyx_v_block_ysize, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 118, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = PyNumber_And(__pyx_v_block_ysize, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 118, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyInt_NeObjC(__pyx_t_7, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 118, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 118, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_4 = __pyx_t_5; - __pyx_L8_bool_binop_done:; - - /* "pygeoprocessing/routing/watershed.pyx":117 - * - * block_xsize, block_ysize = raster_info['block_size'] - * if (block_xsize & (block_xsize - 1) != 0) or ( # <<<<<<<<<<<<<< - * block_ysize & (block_ysize - 1) != 0): - * # If inputs are not a power of two, this will at least print - */ - if (unlikely(__pyx_t_4)) { - - /* "pygeoprocessing/routing/watershed.pyx":124 - * # ValueError in here at least for readability. - * err_msg = ( - * "Error: Block size is not a power of two: " # <<<<<<<<<<<<<< - * "block_xsize: %d, %d, %s. This exception is happening" - * "in Cython, so it will cause a hard seg-fault, but it's" - */ - __pyx_t_3 = PyTuple_New(7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 124, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_9 = 0; - __pyx_t_10 = 127; - __Pyx_INCREF(__pyx_kp_u_Error_Block_size_is_not_a_power); - __pyx_t_9 += 54; - __Pyx_GIVEREF(__pyx_kp_u_Error_Block_size_is_not_a_power); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_u_Error_Block_size_is_not_a_power); - - /* "pygeoprocessing/routing/watershed.pyx":128 - * "in Cython, so it will cause a hard seg-fault, but it's" - * "otherwise meant to be a ValueError." % ( - * block_xsize, block_ysize, raster_path)) # <<<<<<<<<<<<<< - * LOGGER.error(err_msg) - * raise ValueError(err_msg) - */ - __pyx_t_7 = __Pyx_PyObject_FormatAndDecref(__Pyx_PyNumber_IntOrLong(__pyx_v_block_xsize), __pyx_n_u_d); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 128, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_10 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_10) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_10; - __pyx_t_9 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_INCREF(__pyx_kp_u_); - __pyx_t_9 += 2; - __Pyx_GIVEREF(__pyx_kp_u_); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_kp_u_); - __pyx_t_7 = __Pyx_PyObject_FormatAndDecref(__Pyx_PyNumber_IntOrLong(__pyx_v_block_ysize), __pyx_n_u_d); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 128, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_10 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_10) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_10; - __pyx_t_9 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_INCREF(__pyx_kp_u_); - __pyx_t_9 += 2; - __Pyx_GIVEREF(__pyx_kp_u_); - PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_kp_u_); - __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_raster_path), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 128, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_10 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_10) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_10; - __pyx_t_9 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_3, 5, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_INCREF(__pyx_kp_u_This_exception_is_happeningin_C); - __pyx_t_9 += 118; - __Pyx_GIVEREF(__pyx_kp_u_This_exception_is_happeningin_C); - PyTuple_SET_ITEM(__pyx_t_3, 6, __pyx_kp_u_This_exception_is_happeningin_C); - - /* "pygeoprocessing/routing/watershed.pyx":124 - * # ValueError in here at least for readability. - * err_msg = ( - * "Error: Block size is not a power of two: " # <<<<<<<<<<<<<< - * "block_xsize: %d, %d, %s. This exception is happening" - * "in Cython, so it will cause a hard seg-fault, but it's" - */ - __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_3, 7, __pyx_t_9, __pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 124, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_err_msg = ((PyObject*)__pyx_t_7); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":129 - * "otherwise meant to be a ValueError." % ( - * block_xsize, block_ysize, raster_path)) - * LOGGER.error(err_msg) # <<<<<<<<<<<<<< - * raise ValueError(err_msg) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 129, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_error); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 129, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __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); - } - } - __pyx_t_7 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_3, __pyx_v_err_msg) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_err_msg); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 129, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":130 - * block_xsize, block_ysize, raster_path)) - * LOGGER.error(err_msg) - * raise ValueError(err_msg) # <<<<<<<<<<<<<< - * - * def __cinit__(self, raster_path, band_id, write_mode): - */ - __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_v_err_msg); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 130, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_Raise(__pyx_t_7, 0, 0, 0); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __PYX_ERR(0, 130, __pyx_L1_error) - - /* "pygeoprocessing/routing/watershed.pyx":117 - * - * block_xsize, block_ysize = raster_info['block_size'] - * if (block_xsize & (block_xsize - 1) != 0) or ( # <<<<<<<<<<<<<< - * block_ysize & (block_ysize - 1) != 0): - * # If inputs are not a power of two, this will at least print - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":87 - * cdef int closed - * - * def __init__(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_7); - __Pyx_AddTraceback("pygeoprocessing.routing.watershed._ManagedRaster.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_raster_info); - __Pyx_XDECREF(__pyx_v_err_msg); - __Pyx_XDECREF(__pyx_v_block_xsize); - __Pyx_XDECREF(__pyx_v_block_ysize); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pygeoprocessing/routing/watershed.pyx":132 - * raise ValueError(err_msg) - * - * def __cinit__(self, raster_path, band_id, write_mode): # <<<<<<<<<<<<<< - * """Create new instance of Managed Raster. - * - */ - -/* Python wrapper */ -static int __pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_3__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_3__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_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 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, 132, __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, 132, __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, 132, __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, 132, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pygeoprocessing.routing.watershed._ManagedRaster.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_2__cinit__(((struct __pyx_obj_15pygeoprocessing_7routing_9watershed__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_9watershed_14_ManagedRaster_2__cinit__(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__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; - 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; - PyObject *(*__pyx_t_5)(PyObject *); - int __pyx_t_6; - int __pyx_t_7; - long __pyx_t_8; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "pygeoprocessing/routing/watershed.pyx":147 - * None. - * """ - * 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 147, __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, 147, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - 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_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_raster_path); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 147, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_raster_info = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":148 - * """ - * 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_u_raster_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 148, __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, 148, __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, 148, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 148, __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, 148, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext; - index = 0; __pyx_t_3 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L3_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - index = 1; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L3_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) __PYX_ERR(0, 148, __pyx_L1_error) - __pyx_t_5 = NULL; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L4_unpacking_done; - __pyx_L3_unpacking_failed:; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_5 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 148, __pyx_L1_error) - __pyx_L4_unpacking_done:; - } - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 148, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 148, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_self->raster_x_size = __pyx_t_6; - __pyx_v_self->raster_y_size = __pyx_t_7; - - /* "pygeoprocessing/routing/watershed.pyx":149 - * 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_u_block_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 149, __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, 149, __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, 149, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 149, __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, 149, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext; - index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L5_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - index = 1; __pyx_t_3 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L5_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) __PYX_ERR(0, 149, __pyx_L1_error) - __pyx_t_5 = NULL; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L6_unpacking_done; - __pyx_L5_unpacking_failed:; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_5 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 149, __pyx_L1_error) - __pyx_L6_unpacking_done:; - } - __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 149, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 149, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_self->block_xsize = __pyx_t_7; - __pyx_v_self->block_ysize = __pyx_t_6; - - /* "pygeoprocessing/routing/watershed.pyx":150 - * 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/watershed.pyx":151 - * self.block_xsize, self.block_ysize = raster_info['block_size'] - * self.block_xmod = self.block_xsize-1 - * self.block_ymod = self.block_ysize-1 # <<<<<<<<<<<<<< - * - * self.band_id = band_id - */ - __pyx_v_self->block_ymod = (__pyx_v_self->block_ysize - 1); - - /* "pygeoprocessing/routing/watershed.pyx":153 - * self.block_ymod = self.block_ysize-1 - * - * self.band_id = band_id # <<<<<<<<<<<<<< - * - * self.block_xbits = numpy.log2(self.block_xsize) - */ - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_v_band_id); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 153, __pyx_L1_error) - __pyx_v_self->band_id = __pyx_t_6; - - /* "pygeoprocessing/routing/watershed.pyx":155 - * self.band_id = band_id - * - * self.block_xbits = numpy.log2(self.block_xsize) # <<<<<<<<<<<<<< - * self.block_ybits = numpy.log2(self.block_ysize) - * self.block_nx = ( - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 155, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_log2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 155, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->block_xsize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 155, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 155, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 155, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_self->block_xbits = __pyx_t_6; - - /* "pygeoprocessing/routing/watershed.pyx":156 - * - * 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 156, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_log2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 156, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->block_ysize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 156, __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); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 156, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 156, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_self->block_ybits = __pyx_t_6; - - /* "pygeoprocessing/routing/watershed.pyx":158 - * 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_8 = ((__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, 158, __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_8))) { - PyErr_SetString(PyExc_OverflowError, "value too large to perform division"); - __PYX_ERR(0, 158, __pyx_L1_error) - } - - /* "pygeoprocessing/routing/watershed.pyx":157 - * 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_8, __pyx_v_self->block_xsize); - - /* "pygeoprocessing/routing/watershed.pyx":160 - * 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, int*](MANAGED_RASTER_N_BLOCKS) - */ - __pyx_t_8 = ((__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, 160, __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_8))) { - PyErr_SetString(PyExc_OverflowError, "value too large to perform division"); - __PYX_ERR(0, 160, __pyx_L1_error) - } - - /* "pygeoprocessing/routing/watershed.pyx":159 - * 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_8, __pyx_v_self->block_ysize); - - /* "pygeoprocessing/routing/watershed.pyx":162 - * self.raster_y_size + (self.block_ysize) - 1) // self.block_ysize - * - * self.lru_cache = new LRUCache[int, int*](MANAGED_RASTER_N_BLOCKS) # <<<<<<<<<<<<<< - * self.raster_path = raster_path - * self.write_mode = write_mode - */ - __pyx_v_self->lru_cache = new LRUCache (__pyx_v_15pygeoprocessing_7routing_9watershed_MANAGED_RASTER_N_BLOCKS); - - /* "pygeoprocessing/routing/watershed.pyx":163 - * - * self.lru_cache = new LRUCache[int, int*](MANAGED_RASTER_N_BLOCKS) - * self.raster_path = raster_path # <<<<<<<<<<<<<< - * self.write_mode = write_mode - * self.closed = 0 - */ - __pyx_t_1 = __pyx_v_raster_path; - __Pyx_INCREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->raster_path); - __Pyx_DECREF(__pyx_v_self->raster_path); - __pyx_v_self->raster_path = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":164 - * self.lru_cache = new LRUCache[int, int*](MANAGED_RASTER_N_BLOCKS) - * self.raster_path = raster_path - * self.write_mode = write_mode # <<<<<<<<<<<<<< - * self.closed = 0 - * - */ - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_v_write_mode); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 164, __pyx_L1_error) - __pyx_v_self->write_mode = __pyx_t_6; - - /* "pygeoprocessing/routing/watershed.pyx":165 - * self.raster_path = raster_path - * self.write_mode = write_mode - * self.closed = 0 # <<<<<<<<<<<<<< - * - * def __dealloc__(self): - */ - __pyx_v_self->closed = 0; - - /* "pygeoprocessing/routing/watershed.pyx":132 - * raise ValueError(err_msg) - * - * 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_AddTraceback("pygeoprocessing.routing.watershed._ManagedRaster.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_raster_info); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pygeoprocessing/routing/watershed.pyx":167 - * self.closed = 0 - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * """Deallocate _ManagedRaster. - * - */ - -/* Python wrapper */ -static void __pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_5__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_5__dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_4__dealloc__(((struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); -} - -static void __pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_4__dealloc__(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self) { - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__dealloc__", 0); - - /* "pygeoprocessing/routing/watershed.pyx":173 - * 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, 173, __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); - } - } - __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 173, __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/watershed.pyx":167 - * 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.watershed._ManagedRaster.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); - __pyx_L0:; - __Pyx_RefNannyFinishContext(); -} - -/* "pygeoprocessing/routing/watershed.pyx":175 - * self.close() - * - * def close(self): # <<<<<<<<<<<<<< - * """Close the _ManagedRaster and free up resources. - * - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_7close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_6close[] = "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_9watershed_14_ManagedRaster_7close(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_9watershed_14_ManagedRaster_6close(((struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_6close(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self) { - int __pyx_v_xi_copy; - int __pyx_v_yi_copy; - PyArrayObject *__pyx_v_block_array = 0; - int *__pyx_v_int_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_9watershed_BlockBufferPair> ::iterator __pyx_v_it; - std::list<__pyx_t_15pygeoprocessing_7routing_9watershed_BlockBufferPair> ::iterator __pyx_v_end; - PyObject *__pyx_v_raster = NULL; - PyObject *__pyx_v_raster_band = NULL; - std::set ::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; - int *__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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __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/watershed.pyx":184 - * have undefined behavior. - * """ - * if self.closed: # <<<<<<<<<<<<<< - * return - * self.closed = 1 - */ - __pyx_t_1 = (__pyx_v_self->closed != 0); - if (__pyx_t_1) { - - /* "pygeoprocessing/routing/watershed.pyx":185 - * """ - * 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/watershed.pyx":184 - * have undefined behavior. - * """ - * if self.closed: # <<<<<<<<<<<<<< - * return - * self.closed = 1 - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":186 - * if self.closed: - * return - * self.closed = 1 # <<<<<<<<<<<<<< - * cdef int xi_copy, yi_copy - * cdef numpy.ndarray[int, ndim=2] block_array = numpy.empty( - */ - __pyx_v_self->closed = 1; - - /* "pygeoprocessing/routing/watershed.pyx":188 - * self.closed = 1 - * cdef int xi_copy, yi_copy - * cdef numpy.ndarray[int, ndim=2] block_array = numpy.empty( # <<<<<<<<<<<<<< - * (self.block_ysize, self.block_xsize), dtype=numpy.int32) - * cdef int *int_buffer - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 188, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 188, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":189 - * cdef int xi_copy, yi_copy - * cdef numpy.ndarray[int, ndim=2] block_array = numpy.empty( - * (self.block_ysize, self.block_xsize), dtype=numpy.int32) # <<<<<<<<<<<<<< - * cdef int *int_buffer - * cdef int block_xi - */ - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->block_ysize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 189, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_self->block_xsize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 189, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 189, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4); - __pyx_t_2 = 0; - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":188 - * self.closed = 1 - * cdef int xi_copy, yi_copy - * cdef numpy.ndarray[int, ndim=2] block_array = numpy.empty( # <<<<<<<<<<<<<< - * (self.block_ysize, self.block_xsize), dtype=numpy.int32) - * cdef int *int_buffer - */ - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 188, __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 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":189 - * cdef int xi_copy, yi_copy - * cdef numpy.ndarray[int, ndim=2] block_array = numpy.empty( - * (self.block_ysize, self.block_xsize), dtype=numpy.int32) # <<<<<<<<<<<<<< - * cdef int *int_buffer - * cdef int block_xi - */ - __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 189, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 189, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int32); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 189, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 189, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":188 - * self.closed = 1 - * cdef int xi_copy, yi_copy - * cdef numpy.ndarray[int, ndim=2] block_array = numpy.empty( # <<<<<<<<<<<<<< - * (self.block_ysize, self.block_xsize), dtype=numpy.int32) - * cdef int *int_buffer - */ - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 188, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 188, __pyx_L1_error) - __pyx_t_7 = ((PyArrayObject *)__pyx_t_6); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_block_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_int, 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, 188, __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_6); - __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":202 - * 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/watershed.pyx":203 - * - * 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/watershed.pyx":204 - * 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/watershed.pyx":205 - * 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/watershed.pyx":207 - * 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/watershed.pyx":208 - * # write the changed value back if desired - * PyMem_Free(deref(it).second) - * inc(it) # <<<<<<<<<<<<<< - * return - * - */ - (void)((++__pyx_v_it)); - } - - /* "pygeoprocessing/routing/watershed.pyx":209 - * 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/watershed.pyx":204 - * 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/watershed.pyx":211 - * return - * - * raster = gdal.OpenEx( # <<<<<<<<<<<<<< - * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) - * raster_band = raster.GetRasterBand(self.band_id) - */ - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_gdal); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 211, __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, 211, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":212 - * - * raster = gdal.OpenEx( - * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) # <<<<<<<<<<<<<< - * raster_band = raster.GetRasterBand(self.band_id) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_gdal); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 212, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_GA_Update); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 212, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_gdal); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 212, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 212, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyNumber_Or(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 212, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - __pyx_t_8 = 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_8 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_self->raster_path, __pyx_t_5}; - __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 211, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 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_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_self->raster_path, __pyx_t_5}; - __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 211, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - { - __pyx_t_3 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 211, __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_v_self->raster_path); - __Pyx_GIVEREF(__pyx_v_self->raster_path); - PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_8, __pyx_v_self->raster_path); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_8, __pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 211, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_raster = __pyx_t_6; - __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":213 - * 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_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 213, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->band_id); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 213, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = NULL; - 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_6 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 213, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_raster_band = __pyx_t_6; - __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":217 - * # if we get here, we're in write_mode - * cdef cset[int].iterator dirty_itr - * while it != end: # <<<<<<<<<<<<<< - * int_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/watershed.pyx":218 - * cdef cset[int].iterator dirty_itr - * while it != end: - * int_buffer = deref(it).second # <<<<<<<<<<<<<< - * block_index = deref(it).first - * - */ - __pyx_t_9 = (*__pyx_v_it).second; - __pyx_v_int_buffer = __pyx_t_9; - - /* "pygeoprocessing/routing/watershed.pyx":219 - * while it != end: - * int_buffer = deref(it).second - * block_index = deref(it).first # <<<<<<<<<<<<<< - * - * # write to disk if block is dirty - */ - __pyx_t_6 = __Pyx_PyInt_From_int((*__pyx_v_it).first); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 219, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_XDECREF_SET(__pyx_v_block_index, __pyx_t_6); - __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":222 - * - * # 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, 222, __pyx_L1_error) - __pyx_v_dirty_itr = __pyx_v_self->dirty_blocks.find(__pyx_t_8); - - /* "pygeoprocessing/routing/watershed.pyx":223 - * # 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/watershed.pyx":224 - * 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 - */ - (void)(__pyx_v_self->dirty_blocks.erase(__pyx_v_dirty_itr)); - - /* "pygeoprocessing/routing/watershed.pyx":225 - * 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_6 = __Pyx_PyInt_From_int(__pyx_v_self->block_nx); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 225, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_4 = PyNumber_Remainder(__pyx_v_block_index, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 225, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 225, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_block_xi = __pyx_t_8; - - /* "pygeoprocessing/routing/watershed.pyx":226 - * 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_4 = __Pyx_PyInt_From_int(__pyx_v_self->block_nx); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 226, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = __Pyx_PyNumber_Divide(__pyx_v_block_index, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 226, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 226, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_block_yi = __pyx_t_8; - - /* "pygeoprocessing/routing/watershed.pyx":230 - * # 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/watershed.pyx":231 - * # 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/watershed.pyx":233 - * 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/watershed.pyx":234 - * - * 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/watershed.pyx":237 - * - * # 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/watershed.pyx":238 - * # 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/watershed.pyx":237 - * - * # 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/watershed.pyx":240 - * 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/watershed.pyx":241 - * 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/watershed.pyx":240 - * 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/watershed.pyx":244 - * yoff+win_ysize - self.raster_y_size) - * - * for xi_copy in xrange(win_xsize): # <<<<<<<<<<<<<< - * for yi_copy in xrange(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/watershed.pyx":245 - * - * for xi_copy in xrange(win_xsize): - * for yi_copy in xrange(win_ysize): # <<<<<<<<<<<<<< - * block_array[yi_copy, xi_copy] = ( - * int_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/watershed.pyx":246 - * for xi_copy in xrange(win_xsize): - * for yi_copy in xrange(win_ysize): - * block_array[yi_copy, xi_copy] = ( # <<<<<<<<<<<<<< - * int_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, 246, __pyx_L1_error) - } - *__Pyx_BufPtrStrided2d(int *, __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_int_buffer[((__pyx_v_yi_copy << __pyx_v_self->block_xbits) + __pyx_v_xi_copy)]); - } - } - - /* "pygeoprocessing/routing/watershed.pyx":249 - * int_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_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster_band, __pyx_n_s_WriteArray); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 249, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - - /* "pygeoprocessing/routing/watershed.pyx":250 - * (yi_copy << self.block_xbits) + xi_copy]) - * raster_band.WriteArray( - * block_array[0:win_ysize, 0:win_xsize], # <<<<<<<<<<<<<< - * xoff=xoff, yoff=yoff) - * PyMem_Free(int_buffer) - */ - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PySlice_New(__pyx_int_0, __pyx_t_4, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PySlice_New(__pyx_int_0, __pyx_t_4, Py_None); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5); - __pyx_t_3 = 0; - __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_block_array), __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":249 - * int_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 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 249, __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 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":251 - * raster_band.WriteArray( - * block_array[0:win_ysize, 0:win_xsize], - * xoff=xoff, yoff=yoff) # <<<<<<<<<<<<<< - * PyMem_Free(int_buffer) - * inc(it) - */ - __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 251, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_xoff); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 251, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_xoff, __pyx_t_3) < 0) __PYX_ERR(0, 251, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_yoff); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 251, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_yoff, __pyx_t_3) < 0) __PYX_ERR(0, 251, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":249 - * int_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 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 249, __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; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":223 - * # 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/watershed.pyx":252 - * block_array[0:win_ysize, 0:win_xsize], - * xoff=xoff, yoff=yoff) - * PyMem_Free(int_buffer) # <<<<<<<<<<<<<< - * inc(it) - * raster_band.FlushCache() - */ - PyMem_Free(__pyx_v_int_buffer); - - /* "pygeoprocessing/routing/watershed.pyx":253 - * xoff=xoff, yoff=yoff) - * PyMem_Free(int_buffer) - * inc(it) # <<<<<<<<<<<<<< - * raster_band.FlushCache() - * raster_band = None - */ - (void)((++__pyx_v_it)); - } - - /* "pygeoprocessing/routing/watershed.pyx":254 - * PyMem_Free(int_buffer) - * inc(it) - * raster_band.FlushCache() # <<<<<<<<<<<<<< - * raster_band = None - * raster = None - */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster_band, __pyx_n_s_FlushCache); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 254, __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); - } - } - __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 254, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":255 - * 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/watershed.pyx":256 - * raster_band.FlushCache() - * raster_band = None - * raster = None # <<<<<<<<<<<<<< - * - * cdef inline void set(self, int xi, int yi, int value): - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_raster, Py_None); - - /* "pygeoprocessing/routing/watershed.pyx":175 - * 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.watershed._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/watershed.pyx":258 - * raster = None - * - * cdef inline void set(self, int xi, int yi, int value): # <<<<<<<<<<<<<< - * """Set the pixel at `xi,yi` to `value`.""" - * cdef int block_xi = xi >> self.block_xbits - */ - -static CYTHON_INLINE void __pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_set(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self, int __pyx_v_xi, int __pyx_v_yi, int __pyx_v_value) { - int __pyx_v_block_xi; - int __pyx_v_block_yi; - int __pyx_v_block_index; - std::set ::iterator __pyx_v_dirty_itr; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("set", 0); - - /* "pygeoprocessing/routing/watershed.pyx":260 - * cdef inline void set(self, int xi, int yi, int value): - * """Set the pixel at `xi,yi` to `value`.""" - * 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/watershed.pyx":261 - * """Set the pixel at `xi,yi` to `value`.""" - * 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/watershed.pyx":263 - * 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/watershed.pyx":264 - * # 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/watershed.pyx":265 - * 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_9watershed__ManagedRaster *)__pyx_v_self->__pyx_vtab)->_load_block(__pyx_v_self, __pyx_v_block_index); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 265, __pyx_L1_error) - - /* "pygeoprocessing/routing/watershed.pyx":264 - * # 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/watershed.pyx":268 - * self.lru_cache.get( - * block_index)[ - * ((yi & (self.block_ymod))<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/watershed.pyx":270 - * ((yi & (self.block_ymod))<write_mode != 0); - if (__pyx_t_1) { - - /* "pygeoprocessing/routing/watershed.pyx":271 - * (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/watershed.pyx":272 - * 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/watershed.pyx":273 - * dirty_itr = self.dirty_blocks.find(block_index) - * if dirty_itr == self.dirty_blocks.end(): - * self.dirty_blocks.insert(block_index) # <<<<<<<<<<<<<< - * - * cdef inline int get(self, int xi, int yi): - */ - try { - __pyx_v_self->dirty_blocks.insert(__pyx_v_block_index); - } catch(...) { - __Pyx_CppExn2PyErr(); - __PYX_ERR(0, 273, __pyx_L1_error) - } - - /* "pygeoprocessing/routing/watershed.pyx":272 - * 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/watershed.pyx":270 - * ((yi & (self.block_ymod))<> self.block_xbits - */ - - /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_WriteUnraisable("pygeoprocessing.routing.watershed._ManagedRaster.set", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); - __pyx_L0:; - __Pyx_RefNannyFinishContext(); -} - -/* "pygeoprocessing/routing/watershed.pyx":275 - * self.dirty_blocks.insert(block_index) - * - * cdef inline int get(self, int xi, int yi): # <<<<<<<<<<<<<< - * """Return the value of the pixel at `xi,yi`.""" - * cdef int block_xi = xi >> self.block_xbits - */ - -static CYTHON_INLINE int __pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_get(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__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; - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("get", 0); - - /* "pygeoprocessing/routing/watershed.pyx":277 - * cdef inline int get(self, int xi, int yi): - * """Return the value of the pixel at `xi,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/watershed.pyx":278 - * """Return the value of the pixel at `xi,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/watershed.pyx":280 - * 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/watershed.pyx":281 - * # 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/watershed.pyx":282 - * 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_9watershed__ManagedRaster *)__pyx_v_self->__pyx_vtab)->_load_block(__pyx_v_self, __pyx_v_block_index); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 282, __pyx_L1_error) - - /* "pygeoprocessing/routing/watershed.pyx":281 - * # 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/watershed.pyx":284 - * self._load_block(block_index) - * return self.lru_cache.get( - * block_index)[ # <<<<<<<<<<<<<< - * ((yi & (self.block_ymod))<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/watershed.pyx":275 - * self.dirty_blocks.insert(block_index) - * - * cdef inline int get(self, int xi, int yi): # <<<<<<<<<<<<<< - * """Return the value of the pixel at `xi,yi`.""" - * cdef int block_xi = xi >> self.block_xbits - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_WriteUnraisable("pygeoprocessing.routing.watershed._ManagedRaster.get", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pygeoprocessing/routing/watershed.pyx":288 - * (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_9watershed_14_ManagedRaster__load_block(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__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; - int *__pyx_v_int_buffer; - std::list<__pyx_t_15pygeoprocessing_7routing_9watershed_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 ::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; - int *__pyx_t_20; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __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/watershed.pyx":289 - * - * 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, 289, __pyx_L1_error) - } - __pyx_v_block_xi = __Pyx_mod_int(__pyx_v_block_index, __pyx_v_self->block_nx); - - /* "pygeoprocessing/routing/watershed.pyx":290 - * 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, 290, __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, 290, __pyx_L1_error) - } - __pyx_v_block_yi = __Pyx_div_int(__pyx_v_block_index, __pyx_v_self->block_nx); - - /* "pygeoprocessing/routing/watershed.pyx":293 - * - * # 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/watershed.pyx":294 - * # 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/watershed.pyx":305 - * # 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/watershed.pyx":306 - * # 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/watershed.pyx":309 - * - * # 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/watershed.pyx":310 - * # 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/watershed.pyx":309 - * - * # 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/watershed.pyx":311 - * 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/watershed.pyx":312 - * 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/watershed.pyx":311 - * 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/watershed.pyx":314 - * 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_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 314, __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, 314, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 314, __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, 314, __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, 314, __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, 314, __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, 314, __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, 314, __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/watershed.pyx":315 - * - * 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, 315, __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, 315, __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); - } - } - __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_7); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 315, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_raster_band = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":316 - * 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( - */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 316, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - - /* "pygeoprocessing/routing/watershed.pyx":317 - * 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.int32) - */ - __pyx_t_7 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 317, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_xoff); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 317, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_xoff, __pyx_t_6) < 0) __PYX_ERR(0, 317, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_yoff); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 317, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_yoff, __pyx_t_6) < 0) __PYX_ERR(0, 317, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 317, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_win_xsize, __pyx_t_6) < 0) __PYX_ERR(0, 317, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":318 - * block_array = raster_band.ReadAsArray( - * xoff=xoff, yoff=yoff, win_xsize=win_xsize, - * win_ysize=win_ysize).astype( # <<<<<<<<<<<<<< - * numpy.int32) - * raster_band = None - */ - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 318, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_win_ysize, __pyx_t_6) < 0) __PYX_ERR(0, 317, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":316 - * 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( - */ - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_empty_tuple, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 316, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":318 - * block_array = raster_band.ReadAsArray( - * xoff=xoff, yoff=yoff, win_xsize=win_xsize, - * win_ysize=win_ysize).astype( # <<<<<<<<<<<<<< - * numpy.int32) - * raster_band = None - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_astype); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 318, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":319 - * xoff=xoff, yoff=yoff, win_xsize=win_xsize, - * win_ysize=win_ysize).astype( - * numpy.int32) # <<<<<<<<<<<<<< - * raster_band = None - * raster = None - */ - __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_numpy); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 319, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int32); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 319, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 318, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":318 - * block_array = raster_band.ReadAsArray( - * xoff=xoff, yoff=yoff, win_xsize=win_xsize, - * win_ysize=win_ysize).astype( # <<<<<<<<<<<<<< - * numpy.int32) - * raster_band = None - */ - if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 318, __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_int, 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_int, 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, 316, __pyx_L1_error) - } - __pyx_t_8 = 0; - __pyx_v_block_array = ((PyArrayObject *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":320 - * win_ysize=win_ysize).astype( - * numpy.int32) - * raster_band = None # <<<<<<<<<<<<<< - * raster = None - * int_buffer = PyMem_Malloc( - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_raster_band, Py_None); - - /* "pygeoprocessing/routing/watershed.pyx":321 - * numpy.int32) - * raster_band = None - * raster = None # <<<<<<<<<<<<<< - * int_buffer = PyMem_Malloc( - * (sizeof(int) << self.block_xbits) * win_ysize) - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_raster, Py_None); - - /* "pygeoprocessing/routing/watershed.pyx":322 - * raster_band = None - * raster = None - * int_buffer = PyMem_Malloc( # <<<<<<<<<<<<<< - * (sizeof(int) << self.block_xbits) * win_ysize) - * for xi_copy in xrange(win_xsize): - */ - __pyx_v_int_buffer = ((int *)PyMem_Malloc((((sizeof(int)) << __pyx_v_self->block_xbits) * __pyx_v_win_ysize))); - - /* "pygeoprocessing/routing/watershed.pyx":324 - * int_buffer = PyMem_Malloc( - * (sizeof(int) << self.block_xbits) * win_ysize) - * for xi_copy in xrange(win_xsize): # <<<<<<<<<<<<<< - * for yi_copy in xrange(win_ysize): - * int_buffer[(yi_copy<block_index, int_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, 327, __pyx_L1_error) - } - - /* "pygeoprocessing/routing/watershed.pyx":326 - * for xi_copy in xrange(win_xsize): - * for yi_copy in xrange(win_ysize): - * int_buffer[(yi_copy<block_xbits) + __pyx_v_xi_copy)]) = (*__Pyx_BufPtrStrided2d(int *, __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/watershed.pyx":328 - * int_buffer[(yi_copy<block_index, int_buffer, removed_value_list) - * - */ - __pyx_v_self->lru_cache->put(((int)__pyx_v_block_index), ((int *)__pyx_v_int_buffer), __pyx_v_removed_value_list); - - /* "pygeoprocessing/routing/watershed.pyx":331 - * block_index, int_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/watershed.pyx":332 - * - * if self.write_mode: - * raster = gdal.OpenEx( # <<<<<<<<<<<<<< - * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) - * raster_band = raster.GetRasterBand(self.band_id) - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 332, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 332, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":333 - * if self.write_mode: - * raster = gdal.OpenEx( - * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) # <<<<<<<<<<<<<< - * raster_band = raster.GetRasterBand(self.band_id) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 333, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_GA_Update); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 333, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 333, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 333, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyNumber_Or(__pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 333, __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_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_7}; - __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, 332, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 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[3] = {__pyx_t_4, __pyx_v_self->raster_path, __pyx_t_7}; - __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, 332, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - { - __pyx_t_6 = PyTuple_New(2+__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 332, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (__pyx_t_4) { - __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 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_6, 0+__pyx_t_1, __pyx_v_self->raster_path); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_1, __pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 332, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF_SET(__pyx_v_raster, __pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":334 - * 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_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 334, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_self->band_id); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 334, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - } - } - __pyx_t_3 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 334, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF_SET(__pyx_v_raster_band, __pyx_t_3); - __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":331 - * block_index, int_buffer, removed_value_list) - * - * if self.write_mode: # <<<<<<<<<<<<<< - * raster = gdal.OpenEx( - * self.raster_path, gdal.GA_Update | gdal.OF_RASTER) - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":336 - * raster_band = raster.GetRasterBand(self.band_id) - * - * block_array = numpy.empty( # <<<<<<<<<<<<<< - * (self.block_ysize, self.block_xsize), dtype=numpy.int32) - * while not removed_value_list.empty(): - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 336, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 336, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":337 - * - * block_array = numpy.empty( - * (self.block_ysize, self.block_xsize), dtype=numpy.int32) # <<<<<<<<<<<<<< - * 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, 337, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_self->block_xsize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 337, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 337, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6); - __pyx_t_3 = 0; - __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":336 - * raster_band = raster.GetRasterBand(self.band_id) - * - * block_array = numpy.empty( # <<<<<<<<<<<<<< - * (self.block_ysize, self.block_xsize), dtype=numpy.int32) - * while not removed_value_list.empty(): - */ - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 336, __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 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":337 - * - * block_array = numpy.empty( - * (self.block_ysize, self.block_xsize), dtype=numpy.int32) # <<<<<<<<<<<<<< - * while not removed_value_list.empty(): - * # write the changed value back if desired - */ - __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 337, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 337, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int32); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 337, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 337, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":336 - * raster_band = raster.GetRasterBand(self.band_id) - * - * block_array = numpy.empty( # <<<<<<<<<<<<<< - * (self.block_ysize, self.block_xsize), dtype=numpy.int32) - * while not removed_value_list.empty(): - */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 336, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __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; - if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 336, __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_int, 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_int, 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, 336, __pyx_L1_error) - } - __pyx_t_8 = 0; - __Pyx_DECREF_SET(__pyx_v_block_array, ((PyArrayObject *)__pyx_t_4)); - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":338 - * block_array = numpy.empty( - * (self.block_ysize, self.block_xsize), dtype=numpy.int32) - * while not removed_value_list.empty(): # <<<<<<<<<<<<<< - * # write the changed value back if desired - * int_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/watershed.pyx":340 - * while not removed_value_list.empty(): - * # write the changed value back if desired - * int_buffer = removed_value_list.front().second # <<<<<<<<<<<<<< - * - * if self.write_mode: - */ - __pyx_t_20 = __pyx_v_removed_value_list.front().second; - __pyx_v_int_buffer = __pyx_t_20; - - /* "pygeoprocessing/routing/watershed.pyx":342 - * int_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/watershed.pyx":343 - * - * 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/watershed.pyx":346 - * - * # 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/watershed.pyx":347 - * # 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/watershed.pyx":348 - * 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 - */ - (void)(__pyx_v_self->dirty_blocks.erase(__pyx_v_dirty_itr)); - - /* "pygeoprocessing/routing/watershed.pyx":350 - * 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, 350, __pyx_L1_error) - } - __pyx_v_block_xi = __Pyx_mod_int(__pyx_v_block_index, __pyx_v_self->block_nx); - - /* "pygeoprocessing/routing/watershed.pyx":351 - * - * 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, 351, __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, 351, __pyx_L1_error) - } - __pyx_v_block_yi = __Pyx_div_int(__pyx_v_block_index, __pyx_v_self->block_nx); - - /* "pygeoprocessing/routing/watershed.pyx":353 - * 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/watershed.pyx":354 - * - * 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/watershed.pyx":356 - * 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/watershed.pyx":357 - * - * 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/watershed.pyx":359 - * 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/watershed.pyx":360 - * - * 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/watershed.pyx":359 - * 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/watershed.pyx":362 - * 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/watershed.pyx":363 - * 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/watershed.pyx":362 - * 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/watershed.pyx":366 - * yoff+win_ysize - self.raster_y_size) - * - * for xi_copy in xrange(win_xsize): # <<<<<<<<<<<<<< - * for yi_copy in xrange(win_ysize): - * block_array[yi_copy, xi_copy] = int_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/watershed.pyx":367 - * - * for xi_copy in xrange(win_xsize): - * for yi_copy in xrange(win_ysize): # <<<<<<<<<<<<<< - * block_array[yi_copy, xi_copy] = int_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/watershed.pyx":368 - * for xi_copy in xrange(win_xsize): - * for yi_copy in xrange(win_ysize): - * block_array[yi_copy, xi_copy] = int_buffer[ # <<<<<<<<<<<<<< - * (yi_copy << self.block_xbits) + xi_copy] - * raster_band.WriteArray( - */ - __pyx_t_18 = __pyx_v_yi_copy; - __pyx_t_17 = __pyx_v_xi_copy; - __pyx_t_19 = -1; - if (__pyx_t_18 < 0) { - __pyx_t_18 += __pyx_pybuffernd_block_array.diminfo[0].shape; - if (unlikely(__pyx_t_18 < 0)) __pyx_t_19 = 0; - } else if (unlikely(__pyx_t_18 >= __pyx_pybuffernd_block_array.diminfo[0].shape)) __pyx_t_19 = 0; - if (__pyx_t_17 < 0) { - __pyx_t_17 += __pyx_pybuffernd_block_array.diminfo[1].shape; - if (unlikely(__pyx_t_17 < 0)) __pyx_t_19 = 1; - } else if (unlikely(__pyx_t_17 >= __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, 368, __pyx_L1_error) - } - *__Pyx_BufPtrStrided2d(int *, __pyx_pybuffernd_block_array.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_block_array.diminfo[0].strides, __pyx_t_17, __pyx_pybuffernd_block_array.diminfo[1].strides) = (__pyx_v_int_buffer[((__pyx_v_yi_copy << __pyx_v_self->block_xbits) + __pyx_v_xi_copy)]); - } - } - - /* "pygeoprocessing/routing/watershed.pyx":370 - * block_array[yi_copy, xi_copy] = int_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, 370, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - - /* "pygeoprocessing/routing/watershed.pyx":371 - * (yi_copy << self.block_xbits) + xi_copy] - * raster_band.WriteArray( - * block_array[0:win_ysize, 0:win_xsize], # <<<<<<<<<<<<<< - * xoff=xoff, yoff=yoff) - * PyMem_Free(int_buffer) - */ - __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 371, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_6 = PySlice_New(__pyx_int_0, __pyx_t_7, Py_None); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 371, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __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, 371, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_5 = PySlice_New(__pyx_int_0, __pyx_t_7, Py_None); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 371, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 371, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_5); - __pyx_t_6 = 0; - __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_block_array), __pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 371, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":370 - * block_array[yi_copy, xi_copy] = int_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 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 370, __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/watershed.pyx":372 - * raster_band.WriteArray( - * block_array[0:win_ysize, 0:win_xsize], - * xoff=xoff, yoff=yoff) # <<<<<<<<<<<<<< - * PyMem_Free(int_buffer) - * removed_value_list.pop_front() - */ - __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 372, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_xoff); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 372, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_xoff, __pyx_t_6) < 0) __PYX_ERR(0, 372, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_yoff); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 372, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_yoff, __pyx_t_6) < 0) __PYX_ERR(0, 372, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":370 - * block_array[yi_copy, xi_copy] = int_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_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 370, __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_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":347 - * # 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/watershed.pyx":342 - * int_buffer = removed_value_list.front().second - * - * if self.write_mode: # <<<<<<<<<<<<<< - * block_index = removed_value_list.front().first - * - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":373 - * block_array[0:win_ysize, 0:win_xsize], - * xoff=xoff, yoff=yoff) - * PyMem_Free(int_buffer) # <<<<<<<<<<<<<< - * removed_value_list.pop_front() - * - */ - PyMem_Free(__pyx_v_int_buffer); - - /* "pygeoprocessing/routing/watershed.pyx":374 - * xoff=xoff, yoff=yoff) - * PyMem_Free(int_buffer) - * removed_value_list.pop_front() # <<<<<<<<<<<<<< - * - * if self.write_mode: - */ - __pyx_v_removed_value_list.pop_front(); - } - - /* "pygeoprocessing/routing/watershed.pyx":376 - * 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/watershed.pyx":377 - * - * if self.write_mode: - * raster_band = None # <<<<<<<<<<<<<< - * raster = None - * - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_raster_band, Py_None); - - /* "pygeoprocessing/routing/watershed.pyx":378 - * if self.write_mode: - * raster_band = None - * raster = None # <<<<<<<<<<<<<< - * - * - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_raster, Py_None); - - /* "pygeoprocessing/routing/watershed.pyx":376 - * removed_value_list.pop_front() - * - * if self.write_mode: # <<<<<<<<<<<<<< - * raster_band = None - * raster = None - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":288 - * (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.watershed._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_9watershed_14_ManagedRaster_9__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_9__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_9watershed_14_ManagedRaster_8__reduce_cython__(((struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __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__2, 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.watershed._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_9watershed_14_ManagedRaster_11__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static PyObject *__pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_11__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_9watershed_14_ManagedRaster_10__setstate_cython__(((struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __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__3, 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.watershed._ManagedRaster.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pygeoprocessing/routing/watershed.pyx":388 - * - * - * 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_9watershed_1_is_raster_path_band_formatted(PyObject *__pyx_self, PyObject *__pyx_v_raster_path_band); /*proto*/ -static char __pyx_doc_15pygeoprocessing_7routing_9watershed__is_raster_path_band_formatted[] = "Return true if raster path band is a (str, int) tuple/list."; -static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_9watershed_1_is_raster_path_band_formatted = {"_is_raster_path_band_formatted", (PyCFunction)__pyx_pw_15pygeoprocessing_7routing_9watershed_1_is_raster_path_band_formatted, METH_O, __pyx_doc_15pygeoprocessing_7routing_9watershed__is_raster_path_band_formatted}; -static PyObject *__pyx_pw_15pygeoprocessing_7routing_9watershed_1_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_9watershed__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_9watershed__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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("_is_raster_path_band_formatted", 0); - - /* "pygeoprocessing/routing/watershed.pyx":390 - * 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/watershed.pyx":391 - * """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/watershed.pyx":390 - * 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/watershed.pyx":392 - * 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, 392, __pyx_L1_error) - __pyx_t_2 = ((__pyx_t_4 != 2) != 0); - if (__pyx_t_2) { - - /* "pygeoprocessing/routing/watershed.pyx":393 - * 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/watershed.pyx":392 - * 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/watershed.pyx":394 - * 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, 394, __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/watershed.pyx":395 - * 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/watershed.pyx":394 - * 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/watershed.pyx":396 - * 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, 396, __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/watershed.pyx":397 - * 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/watershed.pyx":396 - * elif not isinstance(raster_path_band[0], basestring): - * return False - * elif not isinstance(raster_path_band[1], int): # <<<<<<<<<<<<<< - * return False - * else: - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":399 - * return False - * else: - * return True # <<<<<<<<<<<<<< - * - * - */ - /*else*/ { - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(Py_True); - __pyx_r = Py_True; - goto __pyx_L0; - } - - /* "pygeoprocessing/routing/watershed.pyx":388 - * - * - * 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.watershed._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; -} - -/* "pygeoprocessing/routing/watershed.pyx":402 - * - * - * cdef cset[CoordinatePair] _c_split_geometry_into_seeds( # <<<<<<<<<<<<<< - * source_geom_wkb, tuple flow_dir_geotransform, flow_dir_srs, - * flow_dir_n_cols, flow_dir_n_rows, - */ - -static std::set<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> __pyx_f_15pygeoprocessing_7routing_9watershed__c_split_geometry_into_seeds(PyObject *__pyx_v_source_geom_wkb, PyObject *__pyx_v_flow_dir_geotransform, PyObject *__pyx_v_flow_dir_srs, PyObject *__pyx_v_flow_dir_n_cols, PyObject *__pyx_v_flow_dir_n_rows, PyObject *__pyx_v_target_raster_path, struct __pyx_opt_args_15pygeoprocessing_7routing_9watershed__c_split_geometry_into_seeds *__pyx_optional_args) { - - /* "pygeoprocessing/routing/watershed.pyx":405 - * source_geom_wkb, tuple flow_dir_geotransform, flow_dir_srs, - * flow_dir_n_cols, flow_dir_n_rows, - * target_raster_path, diagnostic_vector_path=None): # <<<<<<<<<<<<<< - * """Split a geometry into 'seeds' of (x, y) coordinate pairs. - * - */ - PyObject *__pyx_v_diagnostic_vector_path = ((PyObject *)Py_None); - float __pyx_v_minx; - float __pyx_v_miny; - float __pyx_v_maxx; - float __pyx_v_maxy; - double __pyx_v_x_origin; - double __pyx_v_y_origin; - double __pyx_v_x_pixelwidth; - double __pyx_v_y_pixelwidth; - double __pyx_v_flow_dir_maxx; - double __pyx_v_flow_dir_miny; - std::set<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> __pyx_v_seed_set; - PyObject *__pyx_v_geometry = NULL; - int __pyx_v_minx_pixelcoord; - int __pyx_v_miny_pixelcoord; - int __pyx_v_maxx_pixelcoord; - int __pyx_v_maxy_pixelcoord; - PyObject *__pyx_v_seed = NULL; - double __pyx_v_minx_aligned; - double __pyx_v_miny_aligned; - double __pyx_v_maxx_aligned; - double __pyx_v_maxy_aligned; - double __pyx_v_local_n_cols; - double __pyx_v_local_n_rows; - PyObject *__pyx_v_memory_driver = NULL; - PyObject *__pyx_v_new_vector = NULL; - PyObject *__pyx_v_new_layer = NULL; - PyObject *__pyx_v_new_feature = NULL; - double __pyx_v_local_origin_x; - double __pyx_v_local_origin_y; - PyObject *__pyx_v_local_geotransform = NULL; - PyObject *__pyx_v_gtiff_driver = NULL; - PyObject *__pyx_v_raster = NULL; - int __pyx_v_write_diagnostic_vector; - PyObject *__pyx_v_diagnostic_vector = NULL; - PyObject *__pyx_v_diagnostic_layer = NULL; - PyObject *__pyx_v_gpkg_driver = NULL; - PyObject *__pyx_v_user_geometry_layer = NULL; - PyObject *__pyx_v_user_feature = NULL; - int __pyx_v_row; - int __pyx_v_col; - int __pyx_v_global_row; - int __pyx_v_global_col; - int __pyx_v_seed_raster_origin_col; - int __pyx_v_seed_raster_origin_row; - PyObject *__pyx_v_block_info = 0; - int __pyx_v_block_xoff; - int __pyx_v_block_yoff; - PyArrayObject *__pyx_v_seed_array = 0; - npy_intp __pyx_v_n_rows; - npy_intp __pyx_v_n_cols; - __Pyx_LocalBuf_ND __pyx_pybuffernd_seed_array; - __Pyx_Buffer __pyx_pybuffer_seed_array; - std::set<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> __pyx_r; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - double __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; - PyObject *(*__pyx_t_8)(PyObject *); - float __pyx_t_9; - float __pyx_t_10; - float __pyx_t_11; - float __pyx_t_12; - int __pyx_t_13; - int __pyx_t_14; - __pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair __pyx_t_15; - double __pyx_t_16; - double __pyx_t_17; - long __pyx_t_18; - int __pyx_t_19; - PyObject *__pyx_t_20 = NULL; - Py_ssize_t __pyx_t_21; - PyObject *(*__pyx_t_22)(PyObject *); - PyArrayObject *__pyx_t_23 = NULL; - PyObject *__pyx_t_24 = NULL; - PyObject *__pyx_t_25 = NULL; - PyObject *__pyx_t_26 = NULL; - npy_intp __pyx_t_27; - npy_intp __pyx_t_28; - npy_intp __pyx_t_29; - npy_intp __pyx_t_30; - int __pyx_t_31; - Py_ssize_t __pyx_t_32; - Py_ssize_t __pyx_t_33; - PyObject *__pyx_t_34 = NULL; - PyObject *__pyx_t_35 = NULL; - PyObject *__pyx_t_36 = NULL; - int __pyx_t_37; - PyObject *__pyx_t_38 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("_c_split_geometry_into_seeds", 0); - if (__pyx_optional_args) { - if (__pyx_optional_args->__pyx_n > 0) { - __pyx_v_diagnostic_vector_path = __pyx_optional_args->diagnostic_vector_path; - } - } - __pyx_pybuffer_seed_array.pybuffer.buf = NULL; - __pyx_pybuffer_seed_array.refcount = 0; - __pyx_pybuffernd_seed_array.data = NULL; - __pyx_pybuffernd_seed_array.rcbuffer = &__pyx_pybuffer_seed_array; - - /* "pygeoprocessing/routing/watershed.pyx":435 - * """ - * cdef float minx, miny, maxx, maxy - * cdef double x_origin = flow_dir_geotransform[0] # <<<<<<<<<<<<<< - * cdef double y_origin = flow_dir_geotransform[3] - * cdef double x_pixelwidth = flow_dir_geotransform[1] - */ - if (unlikely(__pyx_v_flow_dir_geotransform == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 435, __pyx_L1_error) - } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_flow_dir_geotransform, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 435, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 435, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_x_origin = __pyx_t_2; - - /* "pygeoprocessing/routing/watershed.pyx":436 - * cdef float minx, miny, maxx, maxy - * cdef double x_origin = flow_dir_geotransform[0] - * cdef double y_origin = flow_dir_geotransform[3] # <<<<<<<<<<<<<< - * cdef double x_pixelwidth = flow_dir_geotransform[1] - * cdef double y_pixelwidth = flow_dir_geotransform[5] - */ - if (unlikely(__pyx_v_flow_dir_geotransform == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 436, __pyx_L1_error) - } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_flow_dir_geotransform, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 436, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 436, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_y_origin = __pyx_t_2; - - /* "pygeoprocessing/routing/watershed.pyx":437 - * cdef double x_origin = flow_dir_geotransform[0] - * cdef double y_origin = flow_dir_geotransform[3] - * cdef double x_pixelwidth = flow_dir_geotransform[1] # <<<<<<<<<<<<<< - * cdef double y_pixelwidth = flow_dir_geotransform[5] - * cdef double flow_dir_maxx = x_origin + (flow_dir_n_cols * x_pixelwidth) - */ - if (unlikely(__pyx_v_flow_dir_geotransform == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 437, __pyx_L1_error) - } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_flow_dir_geotransform, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 437, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 437, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_x_pixelwidth = __pyx_t_2; - - /* "pygeoprocessing/routing/watershed.pyx":438 - * cdef double y_origin = flow_dir_geotransform[3] - * cdef double x_pixelwidth = flow_dir_geotransform[1] - * cdef double y_pixelwidth = flow_dir_geotransform[5] # <<<<<<<<<<<<<< - * cdef double flow_dir_maxx = x_origin + (flow_dir_n_cols * x_pixelwidth) - * cdef double flow_dir_miny = y_origin + (flow_dir_n_rows * y_pixelwidth) - */ - if (unlikely(__pyx_v_flow_dir_geotransform == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 438, __pyx_L1_error) - } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_flow_dir_geotransform, 5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 438, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 438, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_y_pixelwidth = __pyx_t_2; - - /* "pygeoprocessing/routing/watershed.pyx":439 - * cdef double x_pixelwidth = flow_dir_geotransform[1] - * cdef double y_pixelwidth = flow_dir_geotransform[5] - * cdef double flow_dir_maxx = x_origin + (flow_dir_n_cols * x_pixelwidth) # <<<<<<<<<<<<<< - * cdef double flow_dir_miny = y_origin + (flow_dir_n_rows * y_pixelwidth) - * cdef cset[CoordinatePair] seed_set - */ - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_x_origin); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 439, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyFloat_FromDouble(__pyx_v_x_pixelwidth); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 439, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyNumber_Multiply(__pyx_v_flow_dir_n_cols, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 439, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Add(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 439, __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; - __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 439, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_flow_dir_maxx = __pyx_t_2; - - /* "pygeoprocessing/routing/watershed.pyx":440 - * cdef double y_pixelwidth = flow_dir_geotransform[5] - * cdef double flow_dir_maxx = x_origin + (flow_dir_n_cols * x_pixelwidth) - * cdef double flow_dir_miny = y_origin + (flow_dir_n_rows * y_pixelwidth) # <<<<<<<<<<<<<< - * cdef cset[CoordinatePair] seed_set - * - */ - __pyx_t_3 = PyFloat_FromDouble(__pyx_v_y_origin); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 440, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyFloat_FromDouble(__pyx_v_y_pixelwidth); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 440, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyNumber_Multiply(__pyx_v_flow_dir_n_rows, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 440, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyNumber_Add(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 440, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 440, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_flow_dir_miny = __pyx_t_2; - - /* "pygeoprocessing/routing/watershed.pyx":443 - * cdef cset[CoordinatePair] seed_set - * - * geometry = shapely.wkb.loads(source_geom_wkb) # <<<<<<<<<<<<<< - * - * minx, miny, maxx, maxy = geometry.bounds - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_shapely); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 443, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_wkb); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 443, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_loads); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 443, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_4 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_3, __pyx_v_source_geom_wkb) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_source_geom_wkb); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 443, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_geometry = __pyx_t_4; - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":445 - * geometry = shapely.wkb.loads(source_geom_wkb) - * - * minx, miny, maxx, maxy = geometry.bounds # <<<<<<<<<<<<<< - * cdef int minx_pixelcoord = ((minx - x_origin) // x_pixelwidth) - * cdef int miny_pixelcoord = ((miny - y_origin) // y_pixelwidth) - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_geometry, __pyx_n_s_bounds); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 445, __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 != 4)) { - if (size > 4) __Pyx_RaiseTooManyValuesError(4); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 445, __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); - __pyx_t_5 = PyTuple_GET_ITEM(sequence, 2); - __pyx_t_6 = PyTuple_GET_ITEM(sequence, 3); - } else { - __pyx_t_1 = PyList_GET_ITEM(sequence, 0); - __pyx_t_3 = PyList_GET_ITEM(sequence, 1); - __pyx_t_5 = PyList_GET_ITEM(sequence, 2); - __pyx_t_6 = PyList_GET_ITEM(sequence, 3); - } - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(__pyx_t_6); - #else - { - Py_ssize_t i; - PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_3,&__pyx_t_5,&__pyx_t_6}; - for (i=0; i < 4; i++) { - PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 445, __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_3,&__pyx_t_5,&__pyx_t_6}; - __pyx_t_7 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 445, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; - for (index=0; index < 4; index++) { - PyObject* item = __pyx_t_8(__pyx_t_7); if (unlikely(!item)) goto __pyx_L3_unpacking_failed; - __Pyx_GOTREF(item); - *(temps[index]) = item; - } - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 4) < 0) __PYX_ERR(0, 445, __pyx_L1_error) - __pyx_t_8 = NULL; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L4_unpacking_done; - __pyx_L3_unpacking_failed:; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_8 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 445, __pyx_L1_error) - __pyx_L4_unpacking_done:; - } - __pyx_t_9 = __pyx_PyFloat_AsFloat(__pyx_t_1); if (unlikely((__pyx_t_9 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 445, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_10 = __pyx_PyFloat_AsFloat(__pyx_t_3); if (unlikely((__pyx_t_10 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 445, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_11 = __pyx_PyFloat_AsFloat(__pyx_t_5); if (unlikely((__pyx_t_11 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 445, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_12 = __pyx_PyFloat_AsFloat(__pyx_t_6); if (unlikely((__pyx_t_12 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 445, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_minx = __pyx_t_9; - __pyx_v_miny = __pyx_t_10; - __pyx_v_maxx = __pyx_t_11; - __pyx_v_maxy = __pyx_t_12; - - /* "pygeoprocessing/routing/watershed.pyx":446 - * - * minx, miny, maxx, maxy = geometry.bounds - * cdef int minx_pixelcoord = ((minx - x_origin) // x_pixelwidth) # <<<<<<<<<<<<<< - * cdef int miny_pixelcoord = ((miny - y_origin) // y_pixelwidth) - * cdef int maxx_pixelcoord = ((maxx - x_origin) // x_pixelwidth) - */ - __pyx_t_2 = (__pyx_v_minx - __pyx_v_x_origin); - if (unlikely(__pyx_v_x_pixelwidth == 0)) { - PyErr_SetString(PyExc_ZeroDivisionError, "float division"); - __PYX_ERR(0, 446, __pyx_L1_error) - } - __pyx_v_minx_pixelcoord = ((int)floor(__pyx_t_2 / __pyx_v_x_pixelwidth)); - - /* "pygeoprocessing/routing/watershed.pyx":447 - * minx, miny, maxx, maxy = geometry.bounds - * cdef int minx_pixelcoord = ((minx - x_origin) // x_pixelwidth) - * cdef int miny_pixelcoord = ((miny - y_origin) // y_pixelwidth) # <<<<<<<<<<<<<< - * cdef int maxx_pixelcoord = ((maxx - x_origin) // x_pixelwidth) - * cdef int maxy_pixelcoord = ((maxy - y_origin) // y_pixelwidth) - */ - __pyx_t_2 = (__pyx_v_miny - __pyx_v_y_origin); - if (unlikely(__pyx_v_y_pixelwidth == 0)) { - PyErr_SetString(PyExc_ZeroDivisionError, "float division"); - __PYX_ERR(0, 447, __pyx_L1_error) - } - __pyx_v_miny_pixelcoord = ((int)floor(__pyx_t_2 / __pyx_v_y_pixelwidth)); - - /* "pygeoprocessing/routing/watershed.pyx":448 - * cdef int minx_pixelcoord = ((minx - x_origin) // x_pixelwidth) - * cdef int miny_pixelcoord = ((miny - y_origin) // y_pixelwidth) - * cdef int maxx_pixelcoord = ((maxx - x_origin) // x_pixelwidth) # <<<<<<<<<<<<<< - * cdef int maxy_pixelcoord = ((maxy - y_origin) // y_pixelwidth) - * - */ - __pyx_t_2 = (__pyx_v_maxx - __pyx_v_x_origin); - if (unlikely(__pyx_v_x_pixelwidth == 0)) { - PyErr_SetString(PyExc_ZeroDivisionError, "float division"); - __PYX_ERR(0, 448, __pyx_L1_error) - } - __pyx_v_maxx_pixelcoord = ((int)floor(__pyx_t_2 / __pyx_v_x_pixelwidth)); - - /* "pygeoprocessing/routing/watershed.pyx":449 - * cdef int miny_pixelcoord = ((miny - y_origin) // y_pixelwidth) - * cdef int maxx_pixelcoord = ((maxx - x_origin) // x_pixelwidth) - * cdef int maxy_pixelcoord = ((maxy - y_origin) // y_pixelwidth) # <<<<<<<<<<<<<< - * - * # If the geometry only intersects a single pixel, we can treat it - */ - __pyx_t_2 = (__pyx_v_maxy - __pyx_v_y_origin); - if (unlikely(__pyx_v_y_pixelwidth == 0)) { - PyErr_SetString(PyExc_ZeroDivisionError, "float division"); - __PYX_ERR(0, 449, __pyx_L1_error) - } - __pyx_v_maxy_pixelcoord = ((int)floor(__pyx_t_2 / __pyx_v_y_pixelwidth)); - - /* "pygeoprocessing/routing/watershed.pyx":455 - * # seeds data structure and not have to include it in the disjoint set - * # determination. - * if minx_pixelcoord == maxx_pixelcoord and miny_pixelcoord == maxy_pixelcoord: # <<<<<<<<<<<<<< - * # If the point is over nodata, skip it. - * seed = CoordinatePair(minx_pixelcoord, miny_pixelcoord) - */ - __pyx_t_14 = ((__pyx_v_minx_pixelcoord == __pyx_v_maxx_pixelcoord) != 0); - if (__pyx_t_14) { - } else { - __pyx_t_13 = __pyx_t_14; - goto __pyx_L6_bool_binop_done; - } - __pyx_t_14 = ((__pyx_v_miny_pixelcoord == __pyx_v_maxy_pixelcoord) != 0); - __pyx_t_13 = __pyx_t_14; - __pyx_L6_bool_binop_done:; - if (__pyx_t_13) { - - /* "pygeoprocessing/routing/watershed.pyx":457 - * if minx_pixelcoord == maxx_pixelcoord and miny_pixelcoord == maxy_pixelcoord: - * # If the point is over nodata, skip it. - * seed = CoordinatePair(minx_pixelcoord, miny_pixelcoord) # <<<<<<<<<<<<<< - * seed_set.insert(seed) - * return seed_set - */ - try { - __pyx_t_15 = __pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair(__pyx_v_minx_pixelcoord, __pyx_v_miny_pixelcoord); - } catch(...) { - __Pyx_CppExn2PyErr(); - __PYX_ERR(0, 457, __pyx_L1_error) - } - __pyx_t_4 = __pyx_convert_pair_to_py_long____long(__pyx_t_15); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 457, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_v_seed = __pyx_t_4; - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":458 - * # If the point is over nodata, skip it. - * seed = CoordinatePair(minx_pixelcoord, miny_pixelcoord) - * seed_set.insert(seed) # <<<<<<<<<<<<<< - * return seed_set - * - */ - __pyx_t_15 = __pyx_convert_pair_from_py_long__and_long(__pyx_v_seed); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 458, __pyx_L1_error) - try { - __pyx_v_seed_set.insert(__pyx_t_15); - } catch(...) { - __Pyx_CppExn2PyErr(); - __PYX_ERR(0, 458, __pyx_L1_error) - } - - /* "pygeoprocessing/routing/watershed.pyx":459 - * seed = CoordinatePair(minx_pixelcoord, miny_pixelcoord) - * seed_set.insert(seed) - * return seed_set # <<<<<<<<<<<<<< - * - * # If the geometry's bounding box covers more than one pixel, we need to - */ - __pyx_r = __pyx_v_seed_set; - goto __pyx_L0; - - /* "pygeoprocessing/routing/watershed.pyx":455 - * # seeds data structure and not have to include it in the disjoint set - * # determination. - * if minx_pixelcoord == maxx_pixelcoord and miny_pixelcoord == maxy_pixelcoord: # <<<<<<<<<<<<<< - * # If the point is over nodata, skip it. - * seed = CoordinatePair(minx_pixelcoord, miny_pixelcoord) - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":465 - * cdef double minx_aligned = max( - * x_origin + (minx_pixelcoord * x_pixelwidth), - * x_origin) # <<<<<<<<<<<<<< - * cdef double miny_aligned = max( - * y_origin + ((miny_pixelcoord+1) * y_pixelwidth), - */ - __pyx_t_2 = __pyx_v_x_origin; - - /* "pygeoprocessing/routing/watershed.pyx":464 - * # rasterize it to determine which pixels it intersects. - * cdef double minx_aligned = max( - * x_origin + (minx_pixelcoord * x_pixelwidth), # <<<<<<<<<<<<<< - * x_origin) - * cdef double miny_aligned = max( - */ - __pyx_t_16 = (__pyx_v_x_origin + (__pyx_v_minx_pixelcoord * __pyx_v_x_pixelwidth)); - - /* "pygeoprocessing/routing/watershed.pyx":465 - * cdef double minx_aligned = max( - * x_origin + (minx_pixelcoord * x_pixelwidth), - * x_origin) # <<<<<<<<<<<<<< - * cdef double miny_aligned = max( - * y_origin + ((miny_pixelcoord+1) * y_pixelwidth), - */ - if (((__pyx_t_2 > __pyx_t_16) != 0)) { - __pyx_t_17 = __pyx_t_2; - } else { - __pyx_t_17 = __pyx_t_16; - } - __pyx_v_minx_aligned = __pyx_t_17; - - /* "pygeoprocessing/routing/watershed.pyx":468 - * cdef double miny_aligned = max( - * y_origin + ((miny_pixelcoord+1) * y_pixelwidth), - * flow_dir_miny) # <<<<<<<<<<<<<< - * cdef double maxx_aligned = min( - * x_origin + ((maxx_pixelcoord+1) * x_pixelwidth), - */ - __pyx_t_17 = __pyx_v_flow_dir_miny; - - /* "pygeoprocessing/routing/watershed.pyx":467 - * x_origin) - * cdef double miny_aligned = max( - * y_origin + ((miny_pixelcoord+1) * y_pixelwidth), # <<<<<<<<<<<<<< - * flow_dir_miny) - * cdef double maxx_aligned = min( - */ - __pyx_t_2 = (__pyx_v_y_origin + ((__pyx_v_miny_pixelcoord + 1) * __pyx_v_y_pixelwidth)); - - /* "pygeoprocessing/routing/watershed.pyx":468 - * cdef double miny_aligned = max( - * y_origin + ((miny_pixelcoord+1) * y_pixelwidth), - * flow_dir_miny) # <<<<<<<<<<<<<< - * cdef double maxx_aligned = min( - * x_origin + ((maxx_pixelcoord+1) * x_pixelwidth), - */ - if (((__pyx_t_17 > __pyx_t_2) != 0)) { - __pyx_t_16 = __pyx_t_17; - } else { - __pyx_t_16 = __pyx_t_2; - } - __pyx_v_miny_aligned = __pyx_t_16; - - /* "pygeoprocessing/routing/watershed.pyx":471 - * cdef double maxx_aligned = min( - * x_origin + ((maxx_pixelcoord+1) * x_pixelwidth), - * flow_dir_maxx) # <<<<<<<<<<<<<< - * cdef double maxy_aligned = min( - * y_origin + (maxy_pixelcoord * y_pixelwidth), - */ - __pyx_t_16 = __pyx_v_flow_dir_maxx; - - /* "pygeoprocessing/routing/watershed.pyx":470 - * flow_dir_miny) - * cdef double maxx_aligned = min( - * x_origin + ((maxx_pixelcoord+1) * x_pixelwidth), # <<<<<<<<<<<<<< - * flow_dir_maxx) - * cdef double maxy_aligned = min( - */ - __pyx_t_17 = (__pyx_v_x_origin + ((__pyx_v_maxx_pixelcoord + 1) * __pyx_v_x_pixelwidth)); - - /* "pygeoprocessing/routing/watershed.pyx":471 - * cdef double maxx_aligned = min( - * x_origin + ((maxx_pixelcoord+1) * x_pixelwidth), - * flow_dir_maxx) # <<<<<<<<<<<<<< - * cdef double maxy_aligned = min( - * y_origin + (maxy_pixelcoord * y_pixelwidth), - */ - if (((__pyx_t_16 < __pyx_t_17) != 0)) { - __pyx_t_2 = __pyx_t_16; - } else { - __pyx_t_2 = __pyx_t_17; - } - __pyx_v_maxx_aligned = __pyx_t_2; - - /* "pygeoprocessing/routing/watershed.pyx":474 - * cdef double maxy_aligned = min( - * y_origin + (maxy_pixelcoord * y_pixelwidth), - * y_origin) # <<<<<<<<<<<<<< - * - * # It's possible for a perfectly vertical or horizontal line to cover 0 rows - */ - __pyx_t_2 = __pyx_v_y_origin; - - /* "pygeoprocessing/routing/watershed.pyx":473 - * flow_dir_maxx) - * cdef double maxy_aligned = min( - * y_origin + (maxy_pixelcoord * y_pixelwidth), # <<<<<<<<<<<<<< - * y_origin) - * - */ - __pyx_t_16 = (__pyx_v_y_origin + (__pyx_v_maxy_pixelcoord * __pyx_v_y_pixelwidth)); - - /* "pygeoprocessing/routing/watershed.pyx":474 - * cdef double maxy_aligned = min( - * y_origin + (maxy_pixelcoord * y_pixelwidth), - * y_origin) # <<<<<<<<<<<<<< - * - * # It's possible for a perfectly vertical or horizontal line to cover 0 rows - */ - if (((__pyx_t_2 < __pyx_t_16) != 0)) { - __pyx_t_17 = __pyx_t_2; - } else { - __pyx_t_17 = __pyx_t_16; - } - __pyx_v_maxy_aligned = __pyx_t_17; - - /* "pygeoprocessing/routing/watershed.pyx":478 - * # It's possible for a perfectly vertical or horizontal line to cover 0 rows - * # or columns, so defaulting to row/col count of 1 in these cases. - * local_n_cols = max(abs(maxx_aligned - minx_aligned) // abs(x_pixelwidth), 1) # <<<<<<<<<<<<<< - * local_n_rows = max(abs(maxy_aligned - miny_aligned) // abs(y_pixelwidth), 1) - * - */ - __pyx_t_18 = 1; - __pyx_t_17 = fabs((__pyx_v_maxx_aligned - __pyx_v_minx_aligned)); - __pyx_t_2 = fabs(__pyx_v_x_pixelwidth); - if (unlikely(__pyx_t_2 == 0)) { - PyErr_SetString(PyExc_ZeroDivisionError, "float division"); - __PYX_ERR(0, 478, __pyx_L1_error) - } - __pyx_t_16 = floor(__pyx_t_17 / __pyx_t_2); - if (((__pyx_t_18 > __pyx_t_16) != 0)) { - __pyx_t_2 = __pyx_t_18; - } else { - __pyx_t_2 = __pyx_t_16; - } - __pyx_v_local_n_cols = __pyx_t_2; - - /* "pygeoprocessing/routing/watershed.pyx":479 - * # or columns, so defaulting to row/col count of 1 in these cases. - * local_n_cols = max(abs(maxx_aligned - minx_aligned) // abs(x_pixelwidth), 1) - * local_n_rows = max(abs(maxy_aligned - miny_aligned) // abs(y_pixelwidth), 1) # <<<<<<<<<<<<<< - * - * # The geometry does not fit into a single pixel, so let's create a new - */ - __pyx_t_18 = 1; - __pyx_t_2 = fabs((__pyx_v_maxy_aligned - __pyx_v_miny_aligned)); - __pyx_t_16 = fabs(__pyx_v_y_pixelwidth); - if (unlikely(__pyx_t_16 == 0)) { - PyErr_SetString(PyExc_ZeroDivisionError, "float division"); - __PYX_ERR(0, 479, __pyx_L1_error) - } - __pyx_t_17 = floor(__pyx_t_2 / __pyx_t_16); - if (((__pyx_t_18 > __pyx_t_17) != 0)) { - __pyx_t_16 = __pyx_t_18; - } else { - __pyx_t_16 = __pyx_t_17; - } - __pyx_v_local_n_rows = __pyx_t_16; - - /* "pygeoprocessing/routing/watershed.pyx":483 - * # The geometry does not fit into a single pixel, so let's create a new - * # raster onto which to rasterize it. - * memory_driver = gdal.GetDriverByName('Memory') # <<<<<<<<<<<<<< - * new_vector = memory_driver.Create('mem', 0, 0, 0, gdal.GDT_Unknown) - * new_layer = new_vector.CreateLayer('user_geometry', flow_dir_srs, ogr.wkbUnknown) - */ - __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_gdal); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 483, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_GetDriverByName); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 483, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __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); - } - } - __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_n_u_Memory) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_n_u_Memory); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 483, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_memory_driver = __pyx_t_4; - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":484 - * # raster onto which to rasterize it. - * memory_driver = gdal.GetDriverByName('Memory') - * new_vector = memory_driver.Create('mem', 0, 0, 0, gdal.GDT_Unknown) # <<<<<<<<<<<<<< - * new_layer = new_vector.CreateLayer('user_geometry', flow_dir_srs, ogr.wkbUnknown) - * new_layer.StartTransaction() - */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_memory_driver, __pyx_n_s_Create); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 484, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_gdal); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 484, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_GDT_Unknown); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 484, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = NULL; - __pyx_t_19 = 0; - 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); - __pyx_t_19 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[6] = {__pyx_t_6, __pyx_n_u_mem, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_t_3}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_19, 5+__pyx_t_19); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 484, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_4); - __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[6] = {__pyx_t_6, __pyx_n_u_mem, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_t_3}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_19, 5+__pyx_t_19); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 484, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - { - __pyx_t_1 = PyTuple_New(5+__pyx_t_19); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 484, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (__pyx_t_6) { - __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_6); __pyx_t_6 = NULL; - } - __Pyx_INCREF(__pyx_n_u_mem); - __Pyx_GIVEREF(__pyx_n_u_mem); - PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_19, __pyx_n_u_mem); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_19, __pyx_int_0); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_1, 2+__pyx_t_19, __pyx_int_0); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_1, 3+__pyx_t_19, __pyx_int_0); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_1, 4+__pyx_t_19, __pyx_t_3); - __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, 484, __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_v_new_vector = __pyx_t_4; - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":485 - * memory_driver = gdal.GetDriverByName('Memory') - * new_vector = memory_driver.Create('mem', 0, 0, 0, gdal.GDT_Unknown) - * new_layer = new_vector.CreateLayer('user_geometry', flow_dir_srs, ogr.wkbUnknown) # <<<<<<<<<<<<<< - * new_layer.StartTransaction() - * new_feature = ogr.Feature(new_layer.GetLayerDefn()) - */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_new_vector, __pyx_n_s_CreateLayer); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 485, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 485, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_wkbUnknown); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 485, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - __pyx_t_19 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - __pyx_t_19 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_n_u_user_geometry, __pyx_v_flow_dir_srs, __pyx_t_3}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_19, 3+__pyx_t_19); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 485, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_4); - __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[4] = {__pyx_t_1, __pyx_n_u_user_geometry, __pyx_v_flow_dir_srs, __pyx_t_3}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_19, 3+__pyx_t_19); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 485, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - { - __pyx_t_6 = PyTuple_New(3+__pyx_t_19); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 485, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (__pyx_t_1) { - __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); __pyx_t_1 = NULL; - } - __Pyx_INCREF(__pyx_n_u_user_geometry); - __Pyx_GIVEREF(__pyx_n_u_user_geometry); - PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_19, __pyx_n_u_user_geometry); - __Pyx_INCREF(__pyx_v_flow_dir_srs); - __Pyx_GIVEREF(__pyx_v_flow_dir_srs); - PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_19, __pyx_v_flow_dir_srs); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_19, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 485, __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_v_new_layer = __pyx_t_4; - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":486 - * new_vector = memory_driver.Create('mem', 0, 0, 0, gdal.GDT_Unknown) - * new_layer = new_vector.CreateLayer('user_geometry', flow_dir_srs, ogr.wkbUnknown) - * new_layer.StartTransaction() # <<<<<<<<<<<<<< - * new_feature = ogr.Feature(new_layer.GetLayerDefn()) - * new_feature.SetGeometry(ogr.CreateGeometryFromWkb(source_geom_wkb)) - */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_new_layer, __pyx_n_s_StartTransaction); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 486, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __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); - } - } - __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 486, __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/watershed.pyx":487 - * new_layer = new_vector.CreateLayer('user_geometry', flow_dir_srs, ogr.wkbUnknown) - * new_layer.StartTransaction() - * new_feature = ogr.Feature(new_layer.GetLayerDefn()) # <<<<<<<<<<<<<< - * new_feature.SetGeometry(ogr.CreateGeometryFromWkb(source_geom_wkb)) - * new_layer.CreateFeature(new_feature) - */ - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_ogr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 487, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_Feature); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 487, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_new_layer, __pyx_n_s_GetLayerDefn); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 487, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __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); - } - } - __pyx_t_5 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 487, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(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); - } - } - __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_3, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 487, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_new_feature = __pyx_t_4; - __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":488 - * new_layer.StartTransaction() - * new_feature = ogr.Feature(new_layer.GetLayerDefn()) - * new_feature.SetGeometry(ogr.CreateGeometryFromWkb(source_geom_wkb)) # <<<<<<<<<<<<<< - * new_layer.CreateFeature(new_feature) - * new_layer.CommitTransaction() - */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_new_feature, __pyx_n_s_SetGeometry); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 488, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_ogr); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 488, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_CreateGeometryFromWkb); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 488, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __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); - } - } - __pyx_t_5 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_3, __pyx_v_source_geom_wkb) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_source_geom_wkb); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 488, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - __pyx_t_4 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_1, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 488, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":489 - * new_feature = ogr.Feature(new_layer.GetLayerDefn()) - * new_feature.SetGeometry(ogr.CreateGeometryFromWkb(source_geom_wkb)) - * new_layer.CreateFeature(new_feature) # <<<<<<<<<<<<<< - * new_layer.CommitTransaction() - * - */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_new_layer, __pyx_n_s_CreateFeature); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 489, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_v_new_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_new_feature); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 489, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":490 - * new_feature.SetGeometry(ogr.CreateGeometryFromWkb(source_geom_wkb)) - * new_layer.CreateFeature(new_feature) - * new_layer.CommitTransaction() # <<<<<<<<<<<<<< - * - * local_origin_x = max(minx_aligned, x_origin) - */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_new_layer, __pyx_n_s_CommitTransaction); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 490, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 490, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":492 - * new_layer.CommitTransaction() - * - * local_origin_x = max(minx_aligned, x_origin) # <<<<<<<<<<<<<< - * local_origin_y = min(maxy_aligned, y_origin) - * - */ - __pyx_t_16 = __pyx_v_x_origin; - __pyx_t_17 = __pyx_v_minx_aligned; - if (((__pyx_t_16 > __pyx_t_17) != 0)) { - __pyx_t_2 = __pyx_t_16; - } else { - __pyx_t_2 = __pyx_t_17; - } - __pyx_v_local_origin_x = __pyx_t_2; - - /* "pygeoprocessing/routing/watershed.pyx":493 - * - * local_origin_x = max(minx_aligned, x_origin) - * local_origin_y = min(maxy_aligned, y_origin) # <<<<<<<<<<<<<< - * - * local_geotransform = [ - */ - __pyx_t_2 = __pyx_v_y_origin; - __pyx_t_16 = __pyx_v_maxy_aligned; - if (((__pyx_t_2 < __pyx_t_16) != 0)) { - __pyx_t_17 = __pyx_t_2; - } else { - __pyx_t_17 = __pyx_t_16; - } - __pyx_v_local_origin_y = __pyx_t_17; - - /* "pygeoprocessing/routing/watershed.pyx":496 - * - * local_geotransform = [ - * local_origin_x, flow_dir_geotransform[1], flow_dir_geotransform[2], # <<<<<<<<<<<<<< - * local_origin_y, flow_dir_geotransform[4], flow_dir_geotransform[5]] - * gtiff_driver = gdal.GetDriverByName('GTiff') - */ - __pyx_t_4 = PyFloat_FromDouble(__pyx_v_local_origin_x); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 496, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (unlikely(__pyx_v_flow_dir_geotransform == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 496, __pyx_L1_error) - } - __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v_flow_dir_geotransform, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 496, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (unlikely(__pyx_v_flow_dir_geotransform == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 496, __pyx_L1_error) - } - __pyx_t_5 = __Pyx_GetItemInt_Tuple(__pyx_v_flow_dir_geotransform, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 496, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - - /* "pygeoprocessing/routing/watershed.pyx":497 - * local_geotransform = [ - * local_origin_x, flow_dir_geotransform[1], flow_dir_geotransform[2], - * local_origin_y, flow_dir_geotransform[4], flow_dir_geotransform[5]] # <<<<<<<<<<<<<< - * gtiff_driver = gdal.GetDriverByName('GTiff') - * # Raster is sparse, no need to fill. - */ - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_local_origin_y); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 497, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (unlikely(__pyx_v_flow_dir_geotransform == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 497, __pyx_L1_error) - } - __pyx_t_3 = __Pyx_GetItemInt_Tuple(__pyx_v_flow_dir_geotransform, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 497, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (unlikely(__pyx_v_flow_dir_geotransform == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 497, __pyx_L1_error) - } - __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v_flow_dir_geotransform, 5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 497, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - - /* "pygeoprocessing/routing/watershed.pyx":495 - * local_origin_y = min(maxy_aligned, y_origin) - * - * local_geotransform = [ # <<<<<<<<<<<<<< - * local_origin_x, flow_dir_geotransform[1], flow_dir_geotransform[2], - * local_origin_y, flow_dir_geotransform[4], flow_dir_geotransform[5]] - */ - __pyx_t_20 = PyList_New(6); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 495, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_GIVEREF(__pyx_t_4); - PyList_SET_ITEM(__pyx_t_20, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_6); - PyList_SET_ITEM(__pyx_t_20, 1, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_5); - PyList_SET_ITEM(__pyx_t_20, 2, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_1); - PyList_SET_ITEM(__pyx_t_20, 3, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_3); - PyList_SET_ITEM(__pyx_t_20, 4, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_7); - PyList_SET_ITEM(__pyx_t_20, 5, __pyx_t_7); - __pyx_t_4 = 0; - __pyx_t_6 = 0; - __pyx_t_5 = 0; - __pyx_t_1 = 0; - __pyx_t_3 = 0; - __pyx_t_7 = 0; - __pyx_v_local_geotransform = ((PyObject*)__pyx_t_20); - __pyx_t_20 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":498 - * local_origin_x, flow_dir_geotransform[1], flow_dir_geotransform[2], - * local_origin_y, flow_dir_geotransform[4], flow_dir_geotransform[5]] - * gtiff_driver = gdal.GetDriverByName('GTiff') # <<<<<<<<<<<<<< - * # Raster is sparse, no need to fill. - * raster = gtiff_driver.Create( - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 498, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_GetDriverByName); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 498, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_20 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_7, __pyx_n_u_GTiff) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_n_u_GTiff); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 498, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_gtiff_driver = __pyx_t_20; - __pyx_t_20 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":500 - * gtiff_driver = gdal.GetDriverByName('GTiff') - * # Raster is sparse, no need to fill. - * raster = gtiff_driver.Create( # <<<<<<<<<<<<<< - * target_raster_path, int(local_n_cols), int(local_n_rows), 1, - * gdal.GDT_Byte, options=GTIFF_CREATION_OPTIONS) - */ - __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_v_gtiff_driver, __pyx_n_s_Create); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 500, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - - /* "pygeoprocessing/routing/watershed.pyx":501 - * # Raster is sparse, no need to fill. - * raster = gtiff_driver.Create( - * target_raster_path, int(local_n_cols), int(local_n_rows), 1, # <<<<<<<<<<<<<< - * gdal.GDT_Byte, options=GTIFF_CREATION_OPTIONS) - * raster.SetProjection(flow_dir_srs.ExportToWkt()) - */ - __pyx_t_3 = __Pyx_PyInt_FromDouble(__pyx_v_local_n_cols); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 501, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = __Pyx_PyInt_FromDouble(__pyx_v_local_n_rows); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 501, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - - /* "pygeoprocessing/routing/watershed.pyx":502 - * raster = gtiff_driver.Create( - * target_raster_path, int(local_n_cols), int(local_n_rows), 1, - * gdal.GDT_Byte, options=GTIFF_CREATION_OPTIONS) # <<<<<<<<<<<<<< - * raster.SetProjection(flow_dir_srs.ExportToWkt()) - * raster.SetGeoTransform(local_geotransform) - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 502, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 502, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":500 - * gtiff_driver = gdal.GetDriverByName('GTiff') - * # Raster is sparse, no need to fill. - * raster = gtiff_driver.Create( # <<<<<<<<<<<<<< - * target_raster_path, int(local_n_cols), int(local_n_rows), 1, - * gdal.GDT_Byte, options=GTIFF_CREATION_OPTIONS) - */ - __pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 500, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_target_raster_path); - __Pyx_GIVEREF(__pyx_v_target_raster_path); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_target_raster_path); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_7); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_int_1); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_t_5); - __pyx_t_3 = 0; - __pyx_t_7 = 0; - __pyx_t_5 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":502 - * raster = gtiff_driver.Create( - * target_raster_path, int(local_n_cols), int(local_n_rows), 1, - * gdal.GDT_Byte, options=GTIFF_CREATION_OPTIONS) # <<<<<<<<<<<<<< - * raster.SetProjection(flow_dir_srs.ExportToWkt()) - * raster.SetGeoTransform(local_geotransform) - */ - __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 502, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_GTIFF_CREATION_OPTIONS); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 502, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_options, __pyx_t_7) < 0) __PYX_ERR(0, 502, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":500 - * gtiff_driver = gdal.GetDriverByName('GTiff') - * # Raster is sparse, no need to fill. - * raster = gtiff_driver.Create( # <<<<<<<<<<<<<< - * target_raster_path, int(local_n_cols), int(local_n_rows), 1, - * gdal.GDT_Byte, options=GTIFF_CREATION_OPTIONS) - */ - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_20, __pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 500, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_raster = __pyx_t_7; - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":503 - * target_raster_path, int(local_n_cols), int(local_n_rows), 1, - * gdal.GDT_Byte, options=GTIFF_CREATION_OPTIONS) - * raster.SetProjection(flow_dir_srs.ExportToWkt()) # <<<<<<<<<<<<<< - * raster.SetGeoTransform(local_geotransform) - * - */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster, __pyx_n_s_SetProjection); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 503, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_srs, __pyx_n_s_ExportToWkt); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 503, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_20))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_20); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_20); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_20, function); - } - } - __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_20, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_20); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 503, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __pyx_t_20 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_20)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_20); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - } - } - __pyx_t_7 = (__pyx_t_20) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_20, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_1); - __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 503, __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/watershed.pyx":504 - * gdal.GDT_Byte, options=GTIFF_CREATION_OPTIONS) - * raster.SetProjection(flow_dir_srs.ExportToWkt()) - * raster.SetGeoTransform(local_geotransform) # <<<<<<<<<<<<<< - * - * gdal.RasterizeLayer( - */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster, __pyx_n_s_SetGeoTransform); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 504, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - } - } - __pyx_t_7 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_1, __pyx_v_local_geotransform) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_local_geotransform); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 504, __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/watershed.pyx":506 - * raster.SetGeoTransform(local_geotransform) - * - * gdal.RasterizeLayer( # <<<<<<<<<<<<<< - * raster, [1], new_layer, burn_values=[1], options=['ALL_TOUCHED=True']) - * raster = None - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 506, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_RasterizeLayer); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 506, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":507 - * - * gdal.RasterizeLayer( - * raster, [1], new_layer, burn_values=[1], options=['ALL_TOUCHED=True']) # <<<<<<<<<<<<<< - * raster = None - * - */ - __pyx_t_7 = PyList_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 507, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyList_SET_ITEM(__pyx_t_7, 0, __pyx_int_1); - - /* "pygeoprocessing/routing/watershed.pyx":506 - * raster.SetGeoTransform(local_geotransform) - * - * gdal.RasterizeLayer( # <<<<<<<<<<<<<< - * raster, [1], new_layer, burn_values=[1], options=['ALL_TOUCHED=True']) - * raster = None - */ - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 506, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_raster); - __Pyx_GIVEREF(__pyx_v_raster); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_raster); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_7); - __Pyx_INCREF(__pyx_v_new_layer); - __Pyx_GIVEREF(__pyx_v_new_layer); - PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_new_layer); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":507 - * - * gdal.RasterizeLayer( - * raster, [1], new_layer, burn_values=[1], options=['ALL_TOUCHED=True']) # <<<<<<<<<<<<<< - * raster = None - * - */ - __pyx_t_7 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 507, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_20 = PyList_New(1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 507, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyList_SET_ITEM(__pyx_t_20, 0, __pyx_int_1); - if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_burn_values, __pyx_t_20) < 0) __PYX_ERR(0, 507, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __pyx_t_20 = PyList_New(1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 507, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_INCREF(__pyx_kp_u_ALL_TOUCHED_True); - __Pyx_GIVEREF(__pyx_kp_u_ALL_TOUCHED_True); - PyList_SET_ITEM(__pyx_t_20, 0, __pyx_kp_u_ALL_TOUCHED_True); - if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_options, __pyx_t_20) < 0) __PYX_ERR(0, 507, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":506 - * raster.SetGeoTransform(local_geotransform) - * - * gdal.RasterizeLayer( # <<<<<<<<<<<<<< - * raster, [1], new_layer, burn_values=[1], options=['ALL_TOUCHED=True']) - * raster = None - */ - __pyx_t_20 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_1, __pyx_t_7); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 506, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":508 - * gdal.RasterizeLayer( - * raster, [1], new_layer, burn_values=[1], options=['ALL_TOUCHED=True']) - * raster = None # <<<<<<<<<<<<<< - * - * cdef int write_diagnostic_vector = 0 - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_raster, Py_None); - - /* "pygeoprocessing/routing/watershed.pyx":510 - * raster = None - * - * cdef int write_diagnostic_vector = 0 # <<<<<<<<<<<<<< - * diagnostic_vector = None - * diagnostic_layer = None - */ - __pyx_v_write_diagnostic_vector = 0; - - /* "pygeoprocessing/routing/watershed.pyx":511 - * - * cdef int write_diagnostic_vector = 0 - * diagnostic_vector = None # <<<<<<<<<<<<<< - * diagnostic_layer = None - * if diagnostic_vector_path is not None: - */ - __Pyx_INCREF(Py_None); - __pyx_v_diagnostic_vector = Py_None; - - /* "pygeoprocessing/routing/watershed.pyx":512 - * cdef int write_diagnostic_vector = 0 - * diagnostic_vector = None - * diagnostic_layer = None # <<<<<<<<<<<<<< - * if diagnostic_vector_path is not None: - * write_diagnostic_vector = 1 - */ - __Pyx_INCREF(Py_None); - __pyx_v_diagnostic_layer = Py_None; - - /* "pygeoprocessing/routing/watershed.pyx":513 - * diagnostic_vector = None - * diagnostic_layer = None - * if diagnostic_vector_path is not None: # <<<<<<<<<<<<<< - * write_diagnostic_vector = 1 - * - */ - __pyx_t_13 = (__pyx_v_diagnostic_vector_path != Py_None); - __pyx_t_14 = (__pyx_t_13 != 0); - if (__pyx_t_14) { - - /* "pygeoprocessing/routing/watershed.pyx":514 - * diagnostic_layer = None - * if diagnostic_vector_path is not None: - * write_diagnostic_vector = 1 # <<<<<<<<<<<<<< - * - * gpkg_driver = gdal.GetDriverByName('GPKG') - */ - __pyx_v_write_diagnostic_vector = 1; - - /* "pygeoprocessing/routing/watershed.pyx":516 - * write_diagnostic_vector = 1 - * - * gpkg_driver = gdal.GetDriverByName('GPKG') # <<<<<<<<<<<<<< - * diagnostic_vector = gpkg_driver.Create( - * diagnostic_vector_path, 0, 0, 0, gdal.GDT_Unknown) - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 516, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_GetDriverByName); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 516, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __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); - } - } - __pyx_t_20 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_7, __pyx_n_u_GPKG) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_n_u_GPKG); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 516, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_gpkg_driver = __pyx_t_20; - __pyx_t_20 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":517 - * - * gpkg_driver = gdal.GetDriverByName('GPKG') - * diagnostic_vector = gpkg_driver.Create( # <<<<<<<<<<<<<< - * diagnostic_vector_path, 0, 0, 0, gdal.GDT_Unknown) - * diagnostic_layer = diagnostic_vector.CreateLayer( - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_gpkg_driver, __pyx_n_s_Create); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 517, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/watershed.pyx":518 - * gpkg_driver = gdal.GetDriverByName('GPKG') - * diagnostic_vector = gpkg_driver.Create( - * diagnostic_vector_path, 0, 0, 0, gdal.GDT_Unknown) # <<<<<<<<<<<<<< - * diagnostic_layer = diagnostic_vector.CreateLayer( - * 'seeds', flow_dir_srs, ogr.wkbPoint) - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 518, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_GDT_Unknown); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 518, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - __pyx_t_19 = 0; - if (CYTHON_UNPACK_METHODS && likely(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); - __pyx_t_19 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[6] = {__pyx_t_7, __pyx_v_diagnostic_vector_path, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_t_5}; - __pyx_t_20 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_19, 5+__pyx_t_19); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 517, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_20); - __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[6] = {__pyx_t_7, __pyx_v_diagnostic_vector_path, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_t_5}; - __pyx_t_20 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_19, 5+__pyx_t_19); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 517, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - { - __pyx_t_3 = PyTuple_New(5+__pyx_t_19); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 517, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (__pyx_t_7) { - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_7); __pyx_t_7 = NULL; - } - __Pyx_INCREF(__pyx_v_diagnostic_vector_path); - __Pyx_GIVEREF(__pyx_v_diagnostic_vector_path); - PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_19, __pyx_v_diagnostic_vector_path); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_19, __pyx_int_0); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_3, 2+__pyx_t_19, __pyx_int_0); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_3, 3+__pyx_t_19, __pyx_int_0); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_3, 4+__pyx_t_19, __pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_20 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 517, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF_SET(__pyx_v_diagnostic_vector, __pyx_t_20); - __pyx_t_20 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":519 - * diagnostic_vector = gpkg_driver.Create( - * diagnostic_vector_path, 0, 0, 0, gdal.GDT_Unknown) - * diagnostic_layer = diagnostic_vector.CreateLayer( # <<<<<<<<<<<<<< - * 'seeds', flow_dir_srs, ogr.wkbPoint) - * user_geometry_layer = diagnostic_vector.CreateLayer( - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_diagnostic_vector, __pyx_n_s_CreateLayer); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 519, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/watershed.pyx":520 - * diagnostic_vector_path, 0, 0, 0, gdal.GDT_Unknown) - * diagnostic_layer = diagnostic_vector.CreateLayer( - * 'seeds', flow_dir_srs, ogr.wkbPoint) # <<<<<<<<<<<<<< - * user_geometry_layer = diagnostic_vector.CreateLayer( - * 'user_geometry', flow_dir_srs, ogr.wkbUnknown) - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_ogr); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 520, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_wkbPoint); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 520, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - __pyx_t_19 = 0; - if (CYTHON_UNPACK_METHODS && likely(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_19 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_n_u_seeds, __pyx_v_flow_dir_srs, __pyx_t_5}; - __pyx_t_20 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_19, 3+__pyx_t_19); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 519, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_20); - __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_3, __pyx_n_u_seeds, __pyx_v_flow_dir_srs, __pyx_t_5}; - __pyx_t_20 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_19, 3+__pyx_t_19); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 519, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - { - __pyx_t_7 = PyTuple_New(3+__pyx_t_19); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 519, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_INCREF(__pyx_n_u_seeds); - __Pyx_GIVEREF(__pyx_n_u_seeds); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_19, __pyx_n_u_seeds); - __Pyx_INCREF(__pyx_v_flow_dir_srs); - __Pyx_GIVEREF(__pyx_v_flow_dir_srs); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_19, __pyx_v_flow_dir_srs); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_19, __pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_20 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 519, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF_SET(__pyx_v_diagnostic_layer, __pyx_t_20); - __pyx_t_20 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":521 - * diagnostic_layer = diagnostic_vector.CreateLayer( - * 'seeds', flow_dir_srs, ogr.wkbPoint) - * user_geometry_layer = diagnostic_vector.CreateLayer( # <<<<<<<<<<<<<< - * 'user_geometry', flow_dir_srs, ogr.wkbUnknown) - * user_geometry_layer.StartTransaction() - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_diagnostic_vector, __pyx_n_s_CreateLayer); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 521, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pygeoprocessing/routing/watershed.pyx":522 - * 'seeds', flow_dir_srs, ogr.wkbPoint) - * user_geometry_layer = diagnostic_vector.CreateLayer( - * 'user_geometry', flow_dir_srs, ogr.wkbUnknown) # <<<<<<<<<<<<<< - * user_geometry_layer.StartTransaction() - * user_feature = ogr.Feature(user_geometry_layer.GetLayerDefn()) - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 522, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_wkbUnknown); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 522, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - __pyx_t_19 = 0; - if (CYTHON_UNPACK_METHODS && likely(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); - __pyx_t_19 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_n_u_user_geometry, __pyx_v_flow_dir_srs, __pyx_t_5}; - __pyx_t_20 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_19, 3+__pyx_t_19); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 521, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_20); - __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_7, __pyx_n_u_user_geometry, __pyx_v_flow_dir_srs, __pyx_t_5}; - __pyx_t_20 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_19, 3+__pyx_t_19); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 521, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - { - __pyx_t_3 = PyTuple_New(3+__pyx_t_19); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 521, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (__pyx_t_7) { - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_7); __pyx_t_7 = NULL; - } - __Pyx_INCREF(__pyx_n_u_user_geometry); - __Pyx_GIVEREF(__pyx_n_u_user_geometry); - PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_19, __pyx_n_u_user_geometry); - __Pyx_INCREF(__pyx_v_flow_dir_srs); - __Pyx_GIVEREF(__pyx_v_flow_dir_srs); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_19, __pyx_v_flow_dir_srs); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_3, 2+__pyx_t_19, __pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_20 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 521, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_user_geometry_layer = __pyx_t_20; - __pyx_t_20 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":523 - * user_geometry_layer = diagnostic_vector.CreateLayer( - * 'user_geometry', flow_dir_srs, ogr.wkbUnknown) - * user_geometry_layer.StartTransaction() # <<<<<<<<<<<<<< - * user_feature = ogr.Feature(user_geometry_layer.GetLayerDefn()) - * user_feature.SetGeometry(ogr.CreateGeometryFromWkb(source_geom_wkb)) - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_user_geometry_layer, __pyx_n_s_StartTransaction); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 523, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_20 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 523, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":524 - * 'user_geometry', flow_dir_srs, ogr.wkbUnknown) - * user_geometry_layer.StartTransaction() - * user_feature = ogr.Feature(user_geometry_layer.GetLayerDefn()) # <<<<<<<<<<<<<< - * user_feature.SetGeometry(ogr.CreateGeometryFromWkb(source_geom_wkb)) - * user_geometry_layer.CreateFeature(user_feature) - */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 524, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_Feature); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 524, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_user_geometry_layer, __pyx_n_s_GetLayerDefn); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 524, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - } - } - __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 524, __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_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_20 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 524, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_user_feature = __pyx_t_20; - __pyx_t_20 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":525 - * user_geometry_layer.StartTransaction() - * user_feature = ogr.Feature(user_geometry_layer.GetLayerDefn()) - * user_feature.SetGeometry(ogr.CreateGeometryFromWkb(source_geom_wkb)) # <<<<<<<<<<<<<< - * user_geometry_layer.CreateFeature(user_feature) - * user_geometry_layer.CommitTransaction() - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_user_feature, __pyx_n_s_SetGeometry); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 525, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_ogr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 525, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_CreateGeometryFromWkb); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 525, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __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); - } - } - __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_5, __pyx_v_source_geom_wkb) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_source_geom_wkb); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 525, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_20 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_7, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 525, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":526 - * user_feature = ogr.Feature(user_geometry_layer.GetLayerDefn()) - * user_feature.SetGeometry(ogr.CreateGeometryFromWkb(source_geom_wkb)) - * user_geometry_layer.CreateFeature(user_feature) # <<<<<<<<<<<<<< - * user_geometry_layer.CommitTransaction() - * - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_user_geometry_layer, __pyx_n_s_CreateFeature); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 526, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __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); - } - } - __pyx_t_20 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_1, __pyx_v_user_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_user_feature); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 526, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":527 - * user_feature.SetGeometry(ogr.CreateGeometryFromWkb(source_geom_wkb)) - * user_geometry_layer.CreateFeature(user_feature) - * user_geometry_layer.CommitTransaction() # <<<<<<<<<<<<<< - * - * cdef int row, col - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_user_geometry_layer, __pyx_n_s_CommitTransaction); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 527, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __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); - } - } - __pyx_t_20 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 527, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":513 - * diagnostic_vector = None - * diagnostic_layer = None - * if diagnostic_vector_path is not None: # <<<<<<<<<<<<<< - * write_diagnostic_vector = 1 - * - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":531 - * cdef int row, col - * cdef int global_row, global_col - * cdef int seed_raster_origin_col = ((local_origin_x - x_origin) // x_pixelwidth) # <<<<<<<<<<<<<< - * cdef int seed_raster_origin_row = ((local_origin_y - y_origin) // y_pixelwidth) - * cdef dict block_info - */ - __pyx_t_17 = (__pyx_v_local_origin_x - __pyx_v_x_origin); - if (unlikely(__pyx_v_x_pixelwidth == 0)) { - PyErr_SetString(PyExc_ZeroDivisionError, "float division"); - __PYX_ERR(0, 531, __pyx_L1_error) - } - __pyx_v_seed_raster_origin_col = ((int)floor(__pyx_t_17 / __pyx_v_x_pixelwidth)); - - /* "pygeoprocessing/routing/watershed.pyx":532 - * cdef int global_row, global_col - * cdef int seed_raster_origin_col = ((local_origin_x - x_origin) // x_pixelwidth) - * cdef int seed_raster_origin_row = ((local_origin_y - y_origin) // y_pixelwidth) # <<<<<<<<<<<<<< - * cdef dict block_info - * cdef int block_xoff - */ - __pyx_t_17 = (__pyx_v_local_origin_y - __pyx_v_y_origin); - if (unlikely(__pyx_v_y_pixelwidth == 0)) { - PyErr_SetString(PyExc_ZeroDivisionError, "float division"); - __PYX_ERR(0, 532, __pyx_L1_error) - } - __pyx_v_seed_raster_origin_row = ((int)floor(__pyx_t_17 / __pyx_v_y_pixelwidth)); - - /* "pygeoprocessing/routing/watershed.pyx":537 - * cdef int block_yoff - * cdef numpy.ndarray[numpy.npy_uint8, ndim=2] seed_array - * for block_info, seed_array in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * (target_raster_path, 1)): - * block_xoff = block_info['xoff'] - */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 537, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 537, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":538 - * cdef numpy.ndarray[numpy.npy_uint8, ndim=2] seed_array - * for block_info, seed_array in pygeoprocessing.iterblocks( - * (target_raster_path, 1)): # <<<<<<<<<<<<<< - * block_xoff = block_info['xoff'] - * block_yoff = block_info['yoff'] - */ - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 538, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_target_raster_path); - __Pyx_GIVEREF(__pyx_v_target_raster_path); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_target_raster_path); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_1); - __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); - } - } - __pyx_t_20 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_7, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 537, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":537 - * cdef int block_yoff - * cdef numpy.ndarray[numpy.npy_uint8, ndim=2] seed_array - * for block_info, seed_array in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * (target_raster_path, 1)): - * block_xoff = block_info['xoff'] - */ - if (likely(PyList_CheckExact(__pyx_t_20)) || PyTuple_CheckExact(__pyx_t_20)) { - __pyx_t_1 = __pyx_t_20; __Pyx_INCREF(__pyx_t_1); __pyx_t_21 = 0; - __pyx_t_22 = NULL; - } else { - __pyx_t_21 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_20); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 537, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_22 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 537, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - for (;;) { - if (likely(!__pyx_t_22)) { - if (likely(PyList_CheckExact(__pyx_t_1))) { - if (__pyx_t_21 >= PyList_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_20 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_21); __Pyx_INCREF(__pyx_t_20); __pyx_t_21++; if (unlikely(0 < 0)) __PYX_ERR(0, 537, __pyx_L1_error) - #else - __pyx_t_20 = PySequence_ITEM(__pyx_t_1, __pyx_t_21); __pyx_t_21++; if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 537, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - #endif - } else { - if (__pyx_t_21 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_20 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_21); __Pyx_INCREF(__pyx_t_20); __pyx_t_21++; if (unlikely(0 < 0)) __PYX_ERR(0, 537, __pyx_L1_error) - #else - __pyx_t_20 = PySequence_ITEM(__pyx_t_1, __pyx_t_21); __pyx_t_21++; if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 537, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - #endif - } - } else { - __pyx_t_20 = __pyx_t_22(__pyx_t_1); - if (unlikely(!__pyx_t_20)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 537, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_20); - } - if ((likely(PyTuple_CheckExact(__pyx_t_20))) || (PyList_CheckExact(__pyx_t_20))) { - PyObject* sequence = __pyx_t_20; - 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, 537, __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_7 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_3 = PyList_GET_ITEM(sequence, 0); - __pyx_t_7 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_7); - #else - __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 537, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 537, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - #endif - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_5 = PyObject_GetIter(__pyx_t_20); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 537, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_5)->tp_iternext; - index = 0; __pyx_t_3 = __pyx_t_8(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L11_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - index = 1; __pyx_t_7 = __pyx_t_8(__pyx_t_5); if (unlikely(!__pyx_t_7)) goto __pyx_L11_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_5), 2) < 0) __PYX_ERR(0, 537, __pyx_L1_error) - __pyx_t_8 = NULL; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - goto __pyx_L12_unpacking_done; - __pyx_L11_unpacking_failed:; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_8 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 537, __pyx_L1_error) - __pyx_L12_unpacking_done:; - } - if (!(likely(PyDict_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 537, __pyx_L1_error) - if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 537, __pyx_L1_error) - __Pyx_XDECREF_SET(__pyx_v_block_info, ((PyObject*)__pyx_t_3)); - __pyx_t_3 = 0; - __pyx_t_23 = ((PyArrayObject *)__pyx_t_7); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_seed_array.rcbuffer->pybuffer); - __pyx_t_19 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_seed_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_23, &__Pyx_TypeInfo_nn_npy_uint8, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); - if (unlikely(__pyx_t_19 < 0)) { - PyErr_Fetch(&__pyx_t_24, &__pyx_t_25, &__pyx_t_26); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_seed_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_seed_array, &__Pyx_TypeInfo_nn_npy_uint8, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_24); Py_XDECREF(__pyx_t_25); Py_XDECREF(__pyx_t_26); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_24, __pyx_t_25, __pyx_t_26); - } - __pyx_t_24 = __pyx_t_25 = __pyx_t_26 = 0; - } - __pyx_pybuffernd_seed_array.diminfo[0].strides = __pyx_pybuffernd_seed_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_seed_array.diminfo[0].shape = __pyx_pybuffernd_seed_array.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_seed_array.diminfo[1].strides = __pyx_pybuffernd_seed_array.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_seed_array.diminfo[1].shape = __pyx_pybuffernd_seed_array.rcbuffer->pybuffer.shape[1]; - if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 537, __pyx_L1_error) - } - __pyx_t_23 = 0; - __Pyx_XDECREF_SET(__pyx_v_seed_array, ((PyArrayObject *)__pyx_t_7)); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":539 - * for block_info, seed_array in pygeoprocessing.iterblocks( - * (target_raster_path, 1)): - * block_xoff = block_info['xoff'] # <<<<<<<<<<<<<< - * block_yoff = block_info['yoff'] - * n_rows = seed_array.shape[0] - */ - if (unlikely(__pyx_v_block_info == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 539, __pyx_L1_error) - } - __pyx_t_20 = __Pyx_PyDict_GetItem(__pyx_v_block_info, __pyx_n_u_xoff); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 539, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __pyx_t_19 = __Pyx_PyInt_As_int(__pyx_t_20); if (unlikely((__pyx_t_19 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 539, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __pyx_v_block_xoff = __pyx_t_19; - - /* "pygeoprocessing/routing/watershed.pyx":540 - * (target_raster_path, 1)): - * block_xoff = block_info['xoff'] - * block_yoff = block_info['yoff'] # <<<<<<<<<<<<<< - * n_rows = seed_array.shape[0] - * n_cols = seed_array.shape[1] - */ - if (unlikely(__pyx_v_block_info == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 540, __pyx_L1_error) - } - __pyx_t_20 = __Pyx_PyDict_GetItem(__pyx_v_block_info, __pyx_n_u_yoff); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 540, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __pyx_t_19 = __Pyx_PyInt_As_int(__pyx_t_20); if (unlikely((__pyx_t_19 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 540, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __pyx_v_block_yoff = __pyx_t_19; - - /* "pygeoprocessing/routing/watershed.pyx":541 - * block_xoff = block_info['xoff'] - * block_yoff = block_info['yoff'] - * n_rows = seed_array.shape[0] # <<<<<<<<<<<<<< - * n_cols = seed_array.shape[1] - * - */ - __pyx_v_n_rows = (__pyx_v_seed_array->dimensions[0]); - - /* "pygeoprocessing/routing/watershed.pyx":542 - * block_yoff = block_info['yoff'] - * n_rows = seed_array.shape[0] - * n_cols = seed_array.shape[1] # <<<<<<<<<<<<<< - * - * for row in range(n_rows): - */ - __pyx_v_n_cols = (__pyx_v_seed_array->dimensions[1]); - - /* "pygeoprocessing/routing/watershed.pyx":544 - * n_cols = seed_array.shape[1] - * - * for row in range(n_rows): # <<<<<<<<<<<<<< - * for col in range(n_cols): - * with cython.boundscheck(False): - */ - __pyx_t_27 = __pyx_v_n_rows; - __pyx_t_28 = __pyx_t_27; - for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_28; __pyx_t_19+=1) { - __pyx_v_row = __pyx_t_19; - - /* "pygeoprocessing/routing/watershed.pyx":545 - * - * for row in range(n_rows): - * for col in range(n_cols): # <<<<<<<<<<<<<< - * with cython.boundscheck(False): - * # Check if the pixel does not overlap the geometry. - */ - __pyx_t_29 = __pyx_v_n_cols; - __pyx_t_30 = __pyx_t_29; - for (__pyx_t_31 = 0; __pyx_t_31 < __pyx_t_30; __pyx_t_31+=1) { - __pyx_v_col = __pyx_t_31; - - /* "pygeoprocessing/routing/watershed.pyx":548 - * with cython.boundscheck(False): - * # Check if the pixel does not overlap the geometry. - * if seed_array[row, col] == 0: # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_32 = __pyx_v_row; - __pyx_t_33 = __pyx_v_col; - if (__pyx_t_32 < 0) __pyx_t_32 += __pyx_pybuffernd_seed_array.diminfo[0].shape; - if (__pyx_t_33 < 0) __pyx_t_33 += __pyx_pybuffernd_seed_array.diminfo[1].shape; - __pyx_t_14 = (((*__Pyx_BufPtrStrided2d(npy_uint8 *, __pyx_pybuffernd_seed_array.rcbuffer->pybuffer.buf, __pyx_t_32, __pyx_pybuffernd_seed_array.diminfo[0].strides, __pyx_t_33, __pyx_pybuffernd_seed_array.diminfo[1].strides)) == 0) != 0); - if (__pyx_t_14) { - - /* "pygeoprocessing/routing/watershed.pyx":549 - * # Check if the pixel does not overlap the geometry. - * if seed_array[row, col] == 0: - * continue # <<<<<<<<<<<<<< - * - * global_row = seed_raster_origin_row + block_yoff + row - */ - goto __pyx_L15_continue; - - /* "pygeoprocessing/routing/watershed.pyx":548 - * with cython.boundscheck(False): - * # Check if the pixel does not overlap the geometry. - * if seed_array[row, col] == 0: # <<<<<<<<<<<<<< - * continue - * - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":551 - * continue - * - * global_row = seed_raster_origin_row + block_yoff + row # <<<<<<<<<<<<<< - * global_col = seed_raster_origin_col + block_xoff + col - * - */ - __pyx_v_global_row = ((__pyx_v_seed_raster_origin_row + __pyx_v_block_yoff) + __pyx_v_row); - - /* "pygeoprocessing/routing/watershed.pyx":552 - * - * global_row = seed_raster_origin_row + block_yoff + row - * global_col = seed_raster_origin_col + block_xoff + col # <<<<<<<<<<<<<< - * - * if write_diagnostic_vector == 1: - */ - __pyx_v_global_col = ((__pyx_v_seed_raster_origin_col + __pyx_v_block_xoff) + __pyx_v_col); - - /* "pygeoprocessing/routing/watershed.pyx":554 - * global_col = seed_raster_origin_col + block_xoff + col - * - * if write_diagnostic_vector == 1: # <<<<<<<<<<<<<< - * diagnostic_layer.StartTransaction() - * new_feature = ogr.Feature(diagnostic_layer.GetLayerDefn()) - */ - __pyx_t_14 = ((__pyx_v_write_diagnostic_vector == 1) != 0); - if (__pyx_t_14) { - - /* "pygeoprocessing/routing/watershed.pyx":555 - * - * if write_diagnostic_vector == 1: - * diagnostic_layer.StartTransaction() # <<<<<<<<<<<<<< - * new_feature = ogr.Feature(diagnostic_layer.GetLayerDefn()) - * new_feature.SetGeometry(ogr.CreateGeometryFromWkb( - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_diagnostic_layer, __pyx_n_s_StartTransaction); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 555, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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); - } - } - __pyx_t_20 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 555, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":556 - * if write_diagnostic_vector == 1: - * diagnostic_layer.StartTransaction() - * new_feature = ogr.Feature(diagnostic_layer.GetLayerDefn()) # <<<<<<<<<<<<<< - * new_feature.SetGeometry(ogr.CreateGeometryFromWkb( - * shapely.geometry.Point( - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 556, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_Feature); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 556, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_diagnostic_layer, __pyx_n_s_GetLayerDefn); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 556, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __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); - } - } - __pyx_t_7 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 556, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = NULL; - 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_20 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_7); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 556, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF_SET(__pyx_v_new_feature, __pyx_t_20); - __pyx_t_20 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":557 - * diagnostic_layer.StartTransaction() - * new_feature = ogr.Feature(diagnostic_layer.GetLayerDefn()) - * new_feature.SetGeometry(ogr.CreateGeometryFromWkb( # <<<<<<<<<<<<<< - * shapely.geometry.Point( - * x_origin + ((global_col*x_pixelwidth) + - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_new_feature, __pyx_n_s_SetGeometry); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 557, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_ogr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 557, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_CreateGeometryFromWkb); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 557, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":558 - * new_feature = ogr.Feature(diagnostic_layer.GetLayerDefn()) - * new_feature.SetGeometry(ogr.CreateGeometryFromWkb( - * shapely.geometry.Point( # <<<<<<<<<<<<<< - * x_origin + ((global_col*x_pixelwidth) + - * (x_pixelwidth / 2.)), - */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_shapely); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 558, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_34 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_geometry); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 558, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_34); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_34, __pyx_n_s_Point); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 558, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_34); __pyx_t_34 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":559 - * new_feature.SetGeometry(ogr.CreateGeometryFromWkb( - * shapely.geometry.Point( - * x_origin + ((global_col*x_pixelwidth) + # <<<<<<<<<<<<<< - * (x_pixelwidth / 2.)), - * y_origin + ((global_row*y_pixelwidth) + - */ - __pyx_t_34 = PyFloat_FromDouble((__pyx_v_x_origin + ((__pyx_v_global_col * __pyx_v_x_pixelwidth) + (__pyx_v_x_pixelwidth / 2.)))); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 559, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_34); - - /* "pygeoprocessing/routing/watershed.pyx":561 - * x_origin + ((global_col*x_pixelwidth) + - * (x_pixelwidth / 2.)), - * y_origin + ((global_row*y_pixelwidth) + # <<<<<<<<<<<<<< - * (y_pixelwidth / 2.))).wkb)) - * diagnostic_layer.CreateFeature(new_feature) - */ - __pyx_t_35 = PyFloat_FromDouble((__pyx_v_y_origin + ((__pyx_v_global_row * __pyx_v_y_pixelwidth) + (__pyx_v_y_pixelwidth / 2.)))); if (unlikely(!__pyx_t_35)) __PYX_ERR(0, 561, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_35); - __pyx_t_36 = NULL; - __pyx_t_37 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_36 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_36)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_36); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - __pyx_t_37 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_36, __pyx_t_34, __pyx_t_35}; - __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_37, 2+__pyx_t_37); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 558, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_36); __pyx_t_36 = 0; - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_34); __pyx_t_34 = 0; - __Pyx_DECREF(__pyx_t_35); __pyx_t_35 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_36, __pyx_t_34, __pyx_t_35}; - __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_37, 2+__pyx_t_37); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 558, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_36); __pyx_t_36 = 0; - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_34); __pyx_t_34 = 0; - __Pyx_DECREF(__pyx_t_35); __pyx_t_35 = 0; - } else - #endif - { - __pyx_t_38 = PyTuple_New(2+__pyx_t_37); if (unlikely(!__pyx_t_38)) __PYX_ERR(0, 558, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_38); - if (__pyx_t_36) { - __Pyx_GIVEREF(__pyx_t_36); PyTuple_SET_ITEM(__pyx_t_38, 0, __pyx_t_36); __pyx_t_36 = NULL; - } - __Pyx_GIVEREF(__pyx_t_34); - PyTuple_SET_ITEM(__pyx_t_38, 0+__pyx_t_37, __pyx_t_34); - __Pyx_GIVEREF(__pyx_t_35); - PyTuple_SET_ITEM(__pyx_t_38, 1+__pyx_t_37, __pyx_t_35); - __pyx_t_34 = 0; - __pyx_t_35 = 0; - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_38, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 558, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_38); __pyx_t_38 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":562 - * (x_pixelwidth / 2.)), - * y_origin + ((global_row*y_pixelwidth) + - * (y_pixelwidth / 2.))).wkb)) # <<<<<<<<<<<<<< - * diagnostic_layer.CreateFeature(new_feature) - * diagnostic_layer.CommitTransaction() - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_wkb); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 562, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - __pyx_t_7 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 557, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_20 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_7); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 557, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":563 - * y_origin + ((global_row*y_pixelwidth) + - * (y_pixelwidth / 2.))).wkb)) - * diagnostic_layer.CreateFeature(new_feature) # <<<<<<<<<<<<<< - * diagnostic_layer.CommitTransaction() - * - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_diagnostic_layer, __pyx_n_s_CreateFeature); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 563, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_20 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_7, __pyx_v_new_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_new_feature); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 563, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":564 - * (y_pixelwidth / 2.))).wkb)) - * diagnostic_layer.CreateFeature(new_feature) - * diagnostic_layer.CommitTransaction() # <<<<<<<<<<<<<< - * - * seed_set.insert(CoordinatePair(global_col, global_row)) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_diagnostic_layer, __pyx_n_s_CommitTransaction); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 564, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_20 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 564, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":554 - * global_col = seed_raster_origin_col + block_xoff + col - * - * if write_diagnostic_vector == 1: # <<<<<<<<<<<<<< - * diagnostic_layer.StartTransaction() - * new_feature = ogr.Feature(diagnostic_layer.GetLayerDefn()) - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":566 - * diagnostic_layer.CommitTransaction() - * - * seed_set.insert(CoordinatePair(global_col, global_row)) # <<<<<<<<<<<<<< - * - * return seed_set - */ - try { - __pyx_t_15 = __pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair(__pyx_v_global_col, __pyx_v_global_row); - } catch(...) { - __Pyx_CppExn2PyErr(); - __PYX_ERR(0, 566, __pyx_L1_error) - } - try { - __pyx_v_seed_set.insert(__pyx_t_15); - } catch(...) { - __Pyx_CppExn2PyErr(); - __PYX_ERR(0, 566, __pyx_L1_error) - } - __pyx_L15_continue:; - } - } - - /* "pygeoprocessing/routing/watershed.pyx":537 - * cdef int block_yoff - * cdef numpy.ndarray[numpy.npy_uint8, ndim=2] seed_array - * for block_info, seed_array in pygeoprocessing.iterblocks( # <<<<<<<<<<<<<< - * (target_raster_path, 1)): - * block_xoff = block_info['xoff'] - */ - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":568 - * seed_set.insert(CoordinatePair(global_col, global_row)) - * - * return seed_set # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = __pyx_v_seed_set; - goto __pyx_L0; - - /* "pygeoprocessing/routing/watershed.pyx":402 - * - * - * cdef cset[CoordinatePair] _c_split_geometry_into_seeds( # <<<<<<<<<<<<<< - * source_geom_wkb, tuple flow_dir_geotransform, flow_dir_srs, - * flow_dir_n_cols, flow_dir_n_rows, - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __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_20); - __Pyx_XDECREF(__pyx_t_34); - __Pyx_XDECREF(__pyx_t_35); - __Pyx_XDECREF(__pyx_t_36); - __Pyx_XDECREF(__pyx_t_38); - { 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_seed_array.rcbuffer->pybuffer); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_WriteUnraisable("pygeoprocessing.routing.watershed._c_split_geometry_into_seeds", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); - __Pyx_pretend_to_initialize(&__pyx_r); - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_seed_array.rcbuffer->pybuffer); - __pyx_L2:; - __Pyx_XDECREF(__pyx_v_geometry); - __Pyx_XDECREF(__pyx_v_seed); - __Pyx_XDECREF(__pyx_v_memory_driver); - __Pyx_XDECREF(__pyx_v_new_vector); - __Pyx_XDECREF(__pyx_v_new_layer); - __Pyx_XDECREF(__pyx_v_new_feature); - __Pyx_XDECREF(__pyx_v_local_geotransform); - __Pyx_XDECREF(__pyx_v_gtiff_driver); - __Pyx_XDECREF(__pyx_v_raster); - __Pyx_XDECREF(__pyx_v_diagnostic_vector); - __Pyx_XDECREF(__pyx_v_diagnostic_layer); - __Pyx_XDECREF(__pyx_v_gpkg_driver); - __Pyx_XDECREF(__pyx_v_user_geometry_layer); - __Pyx_XDECREF(__pyx_v_user_feature); - __Pyx_XDECREF(__pyx_v_block_info); - __Pyx_XDECREF((PyObject *)__pyx_v_seed_array); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pygeoprocessing/routing/watershed.pyx":571 - * - * - * def _split_geometry_into_seeds( # <<<<<<<<<<<<<< - * source_geom_wkb, geotransform, flow_dir_srs, - * flow_dir_n_cols, flow_dir_n_rows, target_raster_path, - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15pygeoprocessing_7routing_9watershed_3_split_geometry_into_seeds(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_15pygeoprocessing_7routing_9watershed_2_split_geometry_into_seeds[] = "Split a geometry into 'seeds' of (x, y) coordinate pairs.\n\n This function is a python wrapper around ``_c_split_geometry_into_seeds``\n that is useful for testing.\n\n Parameters:\n source_geom_wkb (str): A string of bytes in WKB representing\n a geometry. Must be in the same projected coordinate system\n as the flow direction raster from which\n ``flow_dir_geotransform`` and ``flow_dir_srs`` are derived.\n flow_dir_geotransform (list): A 6-element array representing\n the GDAL affine geotransform from the flow direction raster.\n flow_dir_srs (osr.SpatialReference): The OSR SpatialReference\n object from the flow direction raster.\n flow_dir_n_cols (int): the number of columns in the flow\n direction raster.\n flow_dir_n_rows (int): the number of rows in the flow\n direction raster.\n target_raster_path (str): The path to a raster onto which\n the geometry might be rasterized. If the geometry is small\n enough to be completely contained within a single pixel, no\n raster will be written to this location.\n diagnostic_vector_path (string or None): If a string, a GeoPackage\n vector will be written to this path containing georeferenced\n points representing the 'seeds' determined by this function.\n If ``None``, no vector is created.\n\n Returns:\n A python ``set`` of (x-index, y-index) tuples.\n\n "; -static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_9watershed_3_split_geometry_into_seeds = {"_split_geometry_into_seeds", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_7routing_9watershed_3_split_geometry_into_seeds, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_7routing_9watershed_2_split_geometry_into_seeds}; -static PyObject *__pyx_pw_15pygeoprocessing_7routing_9watershed_3_split_geometry_into_seeds(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_source_geom_wkb = 0; - PyObject *__pyx_v_geotransform = 0; - PyObject *__pyx_v_flow_dir_srs = 0; - PyObject *__pyx_v_flow_dir_n_cols = 0; - PyObject *__pyx_v_flow_dir_n_rows = 0; - PyObject *__pyx_v_target_raster_path = 0; - PyObject *__pyx_v_diagnostic_vector_path = 0; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_split_geometry_into_seeds (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_source_geom_wkb,&__pyx_n_s_geotransform,&__pyx_n_s_flow_dir_srs,&__pyx_n_s_flow_dir_n_cols,&__pyx_n_s_flow_dir_n_rows,&__pyx_n_s_target_raster_path,&__pyx_n_s_diagnostic_vector_path,0}; - PyObject* values[7] = {0,0,0,0,0,0,0}; - - /* "pygeoprocessing/routing/watershed.pyx":574 - * source_geom_wkb, geotransform, flow_dir_srs, - * flow_dir_n_cols, flow_dir_n_rows, target_raster_path, - * diagnostic_vector_path=None): # <<<<<<<<<<<<<< - * """Split a geometry into 'seeds' of (x, y) coordinate pairs. - * - */ - values[6] = ((PyObject *)Py_None); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - CYTHON_FALLTHROUGH; - 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_source_geom_wkb)) != 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_geotransform)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_split_geometry_into_seeds", 0, 6, 7, 1); __PYX_ERR(0, 571, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_flow_dir_srs)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_split_geometry_into_seeds", 0, 6, 7, 2); __PYX_ERR(0, 571, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_flow_dir_n_cols)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_split_geometry_into_seeds", 0, 6, 7, 3); __PYX_ERR(0, 571, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 4: - if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_flow_dir_n_rows)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_split_geometry_into_seeds", 0, 6, 7, 4); __PYX_ERR(0, 571, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 5: - if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_raster_path)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_split_geometry_into_seeds", 0, 6, 7, 5); __PYX_ERR(0, 571, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 6: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_diagnostic_vector_path); - if (value) { values[6] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_split_geometry_into_seeds") < 0)) __PYX_ERR(0, 571, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - CYTHON_FALLTHROUGH; - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - values[4] = PyTuple_GET_ITEM(__pyx_args, 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_source_geom_wkb = values[0]; - __pyx_v_geotransform = values[1]; - __pyx_v_flow_dir_srs = values[2]; - __pyx_v_flow_dir_n_cols = values[3]; - __pyx_v_flow_dir_n_rows = values[4]; - __pyx_v_target_raster_path = values[5]; - __pyx_v_diagnostic_vector_path = values[6]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_split_geometry_into_seeds", 0, 6, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 571, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pygeoprocessing.routing.watershed._split_geometry_into_seeds", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_15pygeoprocessing_7routing_9watershed_2_split_geometry_into_seeds(__pyx_self, __pyx_v_source_geom_wkb, __pyx_v_geotransform, __pyx_v_flow_dir_srs, __pyx_v_flow_dir_n_cols, __pyx_v_flow_dir_n_rows, __pyx_v_target_raster_path, __pyx_v_diagnostic_vector_path); - - /* "pygeoprocessing/routing/watershed.pyx":571 - * - * - * def _split_geometry_into_seeds( # <<<<<<<<<<<<<< - * source_geom_wkb, geotransform, flow_dir_srs, - * flow_dir_n_cols, flow_dir_n_rows, target_raster_path, - */ - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15pygeoprocessing_7routing_9watershed_2_split_geometry_into_seeds(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_source_geom_wkb, PyObject *__pyx_v_geotransform, PyObject *__pyx_v_flow_dir_srs, PyObject *__pyx_v_flow_dir_n_cols, PyObject *__pyx_v_flow_dir_n_rows, PyObject *__pyx_v_target_raster_path, PyObject *__pyx_v_diagnostic_vector_path) { - PyObject *__pyx_v_return_set = NULL; - std::set<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> __pyx_v_seeds; - __pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair __pyx_v_seed; - std::set<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> ::iterator __pyx_v_seeds_iterator; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - std::set<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> __pyx_t_2; - struct __pyx_opt_args_15pygeoprocessing_7routing_9watershed__c_split_geometry_into_seeds __pyx_t_3; - int __pyx_t_4; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - int __pyx_t_7; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("_split_geometry_into_seeds", 0); - - /* "pygeoprocessing/routing/watershed.pyx":607 - * """ - * - * return_set = set() # <<<<<<<<<<<<<< - * cdef cset[CoordinatePair] seeds = _c_split_geometry_into_seeds( - * source_geom_wkb, geotransform, flow_dir_srs, flow_dir_n_cols, - */ - __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 607, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_return_set = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":609 - * return_set = set() - * cdef cset[CoordinatePair] seeds = _c_split_geometry_into_seeds( - * source_geom_wkb, geotransform, flow_dir_srs, flow_dir_n_cols, # <<<<<<<<<<<<<< - * flow_dir_n_rows, target_raster_path, diagnostic_vector_path) - * - */ - if (!(likely(PyTuple_CheckExact(__pyx_v_geotransform))||((__pyx_v_geotransform) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v_geotransform)->tp_name), 0))) __PYX_ERR(0, 609, __pyx_L1_error) - - /* "pygeoprocessing/routing/watershed.pyx":608 - * - * return_set = set() - * cdef cset[CoordinatePair] seeds = _c_split_geometry_into_seeds( # <<<<<<<<<<<<<< - * source_geom_wkb, geotransform, flow_dir_srs, flow_dir_n_cols, - * flow_dir_n_rows, target_raster_path, diagnostic_vector_path) - */ - __pyx_t_3.__pyx_n = 1; - __pyx_t_3.diagnostic_vector_path = __pyx_v_diagnostic_vector_path; - __pyx_t_2 = __pyx_f_15pygeoprocessing_7routing_9watershed__c_split_geometry_into_seeds(__pyx_v_source_geom_wkb, ((PyObject*)__pyx_v_geotransform), __pyx_v_flow_dir_srs, __pyx_v_flow_dir_n_cols, __pyx_v_flow_dir_n_rows, __pyx_v_target_raster_path, &__pyx_t_3); - __pyx_v_seeds = __pyx_t_2; - - /* "pygeoprocessing/routing/watershed.pyx":613 - * - * cdef CoordinatePair seed - * cdef cset[CoordinatePair].iterator seeds_iterator = seeds.begin() # <<<<<<<<<<<<<< - * while seeds_iterator != seeds.end(): - * seed = deref(seeds_iterator) - */ - __pyx_v_seeds_iterator = __pyx_v_seeds.begin(); - - /* "pygeoprocessing/routing/watershed.pyx":614 - * cdef CoordinatePair seed - * cdef cset[CoordinatePair].iterator seeds_iterator = seeds.begin() - * while seeds_iterator != seeds.end(): # <<<<<<<<<<<<<< - * seed = deref(seeds_iterator) - * inc(seeds_iterator) - */ - while (1) { - __pyx_t_4 = ((__pyx_v_seeds_iterator != __pyx_v_seeds.end()) != 0); - if (!__pyx_t_4) break; - - /* "pygeoprocessing/routing/watershed.pyx":615 - * cdef cset[CoordinatePair].iterator seeds_iterator = seeds.begin() - * while seeds_iterator != seeds.end(): - * seed = deref(seeds_iterator) # <<<<<<<<<<<<<< - * inc(seeds_iterator) - * - */ - __pyx_v_seed = (*__pyx_v_seeds_iterator); - - /* "pygeoprocessing/routing/watershed.pyx":616 - * while seeds_iterator != seeds.end(): - * seed = deref(seeds_iterator) - * inc(seeds_iterator) # <<<<<<<<<<<<<< - * - * return_set.add((seed.first, seed.second)) - */ - (void)((++__pyx_v_seeds_iterator)); - - /* "pygeoprocessing/routing/watershed.pyx":618 - * inc(seeds_iterator) - * - * return_set.add((seed.first, seed.second)) # <<<<<<<<<<<<<< - * - * return return_set - */ - __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_seed.first); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 618, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyInt_From_long(__pyx_v_seed.second); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 618, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 618, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); - __pyx_t_1 = 0; - __pyx_t_5 = 0; - __pyx_t_7 = PySet_Add(__pyx_v_return_set, __pyx_t_6); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 618, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - - /* "pygeoprocessing/routing/watershed.pyx":620 - * return_set.add((seed.first, seed.second)) - * - * return return_set # <<<<<<<<<<<<<< - * - * - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_return_set); - __pyx_r = __pyx_v_return_set; - goto __pyx_L0; - - /* "pygeoprocessing/routing/watershed.pyx":571 - * - * - * def _split_geometry_into_seeds( # <<<<<<<<<<<<<< - * source_geom_wkb, geotransform, flow_dir_srs, - * flow_dir_n_cols, flow_dir_n_rows, target_raster_path, - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("pygeoprocessing.routing.watershed._split_geometry_into_seeds", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_return_set); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pygeoprocessing/routing/watershed.pyx":624 - * - * @cython.boundscheck(False) - * def delineate_watersheds_d8( # <<<<<<<<<<<<<< - * d8_flow_dir_raster_path_band, outflow_vector_path, - * target_watersheds_vector_path, working_dir=None, - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15pygeoprocessing_7routing_9watershed_5delineate_watersheds_d8(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_15pygeoprocessing_7routing_9watershed_4delineate_watersheds_d8[] = "Delineate watersheds for a vector of geometries using D8 flow dir.\n\n Args:\n d8_flow_dir_raster_path_band (tuple): A (path, band_id) tuple\n to a D8 flow direction raster. This raster must be a tiled raster\n with block sizes being a power of 2.\n outflow_vector_path (str): The path to a vector on disk containing\n features with valid geometries from which watersheds will be\n delineated. Only those parts of the geometry that overlap valid\n flow direction pixels will be included in the output watersheds\n vector.\n target_watersheds_vector_path (str): The path to a vector on disk\n where the target watersheds will be stored. Must have the\n extension ``.gpkg``.\n working_dir=None (str or None): The path to a directory on disk\n within which various intermediate files will be stored. If None,\n a folder will be created within the system's temp directory.\n write_diagnostic_vector=False (bool): If ``True``, a set of vectors will\n be written to ``working_dir``, one per watershed. Each vector\n includes geometries for the watershed being represented and\n for the watershed seed pixels the geometry overlaps. Useful in\n debugging issues with feature overlap of the DEM. Setting this\n parameter to ``True`` will dramatically increase runtime when\n outflow geometries cover many pixels.\n remove_temp_files=True (bool): Whether to remove the created temp\n directory at the end of the watershed delineation run.\n target_layer_name='watersheds' (str): The string name to use for\n the watersheds layer. This layer name may be named anything\n except for \"polygonized_watersheds\".\n\n Returns:\n ``None``\n\n "; -static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_9watershed_5delineate_watersheds_d8 = {"delineate_watersheds_d8", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15pygeoprocessing_7routing_9watershed_5delineate_watersheds_d8, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_7routing_9watershed_4delineate_watersheds_d8}; -static PyObject *__pyx_pw_15pygeoprocessing_7routing_9watershed_5delineate_watersheds_d8(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_d8_flow_dir_raster_path_band = 0; - PyObject *__pyx_v_outflow_vector_path = 0; - PyObject *__pyx_v_target_watersheds_vector_path = 0; - PyObject *__pyx_v_working_dir = 0; - PyObject *__pyx_v_write_diagnostic_vector = 0; - PyObject *__pyx_v_remove_temp_files = 0; - PyObject *__pyx_v_target_layer_name = 0; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("delineate_watersheds_d8 (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_d8_flow_dir_raster_path_band,&__pyx_n_s_outflow_vector_path,&__pyx_n_s_target_watersheds_vector_path,&__pyx_n_s_working_dir,&__pyx_n_s_write_diagnostic_vector,&__pyx_n_s_remove_temp_files,&__pyx_n_s_target_layer_name,0}; - PyObject* values[7] = {0,0,0,0,0,0,0}; - - /* "pygeoprocessing/routing/watershed.pyx":626 - * def delineate_watersheds_d8( - * d8_flow_dir_raster_path_band, outflow_vector_path, - * target_watersheds_vector_path, working_dir=None, # <<<<<<<<<<<<<< - * write_diagnostic_vector=False, remove_temp_files=True, - * target_layer_name='watersheds'): - */ - values[3] = ((PyObject *)Py_None); - - /* "pygeoprocessing/routing/watershed.pyx":627 - * d8_flow_dir_raster_path_band, outflow_vector_path, - * target_watersheds_vector_path, working_dir=None, - * write_diagnostic_vector=False, remove_temp_files=True, # <<<<<<<<<<<<<< - * target_layer_name='watersheds'): - * """Delineate watersheds for a vector of geometries using D8 flow dir. - */ - values[4] = ((PyObject *)Py_False); - values[5] = ((PyObject *)Py_True); - values[6] = ((PyObject *)__pyx_n_u_watersheds); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - CYTHON_FALLTHROUGH; - 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_d8_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_outflow_vector_path)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("delineate_watersheds_d8", 0, 3, 7, 1); __PYX_ERR(0, 624, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_watersheds_vector_path)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("delineate_watersheds_d8", 0, 3, 7, 2); __PYX_ERR(0, 624, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_working_dir); - 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_write_diagnostic_vector); - 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_remove_temp_files); - if (value) { values[5] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 6: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_layer_name); - if (value) { values[6] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "delineate_watersheds_d8") < 0)) __PYX_ERR(0, 624, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - CYTHON_FALLTHROUGH; - 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); - 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_d8_flow_dir_raster_path_band = values[0]; - __pyx_v_outflow_vector_path = values[1]; - __pyx_v_target_watersheds_vector_path = values[2]; - __pyx_v_working_dir = values[3]; - __pyx_v_write_diagnostic_vector = values[4]; - __pyx_v_remove_temp_files = values[5]; - __pyx_v_target_layer_name = values[6]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("delineate_watersheds_d8", 0, 3, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 624, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pygeoprocessing.routing.watershed.delineate_watersheds_d8", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_15pygeoprocessing_7routing_9watershed_4delineate_watersheds_d8(__pyx_self, __pyx_v_d8_flow_dir_raster_path_band, __pyx_v_outflow_vector_path, __pyx_v_target_watersheds_vector_path, __pyx_v_working_dir, __pyx_v_write_diagnostic_vector, __pyx_v_remove_temp_files, __pyx_v_target_layer_name); - - /* "pygeoprocessing/routing/watershed.pyx":624 - * - * @cython.boundscheck(False) - * def delineate_watersheds_d8( # <<<<<<<<<<<<<< - * d8_flow_dir_raster_path_band, outflow_vector_path, - * target_watersheds_vector_path, working_dir=None, - */ - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15pygeoprocessing_7routing_9watershed_4delineate_watersheds_d8(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_d8_flow_dir_raster_path_band, PyObject *__pyx_v_outflow_vector_path, PyObject *__pyx_v_target_watersheds_vector_path, PyObject *__pyx_v_working_dir, PyObject *__pyx_v_write_diagnostic_vector, PyObject *__pyx_v_remove_temp_files, PyObject *__pyx_v_target_layer_name) { - PyObject *__pyx_v_working_dir_path = NULL; - PyObject *__pyx_v_flow_dir_info = NULL; - int __pyx_v_flow_dir_nodata; - PyObject *__pyx_v_source_gt = NULL; - double __pyx_v_flow_dir_origin_x; - double __pyx_v_flow_dir_origin_y; - double __pyx_v_flow_dir_pixelsize_x; - double __pyx_v_flow_dir_pixelsize_y; - int __pyx_v_flow_dir_n_cols; - int __pyx_v_flow_dir_n_rows; - int __pyx_v_ws_id; - PyObject *__pyx_v_bbox_minx = NULL; - PyObject *__pyx_v_bbox_miny = NULL; - PyObject *__pyx_v_bbox_maxx = NULL; - PyObject *__pyx_v_bbox_maxy = NULL; - PyObject *__pyx_v_flow_dir_bbox = NULL; - struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_flow_dir_managed_raster = NULL; - PyObject *__pyx_v_gtiff_driver = NULL; - PyObject *__pyx_v_flow_dir_srs = NULL; - PyObject *__pyx_v_outflow_vector = NULL; - PyObject *__pyx_v_driver = NULL; - PyObject *__pyx_v_watersheds_srs = NULL; - PyObject *__pyx_v_watersheds_vector = NULL; - PyObject *__pyx_v_polygonized_watersheds_layer = NULL; - PyObject *__pyx_v_watersheds_layer = NULL; - PyObject *__pyx_v_index_field = NULL; - int *__pyx_v_reverse_flow; - int *__pyx_v_neighbor_col; - int *__pyx_v_neighbor_row; - std::queue<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> __pyx_v_process_queue; - std::set<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> __pyx_v_process_queue_set; - __pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair __pyx_v_neighbor_pixel; - int __pyx_v_ix_min; - int __pyx_v_iy_min; - int __pyx_v_ix_max; - int __pyx_v_iy_max; - struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *__pyx_v_scratch_managed_raster = 0; - int __pyx_v_watersheds_created; - int __pyx_v_current_fid; - int __pyx_v_outflow_feature_count; - std::set<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> ::iterator __pyx_v_seed_iterator; - std::set<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> __pyx_v_seeds_in_watershed; - time_t __pyx_v_last_log_time; - int __pyx_v_n_cells_visited; - PyObject *__pyx_v_outflow_layer = NULL; - PyObject *__pyx_v_feature = NULL; - PyObject *__pyx_v_geom = NULL; - PyObject *__pyx_v_geom_wkb = NULL; - PyObject *__pyx_v_shapely_geom = NULL; - PyObject *__pyx_v_seeds_raster_path = NULL; - PyObject *__pyx_v_diagnostic_vector_path = NULL; - __pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair __pyx_v_seed; - PyObject *__pyx_v_scratch_raster_path = NULL; - PyObject *__pyx_v_scratch_raster = NULL; - __pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair __pyx_v_current_pixel; - long __pyx_v_neighbor_index; - double __pyx_v_x1; - double __pyx_v_y1; - double __pyx_v_x2; - double __pyx_v_y2; - PyObject *__pyx_v_vrt_options = NULL; - PyObject *__pyx_v_vrt_path = NULL; - PyObject *__pyx_v_vrt_raster = NULL; - PyObject *__pyx_v_vrt_band = NULL; - CYTHON_UNUSED PyObject *__pyx_v__ = NULL; - std::map > __pyx_v_fragments_with_duplicates; - int __pyx_v_fid; - PyObject *__pyx_v_source_vector = NULL; - PyObject *__pyx_v_source_layer = NULL; - int __pyx_v_duplicate_fid; - std::set __pyx_v_duplicate_ids_set; - std::set ::iterator __pyx_v_duplicate_ids_set_iterator; - std::map > ::iterator __pyx_v_fragments_with_duplicates_iterator; - PyObject *__pyx_v_source_feature = NULL; - PyObject *__pyx_v_new_geometry = NULL; - PyObject *__pyx_v_duplicate_feature = NULL; - PyObject *__pyx_v_duplicate_geometry = NULL; - PyObject *__pyx_v_watershed_feature = NULL; - PyObject *__pyx_v_field_name = NULL; - PyObject *__pyx_v_field_value = 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; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - int __pyx_t_9; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - PyObject *__pyx_t_12 = NULL; - PyObject *__pyx_t_13 = NULL; - int __pyx_t_14; - double __pyx_t_15; - PyObject *(*__pyx_t_16)(PyObject *); - PyObject *__pyx_t_17 = NULL; - PyObject *__pyx_t_18 = NULL; - PyObject *__pyx_t_19 = NULL; - int __pyx_t_20[8]; - int __pyx_t_21[8]; - int __pyx_t_22[8]; - Py_ssize_t __pyx_t_23; - PyObject *(*__pyx_t_24)(PyObject *); - std::set<__pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair> __pyx_t_25; - struct __pyx_opt_args_15pygeoprocessing_7routing_9watershed__c_split_geometry_into_seeds __pyx_t_26; - long __pyx_t_27; - long __pyx_t_28; - __pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair __pyx_t_29; - long __pyx_t_30; - double __pyx_t_31; - double __pyx_t_32; - std::set __pyx_t_33; - Py_ssize_t __pyx_t_34; - int __pyx_t_35; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("delineate_watersheds_d8", 0); - - /* "pygeoprocessing/routing/watershed.pyx":663 - * - * """ - * try: # <<<<<<<<<<<<<< - * if working_dir is not None: - * os.makedirs(working_dir) - */ - { - __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:*/ { - - /* "pygeoprocessing/routing/watershed.pyx":664 - * """ - * try: - * if working_dir is not None: # <<<<<<<<<<<<<< - * os.makedirs(working_dir) - * except OSError: - */ - __pyx_t_4 = (__pyx_v_working_dir != Py_None); - __pyx_t_5 = (__pyx_t_4 != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/watershed.pyx":665 - * try: - * if working_dir is not None: - * os.makedirs(working_dir) # <<<<<<<<<<<<<< - * except OSError: - * pass - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_os); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 665, __pyx_L3_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_makedirs); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 665, __pyx_L3_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __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); - } - } - __pyx_t_6 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_7, __pyx_v_working_dir) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_working_dir); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 665, __pyx_L3_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":664 - * """ - * try: - * if working_dir is not None: # <<<<<<<<<<<<<< - * os.makedirs(working_dir) - * except OSError: - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":663 - * - * """ - * try: # <<<<<<<<<<<<<< - * if working_dir is not None: - * os.makedirs(working_dir) - */ - } - __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:; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":666 - * if working_dir is not None: - * os.makedirs(working_dir) - * except OSError: # <<<<<<<<<<<<<< - * pass - * working_dir_path = tempfile.mkdtemp( - */ - __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OSError); - if (__pyx_t_9) { - __Pyx_ErrRestore(0,0,0); - goto __pyx_L4_exception_handled; - } - goto __pyx_L5_except_error; - __pyx_L5_except_error:; - - /* "pygeoprocessing/routing/watershed.pyx":663 - * - * """ - * try: # <<<<<<<<<<<<<< - * if working_dir is not None: - * os.makedirs(working_dir) - */ - __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_L4_exception_handled:; - __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); - __pyx_L8_try_end:; - } - - /* "pygeoprocessing/routing/watershed.pyx":668 - * except OSError: - * pass - * working_dir_path = tempfile.mkdtemp( # <<<<<<<<<<<<<< - * dir=working_dir, prefix='watershed_delineation_trivial_%s_' % time.strftime( - * '%Y-%m-%d_%H_%M_%S', time.gmtime())) - */ - __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_tempfile); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 668, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_mkdtemp); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 668, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":669 - * pass - * working_dir_path = tempfile.mkdtemp( - * dir=working_dir, prefix='watershed_delineation_trivial_%s_' % time.strftime( # <<<<<<<<<<<<<< - * '%Y-%m-%d_%H_%M_%S', time.gmtime())) - * - */ - __pyx_t_6 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 669, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dir, __pyx_v_working_dir) < 0) __PYX_ERR(0, 669, __pyx_L1_error) - __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_time); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 669, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_strftime); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 669, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":670 - * working_dir_path = tempfile.mkdtemp( - * dir=working_dir, prefix='watershed_delineation_trivial_%s_' % time.strftime( - * '%Y-%m-%d_%H_%M_%S', time.gmtime())) # <<<<<<<<<<<<<< - * - * if (d8_flow_dir_raster_path_band is not None and not - */ - __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_time); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 670, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_gmtime); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 670, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_13))) { - __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_13); - if (likely(__pyx_t_12)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); - __Pyx_INCREF(__pyx_t_12); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_13, function); - } - } - __pyx_t_10 = (__pyx_t_12) ? __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_12) : __Pyx_PyObject_CallNoArg(__pyx_t_13); - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 670, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_13 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_13)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_13); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_11)) { - PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_kp_u_Y_m_d__H__M__S, __pyx_t_10}; - __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 669, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { - PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_kp_u_Y_m_d__H__M__S, __pyx_t_10}; - __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 669, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } else - #endif - { - __pyx_t_12 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 669, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - if (__pyx_t_13) { - __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_13); __pyx_t_13 = NULL; - } - __Pyx_INCREF(__pyx_kp_u_Y_m_d__H__M__S); - __Pyx_GIVEREF(__pyx_kp_u_Y_m_d__H__M__S); - PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_9, __pyx_kp_u_Y_m_d__H__M__S); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_9, __pyx_t_10); - __pyx_t_10 = 0; - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_12, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 669, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - } - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":669 - * pass - * working_dir_path = tempfile.mkdtemp( - * dir=working_dir, prefix='watershed_delineation_trivial_%s_' % time.strftime( # <<<<<<<<<<<<<< - * '%Y-%m-%d_%H_%M_%S', time.gmtime())) - * - */ - __pyx_t_11 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_watershed_delineation_trivial__s, __pyx_t_7); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 669, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_prefix, __pyx_t_11) < 0) __PYX_ERR(0, 669, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":668 - * except OSError: - * pass - * working_dir_path = tempfile.mkdtemp( # <<<<<<<<<<<<<< - * dir=working_dir, prefix='watershed_delineation_trivial_%s_' % time.strftime( - * '%Y-%m-%d_%H_%M_%S', time.gmtime())) - */ - __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_empty_tuple, __pyx_t_6); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 668, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_working_dir_path = __pyx_t_11; - __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":672 - * '%Y-%m-%d_%H_%M_%S', time.gmtime())) - * - * if (d8_flow_dir_raster_path_band is not None and not # <<<<<<<<<<<<<< - * _is_raster_path_band_formatted(d8_flow_dir_raster_path_band)): - * raise ValueError( - */ - __pyx_t_4 = (__pyx_v_d8_flow_dir_raster_path_band != Py_None); - __pyx_t_14 = (__pyx_t_4 != 0); - if (__pyx_t_14) { - } else { - __pyx_t_5 = __pyx_t_14; - goto __pyx_L11_bool_binop_done; - } - - /* "pygeoprocessing/routing/watershed.pyx":673 - * - * if (d8_flow_dir_raster_path_band is not None and not - * _is_raster_path_band_formatted(d8_flow_dir_raster_path_band)): # <<<<<<<<<<<<<< - * raise ValueError( - * "%s is supposed to be a raster band tuple but it's not." % ( - */ - __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_is_raster_path_band_formatted); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 673, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - __pyx_t_11 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_8, __pyx_v_d8_flow_dir_raster_path_band) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_d8_flow_dir_raster_path_band); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 673, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 673, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":672 - * '%Y-%m-%d_%H_%M_%S', time.gmtime())) - * - * if (d8_flow_dir_raster_path_band is not None and not # <<<<<<<<<<<<<< - * _is_raster_path_band_formatted(d8_flow_dir_raster_path_band)): - * raise ValueError( - */ - __pyx_t_4 = ((!__pyx_t_14) != 0); - __pyx_t_5 = __pyx_t_4; - __pyx_L11_bool_binop_done:; - if (unlikely(__pyx_t_5)) { - - /* "pygeoprocessing/routing/watershed.pyx":675 - * _is_raster_path_band_formatted(d8_flow_dir_raster_path_band)): - * raise ValueError( - * "%s is supposed to be a raster band tuple but it's not." % ( # <<<<<<<<<<<<<< - * d8_flow_dir_raster_path_band)) - * - */ - __pyx_t_11 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_s_is_supposed_to_be_a_raster_ba, __pyx_v_d8_flow_dir_raster_path_band); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 675, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - - /* "pygeoprocessing/routing/watershed.pyx":674 - * if (d8_flow_dir_raster_path_band is not None and not - * _is_raster_path_band_formatted(d8_flow_dir_raster_path_band)): - * raise ValueError( # <<<<<<<<<<<<<< - * "%s is supposed to be a raster band tuple but it's not." % ( - * d8_flow_dir_raster_path_band)) - */ - __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 674, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_Raise(__pyx_t_6, 0, 0, 0); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __PYX_ERR(0, 674, __pyx_L1_error) - - /* "pygeoprocessing/routing/watershed.pyx":672 - * '%Y-%m-%d_%H_%M_%S', time.gmtime())) - * - * if (d8_flow_dir_raster_path_band is not None and not # <<<<<<<<<<<<<< - * _is_raster_path_band_formatted(d8_flow_dir_raster_path_band)): - * raise ValueError( - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":678 - * d8_flow_dir_raster_path_band)) - * - * flow_dir_info = pygeoprocessing.get_raster_info( # <<<<<<<<<<<<<< - * d8_flow_dir_raster_path_band[0]) - * cdef int flow_dir_nodata = flow_dir_info['nodata'][0] - */ - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 678, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 678, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":679 - * - * flow_dir_info = pygeoprocessing.get_raster_info( - * d8_flow_dir_raster_path_band[0]) # <<<<<<<<<<<<<< - * cdef int flow_dir_nodata = flow_dir_info['nodata'][0] - * source_gt = flow_dir_info['geotransform'] - */ - __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_d8_flow_dir_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 679, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __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); - } - } - __pyx_t_6 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_7, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_11); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 678, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_flow_dir_info = __pyx_t_6; - __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":680 - * flow_dir_info = pygeoprocessing.get_raster_info( - * d8_flow_dir_raster_path_band[0]) - * cdef int flow_dir_nodata = flow_dir_info['nodata'][0] # <<<<<<<<<<<<<< - * source_gt = flow_dir_info['geotransform'] - * cdef double flow_dir_origin_x = source_gt[0] - */ - __pyx_t_6 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_nodata); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 680, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_8 = __Pyx_GetItemInt(__pyx_t_6, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 680, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_8); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 680, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_flow_dir_nodata = __pyx_t_9; - - /* "pygeoprocessing/routing/watershed.pyx":681 - * d8_flow_dir_raster_path_band[0]) - * cdef int flow_dir_nodata = flow_dir_info['nodata'][0] - * source_gt = flow_dir_info['geotransform'] # <<<<<<<<<<<<<< - * cdef double flow_dir_origin_x = source_gt[0] - * cdef double flow_dir_origin_y = source_gt[3] - */ - __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_geotransform); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 681, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_v_source_gt = __pyx_t_8; - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":682 - * cdef int flow_dir_nodata = flow_dir_info['nodata'][0] - * source_gt = flow_dir_info['geotransform'] - * cdef double flow_dir_origin_x = source_gt[0] # <<<<<<<<<<<<<< - * cdef double flow_dir_origin_y = source_gt[3] - * cdef double flow_dir_pixelsize_x = source_gt[1] - */ - __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_source_gt, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 682, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_15 = __pyx_PyFloat_AsDouble(__pyx_t_8); if (unlikely((__pyx_t_15 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 682, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_flow_dir_origin_x = __pyx_t_15; - - /* "pygeoprocessing/routing/watershed.pyx":683 - * source_gt = flow_dir_info['geotransform'] - * cdef double flow_dir_origin_x = source_gt[0] - * cdef double flow_dir_origin_y = source_gt[3] # <<<<<<<<<<<<<< - * cdef double flow_dir_pixelsize_x = source_gt[1] - * cdef double flow_dir_pixelsize_y = source_gt[5] - */ - __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_source_gt, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 683, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_15 = __pyx_PyFloat_AsDouble(__pyx_t_8); if (unlikely((__pyx_t_15 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 683, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_flow_dir_origin_y = __pyx_t_15; - - /* "pygeoprocessing/routing/watershed.pyx":684 - * cdef double flow_dir_origin_x = source_gt[0] - * cdef double flow_dir_origin_y = source_gt[3] - * cdef double flow_dir_pixelsize_x = source_gt[1] # <<<<<<<<<<<<<< - * cdef double flow_dir_pixelsize_y = source_gt[5] - * cdef int flow_dir_n_cols = flow_dir_info['raster_size'][0] - */ - __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_source_gt, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 684, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_15 = __pyx_PyFloat_AsDouble(__pyx_t_8); if (unlikely((__pyx_t_15 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 684, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_flow_dir_pixelsize_x = __pyx_t_15; - - /* "pygeoprocessing/routing/watershed.pyx":685 - * cdef double flow_dir_origin_y = source_gt[3] - * cdef double flow_dir_pixelsize_x = source_gt[1] - * cdef double flow_dir_pixelsize_y = source_gt[5] # <<<<<<<<<<<<<< - * cdef int flow_dir_n_cols = flow_dir_info['raster_size'][0] - * cdef int flow_dir_n_rows = flow_dir_info['raster_size'][1] - */ - __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_source_gt, 5, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 685, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_15 = __pyx_PyFloat_AsDouble(__pyx_t_8); if (unlikely((__pyx_t_15 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 685, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_flow_dir_pixelsize_y = __pyx_t_15; - - /* "pygeoprocessing/routing/watershed.pyx":686 - * cdef double flow_dir_pixelsize_x = source_gt[1] - * cdef double flow_dir_pixelsize_y = source_gt[5] - * cdef int flow_dir_n_cols = flow_dir_info['raster_size'][0] # <<<<<<<<<<<<<< - * cdef int flow_dir_n_rows = flow_dir_info['raster_size'][1] - * cdef int ws_id - */ - __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 686, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_8, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 686, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 686, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_flow_dir_n_cols = __pyx_t_9; - - /* "pygeoprocessing/routing/watershed.pyx":687 - * cdef double flow_dir_pixelsize_y = source_gt[5] - * cdef int flow_dir_n_cols = flow_dir_info['raster_size'][0] - * cdef int flow_dir_n_rows = flow_dir_info['raster_size'][1] # <<<<<<<<<<<<<< - * cdef int ws_id - * bbox_minx, bbox_miny, bbox_maxx, bbox_maxy = flow_dir_info['bounding_box'] - */ - __pyx_t_6 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_raster_size); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 687, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_8 = __Pyx_GetItemInt(__pyx_t_6, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 687, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_8); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 687, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_flow_dir_n_rows = __pyx_t_9; - - /* "pygeoprocessing/routing/watershed.pyx":689 - * cdef int flow_dir_n_rows = flow_dir_info['raster_size'][1] - * cdef int ws_id - * bbox_minx, bbox_miny, bbox_maxx, bbox_maxy = flow_dir_info['bounding_box'] # <<<<<<<<<<<<<< - * LOGGER.debug('Creating flow dir bbox') - * flow_dir_bbox = shapely.prepared.prep( - */ - __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_bounding_box); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 689, __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 != 4)) { - if (size > 4) __Pyx_RaiseTooManyValuesError(4); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 689, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_11 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_7 = PyTuple_GET_ITEM(sequence, 2); - __pyx_t_12 = PyTuple_GET_ITEM(sequence, 3); - } else { - __pyx_t_6 = PyList_GET_ITEM(sequence, 0); - __pyx_t_11 = PyList_GET_ITEM(sequence, 1); - __pyx_t_7 = PyList_GET_ITEM(sequence, 2); - __pyx_t_12 = PyList_GET_ITEM(sequence, 3); - } - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(__pyx_t_12); - #else - { - Py_ssize_t i; - PyObject** temps[4] = {&__pyx_t_6,&__pyx_t_11,&__pyx_t_7,&__pyx_t_12}; - for (i=0; i < 4; i++) { - PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 689, __pyx_L1_error) - __Pyx_GOTREF(item); - *(temps[i]) = item; - } - } - #endif - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else { - Py_ssize_t index = -1; - PyObject** temps[4] = {&__pyx_t_6,&__pyx_t_11,&__pyx_t_7,&__pyx_t_12}; - __pyx_t_10 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 689, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_16 = Py_TYPE(__pyx_t_10)->tp_iternext; - for (index=0; index < 4; index++) { - PyObject* item = __pyx_t_16(__pyx_t_10); if (unlikely(!item)) goto __pyx_L13_unpacking_failed; - __Pyx_GOTREF(item); - *(temps[index]) = item; - } - if (__Pyx_IternextUnpackEndCheck(__pyx_t_16(__pyx_t_10), 4) < 0) __PYX_ERR(0, 689, __pyx_L1_error) - __pyx_t_16 = NULL; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - goto __pyx_L14_unpacking_done; - __pyx_L13_unpacking_failed:; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_16 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 689, __pyx_L1_error) - __pyx_L14_unpacking_done:; - } - __pyx_v_bbox_minx = __pyx_t_6; - __pyx_t_6 = 0; - __pyx_v_bbox_miny = __pyx_t_11; - __pyx_t_11 = 0; - __pyx_v_bbox_maxx = __pyx_t_7; - __pyx_t_7 = 0; - __pyx_v_bbox_maxy = __pyx_t_12; - __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":690 - * cdef int ws_id - * bbox_minx, bbox_miny, bbox_maxx, bbox_maxy = flow_dir_info['bounding_box'] - * LOGGER.debug('Creating flow dir bbox') # <<<<<<<<<<<<<< - * flow_dir_bbox = shapely.prepared.prep( - * shapely.geometry.Polygon([ - */ - __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 690, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_debug); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 690, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = NULL; - 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_8 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_12, __pyx_kp_u_Creating_flow_dir_bbox) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_kp_u_Creating_flow_dir_bbox); - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 690, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":691 - * bbox_minx, bbox_miny, bbox_maxx, bbox_maxy = flow_dir_info['bounding_box'] - * LOGGER.debug('Creating flow dir bbox') - * flow_dir_bbox = shapely.prepared.prep( # <<<<<<<<<<<<<< - * shapely.geometry.Polygon([ - * (bbox_minx, bbox_maxy), - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_shapely); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 691, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_prepared); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 691, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_prep); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 691, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":692 - * LOGGER.debug('Creating flow dir bbox') - * flow_dir_bbox = shapely.prepared.prep( - * shapely.geometry.Polygon([ # <<<<<<<<<<<<<< - * (bbox_minx, bbox_maxy), - * (bbox_minx, bbox_miny), - */ - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_shapely); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 692, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_geometry); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 692, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_Polygon); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 692, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":693 - * flow_dir_bbox = shapely.prepared.prep( - * shapely.geometry.Polygon([ - * (bbox_minx, bbox_maxy), # <<<<<<<<<<<<<< - * (bbox_minx, bbox_miny), - * (bbox_maxx, bbox_miny), - */ - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 693, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_INCREF(__pyx_v_bbox_minx); - __Pyx_GIVEREF(__pyx_v_bbox_minx); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_bbox_minx); - __Pyx_INCREF(__pyx_v_bbox_maxy); - __Pyx_GIVEREF(__pyx_v_bbox_maxy); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_bbox_maxy); - - /* "pygeoprocessing/routing/watershed.pyx":694 - * shapely.geometry.Polygon([ - * (bbox_minx, bbox_maxy), - * (bbox_minx, bbox_miny), # <<<<<<<<<<<<<< - * (bbox_maxx, bbox_miny), - * (bbox_maxx, bbox_maxy), - */ - __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 694, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(__pyx_v_bbox_minx); - __Pyx_GIVEREF(__pyx_v_bbox_minx); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_bbox_minx); - __Pyx_INCREF(__pyx_v_bbox_miny); - __Pyx_GIVEREF(__pyx_v_bbox_miny); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_v_bbox_miny); - - /* "pygeoprocessing/routing/watershed.pyx":695 - * (bbox_minx, bbox_maxy), - * (bbox_minx, bbox_miny), - * (bbox_maxx, bbox_miny), # <<<<<<<<<<<<<< - * (bbox_maxx, bbox_maxy), - * (bbox_minx, bbox_maxy)])) - */ - __pyx_t_13 = PyTuple_New(2); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 695, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __Pyx_INCREF(__pyx_v_bbox_maxx); - __Pyx_GIVEREF(__pyx_v_bbox_maxx); - PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_v_bbox_maxx); - __Pyx_INCREF(__pyx_v_bbox_miny); - __Pyx_GIVEREF(__pyx_v_bbox_miny); - PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_v_bbox_miny); - - /* "pygeoprocessing/routing/watershed.pyx":696 - * (bbox_minx, bbox_miny), - * (bbox_maxx, bbox_miny), - * (bbox_maxx, bbox_maxy), # <<<<<<<<<<<<<< - * (bbox_minx, bbox_maxy)])) - * LOGGER.debug('Creating flow dir managed raster') - */ - __pyx_t_17 = PyTuple_New(2); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 696, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_17); - __Pyx_INCREF(__pyx_v_bbox_maxx); - __Pyx_GIVEREF(__pyx_v_bbox_maxx); - PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_v_bbox_maxx); - __Pyx_INCREF(__pyx_v_bbox_maxy); - __Pyx_GIVEREF(__pyx_v_bbox_maxy); - PyTuple_SET_ITEM(__pyx_t_17, 1, __pyx_v_bbox_maxy); - - /* "pygeoprocessing/routing/watershed.pyx":697 - * (bbox_maxx, bbox_miny), - * (bbox_maxx, bbox_maxy), - * (bbox_minx, bbox_maxy)])) # <<<<<<<<<<<<<< - * LOGGER.debug('Creating flow dir managed raster') - * flow_dir_managed_raster = _ManagedRaster(d8_flow_dir_raster_path_band[0], - */ - __pyx_t_18 = PyTuple_New(2); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 697, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_INCREF(__pyx_v_bbox_minx); - __Pyx_GIVEREF(__pyx_v_bbox_minx); - PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_v_bbox_minx); - __Pyx_INCREF(__pyx_v_bbox_maxy); - __Pyx_GIVEREF(__pyx_v_bbox_maxy); - PyTuple_SET_ITEM(__pyx_t_18, 1, __pyx_v_bbox_maxy); - - /* "pygeoprocessing/routing/watershed.pyx":692 - * LOGGER.debug('Creating flow dir bbox') - * flow_dir_bbox = shapely.prepared.prep( - * shapely.geometry.Polygon([ # <<<<<<<<<<<<<< - * (bbox_minx, bbox_maxy), - * (bbox_minx, bbox_miny), - */ - __pyx_t_19 = PyList_New(5); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 692, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_GIVEREF(__pyx_t_6); - PyList_SET_ITEM(__pyx_t_19, 0, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_10); - PyList_SET_ITEM(__pyx_t_19, 1, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_13); - PyList_SET_ITEM(__pyx_t_19, 2, __pyx_t_13); - __Pyx_GIVEREF(__pyx_t_17); - PyList_SET_ITEM(__pyx_t_19, 3, __pyx_t_17); - __Pyx_GIVEREF(__pyx_t_18); - PyList_SET_ITEM(__pyx_t_19, 4, __pyx_t_18); - __pyx_t_6 = 0; - __pyx_t_10 = 0; - __pyx_t_13 = 0; - __pyx_t_17 = 0; - __pyx_t_18 = 0; - __pyx_t_18 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_18 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_18)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_18); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - } - } - __pyx_t_12 = (__pyx_t_18) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_18, __pyx_t_19) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_19); - __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 692, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_8 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_11, __pyx_t_12) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_12); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 691, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_flow_dir_bbox = __pyx_t_8; - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":698 - * (bbox_maxx, bbox_maxy), - * (bbox_minx, bbox_maxy)])) - * LOGGER.debug('Creating flow dir managed raster') # <<<<<<<<<<<<<< - * flow_dir_managed_raster = _ManagedRaster(d8_flow_dir_raster_path_band[0], - * d8_flow_dir_raster_path_band[1], 0) - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 698, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_debug); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 698, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - } - } - __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_7, __pyx_kp_u_Creating_flow_dir_managed_raster) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_kp_u_Creating_flow_dir_managed_raster); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 698, __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/watershed.pyx":699 - * (bbox_minx, bbox_maxy)])) - * LOGGER.debug('Creating flow dir managed raster') - * flow_dir_managed_raster = _ManagedRaster(d8_flow_dir_raster_path_band[0], # <<<<<<<<<<<<<< - * d8_flow_dir_raster_path_band[1], 0) - * - */ - __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_d8_flow_dir_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 699, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - - /* "pygeoprocessing/routing/watershed.pyx":700 - * LOGGER.debug('Creating flow dir managed raster') - * flow_dir_managed_raster = _ManagedRaster(d8_flow_dir_raster_path_band[0], - * d8_flow_dir_raster_path_band[1], 0) # <<<<<<<<<<<<<< - * - * gtiff_driver = gdal.GetDriverByName('GTiff') - */ - __pyx_t_12 = __Pyx_GetItemInt(__pyx_v_d8_flow_dir_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 700, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - - /* "pygeoprocessing/routing/watershed.pyx":699 - * (bbox_minx, bbox_maxy)])) - * LOGGER.debug('Creating flow dir managed raster') - * flow_dir_managed_raster = _ManagedRaster(d8_flow_dir_raster_path_band[0], # <<<<<<<<<<<<<< - * d8_flow_dir_raster_path_band[1], 0) - * - */ - __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 699, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_12); - PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_12); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_int_0); - __pyx_t_8 = 0; - __pyx_t_12 = 0; - __pyx_t_12 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_9watershed__ManagedRaster), __pyx_t_7, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 699, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_flow_dir_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *)__pyx_t_12); - __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":702 - * d8_flow_dir_raster_path_band[1], 0) - * - * gtiff_driver = gdal.GetDriverByName('GTiff') # <<<<<<<<<<<<<< - * flow_dir_srs = osr.SpatialReference() - * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 702, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_GetDriverByName); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 702, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __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); - } - } - __pyx_t_12 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_7, __pyx_n_u_GTiff) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_n_u_GTiff); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 702, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_gtiff_driver = __pyx_t_12; - __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":703 - * - * gtiff_driver = gdal.GetDriverByName('GTiff') - * flow_dir_srs = osr.SpatialReference() # <<<<<<<<<<<<<< - * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_osr); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 703, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_SpatialReference); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 703, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __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); - } - } - __pyx_t_12 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 703, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_flow_dir_srs = __pyx_t_12; - __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":704 - * gtiff_driver = gdal.GetDriverByName('GTiff') - * flow_dir_srs = osr.SpatialReference() - * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) # <<<<<<<<<<<<<< - * - * outflow_vector = gdal.OpenEx(outflow_vector_path, gdal.OF_VECTOR) - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_srs, __pyx_n_s_ImportFromWkt); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 704, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_projection_wkt); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 704, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_12 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_11, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 704, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":706 - * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) - * - * outflow_vector = gdal.OpenEx(outflow_vector_path, gdal.OF_VECTOR) # <<<<<<<<<<<<<< - * if outflow_vector is None: - * raise ValueError(u'Could not open outflow vector %s' % outflow_vector_path) - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 706, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 706, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 706, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OF_VECTOR); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 706, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - __pyx_t_9 = 0; - 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); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_outflow_vector_path, __pyx_t_11}; - __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 706, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_outflow_vector_path, __pyx_t_11}; - __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 706, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } else - #endif - { - __pyx_t_19 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 706, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - if (__pyx_t_7) { - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_7); __pyx_t_7 = NULL; - } - __Pyx_INCREF(__pyx_v_outflow_vector_path); - __Pyx_GIVEREF(__pyx_v_outflow_vector_path); - PyTuple_SET_ITEM(__pyx_t_19, 0+__pyx_t_9, __pyx_v_outflow_vector_path); - __Pyx_GIVEREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_19, 1+__pyx_t_9, __pyx_t_11); - __pyx_t_11 = 0; - __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_19, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 706, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_outflow_vector = __pyx_t_12; - __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":707 - * - * outflow_vector = gdal.OpenEx(outflow_vector_path, gdal.OF_VECTOR) - * if outflow_vector is None: # <<<<<<<<<<<<<< - * raise ValueError(u'Could not open outflow vector %s' % outflow_vector_path) - * - */ - __pyx_t_5 = (__pyx_v_outflow_vector == Py_None); - __pyx_t_4 = (__pyx_t_5 != 0); - if (unlikely(__pyx_t_4)) { - - /* "pygeoprocessing/routing/watershed.pyx":708 - * outflow_vector = gdal.OpenEx(outflow_vector_path, gdal.OF_VECTOR) - * if outflow_vector is None: - * raise ValueError(u'Could not open outflow vector %s' % outflow_vector_path) # <<<<<<<<<<<<<< - * - * driver = ogr.GetDriverByName('GPKG') - */ - __pyx_t_12 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_Could_not_open_outflow_vector_s, __pyx_v_outflow_vector_path); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 708, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_12); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 708, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_Raise(__pyx_t_8, 0, 0, 0); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __PYX_ERR(0, 708, __pyx_L1_error) - - /* "pygeoprocessing/routing/watershed.pyx":707 - * - * outflow_vector = gdal.OpenEx(outflow_vector_path, gdal.OF_VECTOR) - * if outflow_vector is None: # <<<<<<<<<<<<<< - * raise ValueError(u'Could not open outflow vector %s' % outflow_vector_path) - * - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":710 - * raise ValueError(u'Could not open outflow vector %s' % outflow_vector_path) - * - * driver = ogr.GetDriverByName('GPKG') # <<<<<<<<<<<<<< - * watersheds_srs = osr.SpatialReference() - * watersheds_srs.ImportFromWkt(flow_dir_info['projection_wkt']) - */ - __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_ogr); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 710, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_GetDriverByName); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 710, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_19))) { - __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_19); - if (likely(__pyx_t_12)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19); - __Pyx_INCREF(__pyx_t_12); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_19, function); - } - } - __pyx_t_8 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_19, __pyx_t_12, __pyx_n_u_GPKG) : __Pyx_PyObject_CallOneArg(__pyx_t_19, __pyx_n_u_GPKG); - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 710, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __pyx_v_driver = __pyx_t_8; - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":711 - * - * driver = ogr.GetDriverByName('GPKG') - * watersheds_srs = osr.SpatialReference() # <<<<<<<<<<<<<< - * watersheds_srs.ImportFromWkt(flow_dir_info['projection_wkt']) - * watersheds_vector = driver.CreateDataSource(target_watersheds_vector_path) - */ - __Pyx_GetModuleGlobalName(__pyx_t_19, __pyx_n_s_osr); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 711, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_n_s_SpatialReference); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 711, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __pyx_t_19 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_19)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_19); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - } - } - __pyx_t_8 = (__pyx_t_19) ? __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_19) : __Pyx_PyObject_CallNoArg(__pyx_t_12); - __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 711, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_v_watersheds_srs = __pyx_t_8; - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":712 - * driver = ogr.GetDriverByName('GPKG') - * watersheds_srs = osr.SpatialReference() - * watersheds_srs.ImportFromWkt(flow_dir_info['projection_wkt']) # <<<<<<<<<<<<<< - * watersheds_vector = driver.CreateDataSource(target_watersheds_vector_path) - * polygonized_watersheds_layer = watersheds_vector.CreateLayer( - */ - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_watersheds_srs, __pyx_n_s_ImportFromWkt); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 712, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_19 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_projection_wkt); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 712, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - } - } - __pyx_t_8 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_11, __pyx_t_19) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_19); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 712, __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/watershed.pyx":713 - * watersheds_srs = osr.SpatialReference() - * watersheds_srs.ImportFromWkt(flow_dir_info['projection_wkt']) - * watersheds_vector = driver.CreateDataSource(target_watersheds_vector_path) # <<<<<<<<<<<<<< - * polygonized_watersheds_layer = watersheds_vector.CreateLayer( - * 'polygonized_watersheds', watersheds_srs, ogr.wkbPolygon) - */ - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_driver, __pyx_n_s_CreateDataSource); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 713, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_19 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_19)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_19); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - } - } - __pyx_t_8 = (__pyx_t_19) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_19, __pyx_v_target_watersheds_vector_path) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_v_target_watersheds_vector_path); - __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 713, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_v_watersheds_vector = __pyx_t_8; - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":714 - * watersheds_srs.ImportFromWkt(flow_dir_info['projection_wkt']) - * watersheds_vector = driver.CreateDataSource(target_watersheds_vector_path) - * polygonized_watersheds_layer = watersheds_vector.CreateLayer( # <<<<<<<<<<<<<< - * 'polygonized_watersheds', watersheds_srs, ogr.wkbPolygon) - * - */ - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_watersheds_vector, __pyx_n_s_CreateLayer); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 714, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - - /* "pygeoprocessing/routing/watershed.pyx":715 - * watersheds_vector = driver.CreateDataSource(target_watersheds_vector_path) - * polygonized_watersheds_layer = watersheds_vector.CreateLayer( - * 'polygonized_watersheds', watersheds_srs, ogr.wkbPolygon) # <<<<<<<<<<<<<< - * - * # Using wkbUnknown layer data type because it's possible for a single - */ - __Pyx_GetModuleGlobalName(__pyx_t_19, __pyx_n_s_ogr); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 715, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_n_s_wkbPolygon); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 715, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __pyx_t_19 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_19)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_19); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_12)) { - PyObject *__pyx_temp[4] = {__pyx_t_19, __pyx_n_u_polygonized_watersheds, __pyx_v_watersheds_srs, __pyx_t_11}; - __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 714, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) { - PyObject *__pyx_temp[4] = {__pyx_t_19, __pyx_n_u_polygonized_watersheds, __pyx_v_watersheds_srs, __pyx_t_11}; - __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 714, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } else - #endif - { - __pyx_t_7 = PyTuple_New(3+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 714, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_19) { - __Pyx_GIVEREF(__pyx_t_19); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_19); __pyx_t_19 = NULL; - } - __Pyx_INCREF(__pyx_n_u_polygonized_watersheds); - __Pyx_GIVEREF(__pyx_n_u_polygonized_watersheds); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_9, __pyx_n_u_polygonized_watersheds); - __Pyx_INCREF(__pyx_v_watersheds_srs); - __Pyx_GIVEREF(__pyx_v_watersheds_srs); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_9, __pyx_v_watersheds_srs); - __Pyx_GIVEREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_9, __pyx_t_11); - __pyx_t_11 = 0; - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 714, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_v_polygonized_watersheds_layer = __pyx_t_8; - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":722 - * # technically not supported by the GPKG standard although GDAL - * # allows it for the time being. - * watersheds_layer = watersheds_vector.CreateLayer( # <<<<<<<<<<<<<< - * target_layer_name, watersheds_srs, ogr.wkbUnknown) - * index_field = ogr.FieldDefn('ws_id', ogr.OFTInteger) - */ - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_watersheds_vector, __pyx_n_s_CreateLayer); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 722, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - - /* "pygeoprocessing/routing/watershed.pyx":723 - * # allows it for the time being. - * watersheds_layer = watersheds_vector.CreateLayer( - * target_layer_name, watersheds_srs, ogr.wkbUnknown) # <<<<<<<<<<<<<< - * index_field = ogr.FieldDefn('ws_id', ogr.OFTInteger) - * index_field.SetWidth(24) - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ogr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 723, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_wkbUnknown); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 723, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_12)) { - PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_v_target_layer_name, __pyx_v_watersheds_srs, __pyx_t_11}; - __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 722, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) { - PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_v_target_layer_name, __pyx_v_watersheds_srs, __pyx_t_11}; - __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 722, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } else - #endif - { - __pyx_t_19 = PyTuple_New(3+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 722, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - if (__pyx_t_7) { - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_7); __pyx_t_7 = NULL; - } - __Pyx_INCREF(__pyx_v_target_layer_name); - __Pyx_GIVEREF(__pyx_v_target_layer_name); - PyTuple_SET_ITEM(__pyx_t_19, 0+__pyx_t_9, __pyx_v_target_layer_name); - __Pyx_INCREF(__pyx_v_watersheds_srs); - __Pyx_GIVEREF(__pyx_v_watersheds_srs); - PyTuple_SET_ITEM(__pyx_t_19, 1+__pyx_t_9, __pyx_v_watersheds_srs); - __Pyx_GIVEREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_19, 2+__pyx_t_9, __pyx_t_11); - __pyx_t_11 = 0; - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_19, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 722, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - } - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_v_watersheds_layer = __pyx_t_8; - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":724 - * watersheds_layer = watersheds_vector.CreateLayer( - * target_layer_name, watersheds_srs, ogr.wkbUnknown) - * index_field = ogr.FieldDefn('ws_id', ogr.OFTInteger) # <<<<<<<<<<<<<< - * index_field.SetWidth(24) - * polygonized_watersheds_layer.CreateField(index_field) - */ - __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_ogr); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 724, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_FieldDefn); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 724, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_ogr); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 724, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_OFTInteger); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 724, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_19))) { - __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_19); - if (likely(__pyx_t_12)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19); - __Pyx_INCREF(__pyx_t_12); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_19, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_19)) { - PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_n_u_ws_id, __pyx_t_11}; - __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_19, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 724, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_19)) { - PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_n_u_ws_id, __pyx_t_11}; - __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_19, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 724, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 724, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_12) { - __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_12); __pyx_t_12 = NULL; - } - __Pyx_INCREF(__pyx_n_u_ws_id); - __Pyx_GIVEREF(__pyx_n_u_ws_id); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_9, __pyx_n_u_ws_id); - __Pyx_GIVEREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_9, __pyx_t_11); - __pyx_t_11 = 0; - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_19, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 724, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __pyx_v_index_field = __pyx_t_8; - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":725 - * target_layer_name, watersheds_srs, ogr.wkbUnknown) - * index_field = ogr.FieldDefn('ws_id', ogr.OFTInteger) - * index_field.SetWidth(24) # <<<<<<<<<<<<<< - * polygonized_watersheds_layer.CreateField(index_field) - * - */ - __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_v_index_field, __pyx_n_s_SetWidth); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 725, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_19))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_19); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_19, function); - } - } - __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_19, __pyx_t_7, __pyx_int_24) : __Pyx_PyObject_CallOneArg(__pyx_t_19, __pyx_int_24); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 725, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":726 - * index_field = ogr.FieldDefn('ws_id', ogr.OFTInteger) - * index_field.SetWidth(24) - * polygonized_watersheds_layer.CreateField(index_field) # <<<<<<<<<<<<<< - * - * cdef int* reverse_flow = [4, 5, 6, 7, 0, 1, 2, 3] - */ - __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_v_polygonized_watersheds_layer, __pyx_n_s_CreateField); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 726, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_19))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_19); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_19, function); - } - } - __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_19, __pyx_t_7, __pyx_v_index_field) : __Pyx_PyObject_CallOneArg(__pyx_t_19, __pyx_v_index_field); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 726, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":728 - * polygonized_watersheds_layer.CreateField(index_field) - * - * cdef int* reverse_flow = [4, 5, 6, 7, 0, 1, 2, 3] # <<<<<<<<<<<<<< - * cdef int* neighbor_col = [1, 1, 0, -1, -1, -1, 0, 1] - * cdef int* neighbor_row = [0, -1, -1, -1, 0, 1, 1, 1] - */ - __pyx_t_20[0] = 4; - __pyx_t_20[1] = 5; - __pyx_t_20[2] = 6; - __pyx_t_20[3] = 7; - __pyx_t_20[4] = 0; - __pyx_t_20[5] = 1; - __pyx_t_20[6] = 2; - __pyx_t_20[7] = 3; - __pyx_v_reverse_flow = __pyx_t_20; - - /* "pygeoprocessing/routing/watershed.pyx":729 - * - * cdef int* reverse_flow = [4, 5, 6, 7, 0, 1, 2, 3] - * cdef int* neighbor_col = [1, 1, 0, -1, -1, -1, 0, 1] # <<<<<<<<<<<<<< - * cdef int* neighbor_row = [0, -1, -1, -1, 0, 1, 1, 1] - * cdef queue[CoordinatePair] process_queue - */ - __pyx_t_21[0] = 1; - __pyx_t_21[1] = 1; - __pyx_t_21[2] = 0; - __pyx_t_21[3] = -1; - __pyx_t_21[4] = -1; - __pyx_t_21[5] = -1; - __pyx_t_21[6] = 0; - __pyx_t_21[7] = 1; - __pyx_v_neighbor_col = __pyx_t_21; - - /* "pygeoprocessing/routing/watershed.pyx":730 - * cdef int* reverse_flow = [4, 5, 6, 7, 0, 1, 2, 3] - * cdef int* neighbor_col = [1, 1, 0, -1, -1, -1, 0, 1] - * cdef int* neighbor_row = [0, -1, -1, -1, 0, 1, 1, 1] # <<<<<<<<<<<<<< - * cdef queue[CoordinatePair] process_queue - * cdef cset[CoordinatePair] process_queue_set - */ - __pyx_t_22[0] = 0; - __pyx_t_22[1] = -1; - __pyx_t_22[2] = -1; - __pyx_t_22[3] = -1; - __pyx_t_22[4] = 0; - __pyx_t_22[5] = 1; - __pyx_t_22[6] = 1; - __pyx_t_22[7] = 1; - __pyx_v_neighbor_row = __pyx_t_22; - - /* "pygeoprocessing/routing/watershed.pyx":736 - * cdef int ix_min, iy_min, ix_max, iy_max - * cdef _ManagedRaster scratch_managed_raster - * cdef int watersheds_created = 0 # <<<<<<<<<<<<<< - * cdef int current_fid, outflow_feature_count - * cdef cset[CoordinatePair].iterator seed_iterator - */ - __pyx_v_watersheds_created = 0; - - /* "pygeoprocessing/routing/watershed.pyx":741 - * cdef cset[CoordinatePair] seeds_in_watershed - * cdef time_t last_log_time - * cdef int n_cells_visited = 0 # <<<<<<<<<<<<<< - * - * LOGGER.info('Delineating watersheds') - */ - __pyx_v_n_cells_visited = 0; - - /* "pygeoprocessing/routing/watershed.pyx":743 - * cdef int n_cells_visited = 0 - * - * LOGGER.info('Delineating watersheds') # <<<<<<<<<<<<<< - * outflow_layer = outflow_vector.GetLayer() - * outflow_feature_count = outflow_layer.GetFeatureCount() - */ - __Pyx_GetModuleGlobalName(__pyx_t_19, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 743, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_n_s_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 743, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __pyx_t_19 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_19)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_19); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_8 = (__pyx_t_19) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_19, __pyx_kp_u_Delineating_watersheds) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_kp_u_Delineating_watersheds); - __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 743, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":744 - * - * LOGGER.info('Delineating watersheds') - * outflow_layer = outflow_vector.GetLayer() # <<<<<<<<<<<<<< - * outflow_feature_count = outflow_layer.GetFeatureCount() - * flow_dir_srs = osr.SpatialReference() - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_outflow_vector, __pyx_n_s_GetLayer); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 744, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_19 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_19)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_19); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_8 = (__pyx_t_19) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_19) : __Pyx_PyObject_CallNoArg(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 744, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_outflow_layer = __pyx_t_8; - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":745 - * LOGGER.info('Delineating watersheds') - * outflow_layer = outflow_vector.GetLayer() - * outflow_feature_count = outflow_layer.GetFeatureCount() # <<<<<<<<<<<<<< - * flow_dir_srs = osr.SpatialReference() - * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_outflow_layer, __pyx_n_s_GetFeatureCount); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 745, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_19 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_19)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_19); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_8 = (__pyx_t_19) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_19) : __Pyx_PyObject_CallNoArg(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 745, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_8); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 745, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_outflow_feature_count = __pyx_t_9; - - /* "pygeoprocessing/routing/watershed.pyx":746 - * outflow_layer = outflow_vector.GetLayer() - * outflow_feature_count = outflow_layer.GetFeatureCount() - * flow_dir_srs = osr.SpatialReference() # <<<<<<<<<<<<<< - * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) - * for feature in outflow_layer: - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_osr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 746, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_SpatialReference); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 746, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_19))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_19); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_19, function); - } - } - __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_19, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_19); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 746, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __Pyx_DECREF_SET(__pyx_v_flow_dir_srs, __pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":747 - * outflow_feature_count = outflow_layer.GetFeatureCount() - * flow_dir_srs = osr.SpatialReference() - * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) # <<<<<<<<<<<<<< - * for feature in outflow_layer: - * # Some vectors start indexing their FIDs at 0. - */ - __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_srs, __pyx_n_s_ImportFromWkt); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 747, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __pyx_t_7 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_projection_wkt); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 747, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_19))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_19); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_19, function); - } - } - __pyx_t_8 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_19, __pyx_t_11, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_19, __pyx_t_7); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 747, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":748 - * flow_dir_srs = osr.SpatialReference() - * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) - * for feature in outflow_layer: # <<<<<<<<<<<<<< - * # Some vectors start indexing their FIDs at 0. - * # The mask raster input to polygonization, however, only regards pixels - */ - if (likely(PyList_CheckExact(__pyx_v_outflow_layer)) || PyTuple_CheckExact(__pyx_v_outflow_layer)) { - __pyx_t_8 = __pyx_v_outflow_layer; __Pyx_INCREF(__pyx_t_8); __pyx_t_23 = 0; - __pyx_t_24 = NULL; - } else { - __pyx_t_23 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_outflow_layer); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 748, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_24 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 748, __pyx_L1_error) - } - for (;;) { - if (likely(!__pyx_t_24)) { - if (likely(PyList_CheckExact(__pyx_t_8))) { - if (__pyx_t_23 >= PyList_GET_SIZE(__pyx_t_8)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_19 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_23); __Pyx_INCREF(__pyx_t_19); __pyx_t_23++; if (unlikely(0 < 0)) __PYX_ERR(0, 748, __pyx_L1_error) - #else - __pyx_t_19 = PySequence_ITEM(__pyx_t_8, __pyx_t_23); __pyx_t_23++; if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 748, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - #endif - } else { - if (__pyx_t_23 >= PyTuple_GET_SIZE(__pyx_t_8)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_19 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_23); __Pyx_INCREF(__pyx_t_19); __pyx_t_23++; if (unlikely(0 < 0)) __PYX_ERR(0, 748, __pyx_L1_error) - #else - __pyx_t_19 = PySequence_ITEM(__pyx_t_8, __pyx_t_23); __pyx_t_23++; if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 748, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - #endif - } - } else { - __pyx_t_19 = __pyx_t_24(__pyx_t_8); - if (unlikely(!__pyx_t_19)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 748, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_19); - } - __Pyx_XDECREF_SET(__pyx_v_feature, __pyx_t_19); - __pyx_t_19 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":753 - * # as zero or nonzero. Therefore, to make sure we can use the ws_id as - * # the FID and not maintain a separate mask raster, we'll just add 1. - * current_fid = feature.GetFID() # <<<<<<<<<<<<<< - * ws_id = current_fid + 1 - * assert ws_id >= 1, 'WSID <= 1!' - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_feature, __pyx_n_s_GetFID); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 753, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_19 = (__pyx_t_11) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_11) : __Pyx_PyObject_CallNoArg(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 753, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_19); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 753, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __pyx_v_current_fid = __pyx_t_9; - - /* "pygeoprocessing/routing/watershed.pyx":754 - * # the FID and not maintain a separate mask raster, we'll just add 1. - * current_fid = feature.GetFID() - * ws_id = current_fid + 1 # <<<<<<<<<<<<<< - * assert ws_id >= 1, 'WSID <= 1!' - * - */ - __pyx_v_ws_id = (__pyx_v_current_fid + 1); - - /* "pygeoprocessing/routing/watershed.pyx":755 - * current_fid = feature.GetFID() - * ws_id = current_fid + 1 - * assert ws_id >= 1, 'WSID <= 1!' # <<<<<<<<<<<<<< - * - * geom = feature.GetGeometryRef() - */ - #ifndef CYTHON_WITHOUT_ASSERTIONS - if (unlikely(!Py_OptimizeFlag)) { - if (unlikely(!((__pyx_v_ws_id >= 1) != 0))) { - PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_WSID_1); - __PYX_ERR(0, 755, __pyx_L1_error) - } - } - #endif - - /* "pygeoprocessing/routing/watershed.pyx":757 - * assert ws_id >= 1, 'WSID <= 1!' - * - * geom = feature.GetGeometryRef() # <<<<<<<<<<<<<< - * if geom.IsEmpty(): - * LOGGER.debug( - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_feature, __pyx_n_s_GetGeometryRef); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 757, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_19 = (__pyx_t_11) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_11) : __Pyx_PyObject_CallNoArg(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 757, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF_SET(__pyx_v_geom, __pyx_t_19); - __pyx_t_19 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":758 - * - * geom = feature.GetGeometryRef() - * if geom.IsEmpty(): # <<<<<<<<<<<<<< - * LOGGER.debug( - * 'Outflow feature %s has empty geometry. Skipping.', - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_geom, __pyx_n_s_IsEmpty); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 758, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_19 = (__pyx_t_11) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_11) : __Pyx_PyObject_CallNoArg(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 758, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_19); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 758, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - if (__pyx_t_4) { - - /* "pygeoprocessing/routing/watershed.pyx":759 - * geom = feature.GetGeometryRef() - * if geom.IsEmpty(): - * LOGGER.debug( # <<<<<<<<<<<<<< - * 'Outflow feature %s has empty geometry. Skipping.', - * current_fid) - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 759, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_debug); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 759, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":761 - * LOGGER.debug( - * 'Outflow feature %s has empty geometry. Skipping.', - * current_fid) # <<<<<<<<<<<<<< - * continue - * geom_wkb = geom.ExportToWkb() - */ - __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_current_fid); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 761, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_12 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_12)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_12); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_11)) { - PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_kp_u_Outflow_feature_s_has_empty_geom, __pyx_t_7}; - __pyx_t_19 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 759, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { - PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_kp_u_Outflow_feature_s_has_empty_geom, __pyx_t_7}; - __pyx_t_19 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 759, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - { - __pyx_t_18 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 759, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - if (__pyx_t_12) { - __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_12); __pyx_t_12 = NULL; - } - __Pyx_INCREF(__pyx_kp_u_Outflow_feature_s_has_empty_geom); - __Pyx_GIVEREF(__pyx_kp_u_Outflow_feature_s_has_empty_geom); - PyTuple_SET_ITEM(__pyx_t_18, 0+__pyx_t_9, __pyx_kp_u_Outflow_feature_s_has_empty_geom); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_18, 1+__pyx_t_9, __pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_18, NULL); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 759, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - } - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":762 - * 'Outflow feature %s has empty geometry. Skipping.', - * current_fid) - * continue # <<<<<<<<<<<<<< - * geom_wkb = geom.ExportToWkb() - * shapely_geom = shapely.wkb.loads(geom_wkb) - */ - goto __pyx_L16_continue; - - /* "pygeoprocessing/routing/watershed.pyx":758 - * - * geom = feature.GetGeometryRef() - * if geom.IsEmpty(): # <<<<<<<<<<<<<< - * LOGGER.debug( - * 'Outflow feature %s has empty geometry. Skipping.', - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":763 - * current_fid) - * continue - * geom_wkb = geom.ExportToWkb() # <<<<<<<<<<<<<< - * shapely_geom = shapely.wkb.loads(geom_wkb) - * - */ - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_geom, __pyx_n_s_ExportToWkb); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 763, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_18 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_18 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_18)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_18); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - } - } - __pyx_t_19 = (__pyx_t_18) ? __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_18) : __Pyx_PyObject_CallNoArg(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; - if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 763, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_XDECREF_SET(__pyx_v_geom_wkb, __pyx_t_19); - __pyx_t_19 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":764 - * continue - * geom_wkb = geom.ExportToWkb() - * shapely_geom = shapely.wkb.loads(geom_wkb) # <<<<<<<<<<<<<< - * - * LOGGER.debug('Testing geometry bbox') - */ - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_shapely); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 764, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_18 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_wkb); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 764, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_18, __pyx_n_s_loads); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 764, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __pyx_t_18 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_18 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_18)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_18); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - } - } - __pyx_t_19 = (__pyx_t_18) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_18, __pyx_v_geom_wkb) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_v_geom_wkb); - __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; - if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 764, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_XDECREF_SET(__pyx_v_shapely_geom, __pyx_t_19); - __pyx_t_19 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":766 - * shapely_geom = shapely.wkb.loads(geom_wkb) - * - * LOGGER.debug('Testing geometry bbox') # <<<<<<<<<<<<<< - * if not flow_dir_bbox.intersects(shapely.geometry.box(*shapely_geom.bounds)): - * LOGGER.debug( - */ - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 766, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_18 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_debug); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 766, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_18))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_18); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_18); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_18, function); - } - } - __pyx_t_19 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_18, __pyx_t_11, __pyx_kp_u_Testing_geometry_bbox) : __Pyx_PyObject_CallOneArg(__pyx_t_18, __pyx_kp_u_Testing_geometry_bbox); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 766, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":767 - * - * LOGGER.debug('Testing geometry bbox') - * if not flow_dir_bbox.intersects(shapely.geometry.box(*shapely_geom.bounds)): # <<<<<<<<<<<<<< - * LOGGER.debug( - * 'Outflow feature %s does not overlap with the flow ' - */ - __pyx_t_18 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_bbox, __pyx_n_s_intersects); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 767, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_shapely); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 767, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_geometry); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 767, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_box); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 767, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_shapely_geom, __pyx_n_s_bounds); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 767, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_12 = __Pyx_PySequence_Tuple(__pyx_t_7); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 767, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_12, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 767, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_18))) { - __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_18); - if (likely(__pyx_t_12)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_18); - __Pyx_INCREF(__pyx_t_12); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_18, function); - } - } - __pyx_t_19 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_18, __pyx_t_12, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_18, __pyx_t_7); - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 767, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_19); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 767, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __pyx_t_5 = ((!__pyx_t_4) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/watershed.pyx":768 - * LOGGER.debug('Testing geometry bbox') - * if not flow_dir_bbox.intersects(shapely.geometry.box(*shapely_geom.bounds)): - * LOGGER.debug( # <<<<<<<<<<<<<< - * 'Outflow feature %s does not overlap with the flow ' - * 'direction raster. Skipping.', current_fid) - */ - __Pyx_GetModuleGlobalName(__pyx_t_18, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 768, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_18, __pyx_n_s_debug); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 768, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":770 - * LOGGER.debug( - * 'Outflow feature %s does not overlap with the flow ' - * 'direction raster. Skipping.', current_fid) # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_18 = __Pyx_PyInt_From_int(__pyx_v_current_fid); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 770, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __pyx_t_12 = NULL; - __pyx_t_9 = 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_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_kp_u_Outflow_feature_s_does_not_overl, __pyx_t_18}; - __pyx_t_19 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 768, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_kp_u_Outflow_feature_s_does_not_overl, __pyx_t_18}; - __pyx_t_19 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 768, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - } else - #endif - { - __pyx_t_11 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 768, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - if (__pyx_t_12) { - __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_12); __pyx_t_12 = NULL; - } - __Pyx_INCREF(__pyx_kp_u_Outflow_feature_s_does_not_overl); - __Pyx_GIVEREF(__pyx_kp_u_Outflow_feature_s_does_not_overl); - PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_9, __pyx_kp_u_Outflow_feature_s_does_not_overl); - __Pyx_GIVEREF(__pyx_t_18); - PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_9, __pyx_t_18); - __pyx_t_18 = 0; - __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_11, NULL); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 768, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":771 - * 'Outflow feature %s does not overlap with the flow ' - * 'direction raster. Skipping.', current_fid) - * continue # <<<<<<<<<<<<<< - * - * seeds_raster_path = os.path.join(working_dir_path, '%s_rasterized.tif' % ws_id) - */ - goto __pyx_L16_continue; - - /* "pygeoprocessing/routing/watershed.pyx":767 - * - * LOGGER.debug('Testing geometry bbox') - * if not flow_dir_bbox.intersects(shapely.geometry.box(*shapely_geom.bounds)): # <<<<<<<<<<<<<< - * LOGGER.debug( - * 'Outflow feature %s does not overlap with the flow ' - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":773 - * continue - * - * seeds_raster_path = os.path.join(working_dir_path, '%s_rasterized.tif' % ws_id) # <<<<<<<<<<<<<< - * if write_diagnostic_vector: - * diagnostic_vector_path = os.path.join(working_dir_path, '%s_seeds.gpkg' % ws_id) - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_os); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 773, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_path); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 773, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_join); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 773, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_PyInt_From_int(__pyx_v_ws_id); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 773, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_18 = PyUnicode_Format(__pyx_kp_u_s_rasterized_tif, __pyx_t_11); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 773, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_working_dir_path, __pyx_t_18}; - __pyx_t_19 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 773, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_working_dir_path, __pyx_t_18}; - __pyx_t_19 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 773, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - } else - #endif - { - __pyx_t_12 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 773, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - if (__pyx_t_11) { - __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11); __pyx_t_11 = NULL; - } - __Pyx_INCREF(__pyx_v_working_dir_path); - __Pyx_GIVEREF(__pyx_v_working_dir_path); - PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_9, __pyx_v_working_dir_path); - __Pyx_GIVEREF(__pyx_t_18); - PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_9, __pyx_t_18); - __pyx_t_18 = 0; - __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_12, NULL); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 773, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF_SET(__pyx_v_seeds_raster_path, __pyx_t_19); - __pyx_t_19 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":774 - * - * seeds_raster_path = os.path.join(working_dir_path, '%s_rasterized.tif' % ws_id) - * if write_diagnostic_vector: # <<<<<<<<<<<<<< - * diagnostic_vector_path = os.path.join(working_dir_path, '%s_seeds.gpkg' % ws_id) - * else: - */ - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_write_diagnostic_vector); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 774, __pyx_L1_error) - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/watershed.pyx":775 - * seeds_raster_path = os.path.join(working_dir_path, '%s_rasterized.tif' % ws_id) - * if write_diagnostic_vector: - * diagnostic_vector_path = os.path.join(working_dir_path, '%s_seeds.gpkg' % ws_id) # <<<<<<<<<<<<<< - * else: - * diagnostic_vector_path = None - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_os); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 775, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_path); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 775, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_join); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 775, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = __Pyx_PyInt_From_int(__pyx_v_ws_id); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 775, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_18 = PyUnicode_Format(__pyx_kp_u_s_seeds_gpkg, __pyx_t_12); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 775, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && likely(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_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_v_working_dir_path, __pyx_t_18}; - __pyx_t_19 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 775, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_v_working_dir_path, __pyx_t_18}; - __pyx_t_19 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 775, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - } else - #endif - { - __pyx_t_11 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 775, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - if (__pyx_t_12) { - __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_12); __pyx_t_12 = NULL; - } - __Pyx_INCREF(__pyx_v_working_dir_path); - __Pyx_GIVEREF(__pyx_v_working_dir_path); - PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_9, __pyx_v_working_dir_path); - __Pyx_GIVEREF(__pyx_t_18); - PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_9, __pyx_t_18); - __pyx_t_18 = 0; - __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_11, NULL); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 775, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF_SET(__pyx_v_diagnostic_vector_path, __pyx_t_19); - __pyx_t_19 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":774 - * - * seeds_raster_path = os.path.join(working_dir_path, '%s_rasterized.tif' % ws_id) - * if write_diagnostic_vector: # <<<<<<<<<<<<<< - * diagnostic_vector_path = os.path.join(working_dir_path, '%s_seeds.gpkg' % ws_id) - * else: - */ - goto __pyx_L20; - } - - /* "pygeoprocessing/routing/watershed.pyx":777 - * diagnostic_vector_path = os.path.join(working_dir_path, '%s_seeds.gpkg' % ws_id) - * else: - * diagnostic_vector_path = None # <<<<<<<<<<<<<< - * seeds_in_watershed = _c_split_geometry_into_seeds( - * geom_wkb, - */ - /*else*/ { - __Pyx_INCREF(Py_None); - __Pyx_XDECREF_SET(__pyx_v_diagnostic_vector_path, Py_None); - } - __pyx_L20:; - - /* "pygeoprocessing/routing/watershed.pyx":780 - * seeds_in_watershed = _c_split_geometry_into_seeds( - * geom_wkb, - * source_gt, # <<<<<<<<<<<<<< - * flow_dir_srs=flow_dir_srs, - * flow_dir_n_cols=flow_dir_n_cols, - */ - if (!(likely(PyTuple_CheckExact(__pyx_v_source_gt))||((__pyx_v_source_gt) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v_source_gt)->tp_name), 0))) __PYX_ERR(0, 780, __pyx_L1_error) - - /* "pygeoprocessing/routing/watershed.pyx":782 - * source_gt, - * flow_dir_srs=flow_dir_srs, - * flow_dir_n_cols=flow_dir_n_cols, # <<<<<<<<<<<<<< - * flow_dir_n_rows=flow_dir_n_rows, - * target_raster_path=seeds_raster_path, - */ - __pyx_t_19 = __Pyx_PyInt_From_int(__pyx_v_flow_dir_n_cols); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 782, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - - /* "pygeoprocessing/routing/watershed.pyx":783 - * flow_dir_srs=flow_dir_srs, - * flow_dir_n_cols=flow_dir_n_cols, - * flow_dir_n_rows=flow_dir_n_rows, # <<<<<<<<<<<<<< - * target_raster_path=seeds_raster_path, - * diagnostic_vector_path=diagnostic_vector_path - */ - __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_flow_dir_n_rows); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 783, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - - /* "pygeoprocessing/routing/watershed.pyx":778 - * else: - * diagnostic_vector_path = None - * seeds_in_watershed = _c_split_geometry_into_seeds( # <<<<<<<<<<<<<< - * geom_wkb, - * source_gt, - */ - __pyx_t_26.__pyx_n = 1; - __pyx_t_26.diagnostic_vector_path = __pyx_v_diagnostic_vector_path; - __pyx_t_25 = __pyx_f_15pygeoprocessing_7routing_9watershed__c_split_geometry_into_seeds(__pyx_v_geom_wkb, ((PyObject*)__pyx_v_source_gt), __pyx_v_flow_dir_srs, __pyx_t_19, __pyx_t_7, __pyx_v_seeds_raster_path, &__pyx_t_26); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_seeds_in_watershed = __pyx_t_25; - - /* "pygeoprocessing/routing/watershed.pyx":788 - * ) - * - * seed_iterator = seeds_in_watershed.begin() # <<<<<<<<<<<<<< - * while seed_iterator != seeds_in_watershed.end(): - * seed = deref(seed_iterator) - */ - __pyx_v_seed_iterator = __pyx_v_seeds_in_watershed.begin(); - - /* "pygeoprocessing/routing/watershed.pyx":789 - * - * seed_iterator = seeds_in_watershed.begin() - * while seed_iterator != seeds_in_watershed.end(): # <<<<<<<<<<<<<< - * seed = deref(seed_iterator) - * inc(seed_iterator) - */ - while (1) { - __pyx_t_5 = ((__pyx_v_seed_iterator != __pyx_v_seeds_in_watershed.end()) != 0); - if (!__pyx_t_5) break; - - /* "pygeoprocessing/routing/watershed.pyx":790 - * seed_iterator = seeds_in_watershed.begin() - * while seed_iterator != seeds_in_watershed.end(): - * seed = deref(seed_iterator) # <<<<<<<<<<<<<< - * inc(seed_iterator) - * - */ - __pyx_v_seed = (*__pyx_v_seed_iterator); - - /* "pygeoprocessing/routing/watershed.pyx":791 - * while seed_iterator != seeds_in_watershed.end(): - * seed = deref(seed_iterator) - * inc(seed_iterator) # <<<<<<<<<<<<<< - * - * if not 0 <= seed.first < flow_dir_n_cols: - */ - (void)((++__pyx_v_seed_iterator)); - - /* "pygeoprocessing/routing/watershed.pyx":793 - * inc(seed_iterator) - * - * if not 0 <= seed.first < flow_dir_n_cols: # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_5 = (0 <= __pyx_v_seed.first); - if (__pyx_t_5) { - __pyx_t_5 = (__pyx_v_seed.first < __pyx_v_flow_dir_n_cols); - } - __pyx_t_4 = ((!(__pyx_t_5 != 0)) != 0); - if (__pyx_t_4) { - - /* "pygeoprocessing/routing/watershed.pyx":794 - * - * if not 0 <= seed.first < flow_dir_n_cols: - * continue # <<<<<<<<<<<<<< - * - * if not 0 <= seed.second < flow_dir_n_rows: - */ - goto __pyx_L21_continue; - - /* "pygeoprocessing/routing/watershed.pyx":793 - * inc(seed_iterator) - * - * if not 0 <= seed.first < flow_dir_n_cols: # <<<<<<<<<<<<<< - * continue - * - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":796 - * continue - * - * if not 0 <= seed.second < flow_dir_n_rows: # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_4 = (0 <= __pyx_v_seed.second); - if (__pyx_t_4) { - __pyx_t_4 = (__pyx_v_seed.second < __pyx_v_flow_dir_n_rows); - } - __pyx_t_5 = ((!(__pyx_t_4 != 0)) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/watershed.pyx":797 - * - * if not 0 <= seed.second < flow_dir_n_rows: - * continue # <<<<<<<<<<<<<< - * - * if flow_dir_managed_raster.get(seed.first, seed.second) == flow_dir_nodata: - */ - goto __pyx_L21_continue; - - /* "pygeoprocessing/routing/watershed.pyx":796 - * continue - * - * if not 0 <= seed.second < flow_dir_n_rows: # <<<<<<<<<<<<<< - * continue - * - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":799 - * continue - * - * if flow_dir_managed_raster.get(seed.first, seed.second) == flow_dir_nodata: # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_5 = ((__pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_get(__pyx_v_flow_dir_managed_raster, __pyx_v_seed.first, __pyx_v_seed.second) == __pyx_v_flow_dir_nodata) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/watershed.pyx":800 - * - * if flow_dir_managed_raster.get(seed.first, seed.second) == flow_dir_nodata: - * continue # <<<<<<<<<<<<<< - * - * process_queue.push(seed) - */ - goto __pyx_L21_continue; - - /* "pygeoprocessing/routing/watershed.pyx":799 - * continue - * - * if flow_dir_managed_raster.get(seed.first, seed.second) == flow_dir_nodata: # <<<<<<<<<<<<<< - * continue - * - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":802 - * continue - * - * process_queue.push(seed) # <<<<<<<<<<<<<< - * process_queue_set.insert(seed) - * - */ - __pyx_v_process_queue.push(__pyx_v_seed); - - /* "pygeoprocessing/routing/watershed.pyx":803 - * - * process_queue.push(seed) - * process_queue_set.insert(seed) # <<<<<<<<<<<<<< - * - * if process_queue_set.size() == 0: - */ - try { - __pyx_v_process_queue_set.insert(__pyx_v_seed); - } catch(...) { - __Pyx_CppExn2PyErr(); - __PYX_ERR(0, 803, __pyx_L1_error) - } - __pyx_L21_continue:; - } - - /* "pygeoprocessing/routing/watershed.pyx":805 - * process_queue_set.insert(seed) - * - * if process_queue_set.size() == 0: # <<<<<<<<<<<<<< - * LOGGER.debug( - * 'Outflow feature %s does not intersect any pixels with ' - */ - __pyx_t_5 = ((__pyx_v_process_queue_set.size() == 0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/watershed.pyx":806 - * - * if process_queue_set.size() == 0: - * LOGGER.debug( # <<<<<<<<<<<<<< - * 'Outflow feature %s does not intersect any pixels with ' - * 'valid flow direction. Skipping.', current_fid) - */ - __Pyx_GetModuleGlobalName(__pyx_t_19, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 806, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_n_s_debug); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 806, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":808 - * LOGGER.debug( - * 'Outflow feature %s does not intersect any pixels with ' - * 'valid flow direction. Skipping.', current_fid) # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_19 = __Pyx_PyInt_From_int(__pyx_v_current_fid); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 808, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __pyx_t_18 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_18 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_18)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_18); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_11)) { - PyObject *__pyx_temp[3] = {__pyx_t_18, __pyx_kp_u_Outflow_feature_s_does_not_inter, __pyx_t_19}; - __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 806, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { - PyObject *__pyx_temp[3] = {__pyx_t_18, __pyx_kp_u_Outflow_feature_s_does_not_inter, __pyx_t_19}; - __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 806, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - } else - #endif - { - __pyx_t_12 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 806, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - if (__pyx_t_18) { - __Pyx_GIVEREF(__pyx_t_18); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_18); __pyx_t_18 = NULL; - } - __Pyx_INCREF(__pyx_kp_u_Outflow_feature_s_does_not_inter); - __Pyx_GIVEREF(__pyx_kp_u_Outflow_feature_s_does_not_inter); - PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_9, __pyx_kp_u_Outflow_feature_s_does_not_inter); - __Pyx_GIVEREF(__pyx_t_19); - PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_9, __pyx_t_19); - __pyx_t_19 = 0; - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_12, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 806, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - } - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":809 - * 'Outflow feature %s does not intersect any pixels with ' - * 'valid flow direction. Skipping.', current_fid) - * continue # <<<<<<<<<<<<<< - * - * scratch_raster_path = os.path.join(working_dir_path, - */ - goto __pyx_L16_continue; - - /* "pygeoprocessing/routing/watershed.pyx":805 - * process_queue_set.insert(seed) - * - * if process_queue_set.size() == 0: # <<<<<<<<<<<<<< - * LOGGER.debug( - * 'Outflow feature %s does not intersect any pixels with ' - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":811 - * continue - * - * scratch_raster_path = os.path.join(working_dir_path, # <<<<<<<<<<<<<< - * '%s_scratch.tif' % ws_id) - * scratch_raster = gtiff_driver.Create( - */ - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_os); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 811, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_path); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 811, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_join); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 811, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":812 - * - * scratch_raster_path = os.path.join(working_dir_path, - * '%s_scratch.tif' % ws_id) # <<<<<<<<<<<<<< - * scratch_raster = gtiff_driver.Create( - * scratch_raster_path, - */ - __pyx_t_12 = __Pyx_PyInt_From_int(__pyx_v_ws_id); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 812, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_19 = PyUnicode_Format(__pyx_kp_u_s_scratch_tif, __pyx_t_12); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 812, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_12)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_12); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_11)) { - PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_v_working_dir_path, __pyx_t_19}; - __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 811, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { - PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_v_working_dir_path, __pyx_t_19}; - __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 811, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - } else - #endif - { - __pyx_t_18 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 811, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - if (__pyx_t_12) { - __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_12); __pyx_t_12 = NULL; - } - __Pyx_INCREF(__pyx_v_working_dir_path); - __Pyx_GIVEREF(__pyx_v_working_dir_path); - PyTuple_SET_ITEM(__pyx_t_18, 0+__pyx_t_9, __pyx_v_working_dir_path); - __Pyx_GIVEREF(__pyx_t_19); - PyTuple_SET_ITEM(__pyx_t_18, 1+__pyx_t_9, __pyx_t_19); - __pyx_t_19 = 0; - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_18, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 811, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - } - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_XDECREF_SET(__pyx_v_scratch_raster_path, __pyx_t_7); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":813 - * scratch_raster_path = os.path.join(working_dir_path, - * '%s_scratch.tif' % ws_id) - * scratch_raster = gtiff_driver.Create( # <<<<<<<<<<<<<< - * scratch_raster_path, - * flow_dir_n_cols, - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_gtiff_driver, __pyx_n_s_Create); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 813, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - - /* "pygeoprocessing/routing/watershed.pyx":815 - * scratch_raster = gtiff_driver.Create( - * scratch_raster_path, - * flow_dir_n_cols, # <<<<<<<<<<<<<< - * flow_dir_n_rows, - * 1, # n bands - */ - __pyx_t_11 = __Pyx_PyInt_From_int(__pyx_v_flow_dir_n_cols); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 815, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - - /* "pygeoprocessing/routing/watershed.pyx":816 - * scratch_raster_path, - * flow_dir_n_cols, - * flow_dir_n_rows, # <<<<<<<<<<<<<< - * 1, # n bands - * gdal.GDT_UInt32, - */ - __pyx_t_18 = __Pyx_PyInt_From_int(__pyx_v_flow_dir_n_rows); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 816, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - - /* "pygeoprocessing/routing/watershed.pyx":818 - * flow_dir_n_rows, - * 1, # n bands - * gdal.GDT_UInt32, # <<<<<<<<<<<<<< - * options=GTIFF_CREATION_OPTIONS) - * scratch_raster.SetGeoTransform(source_gt) - */ - __Pyx_GetModuleGlobalName(__pyx_t_19, __pyx_n_s_gdal); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 818, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_n_s_GDT_UInt32); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 818, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":813 - * scratch_raster_path = os.path.join(working_dir_path, - * '%s_scratch.tif' % ws_id) - * scratch_raster = gtiff_driver.Create( # <<<<<<<<<<<<<< - * scratch_raster_path, - * flow_dir_n_cols, - */ - __pyx_t_19 = PyTuple_New(5); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 813, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_INCREF(__pyx_v_scratch_raster_path); - __Pyx_GIVEREF(__pyx_v_scratch_raster_path); - PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_v_scratch_raster_path); - __Pyx_GIVEREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_19, 1, __pyx_t_11); - __Pyx_GIVEREF(__pyx_t_18); - PyTuple_SET_ITEM(__pyx_t_19, 2, __pyx_t_18); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_19, 3, __pyx_int_1); - __Pyx_GIVEREF(__pyx_t_12); - PyTuple_SET_ITEM(__pyx_t_19, 4, __pyx_t_12); - __pyx_t_11 = 0; - __pyx_t_18 = 0; - __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":819 - * 1, # n bands - * gdal.GDT_UInt32, - * options=GTIFF_CREATION_OPTIONS) # <<<<<<<<<<<<<< - * scratch_raster.SetGeoTransform(source_gt) - * scratch_raster.SetProjection(flow_dir_info['projection_wkt']) - */ - __pyx_t_12 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 819, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_GetModuleGlobalName(__pyx_t_18, __pyx_n_s_GTIFF_CREATION_OPTIONS); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 819, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_options, __pyx_t_18) < 0) __PYX_ERR(0, 819, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":813 - * scratch_raster_path = os.path.join(working_dir_path, - * '%s_scratch.tif' % ws_id) - * scratch_raster = gtiff_driver.Create( # <<<<<<<<<<<<<< - * scratch_raster_path, - * flow_dir_n_cols, - */ - __pyx_t_18 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_19, __pyx_t_12); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 813, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_XDECREF_SET(__pyx_v_scratch_raster, __pyx_t_18); - __pyx_t_18 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":820 - * gdal.GDT_UInt32, - * options=GTIFF_CREATION_OPTIONS) - * scratch_raster.SetGeoTransform(source_gt) # <<<<<<<<<<<<<< - * scratch_raster.SetProjection(flow_dir_info['projection_wkt']) - * # strictly speaking, there's no need to set the nodata value on the band. - */ - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_scratch_raster, __pyx_n_s_SetGeoTransform); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 820, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_19 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_19)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_19); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - } - } - __pyx_t_18 = (__pyx_t_19) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_19, __pyx_v_source_gt) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_v_source_gt); - __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; - if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 820, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":821 - * options=GTIFF_CREATION_OPTIONS) - * scratch_raster.SetGeoTransform(source_gt) - * scratch_raster.SetProjection(flow_dir_info['projection_wkt']) # <<<<<<<<<<<<<< - * # strictly speaking, there's no need to set the nodata value on the band. - * scratch_raster = None - */ - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_scratch_raster, __pyx_n_s_SetProjection); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 821, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_19 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_info, __pyx_n_u_projection_wkt); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 821, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - } - } - __pyx_t_18 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_7, __pyx_t_19) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_19); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 821, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":823 - * scratch_raster.SetProjection(flow_dir_info['projection_wkt']) - * # strictly speaking, there's no need to set the nodata value on the band. - * scratch_raster = None # <<<<<<<<<<<<<< - * - * scratch_managed_raster = _ManagedRaster(scratch_raster_path, 1, 1) - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_scratch_raster, Py_None); - - /* "pygeoprocessing/routing/watershed.pyx":825 - * scratch_raster = None - * - * scratch_managed_raster = _ManagedRaster(scratch_raster_path, 1, 1) # <<<<<<<<<<<<<< - * ix_min = flow_dir_n_cols - * iy_min = flow_dir_n_rows - */ - __pyx_t_18 = PyTuple_New(3); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 825, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __Pyx_INCREF(__pyx_v_scratch_raster_path); - __Pyx_GIVEREF(__pyx_v_scratch_raster_path); - PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_v_scratch_raster_path); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_18, 1, __pyx_int_1); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_18, 2, __pyx_int_1); - __pyx_t_12 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_9watershed__ManagedRaster), __pyx_t_18, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 825, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __Pyx_XDECREF_SET(__pyx_v_scratch_managed_raster, ((struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *)__pyx_t_12)); - __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":826 - * - * scratch_managed_raster = _ManagedRaster(scratch_raster_path, 1, 1) - * ix_min = flow_dir_n_cols # <<<<<<<<<<<<<< - * iy_min = flow_dir_n_rows - * ix_max = 0 - */ - __pyx_v_ix_min = __pyx_v_flow_dir_n_cols; - - /* "pygeoprocessing/routing/watershed.pyx":827 - * scratch_managed_raster = _ManagedRaster(scratch_raster_path, 1, 1) - * ix_min = flow_dir_n_cols - * iy_min = flow_dir_n_rows # <<<<<<<<<<<<<< - * ix_max = 0 - * iy_max = 0 - */ - __pyx_v_iy_min = __pyx_v_flow_dir_n_rows; - - /* "pygeoprocessing/routing/watershed.pyx":828 - * ix_min = flow_dir_n_cols - * iy_min = flow_dir_n_rows - * ix_max = 0 # <<<<<<<<<<<<<< - * iy_max = 0 - * n_cells_visited = 0 - */ - __pyx_v_ix_max = 0; - - /* "pygeoprocessing/routing/watershed.pyx":829 - * iy_min = flow_dir_n_rows - * ix_max = 0 - * iy_max = 0 # <<<<<<<<<<<<<< - * n_cells_visited = 0 - * LOGGER.info( - */ - __pyx_v_iy_max = 0; - - /* "pygeoprocessing/routing/watershed.pyx":830 - * ix_max = 0 - * iy_max = 0 - * n_cells_visited = 0 # <<<<<<<<<<<<<< - * LOGGER.info( - * 'Delineating watershed %s of %s (ws_id %s)', - */ - __pyx_v_n_cells_visited = 0; - - /* "pygeoprocessing/routing/watershed.pyx":831 - * iy_max = 0 - * n_cells_visited = 0 - * LOGGER.info( # <<<<<<<<<<<<<< - * 'Delineating watershed %s of %s (ws_id %s)', - * current_fid, outflow_feature_count, ws_id) - */ - __Pyx_GetModuleGlobalName(__pyx_t_18, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 831, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_t_18, __pyx_n_s_info); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 831, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":833 - * LOGGER.info( - * 'Delineating watershed %s of %s (ws_id %s)', - * current_fid, outflow_feature_count, ws_id) # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * while not process_queue.empty(): - */ - __pyx_t_18 = __Pyx_PyInt_From_int(__pyx_v_current_fid); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 833, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_outflow_feature_count); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 833, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_11 = __Pyx_PyInt_From_int(__pyx_v_ws_id); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 833, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_17 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_19))) { - __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_19); - if (likely(__pyx_t_17)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19); - __Pyx_INCREF(__pyx_t_17); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_19, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_19)) { - PyObject *__pyx_temp[5] = {__pyx_t_17, __pyx_kp_u_Delineating_watershed_s_of_s_ws, __pyx_t_18, __pyx_t_7, __pyx_t_11}; - __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_19, __pyx_temp+1-__pyx_t_9, 4+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 831, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_19)) { - PyObject *__pyx_temp[5] = {__pyx_t_17, __pyx_kp_u_Delineating_watershed_s_of_s_ws, __pyx_t_18, __pyx_t_7, __pyx_t_11}; - __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_19, __pyx_temp+1-__pyx_t_9, 4+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 831, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } else - #endif - { - __pyx_t_13 = PyTuple_New(4+__pyx_t_9); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 831, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - if (__pyx_t_17) { - __Pyx_GIVEREF(__pyx_t_17); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_17); __pyx_t_17 = NULL; - } - __Pyx_INCREF(__pyx_kp_u_Delineating_watershed_s_of_s_ws); - __Pyx_GIVEREF(__pyx_kp_u_Delineating_watershed_s_of_s_ws); - PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_9, __pyx_kp_u_Delineating_watershed_s_of_s_ws); - __Pyx_GIVEREF(__pyx_t_18); - PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_9, __pyx_t_18); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_13, 2+__pyx_t_9, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_13, 3+__pyx_t_9, __pyx_t_11); - __pyx_t_18 = 0; - __pyx_t_7 = 0; - __pyx_t_11 = 0; - __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_19, __pyx_t_13, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 831, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - } - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":834 - * 'Delineating watershed %s of %s (ws_id %s)', - * current_fid, outflow_feature_count, ws_id) - * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< - * while not process_queue.empty(): - * if ctime(NULL) - last_log_time > 5.0: - */ - __pyx_v_last_log_time = time(NULL); - - /* "pygeoprocessing/routing/watershed.pyx":835 - * current_fid, outflow_feature_count, ws_id) - * last_log_time = ctime(NULL) - * while not process_queue.empty(): # <<<<<<<<<<<<<< - * if ctime(NULL) - last_log_time > 5.0: - * last_log_time = ctime(NULL) - */ - while (1) { - __pyx_t_5 = ((!(__pyx_v_process_queue.empty() != 0)) != 0); - if (!__pyx_t_5) break; - - /* "pygeoprocessing/routing/watershed.pyx":836 - * last_log_time = ctime(NULL) - * while not process_queue.empty(): - * if ctime(NULL) - last_log_time > 5.0: # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * LOGGER.info( - */ - __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > 5.0) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/watershed.pyx":837 - * while not process_queue.empty(): - * if ctime(NULL) - last_log_time > 5.0: - * last_log_time = ctime(NULL) # <<<<<<<<<<<<<< - * LOGGER.info( - * 'Delineating watershed %s of %s (ws_id %s), %s pixels ' - */ - __pyx_v_last_log_time = time(NULL); - - /* "pygeoprocessing/routing/watershed.pyx":838 - * if ctime(NULL) - last_log_time > 5.0: - * last_log_time = ctime(NULL) - * LOGGER.info( # <<<<<<<<<<<<<< - * 'Delineating watershed %s of %s (ws_id %s), %s pixels ' - * 'found so far', current_fid, outflow_feature_count, - */ - __Pyx_GetModuleGlobalName(__pyx_t_19, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 838, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_n_s_info); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 838, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":840 - * LOGGER.info( - * 'Delineating watershed %s of %s (ws_id %s), %s pixels ' - * 'found so far', current_fid, outflow_feature_count, # <<<<<<<<<<<<<< - * ws_id, n_cells_visited) - * - */ - __pyx_t_19 = __Pyx_PyInt_From_int(__pyx_v_current_fid); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 840, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __pyx_t_11 = __Pyx_PyInt_From_int(__pyx_v_outflow_feature_count); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 840, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - - /* "pygeoprocessing/routing/watershed.pyx":841 - * 'Delineating watershed %s of %s (ws_id %s), %s pixels ' - * 'found so far', current_fid, outflow_feature_count, - * ws_id, n_cells_visited) # <<<<<<<<<<<<<< - * - * current_pixel = process_queue.front() - */ - __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_ws_id); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 841, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_18 = __Pyx_PyInt_From_int(__pyx_v_n_cells_visited); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 841, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - __pyx_t_17 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_13))) { - __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_13); - if (likely(__pyx_t_17)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); - __Pyx_INCREF(__pyx_t_17); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_13, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_13)) { - PyObject *__pyx_temp[6] = {__pyx_t_17, __pyx_kp_u_Delineating_watershed_s_of_s_ws_2, __pyx_t_19, __pyx_t_11, __pyx_t_7, __pyx_t_18}; - __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_9, 5+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 838, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_13)) { - PyObject *__pyx_temp[6] = {__pyx_t_17, __pyx_kp_u_Delineating_watershed_s_of_s_ws_2, __pyx_t_19, __pyx_t_11, __pyx_t_7, __pyx_t_18}; - __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_9, 5+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 838, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - } else - #endif - { - __pyx_t_10 = PyTuple_New(5+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 838, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - if (__pyx_t_17) { - __Pyx_GIVEREF(__pyx_t_17); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_17); __pyx_t_17 = NULL; - } - __Pyx_INCREF(__pyx_kp_u_Delineating_watershed_s_of_s_ws_2); - __Pyx_GIVEREF(__pyx_kp_u_Delineating_watershed_s_of_s_ws_2); - PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_kp_u_Delineating_watershed_s_of_s_ws_2); - __Pyx_GIVEREF(__pyx_t_19); - PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_t_19); - __Pyx_GIVEREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_10, 2+__pyx_t_9, __pyx_t_11); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_10, 3+__pyx_t_9, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_18); - PyTuple_SET_ITEM(__pyx_t_10, 4+__pyx_t_9, __pyx_t_18); - __pyx_t_19 = 0; - __pyx_t_11 = 0; - __pyx_t_7 = 0; - __pyx_t_18 = 0; - __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_10, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 838, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":836 - * last_log_time = ctime(NULL) - * while not process_queue.empty(): - * if ctime(NULL) - last_log_time > 5.0: # <<<<<<<<<<<<<< - * last_log_time = ctime(NULL) - * LOGGER.info( - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":843 - * ws_id, n_cells_visited) - * - * current_pixel = process_queue.front() # <<<<<<<<<<<<<< - * process_queue_set.erase(current_pixel) - * process_queue.pop() - */ - __pyx_v_current_pixel = __pyx_v_process_queue.front(); - - /* "pygeoprocessing/routing/watershed.pyx":844 - * - * current_pixel = process_queue.front() - * process_queue_set.erase(current_pixel) # <<<<<<<<<<<<<< - * process_queue.pop() - * - */ - (void)(__pyx_v_process_queue_set.erase(__pyx_v_current_pixel)); - - /* "pygeoprocessing/routing/watershed.pyx":845 - * current_pixel = process_queue.front() - * process_queue_set.erase(current_pixel) - * process_queue.pop() # <<<<<<<<<<<<<< - * - * scratch_managed_raster.set(current_pixel.first, - */ - __pyx_v_process_queue.pop(); - - /* "pygeoprocessing/routing/watershed.pyx":847 - * process_queue.pop() - * - * scratch_managed_raster.set(current_pixel.first, # <<<<<<<<<<<<<< - * current_pixel.second, ws_id) - * n_cells_visited += 1 - */ - __pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_set(__pyx_v_scratch_managed_raster, __pyx_v_current_pixel.first, __pyx_v_current_pixel.second, __pyx_v_ws_id); - - /* "pygeoprocessing/routing/watershed.pyx":849 - * scratch_managed_raster.set(current_pixel.first, - * current_pixel.second, ws_id) - * n_cells_visited += 1 # <<<<<<<<<<<<<< - * - * # These are for tracking the extents of the raster so we can build - */ - __pyx_v_n_cells_visited = (__pyx_v_n_cells_visited + 1); - - /* "pygeoprocessing/routing/watershed.pyx":853 - * # These are for tracking the extents of the raster so we can build - * # a VRT and only polygonize the pixels we need to. - * ix_min = min(ix_min, current_pixel.first) # <<<<<<<<<<<<<< - * iy_min = min(iy_min, current_pixel.second) - * ix_max = max(ix_max, current_pixel.first) - */ - __pyx_t_27 = __pyx_v_current_pixel.first; - __pyx_t_9 = __pyx_v_ix_min; - if (((__pyx_t_27 < __pyx_t_9) != 0)) { - __pyx_t_28 = __pyx_t_27; - } else { - __pyx_t_28 = __pyx_t_9; - } - __pyx_v_ix_min = __pyx_t_28; - - /* "pygeoprocessing/routing/watershed.pyx":854 - * # a VRT and only polygonize the pixels we need to. - * ix_min = min(ix_min, current_pixel.first) - * iy_min = min(iy_min, current_pixel.second) # <<<<<<<<<<<<<< - * ix_max = max(ix_max, current_pixel.first) - * iy_max = max(iy_max, current_pixel.second) - */ - __pyx_t_28 = __pyx_v_current_pixel.second; - __pyx_t_9 = __pyx_v_iy_min; - if (((__pyx_t_28 < __pyx_t_9) != 0)) { - __pyx_t_27 = __pyx_t_28; - } else { - __pyx_t_27 = __pyx_t_9; - } - __pyx_v_iy_min = __pyx_t_27; - - /* "pygeoprocessing/routing/watershed.pyx":855 - * ix_min = min(ix_min, current_pixel.first) - * iy_min = min(iy_min, current_pixel.second) - * ix_max = max(ix_max, current_pixel.first) # <<<<<<<<<<<<<< - * iy_max = max(iy_max, current_pixel.second) - * - */ - __pyx_t_27 = __pyx_v_current_pixel.first; - __pyx_t_9 = __pyx_v_ix_max; - if (((__pyx_t_27 > __pyx_t_9) != 0)) { - __pyx_t_28 = __pyx_t_27; - } else { - __pyx_t_28 = __pyx_t_9; - } - __pyx_v_ix_max = __pyx_t_28; - - /* "pygeoprocessing/routing/watershed.pyx":856 - * iy_min = min(iy_min, current_pixel.second) - * ix_max = max(ix_max, current_pixel.first) - * iy_max = max(iy_max, current_pixel.second) # <<<<<<<<<<<<<< - * - * for neighbor_index in range(8): - */ - __pyx_t_28 = __pyx_v_current_pixel.second; - __pyx_t_9 = __pyx_v_iy_max; - if (((__pyx_t_28 > __pyx_t_9) != 0)) { - __pyx_t_27 = __pyx_t_28; - } else { - __pyx_t_27 = __pyx_t_9; - } - __pyx_v_iy_max = __pyx_t_27; - - /* "pygeoprocessing/routing/watershed.pyx":858 - * iy_max = max(iy_max, current_pixel.second) - * - * for neighbor_index in range(8): # <<<<<<<<<<<<<< - * neighbor_pixel = CoordinatePair( - * current_pixel.first + neighbor_col[neighbor_index], - */ - for (__pyx_t_27 = 0; __pyx_t_27 < 8; __pyx_t_27+=1) { - __pyx_v_neighbor_index = __pyx_t_27; - - /* "pygeoprocessing/routing/watershed.pyx":859 - * - * for neighbor_index in range(8): - * neighbor_pixel = CoordinatePair( # <<<<<<<<<<<<<< - * current_pixel.first + neighbor_col[neighbor_index], - * current_pixel.second + neighbor_row[neighbor_index]) - */ - try { - __pyx_t_29 = __pyx_t_15pygeoprocessing_7routing_9watershed_CoordinatePair((__pyx_v_current_pixel.first + (__pyx_v_neighbor_col[__pyx_v_neighbor_index])), (__pyx_v_current_pixel.second + (__pyx_v_neighbor_row[__pyx_v_neighbor_index]))); - } catch(...) { - __Pyx_CppExn2PyErr(); - __PYX_ERR(0, 859, __pyx_L1_error) - } - __pyx_v_neighbor_pixel = __pyx_t_29; - - /* "pygeoprocessing/routing/watershed.pyx":863 - * current_pixel.second + neighbor_row[neighbor_index]) - * - * if not 0 <= neighbor_pixel.first < flow_dir_n_cols: # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_5 = (0 <= __pyx_v_neighbor_pixel.first); - if (__pyx_t_5) { - __pyx_t_5 = (__pyx_v_neighbor_pixel.first < __pyx_v_flow_dir_n_cols); - } - __pyx_t_4 = ((!(__pyx_t_5 != 0)) != 0); - if (__pyx_t_4) { - - /* "pygeoprocessing/routing/watershed.pyx":864 - * - * if not 0 <= neighbor_pixel.first < flow_dir_n_cols: - * continue # <<<<<<<<<<<<<< - * - * if not 0 <= neighbor_pixel.second < flow_dir_n_rows: - */ - goto __pyx_L30_continue; - - /* "pygeoprocessing/routing/watershed.pyx":863 - * current_pixel.second + neighbor_row[neighbor_index]) - * - * if not 0 <= neighbor_pixel.first < flow_dir_n_cols: # <<<<<<<<<<<<<< - * continue - * - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":866 - * continue - * - * if not 0 <= neighbor_pixel.second < flow_dir_n_rows: # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_4 = (0 <= __pyx_v_neighbor_pixel.second); - if (__pyx_t_4) { - __pyx_t_4 = (__pyx_v_neighbor_pixel.second < __pyx_v_flow_dir_n_rows); - } - __pyx_t_5 = ((!(__pyx_t_4 != 0)) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/watershed.pyx":867 - * - * if not 0 <= neighbor_pixel.second < flow_dir_n_rows: - * continue # <<<<<<<<<<<<<< - * - * # If we've already enqueued the neighbor (either it's - */ - goto __pyx_L30_continue; - - /* "pygeoprocessing/routing/watershed.pyx":866 - * continue - * - * if not 0 <= neighbor_pixel.second < flow_dir_n_rows: # <<<<<<<<<<<<<< - * continue - * - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":872 - * # upstream of another pixel or it's a watershed seed), we - * # don't need to re-enqueue it. - * if (process_queue_set.find(neighbor_pixel) != # <<<<<<<<<<<<<< - * process_queue_set.end()): - * continue - */ - __pyx_t_5 = ((__pyx_v_process_queue_set.find(__pyx_v_neighbor_pixel) != __pyx_v_process_queue_set.end()) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/watershed.pyx":874 - * if (process_queue_set.find(neighbor_pixel) != - * process_queue_set.end()): - * continue # <<<<<<<<<<<<<< - * - * # If the neighbor is known to be a seed, we don't need to - */ - goto __pyx_L30_continue; - - /* "pygeoprocessing/routing/watershed.pyx":872 - * # upstream of another pixel or it's a watershed seed), we - * # don't need to re-enqueue it. - * if (process_queue_set.find(neighbor_pixel) != # <<<<<<<<<<<<<< - * process_queue_set.end()): - * continue - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":879 - * # re-enqueue it either. Either it's been visited already (and - * # may have upstream pixels) or it's going to be. - * if (seeds_in_watershed.find(neighbor_pixel) != # <<<<<<<<<<<<<< - * seeds_in_watershed.end()): - * continue - */ - __pyx_t_5 = ((__pyx_v_seeds_in_watershed.find(__pyx_v_neighbor_pixel) != __pyx_v_seeds_in_watershed.end()) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/watershed.pyx":881 - * if (seeds_in_watershed.find(neighbor_pixel) != - * seeds_in_watershed.end()): - * continue # <<<<<<<<<<<<<< - * - * # Does the neighbor flow into this pixel? - */ - goto __pyx_L30_continue; - - /* "pygeoprocessing/routing/watershed.pyx":879 - * # re-enqueue it either. Either it's been visited already (and - * # may have upstream pixels) or it's going to be. - * if (seeds_in_watershed.find(neighbor_pixel) != # <<<<<<<<<<<<<< - * seeds_in_watershed.end()): - * continue - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":885 - * # Does the neighbor flow into this pixel? - * # If yes, enqueue it. - * if (reverse_flow[neighbor_index] == # <<<<<<<<<<<<<< - * flow_dir_managed_raster.get( - * neighbor_pixel.first, neighbor_pixel.second)): - */ - __pyx_t_5 = (((__pyx_v_reverse_flow[__pyx_v_neighbor_index]) == __pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_get(__pyx_v_flow_dir_managed_raster, __pyx_v_neighbor_pixel.first, __pyx_v_neighbor_pixel.second)) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/watershed.pyx":888 - * flow_dir_managed_raster.get( - * neighbor_pixel.first, neighbor_pixel.second)): - * process_queue.push(neighbor_pixel) # <<<<<<<<<<<<<< - * process_queue_set.insert(neighbor_pixel) - * - */ - __pyx_v_process_queue.push(__pyx_v_neighbor_pixel); - - /* "pygeoprocessing/routing/watershed.pyx":889 - * neighbor_pixel.first, neighbor_pixel.second)): - * process_queue.push(neighbor_pixel) - * process_queue_set.insert(neighbor_pixel) # <<<<<<<<<<<<<< - * - * watersheds_created += 1 - */ - try { - __pyx_v_process_queue_set.insert(__pyx_v_neighbor_pixel); - } catch(...) { - __Pyx_CppExn2PyErr(); - __PYX_ERR(0, 889, __pyx_L1_error) - } - - /* "pygeoprocessing/routing/watershed.pyx":885 - * # Does the neighbor flow into this pixel? - * # If yes, enqueue it. - * if (reverse_flow[neighbor_index] == # <<<<<<<<<<<<<< - * flow_dir_managed_raster.get( - * neighbor_pixel.first, neighbor_pixel.second)): - */ - } - __pyx_L30_continue:; - } - } - - /* "pygeoprocessing/routing/watershed.pyx":891 - * process_queue_set.insert(neighbor_pixel) - * - * watersheds_created += 1 # <<<<<<<<<<<<<< - * scratch_managed_raster.close() - * - */ - __pyx_v_watersheds_created = (__pyx_v_watersheds_created + 1); - - /* "pygeoprocessing/routing/watershed.pyx":892 - * - * watersheds_created += 1 - * scratch_managed_raster.close() # <<<<<<<<<<<<<< - * - * # Build a VRT from the bounds of the affected pixels before - */ - __pyx_t_13 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_scratch_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 892, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_10 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) { - __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_13); - if (likely(__pyx_t_10)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_13, function); - } - } - __pyx_t_12 = (__pyx_t_10) ? __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_10) : __Pyx_PyObject_CallNoArg(__pyx_t_13); - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 892, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":898 - * # raster, this yields a large speedup because we don't have to read in - * # the whole scratch raster in order to polygonize. - * x1 = (flow_dir_origin_x + (max(ix_min-1, 0)*flow_dir_pixelsize_x)) # minx # <<<<<<<<<<<<<< - * y1 = (flow_dir_origin_y + (max(iy_min-1, 0)*flow_dir_pixelsize_y)) # miny - * x2 = (flow_dir_origin_x + (min(ix_max+1, flow_dir_n_cols)*flow_dir_pixelsize_x)) # maxx - */ - __pyx_t_27 = 0; - __pyx_t_28 = (__pyx_v_ix_min - 1); - if (((__pyx_t_27 > __pyx_t_28) != 0)) { - __pyx_t_30 = __pyx_t_27; - } else { - __pyx_t_30 = __pyx_t_28; - } - __pyx_v_x1 = (__pyx_v_flow_dir_origin_x + (__pyx_t_30 * __pyx_v_flow_dir_pixelsize_x)); - - /* "pygeoprocessing/routing/watershed.pyx":899 - * # the whole scratch raster in order to polygonize. - * x1 = (flow_dir_origin_x + (max(ix_min-1, 0)*flow_dir_pixelsize_x)) # minx - * y1 = (flow_dir_origin_y + (max(iy_min-1, 0)*flow_dir_pixelsize_y)) # miny # <<<<<<<<<<<<<< - * x2 = (flow_dir_origin_x + (min(ix_max+1, flow_dir_n_cols)*flow_dir_pixelsize_x)) # maxx - * y2 = (flow_dir_origin_y + (min(iy_max+1, flow_dir_n_rows)*flow_dir_pixelsize_y)) # maxy - */ - __pyx_t_30 = 0; - __pyx_t_27 = (__pyx_v_iy_min - 1); - if (((__pyx_t_30 > __pyx_t_27) != 0)) { - __pyx_t_28 = __pyx_t_30; - } else { - __pyx_t_28 = __pyx_t_27; - } - __pyx_v_y1 = (__pyx_v_flow_dir_origin_y + (__pyx_t_28 * __pyx_v_flow_dir_pixelsize_y)); - - /* "pygeoprocessing/routing/watershed.pyx":900 - * x1 = (flow_dir_origin_x + (max(ix_min-1, 0)*flow_dir_pixelsize_x)) # minx - * y1 = (flow_dir_origin_y + (max(iy_min-1, 0)*flow_dir_pixelsize_y)) # miny - * x2 = (flow_dir_origin_x + (min(ix_max+1, flow_dir_n_cols)*flow_dir_pixelsize_x)) # maxx # <<<<<<<<<<<<<< - * y2 = (flow_dir_origin_y + (min(iy_max+1, flow_dir_n_rows)*flow_dir_pixelsize_y)) # maxy - * - */ - __pyx_t_9 = __pyx_v_flow_dir_n_cols; - __pyx_t_28 = (__pyx_v_ix_max + 1); - if (((__pyx_t_9 < __pyx_t_28) != 0)) { - __pyx_t_30 = __pyx_t_9; - } else { - __pyx_t_30 = __pyx_t_28; - } - __pyx_v_x2 = (__pyx_v_flow_dir_origin_x + (__pyx_t_30 * __pyx_v_flow_dir_pixelsize_x)); - - /* "pygeoprocessing/routing/watershed.pyx":901 - * y1 = (flow_dir_origin_y + (max(iy_min-1, 0)*flow_dir_pixelsize_y)) # miny - * x2 = (flow_dir_origin_x + (min(ix_max+1, flow_dir_n_cols)*flow_dir_pixelsize_x)) # maxx - * y2 = (flow_dir_origin_y + (min(iy_max+1, flow_dir_n_rows)*flow_dir_pixelsize_y)) # maxy # <<<<<<<<<<<<<< - * - * vrt_options = gdal.BuildVRTOptions( - */ - __pyx_t_9 = __pyx_v_flow_dir_n_rows; - __pyx_t_30 = (__pyx_v_iy_max + 1); - if (((__pyx_t_9 < __pyx_t_30) != 0)) { - __pyx_t_28 = __pyx_t_9; - } else { - __pyx_t_28 = __pyx_t_30; - } - __pyx_v_y2 = (__pyx_v_flow_dir_origin_y + (__pyx_t_28 * __pyx_v_flow_dir_pixelsize_y)); - - /* "pygeoprocessing/routing/watershed.pyx":903 - * y2 = (flow_dir_origin_y + (min(iy_max+1, flow_dir_n_rows)*flow_dir_pixelsize_y)) # maxy - * - * vrt_options = gdal.BuildVRTOptions( # <<<<<<<<<<<<<< - * outputBounds=( - * min(x1, x2), - */ - __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_gdal); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 903, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_BuildVRTOptions); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 903, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":904 - * - * vrt_options = gdal.BuildVRTOptions( - * outputBounds=( # <<<<<<<<<<<<<< - * min(x1, x2), - * min(y1, y2), - */ - __pyx_t_12 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 904, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - - /* "pygeoprocessing/routing/watershed.pyx":905 - * vrt_options = gdal.BuildVRTOptions( - * outputBounds=( - * min(x1, x2), # <<<<<<<<<<<<<< - * min(y1, y2), - * max(x1, x2), - */ - __pyx_t_15 = __pyx_v_x2; - __pyx_t_31 = __pyx_v_x1; - if (((__pyx_t_15 < __pyx_t_31) != 0)) { - __pyx_t_32 = __pyx_t_15; - } else { - __pyx_t_32 = __pyx_t_31; - } - __pyx_t_10 = PyFloat_FromDouble(__pyx_t_32); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 905, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - - /* "pygeoprocessing/routing/watershed.pyx":906 - * outputBounds=( - * min(x1, x2), - * min(y1, y2), # <<<<<<<<<<<<<< - * max(x1, x2), - * max(y1, y2)) - */ - __pyx_t_32 = __pyx_v_y2; - __pyx_t_15 = __pyx_v_y1; - if (((__pyx_t_32 < __pyx_t_15) != 0)) { - __pyx_t_31 = __pyx_t_32; - } else { - __pyx_t_31 = __pyx_t_15; - } - __pyx_t_18 = PyFloat_FromDouble(__pyx_t_31); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 906, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_18); - - /* "pygeoprocessing/routing/watershed.pyx":907 - * min(x1, x2), - * min(y1, y2), - * max(x1, x2), # <<<<<<<<<<<<<< - * max(y1, y2)) - * ) - */ - __pyx_t_31 = __pyx_v_x2; - __pyx_t_32 = __pyx_v_x1; - if (((__pyx_t_31 > __pyx_t_32) != 0)) { - __pyx_t_15 = __pyx_t_31; - } else { - __pyx_t_15 = __pyx_t_32; - } - __pyx_t_7 = PyFloat_FromDouble(__pyx_t_15); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 907, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - - /* "pygeoprocessing/routing/watershed.pyx":908 - * min(y1, y2), - * max(x1, x2), - * max(y1, y2)) # <<<<<<<<<<<<<< - * ) - * vrt_path = os.path.join(working_dir_path, '%s_vrt.vrt' % ws_id) - */ - __pyx_t_15 = __pyx_v_y2; - __pyx_t_31 = __pyx_v_y1; - if (((__pyx_t_15 > __pyx_t_31) != 0)) { - __pyx_t_32 = __pyx_t_15; - } else { - __pyx_t_32 = __pyx_t_31; - } - __pyx_t_11 = PyFloat_FromDouble(__pyx_t_32); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 908, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - - /* "pygeoprocessing/routing/watershed.pyx":905 - * vrt_options = gdal.BuildVRTOptions( - * outputBounds=( - * min(x1, x2), # <<<<<<<<<<<<<< - * min(y1, y2), - * max(x1, x2), - */ - __pyx_t_19 = PyTuple_New(4); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 905, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_18); - PyTuple_SET_ITEM(__pyx_t_19, 1, __pyx_t_18); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_19, 2, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_19, 3, __pyx_t_11); - __pyx_t_10 = 0; - __pyx_t_18 = 0; - __pyx_t_7 = 0; - __pyx_t_11 = 0; - if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_outputBounds, __pyx_t_19) < 0) __PYX_ERR(0, 904, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":903 - * y2 = (flow_dir_origin_y + (min(iy_max+1, flow_dir_n_rows)*flow_dir_pixelsize_y)) # maxy - * - * vrt_options = gdal.BuildVRTOptions( # <<<<<<<<<<<<<< - * outputBounds=( - * min(x1, x2), - */ - __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_empty_tuple, __pyx_t_12); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 903, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_XDECREF_SET(__pyx_v_vrt_options, __pyx_t_19); - __pyx_t_19 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":910 - * max(y1, y2)) - * ) - * vrt_path = os.path.join(working_dir_path, '%s_vrt.vrt' % ws_id) # <<<<<<<<<<<<<< - * gdal.BuildVRT(vrt_path, [scratch_raster_path], options=vrt_options) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_os); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 910, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_path); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 910, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_join); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 910, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_13 = __Pyx_PyInt_From_int(__pyx_v_ws_id); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 910, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_11 = PyUnicode_Format(__pyx_kp_u_s_vrt_vrt, __pyx_t_13); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 910, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_13 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_13)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_13); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_12)) { - PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_v_working_dir_path, __pyx_t_11}; - __pyx_t_19 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 910, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) { - PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_v_working_dir_path, __pyx_t_11}; - __pyx_t_19 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 910, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 910, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_13) { - __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_13); __pyx_t_13 = NULL; - } - __Pyx_INCREF(__pyx_v_working_dir_path); - __Pyx_GIVEREF(__pyx_v_working_dir_path); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_9, __pyx_v_working_dir_path); - __Pyx_GIVEREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_9, __pyx_t_11); - __pyx_t_11 = 0; - __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_7, NULL); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 910, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_XDECREF_SET(__pyx_v_vrt_path, __pyx_t_19); - __pyx_t_19 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":911 - * ) - * vrt_path = os.path.join(working_dir_path, '%s_vrt.vrt' % ws_id) - * gdal.BuildVRT(vrt_path, [scratch_raster_path], options=vrt_options) # <<<<<<<<<<<<<< - * - * # Polygonize this new watershed from the VRT. - */ - __Pyx_GetModuleGlobalName(__pyx_t_19, __pyx_n_s_gdal); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 911, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_n_s_BuildVRT); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 911, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __pyx_t_19 = PyList_New(1); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 911, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_INCREF(__pyx_v_scratch_raster_path); - __Pyx_GIVEREF(__pyx_v_scratch_raster_path); - PyList_SET_ITEM(__pyx_t_19, 0, __pyx_v_scratch_raster_path); - __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 911, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_INCREF(__pyx_v_vrt_path); - __Pyx_GIVEREF(__pyx_v_vrt_path); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_vrt_path); - __Pyx_GIVEREF(__pyx_t_19); - PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_19); - __pyx_t_19 = 0; - __pyx_t_19 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 911, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - if (PyDict_SetItem(__pyx_t_19, __pyx_n_s_options, __pyx_v_vrt_options) < 0) __PYX_ERR(0, 911, __pyx_L1_error) - __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_7, __pyx_t_19); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 911, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":914 - * - * # Polygonize this new watershed from the VRT. - * vrt_raster = gdal.OpenEx(vrt_path, gdal.OF_RASTER, allowed_drivers=['VRT']) # <<<<<<<<<<<<<< - * vrt_band = vrt_raster.GetRasterBand(1) - * _ = gdal.Polygonize( - */ - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_gdal); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 914, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 914, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_gdal); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 914, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 914, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 914, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_INCREF(__pyx_v_vrt_path); - __Pyx_GIVEREF(__pyx_v_vrt_path); - PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_vrt_path); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 914, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_12 = PyList_New(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 914, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_INCREF(__pyx_n_u_VRT); - __Pyx_GIVEREF(__pyx_n_u_VRT); - PyList_SET_ITEM(__pyx_t_12, 0, __pyx_n_u_VRT); - if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_allowed_drivers, __pyx_t_12) < 0) __PYX_ERR(0, 914, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_19, __pyx_t_11, __pyx_t_7); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 914, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF_SET(__pyx_v_vrt_raster, __pyx_t_12); - __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":915 - * # Polygonize this new watershed from the VRT. - * vrt_raster = gdal.OpenEx(vrt_path, gdal.OF_RASTER, allowed_drivers=['VRT']) - * vrt_band = vrt_raster.GetRasterBand(1) # <<<<<<<<<<<<<< - * _ = gdal.Polygonize( - * vrt_band, # The source band - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_vrt_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 915, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_12 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_11, __pyx_int_1) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_int_1); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 915, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF_SET(__pyx_v_vrt_band, __pyx_t_12); - __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":916 - * vrt_raster = gdal.OpenEx(vrt_path, gdal.OF_RASTER, allowed_drivers=['VRT']) - * vrt_band = vrt_raster.GetRasterBand(1) - * _ = gdal.Polygonize( # <<<<<<<<<<<<<< - * vrt_band, # The source band - * vrt_band, # The mask. Pixels with 0 are invalid, nonzero are valid - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 916, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_Polygonize); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 916, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":921 - * polygonized_watersheds_layer, - * 0, # ws_id field index - * []) # 8connectedness does not always produce valid geometries. # <<<<<<<<<<<<<< - * _ = None - * vrt_band = None - */ - __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 921, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_19 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_19)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_19); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_11)) { - PyObject *__pyx_temp[6] = {__pyx_t_19, __pyx_v_vrt_band, __pyx_v_vrt_band, __pyx_v_polygonized_watersheds_layer, __pyx_int_0, __pyx_t_7}; - __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 5+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 916, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { - PyObject *__pyx_temp[6] = {__pyx_t_19, __pyx_v_vrt_band, __pyx_v_vrt_band, __pyx_v_polygonized_watersheds_layer, __pyx_int_0, __pyx_t_7}; - __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 5+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 916, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - { - __pyx_t_13 = PyTuple_New(5+__pyx_t_9); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 916, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - if (__pyx_t_19) { - __Pyx_GIVEREF(__pyx_t_19); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_19); __pyx_t_19 = NULL; - } - __Pyx_INCREF(__pyx_v_vrt_band); - __Pyx_GIVEREF(__pyx_v_vrt_band); - PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_9, __pyx_v_vrt_band); - __Pyx_INCREF(__pyx_v_vrt_band); - __Pyx_GIVEREF(__pyx_v_vrt_band); - PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_9, __pyx_v_vrt_band); - __Pyx_INCREF(__pyx_v_polygonized_watersheds_layer); - __Pyx_GIVEREF(__pyx_v_polygonized_watersheds_layer); - PyTuple_SET_ITEM(__pyx_t_13, 2+__pyx_t_9, __pyx_v_polygonized_watersheds_layer); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_13, 3+__pyx_t_9, __pyx_int_0); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_13, 4+__pyx_t_9, __pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_13, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 916, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - } - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_12); - __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":922 - * 0, # ws_id field index - * []) # 8connectedness does not always produce valid geometries. - * _ = None # <<<<<<<<<<<<<< - * vrt_band = None - * vrt_raster = None - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v__, Py_None); - - /* "pygeoprocessing/routing/watershed.pyx":923 - * []) # 8connectedness does not always produce valid geometries. - * _ = None - * vrt_band = None # <<<<<<<<<<<<<< - * vrt_raster = None - * - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_vrt_band, Py_None); - - /* "pygeoprocessing/routing/watershed.pyx":924 - * _ = None - * vrt_band = None - * vrt_raster = None # <<<<<<<<<<<<<< - * - * # Removing files as we go to help manage disk space. - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_vrt_raster, Py_None); - - /* "pygeoprocessing/routing/watershed.pyx":927 - * - * # Removing files as we go to help manage disk space. - * if remove_temp_files: # <<<<<<<<<<<<<< - * os.remove(scratch_raster_path) - * if os.path.exists(seeds_raster_path): - */ - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_remove_temp_files); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 927, __pyx_L1_error) - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/watershed.pyx":928 - * # Removing files as we go to help manage disk space. - * if remove_temp_files: - * os.remove(scratch_raster_path) # <<<<<<<<<<<<<< - * if os.path.exists(seeds_raster_path): - * os.remove(seeds_raster_path) - */ - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_os); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 928, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_remove); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 928, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_13))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_13); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_13, function); - } - } - __pyx_t_12 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_13, __pyx_t_11, __pyx_v_scratch_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_v_scratch_raster_path); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 928, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":929 - * if remove_temp_files: - * os.remove(scratch_raster_path) - * if os.path.exists(seeds_raster_path): # <<<<<<<<<<<<<< - * os.remove(seeds_raster_path) - * os.remove(vrt_path) - */ - __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_os); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 929, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_path); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 929, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_exists); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 929, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_13); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_13, function); - } - } - __pyx_t_12 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_13, __pyx_t_11, __pyx_v_seeds_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_v_seeds_raster_path); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 929, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_12); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 929, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/watershed.pyx":930 - * os.remove(scratch_raster_path) - * if os.path.exists(seeds_raster_path): - * os.remove(seeds_raster_path) # <<<<<<<<<<<<<< - * os.remove(vrt_path) - * if (diagnostic_vector_path - */ - __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_os); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 930, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_remove); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 930, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_13 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_13)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_13); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - } - } - __pyx_t_12 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_13, __pyx_v_seeds_raster_path) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_v_seeds_raster_path); - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 930, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":929 - * if remove_temp_files: - * os.remove(scratch_raster_path) - * if os.path.exists(seeds_raster_path): # <<<<<<<<<<<<<< - * os.remove(seeds_raster_path) - * os.remove(vrt_path) - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":931 - * if os.path.exists(seeds_raster_path): - * os.remove(seeds_raster_path) - * os.remove(vrt_path) # <<<<<<<<<<<<<< - * if (diagnostic_vector_path - * and os.path.exists(diagnostic_vector_path)): - */ - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_os); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 931, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_remove); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 931, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_13))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_13); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_13, function); - } - } - __pyx_t_12 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_13, __pyx_t_11, __pyx_v_vrt_path) : __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_v_vrt_path); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 931, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":932 - * os.remove(seeds_raster_path) - * os.remove(vrt_path) - * if (diagnostic_vector_path # <<<<<<<<<<<<<< - * and os.path.exists(diagnostic_vector_path)): - * os.remove(diagnostic_vector_path) - */ - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_diagnostic_vector_path); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 932, __pyx_L1_error) - if (__pyx_t_4) { - } else { - __pyx_t_5 = __pyx_t_4; - goto __pyx_L40_bool_binop_done; - } - - /* "pygeoprocessing/routing/watershed.pyx":933 - * os.remove(vrt_path) - * if (diagnostic_vector_path - * and os.path.exists(diagnostic_vector_path)): # <<<<<<<<<<<<<< - * os.remove(diagnostic_vector_path) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_os); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 933, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_path); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 933, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_exists); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 933, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_13); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_13, function); - } - } - __pyx_t_12 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_13, __pyx_t_11, __pyx_v_diagnostic_vector_path) : __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_v_diagnostic_vector_path); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 933, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_12); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 933, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_5 = __pyx_t_4; - __pyx_L40_bool_binop_done:; - - /* "pygeoprocessing/routing/watershed.pyx":932 - * os.remove(seeds_raster_path) - * os.remove(vrt_path) - * if (diagnostic_vector_path # <<<<<<<<<<<<<< - * and os.path.exists(diagnostic_vector_path)): - * os.remove(diagnostic_vector_path) - */ - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/watershed.pyx":934 - * if (diagnostic_vector_path - * and os.path.exists(diagnostic_vector_path)): - * os.remove(diagnostic_vector_path) # <<<<<<<<<<<<<< - * - * LOGGER.info('Finished delineating %s watersheds', watersheds_created) - */ - __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_os); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 934, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_remove); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 934, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_13 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_13)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_13); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - } - } - __pyx_t_12 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_13, __pyx_v_diagnostic_vector_path) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_v_diagnostic_vector_path); - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 934, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":932 - * os.remove(seeds_raster_path) - * os.remove(vrt_path) - * if (diagnostic_vector_path # <<<<<<<<<<<<<< - * and os.path.exists(diagnostic_vector_path)): - * os.remove(diagnostic_vector_path) - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":927 - * - * # Removing files as we go to help manage disk space. - * if remove_temp_files: # <<<<<<<<<<<<<< - * os.remove(scratch_raster_path) - * if os.path.exists(seeds_raster_path): - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":748 - * flow_dir_srs = osr.SpatialReference() - * flow_dir_srs.ImportFromWkt(flow_dir_info['projection_wkt']) - * for feature in outflow_layer: # <<<<<<<<<<<<<< - * # Some vectors start indexing their FIDs at 0. - * # The mask raster input to polygonization, however, only regards pixels - */ - __pyx_L16_continue:; - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":936 - * os.remove(diagnostic_vector_path) - * - * LOGGER.info('Finished delineating %s watersheds', watersheds_created) # <<<<<<<<<<<<<< - * - * # The Polygonization algorithm will sometimes identify regions that - */ - __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 936, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_info); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 936, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = __Pyx_PyInt_From_int(__pyx_v_watersheds_created); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 936, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_13 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_13)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_13); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_11)) { - PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_kp_u_Finished_delineating_s_watershed, __pyx_t_12}; - __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 936, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 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_11)) { - PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_kp_u_Finished_delineating_s_watershed, __pyx_t_12}; - __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 936, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 936, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_13) { - __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_13); __pyx_t_13 = NULL; - } - __Pyx_INCREF(__pyx_kp_u_Finished_delineating_s_watershed); - __Pyx_GIVEREF(__pyx_kp_u_Finished_delineating_s_watershed); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_9, __pyx_kp_u_Finished_delineating_s_watershed); - __Pyx_GIVEREF(__pyx_t_12); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_9, __pyx_t_12); - __pyx_t_12 = 0; - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 936, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":944 - * cdef cmap[int, cset[int]] fragments_with_duplicates - * cdef int fid - * for feature in polygonized_watersheds_layer: # <<<<<<<<<<<<<< - * fid = feature.GetFID() - * # ws_id is tracked as 1 more than the FID. See previous note about why. - */ - if (likely(PyList_CheckExact(__pyx_v_polygonized_watersheds_layer)) || PyTuple_CheckExact(__pyx_v_polygonized_watersheds_layer)) { - __pyx_t_8 = __pyx_v_polygonized_watersheds_layer; __Pyx_INCREF(__pyx_t_8); __pyx_t_23 = 0; - __pyx_t_24 = NULL; - } else { - __pyx_t_23 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_polygonized_watersheds_layer); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 944, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_24 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 944, __pyx_L1_error) - } - for (;;) { - if (likely(!__pyx_t_24)) { - if (likely(PyList_CheckExact(__pyx_t_8))) { - if (__pyx_t_23 >= PyList_GET_SIZE(__pyx_t_8)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_11 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_23); __Pyx_INCREF(__pyx_t_11); __pyx_t_23++; if (unlikely(0 < 0)) __PYX_ERR(0, 944, __pyx_L1_error) - #else - __pyx_t_11 = PySequence_ITEM(__pyx_t_8, __pyx_t_23); __pyx_t_23++; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 944, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - #endif - } else { - if (__pyx_t_23 >= PyTuple_GET_SIZE(__pyx_t_8)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_11 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_23); __Pyx_INCREF(__pyx_t_11); __pyx_t_23++; if (unlikely(0 < 0)) __PYX_ERR(0, 944, __pyx_L1_error) - #else - __pyx_t_11 = PySequence_ITEM(__pyx_t_8, __pyx_t_23); __pyx_t_23++; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 944, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - #endif - } - } else { - __pyx_t_11 = __pyx_t_24(__pyx_t_8); - if (unlikely(!__pyx_t_11)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 944, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_11); - } - __Pyx_XDECREF_SET(__pyx_v_feature, __pyx_t_11); - __pyx_t_11 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":945 - * cdef int fid - * for feature in polygonized_watersheds_layer: - * fid = feature.GetFID() # <<<<<<<<<<<<<< - * # ws_id is tracked as 1 more than the FID. See previous note about why. - * ws_id = feature.GetField('ws_id') - 1 - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_feature, __pyx_n_s_GetFID); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 945, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_12 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_11 = (__pyx_t_12) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_12) : __Pyx_PyObject_CallNoArg(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 945, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_11); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 945, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_v_fid = __pyx_t_9; - - /* "pygeoprocessing/routing/watershed.pyx":947 - * fid = feature.GetFID() - * # ws_id is tracked as 1 more than the FID. See previous note about why. - * ws_id = feature.GetField('ws_id') - 1 # <<<<<<<<<<<<<< - * if (fragments_with_duplicates.find(ws_id) - * == fragments_with_duplicates.end()): - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_feature, __pyx_n_s_GetField); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 947, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_12 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_11 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_12, __pyx_n_u_ws_id) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_n_u_ws_id); - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 947, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyInt_SubtractObjC(__pyx_t_11, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 947, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 947, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_ws_id = __pyx_t_9; - - /* "pygeoprocessing/routing/watershed.pyx":949 - * ws_id = feature.GetField('ws_id') - 1 - * if (fragments_with_duplicates.find(ws_id) - * == fragments_with_duplicates.end()): # <<<<<<<<<<<<<< - * fragments_with_duplicates[ws_id] = cset[int]() - * fragments_with_duplicates[ws_id].insert(fid) - */ - __pyx_t_5 = ((__pyx_v_fragments_with_duplicates.find(__pyx_v_ws_id) == __pyx_v_fragments_with_duplicates.end()) != 0); - - /* "pygeoprocessing/routing/watershed.pyx":948 - * # ws_id is tracked as 1 more than the FID. See previous note about why. - * ws_id = feature.GetField('ws_id') - 1 - * if (fragments_with_duplicates.find(ws_id) # <<<<<<<<<<<<<< - * == fragments_with_duplicates.end()): - * fragments_with_duplicates[ws_id] = cset[int]() - */ - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/watershed.pyx":950 - * if (fragments_with_duplicates.find(ws_id) - * == fragments_with_duplicates.end()): - * fragments_with_duplicates[ws_id] = cset[int]() # <<<<<<<<<<<<<< - * fragments_with_duplicates[ws_id].insert(fid) - * polygonized_watersheds_layer.ResetReading() - */ - try { - __pyx_t_33 = std::set (); - } catch(...) { - __Pyx_CppExn2PyErr(); - __PYX_ERR(0, 950, __pyx_L1_error) - } - (__pyx_v_fragments_with_duplicates[__pyx_v_ws_id]) = __pyx_t_33; - - /* "pygeoprocessing/routing/watershed.pyx":948 - * # ws_id is tracked as 1 more than the FID. See previous note about why. - * ws_id = feature.GetField('ws_id') - 1 - * if (fragments_with_duplicates.find(ws_id) # <<<<<<<<<<<<<< - * == fragments_with_duplicates.end()): - * fragments_with_duplicates[ws_id] = cset[int]() - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":951 - * == fragments_with_duplicates.end()): - * fragments_with_duplicates[ws_id] = cset[int]() - * fragments_with_duplicates[ws_id].insert(fid) # <<<<<<<<<<<<<< - * polygonized_watersheds_layer.ResetReading() - * - */ - try { - (__pyx_v_fragments_with_duplicates[__pyx_v_ws_id]).insert(__pyx_v_fid); - } catch(...) { - __Pyx_CppExn2PyErr(); - __PYX_ERR(0, 951, __pyx_L1_error) - } - - /* "pygeoprocessing/routing/watershed.pyx":944 - * cdef cmap[int, cset[int]] fragments_with_duplicates - * cdef int fid - * for feature in polygonized_watersheds_layer: # <<<<<<<<<<<<<< - * fid = feature.GetFID() - * # ws_id is tracked as 1 more than the FID. See previous note about why. - */ - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":952 - * fragments_with_duplicates[ws_id] = cset[int]() - * fragments_with_duplicates[ws_id].insert(fid) - * polygonized_watersheds_layer.ResetReading() # <<<<<<<<<<<<<< - * - * LOGGER.info( - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_polygonized_watersheds_layer, __pyx_n_s_ResetReading); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 952, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_8 = (__pyx_t_11) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_11) : __Pyx_PyObject_CallNoArg(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 952, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":954 - * polygonized_watersheds_layer.ResetReading() - * - * LOGGER.info( # <<<<<<<<<<<<<< - * 'Consolidating %s fragments and copying field values to ' - * 'watersheds layer.', polygonized_watersheds_layer.GetFeatureCount()) - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 954, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_info); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 954, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":956 - * LOGGER.info( - * 'Consolidating %s fragments and copying field values to ' - * 'watersheds layer.', polygonized_watersheds_layer.GetFeatureCount()) # <<<<<<<<<<<<<< - * source_vector = gdal.OpenEx(outflow_vector_path, gdal.OF_VECTOR) - * source_layer = source_vector.GetLayer() - */ - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_polygonized_watersheds_layer, __pyx_n_s_GetFeatureCount); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 956, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_13 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_13)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_13); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - } - } - __pyx_t_7 = (__pyx_t_13) ? __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_13) : __Pyx_PyObject_CallNoArg(__pyx_t_12); - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 956, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_12)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_12); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_11)) { - PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_kp_u_Consolidating_s_fragments_and_co, __pyx_t_7}; - __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 954, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { - PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_kp_u_Consolidating_s_fragments_and_co, __pyx_t_7}; - __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 954, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - { - __pyx_t_13 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 954, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - if (__pyx_t_12) { - __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_12); __pyx_t_12 = NULL; - } - __Pyx_INCREF(__pyx_kp_u_Consolidating_s_fragments_and_co); - __Pyx_GIVEREF(__pyx_kp_u_Consolidating_s_fragments_and_co); - PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_9, __pyx_kp_u_Consolidating_s_fragments_and_co); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_9, __pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_13, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 954, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - } - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":957 - * 'Consolidating %s fragments and copying field values to ' - * 'watersheds layer.', polygonized_watersheds_layer.GetFeatureCount()) - * source_vector = gdal.OpenEx(outflow_vector_path, gdal.OF_VECTOR) # <<<<<<<<<<<<<< - * source_layer = source_vector.GetLayer() - * watersheds_layer.CreateFields(source_layer.schema) - */ - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_gdal); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 957, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 957, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_gdal); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 957, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_OF_VECTOR); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 957, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_13))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_13); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_13, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_13)) { - PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_outflow_vector_path, __pyx_t_7}; - __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 957, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_13)) { - PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_outflow_vector_path, __pyx_t_7}; - __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 957, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - { - __pyx_t_12 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 957, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - if (__pyx_t_11) { - __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11); __pyx_t_11 = NULL; - } - __Pyx_INCREF(__pyx_v_outflow_vector_path); - __Pyx_GIVEREF(__pyx_v_outflow_vector_path); - PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_9, __pyx_v_outflow_vector_path); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_9, __pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_12, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 957, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - } - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_v_source_vector = __pyx_t_8; - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":958 - * 'watersheds layer.', polygonized_watersheds_layer.GetFeatureCount()) - * source_vector = gdal.OpenEx(outflow_vector_path, gdal.OF_VECTOR) - * source_layer = source_vector.GetLayer() # <<<<<<<<<<<<<< - * watersheds_layer.CreateFields(source_layer.schema) - * - */ - __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_source_vector, __pyx_n_s_GetLayer); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 958, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_12 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) { - __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_13); - if (likely(__pyx_t_12)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); - __Pyx_INCREF(__pyx_t_12); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_13, function); - } - } - __pyx_t_8 = (__pyx_t_12) ? __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_12) : __Pyx_PyObject_CallNoArg(__pyx_t_13); - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 958, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_v_source_layer = __pyx_t_8; - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":959 - * source_vector = gdal.OpenEx(outflow_vector_path, gdal.OF_VECTOR) - * source_layer = source_vector.GetLayer() - * watersheds_layer.CreateFields(source_layer.schema) # <<<<<<<<<<<<<< - * - * watersheds_layer.StartTransaction() - */ - __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_watersheds_layer, __pyx_n_s_CreateFields); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 959, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_source_layer, __pyx_n_s_schema); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 959, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_13); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_13, function); - } - } - __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_13, __pyx_t_7, __pyx_t_12) : __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_12); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 959, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":961 - * watersheds_layer.CreateFields(source_layer.schema) - * - * watersheds_layer.StartTransaction() # <<<<<<<<<<<<<< - * cdef int duplicate_fid - * cdef cset[int] duplicate_ids_set - */ - __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_watersheds_layer, __pyx_n_s_StartTransaction); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 961, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_12 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) { - __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_13); - if (likely(__pyx_t_12)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); - __Pyx_INCREF(__pyx_t_12); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_13, function); - } - } - __pyx_t_8 = (__pyx_t_12) ? __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_12) : __Pyx_PyObject_CallNoArg(__pyx_t_13); - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 961, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":966 - * cdef cset[int].iterator duplicate_ids_set_iterator - * cdef cmap[int, cset[int]].iterator fragments_with_duplicates_iterator - * fragments_with_duplicates_iterator = fragments_with_duplicates.begin() # <<<<<<<<<<<<<< - * while fragments_with_duplicates_iterator != fragments_with_duplicates.end(): - * ws_id = deref(fragments_with_duplicates_iterator).first - */ - __pyx_v_fragments_with_duplicates_iterator = __pyx_v_fragments_with_duplicates.begin(); - - /* "pygeoprocessing/routing/watershed.pyx":967 - * cdef cmap[int, cset[int]].iterator fragments_with_duplicates_iterator - * fragments_with_duplicates_iterator = fragments_with_duplicates.begin() - * while fragments_with_duplicates_iterator != fragments_with_duplicates.end(): # <<<<<<<<<<<<<< - * ws_id = deref(fragments_with_duplicates_iterator).first - * duplicate_ids_set = deref(fragments_with_duplicates_iterator).second - */ - while (1) { - __pyx_t_5 = ((__pyx_v_fragments_with_duplicates_iterator != __pyx_v_fragments_with_duplicates.end()) != 0); - if (!__pyx_t_5) break; - - /* "pygeoprocessing/routing/watershed.pyx":968 - * fragments_with_duplicates_iterator = fragments_with_duplicates.begin() - * while fragments_with_duplicates_iterator != fragments_with_duplicates.end(): - * ws_id = deref(fragments_with_duplicates_iterator).first # <<<<<<<<<<<<<< - * duplicate_ids_set = deref(fragments_with_duplicates_iterator).second - * inc(fragments_with_duplicates_iterator) - */ - __pyx_t_9 = (*__pyx_v_fragments_with_duplicates_iterator).first; - __pyx_v_ws_id = __pyx_t_9; - - /* "pygeoprocessing/routing/watershed.pyx":969 - * while fragments_with_duplicates_iterator != fragments_with_duplicates.end(): - * ws_id = deref(fragments_with_duplicates_iterator).first - * duplicate_ids_set = deref(fragments_with_duplicates_iterator).second # <<<<<<<<<<<<<< - * inc(fragments_with_duplicates_iterator) - * - */ - __pyx_t_33 = (*__pyx_v_fragments_with_duplicates_iterator).second; - __pyx_v_duplicate_ids_set = __pyx_t_33; - - /* "pygeoprocessing/routing/watershed.pyx":970 - * ws_id = deref(fragments_with_duplicates_iterator).first - * duplicate_ids_set = deref(fragments_with_duplicates_iterator).second - * inc(fragments_with_duplicates_iterator) # <<<<<<<<<<<<<< - * - * duplicate_ids_set_iterator = duplicate_ids_set.begin() - */ - (void)((++__pyx_v_fragments_with_duplicates_iterator)); - - /* "pygeoprocessing/routing/watershed.pyx":972 - * inc(fragments_with_duplicates_iterator) - * - * duplicate_ids_set_iterator = duplicate_ids_set.begin() # <<<<<<<<<<<<<< - * - * if duplicate_ids_set.size() == 1: - */ - __pyx_v_duplicate_ids_set_iterator = __pyx_v_duplicate_ids_set.begin(); - - /* "pygeoprocessing/routing/watershed.pyx":974 - * duplicate_ids_set_iterator = duplicate_ids_set.begin() - * - * if duplicate_ids_set.size() == 1: # <<<<<<<<<<<<<< - * duplicate_fid = deref(duplicate_ids_set_iterator) - * source_feature = polygonized_watersheds_layer.GetFeature(duplicate_fid) - */ - __pyx_t_5 = ((__pyx_v_duplicate_ids_set.size() == 1) != 0); - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/watershed.pyx":975 - * - * if duplicate_ids_set.size() == 1: - * duplicate_fid = deref(duplicate_ids_set_iterator) # <<<<<<<<<<<<<< - * source_feature = polygonized_watersheds_layer.GetFeature(duplicate_fid) - * new_geometry = source_feature.GetGeometryRef() - */ - __pyx_v_duplicate_fid = (*__pyx_v_duplicate_ids_set_iterator); - - /* "pygeoprocessing/routing/watershed.pyx":976 - * if duplicate_ids_set.size() == 1: - * duplicate_fid = deref(duplicate_ids_set_iterator) - * source_feature = polygonized_watersheds_layer.GetFeature(duplicate_fid) # <<<<<<<<<<<<<< - * new_geometry = source_feature.GetGeometryRef() - * else: - */ - __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_polygonized_watersheds_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 976, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_12 = __Pyx_PyInt_From_int(__pyx_v_duplicate_fid); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 976, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_13); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_13, function); - } - } - __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_13, __pyx_t_7, __pyx_t_12) : __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_12); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 976, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_XDECREF_SET(__pyx_v_source_feature, __pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":977 - * duplicate_fid = deref(duplicate_ids_set_iterator) - * source_feature = polygonized_watersheds_layer.GetFeature(duplicate_fid) - * new_geometry = source_feature.GetGeometryRef() # <<<<<<<<<<<<<< - * else: - * new_geometry = ogr.Geometry(ogr.wkbMultiPolygon) - */ - __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_source_feature, __pyx_n_s_GetGeometryRef); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 977, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_12 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) { - __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_13); - if (likely(__pyx_t_12)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); - __Pyx_INCREF(__pyx_t_12); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_13, function); - } - } - __pyx_t_8 = (__pyx_t_12) ? __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_12) : __Pyx_PyObject_CallNoArg(__pyx_t_13); - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 977, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_XDECREF_SET(__pyx_v_new_geometry, __pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":974 - * duplicate_ids_set_iterator = duplicate_ids_set.begin() - * - * if duplicate_ids_set.size() == 1: # <<<<<<<<<<<<<< - * duplicate_fid = deref(duplicate_ids_set_iterator) - * source_feature = polygonized_watersheds_layer.GetFeature(duplicate_fid) - */ - goto __pyx_L47; - } - - /* "pygeoprocessing/routing/watershed.pyx":979 - * new_geometry = source_feature.GetGeometryRef() - * else: - * new_geometry = ogr.Geometry(ogr.wkbMultiPolygon) # <<<<<<<<<<<<<< - * while duplicate_ids_set_iterator != duplicate_ids_set.end(): - * duplicate_fid = deref(duplicate_ids_set_iterator) - */ - /*else*/ { - __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_ogr); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 979, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_Geometry); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 979, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_ogr); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 979, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_wkbMultiPolygon); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 979, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_13 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_13)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_13); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - } - } - __pyx_t_8 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_13, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_7); - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 979, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_XDECREF_SET(__pyx_v_new_geometry, __pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":980 - * else: - * new_geometry = ogr.Geometry(ogr.wkbMultiPolygon) - * while duplicate_ids_set_iterator != duplicate_ids_set.end(): # <<<<<<<<<<<<<< - * duplicate_fid = deref(duplicate_ids_set_iterator) - * inc(duplicate_ids_set_iterator) - */ - while (1) { - __pyx_t_5 = ((__pyx_v_duplicate_ids_set_iterator != __pyx_v_duplicate_ids_set.end()) != 0); - if (!__pyx_t_5) break; - - /* "pygeoprocessing/routing/watershed.pyx":981 - * new_geometry = ogr.Geometry(ogr.wkbMultiPolygon) - * while duplicate_ids_set_iterator != duplicate_ids_set.end(): - * duplicate_fid = deref(duplicate_ids_set_iterator) # <<<<<<<<<<<<<< - * inc(duplicate_ids_set_iterator) - * - */ - __pyx_v_duplicate_fid = (*__pyx_v_duplicate_ids_set_iterator); - - /* "pygeoprocessing/routing/watershed.pyx":982 - * while duplicate_ids_set_iterator != duplicate_ids_set.end(): - * duplicate_fid = deref(duplicate_ids_set_iterator) - * inc(duplicate_ids_set_iterator) # <<<<<<<<<<<<<< - * - * duplicate_feature = polygonized_watersheds_layer.GetFeature(duplicate_fid) - */ - (void)((++__pyx_v_duplicate_ids_set_iterator)); - - /* "pygeoprocessing/routing/watershed.pyx":984 - * inc(duplicate_ids_set_iterator) - * - * duplicate_feature = polygonized_watersheds_layer.GetFeature(duplicate_fid) # <<<<<<<<<<<<<< - * duplicate_geometry = duplicate_feature.GetGeometryRef() - * new_geometry.AddGeometry(duplicate_geometry) - */ - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_polygonized_watersheds_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 984, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_duplicate_fid); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 984, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_13 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_13)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_13); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - } - } - __pyx_t_8 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_13, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_7); - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 984, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_XDECREF_SET(__pyx_v_duplicate_feature, __pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":985 - * - * duplicate_feature = polygonized_watersheds_layer.GetFeature(duplicate_fid) - * duplicate_geometry = duplicate_feature.GetGeometryRef() # <<<<<<<<<<<<<< - * new_geometry.AddGeometry(duplicate_geometry) - * - */ - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_duplicate_feature, __pyx_n_s_GetGeometryRef); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 985, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - } - } - __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_12); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 985, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_XDECREF_SET(__pyx_v_duplicate_geometry, __pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":986 - * duplicate_feature = polygonized_watersheds_layer.GetFeature(duplicate_fid) - * duplicate_geometry = duplicate_feature.GetGeometryRef() - * new_geometry.AddGeometry(duplicate_geometry) # <<<<<<<<<<<<<< - * - * watershed_feature = ogr.Feature(watersheds_layer.GetLayerDefn()) - */ - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_new_geometry, __pyx_n_s_AddGeometry); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 986, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - } - } - __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_7, __pyx_v_duplicate_geometry) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_v_duplicate_geometry); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 986, __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; - } - } - __pyx_L47:; - - /* "pygeoprocessing/routing/watershed.pyx":988 - * new_geometry.AddGeometry(duplicate_geometry) - * - * watershed_feature = ogr.Feature(watersheds_layer.GetLayerDefn()) # <<<<<<<<<<<<<< - * watershed_feature.SetGeometry(new_geometry) - * - */ - __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_ogr); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 988, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_Feature); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 988, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_watersheds_layer, __pyx_n_s_GetLayerDefn); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 988, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_13); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_13, function); - } - } - __pyx_t_12 = (__pyx_t_11) ? __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_11) : __Pyx_PyObject_CallNoArg(__pyx_t_13); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 988, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_13 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_13)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_13); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_8 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_13, __pyx_t_12) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_12); - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 988, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF_SET(__pyx_v_watershed_feature, __pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":989 - * - * watershed_feature = ogr.Feature(watersheds_layer.GetLayerDefn()) - * watershed_feature.SetGeometry(new_geometry) # <<<<<<<<<<<<<< - * - * source_feature = source_layer.GetFeature(ws_id) - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_feature, __pyx_n_s_SetGeometry); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 989, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_12 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_8 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_12, __pyx_v_new_geometry) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_new_geometry); - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 989, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":991 - * watershed_feature.SetGeometry(new_geometry) - * - * source_feature = source_layer.GetFeature(ws_id) # <<<<<<<<<<<<<< - * for field_name, field_value in source_feature.items().items(): - * watershed_feature.SetField(field_name, field_value) - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_source_layer, __pyx_n_s_GetFeature); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 991, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_12 = __Pyx_PyInt_From_int(__pyx_v_ws_id); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 991, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_13 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_13)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_13); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_8 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_13, __pyx_t_12) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_12); - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 991, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF_SET(__pyx_v_source_feature, __pyx_t_8); - __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":992 - * - * source_feature = source_layer.GetFeature(ws_id) - * for field_name, field_value in source_feature.items().items(): # <<<<<<<<<<<<<< - * watershed_feature.SetField(field_name, field_value) - * if field_name == 'ws_id': - */ - __pyx_t_23 = 0; - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_source_feature, __pyx_n_s_items); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 992, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_13 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_13)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_13); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - } - } - __pyx_t_7 = (__pyx_t_13) ? __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_13) : __Pyx_PyObject_CallNoArg(__pyx_t_12); - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 992, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(__pyx_t_7 == Py_None)) { - PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "items"); - __PYX_ERR(0, 992, __pyx_L1_error) - } - __pyx_t_12 = __Pyx_dict_iterator(__pyx_t_7, 0, __pyx_n_s_items, (&__pyx_t_34), (&__pyx_t_9)); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 992, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF(__pyx_t_8); - __pyx_t_8 = __pyx_t_12; - __pyx_t_12 = 0; - while (1) { - __pyx_t_35 = __Pyx_dict_iter_next(__pyx_t_8, __pyx_t_34, &__pyx_t_23, &__pyx_t_12, &__pyx_t_7, NULL, __pyx_t_9); - if (unlikely(__pyx_t_35 == 0)) break; - if (unlikely(__pyx_t_35 == -1)) __PYX_ERR(0, 992, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_GOTREF(__pyx_t_7); - __Pyx_XDECREF_SET(__pyx_v_field_name, __pyx_t_12); - __pyx_t_12 = 0; - __Pyx_XDECREF_SET(__pyx_v_field_value, __pyx_t_7); - __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":993 - * source_feature = source_layer.GetFeature(ws_id) - * for field_name, field_value in source_feature.items().items(): - * watershed_feature.SetField(field_name, field_value) # <<<<<<<<<<<<<< - * if field_name == 'ws_id': - * continue - */ - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_watershed_feature, __pyx_n_s_SetField); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 993, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_13 = NULL; - __pyx_t_35 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_13)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_13); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - __pyx_t_35 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_12)) { - PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_v_field_name, __pyx_v_field_value}; - __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_35, 2+__pyx_t_35); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 993, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_GOTREF(__pyx_t_7); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) { - PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_v_field_name, __pyx_v_field_value}; - __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_35, 2+__pyx_t_35); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 993, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_GOTREF(__pyx_t_7); - } else - #endif - { - __pyx_t_11 = PyTuple_New(2+__pyx_t_35); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 993, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - if (__pyx_t_13) { - __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_13); __pyx_t_13 = NULL; - } - __Pyx_INCREF(__pyx_v_field_name); - __Pyx_GIVEREF(__pyx_v_field_name); - PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_35, __pyx_v_field_name); - __Pyx_INCREF(__pyx_v_field_value); - __Pyx_GIVEREF(__pyx_v_field_value); - PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_35, __pyx_v_field_value); - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_11, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 993, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":994 - * for field_name, field_value in source_feature.items().items(): - * watershed_feature.SetField(field_name, field_value) - * if field_name == 'ws_id': # <<<<<<<<<<<<<< - * continue - * watersheds_layer.CreateFeature(watershed_feature) - */ - __pyx_t_5 = (__Pyx_PyUnicode_Equals(__pyx_v_field_name, __pyx_n_u_ws_id, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 994, __pyx_L1_error) - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/watershed.pyx":995 - * watershed_feature.SetField(field_name, field_value) - * if field_name == 'ws_id': - * continue # <<<<<<<<<<<<<< - * watersheds_layer.CreateFeature(watershed_feature) - * watersheds_layer.CommitTransaction() - */ - goto __pyx_L50_continue; - - /* "pygeoprocessing/routing/watershed.pyx":994 - * for field_name, field_value in source_feature.items().items(): - * watershed_feature.SetField(field_name, field_value) - * if field_name == 'ws_id': # <<<<<<<<<<<<<< - * continue - * watersheds_layer.CreateFeature(watershed_feature) - */ - } - __pyx_L50_continue:; - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":996 - * if field_name == 'ws_id': - * continue - * watersheds_layer.CreateFeature(watershed_feature) # <<<<<<<<<<<<<< - * watersheds_layer.CommitTransaction() - * - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_watersheds_layer, __pyx_n_s_CreateFeature); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 996, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_12 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_8 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_12, __pyx_v_watershed_feature) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_watershed_feature); - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 996, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - - /* "pygeoprocessing/routing/watershed.pyx":997 - * continue - * watersheds_layer.CreateFeature(watershed_feature) - * watersheds_layer.CommitTransaction() # <<<<<<<<<<<<<< - * - * polygonized_watersheds_layer = None - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_watersheds_layer, __pyx_n_s_CommitTransaction); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 997, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_12 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_8 = (__pyx_t_12) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_12) : __Pyx_PyObject_CallNoArg(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 997, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":999 - * watersheds_layer.CommitTransaction() - * - * polygonized_watersheds_layer = None # <<<<<<<<<<<<<< - * if remove_temp_files: - * watersheds_vector.DeleteLayer('polygonized_watersheds') - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_polygonized_watersheds_layer, Py_None); - - /* "pygeoprocessing/routing/watershed.pyx":1000 - * - * polygonized_watersheds_layer = None - * if remove_temp_files: # <<<<<<<<<<<<<< - * watersheds_vector.DeleteLayer('polygonized_watersheds') - * LOGGER.info('Finished vector consolidation') - */ - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_remove_temp_files); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1000, __pyx_L1_error) - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/watershed.pyx":1001 - * polygonized_watersheds_layer = None - * if remove_temp_files: - * watersheds_vector.DeleteLayer('polygonized_watersheds') # <<<<<<<<<<<<<< - * LOGGER.info('Finished vector consolidation') - * - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_watersheds_vector, __pyx_n_s_DeleteLayer); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1001, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_12 = NULL; - if (CYTHON_UNPACK_METHODS && likely(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_8 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_12, __pyx_n_u_polygonized_watersheds) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_n_u_polygonized_watersheds); - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1001, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":1000 - * - * polygonized_watersheds_layer = None - * if remove_temp_files: # <<<<<<<<<<<<<< - * watersheds_vector.DeleteLayer('polygonized_watersheds') - * LOGGER.info('Finished vector consolidation') - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":1002 - * if remove_temp_files: - * watersheds_vector.DeleteLayer('polygonized_watersheds') - * LOGGER.info('Finished vector consolidation') # <<<<<<<<<<<<<< - * - * watersheds_layer = None - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1002, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_info); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1002, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - } - } - __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_7, __pyx_kp_u_Finished_vector_consolidation) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_kp_u_Finished_vector_consolidation); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1002, __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/watershed.pyx":1004 - * LOGGER.info('Finished vector consolidation') - * - * watersheds_layer = None # <<<<<<<<<<<<<< - * watersheds_vector = None - * source_layer = None - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_watersheds_layer, Py_None); - - /* "pygeoprocessing/routing/watershed.pyx":1005 - * - * watersheds_layer = None - * watersheds_vector = None # <<<<<<<<<<<<<< - * source_layer = None - * source_vector = None - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_watersheds_vector, Py_None); - - /* "pygeoprocessing/routing/watershed.pyx":1006 - * watersheds_layer = None - * watersheds_vector = None - * source_layer = None # <<<<<<<<<<<<<< - * source_vector = None - * - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_source_layer, Py_None); - - /* "pygeoprocessing/routing/watershed.pyx":1007 - * watersheds_vector = None - * source_layer = None - * source_vector = None # <<<<<<<<<<<<<< - * - * if remove_temp_files: - */ - __Pyx_INCREF(Py_None); - __Pyx_DECREF_SET(__pyx_v_source_vector, Py_None); - - /* "pygeoprocessing/routing/watershed.pyx":1009 - * source_vector = None - * - * if remove_temp_files: # <<<<<<<<<<<<<< - * shutil.rmtree(working_dir_path) - * LOGGER.info('Watershed delineation complete') - */ - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_remove_temp_files); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1009, __pyx_L1_error) - if (__pyx_t_5) { - - /* "pygeoprocessing/routing/watershed.pyx":1010 - * - * if remove_temp_files: - * shutil.rmtree(working_dir_path) # <<<<<<<<<<<<<< - * LOGGER.info('Watershed delineation complete') - */ - __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_shutil); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1010, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_rmtree); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1010, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = NULL; - 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_8 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_12, __pyx_v_working_dir_path) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_working_dir_path); - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1010, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":1009 - * source_vector = None - * - * if remove_temp_files: # <<<<<<<<<<<<<< - * shutil.rmtree(working_dir_path) - * LOGGER.info('Watershed delineation complete') - */ - } - - /* "pygeoprocessing/routing/watershed.pyx":1011 - * if remove_temp_files: - * shutil.rmtree(working_dir_path) - * LOGGER.info('Watershed delineation complete') # <<<<<<<<<<<<<< - */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_LOGGER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1011, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_info); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1011, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - } - } - __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_7, __pyx_kp_u_Watershed_delineation_complete) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_kp_u_Watershed_delineation_complete); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1011, __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/watershed.pyx":624 - * - * @cython.boundscheck(False) - * def delineate_watersheds_d8( # <<<<<<<<<<<<<< - * d8_flow_dir_raster_path_band, outflow_vector_path, - * target_watersheds_vector_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_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_XDECREF(__pyx_t_13); - __Pyx_XDECREF(__pyx_t_17); - __Pyx_XDECREF(__pyx_t_18); - __Pyx_XDECREF(__pyx_t_19); - __Pyx_AddTraceback("pygeoprocessing.routing.watershed.delineate_watersheds_d8", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_working_dir_path); - __Pyx_XDECREF(__pyx_v_flow_dir_info); - __Pyx_XDECREF(__pyx_v_source_gt); - __Pyx_XDECREF(__pyx_v_bbox_minx); - __Pyx_XDECREF(__pyx_v_bbox_miny); - __Pyx_XDECREF(__pyx_v_bbox_maxx); - __Pyx_XDECREF(__pyx_v_bbox_maxy); - __Pyx_XDECREF(__pyx_v_flow_dir_bbox); - __Pyx_XDECREF((PyObject *)__pyx_v_flow_dir_managed_raster); - __Pyx_XDECREF(__pyx_v_gtiff_driver); - __Pyx_XDECREF(__pyx_v_flow_dir_srs); - __Pyx_XDECREF(__pyx_v_outflow_vector); - __Pyx_XDECREF(__pyx_v_driver); - __Pyx_XDECREF(__pyx_v_watersheds_srs); - __Pyx_XDECREF(__pyx_v_watersheds_vector); - __Pyx_XDECREF(__pyx_v_polygonized_watersheds_layer); - __Pyx_XDECREF(__pyx_v_watersheds_layer); - __Pyx_XDECREF(__pyx_v_index_field); - __Pyx_XDECREF((PyObject *)__pyx_v_scratch_managed_raster); - __Pyx_XDECREF(__pyx_v_outflow_layer); - __Pyx_XDECREF(__pyx_v_feature); - __Pyx_XDECREF(__pyx_v_geom); - __Pyx_XDECREF(__pyx_v_geom_wkb); - __Pyx_XDECREF(__pyx_v_shapely_geom); - __Pyx_XDECREF(__pyx_v_seeds_raster_path); - __Pyx_XDECREF(__pyx_v_diagnostic_vector_path); - __Pyx_XDECREF(__pyx_v_scratch_raster_path); - __Pyx_XDECREF(__pyx_v_scratch_raster); - __Pyx_XDECREF(__pyx_v_vrt_options); - __Pyx_XDECREF(__pyx_v_vrt_path); - __Pyx_XDECREF(__pyx_v_vrt_raster); - __Pyx_XDECREF(__pyx_v_vrt_band); - __Pyx_XDECREF(__pyx_v__); - __Pyx_XDECREF(__pyx_v_source_vector); - __Pyx_XDECREF(__pyx_v_source_layer); - __Pyx_XDECREF(__pyx_v_source_feature); - __Pyx_XDECREF(__pyx_v_new_geometry); - __Pyx_XDECREF(__pyx_v_duplicate_feature); - __Pyx_XDECREF(__pyx_v_duplicate_geometry); - __Pyx_XDECREF(__pyx_v_watershed_feature); - __Pyx_XDECREF(__pyx_v_field_name); - __Pyx_XDECREF(__pyx_v_field_value); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":735 - * ctypedef npy_cdouble complex_t - * - * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(1, 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew1", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":736 - * - * cdef inline object PyArray_MultiIterNew1(a): - * return PyArray_MultiIterNew(1, 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, 736, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":735 - * ctypedef npy_cdouble complex_t - * - * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(1, 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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":738 - * return PyArray_MultiIterNew(1, a) - * - * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(2, a, 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew2", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":739 - * - * cdef inline object PyArray_MultiIterNew2(a, b): - * return PyArray_MultiIterNew(2, a, 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, 739, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":738 - * return PyArray_MultiIterNew(1, a) - * - * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(2, a, 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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":741 - * return PyArray_MultiIterNew(2, a, b) - * - * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(3, a, b, 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew3", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":742 - * - * cdef inline object PyArray_MultiIterNew3(a, b, c): - * return PyArray_MultiIterNew(3, a, b, 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, 742, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":741 - * return PyArray_MultiIterNew(2, a, b) - * - * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(3, a, b, 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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":744 - * return PyArray_MultiIterNew(3, a, b, c) - * - * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(4, a, b, c, 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew4", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":745 - * - * cdef inline object PyArray_MultiIterNew4(a, b, c, d): - * return PyArray_MultiIterNew(4, a, b, c, 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, 745, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":744 - * return PyArray_MultiIterNew(3, a, b, c) - * - * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(4, a, b, c, 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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":747 - * return PyArray_MultiIterNew(4, a, b, c, d) - * - * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(5, a, b, c, d, 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew5", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":748 - * - * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): - * return PyArray_MultiIterNew(5, a, b, c, d, 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, 748, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":747 - * return PyArray_MultiIterNew(4, a, b, c, d) - * - * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(5, a, b, c, d, 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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":750 - * return PyArray_MultiIterNew(5, a, b, c, d, e) - * - * cdef inline tuple PyDataType_SHAPE(dtype d): # <<<<<<<<<<<<<< - * if PyDataType_HASSUBARRAY(d): - * return 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); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":751 - * - * cdef inline tuple PyDataType_SHAPE(dtype d): - * if PyDataType_HASSUBARRAY(d): # <<<<<<<<<<<<<< - * return d.subarray.shape - * else: - */ - __pyx_t_1 = (PyDataType_HASSUBARRAY(__pyx_v_d) != 0); - if (__pyx_t_1) { - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":752 - * cdef inline tuple PyDataType_SHAPE(dtype d): - * if PyDataType_HASSUBARRAY(d): - * return 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; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":751 - * - * cdef inline tuple PyDataType_SHAPE(dtype d): - * if PyDataType_HASSUBARRAY(d): # <<<<<<<<<<<<<< - * return d.subarray.shape - * else: - */ - } - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":754 - * return d.subarray.shape - * else: - * return () # <<<<<<<<<<<<<< - * - * - */ - /*else*/ { - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_empty_tuple); - __pyx_r = __pyx_empty_tuple; - goto __pyx_L0; - } - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":750 - * return PyArray_MultiIterNew(5, a, b, c, d, e) - * - * cdef inline tuple PyDataType_SHAPE(dtype d): # <<<<<<<<<<<<<< - * if PyDataType_HASSUBARRAY(d): - * return d.subarray.shape - */ - - /* function exit code */ - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":931 - * int _import_umath() except -1 - * - * cdef inline void set_array_base(ndarray arr, object base): # <<<<<<<<<<<<<< - * Py_INCREF(base) # important to do this before stealing the reference below! - * PyArray_SetBaseObject(arr, base) - */ - -static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_arr, PyObject *__pyx_v_base) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("set_array_base", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":932 - * - * cdef inline void set_array_base(ndarray arr, object base): - * Py_INCREF(base) # important to do this before stealing the reference below! # <<<<<<<<<<<<<< - * PyArray_SetBaseObject(arr, base) - * - */ - Py_INCREF(__pyx_v_base); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":933 - * cdef inline void set_array_base(ndarray arr, object base): - * Py_INCREF(base) # important to do this before stealing the reference below! - * PyArray_SetBaseObject(arr, base) # <<<<<<<<<<<<<< - * - * cdef inline object get_array_base(ndarray arr): - */ - (void)(PyArray_SetBaseObject(__pyx_v_arr, __pyx_v_base)); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":931 - * int _import_umath() except -1 - * - * cdef inline void set_array_base(ndarray arr, object base): # <<<<<<<<<<<<<< - * Py_INCREF(base) # important to do this before stealing the reference below! - * PyArray_SetBaseObject(arr, base) - */ - - /* function exit code */ - __Pyx_RefNannyFinishContext(); -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":935 - * PyArray_SetBaseObject(arr, base) - * - * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< - * base = PyArray_BASE(arr) - * if base is NULL: - */ - -static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__pyx_v_arr) { - PyObject *__pyx_v_base; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("get_array_base", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":936 - * - * cdef inline object get_array_base(ndarray arr): - * base = PyArray_BASE(arr) # <<<<<<<<<<<<<< - * if base is NULL: - * return None - */ - __pyx_v_base = PyArray_BASE(__pyx_v_arr); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":937 - * cdef inline object get_array_base(ndarray arr): - * base = PyArray_BASE(arr) - * if base is NULL: # <<<<<<<<<<<<<< - * return None - * return base - */ - __pyx_t_1 = ((__pyx_v_base == NULL) != 0); - if (__pyx_t_1) { - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":938 - * base = PyArray_BASE(arr) - * if base is NULL: - * return None # <<<<<<<<<<<<<< - * return base - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":937 - * cdef inline object get_array_base(ndarray arr): - * base = PyArray_BASE(arr) - * if base is NULL: # <<<<<<<<<<<<<< - * return None - * return base - */ - } - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":939 - * if base is NULL: - * return None - * return base # <<<<<<<<<<<<<< - * - * # Versions of the import_* functions which are more suitable for - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_base)); - __pyx_r = ((PyObject *)__pyx_v_base); - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":935 - * PyArray_SetBaseObject(arr, base) - * - * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< - * base = PyArray_BASE(arr) - * if base is NULL: - */ - - /* function exit code */ - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":943 - * # Versions of the import_* functions which are more suitable for - * # Cython code. - * cdef inline int import_array() except -1: # <<<<<<<<<<<<<< - * try: - * __pyx_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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("import_array", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":944 - * # Cython code. - * cdef inline int import_array() except -1: - * try: # <<<<<<<<<<<<<< - * __pyx_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:*/ { - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":945 - * cdef inline int import_array() except -1: - * try: - * __pyx_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, 945, __pyx_L3_error) - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":944 - * # Cython code. - * cdef inline int import_array() except -1: - * try: # <<<<<<<<<<<<<< - * __pyx_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:; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":946 - * try: - * __pyx_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, 946, __pyx_L5_except_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GOTREF(__pyx_t_7); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":947 - * __pyx_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__4, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 947, __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, 947, __pyx_L5_except_error) - } - goto __pyx_L5_except_error; - __pyx_L5_except_error:; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":944 - * # Cython code. - * cdef inline int import_array() except -1: - * try: # <<<<<<<<<<<<<< - * __pyx_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:; - } - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":943 - * # Versions of the import_* functions which are more suitable for - * # Cython code. - * cdef inline int import_array() except -1: # <<<<<<<<<<<<<< - * try: - * __pyx_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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":949 - * 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("import_umath", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":950 - * - * 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:*/ { - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":951 - * 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, 951, __pyx_L3_error) - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":950 - * - * 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:; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":952 - * 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, 952, __pyx_L5_except_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GOTREF(__pyx_t_7); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":953 - * _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__5, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 953, __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, 953, __pyx_L5_except_error) - } - goto __pyx_L5_except_error; - __pyx_L5_except_error:; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":950 - * - * 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:; - } - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":949 - * 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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":955 - * 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; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("import_ufunc", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":956 - * - * 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:*/ { - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":957 - * 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, 957, __pyx_L3_error) - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":956 - * - * 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:; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":958 - * 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, 958, __pyx_L5_except_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GOTREF(__pyx_t_7); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":959 - * _import_umath() - * except Exception: - * raise ImportError("numpy.core.umath failed to import") # <<<<<<<<<<<<<< - * - * cdef extern from *: - */ - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 959, __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, 959, __pyx_L5_except_error) - } - goto __pyx_L5_except_error; - __pyx_L5_except_error:; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":956 - * - * 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:; - } - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":955 - * 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; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":969 - * - * - * cdef inline bint is_timedelta64_object(object obj): # <<<<<<<<<<<<<< - * """ - * Cython equivalent of `isinstance(obj, np.timedelta64)` - */ - -static CYTHON_INLINE int __pyx_f_5numpy_is_timedelta64_object(PyObject *__pyx_v_obj) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("is_timedelta64_object", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":981 - * bool - * """ - * return PyObject_TypeCheck(obj, &PyTimedeltaArrType_Type) # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = PyObject_TypeCheck(__pyx_v_obj, (&PyTimedeltaArrType_Type)); - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":969 - * - * - * cdef inline bint is_timedelta64_object(object obj): # <<<<<<<<<<<<<< - * """ - * Cython equivalent of `isinstance(obj, np.timedelta64)` - */ - - /* function exit code */ - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":984 - * - * - * cdef inline bint is_datetime64_object(object obj): # <<<<<<<<<<<<<< - * """ - * Cython equivalent of `isinstance(obj, np.datetime64)` - */ - -static CYTHON_INLINE int __pyx_f_5numpy_is_datetime64_object(PyObject *__pyx_v_obj) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("is_datetime64_object", 0); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":996 - * bool - * """ - * return PyObject_TypeCheck(obj, &PyDatetimeArrType_Type) # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = PyObject_TypeCheck(__pyx_v_obj, (&PyDatetimeArrType_Type)); - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":984 - * - * - * cdef inline bint is_datetime64_object(object obj): # <<<<<<<<<<<<<< - * """ - * Cython equivalent of `isinstance(obj, np.datetime64)` - */ - - /* function exit code */ - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":999 - * - * - * cdef inline npy_datetime get_datetime64_value(object obj) nogil: # <<<<<<<<<<<<<< - * """ - * returns the int64 value underlying scalar numpy datetime64 object - */ - -static CYTHON_INLINE npy_datetime __pyx_f_5numpy_get_datetime64_value(PyObject *__pyx_v_obj) { - npy_datetime __pyx_r; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1006 - * also needed. That can be found using `get_datetime64_unit`. - * """ - * return (obj).obval # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = ((PyDatetimeScalarObject *)__pyx_v_obj)->obval; - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":999 - * - * - * cdef inline npy_datetime get_datetime64_value(object obj) nogil: # <<<<<<<<<<<<<< - * """ - * returns the int64 value underlying scalar numpy datetime64 object - */ - - /* function exit code */ - __pyx_L0:; - return __pyx_r; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1009 - * - * - * cdef inline npy_timedelta get_timedelta64_value(object obj) nogil: # <<<<<<<<<<<<<< - * """ - * returns the int64 value underlying scalar numpy timedelta64 object - */ - -static CYTHON_INLINE npy_timedelta __pyx_f_5numpy_get_timedelta64_value(PyObject *__pyx_v_obj) { - npy_timedelta __pyx_r; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1013 - * returns the int64 value underlying scalar numpy timedelta64 object - * """ - * return (obj).obval # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = ((PyTimedeltaScalarObject *)__pyx_v_obj)->obval; - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1009 - * - * - * cdef inline npy_timedelta get_timedelta64_value(object obj) nogil: # <<<<<<<<<<<<<< - * """ - * returns the int64 value underlying scalar numpy timedelta64 object - */ - - /* function exit code */ - __pyx_L0:; - return __pyx_r; -} - -/* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1016 - * - * - * cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil: # <<<<<<<<<<<<<< - * """ - * returns the unit part of the dtype for a numpy datetime64 object. - */ - -static CYTHON_INLINE NPY_DATETIMEUNIT __pyx_f_5numpy_get_datetime64_unit(PyObject *__pyx_v_obj) { - NPY_DATETIMEUNIT __pyx_r; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1020 - * returns the unit part of the dtype for a numpy datetime64 object. - * """ - * return (obj).obmeta.base # <<<<<<<<<<<<<< - */ - __pyx_r = ((NPY_DATETIMEUNIT)((PyDatetimeScalarObject *)__pyx_v_obj)->obmeta.base); - goto __pyx_L0; - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":1016 - * - * - * cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil: # <<<<<<<<<<<<<< - * """ - * returns the unit part of the dtype for a numpy datetime64 object. - */ - - /* function exit code */ - __pyx_L0:; - return __pyx_r; -} - -/* "pair.to_py":158 - * - * @cname("__pyx_convert_pair_to_py_long____long") - * cdef object __pyx_convert_pair_to_py_long____long(const pair[X,Y]& p): # <<<<<<<<<<<<<< - * return p.first, p.second - * - */ - -static PyObject *__pyx_convert_pair_to_py_long____long(std::pair const &__pyx_v_p) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__pyx_convert_pair_to_py_long____long", 0); - - /* "pair.to_py":159 - * @cname("__pyx_convert_pair_to_py_long____long") - * cdef object __pyx_convert_pair_to_py_long____long(const pair[X,Y]& p): - * return p.first, p.second # <<<<<<<<<<<<<< - * - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_p.first); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 159, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_p.second); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 159, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 159, __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_2); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); - __pyx_t_1 = 0; - __pyx_t_2 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - - /* "pair.to_py":158 - * - * @cname("__pyx_convert_pair_to_py_long____long") - * cdef object __pyx_convert_pair_to_py_long____long(const pair[X,Y]& p): # <<<<<<<<<<<<<< - * return p.first, p.second - * - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pair.to_py.__pyx_convert_pair_to_py_long____long", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pair.from_py":145 - * - * @cname("__pyx_convert_pair_from_py_long__and_long") - * cdef pair[X,Y] __pyx_convert_pair_from_py_long__and_long(object o) except *: # <<<<<<<<<<<<<< - * x, y = o - * return pair[X,Y](x, y) - */ - -static std::pair __pyx_convert_pair_from_py_long__and_long(PyObject *__pyx_v_o) { - PyObject *__pyx_v_x = NULL; - PyObject *__pyx_v_y = NULL; - std::pair __pyx_r; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *(*__pyx_t_4)(PyObject *); - long __pyx_t_5; - long __pyx_t_6; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__pyx_convert_pair_from_py_long__and_long", 0); - - /* "pair.from_py":146 - * @cname("__pyx_convert_pair_from_py_long__and_long") - * cdef pair[X,Y] __pyx_convert_pair_from_py_long__and_long(object o) except *: - * x, y = o # <<<<<<<<<<<<<< - * return pair[X,Y](x, y) - * - */ - if ((likely(PyTuple_CheckExact(__pyx_v_o))) || (PyList_CheckExact(__pyx_v_o))) { - PyObject* sequence = __pyx_v_o; - 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(1, 146, __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(1, 146, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 146, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } else { - Py_ssize_t index = -1; - __pyx_t_3 = PyObject_GetIter(__pyx_v_o); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 146, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; - index = 0; __pyx_t_1 = __pyx_t_4(__pyx_t_3); if (unlikely(!__pyx_t_1)) goto __pyx_L3_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - index = 1; __pyx_t_2 = __pyx_t_4(__pyx_t_3); if (unlikely(!__pyx_t_2)) goto __pyx_L3_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_4(__pyx_t_3), 2) < 0) __PYX_ERR(1, 146, __pyx_L1_error) - __pyx_t_4 = NULL; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L4_unpacking_done; - __pyx_L3_unpacking_failed:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_4 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(1, 146, __pyx_L1_error) - __pyx_L4_unpacking_done:; - } - __pyx_v_x = __pyx_t_1; - __pyx_t_1 = 0; - __pyx_v_y = __pyx_t_2; - __pyx_t_2 = 0; - - /* "pair.from_py":147 - * cdef pair[X,Y] __pyx_convert_pair_from_py_long__and_long(object o) except *: - * x, y = o - * return pair[X,Y](x, y) # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_5 = __Pyx_PyInt_As_long(__pyx_v_x); if (unlikely((__pyx_t_5 == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 147, __pyx_L1_error) - __pyx_t_6 = __Pyx_PyInt_As_long(__pyx_v_y); if (unlikely((__pyx_t_6 == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 147, __pyx_L1_error) - __pyx_r = std::pair (((long)__pyx_t_5), ((long)__pyx_t_6)); - goto __pyx_L0; - - /* "pair.from_py":145 - * - * @cname("__pyx_convert_pair_from_py_long__and_long") - * cdef pair[X,Y] __pyx_convert_pair_from_py_long__and_long(object o) except *: # <<<<<<<<<<<<<< - * x, y = o - * return pair[X,Y](x, y) - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pair.from_py.__pyx_convert_pair_from_py_long__and_long", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_pretend_to_initialize(&__pyx_r); - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_x); - __Pyx_XDECREF(__pyx_v_y); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -static struct __pyx_vtabstruct_15pygeoprocessing_7routing_9watershed__ManagedRaster __pyx_vtable_15pygeoprocessing_7routing_9watershed__ManagedRaster; - -static PyObject *__pyx_tp_new_15pygeoprocessing_7routing_9watershed__ManagedRaster(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_15pygeoprocessing_7routing_9watershed__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_9watershed__ManagedRaster *)o); - p->__pyx_vtab = __pyx_vtabptr_15pygeoprocessing_7routing_9watershed__ManagedRaster; - new((void*)&(p->dirty_blocks)) std::set (); - p->raster_path = ((PyObject*)Py_None); Py_INCREF(Py_None); - if (unlikely(__pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_3__cinit__(o, a, k) < 0)) goto bad; - return o; - bad: - Py_DECREF(o); o = 0; - return NULL; -} - -static void __pyx_tp_dealloc_15pygeoprocessing_7routing_9watershed__ManagedRaster(PyObject *o) { - struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *p = (struct __pyx_obj_15pygeoprocessing_7routing_9watershed__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); - __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1); - __pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_5__dealloc__(o); - __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1); - 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_9watershed__ManagedRaster[] = { - {"close", (PyCFunction)__pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_7close, METH_NOARGS, __pyx_doc_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_6close}, - {"__reduce_cython__", (PyCFunction)__pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_9__reduce_cython__, METH_NOARGS, 0}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_11__setstate_cython__, METH_O, 0}, - {0, 0, 0, 0} -}; - -static PyTypeObject __pyx_type_15pygeoprocessing_7routing_9watershed__ManagedRaster = { - PyVarObject_HEAD_INIT(0, 0) - "pygeoprocessing.routing.watershed._ManagedRaster", /*tp_name*/ - sizeof(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_15pygeoprocessing_7routing_9watershed__ManagedRaster, /*tp_dealloc*/ - #if PY_VERSION_HEX < 0x030800b4 - 0, /*tp_print*/ - #endif - #if PY_VERSION_HEX >= 0x030800b4 - 0, /*tp_vectorcall_offset*/ - #endif - 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_9watershed__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*/ - __pyx_pw_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_1__init__, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_15pygeoprocessing_7routing_9watershed__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 - #if PY_VERSION_HEX >= 0x030800b1 - 0, /*tp_vectorcall*/ - #endif - #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000 - 0, /*tp_print*/ - #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_watershed(PyObject* module); /*proto*/ -static PyModuleDef_Slot __pyx_moduledef_slots[] = { - {Py_mod_create, (void*)__pyx_pymod_create}, - {Py_mod_exec, (void*)__pyx_pymod_exec_watershed}, - {0, NULL} -}; -#endif - -static struct PyModuleDef __pyx_moduledef = { - PyModuleDef_HEAD_INIT, - "watershed", - 0, /* 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 -#ifndef CYTHON_SMALL_CODE -#if defined(__clang__) - #define CYTHON_SMALL_CODE -#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) - #define CYTHON_SMALL_CODE __attribute__((cold)) -#else - #define CYTHON_SMALL_CODE -#endif -#endif - -static __Pyx_StringTabEntry __pyx_string_tab[] = { - {&__pyx_kp_u_, __pyx_k_, sizeof(__pyx_k_), 0, 1, 0, 0}, - {&__pyx_kp_u_ALL_TOUCHED_True, __pyx_k_ALL_TOUCHED_True, sizeof(__pyx_k_ALL_TOUCHED_True), 0, 1, 0, 0}, - {&__pyx_n_s_AddGeometry, __pyx_k_AddGeometry, sizeof(__pyx_k_AddGeometry), 0, 0, 1, 1}, - {&__pyx_kp_u_BIGTIFF_YES, __pyx_k_BIGTIFF_YES, sizeof(__pyx_k_BIGTIFF_YES), 0, 1, 0, 0}, - {&__pyx_kp_u_BLOCKXSIZE_d, __pyx_k_BLOCKXSIZE_d, sizeof(__pyx_k_BLOCKXSIZE_d), 0, 1, 0, 0}, - {&__pyx_kp_u_BLOCKYSIZE_d, __pyx_k_BLOCKYSIZE_d, sizeof(__pyx_k_BLOCKYSIZE_d), 0, 1, 0, 0}, - {&__pyx_n_s_BuildVRT, __pyx_k_BuildVRT, sizeof(__pyx_k_BuildVRT), 0, 0, 1, 1}, - {&__pyx_n_s_BuildVRTOptions, __pyx_k_BuildVRTOptions, sizeof(__pyx_k_BuildVRTOptions), 0, 0, 1, 1}, - {&__pyx_kp_u_COMPRESS_LZW, __pyx_k_COMPRESS_LZW, sizeof(__pyx_k_COMPRESS_LZW), 0, 1, 0, 0}, - {&__pyx_n_s_CommitTransaction, __pyx_k_CommitTransaction, sizeof(__pyx_k_CommitTransaction), 0, 0, 1, 1}, - {&__pyx_kp_u_Consolidating_s_fragments_and_co, __pyx_k_Consolidating_s_fragments_and_co, sizeof(__pyx_k_Consolidating_s_fragments_and_co), 0, 1, 0, 0}, - {&__pyx_kp_u_Could_not_open_outflow_vector_s, __pyx_k_Could_not_open_outflow_vector_s, sizeof(__pyx_k_Could_not_open_outflow_vector_s), 0, 1, 0, 0}, - {&__pyx_n_s_Create, __pyx_k_Create, sizeof(__pyx_k_Create), 0, 0, 1, 1}, - {&__pyx_n_s_CreateDataSource, __pyx_k_CreateDataSource, sizeof(__pyx_k_CreateDataSource), 0, 0, 1, 1}, - {&__pyx_n_s_CreateFeature, __pyx_k_CreateFeature, sizeof(__pyx_k_CreateFeature), 0, 0, 1, 1}, - {&__pyx_n_s_CreateField, __pyx_k_CreateField, sizeof(__pyx_k_CreateField), 0, 0, 1, 1}, - {&__pyx_n_s_CreateFields, __pyx_k_CreateFields, sizeof(__pyx_k_CreateFields), 0, 0, 1, 1}, - {&__pyx_n_s_CreateGeometryFromWkb, __pyx_k_CreateGeometryFromWkb, sizeof(__pyx_k_CreateGeometryFromWkb), 0, 0, 1, 1}, - {&__pyx_n_s_CreateLayer, __pyx_k_CreateLayer, sizeof(__pyx_k_CreateLayer), 0, 0, 1, 1}, - {&__pyx_kp_u_Creating_flow_dir_bbox, __pyx_k_Creating_flow_dir_bbox, sizeof(__pyx_k_Creating_flow_dir_bbox), 0, 1, 0, 0}, - {&__pyx_kp_u_Creating_flow_dir_managed_raster, __pyx_k_Creating_flow_dir_managed_raster, sizeof(__pyx_k_Creating_flow_dir_managed_raster), 0, 1, 0, 0}, - {&__pyx_n_s_DeleteLayer, __pyx_k_DeleteLayer, sizeof(__pyx_k_DeleteLayer), 0, 0, 1, 1}, - {&__pyx_kp_u_Delineating_watershed_s_of_s_ws, __pyx_k_Delineating_watershed_s_of_s_ws, sizeof(__pyx_k_Delineating_watershed_s_of_s_ws), 0, 1, 0, 0}, - {&__pyx_kp_u_Delineating_watershed_s_of_s_ws_2, __pyx_k_Delineating_watershed_s_of_s_ws_2, sizeof(__pyx_k_Delineating_watershed_s_of_s_ws_2), 0, 1, 0, 0}, - {&__pyx_kp_u_Delineating_watersheds, __pyx_k_Delineating_watersheds, sizeof(__pyx_k_Delineating_watersheds), 0, 1, 0, 0}, - {&__pyx_kp_u_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, 1, 0, 0}, - {&__pyx_kp_u_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, 1, 0, 0}, - {&__pyx_n_s_ExportToWkb, __pyx_k_ExportToWkb, sizeof(__pyx_k_ExportToWkb), 0, 0, 1, 1}, - {&__pyx_n_s_ExportToWkt, __pyx_k_ExportToWkt, sizeof(__pyx_k_ExportToWkt), 0, 0, 1, 1}, - {&__pyx_n_s_Feature, __pyx_k_Feature, sizeof(__pyx_k_Feature), 0, 0, 1, 1}, - {&__pyx_n_s_FieldDefn, __pyx_k_FieldDefn, sizeof(__pyx_k_FieldDefn), 0, 0, 1, 1}, - {&__pyx_kp_u_Finished_delineating_s_watershed, __pyx_k_Finished_delineating_s_watershed, sizeof(__pyx_k_Finished_delineating_s_watershed), 0, 1, 0, 0}, - {&__pyx_kp_u_Finished_vector_consolidation, __pyx_k_Finished_vector_consolidation, sizeof(__pyx_k_Finished_vector_consolidation), 0, 1, 0, 0}, - {&__pyx_n_s_FlushCache, __pyx_k_FlushCache, sizeof(__pyx_k_FlushCache), 0, 0, 1, 1}, - {&__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_UInt32, __pyx_k_GDT_UInt32, sizeof(__pyx_k_GDT_UInt32), 0, 0, 1, 1}, - {&__pyx_n_s_GDT_Unknown, __pyx_k_GDT_Unknown, sizeof(__pyx_k_GDT_Unknown), 0, 0, 1, 1}, - {&__pyx_n_u_GPKG, __pyx_k_GPKG, sizeof(__pyx_k_GPKG), 0, 1, 0, 1}, - {&__pyx_n_s_GTIFF_CREATION_OPTIONS, __pyx_k_GTIFF_CREATION_OPTIONS, sizeof(__pyx_k_GTIFF_CREATION_OPTIONS), 0, 0, 1, 1}, - {&__pyx_n_u_GTiff, __pyx_k_GTiff, sizeof(__pyx_k_GTiff), 0, 1, 0, 1}, - {&__pyx_n_s_Geometry, __pyx_k_Geometry, sizeof(__pyx_k_Geometry), 0, 0, 1, 1}, - {&__pyx_n_s_GetDriverByName, __pyx_k_GetDriverByName, sizeof(__pyx_k_GetDriverByName), 0, 0, 1, 1}, - {&__pyx_n_s_GetFID, __pyx_k_GetFID, sizeof(__pyx_k_GetFID), 0, 0, 1, 1}, - {&__pyx_n_s_GetFeature, __pyx_k_GetFeature, sizeof(__pyx_k_GetFeature), 0, 0, 1, 1}, - {&__pyx_n_s_GetFeatureCount, __pyx_k_GetFeatureCount, sizeof(__pyx_k_GetFeatureCount), 0, 0, 1, 1}, - {&__pyx_n_s_GetField, __pyx_k_GetField, sizeof(__pyx_k_GetField), 0, 0, 1, 1}, - {&__pyx_n_s_GetGeometryRef, __pyx_k_GetGeometryRef, sizeof(__pyx_k_GetGeometryRef), 0, 0, 1, 1}, - {&__pyx_n_s_GetLayer, __pyx_k_GetLayer, sizeof(__pyx_k_GetLayer), 0, 0, 1, 1}, - {&__pyx_n_s_GetLayerDefn, __pyx_k_GetLayerDefn, sizeof(__pyx_k_GetLayerDefn), 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_ImportFromWkt, __pyx_k_ImportFromWkt, sizeof(__pyx_k_ImportFromWkt), 0, 0, 1, 1}, - {&__pyx_n_s_IsEmpty, __pyx_k_IsEmpty, sizeof(__pyx_k_IsEmpty), 0, 0, 1, 1}, - {&__pyx_n_s_LOGGER, __pyx_k_LOGGER, sizeof(__pyx_k_LOGGER), 0, 0, 1, 1}, - {&__pyx_n_s_ManagedRaster, __pyx_k_ManagedRaster, sizeof(__pyx_k_ManagedRaster), 0, 0, 1, 1}, - {&__pyx_n_u_Memory, __pyx_k_Memory, sizeof(__pyx_k_Memory), 0, 1, 0, 1}, - {&__pyx_n_s_OFTInteger, __pyx_k_OFTInteger, sizeof(__pyx_k_OFTInteger), 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_OF_VECTOR, __pyx_k_OF_VECTOR, sizeof(__pyx_k_OF_VECTOR), 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_kp_u_Outflow_feature_s_does_not_inter, __pyx_k_Outflow_feature_s_does_not_inter, sizeof(__pyx_k_Outflow_feature_s_does_not_inter), 0, 1, 0, 0}, - {&__pyx_kp_u_Outflow_feature_s_does_not_overl, __pyx_k_Outflow_feature_s_does_not_overl, sizeof(__pyx_k_Outflow_feature_s_does_not_overl), 0, 1, 0, 0}, - {&__pyx_kp_u_Outflow_feature_s_has_empty_geom, __pyx_k_Outflow_feature_s_has_empty_geom, sizeof(__pyx_k_Outflow_feature_s_has_empty_geom), 0, 1, 0, 0}, - {&__pyx_n_s_Point, __pyx_k_Point, sizeof(__pyx_k_Point), 0, 0, 1, 1}, - {&__pyx_n_s_Polygon, __pyx_k_Polygon, sizeof(__pyx_k_Polygon), 0, 0, 1, 1}, - {&__pyx_n_s_Polygonize, __pyx_k_Polygonize, sizeof(__pyx_k_Polygonize), 0, 0, 1, 1}, - {&__pyx_n_s_RasterizeLayer, __pyx_k_RasterizeLayer, sizeof(__pyx_k_RasterizeLayer), 0, 0, 1, 1}, - {&__pyx_n_s_ReadAsArray, __pyx_k_ReadAsArray, sizeof(__pyx_k_ReadAsArray), 0, 0, 1, 1}, - {&__pyx_n_s_ResetReading, __pyx_k_ResetReading, sizeof(__pyx_k_ResetReading), 0, 0, 1, 1}, - {&__pyx_kp_u_SPARSE_OK_TRUE, __pyx_k_SPARSE_OK_TRUE, sizeof(__pyx_k_SPARSE_OK_TRUE), 0, 1, 0, 0}, - {&__pyx_n_s_SetField, __pyx_k_SetField, sizeof(__pyx_k_SetField), 0, 0, 1, 1}, - {&__pyx_n_s_SetGeoTransform, __pyx_k_SetGeoTransform, sizeof(__pyx_k_SetGeoTransform), 0, 0, 1, 1}, - {&__pyx_n_s_SetGeometry, __pyx_k_SetGeometry, sizeof(__pyx_k_SetGeometry), 0, 0, 1, 1}, - {&__pyx_n_s_SetProjection, __pyx_k_SetProjection, sizeof(__pyx_k_SetProjection), 0, 0, 1, 1}, - {&__pyx_n_s_SetWidth, __pyx_k_SetWidth, sizeof(__pyx_k_SetWidth), 0, 0, 1, 1}, - {&__pyx_n_s_SpatialReference, __pyx_k_SpatialReference, sizeof(__pyx_k_SpatialReference), 0, 0, 1, 1}, - {&__pyx_n_s_StartTransaction, __pyx_k_StartTransaction, sizeof(__pyx_k_StartTransaction), 0, 0, 1, 1}, - {&__pyx_kp_u_TILED_YES, __pyx_k_TILED_YES, sizeof(__pyx_k_TILED_YES), 0, 1, 0, 0}, - {&__pyx_kp_u_Testing_geometry_bbox, __pyx_k_Testing_geometry_bbox, sizeof(__pyx_k_Testing_geometry_bbox), 0, 1, 0, 0}, - {&__pyx_kp_u_This_exception_is_happeningin_C, __pyx_k_This_exception_is_happeningin_C, sizeof(__pyx_k_This_exception_is_happeningin_C), 0, 1, 0, 0}, - {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1}, - {&__pyx_n_u_VRT, __pyx_k_VRT, sizeof(__pyx_k_VRT), 0, 1, 0, 1}, - {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1}, - {&__pyx_kp_u_WSID_1, __pyx_k_WSID_1, sizeof(__pyx_k_WSID_1), 0, 1, 0, 0}, - {&__pyx_kp_u_Watershed_delineation_complete, __pyx_k_Watershed_delineation_complete, sizeof(__pyx_k_Watershed_delineation_complete), 0, 1, 0, 0}, - {&__pyx_n_s_WriteArray, __pyx_k_WriteArray, sizeof(__pyx_k_WriteArray), 0, 0, 1, 1}, - {&__pyx_kp_u_Y_m_d__H__M__S, __pyx_k_Y_m_d__H__M__S, sizeof(__pyx_k_Y_m_d__H__M__S), 0, 1, 0, 0}, - {&__pyx_n_s__10, __pyx_k__10, sizeof(__pyx_k__10), 0, 0, 1, 1}, - {&__pyx_n_s_allowed_drivers, __pyx_k_allowed_drivers, sizeof(__pyx_k_allowed_drivers), 0, 0, 1, 1}, - {&__pyx_n_s_astype, __pyx_k_astype, sizeof(__pyx_k_astype), 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_bbox_maxx, __pyx_k_bbox_maxx, sizeof(__pyx_k_bbox_maxx), 0, 0, 1, 1}, - {&__pyx_n_s_bbox_maxy, __pyx_k_bbox_maxy, sizeof(__pyx_k_bbox_maxy), 0, 0, 1, 1}, - {&__pyx_n_s_bbox_minx, __pyx_k_bbox_minx, sizeof(__pyx_k_bbox_minx), 0, 0, 1, 1}, - {&__pyx_n_s_bbox_miny, __pyx_k_bbox_miny, sizeof(__pyx_k_bbox_miny), 0, 0, 1, 1}, - {&__pyx_n_u_block_size, __pyx_k_block_size, sizeof(__pyx_k_block_size), 0, 1, 0, 1}, - {&__pyx_n_u_bounding_box, __pyx_k_bounding_box, sizeof(__pyx_k_bounding_box), 0, 1, 0, 1}, - {&__pyx_n_s_bounds, __pyx_k_bounds, sizeof(__pyx_k_bounds), 0, 0, 1, 1}, - {&__pyx_n_s_box, __pyx_k_box, sizeof(__pyx_k_box), 0, 0, 1, 1}, - {&__pyx_n_s_burn_values, __pyx_k_burn_values, sizeof(__pyx_k_burn_values), 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_current_fid, __pyx_k_current_fid, sizeof(__pyx_k_current_fid), 0, 0, 1, 1}, - {&__pyx_n_s_current_pixel, __pyx_k_current_pixel, sizeof(__pyx_k_current_pixel), 0, 0, 1, 1}, - {&__pyx_n_u_d, __pyx_k_d, sizeof(__pyx_k_d), 0, 1, 0, 1}, - {&__pyx_n_s_d8_flow_dir_raster_path_band, __pyx_k_d8_flow_dir_raster_path_band, sizeof(__pyx_k_d8_flow_dir_raster_path_band), 0, 0, 1, 1}, - {&__pyx_n_s_debug, __pyx_k_debug, sizeof(__pyx_k_debug), 0, 0, 1, 1}, - {&__pyx_n_s_delineate_watersheds_d8, __pyx_k_delineate_watersheds_d8, sizeof(__pyx_k_delineate_watersheds_d8), 0, 0, 1, 1}, - {&__pyx_n_s_diagnostic_vector_path, __pyx_k_diagnostic_vector_path, sizeof(__pyx_k_diagnostic_vector_path), 0, 0, 1, 1}, - {&__pyx_n_s_dir, __pyx_k_dir, sizeof(__pyx_k_dir), 0, 0, 1, 1}, - {&__pyx_n_s_driver, __pyx_k_driver, sizeof(__pyx_k_driver), 0, 0, 1, 1}, - {&__pyx_n_s_dtype, __pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 0, 1, 1}, - {&__pyx_n_s_duplicate_feature, __pyx_k_duplicate_feature, sizeof(__pyx_k_duplicate_feature), 0, 0, 1, 1}, - {&__pyx_n_s_duplicate_fid, __pyx_k_duplicate_fid, sizeof(__pyx_k_duplicate_fid), 0, 0, 1, 1}, - {&__pyx_n_s_duplicate_geometry, __pyx_k_duplicate_geometry, sizeof(__pyx_k_duplicate_geometry), 0, 0, 1, 1}, - {&__pyx_n_s_duplicate_ids_set, __pyx_k_duplicate_ids_set, sizeof(__pyx_k_duplicate_ids_set), 0, 0, 1, 1}, - {&__pyx_n_s_duplicate_ids_set_iterator, __pyx_k_duplicate_ids_set_iterator, sizeof(__pyx_k_duplicate_ids_set_iterator), 0, 0, 1, 1}, - {&__pyx_n_s_empty, __pyx_k_empty, sizeof(__pyx_k_empty), 0, 0, 1, 1}, - {&__pyx_n_s_error, __pyx_k_error, sizeof(__pyx_k_error), 0, 0, 1, 1}, - {&__pyx_n_s_exists, __pyx_k_exists, sizeof(__pyx_k_exists), 0, 0, 1, 1}, - {&__pyx_n_s_feature, __pyx_k_feature, sizeof(__pyx_k_feature), 0, 0, 1, 1}, - {&__pyx_n_s_fid, __pyx_k_fid, sizeof(__pyx_k_fid), 0, 0, 1, 1}, - {&__pyx_n_s_field_name, __pyx_k_field_name, sizeof(__pyx_k_field_name), 0, 0, 1, 1}, - {&__pyx_n_s_field_value, __pyx_k_field_value, sizeof(__pyx_k_field_value), 0, 0, 1, 1}, - {&__pyx_n_s_flow_dir_bbox, __pyx_k_flow_dir_bbox, sizeof(__pyx_k_flow_dir_bbox), 0, 0, 1, 1}, - {&__pyx_n_s_flow_dir_info, __pyx_k_flow_dir_info, sizeof(__pyx_k_flow_dir_info), 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_n_cols, __pyx_k_flow_dir_n_cols, sizeof(__pyx_k_flow_dir_n_cols), 0, 0, 1, 1}, - {&__pyx_n_s_flow_dir_n_rows, __pyx_k_flow_dir_n_rows, sizeof(__pyx_k_flow_dir_n_rows), 0, 0, 1, 1}, - {&__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_origin_x, __pyx_k_flow_dir_origin_x, sizeof(__pyx_k_flow_dir_origin_x), 0, 0, 1, 1}, - {&__pyx_n_s_flow_dir_origin_y, __pyx_k_flow_dir_origin_y, sizeof(__pyx_k_flow_dir_origin_y), 0, 0, 1, 1}, - {&__pyx_n_s_flow_dir_pixelsize_x, __pyx_k_flow_dir_pixelsize_x, sizeof(__pyx_k_flow_dir_pixelsize_x), 0, 0, 1, 1}, - {&__pyx_n_s_flow_dir_pixelsize_y, __pyx_k_flow_dir_pixelsize_y, sizeof(__pyx_k_flow_dir_pixelsize_y), 0, 0, 1, 1}, - {&__pyx_n_s_flow_dir_srs, __pyx_k_flow_dir_srs, sizeof(__pyx_k_flow_dir_srs), 0, 0, 1, 1}, - {&__pyx_n_s_fragments_with_duplicates, __pyx_k_fragments_with_duplicates, sizeof(__pyx_k_fragments_with_duplicates), 0, 0, 1, 1}, - {&__pyx_n_s_fragments_with_duplicates_iterat, __pyx_k_fragments_with_duplicates_iterat, sizeof(__pyx_k_fragments_with_duplicates_iterat), 0, 0, 1, 1}, - {&__pyx_n_s_gdal, __pyx_k_gdal, sizeof(__pyx_k_gdal), 0, 0, 1, 1}, - {&__pyx_n_s_geom, __pyx_k_geom, sizeof(__pyx_k_geom), 0, 0, 1, 1}, - {&__pyx_n_s_geom_wkb, __pyx_k_geom_wkb, sizeof(__pyx_k_geom_wkb), 0, 0, 1, 1}, - {&__pyx_n_s_geometry, __pyx_k_geometry, sizeof(__pyx_k_geometry), 0, 0, 1, 1}, - {&__pyx_n_s_geotransform, __pyx_k_geotransform, sizeof(__pyx_k_geotransform), 0, 0, 1, 1}, - {&__pyx_n_u_geotransform, __pyx_k_geotransform, sizeof(__pyx_k_geotransform), 0, 1, 0, 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_driver, __pyx_k_gtiff_driver, sizeof(__pyx_k_gtiff_driver), 0, 0, 1, 1}, - {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, - {&__pyx_n_s_index_field, __pyx_k_index_field, sizeof(__pyx_k_index_field), 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_intersects, __pyx_k_intersects, sizeof(__pyx_k_intersects), 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_items, __pyx_k_items, sizeof(__pyx_k_items), 0, 0, 1, 1}, - {&__pyx_n_s_iterblocks, __pyx_k_iterblocks, sizeof(__pyx_k_iterblocks), 0, 0, 1, 1}, - {&__pyx_n_s_ix_max, __pyx_k_ix_max, sizeof(__pyx_k_ix_max), 0, 0, 1, 1}, - {&__pyx_n_s_ix_min, __pyx_k_ix_min, sizeof(__pyx_k_ix_min), 0, 0, 1, 1}, - {&__pyx_n_s_iy_max, __pyx_k_iy_max, sizeof(__pyx_k_iy_max), 0, 0, 1, 1}, - {&__pyx_n_s_iy_min, __pyx_k_iy_min, sizeof(__pyx_k_iy_min), 0, 0, 1, 1}, - {&__pyx_n_s_join, __pyx_k_join, sizeof(__pyx_k_join), 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_loads, __pyx_k_loads, sizeof(__pyx_k_loads), 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_u_mem, __pyx_k_mem, sizeof(__pyx_k_mem), 0, 1, 0, 1}, - {&__pyx_n_s_mkdtemp, __pyx_k_mkdtemp, sizeof(__pyx_k_mkdtemp), 0, 0, 1, 1}, - {&__pyx_n_u_n_bands, __pyx_k_n_bands, sizeof(__pyx_k_n_bands), 0, 1, 0, 1}, - {&__pyx_n_s_n_cells_visited, __pyx_k_n_cells_visited, sizeof(__pyx_k_n_cells_visited), 0, 0, 1, 1}, - {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, - {&__pyx_n_s_neighbor_col, __pyx_k_neighbor_col, sizeof(__pyx_k_neighbor_col), 0, 0, 1, 1}, - {&__pyx_n_s_neighbor_index, __pyx_k_neighbor_index, sizeof(__pyx_k_neighbor_index), 0, 0, 1, 1}, - {&__pyx_n_s_neighbor_pixel, __pyx_k_neighbor_pixel, sizeof(__pyx_k_neighbor_pixel), 0, 0, 1, 1}, - {&__pyx_n_s_neighbor_row, __pyx_k_neighbor_row, sizeof(__pyx_k_neighbor_row), 0, 0, 1, 1}, - {&__pyx_n_s_new_geometry, __pyx_k_new_geometry, sizeof(__pyx_k_new_geometry), 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_u_nodata, __pyx_k_nodata, sizeof(__pyx_k_nodata), 0, 1, 0, 1}, - {&__pyx_n_s_numpy, __pyx_k_numpy, sizeof(__pyx_k_numpy), 0, 0, 1, 1}, - {&__pyx_kp_u_numpy_core_multiarray_failed_to, __pyx_k_numpy_core_multiarray_failed_to, sizeof(__pyx_k_numpy_core_multiarray_failed_to), 0, 1, 0, 0}, - {&__pyx_kp_u_numpy_core_umath_failed_to_impor, __pyx_k_numpy_core_umath_failed_to_impor, sizeof(__pyx_k_numpy_core_umath_failed_to_impor), 0, 1, 0, 0}, - {&__pyx_n_s_ogr, __pyx_k_ogr, sizeof(__pyx_k_ogr), 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_osr, __pyx_k_osr, sizeof(__pyx_k_osr), 0, 0, 1, 1}, - {&__pyx_n_s_outflow_feature_count, __pyx_k_outflow_feature_count, sizeof(__pyx_k_outflow_feature_count), 0, 0, 1, 1}, - {&__pyx_n_s_outflow_layer, __pyx_k_outflow_layer, sizeof(__pyx_k_outflow_layer), 0, 0, 1, 1}, - {&__pyx_n_s_outflow_vector, __pyx_k_outflow_vector, sizeof(__pyx_k_outflow_vector), 0, 0, 1, 1}, - {&__pyx_n_s_outflow_vector_path, __pyx_k_outflow_vector_path, sizeof(__pyx_k_outflow_vector_path), 0, 0, 1, 1}, - {&__pyx_n_s_outputBounds, __pyx_k_outputBounds, sizeof(__pyx_k_outputBounds), 0, 0, 1, 1}, - {&__pyx_n_s_path, __pyx_k_path, sizeof(__pyx_k_path), 0, 0, 1, 1}, - {&__pyx_n_u_polygonized_watersheds, __pyx_k_polygonized_watersheds, sizeof(__pyx_k_polygonized_watersheds), 0, 1, 0, 1}, - {&__pyx_n_s_polygonized_watersheds_layer, __pyx_k_polygonized_watersheds_layer, sizeof(__pyx_k_polygonized_watersheds_layer), 0, 0, 1, 1}, - {&__pyx_n_s_prefix, __pyx_k_prefix, sizeof(__pyx_k_prefix), 0, 0, 1, 1}, - {&__pyx_n_s_prep, __pyx_k_prep, sizeof(__pyx_k_prep), 0, 0, 1, 1}, - {&__pyx_n_s_prepared, __pyx_k_prepared, sizeof(__pyx_k_prepared), 0, 0, 1, 1}, - {&__pyx_n_s_process_queue, __pyx_k_process_queue, sizeof(__pyx_k_process_queue), 0, 0, 1, 1}, - {&__pyx_n_s_process_queue_set, __pyx_k_process_queue_set, sizeof(__pyx_k_process_queue_set), 0, 0, 1, 1}, - {&__pyx_n_u_projection_wkt, __pyx_k_projection_wkt, sizeof(__pyx_k_projection_wkt), 0, 1, 0, 1}, - {&__pyx_n_s_pygeoprocessing, __pyx_k_pygeoprocessing, sizeof(__pyx_k_pygeoprocessing), 0, 0, 1, 1}, - {&__pyx_n_s_pygeoprocessing_routing_watershe, __pyx_k_pygeoprocessing_routing_watershe, sizeof(__pyx_k_pygeoprocessing_routing_watershe), 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_u_raster_size, __pyx_k_raster_size, sizeof(__pyx_k_raster_size), 0, 1, 0, 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_remove, __pyx_k_remove, sizeof(__pyx_k_remove), 0, 0, 1, 1}, - {&__pyx_n_s_remove_temp_files, __pyx_k_remove_temp_files, sizeof(__pyx_k_remove_temp_files), 0, 0, 1, 1}, - {&__pyx_n_s_return_set, __pyx_k_return_set, sizeof(__pyx_k_return_set), 0, 0, 1, 1}, - {&__pyx_n_s_reverse_flow, __pyx_k_reverse_flow, sizeof(__pyx_k_reverse_flow), 0, 0, 1, 1}, - {&__pyx_n_s_rmtree, __pyx_k_rmtree, sizeof(__pyx_k_rmtree), 0, 0, 1, 1}, - {&__pyx_kp_u_s_is_not_a_file, __pyx_k_s_is_not_a_file, sizeof(__pyx_k_s_is_not_a_file), 0, 1, 0, 0}, - {&__pyx_kp_u_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, 1, 0, 0}, - {&__pyx_kp_u_s_rasterized_tif, __pyx_k_s_rasterized_tif, sizeof(__pyx_k_s_rasterized_tif), 0, 1, 0, 0}, - {&__pyx_kp_u_s_scratch_tif, __pyx_k_s_scratch_tif, sizeof(__pyx_k_s_scratch_tif), 0, 1, 0, 0}, - {&__pyx_kp_u_s_seeds_gpkg, __pyx_k_s_seeds_gpkg, sizeof(__pyx_k_s_seeds_gpkg), 0, 1, 0, 0}, - {&__pyx_kp_u_s_vrt_vrt, __pyx_k_s_vrt_vrt, sizeof(__pyx_k_s_vrt_vrt), 0, 1, 0, 0}, - {&__pyx_n_s_schema, __pyx_k_schema, sizeof(__pyx_k_schema), 0, 0, 1, 1}, - {&__pyx_n_s_scratch_managed_raster, __pyx_k_scratch_managed_raster, sizeof(__pyx_k_scratch_managed_raster), 0, 0, 1, 1}, - {&__pyx_n_s_scratch_raster, __pyx_k_scratch_raster, sizeof(__pyx_k_scratch_raster), 0, 0, 1, 1}, - {&__pyx_n_s_scratch_raster_path, __pyx_k_scratch_raster_path, sizeof(__pyx_k_scratch_raster_path), 0, 0, 1, 1}, - {&__pyx_n_s_seed, __pyx_k_seed, sizeof(__pyx_k_seed), 0, 0, 1, 1}, - {&__pyx_n_s_seed_iterator, __pyx_k_seed_iterator, sizeof(__pyx_k_seed_iterator), 0, 0, 1, 1}, - {&__pyx_n_s_seeds, __pyx_k_seeds, sizeof(__pyx_k_seeds), 0, 0, 1, 1}, - {&__pyx_n_u_seeds, __pyx_k_seeds, sizeof(__pyx_k_seeds), 0, 1, 0, 1}, - {&__pyx_n_s_seeds_in_watershed, __pyx_k_seeds_in_watershed, sizeof(__pyx_k_seeds_in_watershed), 0, 0, 1, 1}, - {&__pyx_n_s_seeds_iterator, __pyx_k_seeds_iterator, sizeof(__pyx_k_seeds_iterator), 0, 0, 1, 1}, - {&__pyx_n_s_seeds_raster_path, __pyx_k_seeds_raster_path, sizeof(__pyx_k_seeds_raster_path), 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_shapely, __pyx_k_shapely, sizeof(__pyx_k_shapely), 0, 0, 1, 1}, - {&__pyx_n_s_shapely_geom, __pyx_k_shapely_geom, sizeof(__pyx_k_shapely_geom), 0, 0, 1, 1}, - {&__pyx_n_s_shapely_geometry, __pyx_k_shapely_geometry, sizeof(__pyx_k_shapely_geometry), 0, 0, 1, 1}, - {&__pyx_n_s_shapely_prepared, __pyx_k_shapely_prepared, sizeof(__pyx_k_shapely_prepared), 0, 0, 1, 1}, - {&__pyx_n_s_shapely_wkb, __pyx_k_shapely_wkb, sizeof(__pyx_k_shapely_wkb), 0, 0, 1, 1}, - {&__pyx_n_s_shutil, __pyx_k_shutil, sizeof(__pyx_k_shutil), 0, 0, 1, 1}, - {&__pyx_n_s_source_feature, __pyx_k_source_feature, sizeof(__pyx_k_source_feature), 0, 0, 1, 1}, - {&__pyx_n_s_source_geom_wkb, __pyx_k_source_geom_wkb, sizeof(__pyx_k_source_geom_wkb), 0, 0, 1, 1}, - {&__pyx_n_s_source_gt, __pyx_k_source_gt, sizeof(__pyx_k_source_gt), 0, 0, 1, 1}, - {&__pyx_n_s_source_layer, __pyx_k_source_layer, sizeof(__pyx_k_source_layer), 0, 0, 1, 1}, - {&__pyx_n_s_source_vector, __pyx_k_source_vector, sizeof(__pyx_k_source_vector), 0, 0, 1, 1}, - {&__pyx_n_s_split_geometry_into_seeds, __pyx_k_split_geometry_into_seeds, sizeof(__pyx_k_split_geometry_into_seeds), 0, 0, 1, 1}, - {&__pyx_kp_s_src_pygeoprocessing_routing_wate, __pyx_k_src_pygeoprocessing_routing_wate, sizeof(__pyx_k_src_pygeoprocessing_routing_wate), 0, 0, 1, 0}, - {&__pyx_n_s_strftime, __pyx_k_strftime, sizeof(__pyx_k_strftime), 0, 0, 1, 1}, - {&__pyx_n_s_target_layer_name, __pyx_k_target_layer_name, sizeof(__pyx_k_target_layer_name), 0, 0, 1, 1}, - {&__pyx_n_s_target_raster_path, __pyx_k_target_raster_path, sizeof(__pyx_k_target_raster_path), 0, 0, 1, 1}, - {&__pyx_n_s_target_watersheds_vector_path, __pyx_k_target_watersheds_vector_path, sizeof(__pyx_k_target_watersheds_vector_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_u_user_geometry, __pyx_k_user_geometry, sizeof(__pyx_k_user_geometry), 0, 1, 0, 1}, - {&__pyx_n_s_vrt_band, __pyx_k_vrt_band, sizeof(__pyx_k_vrt_band), 0, 0, 1, 1}, - {&__pyx_n_s_vrt_options, __pyx_k_vrt_options, sizeof(__pyx_k_vrt_options), 0, 0, 1, 1}, - {&__pyx_n_s_vrt_path, __pyx_k_vrt_path, sizeof(__pyx_k_vrt_path), 0, 0, 1, 1}, - {&__pyx_n_s_vrt_raster, __pyx_k_vrt_raster, sizeof(__pyx_k_vrt_raster), 0, 0, 1, 1}, - {&__pyx_kp_u_watershed_delineation_trivial__s, __pyx_k_watershed_delineation_trivial__s, sizeof(__pyx_k_watershed_delineation_trivial__s), 0, 1, 0, 0}, - {&__pyx_n_s_watershed_feature, __pyx_k_watershed_feature, sizeof(__pyx_k_watershed_feature), 0, 0, 1, 1}, - {&__pyx_n_u_watersheds, __pyx_k_watersheds, sizeof(__pyx_k_watersheds), 0, 1, 0, 1}, - {&__pyx_n_s_watersheds_created, __pyx_k_watersheds_created, sizeof(__pyx_k_watersheds_created), 0, 0, 1, 1}, - {&__pyx_n_s_watersheds_layer, __pyx_k_watersheds_layer, sizeof(__pyx_k_watersheds_layer), 0, 0, 1, 1}, - {&__pyx_n_s_watersheds_srs, __pyx_k_watersheds_srs, sizeof(__pyx_k_watersheds_srs), 0, 0, 1, 1}, - {&__pyx_n_s_watersheds_vector, __pyx_k_watersheds_vector, sizeof(__pyx_k_watersheds_vector), 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_wkb, __pyx_k_wkb, sizeof(__pyx_k_wkb), 0, 0, 1, 1}, - {&__pyx_n_s_wkbMultiPolygon, __pyx_k_wkbMultiPolygon, sizeof(__pyx_k_wkbMultiPolygon), 0, 0, 1, 1}, - {&__pyx_n_s_wkbPoint, __pyx_k_wkbPoint, sizeof(__pyx_k_wkbPoint), 0, 0, 1, 1}, - {&__pyx_n_s_wkbPolygon, __pyx_k_wkbPolygon, sizeof(__pyx_k_wkbPolygon), 0, 0, 1, 1}, - {&__pyx_n_s_wkbUnknown, __pyx_k_wkbUnknown, sizeof(__pyx_k_wkbUnknown), 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_write_diagnostic_vector, __pyx_k_write_diagnostic_vector, sizeof(__pyx_k_write_diagnostic_vector), 0, 0, 1, 1}, - {&__pyx_n_s_write_mode, __pyx_k_write_mode, sizeof(__pyx_k_write_mode), 0, 0, 1, 1}, - {&__pyx_n_s_ws_id, __pyx_k_ws_id, sizeof(__pyx_k_ws_id), 0, 0, 1, 1}, - {&__pyx_n_u_ws_id, __pyx_k_ws_id, sizeof(__pyx_k_ws_id), 0, 1, 0, 1}, - {&__pyx_n_s_x1, __pyx_k_x1, sizeof(__pyx_k_x1), 0, 0, 1, 1}, - {&__pyx_n_s_x2, __pyx_k_x2, sizeof(__pyx_k_x2), 0, 0, 1, 1}, - {&__pyx_n_s_xoff, __pyx_k_xoff, sizeof(__pyx_k_xoff), 0, 0, 1, 1}, - {&__pyx_n_u_xoff, __pyx_k_xoff, sizeof(__pyx_k_xoff), 0, 1, 0, 1}, - {&__pyx_n_s_xrange, __pyx_k_xrange, sizeof(__pyx_k_xrange), 0, 0, 1, 1}, - {&__pyx_n_s_y1, __pyx_k_y1, sizeof(__pyx_k_y1), 0, 0, 1, 1}, - {&__pyx_n_s_y2, __pyx_k_y2, sizeof(__pyx_k_y2), 0, 0, 1, 1}, - {&__pyx_n_s_yoff, __pyx_k_yoff, sizeof(__pyx_k_yoff), 0, 0, 1, 1}, - {&__pyx_n_u_yoff, __pyx_k_yoff, sizeof(__pyx_k_yoff), 0, 1, 0, 1}, - {0, 0, 0, 0, 0, 0, 0} -}; -static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_OSError = __Pyx_GetBuiltinName(__pyx_n_s_OSError); if (!__pyx_builtin_OSError) __PYX_ERR(0, 104, __pyx_L1_error) - __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 114, __pyx_L1_error) - #if PY_MAJOR_VERSION >= 3 - __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_xrange) __PYX_ERR(0, 244, __pyx_L1_error) - #else - __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s_xrange); if (!__pyx_builtin_xrange) __PYX_ERR(0, 244, __pyx_L1_error) - #endif - __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(1, 2, __pyx_L1_error) - __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 544, __pyx_L1_error) - __pyx_builtin_ImportError = __Pyx_GetBuiltinName(__pyx_n_s_ImportError); if (!__pyx_builtin_ImportError) __PYX_ERR(2, 947, __pyx_L1_error) - return 0; - __pyx_L1_error:; - return -1; -} - -static CYTHON_SMALL_CODE 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__2 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__2); - __Pyx_GIVEREF(__pyx_tuple__2); - - /* "(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__3 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__3); - __Pyx_GIVEREF(__pyx_tuple__3); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":947 - * __pyx_import_array() - * except Exception: - * raise ImportError("numpy.core.multiarray failed to import") # <<<<<<<<<<<<<< - * - * cdef inline int import_umath() except -1: - */ - __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_u_numpy_core_multiarray_failed_to); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(2, 947, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__4); - __Pyx_GIVEREF(__pyx_tuple__4); - - /* "../opt/miniconda3/envs/main/lib/python3.9/site-packages/numpy/__init__.pxd":953 - * _import_umath() - * except Exception: - * raise ImportError("numpy.core.umath failed to import") # <<<<<<<<<<<<<< - * - * cdef inline int import_ufunc() except -1: - */ - __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_u_numpy_core_umath_failed_to_impor); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(2, 953, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__5); - __Pyx_GIVEREF(__pyx_tuple__5); - - /* "pygeoprocessing/routing/watershed.pyx":388 - * - * - * 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__6 = PyTuple_Pack(1, __pyx_n_s_raster_path_band); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 388, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__6); - __Pyx_GIVEREF(__pyx_tuple__6); - __pyx_codeobj__7 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__6, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_wate, __pyx_n_s_is_raster_path_band_formatted, 388, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__7)) __PYX_ERR(0, 388, __pyx_L1_error) - - /* "pygeoprocessing/routing/watershed.pyx":571 - * - * - * def _split_geometry_into_seeds( # <<<<<<<<<<<<<< - * source_geom_wkb, geotransform, flow_dir_srs, - * flow_dir_n_cols, flow_dir_n_rows, target_raster_path, - */ - __pyx_tuple__8 = PyTuple_Pack(11, __pyx_n_s_source_geom_wkb, __pyx_n_s_geotransform, __pyx_n_s_flow_dir_srs, __pyx_n_s_flow_dir_n_cols, __pyx_n_s_flow_dir_n_rows, __pyx_n_s_target_raster_path, __pyx_n_s_diagnostic_vector_path, __pyx_n_s_return_set, __pyx_n_s_seeds, __pyx_n_s_seed, __pyx_n_s_seeds_iterator); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 571, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__8); - __Pyx_GIVEREF(__pyx_tuple__8); - __pyx_codeobj__9 = (PyObject*)__Pyx_PyCode_New(7, 0, 11, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__8, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_wate, __pyx_n_s_split_geometry_into_seeds, 571, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__9)) __PYX_ERR(0, 571, __pyx_L1_error) - - /* "pygeoprocessing/routing/watershed.pyx":624 - * - * @cython.boundscheck(False) - * def delineate_watersheds_d8( # <<<<<<<<<<<<<< - * d8_flow_dir_raster_path_band, outflow_vector_path, - * target_watersheds_vector_path, working_dir=None, - */ - __pyx_tuple__11 = PyTuple_Pack(87, __pyx_n_s_d8_flow_dir_raster_path_band, __pyx_n_s_outflow_vector_path, __pyx_n_s_target_watersheds_vector_path, __pyx_n_s_working_dir, __pyx_n_s_write_diagnostic_vector, __pyx_n_s_remove_temp_files, __pyx_n_s_target_layer_name, __pyx_n_s_working_dir_path, __pyx_n_s_flow_dir_info, __pyx_n_s_flow_dir_nodata, __pyx_n_s_source_gt, __pyx_n_s_flow_dir_origin_x, __pyx_n_s_flow_dir_origin_y, __pyx_n_s_flow_dir_pixelsize_x, __pyx_n_s_flow_dir_pixelsize_y, __pyx_n_s_flow_dir_n_cols, __pyx_n_s_flow_dir_n_rows, __pyx_n_s_ws_id, __pyx_n_s_bbox_minx, __pyx_n_s_bbox_miny, __pyx_n_s_bbox_maxx, __pyx_n_s_bbox_maxy, __pyx_n_s_flow_dir_bbox, __pyx_n_s_flow_dir_managed_raster, __pyx_n_s_gtiff_driver, __pyx_n_s_flow_dir_srs, __pyx_n_s_outflow_vector, __pyx_n_s_driver, __pyx_n_s_watersheds_srs, __pyx_n_s_watersheds_vector, __pyx_n_s_polygonized_watersheds_layer, __pyx_n_s_watersheds_layer, __pyx_n_s_index_field, __pyx_n_s_reverse_flow, __pyx_n_s_neighbor_col, __pyx_n_s_neighbor_row, __pyx_n_s_process_queue, __pyx_n_s_process_queue_set, __pyx_n_s_neighbor_pixel, __pyx_n_s_ix_min, __pyx_n_s_iy_min, __pyx_n_s_ix_max, __pyx_n_s_iy_max, __pyx_n_s_scratch_managed_raster, __pyx_n_s_watersheds_created, __pyx_n_s_current_fid, __pyx_n_s_outflow_feature_count, __pyx_n_s_seed_iterator, __pyx_n_s_seeds_in_watershed, __pyx_n_s_last_log_time, __pyx_n_s_n_cells_visited, __pyx_n_s_outflow_layer, __pyx_n_s_feature, __pyx_n_s_geom, __pyx_n_s_geom_wkb, __pyx_n_s_shapely_geom, __pyx_n_s_seeds_raster_path, __pyx_n_s_diagnostic_vector_path, __pyx_n_s_seed, __pyx_n_s_scratch_raster_path, __pyx_n_s_scratch_raster, __pyx_n_s_current_pixel, __pyx_n_s_neighbor_index, __pyx_n_s_x1, __pyx_n_s_y1, __pyx_n_s_x2, __pyx_n_s_y2, __pyx_n_s_vrt_options, __pyx_n_s_vrt_path, __pyx_n_s_vrt_raster, __pyx_n_s_vrt_band, __pyx_n_s__10, __pyx_n_s_fragments_with_duplicates, __pyx_n_s_fid, __pyx_n_s_source_vector, __pyx_n_s_source_layer, __pyx_n_s_duplicate_fid, __pyx_n_s_duplicate_ids_set, __pyx_n_s_duplicate_ids_set_iterator, __pyx_n_s_fragments_with_duplicates_iterat, __pyx_n_s_source_feature, __pyx_n_s_new_geometry, __pyx_n_s_duplicate_feature, __pyx_n_s_duplicate_geometry, __pyx_n_s_watershed_feature, __pyx_n_s_field_name, __pyx_n_s_field_value); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 624, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__11); - __Pyx_GIVEREF(__pyx_tuple__11); - __pyx_codeobj__12 = (PyObject*)__Pyx_PyCode_New(7, 0, 87, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__11, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_wate, __pyx_n_s_delineate_watersheds_d8, 624, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__12)) __PYX_ERR(0, 624, __pyx_L1_error) - __Pyx_RefNannyFinishContext(); - return 0; - __pyx_L1_error:; - __Pyx_RefNannyFinishContext(); - return -1; -} - -static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { - if (__Pyx_InitStrings(__pyx_string_tab) < 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_24 = PyInt_FromLong(24); if (unlikely(!__pyx_int_24)) __PYX_ERR(0, 1, __pyx_L1_error) - return 0; - __pyx_L1_error:; - return -1; -} - -static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/ -static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/ -static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/ -static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/ -static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/ -static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/ -static CYTHON_SMALL_CODE 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 - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); - /*--- Type init code ---*/ - __pyx_vtabptr_15pygeoprocessing_7routing_9watershed__ManagedRaster = &__pyx_vtable_15pygeoprocessing_7routing_9watershed__ManagedRaster; - __pyx_vtable_15pygeoprocessing_7routing_9watershed__ManagedRaster.set = (void (*)(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *, int, int, int))__pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_set; - __pyx_vtable_15pygeoprocessing_7routing_9watershed__ManagedRaster.get = (int (*)(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *, int, int))__pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster_get; - __pyx_vtable_15pygeoprocessing_7routing_9watershed__ManagedRaster._load_block = (void (*)(struct __pyx_obj_15pygeoprocessing_7routing_9watershed__ManagedRaster *, int))__pyx_f_15pygeoprocessing_7routing_9watershed_14_ManagedRaster__load_block; - if (PyType_Ready(&__pyx_type_15pygeoprocessing_7routing_9watershed__ManagedRaster) < 0) __PYX_ERR(0, 69, __pyx_L1_error) - #if PY_VERSION_HEX < 0x030800B1 - __pyx_type_15pygeoprocessing_7routing_9watershed__ManagedRaster.tp_print = 0; - #endif - if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_15pygeoprocessing_7routing_9watershed__ManagedRaster.tp_dictoffset && __pyx_type_15pygeoprocessing_7routing_9watershed__ManagedRaster.tp_getattro == PyObject_GenericGetAttr)) { - __pyx_type_15pygeoprocessing_7routing_9watershed__ManagedRaster.tp_getattro = __Pyx_PyObject_GenericGetAttr; - } - #if CYTHON_COMPILING_IN_CPYTHON - { - PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_15pygeoprocessing_7routing_9watershed__ManagedRaster, "__init__"); if (unlikely(!wrapper)) __PYX_ERR(0, 69, __pyx_L1_error) - if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { - __pyx_wrapperbase_15pygeoprocessing_7routing_9watershed_14_ManagedRaster___init__ = *((PyWrapperDescrObject *)wrapper)->d_base; - __pyx_wrapperbase_15pygeoprocessing_7routing_9watershed_14_ManagedRaster___init__.doc = __pyx_doc_15pygeoprocessing_7routing_9watershed_14_ManagedRaster___init__; - ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_15pygeoprocessing_7routing_9watershed_14_ManagedRaster___init__; - } - } - #endif - if (__Pyx_SetVtable(__pyx_type_15pygeoprocessing_7routing_9watershed__ManagedRaster.tp_dict, __pyx_vtabptr_15pygeoprocessing_7routing_9watershed__ManagedRaster) < 0) __PYX_ERR(0, 69, __pyx_L1_error) - if (PyObject_SetAttr(__pyx_m, __pyx_n_s_ManagedRaster, (PyObject *)&__pyx_type_15pygeoprocessing_7routing_9watershed__ManagedRaster) < 0) __PYX_ERR(0, 69, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_15pygeoprocessing_7routing_9watershed__ManagedRaster) < 0) __PYX_ERR(0, 69, __pyx_L1_error) - __pyx_ptype_15pygeoprocessing_7routing_9watershed__ManagedRaster = &__pyx_type_15pygeoprocessing_7routing_9watershed__ManagedRaster; - __Pyx_RefNannyFinishContext(); - return 0; - __pyx_L1_error:; - __Pyx_RefNannyFinishContext(); - return -1; -} - -static int __Pyx_modinit_type_import_code(void) { - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); - /*--- Type import code ---*/ - __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 9, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", - #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 - sizeof(PyTypeObject), - #else - sizeof(PyHeapTypeObject), - #endif - __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(3, 9, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyImport_ImportModule("numpy"); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 200, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_ptype_5numpy_dtype = __Pyx_ImportType(__pyx_t_1, "numpy", "dtype", sizeof(PyArray_Descr), __Pyx_ImportType_CheckSize_Ignore); - if (!__pyx_ptype_5numpy_dtype) __PYX_ERR(2, 200, __pyx_L1_error) - __pyx_ptype_5numpy_flatiter = __Pyx_ImportType(__pyx_t_1, "numpy", "flatiter", sizeof(PyArrayIterObject), __Pyx_ImportType_CheckSize_Ignore); - if (!__pyx_ptype_5numpy_flatiter) __PYX_ERR(2, 223, __pyx_L1_error) - __pyx_ptype_5numpy_broadcast = __Pyx_ImportType(__pyx_t_1, "numpy", "broadcast", sizeof(PyArrayMultiIterObject), __Pyx_ImportType_CheckSize_Ignore); - if (!__pyx_ptype_5numpy_broadcast) __PYX_ERR(2, 227, __pyx_L1_error) - __pyx_ptype_5numpy_ndarray = __Pyx_ImportType(__pyx_t_1, "numpy", "ndarray", sizeof(PyArrayObject), __Pyx_ImportType_CheckSize_Ignore); - if (!__pyx_ptype_5numpy_ndarray) __PYX_ERR(2, 239, __pyx_L1_error) - __pyx_ptype_5numpy_generic = __Pyx_ImportType(__pyx_t_1, "numpy", "generic", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_generic) __PYX_ERR(2, 771, __pyx_L1_error) - __pyx_ptype_5numpy_number = __Pyx_ImportType(__pyx_t_1, "numpy", "number", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_number) __PYX_ERR(2, 773, __pyx_L1_error) - __pyx_ptype_5numpy_integer = __Pyx_ImportType(__pyx_t_1, "numpy", "integer", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_integer) __PYX_ERR(2, 775, __pyx_L1_error) - __pyx_ptype_5numpy_signedinteger = __Pyx_ImportType(__pyx_t_1, "numpy", "signedinteger", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_signedinteger) __PYX_ERR(2, 777, __pyx_L1_error) - __pyx_ptype_5numpy_unsignedinteger = __Pyx_ImportType(__pyx_t_1, "numpy", "unsignedinteger", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_unsignedinteger) __PYX_ERR(2, 779, __pyx_L1_error) - __pyx_ptype_5numpy_inexact = __Pyx_ImportType(__pyx_t_1, "numpy", "inexact", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_inexact) __PYX_ERR(2, 781, __pyx_L1_error) - __pyx_ptype_5numpy_floating = __Pyx_ImportType(__pyx_t_1, "numpy", "floating", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_floating) __PYX_ERR(2, 783, __pyx_L1_error) - __pyx_ptype_5numpy_complexfloating = __Pyx_ImportType(__pyx_t_1, "numpy", "complexfloating", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_complexfloating) __PYX_ERR(2, 785, __pyx_L1_error) - __pyx_ptype_5numpy_flexible = __Pyx_ImportType(__pyx_t_1, "numpy", "flexible", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_flexible) __PYX_ERR(2, 787, __pyx_L1_error) - __pyx_ptype_5numpy_character = __Pyx_ImportType(__pyx_t_1, "numpy", "character", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_5numpy_character) __PYX_ERR(2, 789, __pyx_L1_error) - __pyx_ptype_5numpy_ufunc = __Pyx_ImportType(__pyx_t_1, "numpy", "ufunc", sizeof(PyUFuncObject), __Pyx_ImportType_CheckSize_Ignore); - if (!__pyx_ptype_5numpy_ufunc) __PYX_ERR(2, 827, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_RefNannyFinishContext(); - return 0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __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; -} - - -#ifndef CYTHON_NO_PYINIT_EXPORT -#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC -#elif PY_MAJOR_VERSION < 3 -#ifdef __cplusplus -#define __Pyx_PyMODINIT_FUNC extern "C" void -#else -#define __Pyx_PyMODINIT_FUNC void -#endif -#else -#ifdef __cplusplus -#define __Pyx_PyMODINIT_FUNC extern "C" PyObject * -#else -#define __Pyx_PyMODINIT_FUNC PyObject * -#endif -#endif - - -#if PY_MAJOR_VERSION < 3 -__Pyx_PyMODINIT_FUNC initwatershed(void) CYTHON_SMALL_CODE; /*proto*/ -__Pyx_PyMODINIT_FUNC initwatershed(void) -#else -__Pyx_PyMODINIT_FUNC PyInit_watershed(void) CYTHON_SMALL_CODE; /*proto*/ -__Pyx_PyMODINIT_FUNC PyInit_watershed(void) -#if CYTHON_PEP489_MULTI_PHASE_INIT -{ - return PyModuleDef_Init(&__pyx_moduledef); -} -static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) { - #if PY_VERSION_HEX >= 0x030700A1 - static PY_INT64_T main_interpreter_id = -1; - PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp); - if (main_interpreter_id == -1) { - main_interpreter_id = current_id; - return (unlikely(current_id == -1)) ? -1 : 0; - } else if (unlikely(main_interpreter_id != current_id)) - #else - static PyInterpreterState *main_interpreter = NULL; - PyInterpreterState *current_interpreter = PyThreadState_Get()->interp; - if (!main_interpreter) { - main_interpreter = current_interpreter; - } else if (unlikely(main_interpreter != current_interpreter)) - #endif - { - PyErr_SetString( - PyExc_ImportError, - "Interpreter change detected - this module can only be loaded into one interpreter per process."); - return -1; - } - return 0; -} -static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) { - PyObject *value = PyObject_GetAttrString(spec, from_name); - int result = 0; - if (likely(value)) { - if (allow_none || value != Py_None) { - result = PyDict_SetItemString(moddict, to_name, value); - } - Py_DECREF(value); - } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { - PyErr_Clear(); - } else { - result = -1; - } - return result; -} -static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) { - PyObject *module = NULL, *moddict, *modname; - if (__Pyx_check_single_interpreter()) - return NULL; - 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__", 1) < 0)) goto bad; - if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad; - if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad; - if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad; - return module; -bad: - Py_XDECREF(module); - return NULL; -} - - -static CYTHON_SMALL_CODE int __pyx_pymod_exec_watershed(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[8]; - static int __pyx_t_5[8]; - static int __pyx_t_6[8]; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannyDeclarations - #if CYTHON_PEP489_MULTI_PHASE_INIT - if (__pyx_m) { - if (__pyx_m == __pyx_pyinit_module) return 0; - PyErr_SetString(PyExc_RuntimeError, "Module 'watershed' has already been imported. Re-initialisation is not supported."); - return -1; - } - #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_watershed(void)", 0); - if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error) - #ifdef __Pxy_PyFrame_Initialize_Offsets - __Pxy_PyFrame_Initialize_Offsets(); - #endif - __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("watershed", __pyx_methods, 0, 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) - Py_INCREF(__pyx_b); - __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) - Py_INCREF(__pyx_cython_runtime); - 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__watershed) { - if (PyObject_SetAttr(__pyx_m, __pyx_n_s_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.watershed")) { - if (unlikely(PyDict_SetItemString(modules, "pygeoprocessing.routing.watershed", __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)) __PYX_ERR(0, 1, __pyx_L1_error) - if (unlikely(__Pyx_modinit_type_import_code() < 0)) __PYX_ERR(0, 1, __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/watershed.pyx":3 - * # coding=UTF-8 - * # cython: language_level=3 - * import logging # <<<<<<<<<<<<<< - * import os - * import shutil - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_logging, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_logging, __pyx_t_1) < 0) __PYX_ERR(0, 3, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":4 - * # cython: language_level=3 - * import logging - * import os # <<<<<<<<<<<<<< - * import shutil - * import tempfile - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_os, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_1) < 0) __PYX_ERR(0, 4, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":5 - * import logging - * import os - * import shutil # <<<<<<<<<<<<<< - * import tempfile - * import time - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_shutil, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_shutil, __pyx_t_1) < 0) __PYX_ERR(0, 5, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":6 - * import os - * import shutil - * import tempfile # <<<<<<<<<<<<<< - * import time - * - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_tempfile, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_tempfile, __pyx_t_1) < 0) __PYX_ERR(0, 6, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":7 - * import shutil - * import tempfile - * import time # <<<<<<<<<<<<<< - * - * cimport cython - */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_time, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 7, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_time, __pyx_t_1) < 0) __PYX_ERR(0, 7, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":21 - * from libcpp.queue cimport queue - * from libcpp.set cimport set as cset - * from osgeo import gdal # <<<<<<<<<<<<<< - * from osgeo import ogr - * from osgeo import osr - */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 21, __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, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 21, __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, 21, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_gdal, __pyx_t_1) < 0) __PYX_ERR(0, 21, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":22 - * from libcpp.set cimport set as cset - * from osgeo import gdal - * from osgeo import ogr # <<<<<<<<<<<<<< - * from osgeo import osr - * import numpy - */ - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 22, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_n_s_ogr); - __Pyx_GIVEREF(__pyx_n_s_ogr); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_ogr); - __pyx_t_1 = __Pyx_Import(__pyx_n_s_osgeo, __pyx_t_2, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 22, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_ogr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 22, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_ogr, __pyx_t_2) < 0) __PYX_ERR(0, 22, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":23 - * from osgeo import gdal - * from osgeo import ogr - * from osgeo import osr # <<<<<<<<<<<<<< - * import numpy - * import shapely.geometry - */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 23, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_n_s_osr); - __Pyx_GIVEREF(__pyx_n_s_osr); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_osr); - __pyx_t_2 = __Pyx_Import(__pyx_n_s_osgeo, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 23, __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_osr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 23, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_osr, __pyx_t_1) < 0) __PYX_ERR(0, 23, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":24 - * from osgeo import ogr - * from osgeo import osr - * import numpy # <<<<<<<<<<<<<< - * import shapely.geometry - * import shapely.prepared - */ - __pyx_t_2 = __Pyx_Import(__pyx_n_s_numpy, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 24, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_numpy, __pyx_t_2) < 0) __PYX_ERR(0, 24, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":25 - * from osgeo import osr - * import numpy - * import shapely.geometry # <<<<<<<<<<<<<< - * import shapely.prepared - * import shapely.wkb - */ - __pyx_t_2 = __Pyx_Import(__pyx_n_s_shapely_geometry, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 25, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_shapely, __pyx_t_2) < 0) __PYX_ERR(0, 25, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":26 - * import numpy - * import shapely.geometry - * import shapely.prepared # <<<<<<<<<<<<<< - * import shapely.wkb - * - */ - __pyx_t_2 = __Pyx_Import(__pyx_n_s_shapely_prepared, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 26, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_shapely, __pyx_t_2) < 0) __PYX_ERR(0, 26, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":27 - * import shapely.geometry - * import shapely.prepared - * import shapely.wkb # <<<<<<<<<<<<<< - * - * import pygeoprocessing - */ - __pyx_t_2 = __Pyx_Import(__pyx_n_s_shapely_wkb, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 27, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_shapely, __pyx_t_2) < 0) __PYX_ERR(0, 27, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":29 - * import shapely.wkb - * - * import pygeoprocessing # <<<<<<<<<<<<<< - * - * LOGGER = logging.getLogger(__name__) - */ - __pyx_t_2 = __Pyx_Import(__pyx_n_s_pygeoprocessing, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 29, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pygeoprocessing, __pyx_t_2) < 0) __PYX_ERR(0, 29, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":31 - * import pygeoprocessing - * - * LOGGER = logging.getLogger(__name__) # <<<<<<<<<<<<<< - * - * # This module creates rasters with a memory xy block size of 2**BLOCK_BITS - */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_logging); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 31, __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, 31, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 31, __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, 31, __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, 31, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":34 - * - * # 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_9watershed_BLOCK_BITS = 8; - - /* "pygeoprocessing/routing/watershed.pyx":37 - * - * # Number of raster blocks to hold in memory at once per Managed Raster - * cdef int MANAGED_RASTER_N_BLOCKS = 2**7 # <<<<<<<<<<<<<< - * - * # these are the creation options that'll be used for all the rasters - */ - __pyx_v_15pygeoprocessing_7routing_9watershed_MANAGED_RASTER_N_BLOCKS = 0x80; - - /* "pygeoprocessing/routing/watershed.pyx":43 - * 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', - * 'SPARSE_OK=TRUE', - * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), # <<<<<<<<<<<<<< - * 'BLOCKYSIZE=%d' % (1 << BLOCK_BITS)) - * - */ - __pyx_t_3 = __Pyx_PyInt_From_long((1 << __pyx_v_15pygeoprocessing_7routing_9watershed_BLOCK_BITS)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 43, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyUnicode_Format(__pyx_kp_u_BLOCKXSIZE_d, __pyx_t_3); 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; - - /* "pygeoprocessing/routing/watershed.pyx":44 - * 'SPARSE_OK=TRUE', - * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), - * 'BLOCKYSIZE=%d' % (1 << BLOCK_BITS)) # <<<<<<<<<<<<<< - * - * # this is used to calculate the opposite D8 direction interpreting the index - */ - __pyx_t_3 = __Pyx_PyInt_From_long((1 << __pyx_v_15pygeoprocessing_7routing_9watershed_BLOCK_BITS)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 44, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyUnicode_Format(__pyx_kp_u_BLOCKYSIZE_d, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 44, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":41 - * # these are the creation options that'll be used for all the rasters - * GTIFF_CREATION_OPTIONS = ( - * 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', # <<<<<<<<<<<<<< - * 'SPARSE_OK=TRUE', - * 'BLOCKXSIZE=%d' % (1 << BLOCK_BITS), - */ - __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 41, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_kp_u_TILED_YES); - __Pyx_GIVEREF(__pyx_kp_u_TILED_YES); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_u_TILED_YES); - __Pyx_INCREF(__pyx_kp_u_BIGTIFF_YES); - __Pyx_GIVEREF(__pyx_kp_u_BIGTIFF_YES); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_kp_u_BIGTIFF_YES); - __Pyx_INCREF(__pyx_kp_u_COMPRESS_LZW); - __Pyx_GIVEREF(__pyx_kp_u_COMPRESS_LZW); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_kp_u_COMPRESS_LZW); - __Pyx_INCREF(__pyx_kp_u_SPARSE_OK_TRUE); - __Pyx_GIVEREF(__pyx_kp_u_SPARSE_OK_TRUE); - PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_kp_u_SPARSE_OK_TRUE); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_3, 5, __pyx_t_1); - __pyx_t_2 = 0; - __pyx_t_1 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_GTIFF_CREATION_OPTIONS, __pyx_t_3) < 0) __PYX_ERR(0, 40, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":48 - * # 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] # <<<<<<<<<<<<<< - * cdef int* NEIGHBOR_COL = [1, 1, 0, -1, -1, -1, 0, 1] - * cdef int* NEIGHBOR_ROW = [0, -1, -1, -1, 0, 1, 1, 1] - */ - __pyx_t_4[0] = 4; - __pyx_t_4[1] = 5; - __pyx_t_4[2] = 6; - __pyx_t_4[3] = 7; - __pyx_t_4[4] = 0; - __pyx_t_4[5] = 1; - __pyx_t_4[6] = 2; - __pyx_t_4[7] = 3; - __pyx_v_15pygeoprocessing_7routing_9watershed_D8_REVERSE_DIRECTION = __pyx_t_4; - - /* "pygeoprocessing/routing/watershed.pyx":49 - * # as a D8 direction - * cdef int* D8_REVERSE_DIRECTION = [4, 5, 6, 7, 0, 1, 2, 3] - * cdef int* NEIGHBOR_COL = [1, 1, 0, -1, -1, -1, 0, 1] # <<<<<<<<<<<<<< - * cdef int* NEIGHBOR_ROW = [0, -1, -1, -1, 0, 1, 1, 1] - * - */ - __pyx_t_5[0] = 1; - __pyx_t_5[1] = 1; - __pyx_t_5[2] = 0; - __pyx_t_5[3] = -1; - __pyx_t_5[4] = -1; - __pyx_t_5[5] = -1; - __pyx_t_5[6] = 0; - __pyx_t_5[7] = 1; - __pyx_v_15pygeoprocessing_7routing_9watershed_NEIGHBOR_COL = __pyx_t_5; - - /* "pygeoprocessing/routing/watershed.pyx":50 - * cdef int* D8_REVERSE_DIRECTION = [4, 5, 6, 7, 0, 1, 2, 3] - * cdef int* NEIGHBOR_COL = [1, 1, 0, -1, -1, -1, 0, 1] - * cdef int* NEIGHBOR_ROW = [0, -1, -1, -1, 0, 1, 1, 1] # <<<<<<<<<<<<<< - * - * # this is a least recently used cache written in C++ in an external file, - */ - __pyx_t_6[0] = 0; - __pyx_t_6[1] = -1; - __pyx_t_6[2] = -1; - __pyx_t_6[3] = -1; - __pyx_t_6[4] = 0; - __pyx_t_6[5] = 1; - __pyx_t_6[6] = 1; - __pyx_t_6[7] = 1; - __pyx_v_15pygeoprocessing_7routing_9watershed_NEIGHBOR_ROW = __pyx_t_6; - - /* "pygeoprocessing/routing/watershed.pyx":388 - * - * - * 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_3 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_9watershed_1_is_raster_path_band_formatted, NULL, __pyx_n_s_pygeoprocessing_routing_watershe); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 388, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_is_raster_path_band_formatted, __pyx_t_3) < 0) __PYX_ERR(0, 388, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":571 - * - * - * def _split_geometry_into_seeds( # <<<<<<<<<<<<<< - * source_geom_wkb, geotransform, flow_dir_srs, - * flow_dir_n_cols, flow_dir_n_rows, target_raster_path, - */ - __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_9watershed_3_split_geometry_into_seeds, NULL, __pyx_n_s_pygeoprocessing_routing_watershe); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 571, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_split_geometry_into_seeds, __pyx_t_3) < 0) __PYX_ERR(0, 571, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":624 - * - * @cython.boundscheck(False) - * def delineate_watersheds_d8( # <<<<<<<<<<<<<< - * d8_flow_dir_raster_path_band, outflow_vector_path, - * target_watersheds_vector_path, working_dir=None, - */ - __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_9watershed_5delineate_watersheds_d8, NULL, __pyx_n_s_pygeoprocessing_routing_watershe); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 624, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_delineate_watersheds_d8, __pyx_t_3) < 0) __PYX_ERR(0, 624, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pygeoprocessing/routing/watershed.pyx":1 - * # coding=UTF-8 # <<<<<<<<<<<<<< - * # cython: language_level=3 - * import logging - */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_3) < 0) __PYX_ERR(0, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pair.from_py":145 - * - * @cname("__pyx_convert_pair_from_py_long__and_long") - * cdef pair[X,Y] __pyx_convert_pair_from_py_long__and_long(object o) except *: # <<<<<<<<<<<<<< - * x, y = o - * return pair[X,Y](x, y) - */ - - /*--- 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.watershed", __pyx_clineno, __pyx_lineno, __pyx_filename); - } - Py_CLEAR(__pyx_m); - } else if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_ImportError, "init pygeoprocessing.routing.watershed"); - } - __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(modname); - if (!m) goto end; - p = PyObject_GetAttrString(m, "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_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 - (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(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 - (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(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; -} - -/* PyDictVersioning */ -#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS -static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { - PyObject *dict = Py_TYPE(obj)->tp_dict; - return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0; -} -static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { - PyObject **dictptr = NULL; - Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; - if (offset) { -#if CYTHON_COMPILING_IN_CPYTHON - dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); -#else - dictptr = _PyObject_GetDictPtr(obj); -#endif - } - return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; -} -static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { - PyObject *dict = Py_TYPE(obj)->tp_dict; - if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict))) - return 0; - return obj_dict_version == __Pyx_get_object_dict_version(obj); -} -#endif - -/* GetModuleGlobalName */ -#if CYTHON_USE_DICT_VERSIONS -static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value) -#else -static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name) -#endif -{ - 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); - __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) - if (likely(result)) { - return __Pyx_NewRef(result); - } else if (unlikely(PyErr_Occurred())) { - return NULL; - } -#else - result = PyDict_GetItem(__pyx_d, name); - __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) - if (likely(result)) { - return __Pyx_NewRef(result); - } -#endif -#else - result = PyObject_GetItem(__pyx_d, name); - __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) - if (likely(result)) { - return __Pyx_NewRef(result); - } - PyErr_Clear(); -#endif - return __Pyx_GetBuiltinName(name); -} - -/* 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 | METH_STACKLESS))); - 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)(void*)meth)) (self, args, nargs, NULL); - } else { - return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs); - } -} -#endif - -/* PyFunctionFastCall */ -#if CYTHON_FAST_PYCALL -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 = __Pyx_PyFrame_GetLocalsplus(f); - 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, Py_ssize_t 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, (int)nargs, - k, (int)nk, - d, (int)nd, kwdefs, closure); -#else - result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL, - args, (int)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 - -/* PyObjectCall2Args */ -static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) { - PyObject *args, *result = NULL; - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(function)) { - PyObject *args[2] = {arg1, arg2}; - return __Pyx_PyFunction_FastCall(function, args, 2); - } - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(function)) { - PyObject *args[2] = {arg1, arg2}; - return __Pyx_PyCFunction_FastCall(function, args, 2); - } - #endif - args = PyTuple_New(2); - if (unlikely(!args)) goto done; - Py_INCREF(arg1); - PyTuple_SET_ITEM(args, 0, arg1); - Py_INCREF(arg2); - PyTuple_SET_ITEM(args, 1, arg2); - Py_INCREF(function); - result = __Pyx_PyObject_Call(function, args, NULL); - Py_DECREF(args); - Py_DECREF(function); -done: - return result; -} - -/* 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 (__Pyx_PyFastCFunction_Check(func)) { - 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 - -/* 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 - -/* 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()) { - if (unlikely(PyTuple_Check(key))) { - PyObject* args = PyTuple_Pack(1, key); - if (likely(args)) { - PyErr_SetObject(PyExc_KeyError, args); - Py_DECREF(args); - } - } else { - PyErr_SetObject(PyExc_KeyError, key); - } - } - 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; -} - -/* PyIntCompare */ -static CYTHON_INLINE PyObject* __Pyx_PyInt_NeObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED long inplace) { - if (op1 == op2) { - Py_RETURN_FALSE; - } - #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))) { - int unequal; - unsigned long uintval; - Py_ssize_t size = Py_SIZE(op1); - const digit* digits = ((PyLongObject*)op1)->ob_digit; - if (intval == 0) { - if (size != 0) Py_RETURN_TRUE; else Py_RETURN_FALSE; - } else if (intval < 0) { - if (size >= 0) - Py_RETURN_TRUE; - intval = -intval; - size = -size; - } else { - if (size <= 0) - Py_RETURN_TRUE; - } - uintval = (unsigned long) intval; -#if PyLong_SHIFT * 4 < SIZEOF_LONG*8 - if (uintval >> (PyLong_SHIFT * 4)) { - unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) - | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); - } else -#endif -#if PyLong_SHIFT * 3 < SIZEOF_LONG*8 - if (uintval >> (PyLong_SHIFT * 3)) { - unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) - | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); - } else -#endif -#if PyLong_SHIFT * 2 < SIZEOF_LONG*8 - if (uintval >> (PyLong_SHIFT * 2)) { - unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) - | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); - } else -#endif -#if PyLong_SHIFT * 1 < SIZEOF_LONG*8 - if (uintval >> (PyLong_SHIFT * 1)) { - unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) - | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); - } else -#endif - unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK)); - if (unequal != 0) 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_NE)); -} - -/* PyIntBinop */ -#if !CYTHON_COMPILING_IN_PYPY -static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) { - (void)inplace; - (void)zerodivision_check; - #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 - -/* PyObjectFormatAndDecref */ -static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f) { - if (unlikely(!s)) return NULL; - if (likely(PyUnicode_CheckExact(s))) return s; - #if PY_MAJOR_VERSION < 3 - if (likely(PyString_CheckExact(s))) { - PyObject *result = PyUnicode_FromEncodedObject(s, NULL, "strict"); - Py_DECREF(s); - return result; - } - #endif - return __Pyx_PyObject_FormatAndDecref(s, f); -} -static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f) { - PyObject *result = PyObject_Format(s, f); - Py_DECREF(s); - return result; -} - -/* JoinPyUnicode */ -static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength, - CYTHON_UNUSED Py_UCS4 max_char) { -#if CYTHON_USE_UNICODE_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - PyObject *result_uval; - int result_ukind; - Py_ssize_t i, char_pos; - void *result_udata; -#if CYTHON_PEP393_ENABLED - result_uval = PyUnicode_New(result_ulength, max_char); - if (unlikely(!result_uval)) return NULL; - result_ukind = (max_char <= 255) ? PyUnicode_1BYTE_KIND : (max_char <= 65535) ? PyUnicode_2BYTE_KIND : PyUnicode_4BYTE_KIND; - result_udata = PyUnicode_DATA(result_uval); -#else - result_uval = PyUnicode_FromUnicode(NULL, result_ulength); - if (unlikely(!result_uval)) return NULL; - result_ukind = sizeof(Py_UNICODE); - result_udata = PyUnicode_AS_UNICODE(result_uval); -#endif - char_pos = 0; - for (i=0; i < value_count; i++) { - int ukind; - Py_ssize_t ulength; - void *udata; - PyObject *uval = PyTuple_GET_ITEM(value_tuple, i); - if (unlikely(__Pyx_PyUnicode_READY(uval))) - goto bad; - ulength = __Pyx_PyUnicode_GET_LENGTH(uval); - if (unlikely(!ulength)) - continue; - if (unlikely(char_pos + ulength < 0)) - goto overflow; - ukind = __Pyx_PyUnicode_KIND(uval); - udata = __Pyx_PyUnicode_DATA(uval); - if (!CYTHON_PEP393_ENABLED || ukind == result_ukind) { - memcpy((char *)result_udata + char_pos * result_ukind, udata, (size_t) (ulength * result_ukind)); - } else { - #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030300F0 || defined(_PyUnicode_FastCopyCharacters) - _PyUnicode_FastCopyCharacters(result_uval, char_pos, uval, 0, ulength); - #else - Py_ssize_t j; - for (j=0; j < ulength; j++) { - Py_UCS4 uchar = __Pyx_PyUnicode_READ(ukind, udata, j); - __Pyx_PyUnicode_WRITE(result_ukind, result_udata, char_pos+j, uchar); - } - #endif - } - char_pos += ulength; - } - return result_uval; -overflow: - PyErr_SetString(PyExc_OverflowError, "join() result is too long for a Python string"); -bad: - Py_DECREF(result_uval); - return NULL; -#else - result_ulength++; - value_count++; - return PyUnicode_Join(__pyx_empty_unicode, value_tuple); -#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_CyFunction_Check(func))) -#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 '?': return "'bool'"; - 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 '?': 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 '?': 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, 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; - ndim = ctx->head->field->type->ndim; - 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 '?': 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->is_valid_array)) { - 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((size_t)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(__Pyx_is_valid_index(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(__Pyx_is_valid_index(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(__Pyx_is_valid_index(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(__Pyx_is_valid_index(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!"); -} - -/* PyIntFromDouble */ - #if PY_MAJOR_VERSION < 3 -static CYTHON_INLINE PyObject* __Pyx_PyInt_FromDouble(double value) { - if (value >= (double)LONG_MIN && value <= (double)LONG_MAX) { - return PyInt_FromLong((long)value); - } - return PyLong_FromDouble(value); -} -#endif - -/* GetTopmostException */ - #if CYTHON_USE_EXC_INFO_STACK -static _PyErr_StackItem * -__Pyx_PyErr_GetTopmostException(PyThreadState *tstate) -{ - _PyErr_StackItem *exc_info = tstate->exc_info; - while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) && - exc_info->previous_item != NULL) - { - exc_info = exc_info->previous_item; - } - return exc_info; -} -#endif - -/* SaveResetException */ - #if CYTHON_FAST_THREAD_STATE -static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { - #if CYTHON_USE_EXC_INFO_STACK - _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate); - *type = exc_info->exc_type; - *value = exc_info->exc_value; - *tb = exc_info->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 CYTHON_USE_EXC_INFO_STACK - _PyErr_StackItem *exc_info = tstate->exc_info; - tmp_type = exc_info->exc_type; - tmp_value = exc_info->exc_value; - tmp_tb = exc_info->exc_traceback; - exc_info->exc_type = type; - exc_info->exc_value = value; - exc_info->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; icurexc_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 - -/* PyObjectGetMethod */ - static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) { - PyObject *attr; -#if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP - PyTypeObject *tp = Py_TYPE(obj); - PyObject *descr; - descrgetfunc f = NULL; - PyObject **dictptr, *dict; - int meth_found = 0; - assert (*method == NULL); - if (unlikely(tp->tp_getattro != PyObject_GenericGetAttr)) { - attr = __Pyx_PyObject_GetAttrStr(obj, name); - goto try_unpack; - } - if (unlikely(tp->tp_dict == NULL) && unlikely(PyType_Ready(tp) < 0)) { - return 0; - } - descr = _PyType_Lookup(tp, name); - if (likely(descr != NULL)) { - Py_INCREF(descr); -#if PY_MAJOR_VERSION >= 3 - #ifdef __Pyx_CyFunction_USED - if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type) || __Pyx_CyFunction_Check(descr))) - #else - if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type))) - #endif -#else - #ifdef __Pyx_CyFunction_USED - if (likely(PyFunction_Check(descr) || __Pyx_CyFunction_Check(descr))) - #else - if (likely(PyFunction_Check(descr))) - #endif -#endif - { - meth_found = 1; - } else { - f = Py_TYPE(descr)->tp_descr_get; - if (f != NULL && PyDescr_IsData(descr)) { - attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); - Py_DECREF(descr); - goto try_unpack; - } - } - } - dictptr = _PyObject_GetDictPtr(obj); - if (dictptr != NULL && (dict = *dictptr) != NULL) { - Py_INCREF(dict); - attr = __Pyx_PyDict_GetItemStr(dict, name); - if (attr != NULL) { - Py_INCREF(attr); - Py_DECREF(dict); - Py_XDECREF(descr); - goto try_unpack; - } - Py_DECREF(dict); - } - if (meth_found) { - *method = descr; - return 1; - } - if (f != NULL) { - attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); - Py_DECREF(descr); - goto try_unpack; - } - if (descr != NULL) { - *method = descr; - return 0; - } - PyErr_Format(PyExc_AttributeError, -#if PY_MAJOR_VERSION >= 3 - "'%.50s' object has no attribute '%U'", - tp->tp_name, name); -#else - "'%.50s' object has no attribute '%.400s'", - tp->tp_name, PyString_AS_STRING(name)); -#endif - return 0; -#else - attr = __Pyx_PyObject_GetAttrStr(obj, name); - goto try_unpack; -#endif -try_unpack: -#if CYTHON_UNPACK_METHODS - if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) { - PyObject *function = PyMethod_GET_FUNCTION(attr); - Py_INCREF(function); - Py_DECREF(attr); - *method = function; - return 1; - } -#endif - *method = attr; - return 0; -} - -/* PyObjectCallMethod0 */ - static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) { - PyObject *method = NULL, *result = NULL; - int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); - if (likely(is_method)) { - result = __Pyx_PyObject_CallOneArg(method, obj); - Py_DECREF(method); - return result; - } - if (unlikely(!method)) goto bad; - result = __Pyx_PyObject_CallNoArg(method); - Py_DECREF(method); -bad: - return result; -} - -/* RaiseNoneIterError */ - static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); -} - -/* UnpackTupleError */ - static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) { - if (t == Py_None) { - __Pyx_RaiseNoneNotIterableError(); - } else if (PyTuple_GET_SIZE(t) < index) { - __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(t)); - } else { - __Pyx_RaiseTooManyValuesError(index); - } -} - -/* UnpackTuple2 */ - static CYTHON_INLINE int __Pyx_unpack_tuple2_exact( - PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2, int decref_tuple) { - PyObject *value1 = NULL, *value2 = NULL; -#if CYTHON_COMPILING_IN_PYPY - value1 = PySequence_ITEM(tuple, 0); if (unlikely(!value1)) goto bad; - value2 = PySequence_ITEM(tuple, 1); if (unlikely(!value2)) goto bad; -#else - value1 = PyTuple_GET_ITEM(tuple, 0); Py_INCREF(value1); - value2 = PyTuple_GET_ITEM(tuple, 1); Py_INCREF(value2); -#endif - if (decref_tuple) { - Py_DECREF(tuple); - } - *pvalue1 = value1; - *pvalue2 = value2; - return 0; -#if CYTHON_COMPILING_IN_PYPY -bad: - Py_XDECREF(value1); - Py_XDECREF(value2); - if (decref_tuple) { Py_XDECREF(tuple); } - return -1; -#endif -} -static int __Pyx_unpack_tuple2_generic(PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2, - int has_known_size, int decref_tuple) { - Py_ssize_t index; - PyObject *value1 = NULL, *value2 = NULL, *iter = NULL; - iternextfunc iternext; - iter = PyObject_GetIter(tuple); - if (unlikely(!iter)) goto bad; - if (decref_tuple) { Py_DECREF(tuple); tuple = NULL; } - iternext = Py_TYPE(iter)->tp_iternext; - value1 = iternext(iter); if (unlikely(!value1)) { index = 0; goto unpacking_failed; } - value2 = iternext(iter); if (unlikely(!value2)) { index = 1; goto unpacking_failed; } - if (!has_known_size && unlikely(__Pyx_IternextUnpackEndCheck(iternext(iter), 2))) goto bad; - Py_DECREF(iter); - *pvalue1 = value1; - *pvalue2 = value2; - return 0; -unpacking_failed: - if (!has_known_size && __Pyx_IterFinish() == 0) - __Pyx_RaiseNeedMoreValuesError(index); -bad: - Py_XDECREF(iter); - Py_XDECREF(value1); - Py_XDECREF(value2); - if (decref_tuple) { Py_XDECREF(tuple); } - return -1; -} - -/* dict_iter */ - static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_dict, PyObject* method_name, - Py_ssize_t* p_orig_length, int* p_source_is_dict) { - is_dict = is_dict || likely(PyDict_CheckExact(iterable)); - *p_source_is_dict = is_dict; - if (is_dict) { -#if !CYTHON_COMPILING_IN_PYPY - *p_orig_length = PyDict_Size(iterable); - Py_INCREF(iterable); - return iterable; -#elif PY_MAJOR_VERSION >= 3 - static PyObject *py_items = NULL, *py_keys = NULL, *py_values = NULL; - PyObject **pp = NULL; - if (method_name) { - const char *name = PyUnicode_AsUTF8(method_name); - if (strcmp(name, "iteritems") == 0) pp = &py_items; - else if (strcmp(name, "iterkeys") == 0) pp = &py_keys; - else if (strcmp(name, "itervalues") == 0) pp = &py_values; - if (pp) { - if (!*pp) { - *pp = PyUnicode_FromString(name + 4); - if (!*pp) - return NULL; - } - method_name = *pp; - } - } -#endif - } - *p_orig_length = 0; - if (method_name) { - PyObject* iter; - iterable = __Pyx_PyObject_CallMethod0(iterable, method_name); - if (!iterable) - return NULL; -#if !CYTHON_COMPILING_IN_PYPY - if (PyTuple_CheckExact(iterable) || PyList_CheckExact(iterable)) - return iterable; -#endif - iter = PyObject_GetIter(iterable); - Py_DECREF(iterable); - return iter; - } - return PyObject_GetIter(iterable); -} -static CYTHON_INLINE int __Pyx_dict_iter_next( - PyObject* iter_obj, CYTHON_NCP_UNUSED Py_ssize_t orig_length, CYTHON_NCP_UNUSED Py_ssize_t* ppos, - PyObject** pkey, PyObject** pvalue, PyObject** pitem, int source_is_dict) { - PyObject* next_item; -#if !CYTHON_COMPILING_IN_PYPY - if (source_is_dict) { - PyObject *key, *value; - if (unlikely(orig_length != PyDict_Size(iter_obj))) { - PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration"); - return -1; - } - if (unlikely(!PyDict_Next(iter_obj, ppos, &key, &value))) { - return 0; - } - if (pitem) { - PyObject* tuple = PyTuple_New(2); - if (unlikely(!tuple)) { - return -1; - } - Py_INCREF(key); - Py_INCREF(value); - PyTuple_SET_ITEM(tuple, 0, key); - PyTuple_SET_ITEM(tuple, 1, value); - *pitem = tuple; - } else { - if (pkey) { - Py_INCREF(key); - *pkey = key; - } - if (pvalue) { - Py_INCREF(value); - *pvalue = value; - } - } - return 1; - } else if (PyTuple_CheckExact(iter_obj)) { - Py_ssize_t pos = *ppos; - if (unlikely(pos >= PyTuple_GET_SIZE(iter_obj))) return 0; - *ppos = pos + 1; - next_item = PyTuple_GET_ITEM(iter_obj, pos); - Py_INCREF(next_item); - } else if (PyList_CheckExact(iter_obj)) { - Py_ssize_t pos = *ppos; - if (unlikely(pos >= PyList_GET_SIZE(iter_obj))) return 0; - *ppos = pos + 1; - next_item = PyList_GET_ITEM(iter_obj, pos); - Py_INCREF(next_item); - } else -#endif - { - next_item = PyIter_Next(iter_obj); - if (unlikely(!next_item)) { - return __Pyx_IterFinish(); - } - } - if (pitem) { - *pitem = next_item; - } else if (pkey && pvalue) { - if (__Pyx_unpack_tuple2(next_item, pkey, pvalue, source_is_dict, source_is_dict, 1)) - return -1; - } else if (pkey) { - *pkey = next_item; - } else { - *pvalue = next_item; - } - return 1; -} - -/* BytesEquals */ - static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) { -#if CYTHON_COMPILING_IN_PYPY - return PyObject_RichCompareBool(s1, s2, equals); -#else - if (s1 == s2) { - return (equals == Py_EQ); - } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) { - const char *ps1, *ps2; - Py_ssize_t length = PyBytes_GET_SIZE(s1); - if (length != PyBytes_GET_SIZE(s2)) - return (equals == Py_NE); - ps1 = PyBytes_AS_STRING(s1); - ps2 = PyBytes_AS_STRING(s2); - if (ps1[0] != ps2[0]) { - return (equals == Py_NE); - } else if (length == 1) { - return (equals == Py_EQ); - } else { - int result; -#if CYTHON_USE_UNICODE_INTERNALS - Py_hash_t hash1, hash2; - hash1 = ((PyBytesObject*)s1)->ob_shash; - hash2 = ((PyBytesObject*)s2)->ob_shash; - if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { - return (equals == Py_NE); - } -#endif - result = memcmp(ps1, ps2, (size_t)length); - return (equals == Py_EQ) ? (result == 0) : (result != 0); - } - } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) { - return (equals == Py_NE); - } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) { - return (equals == Py_NE); - } else { - int result; - PyObject* py_result = PyObject_RichCompare(s1, s2, equals); - if (!py_result) - return -1; - result = __Pyx_PyObject_IsTrue(py_result); - Py_DECREF(py_result); - return result; - } -#endif -} - -/* UnicodeEquals */ - static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) { -#if CYTHON_COMPILING_IN_PYPY - return PyObject_RichCompareBool(s1, s2, equals); -#else -#if PY_MAJOR_VERSION < 3 - PyObject* owned_ref = NULL; -#endif - int s1_is_unicode, s2_is_unicode; - if (s1 == s2) { - goto return_eq; - } - s1_is_unicode = PyUnicode_CheckExact(s1); - s2_is_unicode = PyUnicode_CheckExact(s2); -#if PY_MAJOR_VERSION < 3 - if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) { - owned_ref = PyUnicode_FromObject(s2); - if (unlikely(!owned_ref)) - return -1; - s2 = owned_ref; - s2_is_unicode = 1; - } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) { - owned_ref = PyUnicode_FromObject(s1); - if (unlikely(!owned_ref)) - return -1; - s1 = owned_ref; - s1_is_unicode = 1; - } else if (((!s2_is_unicode) & (!s1_is_unicode))) { - return __Pyx_PyBytes_Equals(s1, s2, equals); - } -#endif - if (s1_is_unicode & s2_is_unicode) { - Py_ssize_t length; - int kind; - void *data1, *data2; - if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0)) - return -1; - length = __Pyx_PyUnicode_GET_LENGTH(s1); - if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) { - goto return_ne; - } -#if CYTHON_USE_UNICODE_INTERNALS - { - Py_hash_t hash1, hash2; - #if CYTHON_PEP393_ENABLED - hash1 = ((PyASCIIObject*)s1)->hash; - hash2 = ((PyASCIIObject*)s2)->hash; - #else - hash1 = ((PyUnicodeObject*)s1)->hash; - hash2 = ((PyUnicodeObject*)s2)->hash; - #endif - if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { - goto return_ne; - } - } -#endif - kind = __Pyx_PyUnicode_KIND(s1); - if (kind != __Pyx_PyUnicode_KIND(s2)) { - goto return_ne; - } - data1 = __Pyx_PyUnicode_DATA(s1); - data2 = __Pyx_PyUnicode_DATA(s2); - if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) { - goto return_ne; - } else if (length == 1) { - goto return_eq; - } else { - int result = memcmp(data1, data2, (size_t)(length * kind)); - #if PY_MAJOR_VERSION < 3 - Py_XDECREF(owned_ref); - #endif - return (equals == Py_EQ) ? (result == 0) : (result != 0); - } - } else if ((s1 == Py_None) & s2_is_unicode) { - goto return_ne; - } else if ((s2 == Py_None) & s1_is_unicode) { - goto return_ne; - } else { - int result; - PyObject* py_result = PyObject_RichCompare(s1, s2, equals); - #if PY_MAJOR_VERSION < 3 - Py_XDECREF(owned_ref); - #endif - if (!py_result) - return -1; - result = __Pyx_PyObject_IsTrue(py_result); - Py_DECREF(py_result); - return result; - } -return_eq: - #if PY_MAJOR_VERSION < 3 - Py_XDECREF(owned_ref); - #endif - return (equals == Py_EQ); -return_ne: - #if PY_MAJOR_VERSION < 3 - Py_XDECREF(owned_ref); - #endif - return (equals == Py_NE); -#endif -} - -/* 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 CYTHON_USE_EXC_INFO_STACK - { - _PyErr_StackItem *exc_info = tstate->exc_info; - tmp_type = exc_info->exc_type; - tmp_value = exc_info->exc_value; - tmp_tb = exc_info->exc_traceback; - exc_info->exc_type = local_type; - exc_info->exc_value = local_value; - exc_info->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; -} - -/* PyObjectGetAttrStrNoError */ - static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) - __Pyx_PyErr_Clear(); -} -static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) { - PyObject *result; -#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1 - PyTypeObject* tp = Py_TYPE(obj); - if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) { - return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1); - } -#endif - result = __Pyx_PyObject_GetAttrStr(obj, attr_name); - if (unlikely(!result)) { - __Pyx_PyObject_GetAttrStr_ClearAttributeError(); - } - return result; -} - -/* 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 __PYX_GOOD; -#else - if (PyObject_HasAttr(type_obj, __pyx_n_s_getstate)) goto __PYX_GOOD; -#endif -#if CYTHON_USE_PYTYPE_LOOKUP - object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; -#else - object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; -#endif - reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto __PYX_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 __PYX_BAD; -#else - object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD; -#endif - reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto __PYX_BAD; - if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) { - reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_reduce_cython); - if (likely(reduce_cython)) { - ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; - ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; - } else if (reduce == object_reduce || PyErr_Occurred()) { - goto __PYX_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_GetAttrStrNoError(type_obj, __pyx_n_s_setstate_cython); - if (likely(setstate_cython)) { - ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; - ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; - } else if (!setstate || PyErr_Occurred()) { - goto __PYX_BAD; - } - } - PyType_Modified((PyTypeObject*)type_obj); - } - } - goto __PYX_GOOD; -__PYX_BAD: - if (!PyErr_Occurred()) - PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name); - ret = -1; -__PYX_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; -} - -/* TypeImport */ - #ifndef __PYX_HAVE_RT_ImportType -#define __PYX_HAVE_RT_ImportType -static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name, - size_t size, enum __Pyx_ImportType_CheckSize check_size) -{ - PyObject *result = 0; - char warning[200]; - Py_ssize_t basicsize; -#ifdef Py_LIMITED_API - PyObject *py_basicsize; -#endif - result = PyObject_GetAttrString(module, class_name); - 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 ((size_t)basicsize < size) { - PyErr_Format(PyExc_ValueError, - "%.200s.%.200s size changed, may indicate binary incompatibility. " - "Expected %zd from C header, got %zd from PyObject", - module_name, class_name, size, basicsize); - goto bad; - } - if (check_size == __Pyx_ImportType_CheckSize_Error && (size_t)basicsize != size) { - PyErr_Format(PyExc_ValueError, - "%.200s.%.200s size changed, may indicate binary incompatibility. " - "Expected %zd from C header, got %zd from PyObject", - module_name, class_name, size, basicsize); - goto bad; - } - else if (check_size == __Pyx_ImportType_CheckSize_Warn && (size_t)basicsize > size) { - PyOS_snprintf(warning, sizeof(warning), - "%s.%s size changed, may indicate binary incompatibility. " - "Expected %zd from C header, got %zd from PyObject", - module_name, class_name, size, basicsize); - if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad; - } - return (PyTypeObject *)result; -bad: - Py_XDECREF(result); - return NULL; -} -#endif - -/* 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 ((1) && (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, (PyObject *)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_NCP_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)) { - __PYX_PY_DICT_LOOKUP_IF_MODIFIED( - use_cline, *cython_runtime_dict, - __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 (use_cline == Py_False || (use_cline != Py_True && 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); - 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)) {} - view->obj = NULL; - Py_DECREF(obj); -} -#endif - - - /* 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;\ - } - -/* 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 = (float)(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 = (float)(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: - 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.0, -1.0); - } - } 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 = (double)(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 = (double)(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: - 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.0, -1.0); - } - } 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_long(long value) { -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const long neg_one = (long) -1, const_zero = (long) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - 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); - } -} - -/* CIntFromPy */ - static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const int neg_one = (int) -1, const_zero = (int) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - 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; -} - -/* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const int neg_one = (int) -1, const_zero = (int) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - 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); - } -} - -/* CIntFromPy */ - static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const long neg_one = (long) -1, const_zero = (long) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - 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; -} - -/* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_Py_intptr_t(Py_intptr_t value) { -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const Py_intptr_t neg_one = (Py_intptr_t) -1, const_zero = (Py_intptr_t) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - const int is_unsigned = neg_one > const_zero; - if (is_unsigned) { - if (sizeof(Py_intptr_t) < sizeof(long)) { - return PyInt_FromLong((long) value); - } else if (sizeof(Py_intptr_t) <= sizeof(unsigned long)) { - return PyLong_FromUnsignedLong((unsigned long) value); -#ifdef HAVE_LONG_LONG - } else if (sizeof(Py_intptr_t) <= sizeof(unsigned PY_LONG_LONG)) { - return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); -#endif - } - } else { - if (sizeof(Py_intptr_t) <= sizeof(long)) { - return PyInt_FromLong((long) value); -#ifdef HAVE_LONG_LONG - } else if (sizeof(Py_intptr_t) <= 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(Py_intptr_t), - little, !is_unsigned); - } -} - -/* 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 int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { - Py_ssize_t i, n; - assert(PyExceptionClass_Check(exc_type)); - n = PyTuple_GET_SIZE(tuple); -#if PY_MAJOR_VERSION >= 3 - for (i=0; ip) { - #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 CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) { - int retval; - if (unlikely(!x)) return -1; - retval = __Pyx_PyObject_IsTrue(x); - Py_DECREF(x); - return retval; -} -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(b); - } -#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 */ From 34cea7cc0b0e5a2dbf2b4aad6ddb1aa5e24d2316 Mon Sep 17 00:00:00 2001 From: emlys Date: Tue, 8 Jun 2021 10:31:02 -0400 Subject: [PATCH 09/10] add history note --- HISTORY.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/HISTORY.rst b/HISTORY.rst index c14b1057..4a8a7640 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -19,6 +19,7 @@ Unreleased Changes uses the individual geometry to infer vector extents. * Expanded the error message raised by ``transform_bounding_box`` when the bounding box cannot be transformed to provide more helpful details. +* Add support and testing for GDAL 3.3.0. 2.2.0 (2020-05-14) From 391ffd4e608d5d02471b36286dce31b28b15a5f6 Mon Sep 17 00:00:00 2001 From: emlys Date: Thu, 10 Jun 2021 15:28:35 -0400 Subject: [PATCH 10/10] remove gdal pin --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1a5fd3bc..306dfe0f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ # pygeoprocessing to work as expected. Cython -GDAL>=3.0.4,<3.3.0 +GDAL>=3.0.4 numpy>=1.10.1 Rtree>=0.8.3 scipy>=0.14.1,!=0.19.1